fix direct leaks in vcl cppunit tests
[LibreOffice.git] / include / editeng / numitem.hxx
blobbaa6ad3204e151707a02b091720cb2c6652863d1
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 <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 <unotools/fontcvt.hxx>
30 #include <editeng/editengdllapi.h>
31 #include <o3tl/typed_flags_set.hxx>
32 #include <vcl/vclenum.hxx>
33 #include <vcl/font.hxx>
34 #include <memory>
35 #include <optional>
36 #include <algorithm>
38 class SvxBrushItem;
39 class Graphic;
40 class SvxNodeNum;
41 namespace com::sun::star::text { class XNumberingFormatter; }
43 namespace com::sun::star::lang { struct Locale; }
46 #define SVX_NO_NUM 200 // Marker for no numbering
47 #define SVX_NO_NUMLEVEL 0x20
48 #define SVX_NUM_REL_SIZE_MIN 25 // Lower limit for numbering relative size
51 #define LINK_TOKEN 0x80 //indicate linked bitmaps - for use in dialog only
53 typedef struct _xmlTextWriter* xmlTextWriterPtr;
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;
85 void dumpAsXml(xmlTextWriterPtr w) const;
88 class EDITENG_DLLPUBLIC SvxNumberFormat : public SvxNumberType
90 public:
91 enum SvxNumPositionAndSpaceMode
93 LABEL_WIDTH_AND_POSITION,
94 LABEL_ALIGNMENT
96 enum LabelFollowedBy
98 LISTTAB,
99 SPACE,
100 NOTHING,
101 NEWLINE
104 private:
105 OUString sPrefix;
106 OUString sSuffix;
107 std::optional<OUString> sListFormat; // Format string ">%1.%2<" can be used instead of prefix/suffix
108 // Right now it is optional value to distinguish empty list format
109 // and not set list format when we need to fallback to prefix/suffix.
111 SvxAdjust eNumAdjust;
113 sal_uInt8 nInclUpperLevels; // Take over numbers from the previous level.
114 sal_uInt16 nStart; // Start of counting
116 sal_UCS4 cBullet; // Symbol
117 sal_uInt16 nBulletRelSize; // percentage size of bullets
118 Color nBulletColor; // Bullet color
120 // mode indicating, if the position and spacing of the list label is
121 // determined by the former attributes (nFirstLineOffset, nAbsLSpace
122 // and nCharTextDistance) called position and spacing via label
123 // width and position (LABEL_WIDTH_AND_POSITION) or by the new attributes
124 // (meLabelFollowedBy, mnListtabPos, mnFirstLineIndent and mnIndentAt)
125 // called position and spacing via label alignment.
126 // Note 1: Attribute <eNumAdjust> is relevant for both modes.
127 // Note 2: The values of the former attributes are treated as 0, if mode
128 // LABEL_ALIGNMENT is active.
129 SvxNumPositionAndSpaceMode mePositionAndSpaceMode;
131 sal_Int32 nFirstLineOffset; // First line indent
132 sal_Int32 nAbsLSpace; // Distance Border<->Number
133 short nCharTextDistance; // Distance Number<->Text
135 // specifies what follows the list label before the text of the first line
136 // of the list item starts
137 LabelFollowedBy meLabelFollowedBy;
138 // specifies an additional list tab stop position for meLabelFollowedBy = LISTTAB
139 tools::Long mnListtabPos;
140 // specifies the first line indent
141 tools::Long mnFirstLineIndent;
142 // specifies the indent before the text, e.g. in L2R-layout the left margin
143 tools::Long mnIndentAt;
145 std::unique_ptr<SvxBrushItem>
146 pGraphicBrush;
147 sal_Int16 eVertOrient; // vertical alignment of a bitmap
149 Size aGraphicSize; // Always! in 1/100 mm
150 std::optional<vcl::Font>
151 pBulletFont; // Pointer to the bullet font
153 OUString sCharStyleName; // Character Style
155 public:
156 explicit SvxNumberFormat( SvxNumType nNumberingType );
157 SvxNumberFormat(const SvxNumberFormat& rFormat);
158 SvxNumberFormat( SvStream & rStream );
160 virtual ~SvxNumberFormat();
162 void Store(SvStream &rStream, FontToSubsFontConverter pConverter);
164 SvxNumberFormat& operator=( const SvxNumberFormat& );
165 bool operator==( const SvxNumberFormat& ) const;
166 bool operator!=( const SvxNumberFormat& rFmt) const {return !(*this == rFmt);}
168 void SetNumAdjust(SvxAdjust eSet) {eNumAdjust = eSet;}
169 SvxAdjust GetNumAdjust() const {return eNumAdjust;}
170 void SetPrefix(const OUString& rSet) { sPrefix = rSet;}
171 const OUString& GetPrefix() const { return sPrefix;}
172 void SetSuffix(const OUString& rSet) { sSuffix = rSet;}
173 const OUString& GetSuffix() const { return sSuffix;}
174 // Based on prefix and suffix initialize them (for backward compatibility) and generate listformat string
175 void SetListFormat(const OUString& rPrefix, const OUString& rSuffix, int nLevel);
176 void SetListFormat(std::optional<OUString> oSet = std::nullopt);
177 bool HasListFormat() const { return sListFormat.has_value(); }
178 OUString GetListFormat(bool bIncludePrefixSuffix = true) const;
180 void SetCharFormatName(const OUString& rSet){ sCharStyleName = rSet; }
181 virtual OUString GetCharFormatName()const;
183 void SetBulletFont(const vcl::Font* pFont);
184 const std::optional<vcl::Font>& GetBulletFont() const { return pBulletFont; }
185 void SetBulletChar(sal_UCS4 cSet){cBullet = cSet;}
186 sal_UCS4 GetBulletChar()const {return cBullet;}
187 void SetBulletRelSize(sal_uInt16 nSet) {nBulletRelSize = std::max(nSet,sal_uInt16(SVX_NUM_REL_SIZE_MIN));}
188 sal_uInt16 GetBulletRelSize() const { return nBulletRelSize;}
189 void SetBulletColor(Color nSet){nBulletColor = nSet;}
190 const Color& GetBulletColor()const {return nBulletColor;}
192 void SetIncludeUpperLevels( sal_uInt8 nSet ) { nInclUpperLevels = nSet;}
193 sal_uInt8 GetIncludeUpperLevels()const { return nInclUpperLevels;}
194 void SetStart(sal_uInt16 nSet) {nStart = nSet;}
195 sal_uInt16 GetStart() const {return nStart;}
197 virtual void SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = nullptr, const sal_Int16* pOrient = nullptr);
198 const SvxBrushItem* GetBrush() const {return pGraphicBrush.get();}
199 void SetGraphic( const OUString& rName );
200 sal_Int16 GetVertOrient() const;
201 void SetGraphicSize(const Size& rSet) {aGraphicSize = rSet;}
202 const Size& GetGraphicSize() const {return aGraphicSize;}
204 SvxNumPositionAndSpaceMode GetPositionAndSpaceMode() const { return mePositionAndSpaceMode;}
205 void SetPositionAndSpaceMode( SvxNumPositionAndSpaceMode ePositionAndSpaceMode );
207 void SetAbsLSpace(sal_Int32 nSet) {nAbsLSpace = nSet;}
208 sal_Int32 GetAbsLSpace() const;
209 void SetFirstLineOffset(sal_Int32 nSet) { nFirstLineOffset = nSet;}
210 sal_Int32 GetFirstLineOffset() const;
211 void SetCharTextDistance(short nSet) { nCharTextDistance = nSet; }
212 short GetCharTextDistance() const;
214 void SetLabelFollowedBy( const LabelFollowedBy eLabelFollowedBy );
215 LabelFollowedBy GetLabelFollowedBy() const { return meLabelFollowedBy;}
216 OUString GetLabelFollowedByAsString() const;
217 void SetListtabPos( const tools::Long nListtabPos );
218 tools::Long GetListtabPos() const { return mnListtabPos;}
219 void SetFirstLineIndent( const tools::Long nFirstLineIndent );
220 tools::Long GetFirstLineIndent() const { return mnFirstLineIndent;}
221 void SetIndentAt( const tools::Long nIndentAt );
222 tools::Long GetIndentAt() const { return mnIndentAt;}
224 static Size GetGraphicSizeMM100(const Graphic* pGraphic);
225 static OUString CreateRomanString( sal_Int32 nNo, bool bUpper );
228 //Feature-Flags (only sal_uInt16!)
229 enum class SvxNumRuleFlags : sal_uInt16
231 NONE = 0x0000,
232 CONTINUOUS = 0x0001, // consecutive numbers possible?
233 CHAR_STYLE = 0x0004, // Character styles?
234 BULLET_REL_SIZE = 0x0008, // relative bullet size?
235 BULLET_COLOR = 0x0010, // Bullet color
236 NO_NUMBERS = 0x0080, // Numbering are not allowed
237 ENABLE_LINKED_BMP = 0x0100, // linked bitmaps are available
238 ENABLE_EMBEDDED_BMP = 0x0200 // embedded bitmaps are available
240 namespace o3tl
242 template<> struct typed_flags<SvxNumRuleFlags> : is_typed_flags<SvxNumRuleFlags, 0x039d> {};
245 enum class SvxNumRuleType : sal_uInt8
247 NUMBERING,
248 OUTLINE_NUMBERING,
249 PRESENTATION_NUMBERING
252 class EDITENG_DLLPUBLIC SvxNumRule final
254 std::unique_ptr<SvxNumberFormat> aFmts[SVX_MAX_NUM];
255 sal_uInt16 nLevelCount; // Number of supported levels
256 SvxNumRuleFlags nFeatureFlags; // What is supported?
257 SvxNumRuleType eNumberingType; // Type of numbering
258 bool bContinuousNumbering; // sequential numbering
259 bool aFmtsSet[SVX_MAX_NUM]; // Flags indicating valid levels
261 static sal_Int32 nRefCount;
262 public:
263 SvxNumRule( SvxNumRuleFlags nFeatures,
264 sal_uInt16 nLevels,
265 bool bCont,
266 SvxNumRuleType eType = SvxNumRuleType::NUMBERING,
267 SvxNumberFormat::SvxNumPositionAndSpaceMode
268 eDefaultNumberFormatPositionAndSpaceMode
269 = SvxNumberFormat::LABEL_WIDTH_AND_POSITION );
270 SvxNumRule(const SvxNumRule& rCopy);
271 SvxNumRule(SvxNumRule&&) noexcept;
272 SvxNumRule(SvStream &rStream);
273 ~SvxNumRule();
275 bool operator==( const SvxNumRule& ) const;
276 bool operator!=( const SvxNumRule& rRule ) const {return !(*this == rRule);}
278 SvxNumRule& operator=( const SvxNumRule& );
279 SvxNumRule& operator=( SvxNumRule&& ) noexcept;
281 void Store(SvStream &rStream);
282 void dumpAsXml(xmlTextWriterPtr pWriter) const;
283 const SvxNumberFormat* Get(sal_uInt16 nLevel)const;
284 const SvxNumberFormat& GetLevel(sal_uInt16 nLevel)const;
285 void SetLevel(sal_uInt16 nLevel, const SvxNumberFormat& rFmt, bool bIsValid = true);
286 void SetLevel(sal_uInt16 nLevel, const SvxNumberFormat* pFmt);
288 bool IsContinuousNumbering()const
289 {return bContinuousNumbering;}
290 void SetContinuousNumbering(bool bSet)
291 {bContinuousNumbering = bSet;}
293 sal_uInt16 GetLevelCount() const {return nLevelCount;}
294 bool IsFeatureSupported(SvxNumRuleFlags nFeature) const
295 { return bool(nFeatureFlags & nFeature); }
296 SvxNumRuleFlags GetFeatureFlags() const {return nFeatureFlags;}
297 void SetFeatureFlag( SvxNumRuleFlags nFlag, bool bSet = true ) { if(bSet) nFeatureFlags |= nFlag; else nFeatureFlags &= ~nFlag; }
299 OUString MakeNumString( const SvxNodeNum& ) const;
301 SvxNumRuleType GetNumRuleType() const { return eNumberingType; }
303 void UnLinkGraphics();
306 class EDITENG_DLLPUBLIC SvxNumBulletItem final : public SfxPoolItem
308 SvxNumRule maNumRule;
309 public:
310 explicit SvxNumBulletItem(SvxNumRule const & rRule);
311 explicit SvxNumBulletItem(SvxNumRule && rRule);
312 SvxNumBulletItem(SvxNumRule const & rRule, sal_uInt16 nWhich );
313 SvxNumBulletItem(SvxNumRule && rRule, sal_uInt16 nWhich );
314 SvxNumBulletItem(const SvxNumBulletItem& rCopy);
315 virtual ~SvxNumBulletItem() override;
317 virtual SvxNumBulletItem* Clone( SfxItemPool *pPool = nullptr ) const override;
318 virtual bool operator==( const SfxPoolItem& ) const override;
320 const SvxNumRule& GetNumRule() const { return maNumRule; }
321 SvxNumRule& GetNumRule() { return maNumRule; }
323 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
324 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
325 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
328 class SvxNodeNum
330 sal_uInt16 nLevelVal[ SVX_MAX_NUM ] = {}; // Numbers of all levels
331 sal_uInt8 nMyLevel = 0; // Current Level
333 public:
334 explicit inline SvxNodeNum() = default;
335 inline SvxNodeNum& operator=( const SvxNodeNum& rCpy );
337 sal_uInt8 GetLevel() const { return nMyLevel; }
338 void SetLevel( sal_uInt8 nVal ) { nMyLevel = nVal; }
340 const sal_uInt16* GetLevelVal() const { return nLevelVal; }
341 sal_uInt16* GetLevelVal() { return nLevelVal; }
344 inline SvxNodeNum& SvxNodeNum::operator=( const SvxNodeNum& rCpy )
346 if ( &rCpy != this)
348 nMyLevel = rCpy.nMyLevel;
350 memcpy( nLevelVal, rCpy.nLevelVal, sizeof( nLevelVal ) );
352 return *this;
355 SvxNumRule SvxConvertNumRule( const SvxNumRule& rRule, sal_uInt16 nLevel, SvxNumRuleType eType );
357 #endif
359 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */