xref: /aoo41x/main/sw/inc/numrule.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _NUMRULE_HXX
24 #define _NUMRULE_HXX
25 
26 #include <tools/link.hxx>
27 #include <tools/gen.hxx>
28 #include <tools/string.hxx>
29 #include <editeng/svxenum.hxx>
30 #include <editeng/numitem.hxx>
31 #include "swdllapi.h"
32 #include <swtypes.hxx>
33 #include <calbck.hxx>
34 #include <errhdl.hxx>
35 #include <error.h>
36 #include <hints.hxx>
37 #include <hash_map>
38 #include <stringhash.hxx>
39 #include <SwNumberTreeTypes.hxx>
40 #include <vector>
41 
42 class SwTxtFmtColl;
43 class IDocumentListsAccess;
44 class SwNodeNum;
45 class Font;
46 class SvxBrushItem;
47 class SvxNumRule;
48 class SwCharFmt;
49 class SwDoc;
50 class SwFmtVertOrient;
51 class SwTxtNode;
52 
53 const sal_Unicode cBulletChar	= 0x2022;	// Charakter fuer Aufzaehlungen
54 
55 class SW_DLLPUBLIC SwNumFmt : public SvxNumberFormat, public SwClient
56 {
57 	SwFmtVertOrient* pVertOrient;
58 
59 	SW_DLLPRIVATE void UpdateNumNodes( SwDoc* pDoc );
60     SW_DLLPRIVATE virtual void NotifyGraphicArrived();
61 
62     using SvxNumberFormat::operator ==;
63     using SvxNumberFormat::operator !=;
64 
65 protected:
66    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew );
67 
68 public:
69 	SwNumFmt();
70 	SwNumFmt( const SwNumFmt& );
71 	SwNumFmt( const SvxNumberFormat&, SwDoc* pDoc);
72 
73 	virtual ~SwNumFmt();
74 
75 	SwNumFmt& operator=( const SwNumFmt& );
76 
77 	sal_Bool operator==( const SwNumFmt& ) const;
78 	sal_Bool operator!=( const SwNumFmt& r ) const { return !(*this == r); }
79 
80 	SwCharFmt* GetCharFmt() const { return (SwCharFmt*)GetRegisteredIn(); }
81 	void SetCharFmt( SwCharFmt* );
82     void ForgetCharFmt();
83 
84 	virtual void			SetCharFmtName(const String& rSet);
85 	virtual const String&	GetCharFmtName()const;
86 
87     virtual void    SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = 0, const sal_Int16* pOrient = 0);
88 
89     virtual void                SetVertOrient(sal_Int16 eSet);
90     virtual sal_Int16   GetVertOrient() const;
91     const SwFmtVertOrient*      GetGraphicOrientation() const;
92 
93     sal_Bool IsEnumeration() const; // #i22362#
94     sal_Bool IsItemize() const; // #i29560#
95 };
96 
97 class SwPaM;
98 enum SwNumRuleType { OUTLINE_RULE = 0, NUM_RULE = 1, RULE_END = 2 };
99 class SW_DLLPUBLIC SwNumRule
100 {
101 // --> OD 2008-02-19 #refactorlists#
102 public:
103     typedef std::vector< SwTxtNode* > tTxtNodeList;
104     typedef std::vector< SwTxtFmtColl* > tParagraphStyleList;
105 // <--
106 private:
107 	friend void _FinitCore();
108 
109 #ifdef DBG_UTIL
110     long int nSerial;
111     static long int nInstances;
112 #endif
113 
114 	static SwNumFmt* aBaseFmts [ RULE_END ][ MAXLEVEL ];
115 	static sal_uInt16 aDefNumIndents[ MAXLEVEL ];
116     // --> OD 2008-02-11 #newlistlevelattrs#
117     // default list level properties for position-and-space mode LABEL_ALIGNMENT
118     static SwNumFmt* aLabelAlignmentBaseFmts [ RULE_END ][ MAXLEVEL ];
119     // <--
120 	static sal_uInt16 nRefCount;
121 	static char* pDefOutlineName;
122 
123 	SwNumFmt* aFmts[ MAXLEVEL ];
124 
125     /** container for associated text nodes
126 
127     */
128     // --> OD 2008-02-19 #refactorlists#
129 //    SwTxtNodeTable* pTxtNodeList;
130     tTxtNodeList maTxtNodeList;
131     // <--
132 
133     /** container for associated paragraph styles
134 
135         OD 2008-03-03 #refactorlists#
136     */
137     tParagraphStyleList maParagraphStyleList;
138 
139     // #i36749#
140     /**
141        hash_map containing "name->rule" relation
142      */
143     std::hash_map<String, SwNumRule *, StringHash> * pNumRuleMap;
144 
145 	String sName;
146 	SwNumRuleType eRuleType;
147 	sal_uInt16 nPoolFmtId;		// Id-fuer "automatich" erzeugte NumRules
148 	sal_uInt16 nPoolHelpId;		// HelpId fuer diese Pool-Vorlage
149 	sal_uInt8 nPoolHlpFileId; 	// FilePos ans Doc auf die Vorlagen-Hilfen
150 	sal_Bool bAutoRuleFlag : 1;
151 	sal_Bool bInvalidRuleFlag : 1;
152 	sal_Bool bContinusNum : 1;	// Fortlaufende Numerierung - ohne Ebenen
153 	sal_Bool bAbsSpaces : 1;	// die Ebenen repraesentieren absol. Einzuege
154     bool mbCountPhantoms;
155 
156     // --> OD 2008-02-11 #newlistlevelattrs#
157     const SvxNumberFormat::SvxNumPositionAndSpaceMode meDefaultNumberFormatPositionAndSpaceMode;
158     // <--
159 
160     // --> OD 2008-04-03 #refactorlists#
161     String msDefaultListId;
162     // <--
163 
164 public:
165     // --> OD 2008-02-08 #newlistlevelattrs#
166     // add parameter <eDefaultNumberFormatPositionAndSpaceMode>
167     SwNumRule( const String& rNm,
168                const SvxNumberFormat::SvxNumPositionAndSpaceMode eDefaultNumberFormatPositionAndSpaceMode,
169                SwNumRuleType = NUM_RULE,
170                sal_Bool bAutoFlg = sal_True );
171 
172 	SwNumRule( const SwNumRule& );
173 	~SwNumRule();
174 
175 	SwNumRule& operator=( const SwNumRule& );
176 	sal_Bool operator==( const SwNumRule& ) const;
177 	sal_Bool operator!=( const SwNumRule& r ) const { return !(*this == r); }
178 
179 	const SwNumFmt* GetNumFmt( sal_uInt16 i ) const;
180 	const SwNumFmt& Get( sal_uInt16 i ) const;
181 
182 	void Set( sal_uInt16 i, const SwNumFmt* );
183 	void Set( sal_uInt16 i, const SwNumFmt& );
184 	String MakeNumString( const SwNodeNum&, sal_Bool bInclStrings = sal_True,
185 							sal_Bool bOnlyArabic = sal_False ) const;
186     // --> OD 2005-10-17 #126238#
187     // - add optional parameter <_nRestrictToThisLevel> in order to
188     //   restrict returned string to this level.
189     String MakeNumString( const SwNumberTree::tNumberVector & rNumVector,
190                           const sal_Bool bInclStrings = sal_True,
191                           const sal_Bool bOnlyArabic = sal_False,
192                           const unsigned int _nRestrictToThisLevel = MAXLEVEL ) const;
193     // <--
194     // --> OD 2007-08-24 #i81002#
195     String MakeRefNumString( const SwNodeNum& rNodeNum,
196                              const bool bInclSuperiorNumLabels = false,
197                              const sal_uInt8 nRestrictInclToThisLevel = 0 ) const;
198     // <--
199 
200     /** Returns list of associated text nodes.
201 
202        OD 2008-02-19 #refactorlists#
203 
204        @return list of associated text nodes
205     */
206 //    const SwTxtNodeTable * GetTxtNodeList() const { return pTxtNodeList; }
207     void GetTxtNodeList( SwNumRule::tTxtNodeList& rTxtNodeList ) const;
208     SwNumRule::tTxtNodeList::size_type GetTxtNodeListSize() const;
209 
210     // --> OD 2008-02-19 #refactorlists#
211     void AddTxtNode( SwTxtNode& rTxtNode );
212     void RemoveTxtNode( SwTxtNode& rTxtNode );
213     // <--
214 
215     // --> OD 2008-03-03 #refactorlists#
216     SwNumRule::tParagraphStyleList::size_type GetParagraphStyleListSize() const;
217     void AddParagraphStyle( SwTxtFmtColl& rTxtFmtColl );
218     void RemoveParagraphStyle( SwTxtFmtColl& rTxtFmtColl );
219     // <--
220 
221     // --> OD 2008-04-03 #refactorlists#
222     inline void SetDefaultListId( const String sDefaultListId )
223     {
224         msDefaultListId = sDefaultListId;
225     }
226     inline String GetDefaultListId() const
227     {
228         return msDefaultListId;
229     }
230     // <--
231     // #i36749#
232     /**
233        Register this rule in a "name->numrule" map.
234 
235        @param pNumRuleMap      map to register in
236      */
237     void SetNumRuleMap(
238                 std::hash_map<String, SwNumRule *, StringHash>* pNumRuleMap );
239 
240 	static char* GetOutlineRuleName() { return pDefOutlineName; }
241 
242 	static sal_uInt16 GetNumIndent( sal_uInt8 nLvl );
243 	static sal_uInt16 GetBullIndent( sal_uInt8 nLvl );
244 
245 	SwNumRuleType GetRuleType() const 			{ return eRuleType; }
246 	void SetRuleType( SwNumRuleType eNew ) 		{ eRuleType = eNew;
247 												  bInvalidRuleFlag = sal_True; }
248 
249 	// eine Art Copy-Constructor, damit die Num-Formate auch an den
250 	// richtigen CharFormaten eines Dokumentes haengen !!
251 	// (Kopiert die NumFormate und returnt sich selbst)
252 	SwNumRule& CopyNumRule( SwDoc*, const SwNumRule& );
253 
254 	// testet ob die CharFormate aus dem angegeben Doc sind und kopiert
255 	// die gegebenfalls
256 	void CheckCharFmts( SwDoc* pDoc );
257 
258     const String& GetName() const       { return sName; }
259     // --> OD 2008-07-08 #i91400#
260     void SetName( const String& rNm,
261                   IDocumentListsAccess& rDocListAccess ); // #i36749#
262     // <--
263 
264 	sal_Bool IsAutoRule() const 			{ return bAutoRuleFlag; }
265 	void SetAutoRule( sal_Bool bFlag )		{ bAutoRuleFlag = bFlag; }
266 
267 	sal_Bool IsInvalidRule() const 			{ return bInvalidRuleFlag; }
268 	void SetInvalidRule( sal_Bool bFlag );
269 
270 	sal_Bool IsContinusNum() const 			{ return bContinusNum; }
271 	void SetContinusNum( sal_Bool bFlag )	{ bContinusNum = bFlag; }
272 
273 	sal_Bool IsAbsSpaces() const 			{ return bAbsSpaces; }
274 	void SetAbsSpaces( sal_Bool bFlag )		{ bAbsSpaces = bFlag; }
275 
276     // #115901#
277     sal_Bool IsOutlineRule() const { return eRuleType == OUTLINE_RULE; }
278 
279     bool IsCountPhantoms() const;
280     void SetCountPhantoms(bool bCountPhantoms);
281 
282 	// erfragen und setzen der Poolvorlagen-Id's
283 	sal_uInt16 GetPoolFmtId() const			{ return nPoolFmtId; }
284 	void SetPoolFmtId( sal_uInt16 nId ) 	{ nPoolFmtId = nId; }
285 
286 	// erfragen und setzen der Hilfe-Id's fuer die Document-Vorlagen
287 	sal_uInt16 GetPoolHelpId() const 		{ return nPoolHelpId; }
288 	void SetPoolHelpId( sal_uInt16 nId ) 	{ nPoolHelpId = nId; }
289 	sal_uInt8 GetPoolHlpFileId() const 		{ return nPoolHlpFileId; }
290 	void SetPoolHlpFileId( sal_uInt8 nId ) 	{ nPoolHlpFileId = nId; }
291 
292 	void		SetSvxRule(const SvxNumRule&, SwDoc* pDoc);
293 	SvxNumRule	MakeSvxNumRule() const;
294 
295     // #i23726#, #i23725#
296     // --> OD 2008-06-09 #i90078#
297     // refactoring: provide certain method for certain purpose
298 //    void        Indent(short aAmount, int nLevel = -1,
299 //                       int nReferenceLevel = -1, sal_Bool bRelative = sal_True,
300 //                       sal_Bool bFirstLine = sal_True, sal_Bool bCheckGtZero = sal_True);
301     // change indent of all list levels by given difference
302     void ChangeIndent( const short nDiff );
303     // set indent of certain list level to given value
304     void SetIndent( const short nNewIndent,
305                     const sal_uInt16 nListLevel );
306     // set indent of first list level to given value and change other list level's
307     // indents accordingly
308     void SetIndentOfFirstListLevelAndChangeOthers( const short nNewIndent );
309     // <--
310 
311     void Validate();
312 };
313 
314 // --> OD 2006-06-27 #b6440955#
315 // namespace for static functions and methods for numbering and bullets
316 namespace numfunc
317 {
318     /** retrieve font family name used for the default bullet list characters
319 
320         @author OD
321     */
322     const String& GetDefBulletFontname();
323 
324     /** determine if default bullet font is user defined
325 
326         OD 2008-06-06 #i63395#
327         The default bullet font is user defined, if it is given in the user configuration
328 
329         @author OD
330     */
331     bool IsDefBulletFontUserDefined();
332 
333     /** retrieve font used for the default bullet list characters
334 
335         @author OD
336     */
337     SW_DLLPUBLIC const Font& GetDefBulletFont();
338 
339     /** retrieve unicode of character used for the default bullet list for the given list level
340 
341         @author OD
342     */
343     sal_Unicode GetBulletChar( sal_uInt8 nLevel );
344 
345     /** configuration, if at first position of the first list item the <TAB>-key
346         increased the indent of the complete list or only demotes this list item.
347         The same for <SHIFT-TAB>-key at the same position for decreasing the
348         indent of the complete list or only promotes this list item.
349 
350         OD 2007-10-01 #b6600435#
351 
352         @author OD
353     */
354     sal_Bool ChangeIndentOnTabAtFirstPosOfFirstListItem();
355 
356     /**
357         OD 2008-06-06 #i89178#
358 
359         @author OD
360     */
361     SvxNumberFormat::SvxNumPositionAndSpaceMode GetDefaultPositionAndSpaceMode();
362 }
363 
364 #endif	// _NUMRULE_HXX
365