Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / editeng / boxitem.hxx
blob6ceff99268c3691e1c1d807e2e4fdad7e87010c5
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_EDITENG_BOXITEM_HXX
21 #define INCLUDED_EDITENG_BOXITEM_HXX
23 #include <svl/poolitem.hxx>
24 #include <editeng/editengdllapi.h>
25 #include <com/sun/star/table/BorderLine2.hpp>
26 #include <o3tl/typed_flags_set.hxx>
27 #include <docmodel/color/ComplexColor.hxx>
28 #include <memory>
29 #include <array>
32 namespace editeng { class SvxBorderLine; }
34 // class SvxBoxItem ------------------------------------------------------
36 /* [Description]
38 This item describes a border attribute
39 (all four edges and the inward distance)
41 enum class SvxBoxItemLine
43 TOP, BOTTOM, LEFT, RIGHT, LAST = RIGHT
46 /**
47 This version causes SvxBoxItem to store the 4 cell spacing distances separately
48 when serializing to stream.
50 constexpr sal_uInt16 BOX_4DISTS_VERSION = 1;
51 /**
52 This version causes SvxBoxItem to store the styles for its border lines when
53 serializing to stream.
55 constexpr sal_uInt16 BOX_BORDER_STYLE_VERSION = 2;
57 class EDITENG_DLLPUBLIC SvxBoxItem final : public SfxPoolItem
59 std::unique_ptr<editeng::SvxBorderLine> mpTopBorderLine;
60 std::unique_ptr<editeng::SvxBorderLine> mpBottomBorderLine;
61 std::unique_ptr<editeng::SvxBorderLine> mpLeftBorderLine;
62 std::unique_ptr<editeng::SvxBorderLine> mpRightBorderLine;
64 sal_Int16 mnTopDistance = 0;
65 sal_Int16 mnBottomDistance = 0;
66 sal_Int16 mnLeftDistance = 0;
67 sal_Int16 mnRightDistance = 0;
69 // Store complex colors until lines are created...
70 std::array<model::ComplexColor, 4> maTempComplexColors;
72 bool mbRemoveAdjCellBorder = false;
74 void tryMigrateComplexColor(SvxBoxItemLine eLine);
76 public:
77 static SfxPoolItem* CreateDefault();
79 explicit SvxBoxItem( const sal_uInt16 nId );
80 SvxBoxItem( const SvxBoxItem &rCpy );
81 virtual ~SvxBoxItem() override;
83 // "pure virtual Methods" from SfxPoolItem
84 virtual bool operator==( const SfxPoolItem& ) const override;
85 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
86 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
88 virtual bool GetPresentation( SfxItemPresentation ePres,
89 MapUnit eCoreMetric,
90 MapUnit ePresMetric,
91 OUString &rText, const IntlWrapper& ) const override;
93 virtual SvxBoxItem* Clone( SfxItemPool *pPool = nullptr ) const override;
95 virtual void ScaleMetrics( tools::Long nMult, tools::Long nDiv ) override;
96 virtual bool HasMetrics() const override;
98 const editeng::SvxBorderLine* GetTop() const
100 return mpTopBorderLine.get();
102 const editeng::SvxBorderLine* GetBottom() const
104 return mpBottomBorderLine.get();
106 const editeng::SvxBorderLine* GetLeft() const
108 return mpLeftBorderLine.get();
110 const editeng::SvxBorderLine* GetRight() const
112 return mpRightBorderLine.get();
115 editeng::SvxBorderLine* GetTop()
117 return mpTopBorderLine.get();
119 editeng::SvxBorderLine* GetBottom()
121 return mpBottomBorderLine.get();
123 editeng::SvxBorderLine* GetLeft()
125 return mpLeftBorderLine.get();
127 editeng::SvxBorderLine* GetRight()
129 return mpRightBorderLine.get();
132 const editeng::SvxBorderLine* GetLine( SvxBoxItemLine nLine ) const;
134 //The Pointers are being copied!
135 void SetLine( const editeng::SvxBorderLine* pNew, SvxBoxItemLine nLine );
137 sal_Int16 GetDistance( SvxBoxItemLine nLine, bool bAllowNegative = false ) const;
138 sal_uInt16 GetSmallestDistance() const;
140 bool IsRemoveAdjacentCellBorder() const { return mbRemoveAdjCellBorder; }
142 void SetDistance( sal_Int16 nNew, SvxBoxItemLine nLine );
143 void SetAllDistances(sal_Int16 nNew)
145 mnTopDistance = mnBottomDistance = mnLeftDistance = mnRightDistance = nNew;
148 void SetRemoveAdjacentCellBorder( bool bSet ) { mbRemoveAdjCellBorder = bSet; }
150 // Line width plus Space plus inward distance
151 // bEvenIfNoLine = TRUE -> Also return distance, when no Line is set
152 sal_uInt16 CalcLineWidth( SvxBoxItemLine nLine ) const;
153 sal_Int16 CalcLineSpace( SvxBoxItemLine nLine, bool bEvenIfNoLine = false, bool bAllowNegative = false ) const;
154 bool HasBorder( bool bTreatPaddingAsBorder ) const;
155 static css::table::BorderLine2 SvxLineToLine( const editeng::SvxBorderLine* pLine, bool bConvert );
156 static bool LineToSvxLine(const css::table::BorderLine& rLine, editeng::SvxBorderLine& rSvxLine, bool bConvert);
157 static bool LineToSvxLine(const css::table::BorderLine2& rLine, editeng::SvxBorderLine& rSvxLine, bool bConvert);
159 virtual boost::property_tree::ptree dumpAsJSON() const override;
160 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
163 // class SvxBoxInfoItem --------------------------------------------------
165 /* [Description]
167 Another item for the border. This item has only limited functionality.
168 On one hand, the general Dialog is told by the item which options it
169 should offer. On the other hand, this attribute may be used to
170 transported the borderline for the inner horizontal and vertical lines.
173 enum class SvxBoxInfoItemLine
175 HORI, VERT, LAST = VERT
178 enum class SvxBoxInfoItemValidFlags
180 NONE = 0x00,
181 TOP = 0x01,
182 BOTTOM = 0x02,
183 LEFT = 0x04,
184 RIGHT = 0x08,
185 HORI = 0x10,
186 VERT = 0x20,
187 DISTANCE = 0x40,
188 DISABLE = 0x80,
189 ALL = 0xff
191 namespace o3tl
193 template<> struct typed_flags<SvxBoxInfoItemValidFlags> : is_typed_flags<SvxBoxInfoItemValidFlags, 0xff> {};
196 class EDITENG_DLLPUBLIC SvxBoxInfoItem final : public SfxPoolItem
198 std::unique_ptr<editeng::SvxBorderLine> mpHorizontalLine; //inner horizontal Line
199 std::unique_ptr<editeng::SvxBorderLine> mpVerticalLine; //inner vertical Line
201 bool mbEnableHorizontalLine = false; /// true = Enable inner horizontal line.
202 bool mbEnableVerticalLine = false; /// true = Enable inner vertical line.
205 Currently only for StarWriter: distance inward from SvxBoxItem. If the
206 distance is requested, then the field for the distance from the dialog be
207 activated. nDefDist is regarded as a default value. If any line is
208 turned on or will be turned on it must this distance be set to default.
209 bMinDist indicates whether the user can go below this value or not.
210 With NDIST is the current distance from the app transported back and
211 forth to the dialogue.
214 bool mbDistance :1; // TRUE, Unlock Distance.
215 bool mbMinimumDistance :1; // TRUE, Going below minimum Distance is prohibited
217 SvxBoxInfoItemValidFlags mnValidFlags;
218 sal_uInt16 mnDefaultMinimumDistance = 0; // The default or minimum distance.
220 public:
221 static SfxPoolItem* CreateDefault();
223 explicit SvxBoxInfoItem( const sal_uInt16 nId );
224 SvxBoxInfoItem( const SvxBoxInfoItem &rCpy );
225 virtual ~SvxBoxInfoItem() override;
227 // "pure virtual Methods" from SfxPoolItem
228 virtual bool operator==( const SfxPoolItem& ) const override;
229 virtual bool GetPresentation( SfxItemPresentation ePres,
230 MapUnit eCoreMetric,
231 MapUnit ePresMetric,
232 OUString &rText, const IntlWrapper& ) const override;
233 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
234 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
236 virtual SvxBoxInfoItem* Clone( SfxItemPool *pPool = nullptr ) const override;
237 virtual void ScaleMetrics( tools::Long nMult, tools::Long nDiv ) override;
238 virtual bool HasMetrics() const override;
240 const editeng::SvxBorderLine* GetHori() const { return mpHorizontalLine.get(); }
241 const editeng::SvxBorderLine* GetVert() const { return mpVerticalLine.get(); }
243 //The Pointers are being copied!
244 void SetLine( const editeng::SvxBorderLine* pNew, SvxBoxInfoItemLine nLine );
246 bool IsTable() const { return mbEnableHorizontalLine && mbEnableVerticalLine; }
247 void SetTable(bool bNew) { mbEnableHorizontalLine = mbEnableVerticalLine = bNew; }
249 bool IsHorEnabled() const { return mbEnableHorizontalLine; }
250 void EnableHor( bool bEnable ) { mbEnableHorizontalLine = bEnable; }
251 bool IsVerEnabled() const { return mbEnableVerticalLine; }
252 void EnableVer( bool bEnable ) { mbEnableVerticalLine = bEnable; }
254 bool IsDist() const { return mbDistance; }
255 void SetDist(bool bNew)
257 mbDistance = bNew;
259 bool IsMinDist() const { return mbMinimumDistance; }
260 void SetMinDist(bool bNew) { mbMinimumDistance = bNew; }
261 sal_uInt16 GetDefDist() const { return mnDefaultMinimumDistance; }
262 void SetDefDist(sal_uInt16 nNew) { mnDefaultMinimumDistance = nNew; }
264 bool IsValid( SvxBoxInfoItemValidFlags nValid ) const
266 return bool(mnValidFlags & nValid);
268 void SetValid(SvxBoxInfoItemValidFlags nValid, bool bValid = true)
270 if (bValid)
271 mnValidFlags |= nValid;
272 else
273 mnValidFlags &= ~nValid;
275 void ResetFlags();
277 virtual boost::property_tree::ptree dumpAsJSON() const override;
280 namespace editeng
283 void EDITENG_DLLPUBLIC BorderDistanceFromWord(bool bFromEdge, sal_Int32& nMargin,
284 sal_Int32& nBorderDistance, sal_Int32 nBorderWidth);
286 struct EDITENG_DLLPUBLIC WordPageMargins final
288 sal_uInt16 nLeft = 0;
289 sal_uInt16 nRight = 0;
290 sal_uInt16 nTop = 0;
291 sal_uInt16 nBottom = 0;
294 struct EDITENG_DLLPUBLIC WordBorderDistances final
296 bool bFromEdge = false;
297 sal_uInt16 nLeft = 0;
298 sal_uInt16 nRight = 0;
299 sal_uInt16 nTop = 0;
300 sal_uInt16 nBottom = 0;
303 // Heuristics to decide if we need to use "from edge" offset of borders. All sizes in twips
304 void EDITENG_DLLPUBLIC BorderDistancesToWord(const SvxBoxItem& rBox, const WordPageMargins& rMargins,
305 WordBorderDistances& rDistances);
309 #endif
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */