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 .
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>
32 namespace editeng
{ class SvxBorderLine
; }
34 // class SvxBoxItem ------------------------------------------------------
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
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;
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
);
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 supportsHashCode() const override
{ return true; }
86 virtual size_t hashCode() const override
;
87 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
= 0 ) const override
;
88 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
) override
;
90 virtual bool GetPresentation( SfxItemPresentation ePres
,
93 OUString
&rText
, const IntlWrapper
& ) const override
;
95 virtual SvxBoxItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
97 virtual void ScaleMetrics( tools::Long nMult
, tools::Long nDiv
) override
;
98 virtual bool HasMetrics() const override
;
100 const editeng::SvxBorderLine
* GetTop() const
102 return mpTopBorderLine
.get();
104 const editeng::SvxBorderLine
* GetBottom() const
106 return mpBottomBorderLine
.get();
108 const editeng::SvxBorderLine
* GetLeft() const
110 return mpLeftBorderLine
.get();
112 const editeng::SvxBorderLine
* GetRight() const
114 return mpRightBorderLine
.get();
117 editeng::SvxBorderLine
* GetTop()
119 ASSERT_CHANGE_REFCOUNTED_ITEM
;
120 return mpTopBorderLine
.get();
122 editeng::SvxBorderLine
* GetBottom()
124 ASSERT_CHANGE_REFCOUNTED_ITEM
;
125 return mpBottomBorderLine
.get();
127 editeng::SvxBorderLine
* GetLeft()
129 ASSERT_CHANGE_REFCOUNTED_ITEM
;
130 return mpLeftBorderLine
.get();
132 editeng::SvxBorderLine
* GetRight()
134 ASSERT_CHANGE_REFCOUNTED_ITEM
;
135 return mpRightBorderLine
.get();
138 const editeng::SvxBorderLine
* GetLine( SvxBoxItemLine nLine
) const;
140 //The Pointers are being copied!
141 void SetLine( const editeng::SvxBorderLine
* pNew
, SvxBoxItemLine nLine
);
143 sal_Int16
GetDistance( SvxBoxItemLine nLine
, bool bAllowNegative
= false ) const;
144 sal_uInt16
GetSmallestDistance() const;
146 bool IsRemoveAdjacentCellBorder() const { return mbRemoveAdjCellBorder
; }
148 void SetDistance( sal_Int16 nNew
, SvxBoxItemLine nLine
);
149 void SetAllDistances(sal_Int16 nNew
)
151 ASSERT_CHANGE_REFCOUNTED_ITEM
;
152 mnTopDistance
= mnBottomDistance
= mnLeftDistance
= mnRightDistance
= nNew
;
155 void SetRemoveAdjacentCellBorder( bool bSet
) { ASSERT_CHANGE_REFCOUNTED_ITEM
; mbRemoveAdjCellBorder
= bSet
; }
157 // Line width plus Space plus inward distance
158 // bEvenIfNoLine = TRUE -> Also return distance, when no Line is set
159 sal_uInt16
CalcLineWidth( SvxBoxItemLine nLine
) const;
160 sal_Int16
CalcLineSpace( SvxBoxItemLine nLine
, bool bEvenIfNoLine
= false, bool bAllowNegative
= false ) const;
161 bool HasBorder( bool bTreatPaddingAsBorder
) const;
162 static css::table::BorderLine2
SvxLineToLine( const editeng::SvxBorderLine
* pLine
, bool bConvert
);
163 static bool LineToSvxLine(const css::table::BorderLine
& rLine
, editeng::SvxBorderLine
& rSvxLine
, bool bConvert
);
164 static bool LineToSvxLine(const css::table::BorderLine2
& rLine
, editeng::SvxBorderLine
& rSvxLine
, bool bConvert
);
166 virtual boost::property_tree::ptree
dumpAsJSON() const override
;
167 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
170 // class SvxBoxInfoItem --------------------------------------------------
174 Another item for the border. This item has only limited functionality.
175 On one hand, the general Dialog is told by the item which options it
176 should offer. On the other hand, this attribute may be used to
177 transported the borderline for the inner horizontal and vertical lines.
180 enum class SvxBoxInfoItemLine
182 HORI
, VERT
, LAST
= VERT
185 enum class SvxBoxInfoItemValidFlags
200 template<> struct typed_flags
<SvxBoxInfoItemValidFlags
> : is_typed_flags
<SvxBoxInfoItemValidFlags
, 0xff> {};
203 class EDITENG_DLLPUBLIC SvxBoxInfoItem final
: public SfxPoolItem
205 std::unique_ptr
<editeng::SvxBorderLine
> mpHorizontalLine
; //inner horizontal Line
206 std::unique_ptr
<editeng::SvxBorderLine
> mpVerticalLine
; //inner vertical Line
208 bool mbEnableHorizontalLine
= false; /// true = Enable inner horizontal line.
209 bool mbEnableVerticalLine
= false; /// true = Enable inner vertical line.
212 Currently only for StarWriter: distance inward from SvxBoxItem. If the
213 distance is requested, then the field for the distance from the dialog be
214 activated. nDefDist is regarded as a default value. If any line is
215 turned on or will be turned on it must this distance be set to default.
216 bMinDist indicates whether the user can go below this value or not.
217 With NDIST is the current distance from the app transported back and
218 forth to the dialogue.
221 bool mbDistance
:1; // TRUE, Unlock Distance.
222 bool mbMinimumDistance
:1; // TRUE, Going below minimum Distance is prohibited
224 SvxBoxInfoItemValidFlags mnValidFlags
;
225 sal_uInt16 mnDefaultMinimumDistance
= 0; // The default or minimum distance.
228 static SfxPoolItem
* CreateDefault();
230 explicit SvxBoxInfoItem( const sal_uInt16 nId
);
231 SvxBoxInfoItem( const SvxBoxInfoItem
&rCpy
);
232 virtual ~SvxBoxInfoItem() override
;
234 // "pure virtual Methods" from SfxPoolItem
235 virtual bool operator==( const SfxPoolItem
& ) const override
;
236 virtual bool GetPresentation( SfxItemPresentation ePres
,
239 OUString
&rText
, const IntlWrapper
& ) const override
;
240 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
= 0 ) const override
;
241 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
) override
;
243 virtual SvxBoxInfoItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
244 virtual void ScaleMetrics( tools::Long nMult
, tools::Long nDiv
) override
;
245 virtual bool HasMetrics() const override
;
247 const editeng::SvxBorderLine
* GetHori() const { return mpHorizontalLine
.get(); }
248 const editeng::SvxBorderLine
* GetVert() const { return mpVerticalLine
.get(); }
250 //The Pointers are being copied!
251 void SetLine( const editeng::SvxBorderLine
* pNew
, SvxBoxInfoItemLine nLine
);
253 bool IsTable() const { return mbEnableHorizontalLine
&& mbEnableVerticalLine
; }
254 void SetTable(bool bNew
) { mbEnableHorizontalLine
= mbEnableVerticalLine
= bNew
; }
256 bool IsHorEnabled() const { return mbEnableHorizontalLine
; }
257 void EnableHor( bool bEnable
) { mbEnableHorizontalLine
= bEnable
; }
258 bool IsVerEnabled() const { return mbEnableVerticalLine
; }
259 void EnableVer( bool bEnable
) { mbEnableVerticalLine
= bEnable
; }
261 bool IsDist() const { return mbDistance
; }
262 void SetDist(bool bNew
)
266 bool IsMinDist() const { return mbMinimumDistance
; }
267 void SetMinDist(bool bNew
) { mbMinimumDistance
= bNew
; }
268 sal_uInt16
GetDefDist() const { return mnDefaultMinimumDistance
; }
269 void SetDefDist(sal_uInt16 nNew
) { mnDefaultMinimumDistance
= nNew
; }
271 bool IsValid( SvxBoxInfoItemValidFlags nValid
) const
273 return bool(mnValidFlags
& nValid
);
275 void SetValid(SvxBoxInfoItemValidFlags nValid
, bool bValid
= true)
278 mnValidFlags
|= nValid
;
280 mnValidFlags
&= ~nValid
;
284 virtual boost::property_tree::ptree
dumpAsJSON() const override
;
290 void EDITENG_DLLPUBLIC
BorderDistanceFromWord(bool bFromEdge
, sal_Int32
& nMargin
,
291 sal_Int32
& nBorderDistance
, sal_Int32 nBorderWidth
);
293 struct EDITENG_DLLPUBLIC WordPageMargins final
295 sal_uInt16 nLeft
= 0;
296 sal_uInt16 nRight
= 0;
298 sal_uInt16 nBottom
= 0;
301 struct EDITENG_DLLPUBLIC WordBorderDistances final
303 bool bFromEdge
= false;
304 sal_uInt16 nLeft
= 0;
305 sal_uInt16 nRight
= 0;
307 sal_uInt16 nBottom
= 0;
310 // Heuristics to decide if we need to use "from edge" offset of borders. All sizes in twips
311 void EDITENG_DLLPUBLIC
BorderDistancesToWord(const SvxBoxItem
& rBox
, const WordPageMargins
& rMargins
,
312 WordBorderDistances
& rDistances
);
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */