LibreOffice Module sw (master)  1
docstyle.hxx
Go to the documentation of this file.
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_DOCSTYLE_HXX
20 #define INCLUDED_SW_INC_DOCSTYLE_HXX
21 
22 #include <rtl/ref.hxx>
23 #include <rtl/ustring.hxx>
24 
25 #include <svl/style.hxx>
26 #include <svl/itemset.hxx>
27 #include "swdllapi.h"
28 
29 #include <unordered_map>
30 #include <memory>
31 #include <optional>
32 #include <string_view>
33 #include <vector>
34 
35 class SwDoc;
37 class SwPageDesc;
38 class SwCharFormat;
39 class SwTextFormatColl;
40 class SwFrameFormat;
41 class SwNumRule;
42 class SwTableAutoFormat;
43 class SwBoxAutoFormat;
44 enum class SwGetPoolIdFromName : sal_uInt16;
45 
46 // Temporary StyleSheet.
48 {
49  friend class SwDocStyleSheetPool;
50  friend class SwStyleSheetIterator;
51 
61 
63 
65  SAL_DLLPRIVATE void Create();
66 
73  };
74 
75  SAL_DLLPRIVATE bool FillStyleSheet(FillStyleType eFType,
76  std::optional<SfxItemSet> * o_ppFlatSet = nullptr);
77 
78  virtual ~SwDocStyleSheet() override;
79 
80 public:
81  SwDocStyleSheet( SwDoc& rDoc,
82  SwDocStyleSheetPool& rPool);
83 
85 
86  void Reset();
87 
88  void SetFamily(SfxStyleFamily eFam) { nFamily = eFam; }
89 
90  bool IsPhysical() const { return m_bPhysical; }
91  void SetPhysical(bool bPhys);
92 
93  virtual void SetHidden( bool bHidden ) override;
94  virtual bool IsHidden( ) const override;
95  void SetGrabBagItem(const css::uno::Any& rVal);
96  void GetGrabBagItem(css::uno::Any& rVal) const;
97 
102  void SetItemSet( const SfxItemSet& rSet,
103  const bool bResetIndentAttrsAtParagraphStyle = false );
104 
105  virtual SfxItemSet& GetItemSet() override;
106  virtual std::optional<SfxItemSet> GetItemSetForPreview() override;
110  virtual const OUString& GetParent() const override;
111  virtual const OUString& GetFollow() const override;
112 
113  virtual sal_uLong GetHelpId( OUString& rFile ) override;
114  virtual void SetHelpId( const OUString& r, sal_uLong nId ) override;
115 
118  void PresetName(const OUString& rName) { aName = rName; }
119  void PresetNameAndFamily(SfxStyleFamily eFamily, const OUString& rName);
120  void PresetParent(const OUString& rName){ aParent = rName; }
121  void PresetFollow(const OUString& rName){ aFollow = rName; }
122 
123  virtual bool SetName(const OUString& rNewName, bool bReindexNow = true) override;
124  virtual bool SetParent( const OUString& rStr) override;
125  virtual bool SetFollow( const OUString& rStr) override;
126 
127  virtual bool HasFollowSupport() const override;
128  virtual bool HasParentSupport() const override;
129  virtual bool HasClearParentSupport() const override;
130  virtual OUString GetDescription(MapUnit eUnit) override;
131 
132  virtual OUString GetUsedBy() override;
133 
137  const SwPageDesc* GetPageDesc();
138  const SwNumRule* GetNumRule();
139  void SetNumRule(const SwNumRule& rRule);
141 
142  virtual bool IsUsed() const override;
143 };
144 
145 namespace std {
146 template<>
147 struct hash<std::pair<SfxStyleFamily,OUString>>
148 {
149  std::size_t operator()(std::pair<SfxStyleFamily,OUString> const & pair) const
150  { return static_cast<std::size_t>(pair.first) ^ std::size_t(pair.second.hashCode()); }
151 };
152 }
153 
154 
155 // Iterator for Pool.
157 {
158  // Local helper class.
160  {
161  std::vector<std::pair<SfxStyleFamily, OUString>> maImpl;
162  typedef std::unordered_map<std::pair<SfxStyleFamily, OUString>, sal_uInt32> UniqueHash;
163  UniqueHash maUnique;
164  void rehash();
165  public:
167  void Append( SfxStyleFamily eFam, const OUString& rStr );
168  void clear() { maImpl.clear(); maUnique.clear(); }
169  size_t size() { return maImpl.size(); }
170  bool empty() { return maImpl.empty(); }
171  sal_uInt32 FindName(SfxStyleFamily eFam, const OUString& rName);
172  void RemoveName(SfxStyleFamily eFam, const OUString& rName);
173  const std::pair<SfxStyleFamily,OUString> &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; }
174  };
175 
179  sal_uInt32 m_nLastPos;
181 
182  void AppendStyleList(const std::vector<OUString>& rLst,
183  bool bUsed,
184  bool bTestHidden,
185  bool bOnlyHidden,
186  SwGetPoolIdFromName nSection,
187  SfxStyleFamily eFamily);
188 
189 public:
192  virtual ~SwStyleSheetIterator() override;
193 
194  virtual sal_Int32 Count() override;
195  virtual SfxStyleSheetBase *operator[](sal_Int32 nIdx) override;
196  virtual SfxStyleSheetBase* First() override;
197  virtual SfxStyleSheetBase* Next() override;
198  virtual SfxStyleSheetBase* Find(const OUString& rStr) override;
199 
200  virtual void Notify( SfxBroadcaster&, const SfxHint& ) override;
201 
202  void InvalidateIterator();
203 };
204 
206 {
209  bool m_bOrganizer : 1;
210 
211  virtual rtl::Reference<SfxStyleSheetBase> Create( const OUString&, SfxStyleFamily, SfxStyleSearchBits nMask) override;
213 
215 
216 public:
217  SwDocStyleSheetPool( SwDoc&, bool bOrganizer );
218 
219  virtual SfxStyleSheetBase& Make(const OUString&, SfxStyleFamily,
220  SfxStyleSearchBits nMask = SfxStyleSearchBits::All) override;
221 
222  virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam,
223  SfxStyleSearchBits n=SfxStyleSearchBits::All ) override;
224 
225  virtual bool SetParent( SfxStyleFamily eFam, const OUString &rStyle,
226  const OUString &rParent ) override;
227 
228  virtual void Remove( SfxStyleSheetBase* pStyle) override;
229 
230  bool IsOrganizerMode() const { return m_bOrganizer; }
231 
232  virtual std::unique_ptr<SfxStyleSheetIterator> CreateIterator( SfxStyleFamily, SfxStyleSearchBits nMask = SfxStyleSearchBits::All) override;
233 
234  SwDoc& GetDoc() const { return m_rDoc; }
235 
236  void dispose();
237 
238  void InvalidateIterator();
239 
240 private:
241  virtual ~SwDocStyleSheetPool() override;
242 
243  SwDocStyleSheetPool( const SwDocStyleSheetPool& ) = delete;
244 };
245 
246 #endif
247 
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual std::unique_ptr< SfxStyleSheetIterator > CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask=SfxStyleSearchBits::All) override
Definition: docstyle.cxx:2399
virtual bool IsUsed() const
virtual const OUString & GetFollow() const
virtual std::optional< SfxItemSet > GetItemSetForPreview()
SwStyleSheetIterator(SwDocStyleSheetPool &rBase, SfxStyleFamily eFam, SfxStyleSearchBits n)
Definition: docstyle.cxx:2606
std::unordered_map< std::pair< SfxStyleFamily, OUString >, sal_uInt32 > UniqueHash
Definition: docstyle.hxx:162
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
bool m_bOrganizer
Organizer.
Definition: docstyle.hxx:209
SwDoc & GetDoc() const
Definition: docstyle.hxx:234
virtual bool HasClearParentSupport() const
SwTableAutoFormat * GetTableFormat()
Definition: docstyle.cxx:2152
void SetNumRule(const SwNumRule &rRule)
Definition: docstyle.cxx:2146
virtual SfxStyleSheetBase * First() override
Definition: docstyle.cxx:2643
virtual bool SetParent(const OUString &)
virtual bool IsHidden() const
sal_uIntPtr sal_uLong
virtual rtl::Reference< SfxStyleSheetBase > Create(const OUString &, SfxStyleFamily, SfxStyleSearchBits nMask) override
Definition: docstyle.cxx:2392
Definition: doc.hxx:188
void GetGrabBagItem(css::uno::Any &rVal) const
Definition: docstyle.cxx:514
virtual const OUString & GetParent() const
virtual bool SetName(const OUString &rNewName, bool bReindexNow=true)
SwPoolFormatList m_aLst
Definition: docstyle.hxx:178
virtual SfxItemSet & GetItemSet()
std::size_t operator()(std::pair< SfxStyleFamily, OUString > const &pair) const
Definition: docstyle.hxx:149
SfxItemSet m_aCoreSet
Definition: docstyle.hxx:60
virtual sal_uLong GetHelpId(OUString &rFile)
virtual void SetHelpId(const OUString &r, sal_uLong nId)
void PresetNameAndFamily(SfxStyleFamily eFamily, const OUString &rName)
Definition: docstyle.cxx:2163
std::vector< std::pair< SfxStyleFamily, OUString > > maImpl
Definition: docstyle.hxx:161
SwDocStyleSheetPool(SwDoc &, bool bOrganizer)
Definition: docstyle.cxx:2359
virtual SfxStyleSheetBase * operator[](sal_Int32 nIdx) override
Definition: docstyle.cxx:2630
virtual void SetHidden(bool bValue)
virtual ~SwDocStyleSheetPool() override
Definition: docstyle.cxx:2367
bool IsPhysical() const
Definition: docstyle.hxx:90
rtl::Reference< SwDocStyleSheet > mxIterSheet
Definition: docstyle.hxx:176
virtual SfxStyleSheetBase * Next() override
Definition: docstyle.cxx:3055
SwFrameFormat * GetFrameFormat()
Definition: docstyle.cxx:2183
virtual bool SetFollow(const OUString &)
sal_uInt32 FindName(SfxStyleFamily eFam, const OUString &rName)
Definition: docstyle.cxx:361
const SwPageDesc * GetPageDesc()
Definition: docstyle.cxx:2131
SfxStyleFamily
SwCharFormat * GetCharFormat()
Definition: docstyle.cxx:2117
virtual bool SetParent(SfxStyleFamily eFam, const OUString &rStyle, const OUString &rParent) override
Definition: docstyle.cxx:2469
void PresetParent(const OUString &rName)
Definition: docstyle.hxx:120
SwTableAutoFormat * m_pTableFormat
Definition: docstyle.hxx:57
const std::pair< SfxStyleFamily, OUString > & operator[](sal_uInt32 nIdx)
Definition: docstyle.hxx:173
virtual SfxStyleSheetBase * Find(const OUString &rStr) override
Definition: docstyle.cxx:3075
Style of a layout element.
Definition: frmfmt.hxx:58
SwCharFormat * m_pCharFormat
Definition: docstyle.hxx:52
void Append(SfxStyleFamily eFam, const OUString &rStr)
Definition: docstyle.cxx:399
sal_uInt32 m_nLastPos
Definition: docstyle.hxx:179
void SetGrabBagItem(const css::uno::Any &rVal)
Definition: docstyle.cxx:465
virtual void Notify(SfxBroadcaster &, const SfxHint &) override
Definition: docstyle.cxx:3170
virtual bool HasFollowSupport() const
void MergeIndentAttrsOfListStyle(SfxItemSet &rSet)
new method for paragraph styles to merge indent attributes of applied list style into the given item ...
Definition: docstyle.cxx:1377
void PresetFollow(const OUString &rName)
Definition: docstyle.hxx:121
void SetItemSet(const SfxItemSet &rSet, const bool bResetIndentAttrsAtParagraphStyle=false)
add optional parameter , default value false, which indicates that...
Definition: docstyle.cxx:1409
SwDocStyleSheet(SwDoc &rDoc, SwDocStyleSheetPool &rPool)
Definition: docstyle.cxx:411
void SetPhysical(bool bPhys)
Definition: docstyle.cxx:2170
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwFrameFormat * m_pFrameFormat
Definition: docstyle.hxx:54
SAL_DLLPRIVATE void Create()
Make empty shell a real StyleSheet (Core).
Definition: docstyle.cxx:2042
virtual SfxStyleSheetBase & Make(const OUString &, SfxStyleFamily, SfxStyleSearchBits nMask=SfxStyleSearchBits::All) override
Definition: docstyle.cxx:2371
void RemoveName(SfxStyleFamily eFam, const OUString &rName)
Definition: docstyle.cxx:386
const SwBoxAutoFormat * m_pBoxFormat
Definition: docstyle.hxx:58
FillStyleType
Fill StyleSheet with data.
Definition: docstyle.hxx:68
const SwNumRule * m_pNumRule
Definition: docstyle.hxx:56
virtual ~SwStyleSheetIterator() override
Definition: docstyle.cxx:2617
void AppendStyleList(const std::vector< OUString > &rLst, bool bUsed, bool bTestHidden, bool bOnlyHidden, SwGetPoolIdFromName nSection, SfxStyleFamily eFamily)
Definition: docstyle.cxx:3097
void PresetName(const OUString &rName)
Preset the members without physical access.
Definition: docstyle.hxx:118
SwTextFormatColl * GetCollection()
Definition: docstyle.cxx:2124
const SwPageDesc * m_pDesc
Definition: docstyle.hxx:55
SwDoc & m_rDoc
Definition: docstyle.hxx:59
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All) override
Definition: docstyle.cxx:2525
SwTextFormatColl * m_pColl
Definition: docstyle.hxx:53
virtual ~SwDocStyleSheet() override
virtual OUString GetUsedBy()
rtl::Reference< SwDocStyleSheet > mxStyleSheet
Definition: docstyle.hxx:177
SAL_DLLPRIVATE bool FillStyleSheet(FillStyleType eFType, std::optional< SfxItemSet > *o_ppFlatSet=nullptr)
Definition: docstyle.cxx:1824
OUString aName
SwGetPoolIdFromName
void SetFamily(SfxStyleFamily eFam)
Definition: docstyle.hxx:88
virtual sal_Int32 Count() override
Definition: docstyle.cxx:2622
MapUnit
bool IsOrganizerMode() const
Definition: docstyle.hxx:230
virtual bool HasParentSupport() const
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
SwNumRule * GetNumRule(SwTextFormatColl &rTextFormatColl)
determines the list style, which directly set at the given paragraph style
Definition: fmtcol.cxx:76
SfxStyleSearchBits
rtl::Reference< SwDocStyleSheet > mxStyleSheet
Definition: docstyle.hxx:207
virtual OUString GetDescription(MapUnit eMetric)
virtual void Remove(SfxStyleSheetBase *pStyle) override
Definition: docstyle.cxx:2409