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_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 <vector>
31 :
32 : class SwDoc;
33 : class SwDocStyleSheetPool;
34 : class SwPageDesc;
35 : class SwCharFormat;
36 : class SwTextFormatColl;
37 : class SwFrameFormat;
38 : class SwNumRule;
39 :
40 : // Temporary StyleSheet.
41 : class SW_DLLPUBLIC SwDocStyleSheet : public SfxStyleSheetBase
42 : {
43 : friend class SwDocStyleSheetPool;
44 : friend class SwStyleSheetIterator;
45 :
46 : SwCharFormat* pCharFormat;
47 : SwTextFormatColl* pColl;
48 : SwFrameFormat* pFrameFormat;
49 : const SwPageDesc* pDesc;
50 : const SwNumRule* pNumRule;
51 :
52 : SwDoc& rDoc;
53 : SfxItemSet aCoreSet;
54 :
55 : bool bPhysical;
56 :
57 : /// Make empty shell a real StyleSheet (Core).
58 : SAL_DLLPRIVATE void Create();
59 :
60 : /// Fill StyleSheet with data.
61 : enum FillStyleType {
62 : FillOnlyName,
63 : FillAllInfo,
64 : FillPhysical
65 : };
66 :
67 : SAL_DLLPRIVATE bool FillStyleSheet( FillStyleType eFType );
68 :
69 : protected:
70 : virtual ~SwDocStyleSheet();
71 :
72 : public:
73 : SwDocStyleSheet( SwDoc& rDoc,
74 : const OUString& rName,
75 : SwDocStyleSheetPool* pPool,
76 : SfxStyleFamily eFam,
77 : sal_uInt16 nMask);
78 :
79 : SwDocStyleSheet( const SwDocStyleSheet& );
80 :
81 : void Reset();
82 :
83 1359847 : void SetMask(sal_uInt16 nMsk) { nMask = nMsk; }
84 906951 : void SetFamily(SfxStyleFamily eFam) { nFamily = eFam; }
85 :
86 884378 : bool IsPhysical() const { return bPhysical; }
87 : void SetPhysical(bool bPhys);
88 :
89 : virtual void SetHidden( bool bHidden ) SAL_OVERRIDE;
90 : virtual bool IsHidden( ) const SAL_OVERRIDE;
91 : void SetGrabBagItem(const com::sun::star::uno::Any& rVal);
92 : void GetGrabBagItem(com::sun::star::uno::Any& rVal) const;
93 :
94 : /** add optional parameter <bResetIndentAttrsAtParagraphStyle>, default value false,
95 : which indicates that the indent attributes at a paragraph style should
96 : be reset in case that a list style is applied to the paragraph style and
97 : no indent attributes are applied. */
98 : void SetItemSet( const SfxItemSet& rSet,
99 : const bool bResetIndentAttrsAtParagraphStyle = false );
100 :
101 : virtual SfxItemSet& GetItemSet() SAL_OVERRIDE;
102 : /** new method for paragraph styles to merge indent attributes of applied list
103 : style into the given item set, if the list style indent attributes are applicable. */
104 : void MergeIndentAttrsOfListStyle( SfxItemSet& rSet );
105 : virtual const OUString& GetParent() const SAL_OVERRIDE;
106 : virtual const OUString& GetFollow() const SAL_OVERRIDE;
107 :
108 : virtual sal_uLong GetHelpId( OUString& rFile ) SAL_OVERRIDE;
109 : virtual void SetHelpId( const OUString& r, sal_uLong nId ) SAL_OVERRIDE;
110 :
111 : /** Preset the members without physical access.
112 : Used by StyleSheetPool. */
113 920811 : void PresetName(const OUString& rName) { aName = rName; }
114 : void PresetNameAndFamily(const OUString& rName);
115 727439 : void PresetParent(const OUString& rName){ aParent = rName; }
116 850789 : void PresetFollow(const OUString& rName){ aFollow = rName; }
117 :
118 : virtual bool SetName(const OUString& rNewName, bool bReindexNow = true) SAL_OVERRIDE;
119 : virtual bool SetParent( const OUString& rStr) SAL_OVERRIDE;
120 : virtual bool SetFollow( const OUString& rStr) SAL_OVERRIDE;
121 :
122 : virtual bool HasFollowSupport() const SAL_OVERRIDE;
123 : virtual bool HasParentSupport() const SAL_OVERRIDE;
124 : virtual bool HasClearParentSupport() const SAL_OVERRIDE;
125 : virtual OUString GetDescription() SAL_OVERRIDE;
126 : virtual OUString GetDescription(SfxMapUnit eUnit) SAL_OVERRIDE;
127 :
128 : SwCharFormat* GetCharFormat();
129 : SwTextFormatColl* GetCollection();
130 : SwFrameFormat* GetFrameFormat();
131 : const SwPageDesc* GetPageDesc();
132 : const SwNumRule* GetNumRule();
133 : void SetNumRule(const SwNumRule& rRule);
134 :
135 : virtual bool IsUsed() const SAL_OVERRIDE;
136 : };
137 :
138 : // Iterator for Pool.
139 : class SwStyleSheetIterator : public SfxStyleSheetIterator, public SfxListener
140 : {
141 : // Local helper class.
142 22732 : class SwPoolFormatList
143 : {
144 : std::vector<OUString> maImpl;
145 : typedef std::unordered_map<OUString, sal_uInt32, OUStringHash> UniqueHash;
146 : UniqueHash maUnique;
147 : void rehash();
148 : public:
149 22734 : SwPoolFormatList() {}
150 : void Append( char cChar, const OUString& rStr );
151 93952 : void clear() { maImpl.clear(); maUnique.clear(); }
152 421587 : size_t size() { return maImpl.size(); }
153 48662 : bool empty() { return maImpl.empty(); }
154 : sal_uInt32 FindName(SfxStyleFamily eFam, const OUString &rName);
155 : void RemoveName(SfxStyleFamily eFam, const OUString &rName);
156 408778 : const OUString &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; }
157 : };
158 :
159 : rtl::Reference< SwDocStyleSheet > mxIterSheet;
160 : rtl::Reference< SwDocStyleSheet > mxStyleSheet;
161 : SwPoolFormatList aLst;
162 : sal_uInt32 nLastPos;
163 : bool bFirstCalled;
164 :
165 : void AppendStyleList(const ::std::vector<OUString>& rLst,
166 : bool bUsed,
167 : bool bTestHidden,
168 : bool bOnlyHidden,
169 : sal_uInt16 nSection,
170 : char cType);
171 :
172 : public:
173 : SwStyleSheetIterator( SwDocStyleSheetPool* pBase,
174 : SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
175 : virtual ~SwStyleSheetIterator();
176 :
177 : virtual sal_uInt16 Count() SAL_OVERRIDE;
178 : virtual SfxStyleSheetBase *operator[](sal_uInt16 nIdx) SAL_OVERRIDE;
179 : virtual SfxStyleSheetBase* First() SAL_OVERRIDE;
180 : virtual SfxStyleSheetBase* Next() SAL_OVERRIDE;
181 : virtual SfxStyleSheetBase* Find(const OUString& rStr) SAL_OVERRIDE;
182 :
183 : virtual void Notify( SfxBroadcaster&, const SfxHint& ) SAL_OVERRIDE;
184 :
185 : void InvalidateIterator();
186 : };
187 :
188 : class SwDocStyleSheetPool : public SfxStyleSheetBasePool
189 : {
190 : rtl::Reference< SwDocStyleSheet > mxStyleSheet;
191 : SwDoc& rDoc;
192 : bool bOrganizer : 1; ///< Organizer
193 :
194 : virtual SfxStyleSheetBase* Create( const OUString&, SfxStyleFamily, sal_uInt16 nMask) SAL_OVERRIDE;
195 : virtual SfxStyleSheetBase* Create( const SfxStyleSheetBase& ) SAL_OVERRIDE;
196 :
197 : using SfxStyleSheetBasePool::Find;
198 :
199 : public:
200 : SwDocStyleSheetPool( SwDoc&, bool bOrganizer = false );
201 :
202 : virtual void Replace( SfxStyleSheetBase& rSource,
203 : SfxStyleSheetBase& rTarget ) SAL_OVERRIDE;
204 : virtual SfxStyleSheetBase& Make(const OUString&, SfxStyleFamily,
205 : sal_uInt16 nMask) SAL_OVERRIDE;
206 :
207 : virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam,
208 : sal_uInt16 n=SFXSTYLEBIT_ALL ) SAL_OVERRIDE;
209 :
210 : virtual bool SetParent( SfxStyleFamily eFam, const OUString &rStyle,
211 : const OUString &rParent ) SAL_OVERRIDE;
212 :
213 : virtual void Remove( SfxStyleSheetBase* pStyle) SAL_OVERRIDE;
214 :
215 : void SetOrganizerMode( bool bMode ) { bOrganizer = bMode; }
216 48662 : bool IsOrganizerMode() const { return bOrganizer; }
217 :
218 : virtual SfxStyleSheetIteratorPtr CreateIterator( SfxStyleFamily, sal_uInt16 nMask ) SAL_OVERRIDE;
219 :
220 311747 : SwDoc& GetDoc() const { return rDoc; }
221 :
222 : void dispose();
223 :
224 : virtual void SAL_CALL acquire( ) throw () SAL_OVERRIDE;
225 : virtual void SAL_CALL release( ) throw () SAL_OVERRIDE;
226 :
227 : void InvalidateIterator();
228 :
229 : protected:
230 : virtual ~SwDocStyleSheetPool();
231 :
232 : private:
233 : SwDocStyleSheetPool( const SwDocStyleSheetPool& ) SAL_DELETED_FUNCTION;
234 : };
235 :
236 : #endif
237 :
238 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|