1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: numrule.hxx,v $
10 * $Revision: 1.39.78.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <tools/link.hxx>
34 #include <tools/gen.hxx>
35 #include <tools/string.hxx>
36 #include <svx/svxenum.hxx>
37 #include <svx/numitem.hxx>
39 #include <swtypes.hxx>
41 #include <errhdl.hxx> // Fuer die inline-ASSERTs
42 #include <error.h> // Fuer die inline-ASSERTs
45 #include <stringhash.hxx>
46 // --> OD 2008-02-21 #refactorlists#
48 #include <SwNumberTreeTypes.hxx>
50 // --> OD 2008-02-19 #refactorlists#
54 // --> OD 2008-07-08 #i91400#
55 class IDocumentListsAccess
;
63 class SwFmtVertOrient
;
66 const sal_Unicode cBulletChar
= 0x2022; // Charakter fuer Aufzaehlungen
68 class SW_DLLPUBLIC SwNumFmt
: public SvxNumberFormat
, public SwClient
70 SwFmtVertOrient
* pVertOrient
;
72 SW_DLLPRIVATE
void UpdateNumNodes( SwDoc
* pDoc
);
73 SW_DLLPRIVATE
virtual void NotifyGraphicArrived();
75 using SvxNumberFormat::operator ==;
76 using SvxNumberFormat::operator !=;
80 SwNumFmt( const SwNumFmt
& );
81 SwNumFmt( const SvxNumberFormat
&, SwDoc
* pDoc
);
85 SwNumFmt
& operator=( const SwNumFmt
& );
87 BOOL
operator==( const SwNumFmt
& ) const;
88 BOOL
operator!=( const SwNumFmt
& r
) const { return !(*this == r
); }
90 SwCharFmt
* GetCharFmt() const { return (SwCharFmt
*)pRegisteredIn
; }
91 void SetCharFmt( SwCharFmt
* );
92 virtual void Modify( SfxPoolItem
* pOld
, SfxPoolItem
* pNew
);
94 virtual void SetCharFmtName(const String
& rSet
);
95 virtual const String
& GetCharFmtName()const;
97 virtual void SetGraphicBrush( const SvxBrushItem
* pBrushItem
, const Size
* pSize
= 0, const sal_Int16
* pOrient
= 0);
99 virtual void SetVertOrient(sal_Int16 eSet
);
100 virtual sal_Int16
GetVertOrient() const;
101 const SwFmtVertOrient
* GetGraphicOrientation() const;
103 BOOL
IsEnumeration() const; // #i22362#
104 BOOL
IsItemize() const; // #i29560#
108 enum SwNumRuleType
{ OUTLINE_RULE
= 0, NUM_RULE
= 1, RULE_END
= 2 };
109 class SW_DLLPUBLIC SwNumRule
111 // --> OD 2008-02-19 #refactorlists#
113 typedef std::vector
< SwTxtNode
* > tTxtNodeList
;
114 typedef std::vector
< SwTxtFmtColl
* > tParagraphStyleList
;
117 friend void _FinitCore();
121 static long int nInstances
;
124 static SwNumFmt
* aBaseFmts
[ RULE_END
][ MAXLEVEL
];
125 static USHORT aDefNumIndents
[ MAXLEVEL
];
126 // --> OD 2008-02-11 #newlistlevelattrs#
127 // default list level properties for position-and-space mode LABEL_ALIGNMENT
128 static SwNumFmt
* aLabelAlignmentBaseFmts
[ RULE_END
][ MAXLEVEL
];
130 static USHORT nRefCount
;
131 static char* pDefOutlineName
;
133 SwNumFmt
* aFmts
[ MAXLEVEL
];
135 /** container for associated text nodes
138 // --> OD 2008-02-19 #refactorlists#
139 // SwTxtNodeTable* pTxtNodeList;
140 tTxtNodeList maTxtNodeList
;
143 /** container for associated paragraph styles
145 OD 2008-03-03 #refactorlists#
147 tParagraphStyleList maParagraphStyleList
;
151 hash_map containing "name->rule" relation
153 std::hash_map
<String
, SwNumRule
*, StringHash
> * pNumRuleMap
;
156 SwNumRuleType eRuleType
;
157 USHORT nPoolFmtId
; // Id-fuer "automatich" erzeugte NumRules
158 USHORT nPoolHelpId
; // HelpId fuer diese Pool-Vorlage
159 BYTE nPoolHlpFileId
; // FilePos ans Doc auf die Vorlagen-Hilfen
160 BOOL bAutoRuleFlag
: 1;
161 BOOL bInvalidRuleFlag
: 1;
162 BOOL bContinusNum
: 1; // Fortlaufende Numerierung - ohne Ebenen
163 BOOL bAbsSpaces
: 1; // die Ebenen repraesentieren absol. Einzuege
164 bool mbCountPhantoms
;
166 // --> OD 2008-02-11 #newlistlevelattrs#
167 const SvxNumberFormat::SvxNumPositionAndSpaceMode meDefaultNumberFormatPositionAndSpaceMode
;
170 // --> OD 2008-04-03 #refactorlists#
171 String msDefaultListId
;
174 // forbidden and not implemented.
178 // --> OD 2008-02-08 #newlistlevelattrs#
179 // add parameter <eDefaultNumberFormatPositionAndSpaceMode>
180 SwNumRule( const String
& rNm
,
181 const SvxNumberFormat::SvxNumPositionAndSpaceMode eDefaultNumberFormatPositionAndSpaceMode
,
182 SwNumRuleType
= NUM_RULE
,
183 BOOL bAutoFlg
= TRUE
);
185 SwNumRule( const SwNumRule
& );
188 SwNumRule
& operator=( const SwNumRule
& );
189 BOOL
operator==( const SwNumRule
& ) const;
190 BOOL
operator!=( const SwNumRule
& r
) const { return !(*this == r
); }
192 const SwNumFmt
* GetNumFmt( USHORT i
) const;
193 const SwNumFmt
& Get( USHORT i
) const;
195 void Set( USHORT i
, const SwNumFmt
* );
196 void Set( USHORT i
, const SwNumFmt
& );
197 String
MakeNumString( const SwNodeNum
&, BOOL bInclStrings
= TRUE
,
198 BOOL bOnlyArabic
= FALSE
) const;
199 // --> OD 2005-10-17 #126238#
200 // - add optional parameter <_nRestrictToThisLevel> in order to
201 // restrict returned string to this level.
202 String
MakeNumString( const SwNumberTree::tNumberVector
& rNumVector
,
203 const BOOL bInclStrings
= TRUE
,
204 const BOOL bOnlyArabic
= FALSE
,
205 const unsigned int _nRestrictToThisLevel
= MAXLEVEL
) const;
207 // --> OD 2007-08-24 #i81002#
208 String
MakeRefNumString( const SwNodeNum
& rNodeNum
,
209 const bool bInclSuperiorNumLabels
= false,
210 const sal_uInt8 nRestrictInclToThisLevel
= 0 ) const;
213 /** Returns list of associated text nodes.
215 OD 2008-02-19 #refactorlists#
217 @return list of associated text nodes
219 // const SwTxtNodeTable * GetTxtNodeList() const { return pTxtNodeList; }
220 void GetTxtNodeList( SwNumRule::tTxtNodeList
& rTxtNodeList
) const;
221 SwNumRule::tTxtNodeList::size_type
GetTxtNodeListSize() const;
223 // --> OD 2008-02-19 #refactorlists#
224 void AddTxtNode( SwTxtNode
& rTxtNode
);
225 void RemoveTxtNode( SwTxtNode
& rTxtNode
);
228 // --> OD 2008-03-03 #refactorlists#
229 SwNumRule::tParagraphStyleList::size_type
GetParagraphStyleListSize() const;
230 void AddParagraphStyle( SwTxtFmtColl
& rTxtFmtColl
);
231 void RemoveParagraphStyle( SwTxtFmtColl
& rTxtFmtColl
);
234 // --> OD 2008-04-03 #refactorlists#
235 inline void SetDefaultListId( const String sDefaultListId
)
237 msDefaultListId
= sDefaultListId
;
239 inline String
GetDefaultListId() const
241 return msDefaultListId
;
246 Register this rule in a "name->numrule" map.
248 @param pNumRuleMap map to register in
251 std::hash_map
<String
, SwNumRule
*, StringHash
>* pNumRuleMap
);
253 static char* GetOutlineRuleName() { return pDefOutlineName
; }
255 static USHORT
GetNumIndent( BYTE nLvl
);
256 static USHORT
GetBullIndent( BYTE nLvl
);
258 SwNumRuleType
GetRuleType() const { return eRuleType
; }
259 void SetRuleType( SwNumRuleType eNew
) { eRuleType
= eNew
;
260 bInvalidRuleFlag
= TRUE
; }
262 // eine Art Copy-Constructor, damit die Num-Formate auch an den
263 // richtigen CharFormaten eines Dokumentes haengen !!
264 // (Kopiert die NumFormate und returnt sich selbst)
265 SwNumRule
& CopyNumRule( SwDoc
*, const SwNumRule
& );
267 // testet ob die CharFormate aus dem angegeben Doc sind und kopiert
269 void CheckCharFmts( SwDoc
* pDoc
);
271 const String
& GetName() const { return sName
; }
272 // --> OD 2008-07-08 #i91400#
273 void SetName( const String
& rNm
,
274 IDocumentListsAccess
& rDocListAccess
); // #i36749#
277 BOOL
IsAutoRule() const { return bAutoRuleFlag
; }
278 void SetAutoRule( BOOL bFlag
) { bAutoRuleFlag
= bFlag
; }
280 BOOL
IsInvalidRule() const { return bInvalidRuleFlag
; }
281 void SetInvalidRule( BOOL bFlag
);
283 BOOL
IsContinusNum() const { return bContinusNum
; }
284 void SetContinusNum( BOOL bFlag
) { bContinusNum
= bFlag
; }
286 BOOL
IsAbsSpaces() const { return bAbsSpaces
; }
287 void SetAbsSpaces( BOOL bFlag
) { bAbsSpaces
= bFlag
; }
290 BOOL
IsOutlineRule() const { return eRuleType
== OUTLINE_RULE
; }
292 bool IsCountPhantoms() const;
293 void SetCountPhantoms(bool bCountPhantoms
);
295 // erfragen und setzen der Poolvorlagen-Id's
296 USHORT
GetPoolFmtId() const { return nPoolFmtId
; }
297 void SetPoolFmtId( USHORT nId
) { nPoolFmtId
= nId
; }
299 // erfragen und setzen der Hilfe-Id's fuer die Document-Vorlagen
300 USHORT
GetPoolHelpId() const { return nPoolHelpId
; }
301 void SetPoolHelpId( USHORT nId
) { nPoolHelpId
= nId
; }
302 BYTE
GetPoolHlpFileId() const { return nPoolHlpFileId
; }
303 void SetPoolHlpFileId( BYTE nId
) { nPoolHlpFileId
= nId
; }
305 void SetSvxRule(const SvxNumRule
&, SwDoc
* pDoc
);
306 SvxNumRule
MakeSvxNumRule() const;
308 // #i23726#, #i23725#
309 // --> OD 2008-06-09 #i90078#
310 // refactoring: provide certain method for certain purpose
311 // void Indent(short aAmount, int nLevel = -1,
312 // int nReferenceLevel = -1, BOOL bRelative = TRUE,
313 // BOOL bFirstLine = TRUE, BOOL bCheckGtZero = TRUE);
314 // change indent of all list levels by given difference
315 void ChangeIndent( const short nDiff
);
316 // set indent of certain list level to given value
317 void SetIndent( const short nNewIndent
,
318 const USHORT nListLevel
);
319 // set indent of first list level to given value and change other list level's
320 // indents accordingly
321 void SetIndentOfFirstListLevelAndChangeOthers( const short nNewIndent
);
327 // --> OD 2006-06-27 #b6440955#
328 // namespace for static functions and methods for numbering and bullets
331 /** retrieve font family name used for the default bullet list characters
335 const String
& GetDefBulletFontname();
337 /** determine if default bullet font is user defined
339 OD 2008-06-06 #i63395#
340 The default bullet font is user defined, if it is given in the user configuration
344 bool IsDefBulletFontUserDefined();
346 /** retrieve font used for the default bullet list characters
350 SW_DLLPUBLIC
const Font
& GetDefBulletFont();
352 /** retrieve unicode of character used for the default bullet list for the given list level
356 sal_Unicode
GetBulletChar( BYTE nLevel
);
358 /** configuration, if at first position of the first list item the <TAB>-key
359 increased the indent of the complete list or only demotes this list item.
360 The same for <SHIFT-TAB>-key at the same position for decreasing the
361 indent of the complete list or only promotes this list item.
363 OD 2007-10-01 #b6600435#
367 sal_Bool
ChangeIndentOnTabAtFirstPosOfFirstListItem();
370 OD 2008-06-06 #i89178#
374 SvxNumberFormat::SvxNumPositionAndSpaceMode
GetDefaultPositionAndSpaceMode();
377 #endif // _NUMRULE_HXX