LibreOffice Module editeng (master) 1
boxitem.hxx
Go to the documentation of this file.
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_EDITENG_BOXITEM_HXX
21#define INCLUDED_EDITENG_BOXITEM_HXX
22
23#include <svl/poolitem.hxx>
25#include <com/sun/star/table/BorderLine2.hpp>
28#include <memory>
29#include <array>
30
31
32namespace editeng { class SvxBorderLine; }
33
34// class SvxBoxItem ------------------------------------------------------
35
36/* [Description]
37
38 This item describes a border attribute
39 (all four edges and the inward distance)
40*/
42{
44};
45
50constexpr sal_uInt16 BOX_4DISTS_VERSION = 1;
55constexpr sal_uInt16 BOX_BORDER_STYLE_VERSION = 2;
56
58{
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;
63
64 sal_Int16 mnTopDistance = 0;
65 sal_Int16 mnBottomDistance = 0;
66 sal_Int16 mnLeftDistance = 0;
67 sal_Int16 mnRightDistance = 0;
68
69 // Store complex colors until lines are created...
70 std::array<model::ComplexColor, 4> maTempComplexColors;
71
72 bool mbRemoveAdjCellBorder = false;
73
74 void tryMigrateComplexColor(SvxBoxItemLine eLine);
75
76public:
77 static SfxPoolItem* CreateDefault();
78
79 explicit SvxBoxItem( const sal_uInt16 nId );
80 SvxBoxItem( const SvxBoxItem &rCpy );
81 virtual ~SvxBoxItem() override;
82
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;
87
88 virtual bool GetPresentation( SfxItemPresentation ePres,
89 MapUnit eCoreMetric,
90 MapUnit ePresMetric,
91 OUString &rText, const IntlWrapper& ) const override;
92
93 virtual SvxBoxItem* Clone( SfxItemPool *pPool = nullptr ) const override;
94
95 virtual void ScaleMetrics( tools::Long nMult, tools::Long nDiv ) override;
96 virtual bool HasMetrics() const override;
97
99 {
100 return mpTopBorderLine.get();
101 }
103 {
104 return mpBottomBorderLine.get();
105 }
107 {
108 return mpLeftBorderLine.get();
109 }
111 {
112 return mpRightBorderLine.get();
113 }
114
116 {
117 return mpTopBorderLine.get();
118 }
120 {
121 return mpBottomBorderLine.get();
122 }
124 {
125 return mpLeftBorderLine.get();
126 }
128 {
129 return mpRightBorderLine.get();
130 }
131
132 const editeng::SvxBorderLine* GetLine( SvxBoxItemLine nLine ) const;
133
134 //The Pointers are being copied!
135 void SetLine( const editeng::SvxBorderLine* pNew, SvxBoxItemLine nLine );
136
137 sal_Int16 GetDistance( SvxBoxItemLine nLine, bool bAllowNegative = false ) const;
138 sal_uInt16 GetSmallestDistance() const;
139
140 bool IsRemoveAdjacentCellBorder() const { return mbRemoveAdjCellBorder; }
141
142 void SetDistance( sal_Int16 nNew, SvxBoxItemLine nLine );
143 void SetAllDistances(sal_Int16 nNew)
144 {
145 mnTopDistance = mnBottomDistance = mnLeftDistance = mnRightDistance = nNew;
146 }
147
148 void SetRemoveAdjacentCellBorder( bool bSet ) { mbRemoveAdjCellBorder = bSet; }
149
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);
158
159 virtual boost::property_tree::ptree dumpAsJSON() const override;
160 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
161};
162
163// class SvxBoxInfoItem --------------------------------------------------
164
165/* [Description]
166
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.
171*/
172
174{
175 HORI, VERT, LAST = VERT
176};
177
179{
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
190};
191namespace o3tl
192{
193 template<> struct typed_flags<SvxBoxInfoItemValidFlags> : is_typed_flags<SvxBoxInfoItemValidFlags, 0xff> {};
194}
195
197{
198 std::unique_ptr<editeng::SvxBorderLine> mpHorizontalLine; //inner horizontal Line
199 std::unique_ptr<editeng::SvxBorderLine> mpVerticalLine; //inner vertical Line
200
201 bool mbEnableHorizontalLine = false;
202 bool mbEnableVerticalLine = false;
203
204 /*
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.
212 */
213
214 bool mbDistance :1; // TRUE, Unlock Distance.
215 bool mbMinimumDistance :1; // TRUE, Going below minimum Distance is prohibited
216
218 sal_uInt16 mnDefaultMinimumDistance = 0; // The default or minimum distance.
219
220public:
221 static SfxPoolItem* CreateDefault();
222
223 explicit SvxBoxInfoItem( const sal_uInt16 nId );
224 SvxBoxInfoItem( const SvxBoxInfoItem &rCpy );
225 virtual ~SvxBoxInfoItem() override;
226
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;
235
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;
239
240 const editeng::SvxBorderLine* GetHori() const { return mpHorizontalLine.get(); }
241 const editeng::SvxBorderLine* GetVert() const { return mpVerticalLine.get(); }
242
243 //The Pointers are being copied!
244 void SetLine( const editeng::SvxBorderLine* pNew, SvxBoxInfoItemLine nLine );
245
246 bool IsTable() const { return mbEnableHorizontalLine && mbEnableVerticalLine; }
247 void SetTable(bool bNew) { mbEnableHorizontalLine = mbEnableVerticalLine = bNew; }
248
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; }
253
254 bool IsDist() const { return mbDistance; }
255 void SetDist(bool bNew)
256 {
257 mbDistance = bNew;
258 }
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; }
263
265 {
266 return bool(mnValidFlags & nValid);
267 }
268 void SetValid(SvxBoxInfoItemValidFlags nValid, bool bValid = true)
269 {
270 if (bValid)
271 mnValidFlags |= nValid;
272 else
273 mnValidFlags &= ~nValid;
274 }
275 void ResetFlags();
276
277 virtual boost::property_tree::ptree dumpAsJSON() const override;
278};
279
280namespace editeng
281{
282
283void EDITENG_DLLPUBLIC BorderDistanceFromWord(bool bFromEdge, sal_Int32& nMargin,
284 sal_Int32& nBorderDistance, sal_Int32 nBorderWidth);
285
287{
288 sal_uInt16 nLeft = 0;
289 sal_uInt16 nRight = 0;
290 sal_uInt16 nTop = 0;
291 sal_uInt16 nBottom = 0;
292};
293
295{
296 bool bFromEdge = false;
297 sal_uInt16 nLeft = 0;
298 sal_uInt16 nRight = 0;
299 sal_uInt16 nTop = 0;
300 sal_uInt16 nBottom = 0;
301};
302
303// Heuristics to decide if we need to use "from edge" offset of borders. All sizes in twips
304void EDITENG_DLLPUBLIC BorderDistancesToWord(const SvxBoxItem& rBox, const WordPageMargins& rMargins,
305 WordBorderDistances& rDistances);
306
307}
308
309#endif
310
311/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt16 BOX_BORDER_STYLE_VERSION
This version causes SvxBoxItem to store the styles for its border lines when serializing to stream.
Definition: boxitem.hxx:55
SvxBoxInfoItemValidFlags
Definition: boxitem.hxx:179
SvxBoxItemLine
Definition: boxitem.hxx:42
SvxBoxInfoItemLine
Definition: boxitem.hxx:174
constexpr sal_uInt16 BOX_4DISTS_VERSION
This version causes SvxBoxItem to store the 4 cell spacing distances separately when serializing to s...
Definition: boxitem.hxx:50
virtual void ScaleMetrics(tools::Long lMult, tools::Long lDiv)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const
virtual bool GetPresentation(SfxItemPresentation ePresentation, MapUnit eCoreMetric, MapUnit ePresentationMetric, OUString &rText, const IntlWrapper &rIntlWrapper) const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
virtual bool operator==(const SfxPoolItem &) const=0
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId)
virtual boost::property_tree::ptree dumpAsJSON() const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
virtual bool HasMetrics() const
bool IsTable() const
Definition: boxitem.hxx:246
SvxBoxInfoItemValidFlags mnValidFlags
Definition: boxitem.hxx:217
void SetTable(bool bNew)
Definition: boxitem.hxx:247
bool mbDistance
true = Enable inner vertical line.
Definition: boxitem.hxx:214
bool IsMinDist() const
Definition: boxitem.hxx:259
bool IsDist() const
Definition: boxitem.hxx:254
std::unique_ptr< editeng::SvxBorderLine > mpVerticalLine
Definition: boxitem.hxx:199
bool IsValid(SvxBoxInfoItemValidFlags nValid) const
Definition: boxitem.hxx:264
bool IsHorEnabled() const
Definition: boxitem.hxx:249
void EnableVer(bool bEnable)
Definition: boxitem.hxx:252
void SetDist(bool bNew)
Definition: boxitem.hxx:255
void SetMinDist(bool bNew)
Definition: boxitem.hxx:260
void SetDefDist(sal_uInt16 nNew)
Definition: boxitem.hxx:262
std::unique_ptr< editeng::SvxBorderLine > mpHorizontalLine
Definition: boxitem.hxx:198
const editeng::SvxBorderLine * GetHori() const
Definition: boxitem.hxx:240
sal_uInt16 GetDefDist() const
Definition: boxitem.hxx:261
bool IsVerEnabled() const
Definition: boxitem.hxx:251
const editeng::SvxBorderLine * GetVert() const
Definition: boxitem.hxx:241
void EnableHor(bool bEnable)
Definition: boxitem.hxx:250
void SetValid(SvxBoxInfoItemValidFlags nValid, bool bValid=true)
Definition: boxitem.hxx:268
bool mbMinimumDistance
Definition: boxitem.hxx:215
void SetRemoveAdjacentCellBorder(bool bSet)
Definition: boxitem.hxx:148
static bool LineToSvxLine(const css::table::BorderLine &rLine, editeng::SvxBorderLine &rSvxLine, bool bConvert)
const editeng::SvxBorderLine * GetTop() const
Definition: boxitem.hxx:98
editeng::SvxBorderLine * GetRight()
Definition: boxitem.hxx:127
bool IsRemoveAdjacentCellBorder() const
Definition: boxitem.hxx:140
std::unique_ptr< editeng::SvxBorderLine > mpBottomBorderLine
Definition: boxitem.hxx:60
const editeng::SvxBorderLine * GetRight() const
Definition: boxitem.hxx:110
std::unique_ptr< editeng::SvxBorderLine > mpTopBorderLine
Definition: boxitem.hxx:59
editeng::SvxBorderLine * GetLeft()
Definition: boxitem.hxx:123
const editeng::SvxBorderLine * GetLeft() const
Definition: boxitem.hxx:106
editeng::SvxBorderLine * GetBottom()
Definition: boxitem.hxx:119
std::array< model::ComplexColor, 4 > maTempComplexColors
Definition: boxitem.hxx:70
std::unique_ptr< editeng::SvxBorderLine > mpLeftBorderLine
Definition: boxitem.hxx:61
static bool LineToSvxLine(const css::table::BorderLine2 &rLine, editeng::SvxBorderLine &rSvxLine, bool bConvert)
editeng::SvxBorderLine * GetTop()
Definition: boxitem.hxx:115
std::unique_ptr< editeng::SvxBorderLine > mpRightBorderLine
Definition: boxitem.hxx:62
const editeng::SvxBorderLine * GetBottom() const
Definition: boxitem.hxx:102
void SetAllDistances(sal_Int16 nNew)
Definition: boxitem.hxx:143
#define EDITENG_DLLPUBLIC
Definition: editengdllapi.h:28
struct _xmlTextWriter * xmlTextWriterPtr
MapUnit
NONE
const sal_uInt32 LEFT
const sal_uInt32 TOP
const sal_uInt32 BOTTOM
const sal_uInt32 RIGHT
void BorderDistanceFromWord(bool bFromEdge, sal_Int32 &nMargin, sal_Int32 &nBorderDistance, sal_Int32 nBorderWidth)
Definition: frmitems.cxx:3604
void BorderDistancesToWord(const SvxBoxItem &rBox, const WordPageMargins &rMargins, WordBorderDistances &rDistances)
Definition: frmitems.cxx:3652
long Long
SfxItemPresentation
unsigned char sal_uInt8