xref: /AOO41X/main/svl/inc/svl/style.hxx (revision 49bd4d4b0041a732963ad6f2f737c048ee2652b5)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef _SFXSTYLE_HXX
23 #define _SFXSTYLE_HXX
24 
25 #include <com/sun/star/style/XStyle.hpp>
26 #include <com/sun/star/lang/XUnoTunnel.hpp>
27 #include <rtl/ref.hxx>
28 #include <vector>
29 #include <comphelper/weak.hxx>
30 #include <cppuhelper/implbase2.hxx>
31 #include <svl/svldllapi.h>
32 #include <rsc/rscsfx.hxx>
33 #include <tools/string.hxx>
34 #include <svl/hint.hxx>
35 #include <svl/lstner.hxx>
36 #include <svl/brdcst.hxx>
37 #include <svl/poolitem.hxx>
38 #include <svl/style.hrc>
39 #include <boost/shared_ptr.hpp>
40 
41 class SfxItemSet;
42 class SfxItemPool;
43 class SfxStyleSheetBasePool;
44 class SvStream;
45 
46 /*
47 Everyone changing instances of SfxStyleSheetBasePool or SfxStyleSheetBase
48 mußt broadcast this using <SfxStyleSheetBasePool::GetBroadcaster()> broadcasten.
49 The class <SfxStyleSheetHint> is used for this, it contains an Action-Id and a
50 pointer to the <SfxStyleSheetBase>. The actions are:
51 
52 #define SFX_STYLESHEET_CREATED      // style is created
53 #define SFX_STYLESHEET_MODIFIED     // style is modified
54 #define SFX_STYLESHEET_CHANGED      // style is replaced
55 #define SFX_STYLESHEET_ERASED       // style is deleted
56 
57 The following methods already broadcast themself
58 
59 SfxStyleSheetHint(SFX_STYLESHEET_MODIFIED) from:
60    SfxStyleSheetBase::SetName( const String& rName )
61    SfxStyleSheetBase::SetParent( const String& rName )
62    SfxStyleSheetBase::SetFollow( const String& rName )
63 
64 SfxSimpleHint(SFX_HINT_DYING) from:
65    SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
66 
67 SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *p ) from:
68    SfxStyleSheetBasePool::Make( const String& rName,
69    SfxStyleFamily eFam, sal_uInt16 mask, sal_uInt16 nPos)
70 
71 SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *pNew ) from:
72    SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
73 
74 SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) from:
75    SfxStyleSheetBasePool::Erase( SfxStyleSheetBase* p )
76    SfxStyleSheetBasePool::Clear()
77 */
78 
79 #define VIRTUAL510 virtual
80 
81 class SVL_DLLPUBLIC SfxStyleSheetBase : public comphelper::OWeakTypeObject
82 {
83     friend class SfxStyleSheetBasePool;
84 
85 protected:
86     SfxStyleSheetBasePool&  rPool;          // zugehoeriger Pool
87     SfxStyleFamily          nFamily;        // Familie
88 
89     UniString               aName, aParent, aFollow;
90     rtl::OUString           maDisplayName;
91     String                  aHelpFile;      // Name der Hilfedatei
92     SfxItemSet*             pSet;           // ItemSet
93     sal_uInt16                  nMask;          // Flags
94 
95     sal_uLong                   nHelpId;        // Hilfe-ID
96 
97     sal_Bool                    bMySet;         // sal_True: Set loeschen im dtor
98 
99     SfxStyleSheetBase(); // do not use!
100     SfxStyleSheetBase( const UniString&, SfxStyleSheetBasePool&, SfxStyleFamily eFam, sal_uInt16 mask );
101     SfxStyleSheetBase( const SfxStyleSheetBase& );
102     virtual ~SfxStyleSheetBase();
103     virtual void Load( SvStream&, sal_uInt16 );
104     virtual void Store( SvStream& );
105 
106 public:
107     TYPEINFO();
108 
109     // returns the internal name of this style
110     virtual const UniString& GetName() const;
111 
112     // sets the internal name of this style
113     virtual sal_Bool SetName( const UniString& );
114 
115     /** returns the display name of this style, it is used at the user interface.
116         If the display name is empty, this method returns the internal name. */
117     virtual rtl::OUString GetDisplayName() const;
118 
119     // sets the display name of this style
120     virtual void SetDisplayName( const rtl::OUString& );
121 
122     virtual const UniString& GetParent() const;
123     virtual sal_Bool SetParent( const UniString& );
124     virtual const UniString& GetFollow() const;
125     virtual sal_Bool SetFollow( const UniString& );
126     virtual sal_Bool HasFollowSupport() const;      // Default sal_True
127     virtual sal_Bool HasParentSupport() const;      // Default sal_True
128     virtual sal_Bool HasClearParentSupport() const; // Default sal_False
129     virtual sal_Bool IsUsed() const;                // Default sal_True
130         // Default aus dem Itemset; entweder dem uebergebenen
131         // oder aus dem per GetItemSet() zurueckgelieferten Set
132     virtual UniString GetDescription();
133     virtual UniString GetDescription( SfxMapUnit eMetric );
134 
GetPool()135     SfxStyleSheetBasePool& GetPool() { return rPool;   }
GetFamily() const136     SfxStyleFamily GetFamily() const     { return nFamily; }
GetMask() const137     sal_uInt16   GetMask() const     { return nMask; }
SetMask(sal_uInt16 mask)138     void     SetMask( sal_uInt16 mask) { nMask = mask; }
IsUserDefined() const139     sal_Bool   IsUserDefined() const
140            { return sal_Bool( ( nMask & SFXSTYLEBIT_USERDEF) != 0 ); }
141 
142     virtual sal_uLong GetHelpId( String& rFile );
143     virtual void   SetHelpId( const String& r, sal_uLong nId );
144 
145     virtual SfxItemSet& GetItemSet();
146     virtual sal_uInt16 GetVersion() const;
147 };
148 
149 //=========================================================================
150 
151 typedef std::vector< rtl::Reference< SfxStyleSheetBase > > SfxStyles;
152 
153 //=========================================================================
154 
155 class SVL_DLLPUBLIC SfxStyleSheetIterator
156 
157 /*  [Beschreibung]
158 
159     Klasse zum Iterieren und Suchen auf einem SfxStyleSheetBasePool.
160 
161 */
162 
163 {
164 public:
165     SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
166                           SfxStyleFamily eFam, sal_uInt16 n=0xFFFF );
167     virtual sal_uInt16 GetSearchMask() const;
168     virtual SfxStyleFamily GetSearchFamily() const;
169     virtual sal_uInt16 Count();
170     virtual SfxStyleSheetBase *operator[](sal_uInt16 nIdx);
171     virtual SfxStyleSheetBase* First();
172     virtual SfxStyleSheetBase* Next();
173     virtual SfxStyleSheetBase* Find(const UniString& rStr);
174     virtual ~SfxStyleSheetIterator();
175 
176 protected:
177 
178     SfxStyleSheetBasePool*  pBasePool;
179     SfxStyleFamily          nSearchFamily;
180     sal_uInt16                  nMask;
SearchUsed() const181     sal_Bool                    SearchUsed() const { return bSearchUsed; }
182 
183 private:
GetPos()184     sal_uInt16                  GetPos(){return nAktPosition;}
185     SVL_DLLPRIVATE sal_Bool                     IsTrivialSearch();
186     SVL_DLLPRIVATE sal_Bool                     DoesStyleMatch(SfxStyleSheetBase *pStyle);
187 
188     void*                   pImp;
189     SfxStyleSheetBase*      pAktStyle;
190     sal_uInt16                  nAktPosition;
191     sal_Bool                    bSearchUsed;
192 
193 friend class SfxStyleSheetBasePool;
194 };
195 
196 typedef ::boost::shared_ptr< SfxStyleSheetIterator > SfxStyleSheetIteratorPtr;
197 //=========================================================================
198 
199 class SfxStyleSheetBasePool_Impl;
200 
201 class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
202 {
203 friend class SfxStyleSheetIterator;
204 friend class SfxStyleSheetBase;
205 
206     SfxStyleSheetBasePool_Impl *pImp;
207 
208 private:
209     SVL_DLLPRIVATE sal_Bool                         Load1_Impl( SvStream& );
210     SVL_DLLPRIVATE SfxStyleSheetIterator&      GetIterator_Impl();
211 protected:
212     String                      aAppName;
213     SfxItemPool&                rPool;
214     SfxStyles                   aStyles;
215     SfxStyleFamily              nSearchFamily;
216     sal_uInt16                      nMask;
217 
218     SfxStyleSheetBase&          Add( SfxStyleSheetBase& );
219     void                        ChangeParent( const UniString&, const UniString&, sal_Bool bVirtual = sal_True );
220     virtual SfxStyleSheetBase*  Create( const UniString&, SfxStyleFamily, sal_uInt16 );
221     virtual SfxStyleSheetBase*  Create( const SfxStyleSheetBase& );
222 
223                                 ~SfxStyleSheetBasePool();
224 
225 public:
226                                 SfxStyleSheetBasePool( SfxItemPool& );
227                                 SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
228 
229     static String               GetStreamName();
230 
GetAppName() const231     const String&               GetAppName() const { return aAppName;   }
232 
233     SfxItemPool&                GetPool();
234     const SfxItemPool&          GetPool() const;
235 
236     virtual SfxStyleSheetIteratorPtr CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
237     virtual sal_uInt16              Count();
238     virtual SfxStyleSheetBase*  operator[](sal_uInt16 nIdx);
239 
240     virtual SfxStyleSheetBase&  Make(const UniString&,
241                                      SfxStyleFamily eFam,
242                                      sal_uInt16 nMask = 0xffff ,
243                                      sal_uInt16 nPos = 0xffff);
244 
245     virtual void             Replace(
246         SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget );
247 
248     virtual void                Remove( SfxStyleSheetBase* );
249     virtual void                Insert( SfxStyleSheetBase* );
250 
251     virtual void                Clear();
252 
253     SfxStyleSheetBasePool&      operator=( const SfxStyleSheetBasePool& );
254     SfxStyleSheetBasePool&      operator+=( const SfxStyleSheetBasePool& );
255 
256     const SfxStyles&            GetStyles();
257     virtual SfxStyleSheetBase*  First();
258     virtual SfxStyleSheetBase*  Next();
259     virtual SfxStyleSheetBase*  Find( const UniString&, SfxStyleFamily eFam, sal_uInt16 n=0xFFFF );
260 
261     virtual sal_Bool                SetParent(SfxStyleFamily eFam,
262                                           const UniString &rStyle,
263                                           const UniString &rParent);
264 
Find(const UniString & rStr)265     SfxStyleSheetBase*          Find(const UniString& rStr)
266                                 { return Find(rStr, nSearchFamily, nMask); }
267 
268     void                        SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n=0xFFFF );
269     sal_uInt16                      GetSearchMask() const;
GetSearchFamily() const270     SfxStyleFamily              GetSearchFamily() const  { return nSearchFamily; }
271 
272     sal_Bool                        Load( SvStream& );
273     sal_Bool                        Store( SvStream&, sal_Bool bUsed = sal_True );
274 };
275 
276 //=========================================================================
277 
278 class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
279                      public SfxListener, public SfxBroadcaster
280 {
281 public:
282                         TYPEINFO();
283 
284                         SfxStyleSheet( const UniString&, const SfxStyleSheetBasePool&, SfxStyleFamily, sal_uInt16 );
285                         SfxStyleSheet( const SfxStyleSheet& );
286 
287     virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
288     virtual sal_Bool        SetParent( const UniString& );
289 
290 protected:
291     SfxStyleSheet(); // do not use!
292     virtual             ~SfxStyleSheet();
293 };
294 
295 //=========================================================================
296 
297 class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
298 {
299 protected:
300     using SfxStyleSheetBasePool::Create;
301     virtual SfxStyleSheetBase* Create(const UniString&, SfxStyleFamily, sal_uInt16 mask);
302     virtual SfxStyleSheetBase* Create(const SfxStyleSheet &);
303 
304 public:
305     SfxStyleSheetPool( SfxItemPool const& );
306 
307 //  virtual sal_Bool CopyTo(SfxStyleSheetPool &rDest, const String &rSourceName);
308 };
309 
310 //=========================================================================
311 
312 #define SFX_STYLESHEET_CREATED       1  // neu
313 #define SFX_STYLESHEET_MODIFIED      2  // ver"andert
314 #define SFX_STYLESHEET_CHANGED       3  // gel"oscht und neu (ausgetauscht)
315 #define SFX_STYLESHEET_ERASED        4  // gel"oscht
316 #define SFX_STYLESHEET_INDESTRUCTION 5  // wird gerade entfernt
317 
318 #define SFX_STYLESHEETPOOL_CHANGES  1  // Aenderungen, die den Zustand
319                                        // des Pools anedern, aber nicht
320                                        // ueber die STYLESHEET Hints
321                                        // verschickt werden sollen.
322 
323 //========================================================================
324 
325 class SVL_DLLPUBLIC SfxStyleSheetPoolHint : public SfxHint
326 {
327     sal_uInt16 nHint;
328 
329 public:
330     TYPEINFO();
331 
SfxStyleSheetPoolHint(sal_uInt16 nArgHint)332                         SfxStyleSheetPoolHint(sal_uInt16 nArgHint) :  nHint(nArgHint){}
GetHint() const333     sal_uInt16              GetHint() const
334                         { return nHint; }
335 };
336 
337 //=========================================================================
338 
339 class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
340 {
341     SfxStyleSheetBase*  pStyleSh;
342     sal_uInt16              nHint;
343 
344 public:
345                         TYPEINFO();
346 
347                         SfxStyleSheetHint( sal_uInt16 );
348                         SfxStyleSheetHint( sal_uInt16, SfxStyleSheetBase& );
GetStyleSheet() const349     SfxStyleSheetBase*  GetStyleSheet() const
350                         { return pStyleSh; }
GetHint() const351     sal_uInt16              GetHint() const
352                         { return nHint; }
353 };
354 
355 class SVL_DLLPUBLIC SfxStyleSheetHintExtended: public SfxStyleSheetHint
356 {
357     String              aName;
358 
359 public:
360                         TYPEINFO();
361 
362                         SfxStyleSheetHintExtended(
363                             sal_uInt16, const String& rOld );
364                         SfxStyleSheetHintExtended(
365                             sal_uInt16, const String& rOld,
366                             SfxStyleSheetBase& );
GetOldName()367     const String&       GetOldName() { return aName; }
368 };
369 
370 class SVL_DLLPUBLIC SfxUnoStyleSheet : public ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >
371 {
372 public:
373     SfxUnoStyleSheet( const UniString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske );
374     SfxUnoStyleSheet( const SfxStyleSheet& _rSheet );
375 
376     static SfxUnoStyleSheet* getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle );
377 
378     // XUnoTunnel
379     virtual ::sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aIdentifier ) throw (::com::sun::star::uno::RuntimeException);
380 
381 private:
382     SfxUnoStyleSheet(); // not implemented
383 
384     static const ::com::sun::star::uno::Sequence< ::sal_Int8 >& getIdentifier();
385 };
386 
387 #endif
388 
389