Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_EDITENG_NUMITEM_HXX
20 : #define INCLUDED_EDITENG_NUMITEM_HXX
21 :
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 :
37 : class SvxBrushItem;
38 : namespace vcl { class Font; }
39 : class Graphic;
40 : class SvxNodeNum;
41 : namespace com{namespace sun{ namespace star{
42 : namespace text{
43 : class XNumberingFormatter;
44 : }
45 : }}}
46 :
47 :
48 : #define SVX_NO_NUM 200 // Marker for no numbering
49 : #define SVX_NO_NUMLEVEL 0x20
50 :
51 : #define LINK_TOKEN 0x80 //indicate linked bitmaps - for use in dialog only
52 : class EDITENG_DLLPUBLIC SvxNumberType
53 : {
54 : static sal_Int32 nRefCount;
55 : static com::sun::star::uno::Reference<com::sun::star::text::XNumberingFormatter> xFormatter;
56 :
57 : sal_Int16 nNumType;
58 : bool bShowSymbol; // Also show Symbol ?
59 :
60 : public:
61 : explicit SvxNumberType(sal_Int16 nType = com::sun::star::style::NumberingType::ARABIC);
62 : SvxNumberType(const SvxNumberType& rType);
63 : ~SvxNumberType();
64 :
65 : OUString GetNumStr( sal_uLong nNo ) const;
66 : OUString GetNumStr( sal_uLong nNo, const com::sun::star::lang::Locale& rLocale ) const;
67 :
68 15823026 : void SetNumberingType(sal_Int16 nSet) {nNumType = nSet;}
69 31952416 : sal_Int16 GetNumberingType() const {return nNumType;}
70 :
71 15557428 : void SetShowSymbol(bool bSet) {bShowSymbol = bSet;}
72 25160826 : bool IsShowSymbol()const{return bShowSymbol;}
73 :
74 6209 : bool IsTextFormat() const
75 : {
76 11970 : return com::sun::star::style::NumberingType::NUMBER_NONE != nNumType &&
77 11684 : com::sun::star::style::NumberingType::CHAR_SPECIAL != nNumType &&
78 11684 : com::sun::star::style::NumberingType::BITMAP != nNumType;
79 : }
80 : };
81 :
82 : class EDITENG_DLLPUBLIC SvxNumberFormat : public SvxNumberType
83 : {
84 : public:
85 : enum SvxNumPositionAndSpaceMode
86 : {
87 : LABEL_WIDTH_AND_POSITION,
88 : LABEL_ALIGNMENT
89 : };
90 : enum LabelFollowedBy
91 : {
92 : LISTTAB,
93 : SPACE,
94 : NOTHING
95 : };
96 :
97 : private:
98 : OUString sPrefix;
99 : OUString sSuffix;
100 :
101 : SvxAdjust eNumAdjust;
102 :
103 : sal_uInt8 nInclUpperLevels; // Take over numbers from the previous level.
104 : sal_uInt16 nStart; // Start of counting
105 :
106 : sal_Unicode cBullet; // Symbol
107 : sal_uInt16 nBulletRelSize; // percentage size of bullets
108 : Color nBulletColor; // Bullet color
109 :
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;
120 :
121 : short nFirstLineOffset; // First line indent
122 : short nAbsLSpace; // Distance Border<->Number
123 : short nCharTextDistance; // Distance Number<->Text
124 :
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
129 : long mnListtabPos;
130 : // specifies the first line indent
131 : long mnFirstLineIndent;
132 : // specifies the indent before the text, e.g. in L2R-layout the left margin
133 : long mnIndentAt;
134 :
135 : SvxBrushItem* pGraphicBrush;
136 : sal_Int16 eVertOrient; // vertical alignment of a bitmap
137 :
138 : Size aGraphicSize; // Always! in 1/100 mm
139 : vcl::Font* pBulletFont; // Pointer to the bullet font
140 :
141 : OUString sCharStyleName; // Character Style
142 :
143 : DECL_LINK( GraphicArrived, void * );
144 : virtual void NotifyGraphicArrived();
145 : public:
146 : explicit SvxNumberFormat( sal_Int16 nNumberingType,
147 : SvxNumPositionAndSpaceMode ePositionAndSpaceMode = LABEL_WIDTH_AND_POSITION );
148 : SvxNumberFormat(const SvxNumberFormat& rFormat);
149 : SvxNumberFormat( SvStream & rStream );
150 :
151 : virtual ~SvxNumberFormat();
152 :
153 : SvStream& Store(SvStream &rStream, FontToSubsFontConverter pConverter);
154 :
155 : SvxNumberFormat& operator=( const SvxNumberFormat& );
156 : bool operator==( const SvxNumberFormat& ) const;
157 1114570 : bool operator!=( const SvxNumberFormat& rFmt) const {return !(*this == rFmt);}
158 :
159 51184 : void SetNumAdjust(SvxAdjust eSet) {eNumAdjust = eSet;}
160 41128 : SvxAdjust GetNumAdjust() const {return eNumAdjust;}
161 52536 : void SetPrefix(const OUString& rSet) { sPrefix = rSet;}
162 51438 : const OUString& GetPrefix() const { return sPrefix;}
163 106184 : void SetSuffix(const OUString& rSet) { sSuffix = rSet;}
164 50188 : const OUString& GetSuffix() const { return sSuffix;}
165 :
166 13023 : void SetCharFormatName(const OUString& rSet){ sCharStyleName = rSet; }
167 : virtual OUString GetCharFormatName()const;
168 :
169 : void SetBulletFont(const vcl::Font* pFont);
170 12261 : const vcl::Font* GetBulletFont() const {return pBulletFont;}
171 137581 : void SetBulletChar(sal_Unicode cSet){cBullet = cSet;}
172 28506 : sal_Unicode GetBulletChar()const {return cBullet;}
173 15256 : void SetBulletRelSize(sal_uInt16 nSet) {nBulletRelSize = nSet;}
174 5980 : sal_uInt16 GetBulletRelSize() const { return nBulletRelSize;}
175 11826 : void SetBulletColor(Color nSet){nBulletColor = nSet;}
176 5980 : Color GetBulletColor()const {return nBulletColor;}
177 :
178 147889 : void SetIncludeUpperLevels( sal_uInt8 nSet ) { nInclUpperLevels = nSet;}
179 1293561 : sal_uInt8 GetIncludeUpperLevels()const { return nInclUpperLevels;}
180 155658 : void SetStart(sal_uInt16 nSet) {nStart = nSet;}
181 14830 : sal_uInt16 GetStart() const {return nStart;}
182 :
183 : virtual void SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = 0, const sal_Int16* pOrient = 0);
184 8235341 : 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 8 : void SetGraphicSize(const Size& rSet) {aGraphicSize = rSet;}
189 6679994 : const Size& GetGraphicSize() const {return aGraphicSize;}
190 :
191 235745 : SvxNumPositionAndSpaceMode GetPositionAndSpaceMode() const { return mePositionAndSpaceMode;}
192 : void SetPositionAndSpaceMode( SvxNumPositionAndSpaceMode ePositionAndSpaceMode );
193 :
194 1757967 : void SetAbsLSpace(short nSet) {nAbsLSpace = nSet;}
195 : short GetAbsLSpace() const;
196 1740184 : void SetFirstLineOffset(short nSet) { nFirstLineOffset = nSet;}
197 : short GetFirstLineOffset() const;
198 34832 : void SetCharTextDistance(short nSet) { nCharTextDistance = nSet; }
199 : short GetCharTextDistance() const;
200 :
201 : void SetLabelFollowedBy( const LabelFollowedBy eLabelFollowedBy );
202 35158 : LabelFollowedBy GetLabelFollowedBy() const { return meLabelFollowedBy;}
203 : void SetListtabPos( const long nListtabPos );
204 20090 : long GetListtabPos() const { return mnListtabPos;}
205 : void SetFirstLineIndent( const long nFirstLineIndent );
206 64405 : long GetFirstLineIndent() const { return mnFirstLineIndent;}
207 : void SetIndentAt( const long nIndentAt );
208 51218 : long GetIndentAt() const { return mnIndentAt;}
209 :
210 : static Size GetGraphicSizeMM100(const Graphic* pGraphic);
211 : static OUString CreateRomanString( sal_uLong nNo, bool bUpper );
212 : };
213 :
214 : //Feature-Flags (only sal_uInt16!)
215 : enum class SvxNumRuleFlags
216 : {
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
227 : };
228 : namespace o3tl
229 : {
230 : template<> struct typed_flags<SvxNumRuleFlags> : is_typed_flags<SvxNumRuleFlags, 0x03df> {};
231 : }
232 :
233 : enum class SvxNumRuleType
234 : {
235 : NUMBERING,
236 : OUTLINE_NUMBERING,
237 : PRESENTATION_NUMBERING,
238 : END
239 : };
240 :
241 : class EDITENG_DLLPUBLIC SvxNumRule
242 : {
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
247 :
248 : SvxNumberFormat* aFmts[SVX_MAX_NUM];
249 : bool aFmtsSet[SVX_MAX_NUM]; // Flags indicating valid levels
250 :
251 : static sal_Int32 nRefCount;
252 : com::sun::star::lang::Locale aLocale;
253 : public:
254 : SvxNumRule( SvxNumRuleFlags nFeatures,
255 : sal_uInt16 nLevels,
256 : bool bCont,
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();
264 :
265 : bool operator==( const SvxNumRule& ) const;
266 0 : bool operator!=( const SvxNumRule& rRule ) const {return !(*this == rRule);}
267 :
268 : SvxNumRule& operator=( const SvxNumRule& );
269 :
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);
275 :
276 155531 : bool IsContinuousNumbering()const
277 155531 : {return bContinuousNumbering;}
278 0 : void SetContinuousNumbering(bool bSet)
279 0 : {bContinuousNumbering = bSet;}
280 :
281 1799903 : sal_uInt16 GetLevelCount() const {return nLevelCount;}
282 0 : bool IsFeatureSupported(SvxNumRuleFlags nFeature) const
283 0 : { return bool(nFeatureFlags & nFeature); }
284 624 : SvxNumRuleFlags GetFeatureFlags() const {return nFeatureFlags;}
285 0 : void SetFeatureFlag( SvxNumRuleFlags nFlag, bool bSet = true ) { if(bSet) nFeatureFlags |= nFlag; else nFeatureFlags &= ~nFlag; }
286 :
287 : OUString MakeNumString( const SvxNodeNum&, bool bInclStrings = true ) const;
288 :
289 3176 : SvxNumRuleType GetNumRuleType() const { return eNumberingType; }
290 : void SetNumRuleType( const SvxNumRuleType& rType ) { eNumberingType = rType; }
291 :
292 : bool UnLinkGraphics();
293 : };
294 :
295 : class EDITENG_DLLPUBLIC SvxNumBulletItem : public SfxPoolItem
296 : {
297 : SvxNumRule* pNumRule;
298 : public:
299 : explicit SvxNumBulletItem(SvxNumRule& rRule);
300 : SvxNumBulletItem(SvxNumRule& rRule, sal_uInt16 nWhich );
301 : SvxNumBulletItem(const SvxNumBulletItem& rCopy);
302 : virtual ~SvxNumBulletItem();
303 :
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;
309 :
310 269587 : SvxNumRule* GetNumRule() const {return pNumRule;}
311 :
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;
314 : };
315 :
316 : class SvxNodeNum
317 : {
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
322 :
323 : public:
324 : explicit inline SvxNodeNum( sal_uInt8 nLevel = SVX_NO_NUM, sal_uInt16 nSetVal = USHRT_MAX );
325 : inline SvxNodeNum& operator=( const SvxNodeNum& rCpy );
326 :
327 0 : sal_uInt8 GetLevel() const { return nMyLevel; }
328 0 : void SetLevel( sal_uInt8 nVal ) { nMyLevel = nVal; }
329 :
330 : bool IsStart() const { return bStartNum; }
331 : void SetStart( bool bFlag = true ) { bStartNum = bFlag; }
332 :
333 : sal_uInt16 GetSetValue() const { return nSetValue; }
334 : void SetSetValue( sal_uInt16 nVal ) { nSetValue = nVal; }
335 :
336 0 : const sal_uInt16* GetLevelVal() const { return nLevelVal; }
337 0 : sal_uInt16* GetLevelVal() { return nLevelVal; }
338 : };
339 :
340 0 : SvxNodeNum::SvxNodeNum( sal_uInt8 nLevel, sal_uInt16 nSetVal )
341 0 : : nSetValue( nSetVal ), nMyLevel( nLevel ), bStartNum( false )
342 : {
343 0 : memset( nLevelVal, 0, sizeof( nLevelVal ) );
344 0 : }
345 :
346 : inline SvxNodeNum& SvxNodeNum::operator=( const SvxNodeNum& rCpy )
347 : {
348 : if ( &rCpy != this)
349 : {
350 : nSetValue = rCpy.nSetValue;
351 : nMyLevel = rCpy.nMyLevel;
352 : bStartNum = rCpy.bStartNum;
353 :
354 : memcpy( nLevelVal, rCpy.nLevelVal, sizeof( nLevelVal ) );
355 : }
356 : return *this;
357 : }
358 :
359 : SvxNumRule* SvxConvertNumRule( const SvxNumRule* pRule, sal_uInt16 nLevel, SvxNumRuleType eType );
360 :
361 : #endif
362 :
363 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|