/src/libreoffice/include/editeng/numitem.hxx
Line | Count | Source (jump to first uncovered line) |
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 <svl/poolitem.hxx> |
24 | | #include <editeng/svxenum.hxx> |
25 | | #include <tools/gen.hxx> |
26 | | #include <editeng/numdef.hxx> |
27 | | #include <tools/color.hxx> |
28 | | #include <com/sun/star/style/NumberingType.hpp> |
29 | | #include <com/sun/star/util/MeasureUnit.hpp> |
30 | | #include <unotools/fontcvt.hxx> |
31 | | #include <editeng/editengdllapi.h> |
32 | | #include <o3tl/typed_flags_set.hxx> |
33 | | #include <vcl/vclenum.hxx> |
34 | | #include <vcl/font.hxx> |
35 | | #include <memory> |
36 | | #include <optional> |
37 | | #include <algorithm> |
38 | | |
39 | | class SvxBrushItem; |
40 | | class Graphic; |
41 | | class SvxNodeNum; |
42 | | namespace com::sun::star::text { class XNumberingFormatter; } |
43 | | |
44 | | namespace com::sun::star::lang { struct Locale; } |
45 | | |
46 | | |
47 | 0 | #define SVX_NO_NUM 200 // Marker for no numbering |
48 | 0 | #define SVX_NO_NUMLEVEL 0x20 |
49 | 2.53M | #define SVX_NUM_REL_SIZE_MIN 25 // Lower limit for numbering relative size |
50 | | |
51 | | |
52 | 44.1k | #define LINK_TOKEN 0x80 //indicate linked bitmaps - for use in dialog only |
53 | | |
54 | | typedef struct _xmlTextWriter* xmlTextWriterPtr; |
55 | | |
56 | | class EDITENG_DLLPUBLIC SvxNumberType |
57 | | { |
58 | | static sal_Int32 nRefCount; |
59 | | static css::uno::Reference<css::text::XNumberingFormatter> xFormatter; |
60 | | |
61 | | SvxNumType nNumType; |
62 | | bool bShowSymbol; // Also show Symbol ? |
63 | | |
64 | | public: |
65 | | explicit SvxNumberType(SvxNumType nType = SVX_NUM_ARABIC); |
66 | | SvxNumberType(const SvxNumberType& rType); |
67 | | ~SvxNumberType(); |
68 | 359k | SvxNumberType & operator =(SvxNumberType const &) = default; |
69 | | |
70 | | OUString GetNumStr( sal_Int32 nNo ) const; |
71 | | OUString GetNumStr( sal_Int32 nNo, const css::lang::Locale& rLocale, bool bIsLegal = false ) const; |
72 | | |
73 | 24.2M | void SetNumberingType(SvxNumType nSet) {nNumType = nSet;} |
74 | 86.9M | SvxNumType GetNumberingType() const {return nNumType;} |
75 | | |
76 | 20.0M | void SetShowSymbol(bool bSet) {bShowSymbol = bSet;} |
77 | 31.9M | bool IsShowSymbol()const{return bShowSymbol;} |
78 | | |
79 | | bool IsTextFormat() const |
80 | 3.69k | { |
81 | 3.69k | return css::style::NumberingType::NUMBER_NONE != nNumType && |
82 | 3.69k | css::style::NumberingType::CHAR_SPECIAL != nNumType && |
83 | 3.69k | css::style::NumberingType::BITMAP != nNumType; |
84 | 3.69k | } |
85 | | |
86 | | virtual void dumpAsXml(xmlTextWriterPtr w) const; |
87 | | }; |
88 | | |
89 | | class EDITENG_DLLPUBLIC SvxNumberFormat : public SvxNumberType |
90 | | { |
91 | | public: |
92 | | enum SvxNumPositionAndSpaceMode |
93 | | { |
94 | | LABEL_WIDTH_AND_POSITION, |
95 | | LABEL_ALIGNMENT |
96 | | }; |
97 | | enum LabelFollowedBy |
98 | | { |
99 | | LISTTAB, |
100 | | SPACE, |
101 | | NOTHING, |
102 | | NEWLINE |
103 | | }; |
104 | | |
105 | | private: |
106 | | OUString sPrefix; |
107 | | OUString sSuffix; |
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. |
111 | | |
112 | | SvxAdjust eNumAdjust; |
113 | | |
114 | | sal_uInt8 nInclUpperLevels; // Take over numbers from the previous level. |
115 | | sal_uInt16 nStart; // Start of counting |
116 | | |
117 | | sal_UCS4 cBullet; // Symbol |
118 | | sal_uInt16 nBulletRelSize; // percentage size of bullets |
119 | | Color nBulletColor; // Bullet color |
120 | | |
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; |
131 | | |
132 | | sal_Int32 nFirstLineOffset; // First line indent |
133 | | sal_Int16 nFirstLineOffsetUnit = css::util::MeasureUnit::TWIP; |
134 | | sal_Int32 nAbsLSpace; // Distance Border<->Number |
135 | | short nCharTextDistance; // Distance Number<->Text |
136 | | |
137 | | // specifies what follows the list label before the text of the first line |
138 | | // of the list item starts |
139 | | LabelFollowedBy meLabelFollowedBy; |
140 | | // specifies an additional list tab stop position for meLabelFollowedBy = LISTTAB |
141 | | tools::Long mnListtabPos; |
142 | | // specifies the first line indent |
143 | | tools::Long mnFirstLineIndent; |
144 | | sal_Int16 mnFirstLineIndentUnit = css::util::MeasureUnit::TWIP; |
145 | | // specifies the indent before the text, e.g. in L2R-layout the left margin |
146 | | tools::Long mnIndentAt; |
147 | | |
148 | | std::unique_ptr<SvxBrushItem> |
149 | | pGraphicBrush; |
150 | | sal_Int16 eVertOrient; // vertical alignment of a bitmap |
151 | | |
152 | | Size aGraphicSize; // Always! in 1/100 mm |
153 | | std::optional<vcl::Font> |
154 | | pBulletFont; // Pointer to the bullet font |
155 | | |
156 | | OUString sCharStyleName; // Character Style |
157 | | |
158 | | bool mbIsLegal = false; // "Legal" level numbering = all levels use arabic numbering |
159 | | |
160 | | public: |
161 | | explicit SvxNumberFormat( SvxNumType nNumberingType ); |
162 | | SvxNumberFormat(const SvxNumberFormat& rFormat); |
163 | | SvxNumberFormat( SvStream & rStream ); |
164 | | |
165 | | virtual ~SvxNumberFormat(); |
166 | | |
167 | | void Store(SvStream &rStream, FontToSubsFontConverter pConverter); |
168 | | |
169 | | SvxNumberFormat& operator=( const SvxNumberFormat& ); |
170 | | bool operator==( const SvxNumberFormat& ) const; |
171 | 5.05M | bool operator!=( const SvxNumberFormat& rFmt) const {return !(*this == rFmt);} |
172 | | |
173 | 513k | void SetNumAdjust(SvxAdjust eSet) {eNumAdjust = eSet;} |
174 | 417k | SvxAdjust GetNumAdjust() const {return eNumAdjust;} |
175 | | void SetPrefix(const OUString& rSet); |
176 | 23.0M | const OUString& GetPrefix() const { return sPrefix;} |
177 | | void SetSuffix(const OUString& rSet); |
178 | 23.0M | const OUString& GetSuffix() const { return sSuffix;} |
179 | | // Based on prefix and suffix initialize them (for backward compatibility) and generate listformat string |
180 | | void SetListFormat(const OUString& rPrefix, const OUString& rSuffix, int nLevel); |
181 | | void SetListFormat(std::optional<OUString> oSet = std::nullopt); |
182 | 14.2k | bool HasListFormat() const { return sListFormat.has_value(); } |
183 | | OUString GetListFormat(bool bIncludePrefixSuffix = true) const; |
184 | | |
185 | 37.8k | void SetCharFormatName(const OUString& rSet){ sCharStyleName = rSet; } |
186 | | virtual OUString GetCharFormatName()const; |
187 | | |
188 | | void SetBulletFont(const vcl::Font* pFont); |
189 | 87.8k | const std::optional<vcl::Font>& GetBulletFont() const { return pBulletFont; } |
190 | 7.08M | void SetBulletChar(sal_UCS4 cSet){cBullet = cSet;} |
191 | 20.8M | sal_UCS4 GetBulletChar()const {return cBullet;} |
192 | 2.53M | void SetBulletRelSize(sal_uInt16 nSet) {nBulletRelSize = std::max(nSet,sal_uInt16(SVX_NUM_REL_SIZE_MIN));} |
193 | 85.3k | sal_uInt16 GetBulletRelSize() const { return nBulletRelSize;} |
194 | 2.01M | void SetBulletColor(Color nSet){nBulletColor = nSet;} |
195 | 85.3k | const Color& GetBulletColor()const {return nBulletColor;} |
196 | | |
197 | 4.00M | void SetIncludeUpperLevels( sal_uInt8 nSet ) { nInclUpperLevels = nSet;} |
198 | 292k | sal_uInt8 GetIncludeUpperLevels()const { return nInclUpperLevels;} |
199 | 5.24M | void SetStart(sal_uInt16 nSet) {nStart = nSet;} |
200 | 236k | sal_uInt16 GetStart() const {return nStart;} |
201 | | |
202 | | virtual void SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = nullptr, const sal_Int16* pOrient = nullptr); |
203 | 7.70M | const SvxBrushItem* GetBrush() const {return pGraphicBrush.get();} |
204 | | void SetGraphic( const OUString& rName ); |
205 | | sal_Int16 GetVertOrient() const; |
206 | 3.01k | void SetGraphicSize(const Size& rSet) {aGraphicSize = rSet;} |
207 | 7.66M | const Size& GetGraphicSize() const {return aGraphicSize;} |
208 | | |
209 | 998k | SvxNumPositionAndSpaceMode GetPositionAndSpaceMode() const { return mePositionAndSpaceMode;} |
210 | | void SetPositionAndSpaceMode( SvxNumPositionAndSpaceMode ePositionAndSpaceMode ); |
211 | | |
212 | 6.52M | void SetAbsLSpace(sal_Int32 nSet) {nAbsLSpace = nSet;} |
213 | | sal_Int32 GetAbsLSpace() const; |
214 | 3.19M | void SetFirstLineOffset(sal_Int32 nSet) { nFirstLineOffset = nSet;} |
215 | | sal_Int32 GetFirstLineOffset() const; |
216 | 0 | sal_Int16 GetFirstLineOffsetUnit() const { return nFirstLineOffsetUnit; } |
217 | 1.06M | void SetCharTextDistance(short nSet) { nCharTextDistance = nSet; } |
218 | | short GetCharTextDistance() const; |
219 | | |
220 | | void SetLabelFollowedBy( const LabelFollowedBy eLabelFollowedBy ); |
221 | 40.5k | LabelFollowedBy GetLabelFollowedBy() const { return meLabelFollowedBy;} |
222 | | OUString GetLabelFollowedByAsString() const; |
223 | | void SetListtabPos( const tools::Long nListtabPos ); |
224 | 14.7k | tools::Long GetListtabPos() const { return mnListtabPos;} |
225 | | void SetFirstLineIndent( const tools::Long nFirstLineIndent ); |
226 | 272k | tools::Long GetFirstLineIndent() const { return mnFirstLineIndent;} |
227 | 147k | sal_Int16 GetFirstLineIndentUnit() const { return mnFirstLineIndentUnit; } |
228 | | void SetIndentAt( const tools::Long nIndentAt ); |
229 | 259k | tools::Long GetIndentAt() const { return mnIndentAt;} |
230 | | |
231 | | static Size GetGraphicSizeMM100(const Graphic* pGraphic); |
232 | | static OUString CreateRomanString( sal_Int32 nNo, bool bUpper ); |
233 | | |
234 | 14.3k | bool GetIsLegal() const { return mbIsLegal; } |
235 | 239k | void SetIsLegal(bool val) { mbIsLegal = val; } |
236 | | |
237 | | void dumpAsXml(xmlTextWriterPtr w) const override; |
238 | | }; |
239 | | |
240 | | //Feature-Flags (only sal_uInt16!) |
241 | | enum class SvxNumRuleFlags : sal_uInt16 |
242 | | { |
243 | | NONE = 0x0000, |
244 | | CONTINUOUS = 0x0001, // consecutive numbers possible? |
245 | | CHAR_STYLE = 0x0004, // Character styles? |
246 | | BULLET_REL_SIZE = 0x0008, // relative bullet size? |
247 | | BULLET_COLOR = 0x0010, // Bullet color |
248 | | NO_NUMBERS = 0x0080, // Numbering are not allowed |
249 | | ENABLE_LINKED_BMP = 0x0100, // linked bitmaps are available |
250 | | ENABLE_EMBEDDED_BMP = 0x0200 // embedded bitmaps are available |
251 | | }; |
252 | | namespace o3tl |
253 | | { |
254 | | template<> struct typed_flags<SvxNumRuleFlags> : is_typed_flags<SvxNumRuleFlags, 0x039d> {}; |
255 | | } |
256 | | |
257 | | enum class SvxNumRuleType : sal_uInt8 |
258 | | { |
259 | | NUMBERING, |
260 | | OUTLINE_NUMBERING, |
261 | | PRESENTATION_NUMBERING |
262 | | }; |
263 | | |
264 | | class EDITENG_DLLPUBLIC SvxNumRule final |
265 | | { |
266 | | std::unique_ptr<SvxNumberFormat> aFmts[SVX_MAX_NUM]; |
267 | | sal_uInt16 nLevelCount; // Number of supported levels |
268 | | SvxNumRuleFlags nFeatureFlags; // What is supported? |
269 | | SvxNumRuleType eNumberingType; // Type of numbering |
270 | | bool bContinuousNumbering; // sequential numbering |
271 | | bool aFmtsSet[SVX_MAX_NUM]; // Flags indicating valid levels |
272 | | |
273 | | static sal_Int32 nRefCount; |
274 | | public: |
275 | | SvxNumRule( SvxNumRuleFlags nFeatures, |
276 | | sal_uInt16 nLevels, |
277 | | bool bCont, |
278 | | SvxNumRuleType eType = SvxNumRuleType::NUMBERING, |
279 | | SvxNumberFormat::SvxNumPositionAndSpaceMode |
280 | | eDefaultNumberFormatPositionAndSpaceMode |
281 | | = SvxNumberFormat::LABEL_WIDTH_AND_POSITION ); |
282 | | SvxNumRule(const SvxNumRule& rCopy); |
283 | | SvxNumRule(SvxNumRule&&) noexcept; |
284 | | SvxNumRule(SvStream &rStream); |
285 | | ~SvxNumRule(); |
286 | | |
287 | | bool operator==( const SvxNumRule& ) const; |
288 | 0 | bool operator!=( const SvxNumRule& rRule ) const {return !(*this == rRule);} |
289 | | |
290 | | SvxNumRule& operator=( const SvxNumRule& ); |
291 | | SvxNumRule& operator=( SvxNumRule&& ) noexcept; |
292 | | |
293 | | void Store(SvStream &rStream); |
294 | | void dumpAsXml(xmlTextWriterPtr pWriter) const; |
295 | | const SvxNumberFormat* Get(sal_uInt16 nLevel)const; |
296 | | const SvxNumberFormat& GetLevel(sal_uInt16 nLevel)const; |
297 | | void SetLevel(sal_uInt16 nLevel, const SvxNumberFormat& rFmt, bool bIsValid = true); |
298 | | void SetLevel(sal_uInt16 nLevel, const SvxNumberFormat* pFmt); |
299 | | |
300 | | bool IsContinuousNumbering()const |
301 | 4.42k | {return bContinuousNumbering;} |
302 | | void SetContinuousNumbering(bool bSet) |
303 | 0 | {bContinuousNumbering = bSet;} |
304 | | |
305 | 28.0M | sal_uInt16 GetLevelCount() const {return nLevelCount;} |
306 | | bool IsFeatureSupported(SvxNumRuleFlags nFeature) const |
307 | 0 | { return bool(nFeatureFlags & nFeature); } |
308 | 105k | SvxNumRuleFlags GetFeatureFlags() const {return nFeatureFlags;} |
309 | 0 | void SetFeatureFlag( SvxNumRuleFlags nFlag, bool bSet = true ) { if(bSet) nFeatureFlags |= nFlag; else nFeatureFlags &= ~nFlag; } |
310 | | |
311 | | OUString MakeNumString( const SvxNodeNum& ) const; |
312 | | |
313 | 178k | SvxNumRuleType GetNumRuleType() const { return eNumberingType; } |
314 | | |
315 | | void UnLinkGraphics(); |
316 | | }; |
317 | | |
318 | | class EDITENG_DLLPUBLIC SvxNumBulletItem final : public SfxPoolItem |
319 | | { |
320 | | SvxNumRule maNumRule; |
321 | | public: |
322 | | DECLARE_ITEM_TYPE_FUNCTION(SvxNumBulletItem) |
323 | | explicit SvxNumBulletItem(SvxNumRule const & rRule); |
324 | | explicit SvxNumBulletItem(SvxNumRule && rRule); |
325 | | SvxNumBulletItem(SvxNumRule const & rRule, sal_uInt16 nWhich ); |
326 | | SvxNumBulletItem(SvxNumRule && rRule, sal_uInt16 nWhich ); |
327 | | SvxNumBulletItem(const SvxNumBulletItem& rCopy); |
328 | | virtual ~SvxNumBulletItem() override; |
329 | | |
330 | | virtual SvxNumBulletItem* Clone( SfxItemPool *pPool = nullptr ) const override; |
331 | | virtual bool operator==( const SfxPoolItem& ) const override; |
332 | | |
333 | 47.6M | const SvxNumRule& GetNumRule() const { return maNumRule; } |
334 | 134k | SvxNumRule& GetNumRule() { return maNumRule; } |
335 | | |
336 | | virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override; |
337 | | virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override; |
338 | | virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override; |
339 | | }; |
340 | | |
341 | | class SvxNodeNum |
342 | | { |
343 | | sal_uInt16 nLevelVal[ SVX_MAX_NUM ] = {}; // Numbers of all levels |
344 | | sal_uInt8 nMyLevel = 0; // Current Level |
345 | | |
346 | | public: |
347 | | explicit inline SvxNodeNum() = default; |
348 | | inline SvxNodeNum& operator=( const SvxNodeNum& rCpy ); |
349 | | |
350 | 0 | sal_uInt8 GetLevel() const { return nMyLevel; } |
351 | 0 | void SetLevel( sal_uInt8 nVal ) { nMyLevel = nVal; } |
352 | | |
353 | 0 | const sal_uInt16* GetLevelVal() const { return nLevelVal; } |
354 | 0 | sal_uInt16* GetLevelVal() { return nLevelVal; } |
355 | | }; |
356 | | |
357 | | inline SvxNodeNum& SvxNodeNum::operator=( const SvxNodeNum& rCpy ) |
358 | 0 | { |
359 | 0 | if ( &rCpy != this) |
360 | 0 | { |
361 | 0 | nMyLevel = rCpy.nMyLevel; |
362 | 0 |
|
363 | 0 | memcpy( nLevelVal, rCpy.nLevelVal, sizeof( nLevelVal ) ); |
364 | 0 | } |
365 | 0 | return *this; |
366 | 0 | } |
367 | | |
368 | | SvxNumRule SvxConvertNumRule( const SvxNumRule& rRule, sal_uInt16 nLevel, SvxNumRuleType eType ); |
369 | | |
370 | | #endif |
371 | | |
372 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |