bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / editeng / numitem.hxx
blob7757948a54aa4eb4296fe3eb166fb195101603f2
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/solar.h>
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 <com/sun/star/style/NumberingType.hpp>
30 #include <unotools/fontcvt.hxx>
31 #include <editeng/editengdllapi.h>
32 #include <o3tl/typed_flags_set.hxx>
33 #include <memory>
34 #include <algorithm>
36 class SvxBrushItem;
37 namespace vcl { class Font; }
38 class Graphic;
39 class SvxNodeNum;
40 namespace com{namespace sun{ namespace star{
41 namespace text{
42 class XNumberingFormatter;
44 }}}
46 namespace com::sun::star::lang { struct Locale; }
49 #define SVX_NO_NUM 200 // Marker for no numbering
50 #define SVX_NO_NUMLEVEL 0x20
51 #define SVX_NUM_REL_SIZE_MIN 25 // Lower limit for numbering relative size
54 #define LINK_TOKEN 0x80 //indicate linked bitmaps - for use in dialog only
55 class EDITENG_DLLPUBLIC SvxNumberType
57 static sal_Int32 nRefCount;
58 static css::uno::Reference<css::text::XNumberingFormatter> xFormatter;
60 SvxNumType nNumType;
61 bool bShowSymbol; // Also show Symbol ?
63 public:
64 explicit SvxNumberType(SvxNumType nType = SVX_NUM_ARABIC);
65 SvxNumberType(const SvxNumberType& rType);
66 ~SvxNumberType();
67 SvxNumberType & operator =(SvxNumberType const &) = default;
69 OUString GetNumStr( sal_Int32 nNo ) const;
70 OUString GetNumStr( sal_Int32 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,
99 NEWLINE
102 private:
103 OUString sPrefix;
104 OUString sSuffix;
106 SvxAdjust eNumAdjust;
108 sal_uInt8 nInclUpperLevels; // Take over numbers from the previous level.
109 sal_uInt16 nStart; // Start of counting
111 sal_Unicode cBullet; // Symbol
112 sal_uInt16 nBulletRelSize; // percentage size of bullets
113 Color nBulletColor; // Bullet color
115 // mode indicating, if the position and spacing of the list label is
116 // determined by the former attributes (nFirstLineOffset, nAbsLSpace
117 // and nCharTextDistance) called position and spacing via label
118 // width and position (LABEL_WIDTH_AND_POSITION) or by the new attributes
119 // (meLabelFollowedBy, mnListtabPos, mnFirstLineIndent and mnIndentAt)
120 // called position and spacing via label alignment.
121 // Note 1: Attribute <eNumAdjust> is relevant for both modes.
122 // Note 2: The values of the former attributes are treated as 0, if mode
123 // LABEL_ALIGNMENT is active.
124 SvxNumPositionAndSpaceMode mePositionAndSpaceMode;
126 sal_Int32 nFirstLineOffset; // First line indent
127 sal_Int32 nAbsLSpace; // Distance Border<->Number
128 short nCharTextDistance; // Distance Number<->Text
130 // specifies what follows the list label before the text of the first line
131 // of the list item starts
132 LabelFollowedBy meLabelFollowedBy;
133 // specifies an additional list tab stop position for meLabelFollowedBy = LISTTAB
134 long mnListtabPos;
135 // specifies the first line indent
136 long mnFirstLineIndent;
137 // specifies the indent before the text, e.g. in L2R-layout the left margin
138 long mnIndentAt;
140 std::unique_ptr<SvxBrushItem>
141 pGraphicBrush;
142 sal_Int16 eVertOrient; // vertical alignment of a bitmap
144 Size aGraphicSize; // Always! in 1/100 mm
145 std::unique_ptr<vcl::Font>
146 pBulletFont; // Pointer to the bullet font
148 OUString sCharStyleName; // Character Style
150 public:
151 explicit SvxNumberFormat( SvxNumType nNumberingType );
152 SvxNumberFormat(const SvxNumberFormat& rFormat);
153 SvxNumberFormat( SvStream & rStream );
155 virtual ~SvxNumberFormat();
157 void Store(SvStream &rStream, FontToSubsFontConverter pConverter);
159 SvxNumberFormat& operator=( const SvxNumberFormat& );
160 bool operator==( const SvxNumberFormat& ) const;
161 bool operator!=( const SvxNumberFormat& rFmt) const {return !(*this == rFmt);}
163 void SetNumAdjust(SvxAdjust eSet) {eNumAdjust = eSet;}
164 SvxAdjust GetNumAdjust() const {return eNumAdjust;}
165 void SetPrefix(const OUString& rSet) { sPrefix = rSet;}
166 const OUString& GetPrefix() const { return sPrefix;}
167 void SetSuffix(const OUString& rSet) { sSuffix = rSet;}
168 const OUString& GetSuffix() const { return sSuffix;}
170 void SetCharFormatName(const OUString& rSet){ sCharStyleName = rSet; }
171 virtual OUString GetCharFormatName()const;
173 void SetBulletFont(const vcl::Font* pFont);
174 const vcl::Font* GetBulletFont() const {return pBulletFont.get();}
175 void SetBulletChar(sal_Unicode cSet){cBullet = cSet;}
176 sal_Unicode GetBulletChar()const {return cBullet;}
177 void SetBulletRelSize(sal_uInt16 nSet) {nBulletRelSize = std::max(nSet,sal_uInt16(SVX_NUM_REL_SIZE_MIN));}
178 sal_uInt16 GetBulletRelSize() const { return nBulletRelSize;}
179 void SetBulletColor(Color nSet){nBulletColor = nSet;}
180 const Color& GetBulletColor()const {return nBulletColor;}
182 void SetIncludeUpperLevels( sal_uInt8 nSet ) { nInclUpperLevels = nSet;}
183 sal_uInt8 GetIncludeUpperLevels()const { return nInclUpperLevels;}
184 void SetStart(sal_uInt16 nSet) {nStart = nSet;}
185 sal_uInt16 GetStart() const {return nStart;}
187 virtual void SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = nullptr, const sal_Int16* pOrient = nullptr);
188 const SvxBrushItem* GetBrush() const {return pGraphicBrush.get();}
189 void SetGraphic( const OUString& rName );
190 sal_Int16 GetVertOrient() const;
191 void SetGraphicSize(const Size& rSet) {aGraphicSize = rSet;}
192 const Size& GetGraphicSize() const {return aGraphicSize;}
194 SvxNumPositionAndSpaceMode GetPositionAndSpaceMode() const { return mePositionAndSpaceMode;}
195 void SetPositionAndSpaceMode( SvxNumPositionAndSpaceMode ePositionAndSpaceMode );
197 void SetAbsLSpace(sal_Int32 nSet) {nAbsLSpace = nSet;}
198 sal_Int32 GetAbsLSpace() const;
199 void SetFirstLineOffset(sal_Int32 nSet) { nFirstLineOffset = nSet;}
200 sal_Int32 GetFirstLineOffset() const;
201 void SetCharTextDistance(short nSet) { nCharTextDistance = nSet; }
202 short GetCharTextDistance() const;
204 void SetLabelFollowedBy( const LabelFollowedBy eLabelFollowedBy );
205 LabelFollowedBy GetLabelFollowedBy() const { return meLabelFollowedBy;}
206 void SetListtabPos( const long nListtabPos );
207 long GetListtabPos() const { return mnListtabPos;}
208 void SetFirstLineIndent( const long nFirstLineIndent );
209 long GetFirstLineIndent() const { return mnFirstLineIndent;}
210 void SetIndentAt( const long nIndentAt );
211 long GetIndentAt() const { return mnIndentAt;}
213 static Size GetGraphicSizeMM100(const Graphic* pGraphic);
214 static OUString CreateRomanString( sal_uLong nNo, bool bUpper );
217 //Feature-Flags (only sal_uInt16!)
218 enum class SvxNumRuleFlags
220 NONE = 0x0000,
221 CONTINUOUS = 0x0001, // consecutive numbers possible?
222 CHAR_STYLE = 0x0004, // Character styles?
223 BULLET_REL_SIZE = 0x0008, // relative bullet size?
224 BULLET_COLOR = 0x0010, // Bullet color
225 NO_NUMBERS = 0x0080, // Numbering are not allowed
226 ENABLE_LINKED_BMP = 0x0100, // linked bitmaps are available
227 ENABLE_EMBEDDED_BMP = 0x0200 // embedded bitmaps are available
229 namespace o3tl
231 template<> struct typed_flags<SvxNumRuleFlags> : is_typed_flags<SvxNumRuleFlags, 0x03dd> {};
234 enum class SvxNumRuleType
236 NUMBERING,
237 OUTLINE_NUMBERING,
238 PRESENTATION_NUMBERING
241 class EDITENG_DLLPUBLIC SvxNumRule final
243 sal_uInt16 nLevelCount; // Number of supported levels
244 SvxNumRuleFlags nFeatureFlags; // What is supported?
245 SvxNumRuleType eNumberingType; // Type of numbering
246 bool bContinuousNumbering; // sequential numbering
248 std::unique_ptr<SvxNumberFormat> aFmts[SVX_MAX_NUM];
249 bool aFmtsSet[SVX_MAX_NUM]; // Flags indicating valid levels
251 static sal_Int32 nRefCount;
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(xmlTextWriterPtr 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 const & rRule);
299 SvxNumBulletItem(SvxNumRule const & rRule, sal_uInt16 nWhich );
300 SvxNumBulletItem(const SvxNumBulletItem& rCopy);
301 virtual ~SvxNumBulletItem() override;
303 virtual SfxPoolItem* Clone( SfxItemPool *pPool = nullptr ) const override;
304 virtual bool operator==( const SfxPoolItem& ) const override;
306 SvxNumRule* GetNumRule() const {return pNumRule.get();}
308 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
309 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
310 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
313 class SvxNodeNum
315 sal_uInt16 nLevelVal[ SVX_MAX_NUM ]; // Numbers of all levels
316 sal_uInt8 nMyLevel; // Current Level
318 public:
319 explicit inline SvxNodeNum();
320 inline SvxNodeNum& operator=( const SvxNodeNum& rCpy );
322 sal_uInt8 GetLevel() const { return nMyLevel; }
323 void SetLevel( sal_uInt8 nVal ) { nMyLevel = nVal; }
325 const sal_uInt16* GetLevelVal() const { return nLevelVal; }
326 sal_uInt16* GetLevelVal() { return nLevelVal; }
329 SvxNodeNum::SvxNodeNum()
330 : nMyLevel( 0 )
332 memset( nLevelVal, 0, sizeof( nLevelVal ) );
335 inline SvxNodeNum& SvxNodeNum::operator=( const SvxNodeNum& rCpy )
337 if ( &rCpy != this)
339 nMyLevel = rCpy.nMyLevel;
341 memcpy( nLevelVal, rCpy.nLevelVal, sizeof( nLevelVal ) );
343 return *this;
346 std::unique_ptr<SvxNumRule> SvxConvertNumRule( const SvxNumRule* pRule, sal_uInt16 nLevel, SvxNumRuleType eType );
348 #endif
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */