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_SW_INC_NUMRULE_HXX
20 #define INCLUDED_SW_INC_NUMRULE_HXX
22 #include <sal/types.h>
23 #include <rtl/ustring.hxx>
24 #include <editeng/svxenum.hxx>
25 #include <editeng/numitem.hxx>
27 #include <swtypes.hxx>
30 #include <SwNumberTreeTypes.hxx>
32 #include <unordered_map>
34 #include <charfmt.hxx>
36 class SwTextFormatColl
;
37 class IDocumentListsAccess
;
39 namespace vcl
{ class Font
; }
44 class SwFormatVertOrient
;
48 const sal_Unicode cBulletChar
= 0x2022; ///< Character for lists.
50 class SW_DLLPUBLIC SwNumFormat
: public SvxNumberFormat
, public SwClient
52 SwFormatVertOrient
* pVertOrient
;
53 //For i120928,record the cp info of graphic within bullet
54 sal_Unicode cGrfBulletCP
;
55 SAL_DLLPRIVATE
void UpdateNumNodes( SwDoc
* pDoc
);
56 SAL_DLLPRIVATE
virtual void NotifyGraphicArrived() SAL_OVERRIDE
;
58 using SvxNumberFormat::operator ==;
59 using SvxNumberFormat::operator !=;
62 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
* pNew
) SAL_OVERRIDE
;
66 SwNumFormat( const SwNumFormat
& );
67 SwNumFormat( const SvxNumberFormat
&, SwDoc
* pDoc
);
69 virtual ~SwNumFormat();
71 SwNumFormat
& operator=( const SwNumFormat
& );
73 bool operator==( const SwNumFormat
& ) const;
74 bool operator!=( const SwNumFormat
& r
) const { return !(*this == r
); }
76 SwCharFormat
* GetCharFormat() const { return const_cast<SwCharFormat
*>(static_cast<const SwCharFormat
*>(GetRegisteredIn())); }
77 void SetCharFormat( SwCharFormat
* );
79 void SetCharFormatName(const OUString
& rSet
);
80 virtual OUString
GetCharFormatName() const SAL_OVERRIDE
;
82 //For i120928,access the cp info of graphic within bullet
83 void SetGrfBulletCP(sal_Unicode cP
){cGrfBulletCP
= cP
;}
84 sal_Unicode
GetGrfBulletCP() const {return cGrfBulletCP
;}
86 virtual void SetGraphicBrush( const SvxBrushItem
* pBrushItem
, const Size
* pSize
= 0, const sal_Int16
* pOrient
= 0) SAL_OVERRIDE
;
88 virtual void SetVertOrient(sal_Int16 eSet
) SAL_OVERRIDE
;
89 virtual sal_Int16
GetVertOrient() const SAL_OVERRIDE
;
90 const SwFormatVertOrient
* GetGraphicOrientation() const;
92 bool IsEnumeration() const; // #i22362#
93 bool IsItemize() const; // #i29560#
97 enum SwNumRuleType
{ OUTLINE_RULE
= 0, NUM_RULE
= 1, RULE_END
= 2 };
98 class SW_DLLPUBLIC SwNumRule
102 typedef std::vector
< SwTextNode
* > tTextNodeList
;
103 typedef std::vector
< SwTextFormatColl
* > tParagraphStyleList
;
107 sal_uInt16 nPrefixChars
;
108 sal_uInt16 nSuffixChars
;
112 friend void _FinitCore();
114 static SwNumFormat
* maBaseFormats
[ RULE_END
][ MAXLEVEL
];
115 static const sal_uInt16 maDefNumIndents
[ MAXLEVEL
];
116 /// default list level properties for position-and-space mode LABEL_ALIGNMENT
117 static SwNumFormat
* maLabelAlignmentBaseFormats
[ RULE_END
][ MAXLEVEL
];
118 static sal_uInt16 mnRefCount
;
120 SwNumFormat
* maFormats
[ MAXLEVEL
];
122 /** container for associated text nodes */
123 tTextNodeList maTextNodeList
;
125 /** container for associated paragraph styles */
126 tParagraphStyleList maParagraphStyleList
;
128 /** unordered_map containing "name->rule" relation */
129 std::unordered_map
<OUString
, SwNumRule
*, OUStringHash
> * mpNumRuleMap
;
132 SwNumRuleType meRuleType
;
133 sal_uInt16 mnPoolFormatId
; ///< Id-for NumRules created "automatically"
134 sal_uInt16 mnPoolHelpId
; ///< HelpId for this Pool-style.
135 sal_uInt8 mnPoolHlpFileId
; ///< FilePos at Doc on style helps.
136 bool mbAutoRuleFlag
: 1;
137 bool mbInvalidRuleFlag
: 1;
138 bool mbContinusNum
: 1; ///< Continuous numbering without levels.
139 bool mbAbsSpaces
: 1; ///< Levels represent absolute indents.
140 bool mbHidden
: 1; ///< Is the numering rule to be hidden in the UI?
141 bool mbCountPhantoms
;
143 const SvxNumberFormat::SvxNumPositionAndSpaceMode meDefaultNumberFormatPositionAndSpaceMode
;
144 OUString msDefaultListId
;
145 boost::shared_ptr
<SfxGrabBagItem
> mpGrabBagItem
; ///< Style InteropGrabBag.
148 /// add parameter <eDefaultNumberFormatPositionAndSpaceMode>
149 SwNumRule( const OUString
& rNm
,
150 const SvxNumberFormat::SvxNumPositionAndSpaceMode eDefaultNumberFormatPositionAndSpaceMode
,
151 SwNumRuleType
= NUM_RULE
,
152 bool bAutoFlg
= true );
154 SwNumRule( const SwNumRule
& );
157 SwNumRule
& operator=( const SwNumRule
& );
158 bool operator==( const SwNumRule
& ) const;
159 bool operator!=( const SwNumRule
& r
) const { return !(*this == r
); }
161 const SwNumFormat
* GetNumFormat( sal_uInt16 i
) const;
162 const SwNumFormat
& Get( sal_uInt16 i
) const;
164 bool IsHidden( ) const { return mbHidden
; }
165 void SetHidden( bool bValue
) { mbHidden
= bValue
; }
167 void Set( sal_uInt16 i
, const SwNumFormat
* );
168 void Set( sal_uInt16 i
, const SwNumFormat
& );
169 OUString
MakeNumString( const SwNodeNum
&, bool bInclStrings
= true,
170 bool bOnlyArabic
= false ) const;
171 /** - add optional parameter <_nRestrictToThisLevel> in order to
172 restrict returned string to this level. */
173 OUString
MakeNumString( const SwNumberTree::tNumberVector
& rNumVector
,
174 const bool bInclStrings
= true,
175 const bool bOnlyArabic
= false,
176 const unsigned int _nRestrictToThisLevel
= MAXLEVEL
,
177 Extremities
* pExtremities
= 0 ) const;
178 OUString
MakeRefNumString( const SwNodeNum
& rNodeNum
,
179 const bool bInclSuperiorNumLabels
= false,
180 const sal_uInt8 nRestrictInclToThisLevel
= 0 ) const;
184 @return list of associated text nodes
186 void GetTextNodeList( SwNumRule::tTextNodeList
& rTextNodeList
) const;
187 SwNumRule::tTextNodeList::size_type
GetTextNodeListSize() const;
189 void AddTextNode( SwTextNode
& rTextNode
);
190 void RemoveTextNode( SwTextNode
& rTextNode
);
192 SwNumRule::tParagraphStyleList::size_type
GetParagraphStyleListSize() const;
193 void AddParagraphStyle( SwTextFormatColl
& rTextFormatColl
);
194 void RemoveParagraphStyle( SwTextFormatColl
& rTextFormatColl
);
196 inline void SetDefaultListId( const OUString
& sDefaultListId
)
198 msDefaultListId
= sDefaultListId
;
200 inline OUString
GetDefaultListId() const
202 return msDefaultListId
;
205 Register this rule in a "name->numrule" map.
207 @param pNumRuleMap map to register in
210 std::unordered_map
<OUString
, SwNumRule
*, OUStringHash
>* pNumRuleMap
);
212 static OUString
GetOutlineRuleName();
214 static sal_uInt16
GetNumIndent( sal_uInt8 nLvl
);
215 static sal_uInt16
GetBullIndent( sal_uInt8 nLvl
);
217 SwNumRuleType
GetRuleType() const { return meRuleType
; }
218 void SetRuleType( SwNumRuleType eNew
) { meRuleType
= eNew
;
219 mbInvalidRuleFlag
= true; }
221 /** A kind of copy-constructor to make sure the num formats are
222 attached to the correctCharFormats of a document!!
223 (Copies the NumFormats and returns itself). */
224 SwNumRule
& CopyNumRule( SwDoc
*, const SwNumRule
& );
226 /** Tests whether the CharFormats are from the given doc
227 and copies them if appropriate. */
228 void CheckCharFormats( SwDoc
* pDoc
);
230 OUString
GetName() const { return msName
; }
232 void SetName( const OUString
& rNm
,
233 IDocumentListsAccess
& rDocListAccess
);
235 bool IsAutoRule() const { return mbAutoRuleFlag
; }
236 void SetAutoRule( bool bFlag
) { mbAutoRuleFlag
= bFlag
; }
238 bool IsInvalidRule() const { return mbInvalidRuleFlag
; }
239 void SetInvalidRule( bool bFlag
);
241 bool IsContinusNum() const { return mbContinusNum
; }
242 void SetContinusNum( bool bFlag
) { mbContinusNum
= bFlag
; }
244 bool IsAbsSpaces() const { return mbAbsSpaces
; }
245 void SetAbsSpaces( bool bFlag
) { mbAbsSpaces
= bFlag
; }
247 bool IsOutlineRule() const { return meRuleType
== OUTLINE_RULE
; }
249 bool IsCountPhantoms() const { return mbCountPhantoms
; }
250 void SetCountPhantoms(bool bCountPhantoms
);
252 /// Query and set PoolFormat IDs.
253 sal_uInt16
GetPoolFormatId() const { return mnPoolFormatId
; }
254 void SetPoolFormatId( sal_uInt16 nId
) { mnPoolFormatId
= nId
; }
256 /// Query and set Help-IDs for document styles.
257 sal_uInt16
GetPoolHelpId() const { return mnPoolHelpId
; }
258 void SetPoolHelpId( sal_uInt16 nId
) { mnPoolHelpId
= nId
; }
259 sal_uInt8
GetPoolHlpFileId() const { return mnPoolHlpFileId
; }
260 void SetPoolHlpFileId( sal_uInt8 nId
) { mnPoolHlpFileId
= nId
; }
262 void SetSvxRule(const SvxNumRule
&, SwDoc
* pDoc
);
263 SvxNumRule
MakeSvxNumRule() const;
265 /// change indent of all list levels by given difference
266 void ChangeIndent( const short nDiff
);
267 /// set indent of certain list level to given value
268 void SetIndent( const short nNewIndent
,
269 const sal_uInt16 nListLevel
);
270 /** set indent of first list level to given value and change other list level's
271 indents accordingly */
272 void SetIndentOfFirstListLevelAndChangeOthers( const short nNewIndent
);
275 void dumpAsXml(xmlTextWriterPtr w
) const;
276 void GetGrabBagItem(com::sun::star::uno::Any
& rVal
) const;
277 void SetGrabBagItem(const com::sun::star::uno::Any
& rVal
);
280 /// namespace for static functions and methods for numbering and bullets
283 /** retrieve font family name used for the default bullet list characters
287 OUString
GetDefBulletFontname();
289 /** determine if default bullet font is user defined
291 The default bullet font is user defined, if it is given in the user configuration
295 bool IsDefBulletFontUserDefined();
297 /** retrieve font used for the default bullet list characters
301 SW_DLLPUBLIC
const vcl::Font
& GetDefBulletFont();
303 /** retrieve unicode of character used for the default bullet list for the given list level
307 sal_Unicode
GetBulletChar( sal_uInt8 nLevel
);
309 /** configuration, if at first position of the first list item the <TAB>-key
310 increased the indent of the complete list or only demotes this list item.
311 The same for <SHIFT-TAB>-key at the same position for decreasing the
312 indent of the complete list or only promotes this list item.
316 bool ChangeIndentOnTabAtFirstPosOfFirstListItem();
321 SvxNumberFormat::SvxNumPositionAndSpaceMode
GetDefaultPositionAndSpaceMode();
324 #endif // INCLUDED_SW_INC_NUMRULE_HXX
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */