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