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 .
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 <vcl/vclenum.hxx>
39 namespace vcl
{ class Font
; }
42 namespace com::sun::star::text
{ class XNumberingFormatter
; }
44 namespace com::sun::star::lang
{ struct Locale
; }
47 #define SVX_NO_NUM 200 // Marker for no numbering
48 #define SVX_NO_NUMLEVEL 0x20
49 #define SVX_NUM_REL_SIZE_MIN 25 // Lower limit for numbering relative size
52 #define LINK_TOKEN 0x80 //indicate linked bitmaps - for use in dialog only
54 typedef struct _xmlTextWriter
* xmlTextWriterPtr
;
56 class EDITENG_DLLPUBLIC SvxNumberType
58 static sal_Int32 nRefCount
;
59 static css::uno::Reference
<css::text::XNumberingFormatter
> xFormatter
;
62 bool bShowSymbol
; // Also show Symbol ?
65 explicit SvxNumberType(SvxNumType nType
= SVX_NUM_ARABIC
);
66 SvxNumberType(const SvxNumberType
& rType
);
68 SvxNumberType
& operator =(SvxNumberType
const &) = default;
70 OUString
GetNumStr( sal_Int32 nNo
) const;
71 OUString
GetNumStr( sal_Int32 nNo
, const css::lang::Locale
& rLocale
) const;
73 void SetNumberingType(SvxNumType nSet
) {nNumType
= nSet
;}
74 SvxNumType
GetNumberingType() const {return nNumType
;}
76 void SetShowSymbol(bool bSet
) {bShowSymbol
= bSet
;}
77 bool IsShowSymbol()const{return bShowSymbol
;}
79 bool IsTextFormat() const
81 return css::style::NumberingType::NUMBER_NONE
!= nNumType
&&
82 css::style::NumberingType::CHAR_SPECIAL
!= nNumType
&&
83 css::style::NumberingType::BITMAP
!= nNumType
;
86 void dumpAsXml(xmlTextWriterPtr w
) const;
89 class EDITENG_DLLPUBLIC SvxNumberFormat
: public SvxNumberType
92 enum SvxNumPositionAndSpaceMode
94 LABEL_WIDTH_AND_POSITION
,
108 std::optional
<OUString
> sListFormat
; // Format string ">%1.%2<" can be used instead of prefix/suffix
109 // Right now it is optional value to distinguish empty list format
110 // and not set list format when we need to fallback to prefix/suffix.
112 SvxAdjust eNumAdjust
;
114 sal_uInt8 nInclUpperLevels
; // Take over numbers from the previous level.
115 sal_uInt16 nStart
; // Start of counting
117 sal_UCS4 cBullet
; // Symbol
118 sal_uInt16 nBulletRelSize
; // percentage size of bullets
119 Color nBulletColor
; // Bullet color
121 // mode indicating, if the position and spacing of the list label is
122 // determined by the former attributes (nFirstLineOffset, nAbsLSpace
123 // and nCharTextDistance) called position and spacing via label
124 // width and position (LABEL_WIDTH_AND_POSITION) or by the new attributes
125 // (meLabelFollowedBy, mnListtabPos, mnFirstLineIndent and mnIndentAt)
126 // called position and spacing via label alignment.
127 // Note 1: Attribute <eNumAdjust> is relevant for both modes.
128 // Note 2: The values of the former attributes are treated as 0, if mode
129 // LABEL_ALIGNMENT is active.
130 SvxNumPositionAndSpaceMode mePositionAndSpaceMode
;
132 sal_Int32 nFirstLineOffset
; // First line indent
133 sal_Int32 nAbsLSpace
; // Distance Border<->Number
134 short nCharTextDistance
; // Distance Number<->Text
136 // specifies what follows the list label before the text of the first line
137 // of the list item starts
138 LabelFollowedBy meLabelFollowedBy
;
139 // specifies an additional list tab stop position for meLabelFollowedBy = LISTTAB
140 tools::Long mnListtabPos
;
141 // specifies the first line indent
142 tools::Long mnFirstLineIndent
;
143 // specifies the indent before the text, e.g. in L2R-layout the left margin
144 tools::Long mnIndentAt
;
146 std::unique_ptr
<SvxBrushItem
>
148 sal_Int16 eVertOrient
; // vertical alignment of a bitmap
150 Size aGraphicSize
; // Always! in 1/100 mm
151 std::unique_ptr
<vcl::Font
>
152 pBulletFont
; // Pointer to the bullet font
154 OUString sCharStyleName
; // Character Style
157 explicit SvxNumberFormat( SvxNumType nNumberingType
);
158 SvxNumberFormat(const SvxNumberFormat
& rFormat
);
159 SvxNumberFormat( SvStream
& rStream
);
161 virtual ~SvxNumberFormat();
163 void Store(SvStream
&rStream
, FontToSubsFontConverter pConverter
);
165 SvxNumberFormat
& operator=( const SvxNumberFormat
& );
166 bool operator==( const SvxNumberFormat
& ) const;
167 bool operator!=( const SvxNumberFormat
& rFmt
) const {return !(*this == rFmt
);}
169 void SetNumAdjust(SvxAdjust eSet
) {eNumAdjust
= eSet
;}
170 SvxAdjust
GetNumAdjust() const {return eNumAdjust
;}
171 void SetPrefix(const OUString
& rSet
) { sPrefix
= rSet
;}
172 const OUString
& GetPrefix() const { return sPrefix
;}
173 void SetSuffix(const OUString
& rSet
) { sSuffix
= rSet
;}
174 const OUString
& GetSuffix() const { return sSuffix
;}
175 void SetListFormat(std::optional
<OUString
> oSet
= std::nullopt
) { sListFormat
= oSet
; }
176 bool HasListFormat() const { return sListFormat
.has_value(); }
177 const OUString
& GetListFormat() const { return *sListFormat
; }
179 void SetCharFormatName(const OUString
& rSet
){ sCharStyleName
= rSet
; }
180 virtual OUString
GetCharFormatName()const;
182 void SetBulletFont(const vcl::Font
* pFont
);
183 const vcl::Font
* GetBulletFont() const {return pBulletFont
.get();}
184 void SetBulletChar(sal_UCS4 cSet
){cBullet
= cSet
;}
185 sal_UCS4
GetBulletChar()const {return cBullet
;}
186 void SetBulletRelSize(sal_uInt16 nSet
) {nBulletRelSize
= std::max(nSet
,sal_uInt16(SVX_NUM_REL_SIZE_MIN
));}
187 sal_uInt16
GetBulletRelSize() const { return nBulletRelSize
;}
188 void SetBulletColor(Color nSet
){nBulletColor
= nSet
;}
189 const Color
& GetBulletColor()const {return nBulletColor
;}
191 void SetIncludeUpperLevels( sal_uInt8 nSet
) { nInclUpperLevels
= nSet
;}
192 sal_uInt8
GetIncludeUpperLevels()const { return nInclUpperLevels
;}
193 void SetStart(sal_uInt16 nSet
) {nStart
= nSet
;}
194 sal_uInt16
GetStart() const {return nStart
;}
196 virtual void SetGraphicBrush( const SvxBrushItem
* pBrushItem
, const Size
* pSize
= nullptr, const sal_Int16
* pOrient
= nullptr);
197 const SvxBrushItem
* GetBrush() const {return pGraphicBrush
.get();}
198 void SetGraphic( const OUString
& rName
);
199 sal_Int16
GetVertOrient() const;
200 void SetGraphicSize(const Size
& rSet
) {aGraphicSize
= rSet
;}
201 const Size
& GetGraphicSize() const {return aGraphicSize
;}
203 SvxNumPositionAndSpaceMode
GetPositionAndSpaceMode() const { return mePositionAndSpaceMode
;}
204 void SetPositionAndSpaceMode( SvxNumPositionAndSpaceMode ePositionAndSpaceMode
);
206 void SetAbsLSpace(sal_Int32 nSet
) {nAbsLSpace
= nSet
;}
207 sal_Int32
GetAbsLSpace() const;
208 void SetFirstLineOffset(sal_Int32 nSet
) { nFirstLineOffset
= nSet
;}
209 sal_Int32
GetFirstLineOffset() const;
210 void SetCharTextDistance(short nSet
) { nCharTextDistance
= nSet
; }
211 short GetCharTextDistance() const;
213 void SetLabelFollowedBy( const LabelFollowedBy eLabelFollowedBy
);
214 LabelFollowedBy
GetLabelFollowedBy() const { return meLabelFollowedBy
;}
215 void SetListtabPos( const tools::Long nListtabPos
);
216 tools::Long
GetListtabPos() const { return mnListtabPos
;}
217 void SetFirstLineIndent( const tools::Long nFirstLineIndent
);
218 tools::Long
GetFirstLineIndent() const { return mnFirstLineIndent
;}
219 void SetIndentAt( const tools::Long nIndentAt
);
220 tools::Long
GetIndentAt() const { return mnIndentAt
;}
222 static Size
GetGraphicSizeMM100(const Graphic
* pGraphic
);
223 static OUString
CreateRomanString( sal_uLong nNo
, bool bUpper
);
226 //Feature-Flags (only sal_uInt16!)
227 enum class SvxNumRuleFlags
230 CONTINUOUS
= 0x0001, // consecutive numbers possible?
231 CHAR_STYLE
= 0x0004, // Character styles?
232 BULLET_REL_SIZE
= 0x0008, // relative bullet size?
233 BULLET_COLOR
= 0x0010, // Bullet color
234 NO_NUMBERS
= 0x0080, // Numbering are not allowed
235 ENABLE_LINKED_BMP
= 0x0100, // linked bitmaps are available
236 ENABLE_EMBEDDED_BMP
= 0x0200 // embedded bitmaps are available
240 template<> struct typed_flags
<SvxNumRuleFlags
> : is_typed_flags
<SvxNumRuleFlags
, 0x039d> {};
243 enum class SvxNumRuleType
247 PRESENTATION_NUMBERING
250 class EDITENG_DLLPUBLIC SvxNumRule final
252 sal_uInt16 nLevelCount
; // Number of supported levels
253 SvxNumRuleFlags nFeatureFlags
; // What is supported?
254 SvxNumRuleType eNumberingType
; // Type of numbering
255 bool bContinuousNumbering
; // sequential numbering
257 std::unique_ptr
<SvxNumberFormat
> aFmts
[SVX_MAX_NUM
];
258 bool aFmtsSet
[SVX_MAX_NUM
]; // Flags indicating valid levels
260 static sal_Int32 nRefCount
;
262 SvxNumRule( SvxNumRuleFlags nFeatures
,
265 SvxNumRuleType eType
= SvxNumRuleType::NUMBERING
,
266 SvxNumberFormat::SvxNumPositionAndSpaceMode
267 eDefaultNumberFormatPositionAndSpaceMode
268 = SvxNumberFormat::LABEL_WIDTH_AND_POSITION
);
269 SvxNumRule(const SvxNumRule
& rCopy
);
270 SvxNumRule(SvStream
&rStream
);
273 bool operator==( const SvxNumRule
& ) const;
274 bool operator!=( const SvxNumRule
& rRule
) const {return !(*this == rRule
);}
276 SvxNumRule
& operator=( const SvxNumRule
& );
278 void Store(SvStream
&rStream
);
279 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
280 const SvxNumberFormat
* Get(sal_uInt16 nLevel
)const;
281 const SvxNumberFormat
& GetLevel(sal_uInt16 nLevel
)const;
282 void SetLevel(sal_uInt16 nLevel
, const SvxNumberFormat
& rFmt
, bool bIsValid
= true);
283 void SetLevel(sal_uInt16 nLevel
, const SvxNumberFormat
* pFmt
);
285 bool IsContinuousNumbering()const
286 {return bContinuousNumbering
;}
287 void SetContinuousNumbering(bool bSet
)
288 {bContinuousNumbering
= bSet
;}
290 sal_uInt16
GetLevelCount() const {return nLevelCount
;}
291 bool IsFeatureSupported(SvxNumRuleFlags nFeature
) const
292 { return bool(nFeatureFlags
& nFeature
); }
293 SvxNumRuleFlags
GetFeatureFlags() const {return nFeatureFlags
;}
294 void SetFeatureFlag( SvxNumRuleFlags nFlag
, bool bSet
= true ) { if(bSet
) nFeatureFlags
|= nFlag
; else nFeatureFlags
&= ~nFlag
; }
296 OUString
MakeNumString( const SvxNodeNum
& ) const;
298 SvxNumRuleType
GetNumRuleType() const { return eNumberingType
; }
300 void UnLinkGraphics();
303 class EDITENG_DLLPUBLIC SvxNumBulletItem final
: public SfxPoolItem
305 std::unique_ptr
<SvxNumRule
> pNumRule
;
307 explicit SvxNumBulletItem(SvxNumRule
const & rRule
);
308 SvxNumBulletItem(SvxNumRule
const & rRule
, sal_uInt16 nWhich
);
309 SvxNumBulletItem(const SvxNumBulletItem
& rCopy
);
310 virtual ~SvxNumBulletItem() override
;
312 virtual SvxNumBulletItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
313 virtual bool operator==( const SfxPoolItem
& ) const override
;
315 SvxNumRule
* GetNumRule() const {return pNumRule
.get();}
317 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
= 0 ) const override
;
318 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
) override
;
319 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
324 sal_uInt16 nLevelVal
[ SVX_MAX_NUM
] = {}; // Numbers of all levels
325 sal_uInt8 nMyLevel
= 0; // Current Level
328 explicit inline SvxNodeNum() = default;
329 inline SvxNodeNum
& operator=( const SvxNodeNum
& rCpy
);
331 sal_uInt8
GetLevel() const { return nMyLevel
; }
332 void SetLevel( sal_uInt8 nVal
) { nMyLevel
= nVal
; }
334 const sal_uInt16
* GetLevelVal() const { return nLevelVal
; }
335 sal_uInt16
* GetLevelVal() { return nLevelVal
; }
338 inline SvxNodeNum
& SvxNodeNum::operator=( const SvxNodeNum
& rCpy
)
342 nMyLevel
= rCpy
.nMyLevel
;
344 memcpy( nLevelVal
, rCpy
.nLevelVal
, sizeof( nLevelVal
) );
349 std::unique_ptr
<SvxNumRule
> SvxConvertNumRule( const SvxNumRule
* pRule
, sal_uInt16 nLevel
, SvxNumRuleType eType
);
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */