13334a7e6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
33334a7e6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
43334a7e6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
53334a7e6SAndrew Rist  * distributed with this work for additional information
63334a7e6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
73334a7e6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
83334a7e6SAndrew Rist  * "License"); you may not use this file except in compliance
93334a7e6SAndrew Rist  * with the License.  You may obtain a copy of the License at
103334a7e6SAndrew Rist  *
113334a7e6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
123334a7e6SAndrew Rist  *
133334a7e6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
143334a7e6SAndrew Rist  * software distributed under the License is distributed on an
153334a7e6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
163334a7e6SAndrew Rist  * KIND, either express or implied.  See the License for the
173334a7e6SAndrew Rist  * specific language governing permissions and limitations
183334a7e6SAndrew Rist  * under the License.
193334a7e6SAndrew Rist  *
203334a7e6SAndrew Rist  *************************************************************/
213334a7e6SAndrew Rist 
223334a7e6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _SVX_TABLECONTROLLER_HXX_
25cdf0e10cSrcweir #define _SVX_TABLECONTROLLER_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/util/XModifyListener.hpp>
28cdf0e10cSrcweir #include <com/sun/star/table/XTable.hpp>
29cdf0e10cSrcweir #include <rtl/ref.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <svx/sdr/overlay/overlayobjectlist.hxx>
32cdf0e10cSrcweir #include <svx/selectioncontroller.hxx>
33cdf0e10cSrcweir #include <svx/svdotable.hxx>
34cdf0e10cSrcweir #include <svx/svdview.hxx>
35766ce4d0SZheng Fan //#include <tablemodel.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir class SdrObjEditView;
38cdf0e10cSrcweir class SdrObject;
39cdf0e10cSrcweir class SfxItemSet;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace sdr { namespace table {
42cdf0e10cSrcweir 
43766ce4d0SZheng Fan class TableModel;
44766ce4d0SZheng Fan 
45cdf0e10cSrcweir const sal_Int16 SELTYPE_NONE = 0;
46cdf0e10cSrcweir const sal_Int16 SELTYPE_MOUSE = 1;
47cdf0e10cSrcweir const sal_Int16 SELTYPE_KEYS = 2;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir class SVX_DLLPUBLIC SvxTableController: public sdr::SelectionController
50cdf0e10cSrcweir {
51cdf0e10cSrcweir public:
52cdf0e10cSrcweir     SVX_DLLPRIVATE SvxTableController( SdrObjEditView* pView, const SdrObject* pObj );
53cdf0e10cSrcweir     SVX_DLLPRIVATE virtual ~SvxTableController();
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     // from sdr::SelectionController
56cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool onKeyInput(const KeyEvent& rKEvt, Window* pWin);
57cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool onMouseButtonDown(const MouseEvent& rMEvt, Window* pWin);
58cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool onMouseButtonUp(const MouseEvent& rMEvt, Window* pWin);
59cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool onMouseMove(const MouseEvent& rMEvt, Window* pWin);
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool DeleteMarked();
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     SVX_DLLPRIVATE virtual void onSelectionHasChanged();
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     SVX_DLLPRIVATE virtual void GetState( SfxItemSet& rSet );
66cdf0e10cSrcweir     SVX_DLLPRIVATE virtual void Execute( SfxRequest& rReq );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool GetStyleSheet( SfxStyleSheet* &rpStyleSheet ) const;
69cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool SetStyleSheet( SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	SVX_DLLPRIVATE virtual bool TakeFormatPaintBrush( boost::shared_ptr< SfxItemSet >& rFormatSet  );
72cdf0e10cSrcweir 	SVX_DLLPRIVATE virtual bool ApplyFormatPaintBrush( SfxItemSet& rFormatSet, bool bNoCharacterFormats, bool bNoParagraphFormats );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	// slots
75cdf0e10cSrcweir     SVX_DLLPRIVATE void onInsert( sal_uInt16 nSId, const SfxItemSet* pArgs = 0 );
76cdf0e10cSrcweir     SVX_DLLPRIVATE void onDelete( sal_uInt16 nSId );
77cdf0e10cSrcweir     SVX_DLLPRIVATE void onSelect( sal_uInt16 nSId );
78cdf0e10cSrcweir     SVX_DLLPRIVATE void onFormatTable( SfxRequest& rReq );
79cdf0e10cSrcweir     SVX_DLLPRIVATE void MergeMarkedCells();
80cdf0e10cSrcweir     SVX_DLLPRIVATE void SplitMarkedCells();
81cdf0e10cSrcweir     SVX_DLLPRIVATE void DistributeColumns();
82cdf0e10cSrcweir     SVX_DLLPRIVATE void DistributeRows();
83cdf0e10cSrcweir     SVX_DLLPRIVATE void SetVertical( sal_uInt16 nSId );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     SVX_DLLPRIVATE static rtl::Reference< sdr::SelectionController > create( SdrObjEditView* pView, const SdrObject* pObj, const rtl::Reference< sdr::SelectionController >& xRefController );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     SVX_DLLPRIVATE void MergeAttrFromSelectedCells(SfxItemSet& rAttr, bool bOnlyHardAttr) const;
88cdf0e10cSrcweir     SVX_DLLPRIVATE void SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bReplaceAll);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAttr) const;
91cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool SetAttributes(const SfxItemSet& rSet, bool bReplaceAll);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool GetMarkedObjModel( SdrPage* pNewPage );
94cdf0e10cSrcweir     SVX_DLLPRIVATE virtual bool PasteObjModel( const SdrModel& rModel );
95cdf0e10cSrcweir 
hasSelectedCells() const96cdf0e10cSrcweir     SVX_DLLPRIVATE bool hasSelectedCells() const { return mbCellSelectionMode || mpView->IsTextEdit(); }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	void getSelectedCells( CellPos& rFirstPos, CellPos& rLastPos );
99cdf0e10cSrcweir 	void setSelectedCells( const CellPos& rFirstPos, const CellPos& rLastPos );
100cdf0e10cSrcweir 	void clearSelection();
101cdf0e10cSrcweir 	void selectAll();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     SVX_DLLPRIVATE void onTableModified();
104cdf0e10cSrcweir 
1059b8096d0SSteve Yin 	sal_Bool selectRow( sal_Int32 row );
1069b8096d0SSteve Yin 	sal_Bool selectColumn( sal_Int32 column );
1079b8096d0SSteve Yin 	sal_Bool deselectRow( sal_Int32 row );
1089b8096d0SSteve Yin 	sal_Bool deselectColumn( sal_Int32 column );
1099b8096d0SSteve Yin 	sal_Bool isRowSelected( sal_Int32 nRow );
1109b8096d0SSteve Yin 	sal_Bool isColumnSelected( sal_Int32 nColumn );
1119b8096d0SSteve Yin 	sal_Bool isRowHeader();
1129b8096d0SSteve Yin 	sal_Bool isColumnHeader();
GetTableObj()1139b8096d0SSteve Yin 	::sdr::table::SdrTableObj* GetTableObj() { return dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() ); }
114*ca62e2c2SSteve Yin 	//declare event notification method
1159b8096d0SSteve Yin 	void NotifySelection( const CellPos& firstPos, const CellPos& lastPos, const CellPos& newPos );
116cdf0e10cSrcweir private:
117cdf0e10cSrcweir     SvxTableController(SvxTableController &); // not defined
118cdf0e10cSrcweir     void operator =(SvxTableController &); // not defined
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	// internals
121cdf0e10cSrcweir     SVX_DLLPRIVATE void ApplyBorderAttr( const SfxItemSet& rAttr );
122cdf0e10cSrcweir     SVX_DLLPRIVATE void UpdateTableShape();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     SVX_DLLPRIVATE void SetTableStyle( const SfxItemSet* pArgs );
125cdf0e10cSrcweir     SVX_DLLPRIVATE void SetTableStyleSettings( const SfxItemSet* pArgs );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     SVX_DLLPRIVATE bool PasteObject( SdrTableObj* pPasteTableObj );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     SVX_DLLPRIVATE bool checkTableObject();
130cdf0e10cSrcweir     SVX_DLLPRIVATE bool updateTableObject();
131cdf0e10cSrcweir     SVX_DLLPRIVATE const CellPos& getSelectionStart();
132cdf0e10cSrcweir     SVX_DLLPRIVATE void setSelectionStart( const CellPos& rPos );
133cdf0e10cSrcweir     SVX_DLLPRIVATE const CellPos& getSelectionEnd();
134cdf0e10cSrcweir     SVX_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellCursor > getSelectionCursor();
135cdf0e10cSrcweir     SVX_DLLPRIVATE void checkCell( CellPos& rPos );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     SVX_DLLPRIVATE void MergeRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     SVX_DLLPRIVATE void EditCell( const CellPos& rPos, ::Window* pWindow, const ::com::sun::star::awt::MouseEvent* pMouseEvent = 0, sal_uInt16 nAction = 0 );
140cdf0e10cSrcweir     SVX_DLLPRIVATE bool StopTextEdit();
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     SVX_DLLPRIVATE void DeleteTable();
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     SVX_DLLPRIVATE sal_uInt16 getKeyboardAction( const KeyEvent& rKEvt, Window* pWindow );
145cdf0e10cSrcweir     SVX_DLLPRIVATE bool executeAction( sal_uInt16 nAction, bool bSelect, Window* pWindow );
146cdf0e10cSrcweir     SVX_DLLPRIVATE void gotoCell( const CellPos& rCell, bool bSelect, Window* pWindow, sal_uInt16 nAction = 0 );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     SVX_DLLPRIVATE void StartSelection( const CellPos& rPos );
149cdf0e10cSrcweir     SVX_DLLPRIVATE void UpdateSelection( const CellPos& rPos );
150cdf0e10cSrcweir     SVX_DLLPRIVATE void RemoveSelection();
151cdf0e10cSrcweir     SVX_DLLPRIVATE void updateSelectionOverlay();
152cdf0e10cSrcweir     SVX_DLLPRIVATE void destroySelectionOverlay();
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     SVX_DLLPRIVATE void findMergeOrigin( CellPos& rPos );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	DECL_LINK( UpdateHdl, void * );
157cdf0e10cSrcweir 
1589b8096d0SSteve Yin 	//TableModelRef mxTable;
1599b8096d0SSteve Yin 	rtl::Reference< TableModel > mxTable;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	CellPos maCursorFirstPos;
162cdf0e10cSrcweir 	CellPos maCursorLastPos;
163cdf0e10cSrcweir 	bool mbCellSelectionMode;
164cdf0e10cSrcweir 	CellPos maMouseDownPos;
165cdf0e10cSrcweir 	bool mbLeftButtonDown;
166cdf0e10cSrcweir 	::sdr::overlay::OverlayObjectList*	mpSelectionOverlay;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	SdrView* mpView;
169cdf0e10cSrcweir 	SdrObjectWeakRef mxTableObj;
170cdf0e10cSrcweir 	SdrModel* mpModel;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > mxModifyListener;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	sal_uLong mnUpdateEvent;
175cdf0e10cSrcweir };
176cdf0e10cSrcweir 
177cdf0e10cSrcweir } }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir #endif // _SVX_TABLECONTROLLER_HXX_
180cdf0e10cSrcweir 
181