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 96 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 ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellCursor > getSelectionCursor(); 124 SVX_DLLPRIVATE void checkCell( CellPos& rPos ); 125 126 SVX_DLLPRIVATE void MergeRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow ); 127 128 SVX_DLLPRIVATE void EditCell( const CellPos& rPos, ::Window* pWindow, const ::com::sun::star::awt::MouseEvent* pMouseEvent = 0, sal_uInt16 nAction = 0 ); 129 SVX_DLLPRIVATE bool StopTextEdit(); 130 131 SVX_DLLPRIVATE void DeleteTable(); 132 133 SVX_DLLPRIVATE sal_uInt16 getKeyboardAction( const KeyEvent& rKEvt, Window* pWindow ); 134 SVX_DLLPRIVATE bool executeAction( sal_uInt16 nAction, bool bSelect, Window* pWindow ); 135 SVX_DLLPRIVATE void gotoCell( const CellPos& rCell, bool bSelect, Window* pWindow, sal_uInt16 nAction = 0 ); 136 137 SVX_DLLPRIVATE void StartSelection( const CellPos& rPos ); 138 SVX_DLLPRIVATE void UpdateSelection( const CellPos& rPos ); 139 SVX_DLLPRIVATE void RemoveSelection(); 140 SVX_DLLPRIVATE void updateSelectionOverlay(); 141 SVX_DLLPRIVATE void destroySelectionOverlay(); 142 143 SVX_DLLPRIVATE void findMergeOrigin( CellPos& rPos ); 144 145 DECL_LINK( UpdateHdl, void * ); 146 147 //TableModelRef mxTable; 148 rtl::Reference< TableModel > mxTable; 149 150 CellPos maCursorFirstPos; 151 CellPos maCursorLastPos; 152 bool mbCellSelectionMode; 153 CellPos maMouseDownPos; 154 bool mbLeftButtonDown; 155 ::sdr::overlay::OverlayObjectList* mpSelectionOverlay; 156 157 SdrView* mpView; 158 SdrObjectWeakRef mxTableObj; 159 SdrModel* mpModel; 160 161 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > mxModifyListener; 162 163 sal_uLong mnUpdateEvent; 164 }; 165 166 } } 167 168 #endif // _SVX_TABLECONTROLLER_HXX_ 169 170