Branch libreoffice-5-0-4
[LibreOffice.git] / include / editeng / boxitem.hxx
blob99379f42fc7529878d10915fb065e488a27dbc86
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/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 ------------------------------------------------------
32 /* [Description]
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
42 /**
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)
47 /**
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,
56 *pBottom,
57 *pLeft,
58 *pRight;
59 sal_uInt16 nTopDist,
60 nBottomDist,
61 nLeftDist,
62 nRightDist;
64 public:
65 TYPEINFO_OVERRIDE();
67 explicit SvxBoxItem( const sal_uInt16 nId );
68 SvxBoxItem( const SvxBoxItem &rCpy );
69 virtual ~SvxBoxItem();
70 SvxBoxItem &operator=( const SvxBoxItem& rBox );
72 // "pure virtual Methods" from SfxPoolItem
73 virtual bool operator==( const SfxPoolItem& ) const SAL_OVERRIDE;
74 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const SAL_OVERRIDE;
75 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) SAL_OVERRIDE;
77 virtual bool GetPresentation( SfxItemPresentation ePres,
78 SfxMapUnit eCoreMetric,
79 SfxMapUnit ePresMetric,
80 OUString &rText, const IntlWrapper * = 0 ) const SAL_OVERRIDE;
82 virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE;
83 virtual SfxPoolItem* Create(SvStream &, sal_uInt16) const SAL_OVERRIDE;
84 virtual SvStream& Store(SvStream &, sal_uInt16 nItemVersion ) const SAL_OVERRIDE;
85 virtual sal_uInt16 GetVersion( sal_uInt16 nFileVersion ) const SAL_OVERRIDE;
87 virtual bool ScaleMetrics( long nMult, long nDiv ) SAL_OVERRIDE;
88 virtual bool HasMetrics() const SAL_OVERRIDE;
90 const editeng::SvxBorderLine* GetTop() const { return pTop; }
91 const editeng::SvxBorderLine* GetBottom() const { return pBottom; }
92 const editeng::SvxBorderLine* GetLeft() const { return pLeft; }
93 const editeng::SvxBorderLine* GetRight() const { return pRight; }
95 const editeng::SvxBorderLine* GetLine( SvxBoxItemLine nLine ) const;
97 //The Pointers are being copied!
98 void SetLine( const editeng::SvxBorderLine* pNew, SvxBoxItemLine nLine );
100 sal_uInt16 GetDistance( SvxBoxItemLine nLine ) const;
101 sal_uInt16 GetDistance() const;
103 void SetDistance( sal_uInt16 nNew, SvxBoxItemLine nLine );
104 inline void SetDistance( sal_uInt16 nNew );
106 // Line width plus Space plus inward distance
107 // bIgnoreLine = TRUE -> Also return distance, when no Line is set
108 sal_uInt16 CalcLineSpace( SvxBoxItemLine nLine, bool bIgnoreLine = false ) const;
109 static com::sun::star::table::BorderLine2 SvxLineToLine( const editeng::SvxBorderLine* pLine, bool bConvert );
110 static bool LineToSvxLine(const ::com::sun::star::table::BorderLine& rLine, editeng::SvxBorderLine& rSvxLine, bool bConvert);
111 static bool LineToSvxLine(const ::com::sun::star::table::BorderLine2& rLine, editeng::SvxBorderLine& rSvxLine, bool bConvert);
114 inline void SvxBoxItem::SetDistance( sal_uInt16 nNew )
116 nTopDist = nBottomDist = nLeftDist = nRightDist = nNew;
119 // class SvxBoxInfoItem --------------------------------------------------
121 /* [Description]
123 Another item for the border. This item has only limited functionality.
124 On one hand, the general Dialog is told by the item which options it
125 should offer. On the other hand, this attribute may be used to
126 transported the borderline for the inner horizontal and vertical lines.
129 enum class SvxBoxInfoItemLine
131 HORI, VERT, LAST = VERT
134 enum class SvxBoxInfoItemValidFlags
136 NONE = 0x00,
137 TOP = 0x01,
138 BOTTOM = 0x02,
139 LEFT = 0x04,
140 RIGHT = 0x08,
141 HORI = 0x10,
142 VERT = 0x20,
143 DISTANCE = 0x40,
144 DISABLE = 0x80,
145 ALL = 0xff
147 namespace o3tl
149 template<> struct typed_flags<SvxBoxInfoItemValidFlags> : is_typed_flags<SvxBoxInfoItemValidFlags, 0xff> {};
152 class EDITENG_DLLPUBLIC SvxBoxInfoItem : public SfxPoolItem
154 editeng::SvxBorderLine* pHori; //inner horizontal Line
155 editeng::SvxBorderLine* pVert; //inner vertical Line
157 bool mbEnableHor; /// true = Enable inner horizontal line.
158 bool mbEnableVer; /// true = Enable inner vertical line.
161 Currently only for StarWriter: distance inward from SvxBoxItem. If the
162 distance is requested, then the field for the distance from the dialog be
163 activated. nDefDist is regarded as a default value. If any line is
164 turned on or will be turned on it must this distance be set to default.
165 bMinDist indicates whether the user can go below this value or not.
166 With NDIST is the current distance from the app transported back and
167 forth to the dialogue.
170 bool bDist :1; // TRUE, Unlock Distance.
171 bool bMinDist :1; // TRUE, Going below minimum Distance is prohibited
173 SvxBoxInfoItemValidFlags nValidFlags;
174 sal_uInt16 nDefDist; // The default or minimum distance.
176 public:
177 TYPEINFO_OVERRIDE();
179 explicit SvxBoxInfoItem( const sal_uInt16 nId );
180 SvxBoxInfoItem( const SvxBoxInfoItem &rCpy );
181 virtual ~SvxBoxInfoItem();
182 SvxBoxInfoItem &operator=( const SvxBoxInfoItem &rCpy );
184 // "pure virtual Methods" from SfxPoolItem
185 virtual bool operator==( const SfxPoolItem& ) const SAL_OVERRIDE;
186 virtual bool GetPresentation( SfxItemPresentation ePres,
187 SfxMapUnit eCoreMetric,
188 SfxMapUnit ePresMetric,
189 OUString &rText, const IntlWrapper * = 0 ) const SAL_OVERRIDE;
190 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const SAL_OVERRIDE;
191 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) SAL_OVERRIDE;
193 virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE;
194 virtual SfxPoolItem* Create(SvStream &, sal_uInt16) const SAL_OVERRIDE;
195 virtual SvStream& Store(SvStream &, sal_uInt16 nItemVersion ) const SAL_OVERRIDE;
196 virtual bool ScaleMetrics( long nMult, long nDiv ) SAL_OVERRIDE;
197 virtual bool HasMetrics() const SAL_OVERRIDE;
199 const editeng::SvxBorderLine* GetHori() const { return pHori; }
200 const editeng::SvxBorderLine* GetVert() const { return pVert; }
202 //The Pointers are being copied!
203 void SetLine( const editeng::SvxBorderLine* pNew, SvxBoxInfoItemLine nLine );
205 bool IsTable() const { return mbEnableHor && mbEnableVer; }
206 void SetTable( bool bNew ) { mbEnableHor = mbEnableVer = bNew; }
208 inline bool IsHorEnabled() const { return mbEnableHor; }
209 inline void EnableHor( bool bEnable ) { mbEnableHor = bEnable; }
210 inline bool IsVerEnabled() const { return mbEnableVer; }
211 inline void EnableVer( bool bEnable ) { mbEnableVer = bEnable; }
213 bool IsDist() const { return bDist; }
214 void SetDist( bool bNew ) { bDist = bNew; }
215 bool IsMinDist() const { return bMinDist; }
216 void SetMinDist( bool bNew ) { bMinDist = bNew; }
217 sal_uInt16 GetDefDist() const { return nDefDist; }
218 void SetDefDist( sal_uInt16 nNew ) { nDefDist = nNew; }
220 bool IsValid( SvxBoxInfoItemValidFlags nValid ) const
221 { return bool( nValidFlags & nValid ); }
222 void SetValid( SvxBoxInfoItemValidFlags nValid, bool bValid = true )
223 { bValid ? ( nValidFlags |= nValid )
224 : ( nValidFlags &= ~nValid ); }
225 void ResetFlags();
227 #endif
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */