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