Branch libreoffice-5-0-4
[LibreOffice.git] / sw / inc / docstyle.hxx
blob8ad216df29154f6c517e9ff06729f442fa73408f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_INC_DOCSTYLE_HXX
20 #define INCLUDED_SW_INC_DOCSTYLE_HXX
22 #include <rtl/ref.hxx>
23 #include <rtl/ustring.hxx>
25 #include <svl/style.hxx>
26 #include <svl/itemset.hxx>
27 #include "swdllapi.h"
29 #include <unordered_map>
30 #include <vector>
32 class SwDoc;
33 class SwDocStyleSheetPool;
34 class SwPageDesc;
35 class SwCharFormat;
36 class SwTextFormatColl;
37 class SwFrameFormat;
38 class SwNumRule;
40 // Temporary StyleSheet.
41 class SW_DLLPUBLIC SwDocStyleSheet : public SfxStyleSheetBase
43 friend class SwDocStyleSheetPool;
44 friend class SwStyleSheetIterator;
46 SwCharFormat* pCharFormat;
47 SwTextFormatColl* pColl;
48 SwFrameFormat* pFrameFormat;
49 const SwPageDesc* pDesc;
50 const SwNumRule* pNumRule;
52 SwDoc& rDoc;
53 SfxItemSet aCoreSet;
55 bool bPhysical;
57 /// Make empty shell a real StyleSheet (Core).
58 SAL_DLLPRIVATE void Create();
60 /// Fill StyleSheet with data.
61 enum FillStyleType {
62 FillOnlyName,
63 FillAllInfo,
64 FillPhysical,
65 FillPreview,
68 SAL_DLLPRIVATE bool FillStyleSheet(FillStyleType eFType,
69 std::unique_ptr<SfxItemSet> * o_ppFlatSet = nullptr);
71 protected:
72 virtual ~SwDocStyleSheet();
74 public:
75 SwDocStyleSheet( SwDoc& rDoc,
76 const OUString& rName,
77 SwDocStyleSheetPool* pPool,
78 SfxStyleFamily eFam,
79 sal_uInt16 nMask);
81 SwDocStyleSheet( const SwDocStyleSheet& );
83 void Reset();
85 void SetMask(sal_uInt16 nMsk) { nMask = nMsk; }
86 void SetFamily(SfxStyleFamily eFam) { nFamily = eFam; }
88 bool IsPhysical() const { return bPhysical; }
89 void SetPhysical(bool bPhys);
91 virtual void SetHidden( bool bHidden ) SAL_OVERRIDE;
92 virtual bool IsHidden( ) const SAL_OVERRIDE;
93 void SetGrabBagItem(const com::sun::star::uno::Any& rVal);
94 void GetGrabBagItem(com::sun::star::uno::Any& rVal) const;
96 /** add optional parameter <bResetIndentAttrsAtParagraphStyle>, default value false,
97 which indicates that the indent attributes at a paragraph style should
98 be reset in case that a list style is applied to the paragraph style and
99 no indent attributes are applied. */
100 void SetItemSet( const SfxItemSet& rSet,
101 const bool bResetIndentAttrsAtParagraphStyle = false );
103 virtual SfxItemSet& GetItemSet() SAL_OVERRIDE;
104 virtual std::unique_ptr<SfxItemSet> GetItemSetForPreview() SAL_OVERRIDE;
105 /** new method for paragraph styles to merge indent attributes of applied list
106 style into the given item set, if the list style indent attributes are applicable. */
107 void MergeIndentAttrsOfListStyle( SfxItemSet& rSet );
108 virtual const OUString& GetParent() const SAL_OVERRIDE;
109 virtual const OUString& GetFollow() const SAL_OVERRIDE;
111 virtual sal_uLong GetHelpId( OUString& rFile ) SAL_OVERRIDE;
112 virtual void SetHelpId( const OUString& r, sal_uLong nId ) SAL_OVERRIDE;
114 /** Preset the members without physical access.
115 Used by StyleSheetPool. */
116 void PresetName(const OUString& rName) { aName = rName; }
117 void PresetNameAndFamily(const OUString& rName);
118 void PresetParent(const OUString& rName){ aParent = rName; }
119 void PresetFollow(const OUString& rName){ aFollow = rName; }
121 virtual bool SetName(const OUString& rNewName, bool bReindexNow = true) SAL_OVERRIDE;
122 virtual bool SetParent( const OUString& rStr) SAL_OVERRIDE;
123 virtual bool SetFollow( const OUString& rStr) SAL_OVERRIDE;
125 virtual bool HasFollowSupport() const SAL_OVERRIDE;
126 virtual bool HasParentSupport() const SAL_OVERRIDE;
127 virtual bool HasClearParentSupport() const SAL_OVERRIDE;
128 virtual OUString GetDescription() SAL_OVERRIDE;
129 virtual OUString GetDescription(SfxMapUnit eUnit) SAL_OVERRIDE;
131 SwCharFormat* GetCharFormat();
132 SwTextFormatColl* GetCollection();
133 SwFrameFormat* GetFrameFormat();
134 const SwPageDesc* GetPageDesc();
135 const SwNumRule* GetNumRule();
136 void SetNumRule(const SwNumRule& rRule);
138 virtual bool IsUsed() const SAL_OVERRIDE;
141 // Iterator for Pool.
142 class SwStyleSheetIterator : public SfxStyleSheetIterator, public SfxListener
144 // Local helper class.
145 class SwPoolFormatList
147 std::vector<OUString> maImpl;
148 typedef std::unordered_map<OUString, sal_uInt32, OUStringHash> UniqueHash;
149 UniqueHash maUnique;
150 void rehash();
151 public:
152 SwPoolFormatList() {}
153 void Append( char cChar, const OUString& rStr );
154 void clear() { maImpl.clear(); maUnique.clear(); }
155 size_t size() { return maImpl.size(); }
156 bool empty() { return maImpl.empty(); }
157 sal_uInt32 FindName(SfxStyleFamily eFam, const OUString &rName);
158 void RemoveName(SfxStyleFamily eFam, const OUString &rName);
159 const OUString &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; }
162 rtl::Reference< SwDocStyleSheet > mxIterSheet;
163 rtl::Reference< SwDocStyleSheet > mxStyleSheet;
164 SwPoolFormatList aLst;
165 sal_uInt32 nLastPos;
166 bool bFirstCalled;
168 void AppendStyleList(const ::std::vector<OUString>& rLst,
169 bool bUsed,
170 bool bTestHidden,
171 bool bOnlyHidden,
172 sal_uInt16 nSection,
173 char cType);
175 public:
176 SwStyleSheetIterator( SwDocStyleSheetPool* pBase,
177 SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
178 virtual ~SwStyleSheetIterator();
180 virtual sal_uInt16 Count() SAL_OVERRIDE;
181 virtual SfxStyleSheetBase *operator[](sal_uInt16 nIdx) SAL_OVERRIDE;
182 virtual SfxStyleSheetBase* First() SAL_OVERRIDE;
183 virtual SfxStyleSheetBase* Next() SAL_OVERRIDE;
184 virtual SfxStyleSheetBase* Find(const OUString& rStr) SAL_OVERRIDE;
186 virtual void Notify( SfxBroadcaster&, const SfxHint& ) SAL_OVERRIDE;
188 void InvalidateIterator();
191 class SwDocStyleSheetPool : public SfxStyleSheetBasePool
193 rtl::Reference< SwDocStyleSheet > mxStyleSheet;
194 SwDoc& rDoc;
195 bool bOrganizer : 1; ///< Organizer
197 virtual SfxStyleSheetBase* Create( const OUString&, SfxStyleFamily, sal_uInt16 nMask) SAL_OVERRIDE;
198 virtual SfxStyleSheetBase* Create( const SfxStyleSheetBase& ) SAL_OVERRIDE;
200 using SfxStyleSheetBasePool::Find;
202 public:
203 SwDocStyleSheetPool( SwDoc&, bool bOrganizer = false );
205 virtual void Replace( SfxStyleSheetBase& rSource,
206 SfxStyleSheetBase& rTarget ) SAL_OVERRIDE;
207 virtual SfxStyleSheetBase& Make(const OUString&, SfxStyleFamily,
208 sal_uInt16 nMask) SAL_OVERRIDE;
210 virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam,
211 sal_uInt16 n=SFXSTYLEBIT_ALL ) SAL_OVERRIDE;
213 virtual bool SetParent( SfxStyleFamily eFam, const OUString &rStyle,
214 const OUString &rParent ) SAL_OVERRIDE;
216 virtual void Remove( SfxStyleSheetBase* pStyle) SAL_OVERRIDE;
218 void SetOrganizerMode( bool bMode ) { bOrganizer = bMode; }
219 bool IsOrganizerMode() const { return bOrganizer; }
221 virtual SfxStyleSheetIteratorPtr CreateIterator( SfxStyleFamily, sal_uInt16 nMask ) SAL_OVERRIDE;
223 SwDoc& GetDoc() const { return rDoc; }
225 void dispose();
227 virtual void SAL_CALL acquire( ) throw () SAL_OVERRIDE;
228 virtual void SAL_CALL release( ) throw () SAL_OVERRIDE;
230 void InvalidateIterator();
232 protected:
233 virtual ~SwDocStyleSheetPool();
235 private:
236 SwDocStyleSheetPool( const SwDocStyleSheetPool& ) SAL_DELETED_FUNCTION;
239 #endif
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */