1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
34 namespace sdr::contact
{
35 class ViewContactOfTableObj
;
38 namespace sdr::table
{
41 struct ImplTableShadowPaintInfo
;
46 typedef rtl::Reference
< Cell
> CellRef
;
51 enum class TableHitKind
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 TableStyleSettings
79 bool mbUseFirstColumn
;
82 bool mbUseColumnBanding
;
85 TableStyleSettings( const TableStyleSettings
& rStyle
);
86 TableStyleSettings
& operator=(const TableStyleSettings
& rStyle
);
88 bool operator==( const TableStyleSettings
& r
) const;
92 class SdrTableObjImpl
;
94 class SVXCORE_DLLPUBLIC SdrTableObj final
: public ::SdrTextObj
97 friend class SdrTableObjImpl
;
99 // protected destructor
100 virtual ~SdrTableObj() override
;
103 SdrTableObj(SdrModel
& rSdrModel
);
105 SdrTableObj(SdrModel
& rSdrModel
, SdrTableObj
const & rSource
);
108 const ::tools::Rectangle
& rNewRect
,
112 // helper to limit existing TableModel to a given selection
113 void CropTableModelToSelection(const CellPos
& rStart
, const CellPos
& rEnd
);
116 void DistributeColumns( sal_Int32 nFirstColumn
, sal_Int32 nLastColumn
, const bool bOptimize
, const bool bMinimize
);
117 void DistributeRows( sal_Int32 nFirstRow
, sal_Int32 nLastRow
, const bool bOptimize
, const bool bMinimize
);
119 css::uno::Reference
< css::table::XTable
> getTable() const;
120 /// Get the concrete UNO class for the table
121 const rtl::Reference
< sdr::table::TableModel
> & getUnoTable() const;
123 bool isValid( const sdr::table::CellPos
& rPos
) const;
124 static CellPos
getFirstCell();
125 CellPos
getLastCell() const;
126 CellPos
getLeftCell( const CellPos
& rPos
, bool bEdgeTravel
) const;
127 CellPos
getRightCell( const CellPos
& rPos
, bool bEdgeTravel
) const;
128 CellPos
getUpCell( const CellPos
& rPos
, bool bEdgeTravel
) const;
129 CellPos
getDownCell( const CellPos
& rPos
, bool bEdgeTravel
) const;
130 CellPos
getPreviousCell( const CellPos
& rPos
, bool bEdgeTravel
) const;
131 CellPos
getNextCell( const CellPos
& rPos
, bool bEdgeTravel
) const;
132 CellPos
getPreviousRow( const CellPos
& rPos
, bool bEdgeTravel
) const;
133 CellPos
getNextRow( const CellPos
& rPos
, bool bEdgeTravel
) const;
135 void createCell( sdr::table::CellRef
& xCell
);
137 const sdr::table::TableStyleSettings
& getTableStyleSettings() const;
138 void setTableStyleSettings( const sdr::table::TableStyleSettings
& rStyle
);
140 TableHitKind
CheckTableHit( const Point
& rPos
, sal_Int32
& rnX
, sal_Int32
& rnY
, const sal_uInt16 aTol
= 0 ) const;
145 /** The active table has the focus or is currently edited */
146 const sdr::table::CellRef
& getActiveCell() const;
148 void setActiveCell( const sdr::table::CellPos
& rPos
);
149 void getActiveCellPos( sdr::table::CellPos
& rPos
) const;
150 sal_Int32
getColumnCount() const;
151 sal_Int32
getRowCount() const;
153 bool createTableEdgesJson(boost::property_tree::ptree
& rJsonRoot
);
154 void changeEdge(bool bHorizontal
, int nEdge
, sal_Int32 nOffset
);
156 void getCellBounds( const sdr::table::CellPos
& rPos
, ::tools::Rectangle
& rCellRect
);
158 const SfxItemSet
& GetActiveCellItemSet() const;
160 void setTableStyle( const css::uno::Reference
< css::container::XIndexAccess
>& xAutoFormatStyle
);
161 const css::uno::Reference
< css::container::XIndexAccess
>& getTableStyle() const;
165 /** Returns the currently active text */
166 virtual SdrText
* getActiveText() const override
;
168 /** Returns the nth available text */
169 virtual SdrText
* getText( sal_Int32 nIndex
) const override
;
171 /** Returns the number of texts available for this object */
172 virtual sal_Int32
getTextCount() const override
;
174 /** Changes the current active text */
175 virtual void setActiveText( sal_Int32 nIndex
) override
;
177 /** Returns the index of the text that contains the given point or -1 */
178 virtual sal_Int32
CheckTextHit(const Point
& rPnt
) const override
;
181 virtual bool HasText() const override
;
183 bool IsTextEditActive() const { return mpEditingOutliner
!= nullptr; }
184 bool IsTextEditActive( const sdr::table::CellPos
& rPos
);
186 /** Returns true only if we are in edit mode and the user actually changed anything */
187 virtual bool IsReallyEdited() const override
;
189 /** At the same time, we set the text in the outliner (if applicable the EditOutliners')
190 * as well as the PaperSize
192 void TakeTextRect( const sdr::table::CellPos
& rPos
, SdrOutliner
& rOutliner
, ::tools::Rectangle
& rTextRect
, bool bNoEditText
, ::tools::Rectangle
* pAnchorRect
) const;
193 virtual void TakeTextRect( SdrOutliner
& rOutliner
, tools::Rectangle
& rTextRect
, bool bNoEditText
, tools::Rectangle
* pAnchorRect
, bool bLineWidth
= true ) const override
;
194 void TakeTextAnchorRect(const sdr::table::CellPos
& rPos
, ::tools::Rectangle
& rAnchorRect
) const;
195 virtual void TakeTextAnchorRect(::tools::Rectangle
& rAnchorRect
) const override
;
197 virtual bool IsAutoGrowHeight() const override
;
198 virtual bool IsAutoGrowWidth() const override
;
200 virtual bool IsFontwork() const override
;
202 virtual void TakeObjInfo(SdrObjTransformInfoRec
& rInfo
) const override
;
203 virtual SdrObjKind
GetObjIdentifier() const override
;
204 virtual void SetChanged() override
;
206 virtual bool AdjustTextFrameWidthAndHeight(tools::Rectangle
& rR
, bool bHgt
= true, bool bWdt
= true) const override
;
207 virtual bool AdjustTextFrameWidthAndHeight() override
;
208 virtual OUString
TakeObjNameSingul() const override
;
209 virtual OUString
TakeObjNamePlural() const override
;
210 virtual rtl::Reference
<SdrObject
> CloneSdrObject(SdrModel
& rTargetModel
) const override
;
211 virtual void RecalcSnapRect() override
;
212 virtual const tools::Rectangle
& GetSnapRect() const override
;
213 virtual void NbcSetSnapRect(const tools::Rectangle
& rRect
) override
;
215 virtual const tools::Rectangle
& GetLogicRect() const override
;
216 virtual void NbcSetLogicRect(const tools::Rectangle
& rRect
, bool bAdaptTextMinSize
= true) override
;
217 virtual void AdjustToMaxRect( const tools::Rectangle
& rMaxRect
, bool bShrinkOnly
= false ) override
;
219 virtual sal_uInt32
GetHdlCount() const override
;
220 virtual void AddToHdlList(SdrHdlList
& rHdlList
) const override
;
222 // Special drag methods
223 virtual bool hasSpecialDrag() const override
;
224 virtual bool beginSpecialDrag(SdrDragStat
& rDrag
) const override
;
225 virtual bool applySpecialDrag(SdrDragStat
& rDrag
) override
;
226 virtual basegfx::B2DPolyPolygon
getSpecialDragPoly(const SdrDragStat
& rDrag
) const override
;
228 virtual bool BegCreate(SdrDragStat
& rStat
) override
;
229 virtual bool MovCreate(SdrDragStat
& rStat
) override
;
230 virtual bool EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
) override
;
231 virtual bool BckCreate(SdrDragStat
& rStat
) override
;
232 virtual void BrkCreate(SdrDragStat
& rStat
) override
;
233 virtual basegfx::B2DPolyPolygon
TakeCreatePoly(const SdrDragStat
& rDrag
) const override
;
234 virtual PointerStyle
GetCreatePointer() const override
;
236 virtual void NbcMove(const Size
& rSiz
) override
;
237 virtual void NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
) override
;
239 virtual bool BegTextEdit(SdrOutliner
& rOutl
) override
;
240 virtual void EndTextEdit(SdrOutliner
& rOutl
) override
;
241 virtual void TakeTextEditArea(Size
* pPaperMin
, Size
* pPaperMax
, tools::Rectangle
* pViewInit
, tools::Rectangle
* pViewMin
) const override
;
242 void TakeTextEditArea(const sdr::table::CellPos
& rPos
, Size
* pPaperMin
, Size
* pPaperMax
, tools::Rectangle
* pViewInit
, tools::Rectangle
* pViewMin
) const;
243 virtual EEAnchorMode
GetOutlinerViewAnchorMode() const override
;
245 virtual void NbcSetOutlinerParaObject(std::optional
<OutlinerParaObject
> pTextObject
, bool bAdjustTextFrameWidthAndHeight
= true) override
;
247 virtual OutlinerParaObject
* GetOutlinerParaObject() const override
;
249 virtual void NbcReformatText() override
;
251 virtual bool IsVerticalWriting() const override
;
252 virtual void SetVerticalWriting(bool bVertical
) override
;
254 css::text::WritingMode
GetWritingMode() const;
256 /// Add an undo action that should be on the undo stack after ending text edit.
257 void AddUndo(SdrUndoAction
* pUndo
);
259 /// Next time layouting would be done, skip it (to layout at the end of multiple actions).
260 void SetSkipChangeLayout(bool bSkipChangeLayout
);
262 void LayoutTableHeight(tools::Rectangle
& rArea
);
264 virtual void onEditOutlinerStatusEvent( EditStatus
* pEditStatus
) override
;
266 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
268 const TableLayouter
& getTableLayouter() const;
271 void init( sal_Int32 nColumns
, sal_Int32 nRows
);
273 virtual std::unique_ptr
<sdr::properties::BaseProperties
> CreateObjectSpecificProperties() override
;
274 virtual std::unique_ptr
<sdr::contact::ViewContact
> CreateObjectSpecificViewContact() override
;
276 virtual std::unique_ptr
<SdrObjGeoData
> NewGeoData() const override
;
277 virtual void SaveGeoData(SdrObjGeoData
& rGeo
) const override
;
278 virtual void RestoreGeoData(const SdrObjGeoData
& rGeo
) override
;
280 SdrOutliner
* GetCellTextEditOutliner( const sdr::table::Cell
& rCell
) const;
282 tools::Rectangle maLogicRect
;
283 rtl::Reference
<SdrTableObjImpl
> mpImpl
;
286 /** Hack for clipboard with calc and writer, export and import table content as rtf table */
287 SVX_DLLPUBLIC
void ExportAsRTF( SvStream
& rStrm
, SdrTableObj
& rObj
);
288 SVX_DLLPUBLIC
void ImportAsRTF( SvStream
& rStrm
, SdrTableObj
& rObj
);
290 SVX_DLLPUBLIC
void ImportAsHTML( SvStream
& rStrm
, SdrTableObj
& rObj
);
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */