Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / editeng / numitem.hxx
blob1e72154b43b2eab13140e290d0a2de506c88fcfe
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 .
19 #ifndef INCLUDED_EDITENG_NUMITEM_HXX
20 #define INCLUDED_EDITENG_NUMITEM_HXX
22 #include <rtl/ustring.hxx>
23 #include <tools/link.hxx>
24 #include <svl/poolitem.hxx>
25 #include <editeng/svxenum.hxx>
26 #include <tools/gen.hxx>
27 #include <editeng/numdef.hxx>
28 #include <tools/color.hxx>
29 #include <cppuhelper/weakref.hxx>
30 #include <com/sun/star/lang/Locale.hpp>
31 #include <com/sun/star/uno/Reference.h>
32 #include <com/sun/star/style/NumberingType.hpp>
33 #include <unotools/fontcvt.hxx>
34 #include <editeng/editengdllapi.h>
35 #include <o3tl/typed_flags_set.hxx>
36 #include <memory>
37 #include <algorithm>
39 class SvxBrushItem;
40 namespace vcl { class Font; }
41 class Graphic;
42 class SvxNodeNum;
43 namespace com{namespace sun{ namespace star{
44 namespace text{
45 class XNumberingFormatter;
47 }}}
50 #define SVX_NO_NUM 200 // Marker for no numbering
51 #define SVX_NO_NUMLEVEL 0x20
52 #define SVX_NUM_REL_SIZE_MIN 25 // Lower limit for numbering relative size
55 #define LINK_TOKEN 0x80 //indicate linked bitmaps - for use in dialog only
56 class EDITENG_DLLPUBLIC SvxNumberType
58 static sal_Int32 nRefCount;
59 static css::uno::Reference<css::text::XNumberingFormatter> xFormatter;
61 SvxNumType nNumType;
62 bool bShowSymbol; // Also show Symbol ?
64 public:
65 explicit SvxNumberType(SvxNumType nType = SVX_NUM_ARABIC);
66 SvxNumberType(const SvxNumberType& rType);
67 ~SvxNumberType();
69 OUString GetNumStr( sal_uLong nNo ) const;
70 OUString GetNumStr( sal_uLong nNo, const css::lang::Locale& rLocale ) const;
72 void SetNumberingType(SvxNumType nSet) {nNumType = nSet;}
73 SvxNumType GetNumberingType() const {return nNumType;}
75 void SetShowSymbol(bool bSet) {bShowSymbol = bSet;}
76 bool IsShowSymbol()const{return bShowSymbol;}
78 bool IsTextFormat() const
80 return css::style::NumberingType::NUMBER_NONE != nNumType &&
81 css::style::NumberingType::CHAR_SPECIAL != nNumType &&
82 css::style::NumberingType::BITMAP != nNumType;
86 class EDITENG_DLLPUBLIC SvxNumberFormat : public SvxNumberType
88 public:
89 enum SvxNumPositionAndSpaceMode
91 LABEL_WIDTH_AND_POSITION,
92 LABEL_ALIGNMENT
94 enum LabelFollowedBy
96 LISTTAB,
97 SPACE,
98 NOTHING
101 private:
102 OUString sPrefix;
103 OUString sSuffix;
105 SvxAdjust eNumAdjust;
107 sal_uInt8 nInclUpperLevels; // Take over numbers from the previous level.
108 sal_uInt16 nStart; // Start of counting
110 sal_Unicode cBullet; // Symbol
111 sal_uInt16 nBulletRelSize; // percentage size of bullets
112 Color nBulletColor; // Bullet color
114 // mode indicating, if the position and spacing of the list label is
115 // determined by the former attributes (nFirstLineOffset, nAbsLSpace
116 // and nCharTextDistance) called position and spacing via label
117 // width and position (LABEL_WIDTH_AND_POSITION) or by the new attributes
118 // (meLabelFollowedBy, mnListtabPos, mnFirstLineIndent and mnIndentAt)
119 // called position and spacing via label alignment.
120 // Note 1: Attribute <eNumAdjust> is relevant for both modes.
121 // Note 2: The values of the former attributes are treated as 0, if mode
122 // LABEL_ALIGNMENT is active.
123 SvxNumPositionAndSpaceMode mePositionAndSpaceMode;
125 short nFirstLineOffset; // First line indent
126 short nAbsLSpace; // Distance Border<->Number
127 short nCharTextDistance; // Distance Number<->Text
129 // specifies what follows the list label before the text of the first line
130 // of the list item starts
131 LabelFollowedBy meLabelFollowedBy;
132 // specifies an additional list tab stop position for meLabelFollowedBy = LISTTAB
133 long mnListtabPos;
134 // specifies the first line indent
135 long mnFirstLineIndent;
136 // specifies the indent before the text, e.g. in L2R-layout the left margin
137 long mnIndentAt;
139 SvxBrushItem* pGraphicBrush;
140 sal_Int16 eVertOrient; // vertical alignment of a bitmap
142 Size aGraphicSize; // Always! in 1/100 mm
143 vcl::Font* pBulletFont; // Pointer to the bullet font
145 OUString sCharStyleName; // Character Style
147 public:
148 explicit SvxNumberFormat( SvxNumType nNumberingType );
149 SvxNumberFormat(const SvxNumberFormat& rFormat);
150 SvxNumberFormat( SvStream & rStream );
152 virtual ~SvxNumberFormat();
154 void Store(SvStream &rStream, FontToSubsFontConverter pConverter);
156 SvxNumberFormat& operator=( const SvxNumberFormat& );
157 bool operator==( const SvxNumberFormat& ) const;
158 bool operator!=( const SvxNumberFormat& rFmt) const {return !(*this == rFmt);}
160 void SetNumAdjust(SvxAdjust eSet) {eNumAdjust = eSet;}
161 SvxAdjust GetNumAdjust() const {return eNumAdjust;}
162 void SetPrefix(const OUString& rSet) { sPrefix = rSet;}
163 const OUString& GetPrefix() const { return sPrefix;}
164 void SetSuffix(const OUString& rSet) { sSuffix = rSet;}
165 const OUString& GetSuffix() const { return sSuffix;}
167 void SetCharFormatName(const OUString& rSet){ sCharStyleName = rSet; }
168 virtual OUString GetCharFormatName()const;
170 void SetBulletFont(const vcl::Font* pFont);
171 const vcl::Font* GetBulletFont() const {return pBulletFont;}
172 void SetBulletChar(sal_Unicode cSet){cBullet = cSet;}
173 sal_Unicode GetBulletChar()const {return cBullet;}
174 void SetBulletRelSize(sal_uInt16 nSet) {nBulletRelSize = std::max(nSet,sal_uInt16(SVX_NUM_REL_SIZE_MIN));}
175 sal_uInt16 GetBulletRelSize() const { return nBulletRelSize;}
176 void SetBulletColor(Color nSet){nBulletColor = nSet;}
177 const Color& GetBulletColor()const {return nBulletColor;}
179 void SetIncludeUpperLevels( sal_uInt8 nSet ) { nInclUpperLevels = nSet;}
180 sal_uInt8 GetIncludeUpperLevels()const { return nInclUpperLevels;}
181 void SetStart(sal_uInt16 nSet) {nStart = nSet;}
182 sal_uInt16 GetStart() const {return nStart;}
184 virtual void SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = nullptr, const sal_Int16* pOrient = nullptr);
185 const SvxBrushItem* GetBrush() const {return pGraphicBrush;}
186 void SetGraphic( const OUString& rName );
187 sal_Int16 GetVertOrient() const;
188 void SetGraphicSize(const Size& rSet) {aGraphicSize = rSet;}
189 const Size& GetGraphicSize() const {return aGraphicSize;}
191 SvxNumPositionAndSpaceMode GetPositionAndSpaceMode() const { return mePositionAndSpaceMode;}
192 void SetPositionAndSpaceMode( SvxNumPositionAndSpaceMode ePositionAndSpaceMode );
194 void SetAbsLSpace(short nSet) {nAbsLSpace = nSet;}
195 short GetAbsLSpace() const;
196 void SetFirstLineOffset(short nSet) { nFirstLineOffset = nSet;}
197 short GetFirstLineOffset() const;
198 void SetCharTextDistance(short nSet) { nCharTextDistance = nSet; }
199 short GetCharTextDistance() const;
201 void SetLabelFollowedBy( const LabelFollowedBy eLabelFollowedBy );
202 LabelFollowedBy GetLabelFollowedBy() const { return meLabelFollowedBy;}
203 void SetListtabPos( const long nListtabPos );
204 long GetListtabPos() const { return mnListtabPos;}
205 void SetFirstLineIndent( const long nFirstLineIndent );
206 long GetFirstLineIndent() const { return mnFirstLineIndent;}
207 void SetIndentAt( const long nIndentAt );
208 long GetIndentAt() const { return mnIndentAt;}
210 static Size GetGraphicSizeMM100(const Graphic* pGraphic);
211 static OUString CreateRomanString( sal_uLong nNo, bool bUpper );
214 //Feature-Flags (only sal_uInt16!)
215 enum class SvxNumRuleFlags
217 NONE = 0x0000,
218 CONTINUOUS = 0x0001, // consecutive numbers possible?
219 CHAR_TEXT_DISTANCE = 0x0002, // Distance Symbol<->Text?
220 CHAR_STYLE = 0x0004, // Character styles?
221 BULLET_REL_SIZE = 0x0008, // relative bullet size?
222 BULLET_COLOR = 0x0010, // Bullet color
223 SYMBOL_ALIGNMENT = 0x0040, // alignment to be shown in the options
224 NO_NUMBERS = 0x0080, // Numbering are not allowed
225 ENABLE_LINKED_BMP = 0x0100, // linked bitmaps are available
226 ENABLE_EMBEDDED_BMP = 0x0200 // embedded bitmaps are available
228 namespace o3tl
230 template<> struct typed_flags<SvxNumRuleFlags> : is_typed_flags<SvxNumRuleFlags, 0x03df> {};
233 enum class SvxNumRuleType
235 NUMBERING,
236 OUTLINE_NUMBERING,
237 PRESENTATION_NUMBERING
240 class EDITENG_DLLPUBLIC SvxNumRule final
242 sal_uInt16 nLevelCount; // Number of supported levels
243 SvxNumRuleFlags nFeatureFlags; // What is supported?
244 SvxNumRuleType eNumberingType; // Type of numbering
245 bool bContinuousNumbering; // sequential numbering
247 SvxNumberFormat* aFmts[SVX_MAX_NUM];
248 bool aFmtsSet[SVX_MAX_NUM]; // Flags indicating valid levels
250 static sal_Int32 nRefCount;
251 css::lang::Locale aLocale;
252 public:
253 SvxNumRule( SvxNumRuleFlags nFeatures,
254 sal_uInt16 nLevels,
255 bool bCont,
256 SvxNumRuleType eType = SvxNumRuleType::NUMBERING,
257 SvxNumberFormat::SvxNumPositionAndSpaceMode
258 eDefaultNumberFormatPositionAndSpaceMode
259 = SvxNumberFormat::LABEL_WIDTH_AND_POSITION );
260 SvxNumRule(const SvxNumRule& rCopy);
261 SvxNumRule(SvStream &rStream);
262 ~SvxNumRule();
264 bool operator==( const SvxNumRule& ) const;
265 bool operator!=( const SvxNumRule& rRule ) const {return !(*this == rRule);}
267 SvxNumRule& operator=( const SvxNumRule& );
269 void Store(SvStream &rStream);
270 void dumpAsXml(struct _xmlTextWriter* pWriter) const;
271 const SvxNumberFormat* Get(sal_uInt16 nLevel)const;
272 const SvxNumberFormat& GetLevel(sal_uInt16 nLevel)const;
273 void SetLevel(sal_uInt16 nLevel, const SvxNumberFormat& rFmt, bool bIsValid = true);
274 void SetLevel(sal_uInt16 nLevel, const SvxNumberFormat* pFmt);
276 bool IsContinuousNumbering()const
277 {return bContinuousNumbering;}
278 void SetContinuousNumbering(bool bSet)
279 {bContinuousNumbering = bSet;}
281 sal_uInt16 GetLevelCount() const {return nLevelCount;}
282 bool IsFeatureSupported(SvxNumRuleFlags nFeature) const
283 { return bool(nFeatureFlags & nFeature); }
284 SvxNumRuleFlags GetFeatureFlags() const {return nFeatureFlags;}
285 void SetFeatureFlag( SvxNumRuleFlags nFlag, bool bSet = true ) { if(bSet) nFeatureFlags |= nFlag; else nFeatureFlags &= ~nFlag; }
287 OUString MakeNumString( const SvxNodeNum& ) const;
289 SvxNumRuleType GetNumRuleType() const { return eNumberingType; }
291 void UnLinkGraphics();
294 class EDITENG_DLLPUBLIC SvxNumBulletItem : public SfxPoolItem
296 std::unique_ptr<SvxNumRule> pNumRule;
297 public:
298 explicit SvxNumBulletItem(SvxNumRule& rRule);
299 SvxNumBulletItem(SvxNumRule& rRule, sal_uInt16 nWhich );
300 SvxNumBulletItem(const SvxNumBulletItem& rCopy);
301 virtual ~SvxNumBulletItem() override;
303 virtual SfxPoolItem* Clone( SfxItemPool *pPool = nullptr ) const override;
304 virtual SfxPoolItem* Create(SvStream &rStream, sal_uInt16 nItemVersion) const override;
305 sal_uInt16 GetVersion( sal_uInt16 nFileVersion ) const override;
306 virtual SvStream& Store(SvStream &rStream, sal_uInt16 nItemVersion ) const override;
307 virtual bool operator==( const SfxPoolItem& ) const override;
309 SvxNumRule* GetNumRule() const {return pNumRule.get();}
311 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
312 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
313 virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const override;
316 class SvxNodeNum
318 sal_uInt16 nLevelVal[ SVX_MAX_NUM ]; // Numbers of all levels
319 sal_uInt8 nMyLevel; // Current Level
321 public:
322 explicit inline SvxNodeNum();
323 inline SvxNodeNum& operator=( const SvxNodeNum& rCpy );
325 sal_uInt8 GetLevel() const { return nMyLevel; }
326 void SetLevel( sal_uInt8 nVal ) { nMyLevel = nVal; }
328 const sal_uInt16* GetLevelVal() const { return nLevelVal; }
329 sal_uInt16* GetLevelVal() { return nLevelVal; }
332 SvxNodeNum::SvxNodeNum()
333 : nMyLevel( 0 )
335 memset( nLevelVal, 0, sizeof( nLevelVal ) );
338 inline SvxNodeNum& SvxNodeNum::operator=( const SvxNodeNum& rCpy )
340 if ( &rCpy != this)
342 nMyLevel = rCpy.nMyLevel;
344 memcpy( nLevelVal, rCpy.nLevelVal, sizeof( nLevelVal ) );
346 return *this;
349 SvxNumRule* SvxConvertNumRule( const SvxNumRule* pRule, sal_uInt16 nLevel, SvxNumRuleType eType );
351 #endif
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */