/src/libreoffice/include/svx/svdotable.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <com/sun/star/text/WritingMode.hpp> |
23 | | #include <com/sun/star/container/XIndexAccess.hpp> |
24 | | #include <com/sun/star/table/XTable.hpp> |
25 | | #include <rtl/ref.hxx> |
26 | | #include <svx/svdotext.hxx> |
27 | | #include <svx/svxdllapi.h> |
28 | | #include <boost/property_tree/ptree_fwd.hpp> |
29 | | |
30 | | class SvStream; |
31 | | class SdrUndoAction; |
32 | | |
33 | | namespace sdr::table { |
34 | | |
35 | | class TableLayouter; |
36 | | class TableModel; |
37 | | |
38 | | #ifndef CellRef |
39 | | class Cell; |
40 | | typedef rtl::Reference< Cell > CellRef; |
41 | | #endif |
42 | | |
43 | | |
44 | | /// SdrTableHitKind |
45 | | enum class TableHitKind |
46 | | { |
47 | | NONE, |
48 | | Cell, |
49 | | CellTextArea, |
50 | | HorizontalBorder, |
51 | | VerticallBorder |
52 | | }; |
53 | | |
54 | | |
55 | | struct CellPos |
56 | | { |
57 | | sal_Int32 mnCol; |
58 | | sal_Int32 mnRow; |
59 | | |
60 | 19.4k | CellPos() : mnCol( 0 ), mnRow( 0 ) {} |
61 | 35.9k | CellPos( sal_Int32 nCol, sal_Int32 nRow ) { mnCol = nCol; mnRow = nRow; } |
62 | | |
63 | 2.41k | bool operator==( const CellPos& r ) const { return (r.mnCol == mnCol) && (r.mnRow == mnRow); } |
64 | 0 | bool operator!=( const CellPos& r ) const { return (r.mnCol != mnCol) || (r.mnRow != mnRow); } |
65 | | }; |
66 | | |
67 | | |
68 | | /// TableStyleSettings |
69 | | struct TableStyleSettings |
70 | | { |
71 | | bool mbUseFirstRow; |
72 | | bool mbUseLastRow; |
73 | | bool mbUseFirstColumn; |
74 | | bool mbUseLastColumn; |
75 | | bool mbUseRowBanding; |
76 | | bool mbUseColumnBanding; |
77 | | |
78 | | TableStyleSettings(); |
79 | | TableStyleSettings( const TableStyleSettings& rStyle ); |
80 | | TableStyleSettings& operator=(const TableStyleSettings& rStyle); |
81 | | |
82 | | bool operator==( const TableStyleSettings& r ) const; |
83 | | }; |
84 | | |
85 | | /// SdrTableObj |
86 | | class SdrTableObjImpl; |
87 | | |
88 | | class SVXCORE_DLLPUBLIC SdrTableObj final : public ::SdrTextObj |
89 | | { |
90 | | friend class Cell; |
91 | | friend class SdrTableObjImpl; |
92 | | |
93 | | // protected destructor |
94 | | virtual ~SdrTableObj() override; |
95 | | |
96 | | public: |
97 | | SdrTableObj(SdrModel& rSdrModel); |
98 | | // Copy constructor |
99 | | SdrTableObj(SdrModel& rSdrModel, SdrTableObj const & rSource); |
100 | | SdrTableObj( |
101 | | SdrModel& rSdrModel, |
102 | | const ::tools::Rectangle& rNewRect, |
103 | | sal_Int32 nColumns, |
104 | | sal_Int32 nRows); |
105 | | |
106 | | // helper to limit existing TableModel to a given selection |
107 | | void CropTableModelToSelection(const CellPos& rStart, const CellPos& rEnd); |
108 | | |
109 | | // Table stuff |
110 | | void DistributeColumns( sal_Int32 nFirstColumn, sal_Int32 nLastColumn, const bool bOptimize, const bool bMinimize ); |
111 | | void DistributeRows( sal_Int32 nFirstRow, sal_Int32 nLastRow, const bool bOptimize, const bool bMinimize ); |
112 | | |
113 | | css::uno::Reference< css::table::XTable > getTable() const; |
114 | | /// Get the concrete UNO class for the table |
115 | | const rtl::Reference< sdr::table::TableModel > & getUnoTable() const; |
116 | | |
117 | | bool isValid( const sdr::table::CellPos& rPos ) const; |
118 | | static CellPos getFirstCell(); |
119 | | CellPos getLastCell() const; |
120 | | CellPos getLeftCell( const CellPos& rPos, bool bEdgeTravel ) const; |
121 | | CellPos getRightCell( const CellPos& rPos, bool bEdgeTravel ) const; |
122 | | CellPos getUpCell( const CellPos& rPos, bool bEdgeTravel ) const; |
123 | | CellPos getDownCell( const CellPos& rPos, bool bEdgeTravel ) const; |
124 | | CellPos getPreviousCell( const CellPos& rPos, bool bEdgeTravel ) const; |
125 | | CellPos getNextCell( const CellPos& rPos, bool bEdgeTravel ) const; |
126 | | CellPos getPreviousRow( const CellPos& rPos, bool bEdgeTravel ) const; |
127 | | CellPos getNextRow( const CellPos& rPos, bool bEdgeTravel ) const; |
128 | | |
129 | | void createCell( sdr::table::CellRef& xCell ); |
130 | | |
131 | | const sdr::table::TableStyleSettings& getTableStyleSettings() const; |
132 | | void setTableStyleSettings( const sdr::table::TableStyleSettings& rStyle ); |
133 | | |
134 | | TableHitKind CheckTableHit( const Point& rPos, sal_Int32& rnX, sal_Int32& rnY, const sal_uInt16 aTol = 0 ) const; |
135 | | |
136 | | void uno_lock(); |
137 | | void uno_unlock(); |
138 | | |
139 | | /** The active table has the focus or is currently edited */ |
140 | | const sdr::table::CellRef& getActiveCell() const; |
141 | | |
142 | | void setActiveCell( const sdr::table::CellPos& rPos ); |
143 | | void getActiveCellPos( sdr::table::CellPos& rPos ) const; |
144 | | sal_Int32 getColumnCount() const; |
145 | | sal_Int32 getRowCount() const; |
146 | | |
147 | | bool createTableEdgesJson(boost::property_tree::ptree & rJsonRoot); |
148 | | void changeEdge(bool bHorizontal, int nEdge, sal_Int32 nOffset); |
149 | | |
150 | | void getCellBounds( const sdr::table::CellPos& rPos, ::tools::Rectangle& rCellRect ); |
151 | | |
152 | | const SfxItemSet& GetActiveCellItemSet() const; |
153 | | |
154 | | void setTableStyle( const css::uno::Reference< css::container::XIndexAccess >& xAutoFormatStyle ); |
155 | | const css::uno::Reference< css::container::XIndexAccess >& getTableStyle() const; |
156 | | |
157 | | // Text stuff |
158 | | |
159 | | /** Returns the currently active text */ |
160 | | virtual SdrText* getActiveText() const override; |
161 | | |
162 | | /** Returns the nth available text */ |
163 | | virtual SdrText* getText( sal_Int32 nIndex ) const override; |
164 | | |
165 | | /** Returns the number of texts available for this object */ |
166 | | virtual sal_Int32 getTextCount() const override; |
167 | | |
168 | | /** Changes the current active text */ |
169 | | virtual void setActiveText( sal_Int32 nIndex ) override; |
170 | | |
171 | | /** Returns the index of the text that contains the given point or -1 */ |
172 | | virtual sal_Int32 CheckTextHit(const Point& rPnt) const override; |
173 | | |
174 | | // #i121917# |
175 | | virtual bool HasText() const override; |
176 | | |
177 | 0 | bool IsTextEditActive() const { return mpEditingOutliner != nullptr; } |
178 | | bool IsTextEditActive( const sdr::table::CellPos& rPos ); |
179 | | |
180 | | /** Returns true only if we are in edit mode and the user actually changed anything */ |
181 | | virtual bool IsReallyEdited() const override; |
182 | | |
183 | | /** At the same time, we set the text in the outliner (if applicable the EditOutliners') |
184 | | * as well as the PaperSize |
185 | | */ |
186 | | void TakeTextRect( const sdr::table::CellPos& rPos, SdrOutliner& rOutliner, ::tools::Rectangle& rTextRect, bool bNoEditText, ::tools::Rectangle* pAnchorRect ) const; |
187 | | virtual void TakeTextRect( SdrOutliner& rOutliner, tools::Rectangle& rTextRect, bool bNoEditText, tools::Rectangle* pAnchorRect, bool bLineWidth = true ) const override; |
188 | | void TakeTextAnchorRect(const sdr::table::CellPos& rPos, ::tools::Rectangle& rAnchorRect ) const; |
189 | | virtual void TakeTextAnchorRect(::tools::Rectangle& rAnchorRect) const override; |
190 | | |
191 | | virtual bool IsAutoGrowHeight() const override; |
192 | | virtual bool IsAutoGrowWidth() const override; |
193 | | |
194 | | virtual bool IsFontwork() const override; |
195 | | |
196 | | virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override; |
197 | | virtual SdrObjKind GetObjIdentifier() const override; |
198 | | virtual void SetChanged() override; |
199 | | |
200 | | virtual bool AdjustTextFrameWidthAndHeight(tools::Rectangle& rR, bool bHgt = true, bool bWdt = true) const override; |
201 | | virtual bool AdjustTextFrameWidthAndHeight() override; |
202 | | virtual OUString TakeObjNameSingul() const override; |
203 | | virtual OUString TakeObjNamePlural() const override; |
204 | | virtual rtl::Reference<SdrObject> CloneSdrObject(SdrModel& rTargetModel) const override; |
205 | | virtual void RecalcSnapRect() override; |
206 | | virtual const tools::Rectangle& GetSnapRect() const override; |
207 | | virtual void NbcSetSnapRect(const tools::Rectangle& rRect) override; |
208 | | |
209 | | virtual const tools::Rectangle& GetLogicRect() const override; |
210 | | virtual void NbcSetLogicRect(const tools::Rectangle& rRect, bool bAdaptTextMinSize = true) override; |
211 | | virtual void AdjustToMaxRect( const tools::Rectangle& rMaxRect, bool bShrinkOnly = false ) override; |
212 | | |
213 | | virtual sal_uInt32 GetHdlCount() const override; |
214 | | virtual void AddToHdlList(SdrHdlList& rHdlList) const override; |
215 | | |
216 | | // Special drag methods |
217 | | virtual bool hasSpecialDrag() const override; |
218 | | virtual bool beginSpecialDrag(SdrDragStat& rDrag) const override; |
219 | | virtual bool applySpecialDrag(SdrDragStat& rDrag) override; |
220 | | virtual basegfx::B2DPolyPolygon getSpecialDragPoly(const SdrDragStat& rDrag) const override; |
221 | | |
222 | | virtual bool BegCreate(SdrDragStat& rStat) override; |
223 | | virtual bool MovCreate(SdrDragStat& rStat) override; |
224 | | virtual bool EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd) override; |
225 | | virtual bool BckCreate(SdrDragStat& rStat) override; |
226 | | virtual void BrkCreate(SdrDragStat& rStat) override; |
227 | | virtual basegfx::B2DPolyPolygon TakeCreatePoly(const SdrDragStat& rDrag) const override; |
228 | | virtual PointerStyle GetCreatePointer() const override; |
229 | | |
230 | | virtual void NbcMove(const Size& rSiz) override; |
231 | | virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) override; |
232 | | |
233 | | virtual bool BegTextEdit(SdrOutliner& rOutl) override; |
234 | | virtual void EndTextEdit(SdrOutliner& rOutl) override; |
235 | | virtual void TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, tools::Rectangle* pViewInit, tools::Rectangle* pViewMin) const override; |
236 | | void TakeTextEditArea(const sdr::table::CellPos& rPos, Size* pPaperMin, Size* pPaperMax, tools::Rectangle* pViewInit, tools::Rectangle* pViewMin) const; |
237 | | virtual EEAnchorMode GetOutlinerViewAnchorMode() const override; |
238 | | |
239 | | virtual void NbcSetOutlinerParaObject(std::optional<OutlinerParaObject> pTextObject, bool bAdjustTextFrameWidthAndHeight = true) override; |
240 | | |
241 | | virtual OutlinerParaObject* GetOutlinerParaObject() const override; |
242 | | |
243 | | virtual void NbcReformatText() override; |
244 | | |
245 | | virtual bool IsVerticalWriting() const override; |
246 | | virtual void SetVerticalWriting(bool bVertical) override; |
247 | | |
248 | | css::text::WritingMode GetWritingMode() const; |
249 | | |
250 | | /// Add an undo action that should be on the undo stack after ending text edit. |
251 | | void AddUndo(SdrUndoAction* pUndo); |
252 | | |
253 | | /// Next time layouting would be done, skip it (to layout at the end of multiple actions). |
254 | | void SetSkipChangeLayout(bool bSkipChangeLayout); |
255 | | |
256 | | void LayoutTableHeight(tools::Rectangle& rArea); |
257 | | |
258 | | virtual void onEditOutlinerStatusEvent( EditStatus* pEditStatus ) override; |
259 | | |
260 | | virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override; |
261 | | |
262 | | const TableLayouter& getTableLayouter() const; |
263 | | |
264 | | private: |
265 | | void init( sal_Int32 nColumns, sal_Int32 nRows ); |
266 | | |
267 | | virtual std::unique_ptr<sdr::properties::BaseProperties> CreateObjectSpecificProperties() override; |
268 | | virtual std::unique_ptr<sdr::contact::ViewContact> CreateObjectSpecificViewContact() override; |
269 | | |
270 | | virtual std::unique_ptr<SdrObjGeoData> NewGeoData() const override; |
271 | | virtual void SaveGeoData(SdrObjGeoData& rGeo) const override; |
272 | | virtual void RestoreGeoData(const SdrObjGeoData& rGeo) override; |
273 | | |
274 | | SdrOutliner* GetCellTextEditOutliner( const sdr::table::Cell& rCell ) const; |
275 | | |
276 | | tools::Rectangle maLogicRect; |
277 | | rtl::Reference<SdrTableObjImpl> mpImpl; |
278 | | }; |
279 | | |
280 | | /** Hack for clipboard with calc and writer, export and import table content as rtf table */ |
281 | | SVX_DLLPUBLIC void ExportAsRTF( SvStream& rStrm, SdrTableObj& rObj ); |
282 | | SVX_DLLPUBLIC void ImportAsRTF( SvStream& rStrm, SdrTableObj& rObj ); |
283 | | |
284 | | SVX_DLLPUBLIC void ImportAsHTML( SvStream& rStrm, SdrTableObj& rObj ); |
285 | | |
286 | | } |
287 | | |
288 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |