xref: /trunk/main/sw/inc/numrule.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _NUMRULE_HXX
28 #define _NUMRULE_HXX
29 
30 #include <tools/link.hxx>
31 #include <tools/gen.hxx>
32 #include <tools/string.hxx>
33 #include <editeng/svxenum.hxx>
34 #include <editeng/numitem.hxx>
35 #include "swdllapi.h"
36 #include <swtypes.hxx>
37 #include <calbck.hxx>
38 #include <errhdl.hxx>
39 #include <error.h>
40 #include <hints.hxx>
41 #include <hash_map>
42 #include <stringhash.hxx>
43 #include <SwNumberTreeTypes.hxx>
44 #include <vector>
45 
46 class SwTxtFmtColl;
47 class IDocumentListsAccess;
48 class SwNodeNum;
49 class Font;
50 class SvxBrushItem;
51 class SvxNumRule;
52 class SwCharFmt;
53 class SwDoc;
54 class SwFmtVertOrient;
55 class SwTxtNode;
56 
57 const sal_Unicode cBulletChar   = 0x2022;   // Charakter fuer Aufzaehlungen
58 
59 class SW_DLLPUBLIC SwNumFmt : public SvxNumberFormat, public SwClient
60 {
61     SwFmtVertOrient* pVertOrient;
62 
63     SW_DLLPRIVATE void UpdateNumNodes( SwDoc* pDoc );
64     SW_DLLPRIVATE virtual void NotifyGraphicArrived();
65 
66     using SvxNumberFormat::operator ==;
67     using SvxNumberFormat::operator !=;
68 
69 protected:
70    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew );
71 
72 public:
73     SwNumFmt();
74     SwNumFmt( const SwNumFmt& );
75     SwNumFmt( const SvxNumberFormat&, SwDoc* pDoc);
76 
77     virtual ~SwNumFmt();
78 
79     SwNumFmt& operator=( const SwNumFmt& );
80 
81     sal_Bool operator==( const SwNumFmt& ) const;
82     sal_Bool operator!=( const SwNumFmt& r ) const { return !(*this == r); }
83 
84     SwCharFmt* GetCharFmt() const { return (SwCharFmt*)GetRegisteredIn(); }
85     void SetCharFmt( SwCharFmt* );
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;
181     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#
226     inline void SetDefaultListId( const String sDefaultListId )
227     {
228         msDefaultListId = sDefaultListId;
229     }
230     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 
244     static char* GetOutlineRuleName() { return pDefOutlineName; }
245 
246     static sal_uInt16 GetNumIndent( sal_uInt8 nLvl );
247     static sal_uInt16 GetBullIndent( sal_uInt8 nLvl );
248 
249     SwNumRuleType GetRuleType() const           { return eRuleType; }
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 
262     const String& GetName() const       { return sName; }
263     // --> OD 2008-07-08 #i91400#
264     void SetName( const String& rNm,
265                   IDocumentListsAccess& rDocListAccess ); // #i36749#
266     // <--
267 
268     sal_Bool IsAutoRule() const             { return bAutoRuleFlag; }
269     void SetAutoRule( sal_Bool bFlag )      { bAutoRuleFlag = bFlag; }
270 
271     sal_Bool IsInvalidRule() const          { return bInvalidRuleFlag; }
272     void SetInvalidRule( sal_Bool bFlag );
273 
274     sal_Bool IsContinusNum() const          { return bContinusNum; }
275     void SetContinusNum( sal_Bool bFlag )   { bContinusNum = bFlag; }
276 
277     sal_Bool IsAbsSpaces() const            { return bAbsSpaces; }
278     void SetAbsSpaces( sal_Bool bFlag )     { bAbsSpaces = bFlag; }
279 
280     // #115901#
281     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
287     sal_uInt16 GetPoolFmtId() const         { return nPoolFmtId; }
288     void SetPoolFmtId( sal_uInt16 nId )     { nPoolFmtId = nId; }
289 
290     // erfragen und setzen der Hilfe-Id's fuer die Document-Vorlagen
291     sal_uInt16 GetPoolHelpId() const        { return nPoolHelpId; }
292     void SetPoolHelpId( sal_uInt16 nId )    { nPoolHelpId = nId; }
293     sal_uInt8 GetPoolHlpFileId() const      { return nPoolHlpFileId; }
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