Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_SW_INC_NUMRULE_HXX
20 : #define INCLUDED_SW_INC_NUMRULE_HXX
21 :
22 : #include <sal/types.h>
23 : #include <rtl/ustring.hxx>
24 : #include <editeng/svxenum.hxx>
25 : #include <editeng/numitem.hxx>
26 : #include "swdllapi.h"
27 : #include <swtypes.hxx>
28 : #include <calbck.hxx>
29 : #include <hints.hxx>
30 : #include <SwNumberTreeTypes.hxx>
31 : #include <ndarr.hxx>
32 : #include <unordered_map>
33 : #include <vector>
34 : #include <charfmt.hxx>
35 :
36 : class SwTextFormatColl;
37 : class IDocumentListsAccess;
38 : class SwNodeNum;
39 : namespace vcl { class Font; }
40 : class SvxBrushItem;
41 : class SfxGrabBagItem;
42 : class SvxNumRule;
43 : class SwDoc;
44 : class SwFormatVertOrient;
45 : class SwTextNode;
46 : class Size;
47 :
48 : const sal_Unicode cBulletChar = 0x2022; ///< Character for lists.
49 :
50 : class SW_DLLPUBLIC SwNumFormat : public SvxNumberFormat, public SwClient
51 : {
52 : SwFormatVertOrient* pVertOrient;
53 : //For i120928,record the cp info of graphic within bullet
54 : sal_Unicode cGrfBulletCP;
55 : SAL_DLLPRIVATE void UpdateNumNodes( SwDoc* pDoc );
56 : SAL_DLLPRIVATE virtual void NotifyGraphicArrived() SAL_OVERRIDE;
57 :
58 : using SvxNumberFormat::operator ==;
59 : using SvxNumberFormat::operator !=;
60 :
61 : protected:
62 : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) SAL_OVERRIDE;
63 :
64 : public:
65 : SwNumFormat();
66 : SwNumFormat( const SwNumFormat& );
67 : SwNumFormat( const SvxNumberFormat&, SwDoc* pDoc);
68 :
69 : virtual ~SwNumFormat();
70 :
71 : SwNumFormat& operator=( const SwNumFormat& );
72 :
73 : bool operator==( const SwNumFormat& ) const;
74 3826333 : bool operator!=( const SwNumFormat& r ) const { return !(*this == r); }
75 :
76 3725577 : SwCharFormat* GetCharFormat() const { return const_cast<SwCharFormat*>(static_cast<const SwCharFormat*>(GetRegisteredIn())); }
77 : void SetCharFormat( SwCharFormat* );
78 :
79 : void SetCharFormatName(const OUString& rSet);
80 : virtual OUString GetCharFormatName() const SAL_OVERRIDE;
81 :
82 : //For i120928,access the cp info of graphic within bullet
83 0 : void SetGrfBulletCP(sal_Unicode cP){cGrfBulletCP = cP;}
84 0 : sal_Unicode GetGrfBulletCP() const {return cGrfBulletCP;}
85 :
86 : virtual void SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = 0, const sal_Int16* pOrient = 0) SAL_OVERRIDE;
87 :
88 : virtual void SetVertOrient(sal_Int16 eSet) SAL_OVERRIDE;
89 : virtual sal_Int16 GetVertOrient() const SAL_OVERRIDE;
90 : const SwFormatVertOrient* GetGraphicOrientation() const;
91 :
92 : bool IsEnumeration() const; // #i22362#
93 : bool IsItemize() const; // #i29560#
94 : };
95 :
96 : class SwPaM;
97 : enum SwNumRuleType { OUTLINE_RULE = 0, NUM_RULE = 1, RULE_END = 2 };
98 : class SW_DLLPUBLIC SwNumRule
99 : {
100 :
101 : public:
102 : typedef std::vector< SwTextNode* > tTextNodeList;
103 : typedef std::vector< SwTextFormatColl* > tParagraphStyleList;
104 :
105 : struct Extremities
106 : {
107 : sal_uInt16 nPrefixChars;
108 : sal_uInt16 nSuffixChars;
109 : };
110 :
111 : private:
112 : friend void _FinitCore();
113 :
114 : static SwNumFormat* maBaseFormats [ RULE_END ][ MAXLEVEL ];
115 : static const sal_uInt16 maDefNumIndents[ MAXLEVEL ];
116 : /// default list level properties for position-and-space mode LABEL_ALIGNMENT
117 : static SwNumFormat* maLabelAlignmentBaseFormats [ RULE_END ][ MAXLEVEL ];
118 : static sal_uInt16 mnRefCount;
119 :
120 : SwNumFormat* maFormats[ MAXLEVEL ];
121 :
122 : /** container for associated text nodes */
123 : tTextNodeList maTextNodeList;
124 :
125 : /** container for associated paragraph styles */
126 : tParagraphStyleList maParagraphStyleList;
127 :
128 : /** unordered_map containing "name->rule" relation */
129 : std::unordered_map<OUString, SwNumRule *, OUStringHash> * mpNumRuleMap;
130 :
131 : OUString msName;
132 : SwNumRuleType meRuleType;
133 : sal_uInt16 mnPoolFormatId; ///< Id-for NumRules created "automatically"
134 : sal_uInt16 mnPoolHelpId; ///< HelpId for this Pool-style.
135 : sal_uInt8 mnPoolHlpFileId; ///< FilePos at Doc on style helps.
136 : bool mbAutoRuleFlag : 1;
137 : bool mbInvalidRuleFlag : 1;
138 : bool mbContinusNum : 1; ///< Continuous numbering without levels.
139 : bool mbAbsSpaces : 1; ///< Levels represent absolute indents.
140 : bool mbHidden : 1; ///< Is the numering rule to be hidden in the UI?
141 : bool mbCountPhantoms;
142 :
143 : const SvxNumberFormat::SvxNumPositionAndSpaceMode meDefaultNumberFormatPositionAndSpaceMode;
144 : OUString msDefaultListId;
145 : boost::shared_ptr<SfxGrabBagItem> mpGrabBagItem; ///< Style InteropGrabBag.
146 :
147 : public:
148 : /// add parameter <eDefaultNumberFormatPositionAndSpaceMode>
149 : SwNumRule( const OUString& rNm,
150 : const SvxNumberFormat::SvxNumPositionAndSpaceMode eDefaultNumberFormatPositionAndSpaceMode,
151 : SwNumRuleType = NUM_RULE,
152 : bool bAutoFlg = true );
153 :
154 : SwNumRule( const SwNumRule& );
155 : ~SwNumRule();
156 :
157 : SwNumRule& operator=( const SwNumRule& );
158 : bool operator==( const SwNumRule& ) const;
159 2681 : bool operator!=( const SwNumRule& r ) const { return !(*this == r); }
160 :
161 : const SwNumFormat* GetNumFormat( sal_uInt16 i ) const;
162 : const SwNumFormat& Get( sal_uInt16 i ) const;
163 :
164 75 : bool IsHidden( ) const { return mbHidden; }
165 346 : void SetHidden( bool bValue ) { mbHidden = bValue; }
166 :
167 : void Set( sal_uInt16 i, const SwNumFormat* );
168 : void Set( sal_uInt16 i, const SwNumFormat& );
169 : OUString MakeNumString( const SwNodeNum&, bool bInclStrings = true,
170 : bool bOnlyArabic = false ) const;
171 : /** - add optional parameter <_nRestrictToThisLevel> in order to
172 : restrict returned string to this level. */
173 : OUString MakeNumString( const SwNumberTree::tNumberVector & rNumVector,
174 : const bool bInclStrings = true,
175 : const bool bOnlyArabic = false,
176 : const unsigned int _nRestrictToThisLevel = MAXLEVEL,
177 : Extremities* pExtremities = 0 ) const;
178 : OUString MakeRefNumString( const SwNodeNum& rNodeNum,
179 : const bool bInclSuperiorNumLabels = false,
180 : const sal_uInt8 nRestrictInclToThisLevel = 0 ) const;
181 :
182 : /**
183 :
184 : @return list of associated text nodes
185 : */
186 : void GetTextNodeList( SwNumRule::tTextNodeList& rTextNodeList ) const;
187 : SwNumRule::tTextNodeList::size_type GetTextNodeListSize() const;
188 :
189 : void AddTextNode( SwTextNode& rTextNode );
190 : void RemoveTextNode( SwTextNode& rTextNode );
191 :
192 : SwNumRule::tParagraphStyleList::size_type GetParagraphStyleListSize() const;
193 : void AddParagraphStyle( SwTextFormatColl& rTextFormatColl );
194 : void RemoveParagraphStyle( SwTextFormatColl& rTextFormatColl );
195 :
196 22589 : inline void SetDefaultListId( const OUString& sDefaultListId )
197 : {
198 22589 : msDefaultListId = sDefaultListId;
199 22589 : }
200 35432 : inline OUString GetDefaultListId() const
201 : {
202 35432 : return msDefaultListId;
203 : }
204 : /**
205 : Register this rule in a "name->numrule" map.
206 :
207 : @param pNumRuleMap map to register in
208 : */
209 : void SetNumRuleMap(
210 : std::unordered_map<OUString, SwNumRule *, OUStringHash>* pNumRuleMap );
211 :
212 : static OUString GetOutlineRuleName();
213 :
214 : static sal_uInt16 GetNumIndent( sal_uInt8 nLvl );
215 : static sal_uInt16 GetBullIndent( sal_uInt8 nLvl );
216 :
217 273 : SwNumRuleType GetRuleType() const { return meRuleType; }
218 6803 : void SetRuleType( SwNumRuleType eNew ) { meRuleType = eNew;
219 6803 : mbInvalidRuleFlag = true; }
220 :
221 : /** A kind of copy-constructor to make sure the num formats are
222 : attached to the correctCharFormats of a document!!
223 : (Copies the NumFormats and returns itself). */
224 : SwNumRule& CopyNumRule( SwDoc*, const SwNumRule& );
225 :
226 : /** Tests whether the CharFormats are from the given doc
227 : and copies them if appropriate. */
228 : void CheckCharFormats( SwDoc* pDoc );
229 :
230 124147578 : OUString GetName() const { return msName; }
231 :
232 : void SetName( const OUString& rNm,
233 : IDocumentListsAccess& rDocListAccess );
234 :
235 8739 : bool IsAutoRule() const { return mbAutoRuleFlag; }
236 26378 : void SetAutoRule( bool bFlag ) { mbAutoRuleFlag = bFlag; }
237 :
238 244112529 : bool IsInvalidRule() const { return mbInvalidRuleFlag; }
239 : void SetInvalidRule( bool bFlag );
240 :
241 644210 : bool IsContinusNum() const { return mbContinusNum; }
242 298630 : void SetContinusNum( bool bFlag ) { mbContinusNum = bFlag; }
243 :
244 5314 : bool IsAbsSpaces() const { return mbAbsSpaces; }
245 5 : void SetAbsSpaces( bool bFlag ) { mbAbsSpaces = bFlag; }
246 :
247 19250 : bool IsOutlineRule() const { return meRuleType == OUTLINE_RULE; }
248 :
249 361 : bool IsCountPhantoms() const { return mbCountPhantoms; }
250 : void SetCountPhantoms(bool bCountPhantoms);
251 :
252 : /// Query and set PoolFormat IDs.
253 530301 : sal_uInt16 GetPoolFormatId() const { return mnPoolFormatId; }
254 81 : void SetPoolFormatId( sal_uInt16 nId ) { mnPoolFormatId = nId; }
255 :
256 : /// Query and set Help-IDs for document styles.
257 529302 : sal_uInt16 GetPoolHelpId() const { return mnPoolHelpId; }
258 0 : void SetPoolHelpId( sal_uInt16 nId ) { mnPoolHelpId = nId; }
259 529302 : sal_uInt8 GetPoolHlpFileId() const { return mnPoolHlpFileId; }
260 0 : void SetPoolHlpFileId( sal_uInt8 nId ) { mnPoolHlpFileId = nId; }
261 :
262 : void SetSvxRule(const SvxNumRule&, SwDoc* pDoc);
263 : SvxNumRule MakeSvxNumRule() const;
264 :
265 : /// change indent of all list levels by given difference
266 : void ChangeIndent( const short nDiff );
267 : /// set indent of certain list level to given value
268 : void SetIndent( const short nNewIndent,
269 : const sal_uInt16 nListLevel );
270 : /** set indent of first list level to given value and change other list level's
271 : indents accordingly */
272 : void SetIndentOfFirstListLevelAndChangeOthers( const short nNewIndent );
273 :
274 : void Validate();
275 : void dumpAsXml(xmlTextWriterPtr w) const;
276 : void GetGrabBagItem(com::sun::star::uno::Any& rVal) const;
277 : void SetGrabBagItem(const com::sun::star::uno::Any& rVal);
278 : };
279 :
280 : /// namespace for static functions and methods for numbering and bullets
281 : namespace numfunc
282 : {
283 : /** retrieve font family name used for the default bullet list characters
284 :
285 : @author OD
286 : */
287 : OUString GetDefBulletFontname();
288 :
289 : /** determine if default bullet font is user defined
290 :
291 : The default bullet font is user defined, if it is given in the user configuration
292 :
293 : @author OD
294 : */
295 : bool IsDefBulletFontUserDefined();
296 :
297 : /** retrieve font used for the default bullet list characters
298 :
299 : @author OD
300 : */
301 : SW_DLLPUBLIC const vcl::Font& GetDefBulletFont();
302 :
303 : /** retrieve unicode of character used for the default bullet list for the given list level
304 :
305 : @author OD
306 : */
307 : sal_Unicode GetBulletChar( sal_uInt8 nLevel );
308 :
309 : /** configuration, if at first position of the first list item the <TAB>-key
310 : increased the indent of the complete list or only demotes this list item.
311 : The same for <SHIFT-TAB>-key at the same position for decreasing the
312 : indent of the complete list or only promotes this list item.
313 :
314 : @author OD
315 : */
316 : bool ChangeIndentOnTabAtFirstPosOfFirstListItem();
317 :
318 : /**
319 : @author OD
320 : */
321 : SvxNumberFormat::SvxNumPositionAndSpaceMode GetDefaultPositionAndSpaceMode();
322 : }
323 :
324 : #endif // INCLUDED_SW_INC_NUMRULE_HXX
325 :
326 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|