xref: /aoo4110/main/sw/inc/numrule.hxx (revision b1cdbd2c)
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 	//For i120928,record the cp info of graphic within bullet
59 	sal_Unicode 	cGrfBulletCP;
60 	SW_DLLPRIVATE void UpdateNumNodes( SwDoc* pDoc );
61     SW_DLLPRIVATE virtual void NotifyGraphicArrived();
62 
63     using SvxNumberFormat::operator ==;
64     using SvxNumberFormat::operator !=;
65 
66 protected:
67    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew );
68 
69 public:
70 	SwNumFmt();
71 	SwNumFmt( const SwNumFmt& );
72 	SwNumFmt( const SvxNumberFormat&, SwDoc* pDoc);
73 
74 	virtual ~SwNumFmt();
75 
76 	SwNumFmt& operator=( const SwNumFmt& );
77 
78 	sal_Bool operator==( const SwNumFmt& ) const;
operator !=(const SwNumFmt & r) const79 	sal_Bool operator!=( const SwNumFmt& r ) const { return !(*this == r); }
80 
GetCharFmt() const81 	SwCharFmt* GetCharFmt() const { return (SwCharFmt*)GetRegisteredIn(); }
82 	void SetCharFmt( SwCharFmt* );
83 	//For i120928,access the cp info of graphic within bullet
SetGrfBulletCP(sal_Unicode cP)84 	void			SetGrfBulletCP(sal_Unicode cP){cGrfBulletCP = cP;}
GetGrfBulletCP() const85 	sal_Unicode 	GetGrfBulletCP()const {return cGrfBulletCP;}
86     void ForgetCharFmt();
87 
88 	virtual void			SetCharFmtName(const String& rSet);
89 	virtual const String&	GetCharFmtName()const;
90 
91     virtual void    SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = 0, const sal_Int16* pOrient = 0);
92 
93     virtual void                SetVertOrient(sal_Int16 eSet);
94     virtual sal_Int16   GetVertOrient() const;
95     const SwFmtVertOrient*      GetGraphicOrientation() const;
96 
97     sal_Bool IsEnumeration() const; // #i22362#
98     sal_Bool IsItemize() const; // #i29560#
99 };
100 
101 class SwPaM;
102 enum SwNumRuleType { OUTLINE_RULE = 0, NUM_RULE = 1, RULE_END = 2 };
103 class SW_DLLPUBLIC SwNumRule
104 {
105 // --> OD 2008-02-19 #refactorlists#
106 public:
107     typedef std::vector< SwTxtNode* > tTxtNodeList;
108     typedef std::vector< SwTxtFmtColl* > tParagraphStyleList;
109 // <--
110 private:
111 	friend void _FinitCore();
112 
113 #ifdef DBG_UTIL
114     long int nSerial;
115     static long int nInstances;
116 #endif
117 
118 	static SwNumFmt* aBaseFmts [ RULE_END ][ MAXLEVEL ];
119 	static sal_uInt16 aDefNumIndents[ MAXLEVEL ];
120     // --> OD 2008-02-11 #newlistlevelattrs#
121     // default list level properties for position-and-space mode LABEL_ALIGNMENT
122     static SwNumFmt* aLabelAlignmentBaseFmts [ RULE_END ][ MAXLEVEL ];
123     // <--
124 	static sal_uInt16 nRefCount;
125 	static char* pDefOutlineName;
126 
127 	SwNumFmt* aFmts[ MAXLEVEL ];
128 
129     /** container for associated text nodes
130 
131     */
132     // --> OD 2008-02-19 #refactorlists#
133 //    SwTxtNodeTable* pTxtNodeList;
134     tTxtNodeList maTxtNodeList;
135     // <--
136 
137     /** container for associated paragraph styles
138 
139         OD 2008-03-03 #refactorlists#
140     */
141     tParagraphStyleList maParagraphStyleList;
142 
143     // #i36749#
144     /**
145        hash_map containing "name->rule" relation
146      */
147     std::hash_map<String, SwNumRule *, StringHash> * pNumRuleMap;
148 
149 	String sName;
150 	SwNumRuleType eRuleType;
151 	sal_uInt16 nPoolFmtId;		// Id-fuer "automatich" erzeugte NumRules
152 	sal_uInt16 nPoolHelpId;		// HelpId fuer diese Pool-Vorlage
153 	sal_uInt8 nPoolHlpFileId; 	// FilePos ans Doc auf die Vorlagen-Hilfen
154 	sal_Bool bAutoRuleFlag : 1;
155 	sal_Bool bInvalidRuleFlag : 1;
156 	sal_Bool bContinusNum : 1;	// Fortlaufende Numerierung - ohne Ebenen
157 	sal_Bool bAbsSpaces : 1;	// die Ebenen repraesentieren absol. Einzuege
158     bool mbCountPhantoms;
159 
160     // --> OD 2008-02-11 #newlistlevelattrs#
161     const SvxNumberFormat::SvxNumPositionAndSpaceMode meDefaultNumberFormatPositionAndSpaceMode;
162     // <--
163 
164     // --> OD 2008-04-03 #refactorlists#
165     String msDefaultListId;
166     // <--
167 
168 public:
169     // --> OD 2008-02-08 #newlistlevelattrs#
170     // add parameter <eDefaultNumberFormatPositionAndSpaceMode>
171     SwNumRule( const String& rNm,
172                const SvxNumberFormat::SvxNumPositionAndSpaceMode eDefaultNumberFormatPositionAndSpaceMode,
173                SwNumRuleType = NUM_RULE,
174                sal_Bool bAutoFlg = sal_True );
175 
176 	SwNumRule( const SwNumRule& );
177 	~SwNumRule();
178 
179 	SwNumRule& operator=( const SwNumRule& );
180 	sal_Bool operator==( const SwNumRule& ) const;
operator !=(const SwNumRule & r) const181 	sal_Bool operator!=( const SwNumRule& r ) const { return !(*this == r); }
182 
183 	const SwNumFmt* GetNumFmt( sal_uInt16 i ) const;
184 	const SwNumFmt& Get( sal_uInt16 i ) const;
185 
186 	void Set( sal_uInt16 i, const SwNumFmt* );
187 	void Set( sal_uInt16 i, const SwNumFmt& );
188 	String MakeNumString( const SwNodeNum&, sal_Bool bInclStrings = sal_True,
189 							sal_Bool bOnlyArabic = sal_False ) const;
190     // --> OD 2005-10-17 #126238#
191     // - add optional parameter <_nRestrictToThisLevel> in order to
192     //   restrict returned string to this level.
193     String MakeNumString( const SwNumberTree::tNumberVector & rNumVector,
194                           const sal_Bool bInclStrings = sal_True,
195                           const sal_Bool bOnlyArabic = sal_False,
196                           const unsigned int _nRestrictToThisLevel = MAXLEVEL ) const;
197     // <--
198     // --> OD 2007-08-24 #i81002#
199     String MakeRefNumString( const SwNodeNum& rNodeNum,
200                              const bool bInclSuperiorNumLabels = false,
201                              const sal_uInt8 nRestrictInclToThisLevel = 0 ) const;
202     // <--
203 
204     /** Returns list of associated text nodes.
205 
206        OD 2008-02-19 #refactorlists#
207 
208        @return list of associated text nodes
209     */
210 //    const SwTxtNodeTable * GetTxtNodeList() const { return pTxtNodeList; }
211     void GetTxtNodeList( SwNumRule::tTxtNodeList& rTxtNodeList ) const;
212     SwNumRule::tTxtNodeList::size_type GetTxtNodeListSize() const;
213 
214     // --> OD 2008-02-19 #refactorlists#
215     void AddTxtNode( SwTxtNode& rTxtNode );
216     void RemoveTxtNode( SwTxtNode& rTxtNode );
217     // <--
218 
219     // --> OD 2008-03-03 #refactorlists#
220     SwNumRule::tParagraphStyleList::size_type GetParagraphStyleListSize() const;
221     void AddParagraphStyle( SwTxtFmtColl& rTxtFmtColl );
222     void RemoveParagraphStyle( SwTxtFmtColl& rTxtFmtColl );
223     // <--
224 
225     // --> OD 2008-04-03 #refactorlists#
SetDefaultListId(const String sDefaultListId)226     inline void SetDefaultListId( const String sDefaultListId )
227     {
228         msDefaultListId = sDefaultListId;
229     }
GetDefaultListId() const230     inline String GetDefaultListId() const
231     {
232         return msDefaultListId;
233     }
234     // <--
235     // #i36749#
236     /**
237        Register this rule in a "name->numrule" map.
238 
239        @param pNumRuleMap      map to register in
240      */
241     void SetNumRuleMap(
242                 std::hash_map<String, SwNumRule *, StringHash>* pNumRuleMap );
243 
GetOutlineRuleName()244 	static char* GetOutlineRuleName() { return pDefOutlineName; }
245 
246 	static sal_uInt16 GetNumIndent( sal_uInt8 nLvl );
247 	static sal_uInt16 GetBullIndent( sal_uInt8 nLvl );
248 
GetRuleType() const249 	SwNumRuleType GetRuleType() const 			{ return eRuleType; }
SetRuleType(SwNumRuleType eNew)250 	void SetRuleType( SwNumRuleType eNew ) 		{ eRuleType = eNew;
251 												  bInvalidRuleFlag = sal_True; }
252 
253 	// eine Art Copy-Constructor, damit die Num-Formate auch an den
254 	// richtigen CharFormaten eines Dokumentes haengen !!
255 	// (Kopiert die NumFormate und returnt sich selbst)
256 	SwNumRule& CopyNumRule( SwDoc*, const SwNumRule& );
257 
258 	// testet ob die CharFormate aus dem angegeben Doc sind und kopiert
259 	// die gegebenfalls
260 	void CheckCharFmts( SwDoc* pDoc );
261 
GetName() const262     const String& GetName() const       { return sName; }
263     // --> OD 2008-07-08 #i91400#
264     void SetName( const String& rNm,
265                   IDocumentListsAccess& rDocListAccess ); // #i36749#
266     // <--
267 
IsAutoRule() const268 	sal_Bool IsAutoRule() const 			{ return bAutoRuleFlag; }
SetAutoRule(sal_Bool bFlag)269 	void SetAutoRule( sal_Bool bFlag )		{ bAutoRuleFlag = bFlag; }
270 
IsInvalidRule() const271 	sal_Bool IsInvalidRule() const 			{ return bInvalidRuleFlag; }
272 	void SetInvalidRule( sal_Bool bFlag );
273 
IsContinusNum() const274 	sal_Bool IsContinusNum() const 			{ return bContinusNum; }
SetContinusNum(sal_Bool bFlag)275 	void SetContinusNum( sal_Bool bFlag )	{ bContinusNum = bFlag; }
276 
IsAbsSpaces() const277 	sal_Bool IsAbsSpaces() const 			{ return bAbsSpaces; }
SetAbsSpaces(sal_Bool bFlag)278 	void SetAbsSpaces( sal_Bool bFlag )		{ bAbsSpaces = bFlag; }
279 
280     // #115901#
IsOutlineRule() const281     sal_Bool IsOutlineRule() const { return eRuleType == OUTLINE_RULE; }
282 
283     bool IsCountPhantoms() const;
284     void SetCountPhantoms(bool bCountPhantoms);
285 
286 	// erfragen und setzen der Poolvorlagen-Id's
GetPoolFmtId() const287 	sal_uInt16 GetPoolFmtId() const			{ return nPoolFmtId; }
SetPoolFmtId(sal_uInt16 nId)288 	void SetPoolFmtId( sal_uInt16 nId ) 	{ nPoolFmtId = nId; }
289 
290 	// erfragen und setzen der Hilfe-Id's fuer die Document-Vorlagen
GetPoolHelpId() const291 	sal_uInt16 GetPoolHelpId() const 		{ return nPoolHelpId; }
SetPoolHelpId(sal_uInt16 nId)292 	void SetPoolHelpId( sal_uInt16 nId ) 	{ nPoolHelpId = nId; }
GetPoolHlpFileId() const293 	sal_uInt8 GetPoolHlpFileId() const 		{ return nPoolHlpFileId; }
SetPoolHlpFileId(sal_uInt8 nId)294 	void SetPoolHlpFileId( sal_uInt8 nId ) 	{ nPoolHlpFileId = nId; }
295 
296 	void		SetSvxRule(const SvxNumRule&, SwDoc* pDoc);
297 	SvxNumRule	MakeSvxNumRule() const;
298 
299     // #i23726#, #i23725#
300     // --> OD 2008-06-09 #i90078#
301     // refactoring: provide certain method for certain purpose
302 //    void        Indent(short aAmount, int nLevel = -1,
303 //                       int nReferenceLevel = -1, sal_Bool bRelative = sal_True,
304 //                       sal_Bool bFirstLine = sal_True, sal_Bool bCheckGtZero = sal_True);
305     // change indent of all list levels by given difference
306     void ChangeIndent( const short nDiff );
307     // set indent of certain list level to given value
308     void SetIndent( const short nNewIndent,
309                     const sal_uInt16 nListLevel );
310     // set indent of first list level to given value and change other list level's
311     // indents accordingly
312     void SetIndentOfFirstListLevelAndChangeOthers( const short nNewIndent );
313     // <--
314 
315     void Validate();
316 };
317 
318 // --> OD 2006-06-27 #b6440955#
319 // namespace for static functions and methods for numbering and bullets
320 namespace numfunc
321 {
322     /** retrieve font family name used for the default bullet list characters
323 
324         @author OD
325     */
326     const String& GetDefBulletFontname();
327 
328     /** determine if default bullet font is user defined
329 
330         OD 2008-06-06 #i63395#
331         The default bullet font is user defined, if it is given in the user configuration
332 
333         @author OD
334     */
335     bool IsDefBulletFontUserDefined();
336 
337     /** retrieve font used for the default bullet list characters
338 
339         @author OD
340     */
341     SW_DLLPUBLIC const Font& GetDefBulletFont();
342 
343     /** retrieve unicode of character used for the default bullet list for the given list level
344 
345         @author OD
346     */
347     sal_Unicode GetBulletChar( sal_uInt8 nLevel );
348 
349     /** configuration, if at first position of the first list item the <TAB>-key
350         increased the indent of the complete list or only demotes this list item.
351         The same for <SHIFT-TAB>-key at the same position for decreasing the
352         indent of the complete list or only promotes this list item.
353 
354         OD 2007-10-01 #b6600435#
355 
356         @author OD
357     */
358     sal_Bool ChangeIndentOnTabAtFirstPosOfFirstListItem();
359 
360     /**
361         OD 2008-06-06 #i89178#
362 
363         @author OD
364     */
365     SvxNumberFormat::SvxNumPositionAndSpaceMode GetDefaultPositionAndSpaceMode();
366 }
367 
368 #endif	// _NUMRULE_HXX
369