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 .
22 #include <sal/types.h>
23 #include <tools/string.hxx>
24 #include <editeng/svxenum.hxx>
25 #include <editeng/numitem.hxx>
27 #include <swtypes.hxx>
30 #include <boost/unordered_map.hpp>
31 #include <stringhash.hxx>
32 #include <SwNumberTreeTypes.hxx>
36 class IDocumentListsAccess
;
43 class SwFmtVertOrient
;
47 const sal_Unicode cBulletChar
= 0x2022; ///< Character for lists.
49 class SW_DLLPUBLIC SwNumFmt
: public SvxNumberFormat
, public SwClient
51 SwFmtVertOrient
* pVertOrient
;
52 //For i120928,record the cp info of graphic within bullet
53 sal_Unicode cGrfBulletCP
;
54 SW_DLLPRIVATE
void UpdateNumNodes( SwDoc
* pDoc
);
55 SW_DLLPRIVATE
virtual void NotifyGraphicArrived();
57 using SvxNumberFormat::operator ==;
58 using SvxNumberFormat::operator !=;
61 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
* pNew
);
65 SwNumFmt( const SwNumFmt
& );
66 SwNumFmt( const SvxNumberFormat
&, SwDoc
* pDoc
);
70 SwNumFmt
& operator=( const SwNumFmt
& );
72 sal_Bool
operator==( const SwNumFmt
& ) const;
73 sal_Bool
operator!=( const SwNumFmt
& r
) const { return !(*this == r
); }
75 SwCharFmt
* GetCharFmt() const { return (SwCharFmt
*)GetRegisteredIn(); }
76 void SetCharFmt( SwCharFmt
* );
78 virtual void SetCharFmtName(const String
& rSet
);
79 virtual const String
& GetCharFmtName()const;
81 //For i120928,access the cp info of graphic within bullet
82 void SetGrfBulletCP(sal_Unicode cP
){cGrfBulletCP
= cP
;}
83 sal_Unicode
GetGrfBulletCP()const {return cGrfBulletCP
;}
85 virtual void SetGraphicBrush( const SvxBrushItem
* pBrushItem
, const Size
* pSize
= 0, const sal_Int16
* pOrient
= 0);
87 virtual void SetVertOrient(sal_Int16 eSet
);
88 virtual sal_Int16
GetVertOrient() const;
89 const SwFmtVertOrient
* GetGraphicOrientation() const;
91 sal_Bool
IsEnumeration() const; // #i22362#
92 sal_Bool
IsItemize() const; // #i29560#
96 enum SwNumRuleType
{ OUTLINE_RULE
= 0, NUM_RULE
= 1, RULE_END
= 2 };
97 class SW_DLLPUBLIC SwNumRule
101 typedef std::vector
< SwTxtNode
* > tTxtNodeList
;
102 typedef std::vector
< SwTxtFmtColl
* > tParagraphStyleList
;
106 sal_uInt16 nPrefixChars
;
107 sal_uInt16 nSuffixChars
;
111 friend void _FinitCore();
113 static SwNumFmt
* aBaseFmts
[ RULE_END
][ MAXLEVEL
];
114 static sal_uInt16 aDefNumIndents
[ MAXLEVEL
];
115 /// default list level properties for position-and-space mode LABEL_ALIGNMENT
116 static SwNumFmt
* aLabelAlignmentBaseFmts
[ RULE_END
][ MAXLEVEL
];
117 static sal_uInt16 nRefCount
;
118 static char* pDefOutlineName
;
120 SwNumFmt
* aFmts
[ MAXLEVEL
];
122 /** container for associated text nodes */
123 tTxtNodeList maTxtNodeList
;
125 /** container for associated paragraph styles */
126 tParagraphStyleList maParagraphStyleList
;
128 /** boost::unordered_map containing "name->rule" relation */
129 boost::unordered_map
<String
, SwNumRule
*, StringHash
> * pNumRuleMap
;
132 SwNumRuleType eRuleType
;
133 sal_uInt16 nPoolFmtId
; ///< Id-for NumRules created "automatically"
134 sal_uInt16 nPoolHelpId
; ///< HelpId for this Pool-style.
135 sal_uInt8 nPoolHlpFileId
; ///< FilePos at Doc on style helps.
136 sal_Bool bAutoRuleFlag
: 1;
137 sal_Bool bInvalidRuleFlag
: 1;
138 sal_Bool bContinusNum
: 1; ///< Continuous numbering without levels.
139 sal_Bool bAbsSpaces
: 1; ///< Levels represent absolute indents.
140 sal_Bool bHidden
: 1; ///< Is the numering rule to be hidden in the UI?
141 bool mbCountPhantoms
;
143 const SvxNumberFormat::SvxNumPositionAndSpaceMode meDefaultNumberFormatPositionAndSpaceMode
;
144 String msDefaultListId
;
147 /// add parameter <eDefaultNumberFormatPositionAndSpaceMode>
148 SwNumRule( const String
& rNm
,
149 const SvxNumberFormat::SvxNumPositionAndSpaceMode eDefaultNumberFormatPositionAndSpaceMode
,
150 SwNumRuleType
= NUM_RULE
,
151 sal_Bool bAutoFlg
= sal_True
);
153 SwNumRule( const SwNumRule
& );
156 SwNumRule
& operator=( const SwNumRule
& );
157 sal_Bool
operator==( const SwNumRule
& ) const;
158 sal_Bool
operator!=( const SwNumRule
& r
) const { return !(*this == r
); }
160 const SwNumFmt
* GetNumFmt( sal_uInt16 i
) const;
161 const SwNumFmt
& Get( sal_uInt16 i
) const;
163 sal_Bool
IsHidden( ) const { return bHidden
; }
164 void SetHidden( sal_Bool bValue
) { bHidden
= bValue
; }
166 void Set( sal_uInt16 i
, const SwNumFmt
* );
167 void Set( sal_uInt16 i
, const SwNumFmt
& );
168 String
MakeNumString( const SwNodeNum
&, sal_Bool bInclStrings
= sal_True
,
169 sal_Bool bOnlyArabic
= sal_False
) const;
170 /** - add optional parameter <_nRestrictToThisLevel> in order to
171 restrict returned string to this level. */
172 String
MakeNumString( const SwNumberTree::tNumberVector
& rNumVector
,
173 const sal_Bool bInclStrings
= sal_True
,
174 const sal_Bool bOnlyArabic
= sal_False
,
175 const unsigned int _nRestrictToThisLevel
= MAXLEVEL
,
176 Extremities
* pExtremities
= 0 ) const;
177 String
MakeRefNumString( const SwNodeNum
& rNodeNum
,
178 const bool bInclSuperiorNumLabels
= false,
179 const sal_uInt8 nRestrictInclToThisLevel
= 0 ) const;
183 @return list of associated text nodes
185 void GetTxtNodeList( SwNumRule::tTxtNodeList
& rTxtNodeList
) const;
186 SwNumRule::tTxtNodeList::size_type
GetTxtNodeListSize() const;
188 void AddTxtNode( SwTxtNode
& rTxtNode
);
189 void RemoveTxtNode( SwTxtNode
& rTxtNode
);
191 SwNumRule::tParagraphStyleList::size_type
GetParagraphStyleListSize() const;
192 void AddParagraphStyle( SwTxtFmtColl
& rTxtFmtColl
);
193 void RemoveParagraphStyle( SwTxtFmtColl
& rTxtFmtColl
);
195 inline void SetDefaultListId( const String sDefaultListId
)
197 msDefaultListId
= sDefaultListId
;
199 inline String
GetDefaultListId() const
201 return msDefaultListId
;
204 Register this rule in a "name->numrule" map.
206 @param pNumRuleMap map to register in
209 boost::unordered_map
<String
, SwNumRule
*, StringHash
>* pNumRuleMap
);
211 static char* GetOutlineRuleName() { return pDefOutlineName
; }
213 static sal_uInt16
GetNumIndent( sal_uInt8 nLvl
);
214 static sal_uInt16
GetBullIndent( sal_uInt8 nLvl
);
216 SwNumRuleType
GetRuleType() const { return eRuleType
; }
217 void SetRuleType( SwNumRuleType eNew
) { eRuleType
= eNew
;
218 bInvalidRuleFlag
= sal_True
; }
220 /** A kind of copy-constructor to make sure the num formats are
221 attached to the correctCharFormats of a document!!
222 (Copies the NumFormats and returns itself). */
223 SwNumRule
& CopyNumRule( SwDoc
*, const SwNumRule
& );
225 /** Tests whether the CharFormats are from the given doc
226 and copies them if appropriate. */
227 void CheckCharFmts( SwDoc
* pDoc
);
229 const String
& GetName() const { return sName
; }
231 void SetName( const String
& rNm
,
232 IDocumentListsAccess
& rDocListAccess
);
234 sal_Bool
IsAutoRule() const { return bAutoRuleFlag
; }
235 void SetAutoRule( sal_Bool bFlag
) { bAutoRuleFlag
= bFlag
; }
237 sal_Bool
IsInvalidRule() const { return bInvalidRuleFlag
; }
238 void SetInvalidRule( sal_Bool bFlag
);
240 sal_Bool
IsContinusNum() const { return bContinusNum
; }
241 void SetContinusNum( sal_Bool bFlag
) { bContinusNum
= bFlag
; }
243 sal_Bool
IsAbsSpaces() const { return bAbsSpaces
; }
244 void SetAbsSpaces( sal_Bool bFlag
) { bAbsSpaces
= bFlag
; }
246 sal_Bool
IsOutlineRule() const { return eRuleType
== OUTLINE_RULE
; }
248 bool IsCountPhantoms() const;
249 void SetCountPhantoms(bool bCountPhantoms
);
251 /// Query and set PoolFormat IDs.
252 sal_uInt16
GetPoolFmtId() const { return nPoolFmtId
; }
253 void SetPoolFmtId( sal_uInt16 nId
) { nPoolFmtId
= nId
; }
255 /// Query and set Help-IDs for document styles.
256 sal_uInt16
GetPoolHelpId() const { return nPoolHelpId
; }
257 void SetPoolHelpId( sal_uInt16 nId
) { nPoolHelpId
= nId
; }
258 sal_uInt8
GetPoolHlpFileId() const { return nPoolHlpFileId
; }
259 void SetPoolHlpFileId( sal_uInt8 nId
) { nPoolHlpFileId
= nId
; }
261 void SetSvxRule(const SvxNumRule
&, SwDoc
* pDoc
);
262 SvxNumRule
MakeSvxNumRule() const;
264 /// change indent of all list levels by given difference
265 void ChangeIndent( const short nDiff
);
266 /// set indent of certain list level to given value
267 void SetIndent( const short nNewIndent
,
268 const sal_uInt16 nListLevel
);
269 /** set indent of first list level to given value and change other list level's
270 indents accordingly */
271 void SetIndentOfFirstListLevelAndChangeOthers( const short nNewIndent
);
276 /// namespace for static functions and methods for numbering and bullets
279 /** retrieve font family name used for the default bullet list characters
283 const String
& GetDefBulletFontname();
285 /** determine if default bullet font is user defined
287 The default bullet font is user defined, if it is given in the user configuration
291 bool IsDefBulletFontUserDefined();
293 /** retrieve font used for the default bullet list characters
297 SW_DLLPUBLIC
const Font
& GetDefBulletFont();
299 /** retrieve unicode of character used for the default bullet list for the given list level
303 sal_Unicode
GetBulletChar( sal_uInt8 nLevel
);
305 /** configuration, if at first position of the first list item the <TAB>-key
306 increased the indent of the complete list or only demotes this list item.
307 The same for <SHIFT-TAB>-key at the same position for decreasing the
308 indent of the complete list or only promotes this list item.
312 sal_Bool
ChangeIndentOnTabAtFirstPosOfFirstListItem();
317 SvxNumberFormat::SvxNumPositionAndSpaceMode
GetDefaultPositionAndSpaceMode();
320 #endif // _NUMRULE_HXX
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */