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/borderline.hxx>
25 #include <editeng/editengdllapi.h>
26 #include <com/sun/star/table/BorderLine2.hpp>
27 #include <o3tl/typed_flags_set.hxx>
30 // class SvxBoxItem ------------------------------------------------------
34 This item describes a border attribute
35 (all four edges and the inward distance)
37 enum class SvxBoxItemLine
39 TOP
, BOTTOM
, LEFT
, RIGHT
, LAST
= RIGHT
43 This version causes SvxBoxItem to store the 4 cell spacing distances separately
44 when serializing to stream.
46 #define BOX_4DISTS_VERSION ((sal_uInt16)1)
48 This version causes SvxBoxItem to store the styles for its border lines when
49 serializing to stream.
51 #define BOX_BORDER_STYLE_VERSION ((sal_uInt16)2)
53 class EDITENG_DLLPUBLIC SvxBoxItem
: public SfxPoolItem
55 editeng::SvxBorderLine
*pTop
,
63 bool bRemoveAdjCellBorder
;
66 static SfxPoolItem
* CreateDefault();
68 explicit SvxBoxItem( const sal_uInt16 nId
);
69 SvxBoxItem( const SvxBoxItem
&rCpy
);
70 virtual ~SvxBoxItem() override
;
71 SvxBoxItem
&operator=( const SvxBoxItem
& rBox
);
73 // "pure virtual Methods" from SfxPoolItem
74 virtual bool operator==( const SfxPoolItem
& ) const override
;
75 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
= 0 ) const override
;
76 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
) override
;
78 virtual bool GetPresentation( SfxItemPresentation ePres
,
81 OUString
&rText
, const IntlWrapper
* = nullptr ) const override
;
83 virtual SfxPoolItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
84 virtual SfxPoolItem
* Create(SvStream
&, sal_uInt16
) const override
;
85 virtual SvStream
& Store(SvStream
&, sal_uInt16 nItemVersion
) const override
;
86 virtual sal_uInt16
GetVersion( sal_uInt16 nFileVersion
) const override
;
88 virtual void ScaleMetrics( long nMult
, long nDiv
) override
;
89 virtual bool HasMetrics() const override
;
91 const editeng::SvxBorderLine
* GetTop() const { return pTop
; }
92 const editeng::SvxBorderLine
* GetBottom() const { return pBottom
; }
93 const editeng::SvxBorderLine
* GetLeft() const { return pLeft
; }
94 const editeng::SvxBorderLine
* GetRight() const { return pRight
; }
96 const editeng::SvxBorderLine
* GetLine( SvxBoxItemLine nLine
) const;
98 //The Pointers are being copied!
99 void SetLine( const editeng::SvxBorderLine
* pNew
, SvxBoxItemLine nLine
);
101 sal_uInt16
GetDistance( SvxBoxItemLine nLine
) const;
102 sal_uInt16
GetSmallestDistance() const;
104 bool IsRemoveAdjacentCellBorder() const { return bRemoveAdjCellBorder
; }
106 void SetDistance( sal_uInt16 nNew
, SvxBoxItemLine nLine
);
107 inline void SetAllDistances( sal_uInt16 nNew
);
109 void SetRemoveAdjacentCellBorder( bool bSet
) { bRemoveAdjCellBorder
= bSet
; }
111 // Line width plus Space plus inward distance
112 // bEvenIfNoLine = TRUE -> Also return distance, when no Line is set
113 sal_uInt16
CalcLineWidth( SvxBoxItemLine nLine
) const;
114 sal_uInt16
CalcLineSpace( SvxBoxItemLine nLine
, bool bEvenIfNoLine
= false ) const;
115 bool HasBorder( bool bTreatPaddingAsBorder
= false ) const;
116 static css::table::BorderLine2
SvxLineToLine( const editeng::SvxBorderLine
* pLine
, bool bConvert
);
117 static bool LineToSvxLine(const css::table::BorderLine
& rLine
, editeng::SvxBorderLine
& rSvxLine
, bool bConvert
);
118 static bool LineToSvxLine(const css::table::BorderLine2
& rLine
, editeng::SvxBorderLine
& rSvxLine
, bool bConvert
);
121 inline void SvxBoxItem::SetAllDistances(sal_uInt16
const nNew
)
123 nTopDist
= nBottomDist
= nLeftDist
= nRightDist
= nNew
;
126 // class SvxBoxInfoItem --------------------------------------------------
130 Another item for the border. This item has only limited functionality.
131 On one hand, the general Dialog is told by the item which options it
132 should offer. On the other hand, this attribute may be used to
133 transported the borderline for the inner horizontal and vertical lines.
136 enum class SvxBoxInfoItemLine
138 HORI
, VERT
, LAST
= VERT
141 enum class SvxBoxInfoItemValidFlags
156 template<> struct typed_flags
<SvxBoxInfoItemValidFlags
> : is_typed_flags
<SvxBoxInfoItemValidFlags
, 0xff> {};
159 class EDITENG_DLLPUBLIC SvxBoxInfoItem
: public SfxPoolItem
161 editeng::SvxBorderLine
* pHori
; //inner horizontal Line
162 editeng::SvxBorderLine
* pVert
; //inner vertical Line
164 bool mbEnableHor
; /// true = Enable inner horizontal line.
165 bool mbEnableVer
; /// true = Enable inner vertical line.
168 Currently only for StarWriter: distance inward from SvxBoxItem. If the
169 distance is requested, then the field for the distance from the dialog be
170 activated. nDefDist is regarded as a default value. If any line is
171 turned on or will be turned on it must this distance be set to default.
172 bMinDist indicates whether the user can go below this value or not.
173 With NDIST is the current distance from the app transported back and
174 forth to the dialogue.
177 bool bDist
:1; // TRUE, Unlock Distance.
178 bool bMinDist
:1; // TRUE, Going below minimum Distance is prohibited
180 SvxBoxInfoItemValidFlags nValidFlags
;
181 sal_uInt16 nDefDist
; // The default or minimum distance.
184 static SfxPoolItem
* CreateDefault();
186 explicit SvxBoxInfoItem( const sal_uInt16 nId
);
187 SvxBoxInfoItem( const SvxBoxInfoItem
&rCpy
);
188 virtual ~SvxBoxInfoItem() override
;
189 SvxBoxInfoItem
&operator=( const SvxBoxInfoItem
&rCpy
);
191 // "pure virtual Methods" from SfxPoolItem
192 virtual bool operator==( const SfxPoolItem
& ) const override
;
193 virtual bool GetPresentation( SfxItemPresentation ePres
,
196 OUString
&rText
, const IntlWrapper
* = nullptr ) const override
;
197 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
= 0 ) const override
;
198 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
) override
;
200 virtual SfxPoolItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
201 virtual SfxPoolItem
* Create(SvStream
&, sal_uInt16
) const override
;
202 virtual SvStream
& Store(SvStream
&, sal_uInt16 nItemVersion
) const override
;
203 virtual void ScaleMetrics( long nMult
, long nDiv
) override
;
204 virtual bool HasMetrics() const override
;
206 const editeng::SvxBorderLine
* GetHori() const { return pHori
; }
207 const editeng::SvxBorderLine
* GetVert() const { return pVert
; }
209 //The Pointers are being copied!
210 void SetLine( const editeng::SvxBorderLine
* pNew
, SvxBoxInfoItemLine nLine
);
212 bool IsTable() const { return mbEnableHor
&& mbEnableVer
; }
213 void SetTable( bool bNew
) { mbEnableHor
= mbEnableVer
= bNew
; }
215 bool IsHorEnabled() const { return mbEnableHor
; }
216 void EnableHor( bool bEnable
) { mbEnableHor
= bEnable
; }
217 bool IsVerEnabled() const { return mbEnableVer
; }
218 void EnableVer( bool bEnable
) { mbEnableVer
= bEnable
; }
220 bool IsDist() const { return bDist
; }
221 void SetDist( bool bNew
) { bDist
= bNew
; }
222 bool IsMinDist() const { return bMinDist
; }
223 void SetMinDist( bool bNew
) { bMinDist
= bNew
; }
224 sal_uInt16
GetDefDist() const { return nDefDist
; }
225 void SetDefDist( sal_uInt16 nNew
) { nDefDist
= nNew
; }
227 bool IsValid( SvxBoxInfoItemValidFlags nValid
) const
228 { return bool( nValidFlags
& nValid
); }
229 void SetValid( SvxBoxInfoItemValidFlags nValid
, bool bValid
= true )
230 { bValid
? ( nValidFlags
|= nValid
)
231 : ( nValidFlags
&= ~nValid
); }
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */