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