Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / svx / svdotable.hxx
blob29495ab5524b2e802bb744cba0d5655dab9364dc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_SVDOTABLE_HXX
21 #define INCLUDED_SVX_SVDOTABLE_HXX
23 #include <com/sun/star/text/WritingMode.hpp>
24 #include <com/sun/star/container/XIndexAccess.hpp>
25 #include <com/sun/star/table/XTable.hpp>
26 #include <rtl/ref.hxx>
27 #include <svx/svdotext.hxx>
28 #include <svx/svxdllapi.h>
31 class SvStream;
32 class SfxStyleSheet;
33 class SdrUndoAction;
35 namespace sdr { namespace contact {
36 class ViewContactOfTableObj;
39 namespace sdr { namespace table {
41 class TableLayouter;
42 struct ImplTableShadowPaintInfo;
44 #ifndef CellRef
45 class Cell;
46 typedef rtl::Reference< Cell > CellRef;
47 #endif
50 /// SdrTableHitKind
51 enum class TableHitKind
53 NONE,
54 Cell,
55 CellTextArea,
56 HorizontalBorder,
57 VerticallBorder
61 struct CellPos
63 sal_Int32 mnCol;
64 sal_Int32 mnRow;
66 CellPos() : mnCol( 0 ), mnRow( 0 ) {}
67 CellPos( sal_Int32 nCol, sal_Int32 nRow ) { mnCol = nCol; mnRow = nRow; }
69 bool operator==( const CellPos& r ) const { return (r.mnCol == mnCol) && (r.mnRow == mnRow); }
70 bool operator!=( const CellPos& r ) const { return (r.mnCol != mnCol) || (r.mnRow != mnRow); }
74 /// TableStyleSettings
75 struct SVX_DLLPUBLIC TableStyleSettings
77 bool mbUseFirstRow;
78 bool mbUseLastRow;
79 bool mbUseFirstColumn;
80 bool mbUseLastColumn;
81 bool mbUseRowBanding;
82 bool mbUseColumnBanding;
84 TableStyleSettings();
85 TableStyleSettings( const TableStyleSettings& rStyle );
86 TableStyleSettings& operator=(const TableStyleSettings& rStyle);
88 bool operator==( const TableStyleSettings& r ) const;
92 /// SdrTableObj
93 class SdrTableObjImpl;
95 class SVX_DLLPUBLIC SdrTableObj : public ::SdrTextObj
97 friend class Cell;
98 friend class SdrTableObjImpl;
100 public:
101 SdrTableObj(SdrModel* _pModel);
102 SdrTableObj(SdrModel* _pModel, const ::tools::Rectangle& rNewRect, sal_Int32 nColumns, sal_Int32 nRows);
103 virtual ~SdrTableObj() override;
106 // Table stuff
107 SdrTableObj* CloneRange( const CellPos& rStartPos, const CellPos& rEndPos );
108 void DistributeColumns( sal_Int32 nFirstColumn, sal_Int32 nLastColumn );
109 void DistributeRows( sal_Int32 nFirstRow, sal_Int32 nLastRow );
111 css::uno::Reference< css::table::XTable > getTable() const;
113 bool isValid( const sdr::table::CellPos& rPos ) const;
114 static CellPos getFirstCell();
115 CellPos getLastCell() const;
116 CellPos getLeftCell( const CellPos& rPos, bool bEdgeTravel ) const;
117 CellPos getRightCell( const CellPos& rPos, bool bEdgeTravel ) const;
118 CellPos getUpCell( const CellPos& rPos, bool bEdgeTravel ) const;
119 CellPos getDownCell( const CellPos& rPos, bool bEdgeTravel ) const;
120 CellPos getPreviousCell( const CellPos& rPos, bool bEdgeTravel ) const;
121 CellPos getNextCell( const CellPos& rPos, bool bEdgeTravel ) const;
122 CellPos getPreviousRow( const CellPos& rPos, bool bEdgeTravel ) const;
123 CellPos getNextRow( const CellPos& rPos, bool bEdgeTravel ) const;
125 void createCell( sdr::table::CellRef& xCell );
127 const sdr::table::TableStyleSettings& getTableStyleSettings() const;
128 void setTableStyleSettings( const sdr::table::TableStyleSettings& rStyle );
130 TableHitKind CheckTableHit( const Point& rPos, sal_Int32& rnX, sal_Int32& rnY, const sal_uInt16 aTol = 0 ) const;
132 void uno_lock();
133 void uno_unlock();
135 /** The active table has the focus or is currently edited */
136 const sdr::table::CellRef& getActiveCell() const;
138 void setActiveCell( const sdr::table::CellPos& rPos );
139 void getActiveCellPos( sdr::table::CellPos& rPos ) const;
140 sal_Int32 getColumnCount() const;
141 void getCellBounds( const sdr::table::CellPos& rPos, ::tools::Rectangle& rCellRect );
143 const SfxItemSet& GetActiveCellItemSet() const;
144 void SetMergedItemSetAndBroadcastOnActiveCell(const SfxItemSet& rSet);
146 void setTableStyle( const css::uno::Reference< css::container::XIndexAccess >& xAutoFormatStyle );
147 const css::uno::Reference< css::container::XIndexAccess >& getTableStyle() const;
149 // Text stuff
151 /** Returns the currently active text */
152 virtual SdrText* getActiveText() const override;
154 /** Returns the nth available text */
155 virtual SdrText* getText( sal_Int32 nIndex ) const override;
157 /** Returns the number of texts available for this object */
158 virtual sal_Int32 getTextCount() const override;
160 /** Changes the current active text */
161 virtual void setActiveText( sal_Int32 nIndex ) override;
163 /** Returns the index of the text that contains the given point or -1 */
164 virtual sal_Int32 CheckTextHit(const Point& rPnt) const override;
166 // #i121917#
167 virtual bool HasText() const override;
169 bool IsTextEditActive() const { return (pEdtOutl != nullptr); }
170 bool IsTextEditActive( const sdr::table::CellPos& rPos );
172 /** Returns true only if we are in edit mode and the user actually changed anything */
173 virtual bool IsReallyEdited() const override;
175 /** At the same time, we set the text in the outliner (if applicable the EditOutliners')
176 * as well as the PaperSize
178 void TakeTextRect( const sdr::table::CellPos& rPos, SdrOutliner& rOutliner, ::tools::Rectangle& rTextRect, bool bNoEditText, ::tools::Rectangle* pAnchorRect=nullptr ) const;
179 virtual void TakeTextRect( SdrOutliner& rOutliner, tools::Rectangle& rTextRect, bool bNoEditText, tools::Rectangle* pAnchorRect, bool bLineWidth = true ) const override;
180 void TakeTextAnchorRect(const sdr::table::CellPos& rPos, ::tools::Rectangle& rAnchorRect ) const;
181 virtual void TakeTextAnchorRect(::tools::Rectangle& rAnchorRect) const override;
183 virtual bool IsAutoGrowHeight() const override;
184 virtual bool IsAutoGrowWidth() const override;
186 virtual bool IsFontwork() const override;
188 virtual void SetModel(SdrModel* pNewModel) override;
189 virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
190 virtual sal_uInt16 GetObjIdentifier() const override;
191 virtual void SetChanged() override;
193 virtual bool AdjustTextFrameWidthAndHeight(tools::Rectangle& rR, bool bHgt = true, bool bWdt = true) const override;
194 virtual bool AdjustTextFrameWidthAndHeight() override;
195 virtual OUString TakeObjNameSingul() const override;
196 virtual OUString TakeObjNamePlural() const override;
197 virtual SdrTableObj* Clone() const override;
198 SdrTableObj& operator=(const SdrTableObj& rObj);
199 virtual void RecalcSnapRect() override;
200 virtual const tools::Rectangle& GetSnapRect() const override;
201 virtual void NbcSetSnapRect(const tools::Rectangle& rRect) override;
203 virtual const tools::Rectangle& GetLogicRect() const override;
204 virtual void NbcSetLogicRect(const tools::Rectangle& rRect) override;
205 virtual void AdjustToMaxRect( const tools::Rectangle& rMaxRect, bool bShrinkOnly = false ) override;
207 virtual sal_uInt32 GetHdlCount() const override;
208 virtual SdrHdl* GetHdl(sal_uInt32 nHdlNum) const override;
209 virtual void AddToHdlList(SdrHdlList& rHdlList) const override;
211 // Special drag methods
212 virtual bool hasSpecialDrag() const override;
213 virtual bool beginSpecialDrag(SdrDragStat& rDrag) const override;
214 virtual bool applySpecialDrag(SdrDragStat& rDrag) override;
215 virtual basegfx::B2DPolyPolygon getSpecialDragPoly(const SdrDragStat& rDrag) const override;
217 virtual bool BegCreate(SdrDragStat& rStat) override;
218 virtual bool MovCreate(SdrDragStat& rStat) override;
219 virtual bool EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd) override;
220 virtual bool BckCreate(SdrDragStat& rStat) override;
221 virtual void BrkCreate(SdrDragStat& rStat) override;
222 virtual basegfx::B2DPolyPolygon TakeCreatePoly(const SdrDragStat& rDrag) const override;
223 virtual Pointer GetCreatePointer() const override;
225 virtual void NbcMove(const Size& rSiz) override;
226 virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) override;
228 virtual bool BegTextEdit(SdrOutliner& rOutl) override;
229 virtual void EndTextEdit(SdrOutliner& rOutl) override;
230 virtual void TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, tools::Rectangle* pViewInit, tools::Rectangle* pViewMin) const override;
231 void TakeTextEditArea(const sdr::table::CellPos& rPos, Size* pPaperMin, Size* pPaperMax, tools::Rectangle* pViewInit, tools::Rectangle* pViewMin) const;
232 virtual EEAnchorMode GetOutlinerViewAnchorMode() const override;
234 virtual void NbcSetOutlinerParaObject(OutlinerParaObject* pTextObject) override;
236 virtual OutlinerParaObject* GetOutlinerParaObject() const override;
238 virtual void NbcReformatText() override;
239 virtual void ReformatText() override;
241 virtual bool IsVerticalWriting() const override;
242 virtual void SetVerticalWriting(bool bVertical) override;
244 css::text::WritingMode GetWritingMode() const;
246 /// Add an undo action that should be on the undo stack after ending text edit.
247 void AddUndo(SdrUndoAction* pUndo);
249 /// Next time layouting would be done, skip it (to layout at the end of multiple actions).
250 void SetSkipChangeLayout(bool bSkipChangeLayout);
252 virtual void onEditOutlinerStatusEvent( EditStatus* pEditStatus ) override;
254 /** Hack for clipboard with calc and writer, export and import table content as rtf table */
255 static void ExportAsRTF( SvStream& rStrm, SdrTableObj& rObj );
256 static void ImportAsRTF( SvStream& rStrm, SdrTableObj& rObj );
258 virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const override;
260 private:
261 void init( sal_Int32 nColumns, sal_Int32 nRows );
263 protected:
264 virtual sdr::properties::BaseProperties* CreateObjectSpecificProperties() override;
265 virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() override;
267 virtual SdrObjGeoData* NewGeoData() const override;
268 virtual void SaveGeoData(SdrObjGeoData& rGeo) const override;
269 virtual void RestGeoData(const SdrObjGeoData& rGeo) override;
271 private:
272 SdrOutliner* GetCellTextEditOutliner( const sdr::table::Cell& rCell ) const;
274 private:
275 // For the ViewContactOfTableObj to build the primitive representation, it is necessary to access the
276 // TableLayouter for position and attribute information
277 friend class sdr::contact::ViewContactOfTableObj;
278 const TableLayouter& getTableLayouter() const;
280 tools::Rectangle maLogicRect;
281 private:
282 rtl::Reference<SdrTableObjImpl> mpImpl;
288 #endif
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */