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/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>
38 namespace vcl
{ class Font
; }
41 namespace com
{namespace sun
{ namespace star
{
43 class XNumberingFormatter
;
48 #define SVX_NO_NUM 200 // Marker for no numbering
49 #define SVX_NO_NUMLEVEL 0x20
51 #define LINK_TOKEN 0x80 //indicate linked bitmaps - for use in dialog only
52 class EDITENG_DLLPUBLIC SvxNumberType
54 static sal_Int32 nRefCount
;
55 static com::sun::star::uno::Reference
<com::sun::star::text::XNumberingFormatter
> xFormatter
;
58 bool bShowSymbol
; // Also show Symbol ?
61 explicit SvxNumberType(sal_Int16 nType
= com::sun::star::style::NumberingType::ARABIC
);
62 SvxNumberType(const SvxNumberType
& rType
);
65 OUString
GetNumStr( sal_uLong nNo
) const;
66 OUString
GetNumStr( sal_uLong nNo
, const com::sun::star::lang::Locale
& rLocale
) const;
68 void SetNumberingType(sal_Int16 nSet
) {nNumType
= nSet
;}
69 sal_Int16
GetNumberingType() const {return nNumType
;}
71 void SetShowSymbol(bool bSet
) {bShowSymbol
= bSet
;}
72 bool IsShowSymbol()const{return bShowSymbol
;}
74 bool IsTextFormat() const
76 return com::sun::star::style::NumberingType::NUMBER_NONE
!= nNumType
&&
77 com::sun::star::style::NumberingType::CHAR_SPECIAL
!= nNumType
&&
78 com::sun::star::style::NumberingType::BITMAP
!= nNumType
;
82 class EDITENG_DLLPUBLIC SvxNumberFormat
: public SvxNumberType
85 enum SvxNumPositionAndSpaceMode
87 LABEL_WIDTH_AND_POSITION
,
101 SvxAdjust eNumAdjust
;
103 sal_uInt8 nInclUpperLevels
; // Take over numbers from the previous level.
104 sal_uInt16 nStart
; // Start of counting
106 sal_Unicode cBullet
; // Symbol
107 sal_uInt16 nBulletRelSize
; // percentage size of bullets
108 Color nBulletColor
; // Bullet color
110 // mode indicating, if the position and spacing of the list label is
111 // determined by the former attributes (nFirstLineOffset, nAbsLSpace
112 // and nCharTextDistance) called position and spacing via label
113 // width and position (LABEL_WIDTH_AND_POSITION) or by the new attributes
114 // (meLabelFollowedBy, mnListtabPos, mnFirstLineIndent and mnIndentAt)
115 // called position and spacing via label alignment.
116 // Note 1: Attribute <eNumAdjust> is relevant for both modes.
117 // Note 2: The values of the former attributes are treated as 0, if mode
118 // LABEL_ALIGNMENT is active.
119 SvxNumPositionAndSpaceMode mePositionAndSpaceMode
;
121 short nFirstLineOffset
; // First line indent
122 short nAbsLSpace
; // Distance Border<->Number
123 short nCharTextDistance
; // Distance Number<->Text
125 // specifies what follows the list label before the text of the first line
126 // of the list item starts
127 LabelFollowedBy meLabelFollowedBy
;
128 // specifies an additional list tab stop position for meLabelFollowedBy = LISTTAB
130 // specifies the first line indent
131 long mnFirstLineIndent
;
132 // specifies the indent before the text, e.g. in L2R-layout the left margin
135 SvxBrushItem
* pGraphicBrush
;
136 sal_Int16 eVertOrient
; // vertical alignment of a bitmap
138 Size aGraphicSize
; // Always! in 1/100 mm
139 vcl::Font
* pBulletFont
; // Pointer to the bullet font
141 OUString sCharStyleName
; // Character Style
143 DECL_LINK( GraphicArrived
, void * );
144 virtual void NotifyGraphicArrived();
146 explicit SvxNumberFormat( sal_Int16 nNumberingType
,
147 SvxNumPositionAndSpaceMode ePositionAndSpaceMode
= LABEL_WIDTH_AND_POSITION
);
148 SvxNumberFormat(const SvxNumberFormat
& rFormat
);
149 SvxNumberFormat( SvStream
& rStream
);
151 virtual ~SvxNumberFormat();
153 SvStream
& Store(SvStream
&rStream
, FontToSubsFontConverter pConverter
);
155 SvxNumberFormat
& operator=( const SvxNumberFormat
& );
156 bool operator==( const SvxNumberFormat
& ) const;
157 bool operator!=( const SvxNumberFormat
& rFmt
) const {return !(*this == rFmt
);}
159 void SetNumAdjust(SvxAdjust eSet
) {eNumAdjust
= eSet
;}
160 SvxAdjust
GetNumAdjust() const {return eNumAdjust
;}
161 void SetPrefix(const OUString
& rSet
) { sPrefix
= rSet
;}
162 const OUString
& GetPrefix() const { return sPrefix
;}
163 void SetSuffix(const OUString
& rSet
) { sSuffix
= rSet
;}
164 const OUString
& GetSuffix() const { return sSuffix
;}
166 void SetCharFormatName(const OUString
& rSet
){ sCharStyleName
= rSet
; }
167 virtual OUString
GetCharFormatName()const;
169 void SetBulletFont(const vcl::Font
* pFont
);
170 const vcl::Font
* GetBulletFont() const {return pBulletFont
;}
171 void SetBulletChar(sal_Unicode cSet
){cBullet
= cSet
;}
172 sal_Unicode
GetBulletChar()const {return cBullet
;}
173 void SetBulletRelSize(sal_uInt16 nSet
) {nBulletRelSize
= nSet
;}
174 sal_uInt16
GetBulletRelSize() const { return nBulletRelSize
;}
175 void SetBulletColor(Color nSet
){nBulletColor
= nSet
;}
176 Color
GetBulletColor()const {return nBulletColor
;}
178 void SetIncludeUpperLevels( sal_uInt8 nSet
) { nInclUpperLevels
= nSet
;}
179 sal_uInt8
GetIncludeUpperLevels()const { return nInclUpperLevels
;}
180 void SetStart(sal_uInt16 nSet
) {nStart
= nSet
;}
181 sal_uInt16
GetStart() const {return nStart
;}
183 virtual void SetGraphicBrush( const SvxBrushItem
* pBrushItem
, const Size
* pSize
= 0, const sal_Int16
* pOrient
= 0);
184 const SvxBrushItem
* GetBrush() const {return pGraphicBrush
;}
185 void SetGraphic( const OUString
& rName
);
186 virtual void SetVertOrient(sal_Int16 eSet
);
187 virtual 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
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
230 template<> struct typed_flags
<SvxNumRuleFlags
> : is_typed_flags
<SvxNumRuleFlags
, 0x03df> {};
233 enum class SvxNumRuleType
237 PRESENTATION_NUMBERING
,
241 class EDITENG_DLLPUBLIC SvxNumRule
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 SvxNumberFormat
* aFmts
[SVX_MAX_NUM
];
249 bool aFmtsSet
[SVX_MAX_NUM
]; // Flags indicating valid levels
251 static sal_Int32 nRefCount
;
252 com::sun::star::lang::Locale aLocale
;
254 SvxNumRule( SvxNumRuleFlags nFeatures
,
257 SvxNumRuleType eType
= SvxNumRuleType::NUMBERING
,
258 SvxNumberFormat::SvxNumPositionAndSpaceMode
259 eDefaultNumberFormatPositionAndSpaceMode
260 = SvxNumberFormat::LABEL_WIDTH_AND_POSITION
);
261 SvxNumRule(const SvxNumRule
& rCopy
);
262 SvxNumRule(SvStream
&rStream
);
263 virtual ~SvxNumRule();
265 bool operator==( const SvxNumRule
& ) const;
266 bool operator!=( const SvxNumRule
& rRule
) const {return !(*this == rRule
);}
268 SvxNumRule
& operator=( const SvxNumRule
& );
270 SvStream
& Store(SvStream
&rStream
);
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
&, bool bInclStrings
= true ) const;
289 SvxNumRuleType
GetNumRuleType() const { return eNumberingType
; }
290 void SetNumRuleType( const SvxNumRuleType
& rType
) { eNumberingType
= rType
; }
292 bool UnLinkGraphics();
295 class EDITENG_DLLPUBLIC SvxNumBulletItem
: public SfxPoolItem
297 SvxNumRule
* pNumRule
;
299 explicit SvxNumBulletItem(SvxNumRule
& rRule
);
300 SvxNumBulletItem(SvxNumRule
& rRule
, sal_uInt16 nWhich
);
301 SvxNumBulletItem(const SvxNumBulletItem
& rCopy
);
302 virtual ~SvxNumBulletItem();
304 virtual SfxPoolItem
* Clone( SfxItemPool
*pPool
= 0 ) const SAL_OVERRIDE
;
305 virtual SfxPoolItem
* Create(SvStream
&rStream
, sal_uInt16 nItemVersion
) const SAL_OVERRIDE
;
306 sal_uInt16
GetVersion( sal_uInt16 nFileVersion
) const SAL_OVERRIDE
;
307 virtual SvStream
& Store(SvStream
&rStream
, sal_uInt16 nItemVersion
) const SAL_OVERRIDE
;
308 virtual bool operator==( const SfxPoolItem
& ) const SAL_OVERRIDE
;
310 SvxNumRule
* GetNumRule() const {return pNumRule
;}
312 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
= 0 ) const SAL_OVERRIDE
;
313 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
= 0 ) SAL_OVERRIDE
;
318 sal_uInt16 nLevelVal
[ SVX_MAX_NUM
]; // Numbers of all levels
319 sal_uInt16 nSetValue
; // predetermined number
320 sal_uInt8 nMyLevel
; // Current Level
321 bool bStartNum
; // Restart numbering
324 explicit inline SvxNodeNum( sal_uInt8 nLevel
= SVX_NO_NUM
, sal_uInt16 nSetVal
= USHRT_MAX
);
325 inline SvxNodeNum
& operator=( const SvxNodeNum
& rCpy
);
327 sal_uInt8
GetLevel() const { return nMyLevel
; }
328 void SetLevel( sal_uInt8 nVal
) { nMyLevel
= nVal
; }
330 bool IsStart() const { return bStartNum
; }
331 void SetStart( bool bFlag
= true ) { bStartNum
= bFlag
; }
333 sal_uInt16
GetSetValue() const { return nSetValue
; }
334 void SetSetValue( sal_uInt16 nVal
) { nSetValue
= nVal
; }
336 const sal_uInt16
* GetLevelVal() const { return nLevelVal
; }
337 sal_uInt16
* GetLevelVal() { return nLevelVal
; }
340 SvxNodeNum::SvxNodeNum( sal_uInt8 nLevel
, sal_uInt16 nSetVal
)
341 : nSetValue( nSetVal
), nMyLevel( nLevel
), bStartNum( false )
343 memset( nLevelVal
, 0, sizeof( nLevelVal
) );
346 inline SvxNodeNum
& SvxNodeNum::operator=( const SvxNodeNum
& rCpy
)
350 nSetValue
= rCpy
.nSetValue
;
351 nMyLevel
= rCpy
.nMyLevel
;
352 bStartNum
= rCpy
.bStartNum
;
354 memcpy( nLevelVal
, rCpy
.nLevelVal
, sizeof( nLevelVal
) );
359 SvxNumRule
* SvxConvertNumRule( const SvxNumRule
* pRule
, sal_uInt16 nLevel
, SvxNumRuleType eType
);
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */