Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _SVX_TABLECONTROLLER_HXX_
21 : #define _SVX_TABLECONTROLLER_HXX_
22 :
23 : #include <com/sun/star/util/XModifyListener.hpp>
24 : #include <com/sun/star/table/XTable.hpp>
25 : #include <rtl/ref.hxx>
26 :
27 : #include <svx/sdr/overlay/overlayobjectlist.hxx>
28 : #include <svx/selectioncontroller.hxx>
29 : #include <svx/svdotable.hxx>
30 : #include <svx/svdview.hxx>
31 : //#include <tablemodel.hxx>
32 :
33 : class SdrObjEditView;
34 : class SdrObject;
35 : class SfxItemSet;
36 : class SvxBoxInfoItem;
37 : class SvxBoxItem;
38 :
39 : namespace sdr { namespace table {
40 :
41 : class TableModel;
42 :
43 : class SVX_DLLPUBLIC SvxTableController: public sdr::SelectionController
44 : {
45 : public:
46 : SVX_DLLPRIVATE SvxTableController( SdrObjEditView* pView, const SdrObject* pObj );
47 : SVX_DLLPRIVATE virtual ~SvxTableController();
48 :
49 : // from sdr::SelectionController
50 : SVX_DLLPRIVATE virtual bool onKeyInput(const KeyEvent& rKEvt, Window* pWin);
51 : SVX_DLLPRIVATE virtual bool onMouseButtonDown(const MouseEvent& rMEvt, Window* pWin);
52 : SVX_DLLPRIVATE virtual bool onMouseButtonUp(const MouseEvent& rMEvt, Window* pWin);
53 : SVX_DLLPRIVATE virtual bool onMouseMove(const MouseEvent& rMEvt, Window* pWin);
54 :
55 : SVX_DLLPRIVATE virtual bool DeleteMarked();
56 :
57 : SVX_DLLPRIVATE virtual void onSelectionHasChanged();
58 :
59 : SVX_DLLPRIVATE virtual void GetState( SfxItemSet& rSet );
60 : SVX_DLLPRIVATE virtual void Execute( SfxRequest& rReq );
61 :
62 : SVX_DLLPRIVATE virtual bool GetStyleSheet( SfxStyleSheet* &rpStyleSheet ) const;
63 : SVX_DLLPRIVATE virtual bool SetStyleSheet( SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr );
64 :
65 : SVX_DLLPRIVATE virtual bool TakeFormatPaintBrush( boost::shared_ptr< SfxItemSet >& rFormatSet );
66 : SVX_DLLPRIVATE virtual bool ApplyFormatPaintBrush( SfxItemSet& rFormatSet, bool bNoCharacterFormats, bool bNoParagraphFormats );
67 :
68 : // slots
69 : SVX_DLLPRIVATE void onInsert( sal_uInt16 nSId, const SfxItemSet* pArgs = 0 );
70 : SVX_DLLPRIVATE void onDelete( sal_uInt16 nSId );
71 : SVX_DLLPRIVATE void onSelect( sal_uInt16 nSId );
72 : SVX_DLLPRIVATE void onFormatTable( SfxRequest& rReq );
73 : SVX_DLLPRIVATE void MergeMarkedCells();
74 : SVX_DLLPRIVATE void SplitMarkedCells();
75 : SVX_DLLPRIVATE void DistributeColumns();
76 : SVX_DLLPRIVATE void DistributeRows();
77 : SVX_DLLPRIVATE void SetVertical( sal_uInt16 nSId );
78 :
79 : SVX_DLLPRIVATE static rtl::Reference< sdr::SelectionController > create( SdrObjEditView* pView, const SdrObject* pObj, const rtl::Reference< sdr::SelectionController >& xRefController );
80 :
81 : SVX_DLLPRIVATE void MergeAttrFromSelectedCells(SfxItemSet& rAttr, bool bOnlyHardAttr) const;
82 : SVX_DLLPRIVATE void SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bReplaceAll);
83 : /** Fill the values that are common for all selected cells.
84 : *
85 : * This lets the Borders dialog to display the line arrangement
86 : * properly.
87 : */
88 : SVX_DLLPRIVATE void FillCommonBorderAttrFromSelectedCells(SvxBoxItem& rBox, SvxBoxInfoItem& rBoxInfo) const;
89 :
90 : SVX_DLLPRIVATE virtual bool GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAttr) const;
91 : SVX_DLLPRIVATE virtual bool SetAttributes(const SfxItemSet& rSet, bool bReplaceAll);
92 :
93 : SVX_DLLPRIVATE virtual bool GetMarkedObjModel( SdrPage* pNewPage );
94 : SVX_DLLPRIVATE virtual bool PasteObjModel( const SdrModel& rModel );
95 :
96 0 : SVX_DLLPRIVATE bool hasSelectedCells() const { return mbCellSelectionMode || mpView->IsTextEdit(); }
97 :
98 : void getSelectedCells( CellPos& rFirstPos, CellPos& rLastPos );
99 : void setSelectedCells( const CellPos& rFirstPos, const CellPos& rLastPos );
100 : void clearSelection();
101 : void selectAll();
102 :
103 : SVX_DLLPRIVATE void onTableModified();
104 :
105 : private:
106 : SvxTableController(SvxTableController &); // not defined
107 : void operator =(SvxTableController &); // not defined
108 :
109 : // internals
110 : SVX_DLLPRIVATE void ApplyBorderAttr( const SfxItemSet& rAttr );
111 : SVX_DLLPRIVATE void UpdateTableShape();
112 :
113 : SVX_DLLPRIVATE void SetTableStyle( const SfxItemSet* pArgs );
114 : SVX_DLLPRIVATE void SetTableStyleSettings( const SfxItemSet* pArgs );
115 :
116 : SVX_DLLPRIVATE bool PasteObject( SdrTableObj* pPasteTableObj );
117 :
118 : SVX_DLLPRIVATE bool checkTableObject();
119 : SVX_DLLPRIVATE bool updateTableObject();
120 : SVX_DLLPRIVATE const CellPos& getSelectionStart();
121 : SVX_DLLPRIVATE void setSelectionStart( const CellPos& rPos );
122 : SVX_DLLPRIVATE const CellPos& getSelectionEnd();
123 : SVX_DLLPRIVATE void checkCell( CellPos& rPos );
124 :
125 : SVX_DLLPRIVATE void MergeRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow );
126 :
127 : SVX_DLLPRIVATE void EditCell( const CellPos& rPos, ::Window* pWindow, const ::com::sun::star::awt::MouseEvent* pMouseEvent = 0, sal_uInt16 nAction = 0 );
128 : SVX_DLLPRIVATE bool StopTextEdit();
129 :
130 : SVX_DLLPRIVATE sal_uInt16 getKeyboardAction( const KeyEvent& rKEvt, Window* pWindow );
131 : SVX_DLLPRIVATE bool executeAction( sal_uInt16 nAction, bool bSelect, Window* pWindow );
132 : SVX_DLLPRIVATE void gotoCell( const CellPos& rCell, bool bSelect, Window* pWindow, sal_uInt16 nAction = 0 );
133 :
134 : SVX_DLLPRIVATE void StartSelection( const CellPos& rPos );
135 : SVX_DLLPRIVATE void UpdateSelection( const CellPos& rPos );
136 : SVX_DLLPRIVATE void RemoveSelection();
137 : SVX_DLLPRIVATE void updateSelectionOverlay();
138 : SVX_DLLPRIVATE void destroySelectionOverlay();
139 :
140 : SVX_DLLPRIVATE void findMergeOrigin( CellPos& rPos );
141 :
142 : DECL_LINK( UpdateHdl, void * );
143 :
144 : //TableModelRef mxTable;
145 : rtl::Reference< TableModel > mxTable;
146 :
147 : CellPos maCursorFirstPos;
148 : CellPos maCursorLastPos;
149 : bool mbCellSelectionMode;
150 : CellPos maMouseDownPos;
151 : bool mbLeftButtonDown;
152 : ::sdr::overlay::OverlayObjectList* mpSelectionOverlay;
153 :
154 : SdrView* mpView;
155 : SdrObjectWeakRef mxTableObj;
156 : SdrModel* mpModel;
157 :
158 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > mxModifyListener;
159 :
160 : sal_uLong mnUpdateEvent;
161 : };
162 :
163 : } }
164 :
165 : #endif // _SVX_TABLECONTROLLER_HXX_
166 :
167 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|