xref: /core/sw/inc/numrule.hxx (revision 0ed1cb54)
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/numitem.hxx>
25 #include <i18nlangtag/lang.h>
26 #include "swdllapi.h"
27 #include "swtypes.hxx"
28 #include "calbck.hxx"
29 #include "SwNumberTreeTypes.hxx"
30 #include "ndarr.hxx"
31 #include <unordered_map>
32 #include <memory>
33 #include <vector>
34 #include "charfmt.hxx"
35 #include "fmtornt.hxx"
36 
37 class SwTextFormatColl;
38 class IDocumentListsAccess;
39 class SwNodeNum;
40 namespace vcl { class Font; }
41 class SvxBrushItem;
42 class SfxGrabBagItem;
43 class SwDoc;
44 class SwTextNode;
45 class Size;
46 class SwWrtShell;
47 
48 const sal_Unicode cBulletChar = 0x2022; ///< Character for lists.
49 
50 class SW_DLLPUBLIC SwNumFormat final : public SvxNumberFormat, public SwClient
51 {
52     SwFormatVertOrient m_aVertOrient;
53     //For i120928,record the cp info of graphic within bullet
54     sal_Unicode     m_cGrfBulletCP;
55     SAL_DLLPRIVATE void UpdateNumNodes(SwDoc& rDoc);
56 
57     using SvxNumberFormat::operator ==;
58     using SvxNumberFormat::operator !=;
59 
60     virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
61 
62 public:
63     SwNumFormat();
64     SwNumFormat( const SwNumFormat& );
65     SwNumFormat( const SvxNumberFormat&, SwDoc* pDoc);
66 
67     virtual ~SwNumFormat() override;
68 
69     SwNumFormat& operator=( const SwNumFormat& );
70 
71     bool operator==( const SwNumFormat& ) const;
operator !=(const SwNumFormat & r) const72     bool operator!=( const SwNumFormat& r ) const { return !(*this == r); }
73 
GetCharFormat() const74     SwCharFormat* GetCharFormat() const { return const_cast<SwCharFormat*>(static_cast<const SwCharFormat*>(GetRegisteredIn())); }
75     void       SetCharFormat( SwCharFormat* );
76 
77     using SvxNumberFormat::SetCharFormatName;
78     virtual OUString        GetCharFormatName() const override;
79 
80     //For i120928,access the cp info of graphic within bullet
SetGrfBulletCP(sal_Unicode cP)81     void            SetGrfBulletCP(sal_Unicode cP){m_cGrfBulletCP = cP;}
GetGrfBulletCP() const82     sal_Unicode     GetGrfBulletCP() const {return m_cGrfBulletCP;}
83 
84     virtual void    SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = nullptr, const sal_Int16* pOrient = nullptr) override;
85 
86     const SwFormatVertOrient*      GetGraphicOrientation() const;
87 
88     bool IsEnumeration() const; // #i22362#
89     bool IsItemize() const; // #i29560#
90 };
91 
92 enum SwNumRuleType { OUTLINE_RULE = 0, NUM_RULE = 1, RULE_END = 2 };
93 class SwNumRule
94 {
95 
96 public:
97     typedef std::vector< SwTextNode* > tTextNodeList;
98     typedef std::vector< SwTextFormatColl* > tParagraphStyleList;
99 
100     struct Extremities
101     {
102         sal_uInt16 nPrefixChars;
103         sal_uInt16 nSuffixChars;
104     };
105 
106 private:
107     friend void FinitCore();
108 
109     static SwNumFormat* saBaseFormats [ RULE_END ][ MAXLEVEL ];
110     static const sal_uInt16 saDefNumIndents[ MAXLEVEL ];
111     /// default list level properties for position-and-space mode LABEL_ALIGNMENT
112     static SwNumFormat* saLabelAlignmentBaseFormats [ RULE_END ][ MAXLEVEL ];
113     static sal_uInt16 snRefCount;
114 
115     std::unique_ptr<SwNumFormat> maFormats[ MAXLEVEL ];
116 
117     /** container for associated text nodes */
118     tTextNodeList maTextNodeList;
119 
120     /** container for associated paragraph styles */
121     tParagraphStyleList maParagraphStyleList;
122 
123     /** unordered_map containing "name->rule" relation */
124     std::unordered_map<OUString, SwNumRule *> * mpNumRuleMap;
125 
126     OUString msName;
127     SwNumRuleType meRuleType;
128     sal_uInt16 mnPoolFormatId;      ///< Id-for NumRules created "automatically"
129     sal_uInt16 mnPoolHelpId;     ///< HelpId for this Pool-style.
130     sal_uInt8 mnPoolHlpFileId;   ///< FilePos at Doc on style helps.
131     bool mbAutoRuleFlag : 1;
132     bool mbInvalidRuleFlag : 1;
133     bool mbContinusNum : 1;  ///< Continuous numbering without levels.
134     bool mbAbsSpaces : 1;    ///< Levels represent absolute indents.
135     bool mbHidden : 1;       ///< Is the numbering rule to be hidden in the UI?
136     bool mbCountPhantoms;
137     bool mbUsedByRedline;    /// it needs to export as part of tracked numbering change
138 
139     SvxNumberFormat::SvxNumPositionAndSpaceMode meDefaultNumberFormatPositionAndSpaceMode;
140     OUString msDefaultListId;
141     std::shared_ptr<SfxGrabBagItem> mpGrabBagItem; ///< Style InteropGrabBag.
142 
143 public:
144     /// add parameter <eDefaultNumberFormatPositionAndSpaceMode>
145     SW_DLLPUBLIC SwNumRule( OUString aNm,
146                const SvxNumberFormat::SvxNumPositionAndSpaceMode eDefaultNumberFormatPositionAndSpaceMode,
147                SwNumRuleType = NUM_RULE );
148 
149     SW_DLLPUBLIC SwNumRule( const SwNumRule& );
150     SW_DLLPUBLIC ~SwNumRule();
151 
152     SW_DLLPUBLIC SwNumRule& operator=( const SwNumRule& );
153     SW_DLLPUBLIC bool operator==( const SwNumRule& ) const;
operator !=(const SwNumRule & r) const154     bool operator!=( const SwNumRule& r ) const { return !(*this == r); }
155 
156     void Reset( const OUString& rName );
157 
158     SW_DLLPUBLIC const SwNumFormat* GetNumFormat( sal_uInt16 i ) const;
159     SW_DLLPUBLIC const SwNumFormat& Get( sal_uInt16 i ) const;
160 
IsHidden() const161     bool IsHidden( ) const { return mbHidden; }
SetHidden(bool bValue)162     void SetHidden( bool bValue ) { mbHidden = bValue; }
163 
164     void Set( sal_uInt16 i, const SwNumFormat* );
165     SW_DLLPUBLIC void Set( sal_uInt16 i, const SwNumFormat& );
166     OUString MakeNumString( const SwNodeNum&, bool bInclStrings = true ) const;
167     /** - add optional parameter <_nRestrictToThisLevel> in order to
168          restrict returned string to this level. */
169     SW_DLLPUBLIC OUString MakeNumString( const SwNumberTree::tNumberVector & rNumVector,
170                           const bool bInclStrings = true,
171                           const unsigned int _nRestrictToThisLevel = MAXLEVEL,
172                           const bool bHideNonNumerical = false,
173                           Extremities* pExtremities = nullptr,
174                           LanguageType nLang = LANGUAGE_SYSTEM) const;
175     OUString MakeRefNumString( const SwNodeNum& rNodeNum,
176                              const bool bInclSuperiorNumLabels,
177                              const int nRestrictInclToThisLevel,
178                              const bool bHideNonNumerical ) const;
179     OUString MakeParagraphStyleListString() const;
180 
181     /** @return list of associated text nodes */
182     void GetTextNodeList( SwNumRule::tTextNodeList& rTextNodeList ) const;
183     SwNumRule::tTextNodeList::size_type GetTextNodeListSize() const;
184 
185     void AddTextNode( SwTextNode& rTextNode );
186     void RemoveTextNode( SwTextNode& rTextNode );
187 
188     SwNumRule::tParagraphStyleList::size_type GetParagraphStyleListSize() const;
189     void AddParagraphStyle( SwTextFormatColl& rTextFormatColl );
190     void RemoveParagraphStyle( SwTextFormatColl& rTextFormatColl );
191 
SetDefaultListId(const OUString & sDefaultListId)192     void SetDefaultListId( const OUString& sDefaultListId )
193     {
194         msDefaultListId = sDefaultListId;
195     }
GetDefaultListId() const196     const OUString& GetDefaultListId() const
197     {
198         return msDefaultListId;
199     }
200     /**
201        Register this rule in a "name->numrule" map.
202 
203        @param pNumRuleMap      map to register in
204      */
205     void SetNumRuleMap(
206                 std::unordered_map<OUString, SwNumRule *>* pNumRuleMap );
207 
208     static OUString GetOutlineRuleName();
209 
210     static sal_uInt16 GetNumIndent( sal_uInt8 nLvl );
211     static sal_uInt16 GetBullIndent( sal_uInt8 nLvl );
212 
GetRuleType() const213     SwNumRuleType GetRuleType() const           { return meRuleType; }
SetRuleType(SwNumRuleType eNew)214     void SetRuleType( SwNumRuleType eNew )      { meRuleType = eNew;
215                                                   mbInvalidRuleFlag = true; }
216 
217     /** A kind of copy-constructor to make sure the num formats are
218        attached to the correctCharFormats of a document!!
219        (Copies the NumFormats and returns itself). */
220     SwNumRule& CopyNumRule( SwDoc&, const SwNumRule& );
221 
222     /** Tests whether the CharFormats are from the given doc
223        and copies them if appropriate. */
224     void CheckCharFormats( SwDoc& rDoc );
225 
GetName() const226     const OUString& GetName() const { return msName; }
227 
228     void SetName( const OUString& rNm,
229                   IDocumentListsAccess& rDocListAccess );
230 
IsAutoRule() const231     bool IsAutoRule() const             { return mbAutoRuleFlag; }
SetAutoRule(bool bFlag)232     void SetAutoRule( bool bFlag )      { mbAutoRuleFlag = bFlag; }
233 
IsInvalidRule() const234     bool IsInvalidRule() const          { return mbInvalidRuleFlag; }
Invalidate()235     void Invalidate() { mbInvalidRuleFlag = true; }
236 
IsContinusNum() const237     bool IsContinusNum() const          { return mbContinusNum; }
SetContinusNum(bool bFlag)238     void SetContinusNum( bool bFlag )   { mbContinusNum = bFlag; }
239 
IsAbsSpaces() const240     bool IsAbsSpaces() const            { return mbAbsSpaces; }
SetAbsSpaces(bool bFlag)241     void SetAbsSpaces( bool bFlag )     { mbAbsSpaces = bFlag; }
242 
IsOutlineRule() const243     bool IsOutlineRule() const { return meRuleType == OUTLINE_RULE; }
244 
IsCountPhantoms() const245     bool IsCountPhantoms() const        { return mbCountPhantoms; }
246     void SetCountPhantoms(bool bCountPhantoms);
247 
IsUsedByRedline() const248     bool IsUsedByRedline() const        { return mbUsedByRedline; }
SetUsedByRedline(bool bUsed)249     void SetUsedByRedline(bool bUsed )  { mbUsedByRedline = bUsed; }
250 
251     /// Query and set PoolFormat IDs.
GetPoolFormatId() const252     sal_uInt16 GetPoolFormatId() const         { return mnPoolFormatId; }
SetPoolFormatId(sal_uInt16 nId)253     void SetPoolFormatId( sal_uInt16 nId )     { mnPoolFormatId = nId; }
254 
255     /// Query and set Help-IDs for document styles.
GetPoolHelpId() const256     sal_uInt16 GetPoolHelpId() const        { return mnPoolHelpId; }
SetPoolHelpId(sal_uInt32 nId)257     void SetPoolHelpId( sal_uInt32 nId )    { mnPoolHelpId = nId; }
GetPoolHlpFileId() const258     sal_uInt8 GetPoolHlpFileId() const      { return mnPoolHlpFileId; }
SetPoolHlpFileId(sal_uInt8 nId)259     void SetPoolHlpFileId( sal_uInt8 nId )  { mnPoolHlpFileId = nId; }
260 
261     void        SetSvxRule(const SvxNumRule&, SwDoc* pDoc);
262     SvxNumRule  MakeSvxNumRule() const;
263 
264     /// change indent of all list levels by given difference
265     void ChangeIndent( const sal_Int32 nDiff );
266     /// set indent of certain list level to given value
267     void SetIndent( const short nNewIndent,
268                     const sal_uInt16 nListLevel );
269     /** set indent of first list level to given value and change other list level's
270        indents accordingly */
271     void SetIndentOfFirstListLevelAndChangeOthers( const short nNewIndent );
272 
273     void Validate(const SwDoc& rDoc);
274     void dumpAsXml(xmlTextWriterPtr w) const;
275     SW_DLLPUBLIC void GetGrabBagItem(css::uno::Any& rVal) const;
276     void SetGrabBagItem(const css::uno::Any& rVal);
277 };
278 
279 /// namespace for static functions and methods for numbering and bullets
280 namespace numfunc
281 {
282     /** retrieve font family name used for the default bullet list characters */
283     OUString const & GetDefBulletFontname();
284 
285     /** determine if default bullet font is user defined
286 
287         The default bullet font is user defined, if it is given in the user configuration
288     */
289     bool IsDefBulletFontUserDefined();
290 
291     /** retrieve font used for the default bullet list characters */
292     SW_DLLPUBLIC const vcl::Font& GetDefBulletFont();
293 
294     /** retrieve unicode of character used for the default bullet list for the given list level */
295     sal_Unicode GetBulletChar( sal_uInt8 nLevel );
296 
297     /** configuration, if at first position of the first list item the <TAB>-key
298         increased the indent of the complete list or only demotes this list item.
299         The same for <SHIFT-TAB>-key at the same position for decreasing the
300         indent of the complete list or only promotes this list item.
301     */
302     bool ChangeIndentOnTabAtFirstPosOfFirstListItem();
303 
304     /**
305      * Decides if increasing ("downing") the numbering level will change the amount of indentation
306      * or not. This is typically true, unless the numbering levels are invisible and have no
307      * indents.
308      */
309     bool NumDownChangesIndent(const SwWrtShell& rShell);
310 
311     SvxNumberFormat::SvxNumPositionAndSpaceMode GetDefaultPositionAndSpaceMode();
312 }
313 
314 #endif // INCLUDED_SW_INC_NUMRULE_HXX
315 
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
317