1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SVX_TABLECONTROLLER_HXX_
25 #define _SVX_TABLECONTROLLER_HXX_
26 
27 #include <com/sun/star/util/XModifyListener.hpp>
28 #include <com/sun/star/table/XTable.hpp>
29 #include <rtl/ref.hxx>
30 
31 #include <svx/sdr/overlay/overlayobjectlist.hxx>
32 #include <svx/selectioncontroller.hxx>
33 #include <svx/svdotable.hxx>
34 #include <svx/svdview.hxx>
35 //#include <tablemodel.hxx>
36 
37 class SdrObjEditView;
38 class SdrObject;
39 class SfxItemSet;
40 
41 namespace sdr { namespace table {
42 
43 class TableModel;
44 
45 const sal_Int16 SELTYPE_NONE = 0;
46 const sal_Int16 SELTYPE_MOUSE = 1;
47 const sal_Int16 SELTYPE_KEYS = 2;
48 
49 class SVX_DLLPUBLIC SvxTableController: public sdr::SelectionController
50 {
51 public:
52     SVX_DLLPRIVATE SvxTableController( SdrObjEditView* pView, const SdrObject* pObj );
53     SVX_DLLPRIVATE virtual ~SvxTableController();
54 
55     // from sdr::SelectionController
56     SVX_DLLPRIVATE virtual bool onKeyInput(const KeyEvent& rKEvt, Window* pWin);
57     SVX_DLLPRIVATE virtual bool onMouseButtonDown(const MouseEvent& rMEvt, Window* pWin);
58     SVX_DLLPRIVATE virtual bool onMouseButtonUp(const MouseEvent& rMEvt, Window* pWin);
59     SVX_DLLPRIVATE virtual bool onMouseMove(const MouseEvent& rMEvt, Window* pWin);
60 
61     SVX_DLLPRIVATE virtual bool DeleteMarked();
62 
63     SVX_DLLPRIVATE virtual void onSelectionHasChanged();
64 
65     SVX_DLLPRIVATE virtual void GetState( SfxItemSet& rSet );
66     SVX_DLLPRIVATE virtual void Execute( SfxRequest& rReq );
67 
68     SVX_DLLPRIVATE virtual bool GetStyleSheet( SfxStyleSheet* &rpStyleSheet ) const;
69     SVX_DLLPRIVATE virtual bool SetStyleSheet( SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr );
70 
71 	SVX_DLLPRIVATE virtual bool TakeFormatPaintBrush( boost::shared_ptr< SfxItemSet >& rFormatSet  );
72 	SVX_DLLPRIVATE virtual bool ApplyFormatPaintBrush( SfxItemSet& rFormatSet, bool bNoCharacterFormats, bool bNoParagraphFormats );
73 
74 	// slots
75     SVX_DLLPRIVATE void onInsert( sal_uInt16 nSId, const SfxItemSet* pArgs = 0 );
76     SVX_DLLPRIVATE void onDelete( sal_uInt16 nSId );
77     SVX_DLLPRIVATE void onSelect( sal_uInt16 nSId );
78     SVX_DLLPRIVATE void onFormatTable( SfxRequest& rReq );
79     SVX_DLLPRIVATE void MergeMarkedCells();
80     SVX_DLLPRIVATE void SplitMarkedCells();
81     SVX_DLLPRIVATE void DistributeColumns();
82     SVX_DLLPRIVATE void DistributeRows();
83     SVX_DLLPRIVATE void SetVertical( sal_uInt16 nSId );
84 
85     SVX_DLLPRIVATE static rtl::Reference< sdr::SelectionController > create( SdrObjEditView* pView, const SdrObject* pObj, const rtl::Reference< sdr::SelectionController >& xRefController );
86 
87     SVX_DLLPRIVATE void MergeAttrFromSelectedCells(SfxItemSet& rAttr, bool bOnlyHardAttr) const;
88     SVX_DLLPRIVATE void SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bReplaceAll);
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 
hasSelectedCells() const96     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 	sal_Bool selectRow( sal_Int32 row );
106 	sal_Bool selectColumn( sal_Int32 column );
107 	sal_Bool deselectRow( sal_Int32 row );
108 	sal_Bool deselectColumn( sal_Int32 column );
109 	sal_Bool isRowSelected( sal_Int32 nRow );
110 	sal_Bool isColumnSelected( sal_Int32 nColumn );
111 	sal_Bool isRowHeader();
112 	sal_Bool isColumnHeader();
GetTableObj()113 	::sdr::table::SdrTableObj* GetTableObj() { return dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() ); }
114 	//declare event notification method
115 	void NotifySelection( const CellPos& firstPos, const CellPos& lastPos, const CellPos& newPos );
116 private:
117     SvxTableController(SvxTableController &); // not defined
118     void operator =(SvxTableController &); // not defined
119 
120 	// internals
121     SVX_DLLPRIVATE void ApplyBorderAttr( const SfxItemSet& rAttr );
122     SVX_DLLPRIVATE void UpdateTableShape();
123 
124     SVX_DLLPRIVATE void SetTableStyle( const SfxItemSet* pArgs );
125     SVX_DLLPRIVATE void SetTableStyleSettings( const SfxItemSet* pArgs );
126 
127     SVX_DLLPRIVATE bool PasteObject( SdrTableObj* pPasteTableObj );
128 
129     SVX_DLLPRIVATE bool checkTableObject();
130     SVX_DLLPRIVATE bool updateTableObject();
131     SVX_DLLPRIVATE const CellPos& getSelectionStart();
132     SVX_DLLPRIVATE void setSelectionStart( const CellPos& rPos );
133     SVX_DLLPRIVATE const CellPos& getSelectionEnd();
134     SVX_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellCursor > getSelectionCursor();
135     SVX_DLLPRIVATE void checkCell( CellPos& rPos );
136 
137     SVX_DLLPRIVATE void MergeRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow );
138 
139     SVX_DLLPRIVATE void EditCell( const CellPos& rPos, ::Window* pWindow, const ::com::sun::star::awt::MouseEvent* pMouseEvent = 0, sal_uInt16 nAction = 0 );
140     SVX_DLLPRIVATE bool StopTextEdit();
141 
142     SVX_DLLPRIVATE void DeleteTable();
143 
144     SVX_DLLPRIVATE sal_uInt16 getKeyboardAction( const KeyEvent& rKEvt, Window* pWindow );
145     SVX_DLLPRIVATE bool executeAction( sal_uInt16 nAction, bool bSelect, Window* pWindow );
146     SVX_DLLPRIVATE void gotoCell( const CellPos& rCell, bool bSelect, Window* pWindow, sal_uInt16 nAction = 0 );
147 
148     SVX_DLLPRIVATE void StartSelection( const CellPos& rPos );
149     SVX_DLLPRIVATE void UpdateSelection( const CellPos& rPos );
150     SVX_DLLPRIVATE void RemoveSelection();
151     SVX_DLLPRIVATE void updateSelectionOverlay();
152     SVX_DLLPRIVATE void destroySelectionOverlay();
153 
154     SVX_DLLPRIVATE void findMergeOrigin( CellPos& rPos );
155 
156 	DECL_LINK( UpdateHdl, void * );
157 
158 	//TableModelRef mxTable;
159 	rtl::Reference< TableModel > mxTable;
160 
161 	CellPos maCursorFirstPos;
162 	CellPos maCursorLastPos;
163 	bool mbCellSelectionMode;
164 	CellPos maMouseDownPos;
165 	bool mbLeftButtonDown;
166 	::sdr::overlay::OverlayObjectList*	mpSelectionOverlay;
167 
168 	SdrView* mpView;
169 	SdrObjectWeakRef mxTableObj;
170 	SdrModel* mpModel;
171 
172 	::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > mxModifyListener;
173 
174 	sal_uLong mnUpdateEvent;
175 };
176 
177 } }
178 
179 #endif // _SVX_TABLECONTROLLER_HXX_
180 
181