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 20 #include <svx/svxids.hrc> 21 #include <hintids.hxx> 22 #include <vcl/svapp.hxx> 23 #include <svl/hint.hxx> 24 #include <svtools/ctrltool.hxx> 25 #include <svl/style.hxx> 26 #include <svl/itemiter.hxx> 27 #include <svl/listener.hxx> 28 #include <svl/zforlist.hxx> 29 #include <svl/zformat.hxx> 30 #include <svx/pageitem.hxx> 31 #include <editeng/sizeitem.hxx> 32 #include <editeng/ulspitem.hxx> 33 #include <editeng/lrspitem.hxx> 34 #include <editeng/boxitem.hxx> 35 #include <editeng/shaditem.hxx> 36 #include <editeng/brushitem.hxx> 37 #include <editeng/flstitem.hxx> 38 #include <editeng/paperinf.hxx> 39 #include <pagedesc.hxx> 40 #include <doc.hxx> 41 #include <IDocumentUndoRedo.hxx> 42 #include <IDocumentDeviceAccess.hxx> 43 #include <IDocumentStylePoolAccess.hxx> 44 #include <docary.hxx> 45 #include <charfmt.hxx> 46 #include <cmdid.h> 47 #include <unomid.h> 48 #include <unomap.hxx> 49 #include <unostyle.hxx> 50 #include <unosett.hxx> 51 #include <docsh.hxx> 52 #include <paratr.hxx> 53 #include <unoprnms.hxx> 54 #include <shellio.hxx> 55 #include <docstyle.hxx> 56 #include <unotextbodyhf.hxx> 57 #include <fmthdft.hxx> 58 #include <fmtpdsc.hxx> 59 #include <strings.hrc> 60 #include <poolfmt.hxx> 61 #include <unoevent.hxx> 62 #include <fmtruby.hxx> 63 #include <SwStyleNameMapper.hxx> 64 #include <sfx2/printer.hxx> 65 #include <com/sun/star/io/IOException.hpp> 66 #include <com/sun/star/style/ParagraphStyleCategory.hpp> 67 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 68 #include <com/sun/star/text/XTextTablesSupplier.hpp> 69 #include <com/sun/star/beans/PropertyAttribute.hpp> 70 #include <com/sun/star/beans/NamedValue.hpp> 71 #include <com/sun/star/drawing/BitmapMode.hpp> 72 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> 73 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> 74 #include <com/sun/star/document/XEventsSupplier.hpp> 75 #include <istyleaccess.hxx> 76 #include <GetMetricVal.hxx> 77 #include <fmtfsize.hxx> 78 #include <numrule.hxx> 79 #include <tblafmt.hxx> 80 #include <fmtautofmt.hxx> 81 82 #include <comphelper/servicehelper.hxx> 83 #include <cppuhelper/exc_hlp.hxx> 84 #include <cppuhelper/supportsservice.hxx> 85 #include <comphelper/sequence.hxx> 86 #include <sal/log.hxx> 87 88 #include <svl/stylepool.hxx> 89 #include <svx/unobrushitemhelper.hxx> 90 #include <editeng/unoipset.hxx> 91 #include <editeng/memberids.h> 92 #include <svx/unoshape.hxx> 93 #include <svx/xflbstit.hxx> 94 #include <svx/xflbmtit.hxx> 95 #include <swunohelper.hxx> 96 #include <svx/xbtmpit.hxx> 97 98 #include <ccoll.hxx> 99 #include <hints.hxx> 100 101 #include <cassert> 102 #include <memory> 103 #include <set> 104 #include <limits> 105 106 class SwXStyle; 107 class SwStyleProperties_Impl; 108 109 namespace 110 { 111 struct StyleFamilyEntry 112 { 113 using GetCountOrName_t = std::function<sal_Int32 (const SwDoc&, OUString*, sal_Int32)>; 114 using CreateStyle_t = std::function<uno::Reference<css::style::XStyle>(SfxStyleSheetBasePool*, SwDocShell*, const OUString&)>; 115 using TranslateIndex_t = std::function<sal_uInt16(const sal_uInt16)>; 116 SfxStyleFamily const m_eFamily; 117 sal_uInt16 const m_nPropMapType; 118 uno::Reference<beans::XPropertySetInfo> m_xPSInfo; 119 SwGetPoolIdFromName const m_aPoolId; 120 OUString const m_sName; 121 const char* m_pResId; 122 GetCountOrName_t const m_fGetCountOrName; 123 CreateStyle_t const m_fCreateStyle; 124 TranslateIndex_t const m_fTranslateIndex; 125 StyleFamilyEntry(SfxStyleFamily eFamily, sal_uInt16 nPropMapType, SwGetPoolIdFromName aPoolId, OUString const& sName, const char* pResId, GetCountOrName_t const & fGetCountOrName, CreateStyle_t const & fCreateStyle, TranslateIndex_t const & fTranslateIndex) 126 : m_eFamily(eFamily) 127 , m_nPropMapType(nPropMapType) 128 , m_xPSInfo(aSwMapProvider.GetPropertySet(nPropMapType)->getPropertySetInfo()) 129 , m_aPoolId(aPoolId) 130 , m_sName(sName) 131 , m_pResId(pResId) 132 , m_fGetCountOrName(fGetCountOrName) 133 , m_fCreateStyle(fCreateStyle) 134 , m_fTranslateIndex(fTranslateIndex) 135 { } 136 }; 137 static const std::vector<StyleFamilyEntry>* our_pStyleFamilyEntries; 138 // these should really be constexprs, but MSVC still is apparently too stupid for them 139 #define nPoolChrNormalRange (RES_POOLCHR_NORMAL_END - RES_POOLCHR_NORMAL_BEGIN) 140 #define nPoolChrHtmlRange (RES_POOLCHR_HTML_END - RES_POOLCHR_HTML_BEGIN) 141 #define nPoolCollTextRange ( RES_POOLCOLL_TEXT_END - RES_POOLCOLL_TEXT_BEGIN) 142 #define nPoolCollListsRange ( RES_POOLCOLL_LISTS_END - RES_POOLCOLL_LISTS_BEGIN) 143 #define nPoolCollExtraRange ( RES_POOLCOLL_EXTRA_END - RES_POOLCOLL_EXTRA_BEGIN) 144 #define nPoolCollRegisterRange ( RES_POOLCOLL_REGISTER_END - RES_POOLCOLL_REGISTER_BEGIN) 145 #define nPoolCollDocRange ( RES_POOLCOLL_DOC_END - RES_POOLCOLL_DOC_BEGIN) 146 #define nPoolCollHtmlRange ( RES_POOLCOLL_HTML_END - RES_POOLCOLL_HTML_BEGIN) 147 #define nPoolFrameRange ( RES_POOLFRM_END - RES_POOLFRM_BEGIN) 148 #define nPoolPageRange ( RES_POOLPAGE_END - RES_POOLPAGE_BEGIN) 149 #define nPoolNumRange ( RES_POOLNUMRULE_END - RES_POOLNUMRULE_BEGIN) 150 #define nPoolCollListsStackedStart ( nPoolCollTextRange) 151 #define nPoolCollExtraStackedStart ( nPoolCollListsStackedStart + nPoolCollListsRange) 152 #define nPoolCollRegisterStackedStart ( nPoolCollExtraStackedStart + nPoolCollExtraRange) 153 #define nPoolCollDocStackedStart ( nPoolCollRegisterStackedStart + nPoolCollRegisterRange) 154 #define nPoolCollHtmlStackedStart ( nPoolCollDocStackedStart + nPoolCollDocRange) 155 using paragraphstyle_t = std::remove_const<decltype(style::ParagraphStyleCategory::TEXT)>::type; 156 using collectionbits_t = sal_uInt16; 157 struct ParagraphStyleCategoryEntry 158 { 159 paragraphstyle_t const m_eCategory; 160 SfxStyleSearchBits const m_nSwStyleBits; 161 collectionbits_t const m_nCollectionBits; 162 ParagraphStyleCategoryEntry(paragraphstyle_t eCategory, SfxStyleSearchBits nSwStyleBits, collectionbits_t nCollectionBits) 163 : m_eCategory(eCategory) 164 , m_nSwStyleBits(nSwStyleBits) 165 , m_nCollectionBits(nCollectionBits) 166 { } 167 }; 168 static const std::vector<ParagraphStyleCategoryEntry>* our_pParagraphStyleCategoryEntries; 169 } 170 static const std::vector<StyleFamilyEntry>* lcl_GetStyleFamilyEntries(); 171 172 using namespace ::com::sun::star; 173 174 namespace sw 175 { 176 class XStyleFamily : public cppu::WeakImplHelper 177 < 178 container::XNameContainer, 179 lang::XServiceInfo, 180 container::XIndexAccess, 181 beans::XPropertySet 182 > 183 , public SfxListener 184 { 185 const StyleFamilyEntry& m_rEntry; 186 SfxStyleSheetBasePool* m_pBasePool; 187 SwDocShell* m_pDocShell; 188 189 SwXStyle* FindStyle(const OUString& rStyleName) const; 190 sal_Int32 GetCountOrName(OUString* pString, sal_Int32 nIndex = SAL_MAX_INT32) 191 { return m_rEntry.m_fGetCountOrName(*m_pDocShell->GetDoc(), pString, nIndex); }; 192 static const StyleFamilyEntry& InitEntry(SfxStyleFamily eFamily) 193 { 194 auto pEntries = lcl_GetStyleFamilyEntries(); 195 const auto pEntry = std::find_if(pEntries->begin(), pEntries->end(), 196 [eFamily] (const StyleFamilyEntry& e) { return e.m_eFamily == eFamily; }); 197 assert(pEntry != pEntries->end()); 198 return *pEntry; 199 } 200 public: 201 XStyleFamily(SwDocShell* pDocShell, const SfxStyleFamily eFamily) 202 : m_rEntry(InitEntry(eFamily)) 203 , m_pBasePool(pDocShell->GetStyleSheetPool()) 204 , m_pDocShell(pDocShell) 205 { 206 StartListening(*m_pBasePool); 207 } 208 209 //XIndexAccess 210 virtual sal_Int32 SAL_CALL getCount() override 211 { 212 SolarMutexGuard aGuard; 213 return GetCountOrName(nullptr); 214 }; 215 virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override; 216 217 //XElementAccess 218 virtual uno::Type SAL_CALL getElementType( ) override 219 { return cppu::UnoType<style::XStyle>::get(); }; 220 virtual sal_Bool SAL_CALL hasElements( ) override 221 { 222 if(!m_pBasePool) 223 throw uno::RuntimeException(); 224 return true; 225 } 226 227 //XNameAccess 228 virtual uno::Any SAL_CALL getByName(const OUString& Name) override; 229 virtual uno::Sequence< OUString > SAL_CALL getElementNames() override; 230 virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override; 231 232 //XNameContainer 233 virtual void SAL_CALL insertByName(const OUString& Name, const uno::Any& Element) override; 234 virtual void SAL_CALL replaceByName(const OUString& Name, const uno::Any& Element) override; 235 virtual void SAL_CALL removeByName(const OUString& Name) override; 236 237 //XPropertySet 238 virtual uno::Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override 239 { return {}; }; 240 virtual void SAL_CALL setPropertyValue( const OUString&, const uno::Any&) override 241 { SAL_WARN("sw.uno", "###unexpected!"); }; 242 virtual uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; 243 virtual void SAL_CALL addPropertyChangeListener( const OUString&, const uno::Reference<beans::XPropertyChangeListener>&) override 244 { SAL_WARN("sw.uno", "###unexpected!"); }; 245 virtual void SAL_CALL removePropertyChangeListener( const OUString&, const uno::Reference<beans::XPropertyChangeListener>&) override 246 { SAL_WARN("sw.uno", "###unexpected!"); }; 247 virtual void SAL_CALL addVetoableChangeListener(const OUString&, const uno::Reference<beans::XVetoableChangeListener>&) override 248 { SAL_WARN("sw.uno", "###unexpected!"); }; 249 virtual void SAL_CALL removeVetoableChangeListener(const OUString&, const uno::Reference<beans::XVetoableChangeListener>&) override 250 { SAL_WARN("sw.uno", "###unexpected!"); }; 251 252 //SfxListener 253 virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override 254 { 255 if(rHint.GetId() == SfxHintId::Dying) 256 { 257 m_pBasePool = nullptr; 258 m_pDocShell = nullptr; 259 EndListening(rBC); 260 } 261 } 262 263 //XServiceInfo 264 virtual OUString SAL_CALL getImplementationName() override 265 { return {"XStyleFamily"}; }; 266 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override 267 { return cppu::supportsService(this, rServiceName); }; 268 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override 269 { return { "com.sun.star.style.StyleFamily" }; } 270 }; 271 272 } 273 274 class SwStyleBase_Impl; 275 class SwXStyle : public cppu::WeakImplHelper 276 < 277 css::style::XStyle, 278 css::beans::XPropertySet, 279 css::beans::XMultiPropertySet, 280 css::lang::XServiceInfo, 281 css::lang::XUnoTunnel, 282 css::beans::XPropertyState, 283 css::beans::XMultiPropertyStates 284 > 285 , public SfxListener 286 , public SvtListener 287 { 288 SwDoc* m_pDoc; 289 OUString m_sStyleName; 290 const StyleFamilyEntry& m_rEntry; 291 bool m_bIsDescriptor; 292 bool const m_bIsConditional; 293 OUString m_sParentStyleName; 294 295 protected: 296 SfxStyleSheetBasePool* m_pBasePool; 297 std::unique_ptr<SwStyleProperties_Impl> m_pPropertiesImpl; 298 css::uno::Reference<css::container::XNameAccess> m_xStyleFamily; 299 css::uno::Reference<css::beans::XPropertySet> m_xStyleData; 300 301 template<sal_uInt16> 302 void SetPropertyValue(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&); 303 void SetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ); 304 SfxStyleSheetBase* GetStyleSheetBase(); 305 void PrepareStyleBase(SwStyleBase_Impl& rBase); 306 template<sal_uInt16> 307 uno::Any GetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase); 308 uno::Any GetStyleProperty_Impl(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase); 309 uno::Any GetPropertyValue_Impl(const SfxItemPropertySet* pPropSet, SwStyleBase_Impl& rBase, const OUString& rPropertyName); 310 311 public: 312 SwXStyle(SwDoc* pDoc, SfxStyleFamily eFam, bool bConditional = false); 313 SwXStyle(SfxStyleSheetBasePool* pPool, SfxStyleFamily eFamily, SwDoc* pDoc, const OUString& rStyleName); 314 virtual ~SwXStyle() override; 315 316 317 static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId(); 318 319 //XUnoTunnel 320 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; 321 322 //XNamed 323 virtual OUString SAL_CALL getName() override; 324 virtual void SAL_CALL setName(const OUString& Name_) override; 325 326 //XStyle 327 virtual sal_Bool SAL_CALL isUserDefined() override; 328 virtual sal_Bool SAL_CALL isInUse() override; 329 virtual OUString SAL_CALL getParentStyle() override; 330 virtual void SAL_CALL setParentStyle(const OUString& aParentStyle) override; 331 332 //XPropertySet 333 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; 334 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override; 335 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; 336 virtual void SAL_CALL addPropertyChangeListener( const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener >& ) override 337 { OSL_FAIL("not implemented"); }; 338 virtual void SAL_CALL removePropertyChangeListener( const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener >& ) override 339 { OSL_FAIL("not implemented"); }; 340 virtual void SAL_CALL addVetoableChangeListener( const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener >& ) override 341 { OSL_FAIL("not implemented"); }; 342 virtual void SAL_CALL removeVetoableChangeListener( const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener >& ) override 343 { OSL_FAIL("not implemented"); }; 344 345 //XMultiPropertySet 346 virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ) override; 347 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames ) override; 348 virtual void SAL_CALL addPropertiesChangeListener( const css::uno::Sequence< OUString >&, const css::uno::Reference< css::beans::XPropertiesChangeListener >& ) override 349 {}; 350 virtual void SAL_CALL removePropertiesChangeListener( const css::uno::Reference< css::beans::XPropertiesChangeListener >& ) override 351 {}; 352 virtual void SAL_CALL firePropertiesChangeEvent( const css::uno::Sequence< OUString >&, const css::uno::Reference< css::beans::XPropertiesChangeListener >& ) override 353 {}; 354 355 //XPropertyState 356 virtual css::beans::PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) override; 357 virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates( const css::uno::Sequence< OUString >& aPropertyName ) override; 358 virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) override; 359 virtual css::uno::Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) override; 360 361 //XMultiPropertyStates 362 virtual void SAL_CALL setAllPropertiesToDefault( ) override; 363 virtual void SAL_CALL setPropertiesToDefault( const css::uno::Sequence< OUString >& aPropertyNames ) override; 364 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyDefaults( const css::uno::Sequence< OUString >& aPropertyNames ) override; 365 366 //XServiceInfo 367 virtual OUString SAL_CALL getImplementationName() override 368 { return {"SwXStyle"}; }; 369 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override 370 { return cppu::supportsService(this, rServiceName); }; 371 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; 372 373 //SfxListener 374 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; 375 //SvtListener 376 virtual void Notify(const SfxHint&) override; 377 const OUString& GetStyleName() const { return m_sStyleName;} 378 SfxStyleFamily GetFamily() const {return m_rEntry.m_eFamily;} 379 380 bool IsDescriptor() const {return m_bIsDescriptor;} 381 bool IsConditional() const { return m_bIsConditional;} 382 const OUString& GetParentStyleName() const { return m_sParentStyleName;} 383 void SetDoc(SwDoc* pDc, SfxStyleSheetBasePool* pPool) 384 { 385 m_bIsDescriptor = false; m_pDoc = pDc; 386 m_pBasePool = pPool; 387 SfxListener::StartListening(*m_pBasePool); 388 } 389 SwDoc* GetDoc() const { return m_pDoc; } 390 void Invalidate(); 391 void ApplyDescriptorProperties(); 392 void SetStyleName(const OUString& rSet){ m_sStyleName = rSet;} 393 /// @throws beans::PropertyVetoException 394 /// @throws lang::IllegalArgumentException 395 /// @throws lang::WrappedTargetException 396 /// @throws uno::RuntimeException 397 void SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase); 398 void PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet, const SfxItemPropertySimpleEntry& rEntry, const uno::Any& rVal, SwStyleBase_Impl& rBaseImpl); 399 }; 400 401 class SwXFrameStyle 402 : public SwXStyle 403 , public css::document::XEventsSupplier 404 , public sw::ICoreFrameStyle 405 { 406 public: 407 SwXFrameStyle(SfxStyleSheetBasePool& rPool, 408 SwDoc* pDoc, 409 const OUString& rStyleName) : 410 SwXStyle(&rPool, SfxStyleFamily::Frame, pDoc, rStyleName){} 411 explicit SwXFrameStyle(SwDoc *pDoc); 412 413 virtual void SAL_CALL acquire( ) throw() override {SwXStyle::acquire();} 414 virtual void SAL_CALL release( ) throw() override {SwXStyle::release();} 415 416 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; 417 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; 418 virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override; 419 420 //ICoreStyle 421 virtual void SetItem(sal_uInt16 eAtr, const SfxPoolItem& rItem) override; 422 virtual const SfxPoolItem* GetItem(sal_uInt16 eAtr) override; 423 virtual css::document::XEventsSupplier& GetEventsSupplier() override 424 { return *this; }; 425 }; 426 427 class SwXPageStyle 428 : public SwXStyle 429 { 430 protected: 431 void SetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ); 432 css::uno::Sequence< css::uno::Any > GetPropertyValues_Impl( const css::uno::Sequence< OUString >& aPropertyNames ); 433 434 public: 435 SwXPageStyle(SfxStyleSheetBasePool& rPool, SwDocShell* pDocSh, const OUString& rStyleName); 436 explicit SwXPageStyle(SwDocShell* pDocSh); 437 438 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override; 439 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; 440 441 virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ) override; 442 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames ) override; 443 }; 444 445 446 using sw::XStyleFamily; 447 448 OUString SwXStyleFamilies::getImplementationName() 449 { return {"SwXStyleFamilies"}; } 450 451 sal_Bool SwXStyleFamilies::supportsService(const OUString& rServiceName) 452 { 453 return cppu::supportsService(this, rServiceName); 454 } 455 456 uno::Sequence< OUString > SwXStyleFamilies::getSupportedServiceNames() 457 { return { "com.sun.star.style.StyleFamilies" }; } 458 459 SwXStyleFamilies::SwXStyleFamilies(SwDocShell& rDocShell) : 460 SwUnoCollection(rDocShell.GetDoc()), 461 m_pDocShell(&rDocShell) 462 { } 463 464 SwXStyleFamilies::~SwXStyleFamilies() 465 { } 466 467 uno::Any SAL_CALL SwXStyleFamilies::getByName(const OUString& Name) 468 { 469 SolarMutexGuard aGuard; 470 if(!IsValid()) 471 throw uno::RuntimeException(); 472 auto pEntries(lcl_GetStyleFamilyEntries()); 473 const auto pEntry = std::find_if(pEntries->begin(), pEntries->end(), 474 [&Name] (const StyleFamilyEntry& e) { return e.m_sName == Name; }); 475 if(pEntry == pEntries->end()) 476 throw container::NoSuchElementException(); 477 return getByIndex(pEntry-pEntries->begin()); 478 } 479 480 uno::Sequence< OUString > SwXStyleFamilies::getElementNames() 481 { 482 auto pEntries(lcl_GetStyleFamilyEntries()); 483 uno::Sequence<OUString> aNames(pEntries->size()); 484 std::transform(pEntries->begin(), pEntries->end(), 485 aNames.begin(), [] (const StyleFamilyEntry& e) { return e.m_sName; }); 486 return aNames; 487 } 488 489 sal_Bool SwXStyleFamilies::hasByName(const OUString& Name) 490 { 491 auto pEntries(lcl_GetStyleFamilyEntries()); 492 return std::any_of(pEntries->begin(), pEntries->end(), 493 [&Name] (const StyleFamilyEntry& e) { return e.m_sName == Name; }); 494 } 495 496 sal_Int32 SwXStyleFamilies::getCount() 497 { 498 return lcl_GetStyleFamilyEntries()->size(); 499 } 500 501 uno::Any SwXStyleFamilies::getByIndex(sal_Int32 nIndex) 502 { 503 auto pEntries(lcl_GetStyleFamilyEntries()); 504 SolarMutexGuard aGuard; 505 if(nIndex < 0 || nIndex >= static_cast<sal_Int32>(pEntries->size())) 506 throw lang::IndexOutOfBoundsException(); 507 if(!IsValid()) 508 throw uno::RuntimeException(); 509 auto eFamily = (*pEntries)[nIndex].m_eFamily; 510 assert(eFamily != SfxStyleFamily::All); 511 auto& rxFamily = m_vFamilies[eFamily]; 512 if(!rxFamily.is()) 513 rxFamily = new XStyleFamily(m_pDocShell, eFamily); 514 return uno::makeAny(rxFamily); 515 } 516 517 uno::Type SwXStyleFamilies::getElementType() 518 { 519 return cppu::UnoType<container::XNameContainer>::get(); 520 } 521 522 sal_Bool SwXStyleFamilies::hasElements() 523 { return true; } 524 525 void SwXStyleFamilies::loadStylesFromURL(const OUString& rURL, 526 const uno::Sequence< beans::PropertyValue >& aOptions) 527 { 528 SolarMutexGuard aGuard; 529 if(!IsValid() || rURL.isEmpty()) 530 throw uno::RuntimeException(); 531 SwgReaderOption aOpt; 532 aOpt.SetFrameFormats(true); 533 aOpt.SetTextFormats(true); 534 aOpt.SetPageDescs(true); 535 aOpt.SetNumRules(true); 536 aOpt.SetMerge(false); 537 for(const auto& rProperty: aOptions) 538 { 539 if(rProperty.Value.getValueType() != cppu::UnoType<bool>::get()) 540 continue; 541 const bool bValue = rProperty.Value.get<bool>(); 542 if(rProperty.Name == UNO_NAME_OVERWRITE_STYLES) 543 aOpt.SetMerge(!bValue); 544 else if(rProperty.Name == UNO_NAME_LOAD_NUMBERING_STYLES) 545 aOpt.SetNumRules(bValue); 546 else if(rProperty.Name == UNO_NAME_LOAD_PAGE_STYLES) 547 aOpt.SetPageDescs(bValue); 548 else if(rProperty.Name == UNO_NAME_LOAD_FRAME_STYLES) 549 aOpt.SetFrameFormats(bValue); 550 else if(rProperty.Name == UNO_NAME_LOAD_TEXT_STYLES) 551 aOpt.SetTextFormats(bValue); 552 } 553 const ErrCode nErr = m_pDocShell->LoadStylesFromFile( rURL, aOpt, true ); 554 if(nErr) 555 throw io::IOException(); 556 } 557 558 uno::Sequence< beans::PropertyValue > SwXStyleFamilies::getStyleLoaderOptions() 559 { 560 SolarMutexGuard aGuard; 561 uno::Sequence< beans::PropertyValue > aSeq(5); 562 beans::PropertyValue* pArray = aSeq.getArray(); 563 const uno::Any aVal(true); 564 pArray[0] = beans::PropertyValue(UNO_NAME_LOAD_TEXT_STYLES, -1, aVal, beans::PropertyState_DIRECT_VALUE); 565 pArray[1] = beans::PropertyValue(UNO_NAME_LOAD_FRAME_STYLES, -1, aVal, beans::PropertyState_DIRECT_VALUE); 566 pArray[2] = beans::PropertyValue(UNO_NAME_LOAD_PAGE_STYLES, -1, aVal, beans::PropertyState_DIRECT_VALUE); 567 pArray[3] = beans::PropertyValue(UNO_NAME_LOAD_NUMBERING_STYLES, -1, aVal, beans::PropertyState_DIRECT_VALUE); 568 pArray[4] = beans::PropertyValue(UNO_NAME_OVERWRITE_STYLES, -1, aVal, beans::PropertyState_DIRECT_VALUE); 569 return aSeq; 570 } 571 572 static bool lcl_GetHeaderFooterItem( 573 SfxItemSet const& rSet, OUString const& rPropName, bool const bFooter, 574 SvxSetItem const*& o_rpItem) 575 { 576 SfxItemState eState = rSet.GetItemState( 577 bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, 578 false, reinterpret_cast<const SfxPoolItem**>(&o_rpItem)); 579 if (SfxItemState::SET != eState && 580 rPropName == UNO_NAME_FIRST_IS_SHARED) 581 { // fdo#79269 header may not exist, check footer then 582 eState = rSet.GetItemState( 583 (!bFooter) ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, 584 false, reinterpret_cast<const SfxPoolItem**>(&o_rpItem)); 585 } 586 return SfxItemState::SET == eState; 587 } 588 589 template<enum SfxStyleFamily> 590 static sal_Int32 lcl_GetCountOrName(const SwDoc&, OUString*, sal_Int32); 591 592 template<> 593 sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Char>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex) 594 { 595 const sal_uInt16 nBaseCount = nPoolChrHtmlRange + nPoolChrNormalRange; 596 nIndex -= nBaseCount; 597 sal_Int32 nCount = 0; 598 for(auto pFormat : *rDoc.GetCharFormats()) 599 { 600 if(pFormat->IsDefault() && pFormat != rDoc.GetDfltCharFormat()) 601 continue; 602 if(!IsPoolUserFormat(pFormat->GetPoolFormatId())) 603 continue; 604 if(nIndex == nCount) 605 { 606 // the default character format needs to be set to "Default!" 607 if(rDoc.GetDfltCharFormat() == pFormat) 608 SwStyleNameMapper::FillUIName(RES_POOLCOLL_STANDARD, *pString); 609 else 610 *pString = pFormat->GetName(); 611 break; 612 } 613 ++nCount; 614 } 615 return nCount + nBaseCount; 616 } 617 618 template<> 619 sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Para>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex) 620 { 621 const sal_uInt16 nBaseCount = nPoolCollHtmlStackedStart + nPoolCollHtmlRange; 622 nIndex -= nBaseCount; 623 sal_Int32 nCount = 0; 624 for(auto pColl : *rDoc.GetTextFormatColls()) 625 { 626 if(pColl->IsDefault()) 627 continue; 628 if(!IsPoolUserFormat(pColl->GetPoolFormatId())) 629 continue; 630 if(nIndex == nCount) 631 { 632 *pString = pColl->GetName(); 633 break; 634 } 635 ++nCount; 636 } 637 return nCount + nBaseCount; 638 } 639 640 template<> 641 sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Frame>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex) 642 { 643 nIndex -= nPoolFrameRange; 644 sal_Int32 nCount = 0; 645 for(const auto pFormat : *rDoc.GetFrameFormats()) 646 { 647 if(pFormat->IsDefault() || pFormat->IsAuto()) 648 continue; 649 if(!IsPoolUserFormat(pFormat->GetPoolFormatId())) 650 continue; 651 if(nIndex == nCount) 652 { 653 *pString = pFormat->GetName(); 654 break; 655 } 656 ++nCount; 657 } 658 return nCount + nPoolFrameRange; 659 } 660 661 template<> 662 sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Page>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex) 663 { 664 nIndex -= nPoolPageRange; 665 sal_Int32 nCount = 0; 666 const size_t nArrLen = rDoc.GetPageDescCnt(); 667 for(size_t i = 0; i < nArrLen; ++i) 668 { 669 const SwPageDesc& rDesc = rDoc.GetPageDesc(i); 670 if(!IsPoolUserFormat(rDesc.GetPoolFormatId())) 671 continue; 672 if(nIndex == nCount) 673 { 674 *pString = rDesc.GetName(); 675 break; 676 } 677 ++nCount; 678 } 679 nCount += nPoolPageRange; 680 return nCount; 681 } 682 683 template<> 684 sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Pseudo>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex) 685 { 686 nIndex -= nPoolNumRange; 687 sal_Int32 nCount = 0; 688 for(const auto pRule : rDoc.GetNumRuleTable()) 689 { 690 if(pRule->IsAutoRule()) 691 continue; 692 if(!IsPoolUserFormat(pRule->GetPoolFormatId())) 693 continue; 694 if(nIndex == nCount) 695 { 696 *pString = pRule->GetName(); 697 break; 698 } 699 ++nCount; 700 } 701 return nCount + nPoolNumRange; 702 } 703 704 template<> 705 sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Table>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex) 706 { 707 if (!rDoc.HasTableStyles()) 708 return 0; 709 710 const auto pAutoFormats = &rDoc.GetTableStyles(); 711 const sal_Int32 nCount = pAutoFormats->size(); 712 if (0 <= nIndex && nIndex < nCount) 713 *pString = pAutoFormats->operator[](nIndex).GetName(); 714 715 return nCount; 716 } 717 718 template<> 719 sal_Int32 lcl_GetCountOrName<SfxStyleFamily::Cell>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex) 720 { 721 const auto& rAutoFormats = rDoc.GetTableStyles(); 722 const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap(); 723 const sal_Int32 nUsedCellStylesCount = rAutoFormats.size() * rTableTemplateMap.size(); 724 const sal_Int32 nCount = nUsedCellStylesCount + rDoc.GetCellStyles().size(); 725 if (0 <= nIndex && nIndex < nCount) 726 { 727 if (nUsedCellStylesCount > nIndex) 728 { 729 const sal_Int32 nAutoFormat = nIndex / rTableTemplateMap.size(); 730 const sal_Int32 nBoxFormat = rTableTemplateMap[nIndex % rTableTemplateMap.size()]; 731 const SwTableAutoFormat& rTableFormat = rAutoFormats[nAutoFormat]; 732 *pString = rTableFormat.GetName() 733 + rTableFormat.GetTableTemplateCellSubName(rTableFormat.GetBoxFormat(nBoxFormat)); 734 } 735 else 736 *pString = rDoc.GetCellStyles()[nIndex-nUsedCellStylesCount].GetName(); 737 } 738 return nCount; 739 } 740 741 template<SfxStyleFamily eFamily> 742 static uno::Reference< css::style::XStyle> lcl_CreateStyle(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) 743 { return pBasePool ? new SwXStyle(pBasePool, eFamily, pDocShell->GetDoc(), sStyleName) : new SwXStyle(pDocShell->GetDoc(), eFamily, false); }; 744 745 template<> 746 uno::Reference< css::style::XStyle> lcl_CreateStyle<SfxStyleFamily::Para>(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) 747 { return pBasePool ? new SwXStyle(pBasePool, SfxStyleFamily::Para, pDocShell->GetDoc(), sStyleName) : new SwXStyle(pDocShell->GetDoc(), SfxStyleFamily::Para, false); }; 748 template<> 749 uno::Reference< css::style::XStyle> lcl_CreateStyle<SfxStyleFamily::Frame>(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) 750 { return pBasePool ? new SwXFrameStyle(*pBasePool, pDocShell->GetDoc(), sStyleName) : new SwXFrameStyle(pDocShell->GetDoc()); }; 751 752 template<> 753 uno::Reference< css::style::XStyle> lcl_CreateStyle<SfxStyleFamily::Page>(SfxStyleSheetBasePool* pBasePool, SwDocShell* pDocShell, const OUString& sStyleName) 754 { return pBasePool ? new SwXPageStyle(*pBasePool, pDocShell, sStyleName) : new SwXPageStyle(pDocShell); }; 755 756 template<> 757 uno::Reference< css::style::XStyle> lcl_CreateStyle<SfxStyleFamily::Table>(SfxStyleSheetBasePool* /*pBasePool*/, SwDocShell* pDocShell, const OUString& sStyleName) 758 { return SwXTextTableStyle::CreateXTextTableStyle(pDocShell, sStyleName); }; 759 760 template<> 761 uno::Reference< css::style::XStyle> lcl_CreateStyle<SfxStyleFamily::Cell>(SfxStyleSheetBasePool* /*pBasePool*/, SwDocShell* pDocShell, const OUString& sStyleName) 762 { return SwXTextCellStyle::CreateXTextCellStyle(pDocShell, sStyleName); }; 763 764 uno::Reference<css::style::XStyle> SwXStyleFamilies::CreateStyle(SfxStyleFamily eFamily, SwDoc& rDoc) 765 { 766 auto pEntries(lcl_GetStyleFamilyEntries()); 767 const auto pEntry = std::find_if(pEntries->begin(), pEntries->end(), 768 [eFamily] (const StyleFamilyEntry& e) { return e.m_eFamily == eFamily; }); 769 return pEntry == pEntries->end() ? nullptr : pEntry->m_fCreateStyle(nullptr, rDoc.GetDocShell(), ""); 770 } 771 772 // FIXME: Ugly special casing that should die. 773 uno::Reference<css::style::XStyle> SwXStyleFamilies::CreateStyleCondParagraph(SwDoc& rDoc) 774 { return new SwXStyle(&rDoc, SfxStyleFamily::Para, true); }; 775 776 template<enum SfxStyleFamily> 777 static sal_uInt16 lcl_TranslateIndex(const sal_uInt16 nIndex); 778 779 template<> 780 sal_uInt16 lcl_TranslateIndex<SfxStyleFamily::Char>(const sal_uInt16 nIndex) 781 { 782 static_assert(nPoolChrNormalRange > 0 && nPoolChrHtmlRange > 0, "invalid pool range"); 783 if(nIndex < nPoolChrNormalRange) 784 return nIndex + RES_POOLCHR_NORMAL_BEGIN; 785 else if(nIndex < (nPoolChrHtmlRange+nPoolChrNormalRange)) 786 return nIndex + RES_POOLCHR_HTML_BEGIN - nPoolChrNormalRange; 787 throw lang::IndexOutOfBoundsException(); 788 } 789 790 template<> 791 sal_uInt16 lcl_TranslateIndex<SfxStyleFamily::Para>(const sal_uInt16 nIndex) 792 { 793 static_assert(nPoolCollTextRange > 0 && nPoolCollListsRange > 0 && nPoolCollExtraRange > 0 && nPoolCollRegisterRange > 0 && nPoolCollDocRange > 0 && nPoolCollHtmlRange > 0, "weird pool range"); 794 if(nIndex < nPoolCollListsStackedStart) 795 return nIndex + RES_POOLCOLL_TEXT_BEGIN; 796 else if(nIndex < nPoolCollExtraStackedStart) 797 return nIndex + RES_POOLCOLL_LISTS_BEGIN - nPoolCollListsStackedStart; 798 else if(nIndex < nPoolCollRegisterStackedStart) 799 return nIndex + RES_POOLCOLL_EXTRA_BEGIN - nPoolCollExtraStackedStart; 800 else if(nIndex < nPoolCollDocStackedStart) 801 return nIndex + RES_POOLCOLL_REGISTER_BEGIN - nPoolCollRegisterStackedStart; 802 else if(nIndex < nPoolCollHtmlStackedStart) 803 return nIndex + RES_POOLCOLL_DOC_BEGIN - nPoolCollDocStackedStart; 804 else if(nIndex < nPoolCollHtmlStackedStart + nPoolCollTextRange) 805 return nIndex + RES_POOLCOLL_HTML_BEGIN - nPoolCollHtmlStackedStart; 806 throw lang::IndexOutOfBoundsException(); 807 } 808 809 template<> 810 sal_uInt16 lcl_TranslateIndex<SfxStyleFamily::Table>(const sal_uInt16 nIndex) 811 { 812 return nIndex; 813 } 814 815 template<> 816 sal_uInt16 lcl_TranslateIndex<SfxStyleFamily::Cell>(const sal_uInt16 nIndex) 817 { 818 return nIndex; 819 } 820 821 template<sal_uInt16 nRangeBegin, sal_uInt16 nRangeSize> 822 static sal_uInt16 lcl_TranslateIndexRange(const sal_uInt16 nIndex) 823 { 824 if(nIndex < nRangeSize) 825 return nIndex + nRangeBegin; 826 throw lang::IndexOutOfBoundsException(); 827 } 828 829 uno::Any XStyleFamily::getByIndex(sal_Int32 nIndex) 830 { 831 SolarMutexGuard aGuard; 832 if(nIndex < 0) 833 throw lang::IndexOutOfBoundsException(); 834 if(!m_pBasePool) 835 throw uno::RuntimeException(); 836 OUString sStyleName; 837 try 838 { 839 SwStyleNameMapper::FillUIName(m_rEntry.m_fTranslateIndex(nIndex), sStyleName); 840 } catch(...) {} 841 if (sStyleName.isEmpty()) 842 GetCountOrName(&sStyleName, nIndex); 843 if(sStyleName.isEmpty()) 844 throw lang::IndexOutOfBoundsException(); 845 return getByName(sStyleName); 846 } 847 848 uno::Any XStyleFamily::getByName(const OUString& rName) 849 { 850 SolarMutexGuard aGuard; 851 OUString sStyleName; 852 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.m_aPoolId); 853 if(!m_pBasePool) 854 throw uno::RuntimeException(); 855 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 856 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName); 857 if(!pBase) 858 throw container::NoSuchElementException(); 859 uno::Reference<style::XStyle> xStyle = FindStyle(sStyleName); 860 if(!xStyle.is()) 861 xStyle = m_rEntry.m_fCreateStyle(m_pBasePool, m_pDocShell, m_rEntry.m_eFamily == SfxStyleFamily::Frame ? pBase->GetName() : sStyleName); 862 return uno::makeAny(xStyle); 863 } 864 865 uno::Sequence<OUString> XStyleFamily::getElementNames() 866 { 867 SolarMutexGuard aGuard; 868 if(!m_pBasePool) 869 throw uno::RuntimeException(); 870 std::vector<OUString> vRet; 871 std::unique_ptr<SfxStyleSheetIterator> pIt = m_pBasePool->CreateIterator(m_rEntry.m_eFamily, SfxStyleSearchBits::All); 872 for (SfxStyleSheetBase* pStyle = pIt->First(); pStyle; pStyle = pIt->Next()) 873 { 874 OUString sName; 875 SwStyleNameMapper::FillProgName(pStyle->GetName(), sName, m_rEntry.m_aPoolId); 876 vRet.push_back(sName); 877 } 878 return comphelper::containerToSequence(vRet); 879 } 880 881 sal_Bool XStyleFamily::hasByName(const OUString& rName) 882 { 883 SolarMutexGuard aGuard; 884 if(!m_pBasePool) 885 throw uno::RuntimeException(); 886 OUString sStyleName; 887 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.m_aPoolId); 888 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 889 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName); 890 return nullptr != pBase; 891 } 892 893 894 void XStyleFamily::insertByName(const OUString& rName, const uno::Any& rElement) 895 { 896 SolarMutexGuard aGuard; 897 if(!m_pBasePool) 898 throw uno::RuntimeException(); 899 OUString sStyleName; 900 SwStyleNameMapper::FillUIName(rName, sStyleName, m_rEntry.m_aPoolId); 901 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 902 SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName); 903 SfxStyleSheetBase* pUINameBase = m_pBasePool->Find( sStyleName ); 904 if(pBase || pUINameBase) 905 throw container::ElementExistException(); 906 if(rElement.getValueType().getTypeClass() != uno::TypeClass_INTERFACE) 907 throw lang::IllegalArgumentException(); 908 if (SwGetPoolIdFromName::CellStyle == m_rEntry.m_aPoolId) 909 { 910 // handle cell style 911 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>(); 912 SwXTextCellStyle* pNewStyle = dynamic_cast<SwXTextCellStyle*>(xStyle.get()); 913 if (!pNewStyle) 914 throw lang::IllegalArgumentException(); 915 916 pNewStyle->setName(sStyleName); // insertByName sets the element name 917 m_pDocShell->GetDoc()->GetCellStyles().AddBoxFormat(*pNewStyle->GetBoxFormat(), sStyleName); 918 pNewStyle->SetPhysical(); 919 } 920 else if (SwGetPoolIdFromName::TabStyle == m_rEntry.m_aPoolId) 921 { 922 // handle table style 923 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>(); 924 SwXTextTableStyle* pNewStyle = dynamic_cast<SwXTextTableStyle*>(xStyle.get()); 925 if (!pNewStyle) 926 throw lang::IllegalArgumentException(); 927 928 pNewStyle->setName(sStyleName); // insertByName sets the element name 929 m_pDocShell->GetDoc()->GetTableStyles().AddAutoFormat(*pNewStyle->GetTableFormat()); 930 pNewStyle->SetPhysical(); 931 } 932 else 933 { 934 uno::Reference<lang::XUnoTunnel> xStyleTunnel = rElement.get<uno::Reference<lang::XUnoTunnel>>(); 935 SwXStyle* pNewStyle = nullptr; 936 if(xStyleTunnel.is()) 937 { 938 pNewStyle = reinterpret_cast< SwXStyle * >( 939 sal::static_int_cast< sal_IntPtr >( xStyleTunnel->getSomething( SwXStyle::getUnoTunnelId()) )); 940 } 941 942 if (!pNewStyle || !pNewStyle->IsDescriptor() || pNewStyle->GetFamily() != m_rEntry.m_eFamily) 943 throw lang::IllegalArgumentException(); 944 945 SfxStyleSearchBits nMask = SfxStyleSearchBits::All; 946 if(m_rEntry.m_eFamily == SfxStyleFamily::Para && !pNewStyle->IsConditional()) 947 nMask &= ~SfxStyleSearchBits::SwCondColl; 948 m_pBasePool->Make(sStyleName, m_rEntry.m_eFamily, nMask); 949 pNewStyle->SetDoc(m_pDocShell->GetDoc(), m_pBasePool); 950 pNewStyle->SetStyleName(sStyleName); 951 const OUString sParentStyleName(pNewStyle->GetParentStyleName()); 952 if (!sParentStyleName.isEmpty()) 953 { 954 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 955 SfxStyleSheetBase* pParentBase = m_pBasePool->Find(sParentStyleName); 956 if(pParentBase && pParentBase->GetFamily() == m_rEntry.m_eFamily && 957 pParentBase->GetPool() == m_pBasePool) 958 m_pBasePool->SetParent(m_rEntry.m_eFamily, sStyleName, sParentStyleName); 959 } 960 // after all, we still need to apply the properties of the descriptor 961 pNewStyle->ApplyDescriptorProperties(); 962 } 963 } 964 965 void XStyleFamily::replaceByName(const OUString& rName, const uno::Any& rElement) 966 { 967 SolarMutexGuard aGuard; 968 if(!m_pBasePool) 969 throw uno::RuntimeException(); 970 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 971 SfxStyleSheetBase* pBase = m_pBasePool->Find(rName); 972 // replacements only for userdefined styles 973 if(!pBase) 974 throw container::NoSuchElementException(); 975 if (SwGetPoolIdFromName::CellStyle == m_rEntry.m_aPoolId) 976 { 977 // handle cell styles, don't call on assigned cell styles (TableStyle child) 978 OUString sParent; 979 SwBoxAutoFormat* pBoxAutoFormat = SwXTextCellStyle::GetBoxAutoFormat(m_pDocShell, rName, &sParent); 980 if (pBoxAutoFormat && sParent.isEmpty())// if parent exists then this style is assigned to a table style. Don't replace. 981 { 982 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>(); 983 SwXTextCellStyle* pStyleToReplaceWith = dynamic_cast<SwXTextCellStyle*>(xStyle.get()); 984 if (!pStyleToReplaceWith) 985 throw lang::IllegalArgumentException(); 986 987 pStyleToReplaceWith->setName(rName); 988 *pBoxAutoFormat = *pStyleToReplaceWith->GetBoxFormat(); 989 pStyleToReplaceWith->SetPhysical(); 990 } 991 } 992 else if (SwGetPoolIdFromName::TabStyle == m_rEntry.m_aPoolId) 993 { 994 // handle table styles 995 SwTableAutoFormat* pTableAutoFormat = SwXTextTableStyle::GetTableAutoFormat(m_pDocShell, rName); 996 if (pTableAutoFormat) 997 { 998 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>(); 999 SwXTextTableStyle* pStyleToReplaceWith = dynamic_cast<SwXTextTableStyle*>(xStyle.get()); 1000 if (!pStyleToReplaceWith) 1001 throw lang::IllegalArgumentException(); 1002 1003 pStyleToReplaceWith->setName(rName); 1004 *pTableAutoFormat = *pStyleToReplaceWith->GetTableFormat(); 1005 pStyleToReplaceWith->SetPhysical(); 1006 } 1007 } 1008 else 1009 { 1010 if(!pBase->IsUserDefined()) 1011 throw lang::IllegalArgumentException(); 1012 //if there's an object available to this style then it must be invalidated 1013 uno::Reference<style::XStyle> xStyle = FindStyle(pBase->GetName()); 1014 if(xStyle.is()) 1015 { 1016 uno::Reference<lang::XUnoTunnel> xTunnel( xStyle, uno::UNO_QUERY); 1017 if(xTunnel.is()) 1018 { 1019 SwXStyle* pStyle = reinterpret_cast< SwXStyle * >( 1020 sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething( SwXStyle::getUnoTunnelId()) )); 1021 pStyle->Invalidate(); 1022 } 1023 } 1024 m_pBasePool->Remove(pBase); 1025 insertByName(rName, rElement); 1026 } 1027 } 1028 1029 void XStyleFamily::removeByName(const OUString& rName) 1030 { 1031 SolarMutexGuard aGuard; 1032 if(!m_pBasePool) 1033 throw uno::RuntimeException(); 1034 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 1035 OUString sName; 1036 SwStyleNameMapper::FillUIName(rName, sName, m_rEntry.m_aPoolId); 1037 SfxStyleSheetBase* pBase = m_pBasePool->Find( sName ); 1038 if(!pBase) 1039 throw container::NoSuchElementException(); 1040 if (SwGetPoolIdFromName::CellStyle == m_rEntry.m_aPoolId) 1041 { 1042 // handle cell style 1043 m_pDocShell->GetDoc()->GetCellStyles().RemoveBoxFormat(rName); 1044 } 1045 else if (SwGetPoolIdFromName::TabStyle == m_rEntry.m_aPoolId) 1046 { 1047 // handle table style 1048 m_pDocShell->GetDoc()->GetTableStyles().EraseAutoFormat(rName); 1049 } 1050 else 1051 m_pBasePool->Remove(pBase); 1052 } 1053 1054 uno::Any SAL_CALL XStyleFamily::getPropertyValue( const OUString& sPropertyName ) 1055 { 1056 if(sPropertyName != "DisplayName") 1057 throw beans::UnknownPropertyException( "unknown property: " + sPropertyName, static_cast<OWeakObject *>(this) ); 1058 SolarMutexGuard aGuard; 1059 return uno::makeAny(SwResId(m_rEntry.m_pResId)); 1060 } 1061 1062 1063 SwXStyle* XStyleFamily::FindStyle(const OUString& rStyleName) const 1064 { 1065 const size_t nLCount = m_pBasePool->GetSizeOfVector(); 1066 for(size_t i = 0; i < nLCount; ++i) 1067 { 1068 SfxListener* pListener = m_pBasePool->GetListener(i); 1069 SwXStyle* pTempStyle = dynamic_cast<SwXStyle*>(pListener); 1070 if(pTempStyle && pTempStyle->GetFamily() == m_rEntry.m_eFamily && pTempStyle->GetStyleName() == rStyleName) 1071 return pTempStyle; 1072 } 1073 return nullptr; 1074 } 1075 1076 static const std::vector<StyleFamilyEntry>* lcl_GetStyleFamilyEntries() 1077 { 1078 if(!our_pStyleFamilyEntries) 1079 { 1080 our_pStyleFamilyEntries = new std::vector<StyleFamilyEntry>{ 1081 { SfxStyleFamily::Char, PROPERTY_MAP_CHAR_STYLE, SwGetPoolIdFromName::ChrFmt, "CharacterStyles", STR_STYLE_FAMILY_CHARACTER, &lcl_GetCountOrName<SfxStyleFamily::Char>, &lcl_CreateStyle<SfxStyleFamily::Char>, &lcl_TranslateIndex<SfxStyleFamily::Char> }, 1082 { SfxStyleFamily::Para, PROPERTY_MAP_PARA_STYLE, SwGetPoolIdFromName::TxtColl, "ParagraphStyles", STR_STYLE_FAMILY_PARAGRAPH, &lcl_GetCountOrName<SfxStyleFamily::Para>, &lcl_CreateStyle<SfxStyleFamily::Para>, &lcl_TranslateIndex<SfxStyleFamily::Para> }, 1083 { SfxStyleFamily::Page, PROPERTY_MAP_PAGE_STYLE, SwGetPoolIdFromName::PageDesc, "PageStyles", STR_STYLE_FAMILY_PAGE, &lcl_GetCountOrName<SfxStyleFamily::Page>, &lcl_CreateStyle<SfxStyleFamily::Page>, &lcl_TranslateIndexRange<RES_POOLPAGE_BEGIN, nPoolPageRange> }, 1084 { SfxStyleFamily::Frame, PROPERTY_MAP_FRAME_STYLE, SwGetPoolIdFromName::FrmFmt, "FrameStyles", STR_STYLE_FAMILY_FRAME, &lcl_GetCountOrName<SfxStyleFamily::Frame>, &lcl_CreateStyle<SfxStyleFamily::Frame>, &lcl_TranslateIndexRange<RES_POOLFRM_BEGIN, nPoolFrameRange> }, 1085 { SfxStyleFamily::Pseudo, PROPERTY_MAP_NUM_STYLE, SwGetPoolIdFromName::NumRule, "NumberingStyles", STR_STYLE_FAMILY_NUMBERING, &lcl_GetCountOrName<SfxStyleFamily::Pseudo>, &lcl_CreateStyle<SfxStyleFamily::Pseudo>, &lcl_TranslateIndexRange<RES_POOLNUMRULE_BEGIN, nPoolNumRange> }, 1086 { SfxStyleFamily::Table, PROPERTY_MAP_TABLE_STYLE, SwGetPoolIdFromName::TabStyle, "TableStyles", STR_STYLE_FAMILY_TABLE, &lcl_GetCountOrName<SfxStyleFamily::Table>, &lcl_CreateStyle<SfxStyleFamily::Table>, &lcl_TranslateIndex<SfxStyleFamily::Table> }, 1087 { SfxStyleFamily::Cell, PROPERTY_MAP_CELL_STYLE, SwGetPoolIdFromName::CellStyle,"CellStyles", STR_STYLE_FAMILY_CELL, &lcl_GetCountOrName<SfxStyleFamily::Cell>, &lcl_CreateStyle<SfxStyleFamily::Cell>, &lcl_TranslateIndex<SfxStyleFamily::Cell> } 1088 }; 1089 } 1090 return our_pStyleFamilyEntries; 1091 } 1092 1093 static const std::vector<ParagraphStyleCategoryEntry>* lcl_GetParagraphStyleCategoryEntries() 1094 { 1095 if(!our_pParagraphStyleCategoryEntries) 1096 { 1097 our_pParagraphStyleCategoryEntries = new std::vector<ParagraphStyleCategoryEntry>{ 1098 { style::ParagraphStyleCategory::TEXT, SfxStyleSearchBits::SwText, COLL_TEXT_BITS }, 1099 { style::ParagraphStyleCategory::CHAPTER, SfxStyleSearchBits::SwChapter, COLL_DOC_BITS }, 1100 { style::ParagraphStyleCategory::LIST, SfxStyleSearchBits::SwList, COLL_LISTS_BITS }, 1101 { style::ParagraphStyleCategory::INDEX, SfxStyleSearchBits::SwIndex, COLL_REGISTER_BITS }, 1102 { style::ParagraphStyleCategory::EXTRA, SfxStyleSearchBits::SwExtra, COLL_EXTRA_BITS }, 1103 { style::ParagraphStyleCategory::HTML, SfxStyleSearchBits::SwHtml, COLL_HTML_BITS } 1104 }; 1105 } 1106 return our_pParagraphStyleCategoryEntries; 1107 } 1108 1109 class SwStyleProperties_Impl 1110 { 1111 const PropertyEntryVector_t aPropertyEntries; 1112 std::map<OUString, uno::Any> m_vPropertyValues; 1113 public: 1114 explicit SwStyleProperties_Impl(const SfxItemPropertyMap& rMap) 1115 : aPropertyEntries(rMap.getPropertyEntries()) 1116 { } 1117 1118 bool AllowsKey(const OUString& rName) 1119 { 1120 return std::any_of(aPropertyEntries.begin(), aPropertyEntries.end(), 1121 [rName] (const SfxItemPropertyNamedEntry& rEntry) {return rName == rEntry.sName;} ); 1122 } 1123 bool SetProperty(const OUString& rName, const uno::Any& rValue) 1124 { 1125 if(!AllowsKey(rName)) 1126 return false; 1127 m_vPropertyValues[rName] = rValue; 1128 return true; 1129 } 1130 void GetProperty(const OUString& rName, const uno::Any*& pAny) 1131 { 1132 if(!AllowsKey(rName)) 1133 { 1134 pAny = nullptr; 1135 return; 1136 } 1137 pAny = &m_vPropertyValues[rName]; 1138 return; 1139 } 1140 bool ClearProperty( const OUString& rName ) 1141 { 1142 if(!AllowsKey(rName)) 1143 return false; 1144 m_vPropertyValues[rName] = uno::Any(); 1145 return true; 1146 } 1147 void ClearAllProperties( ) 1148 { m_vPropertyValues.clear(); } 1149 void Apply(SwXStyle& rStyle) 1150 { 1151 for(const auto& rPropertyPair : m_vPropertyValues) 1152 { 1153 if(rPropertyPair.second.hasValue()) 1154 rStyle.setPropertyValue(rPropertyPair.first, rPropertyPair.second); 1155 } 1156 } 1157 static void GetProperty(const OUString &rPropertyName, const uno::Reference < beans::XPropertySet > &rxPropertySet, uno::Any& rAny ) 1158 { 1159 rAny = rxPropertySet->getPropertyValue( rPropertyName ); 1160 } 1161 }; 1162 1163 static SwGetPoolIdFromName lcl_GetSwEnumFromSfxEnum(SfxStyleFamily eFamily) 1164 { 1165 auto pEntries(lcl_GetStyleFamilyEntries()); 1166 const auto pEntry = std::find_if(pEntries->begin(), pEntries->end(), 1167 [eFamily] (const StyleFamilyEntry& e) { return e.m_eFamily == eFamily; }); 1168 if(pEntry != pEntries->end()) 1169 return pEntry->m_aPoolId; 1170 SAL_WARN("sw.uno", "someone asking for all styles in unostyle.cxx!" ); 1171 return SwGetPoolIdFromName::ChrFmt; 1172 } 1173 1174 namespace 1175 { 1176 class theSwXStyleUnoTunnelId : public rtl::Static<UnoTunnelIdInit, theSwXStyleUnoTunnelId> {}; 1177 } 1178 1179 const uno::Sequence<sal_Int8>& SwXStyle::getUnoTunnelId() 1180 { 1181 return theSwXStyleUnoTunnelId::get().getSeq(); 1182 } 1183 1184 sal_Int64 SAL_CALL SwXStyle::getSomething(const uno::Sequence<sal_Int8>& rId) 1185 { 1186 if(rId.getLength() != 16) 1187 return 0; 1188 if(0 == memcmp(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16)) 1189 { 1190 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); 1191 } 1192 return 0; 1193 } 1194 1195 1196 uno::Sequence< OUString > SwXStyle::getSupportedServiceNames() 1197 { 1198 long nCount = 1; 1199 if(SfxStyleFamily::Para == m_rEntry.m_eFamily) 1200 { 1201 nCount = 5; 1202 if(m_bIsConditional) 1203 nCount++; 1204 } 1205 else if(SfxStyleFamily::Char == m_rEntry.m_eFamily) 1206 nCount = 5; 1207 else if(SfxStyleFamily::Page == m_rEntry.m_eFamily) 1208 nCount = 3; 1209 uno::Sequence< OUString > aRet(nCount); 1210 OUString* pArray = aRet.getArray(); 1211 pArray[0] = "com.sun.star.style.Style"; 1212 switch(m_rEntry.m_eFamily) 1213 { 1214 case SfxStyleFamily::Char: 1215 pArray[1] = "com.sun.star.style.CharacterStyle"; 1216 pArray[2] = "com.sun.star.style.CharacterProperties"; 1217 pArray[3] = "com.sun.star.style.CharacterPropertiesAsian"; 1218 pArray[4] = "com.sun.star.style.CharacterPropertiesComplex"; 1219 break; 1220 case SfxStyleFamily::Page: 1221 pArray[1] = "com.sun.star.style.PageStyle"; 1222 pArray[2] = "com.sun.star.style.PageProperties"; 1223 break; 1224 case SfxStyleFamily::Para: 1225 pArray[1] = "com.sun.star.style.ParagraphStyle"; 1226 pArray[2] = "com.sun.star.style.ParagraphProperties"; 1227 pArray[3] = "com.sun.star.style.ParagraphPropertiesAsian"; 1228 pArray[4] = "com.sun.star.style.ParagraphPropertiesComplex"; 1229 if(m_bIsConditional) 1230 pArray[5] = "com.sun.star.style.ConditionalParagraphStyle"; 1231 break; 1232 1233 default: 1234 ; 1235 } 1236 return aRet; 1237 } 1238 1239 static uno::Reference<beans::XPropertySet> lcl_InitStandardStyle(const SfxStyleFamily eFamily, uno::Reference<container::XNameAccess> const & rxStyleFamily) 1240 { 1241 using return_t = decltype(lcl_InitStandardStyle(eFamily, rxStyleFamily)); 1242 if(eFamily != SfxStyleFamily::Para && eFamily != SfxStyleFamily::Page) 1243 return {}; 1244 auto aResult(rxStyleFamily->getByName("Standard")); 1245 if(!aResult.has<return_t>()) 1246 return {}; 1247 return aResult.get<return_t>(); 1248 } 1249 1250 static uno::Reference<container::XNameAccess> lcl_InitStyleFamily(SwDoc* pDoc, const StyleFamilyEntry& rEntry) 1251 { 1252 using return_t = decltype(lcl_InitStyleFamily(pDoc, rEntry)); 1253 if(rEntry.m_eFamily != SfxStyleFamily::Char 1254 && rEntry.m_eFamily != SfxStyleFamily::Para 1255 && rEntry.m_eFamily != SfxStyleFamily::Page) 1256 return {}; 1257 auto xModel(pDoc->GetDocShell()->GetBaseModel()); 1258 uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xModel, uno::UNO_QUERY); 1259 auto xFamilies = xFamilySupplier->getStyleFamilies(); 1260 auto aResult(xFamilies->getByName(rEntry.m_sName)); 1261 if(!aResult.has<return_t>()) 1262 return {}; 1263 return aResult.get<return_t>(); 1264 } 1265 1266 static bool lcl_InitConditional(SfxStyleSheetBasePool* pBasePool, const SfxStyleFamily eFamily, const OUString& rStyleName) 1267 { 1268 if(!pBasePool || eFamily != SfxStyleFamily::Para) 1269 return false; 1270 pBasePool->SetSearchMask(eFamily); 1271 SfxStyleSheetBase* pBase = pBasePool->Find(rStyleName); 1272 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?" ); 1273 if(!pBase) 1274 return false; 1275 const sal_uInt16 nId(SwStyleNameMapper::GetPoolIdFromUIName(rStyleName, SwGetPoolIdFromName::TxtColl)); 1276 if(nId != USHRT_MAX) 1277 return ::IsConditionalByPoolId(nId); 1278 return RES_CONDTXTFMTCOLL == static_cast<SwDocStyleSheet*>(pBase)->GetCollection()->Which(); 1279 } 1280 1281 static const StyleFamilyEntry& lcl_GetStyleEntry(const SfxStyleFamily eFamily) 1282 { 1283 auto pEntries = lcl_GetStyleFamilyEntries(); 1284 const auto pEntry = std::find_if(pEntries->begin(), pEntries->end(), 1285 [eFamily] (const StyleFamilyEntry& e) { return e.m_eFamily == eFamily; }); 1286 assert(pEntry != pEntries->end()); 1287 return *pEntry; 1288 } 1289 1290 SwXStyle::SwXStyle(SwDoc* pDoc, SfxStyleFamily eFamily, bool bConditional) 1291 : m_pDoc(pDoc) 1292 , m_rEntry(lcl_GetStyleEntry(eFamily)) 1293 , m_bIsDescriptor(true) 1294 , m_bIsConditional(bConditional) 1295 , m_pBasePool(nullptr) 1296 , m_xStyleFamily(lcl_InitStyleFamily(pDoc, m_rEntry)) 1297 , m_xStyleData(lcl_InitStandardStyle(eFamily, m_xStyleFamily)) 1298 { 1299 assert(!m_bIsConditional || m_rEntry.m_eFamily == SfxStyleFamily::Para); // only paragraph styles are conditional 1300 // Register ourselves as a listener to the document (via the page descriptor) 1301 SvtListener::StartListening(pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); 1302 m_pPropertiesImpl = std::make_unique<SwStyleProperties_Impl>( 1303 aSwMapProvider.GetPropertySet(m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.m_nPropMapType)->getPropertyMap()); 1304 } 1305 1306 SwXStyle::SwXStyle(SfxStyleSheetBasePool* pPool, SfxStyleFamily eFamily, SwDoc* pDoc, const OUString& rStyleName) 1307 : m_pDoc(pDoc) 1308 , m_sStyleName(rStyleName) 1309 , m_rEntry(lcl_GetStyleEntry(eFamily)) 1310 , m_bIsDescriptor(false) 1311 , m_bIsConditional(lcl_InitConditional(pPool, eFamily, rStyleName)) 1312 , m_pBasePool(pPool) 1313 { } 1314 1315 SwXStyle::~SwXStyle() 1316 { 1317 SolarMutexGuard aGuard; 1318 if(m_pBasePool) 1319 SfxListener::EndListening(*m_pBasePool); 1320 m_pPropertiesImpl.reset(); 1321 SvtListener::EndListeningAll(); 1322 } 1323 1324 void SwXStyle::Notify(const SfxHint& rHint) 1325 { 1326 if(rHint.GetId() == SfxHintId::Dying) 1327 { 1328 m_pDoc = nullptr; 1329 m_xStyleData.clear(); 1330 m_xStyleFamily.clear(); 1331 } 1332 } 1333 1334 OUString SwXStyle::getName() 1335 { 1336 SolarMutexGuard aGuard; 1337 if(!m_pBasePool) 1338 return m_sStyleName; 1339 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 1340 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); 1341 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?"); 1342 if(!pBase) 1343 throw uno::RuntimeException(); 1344 OUString aString; 1345 SwStyleNameMapper::FillProgName(pBase->GetName(), aString, lcl_GetSwEnumFromSfxEnum ( m_rEntry.m_eFamily )); 1346 return aString; 1347 } 1348 1349 void SwXStyle::setName(const OUString& rName) 1350 { 1351 SolarMutexGuard aGuard; 1352 if(!m_pBasePool) 1353 { 1354 m_sStyleName = rName; 1355 return; 1356 } 1357 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 1358 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); 1359 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?"); 1360 if(!pBase || !pBase->IsUserDefined()) 1361 throw uno::RuntimeException(); 1362 rtl::Reference<SwDocStyleSheet> xTmp(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 1363 if(!xTmp->SetName(rName)) 1364 throw uno::RuntimeException(); 1365 m_sStyleName = rName; 1366 } 1367 1368 sal_Bool SwXStyle::isUserDefined() 1369 { 1370 SolarMutexGuard aGuard; 1371 if(!m_pBasePool) 1372 throw uno::RuntimeException(); 1373 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 1374 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); 1375 //if it is not found it must be non user defined 1376 return pBase && pBase->IsUserDefined(); 1377 } 1378 1379 sal_Bool SwXStyle::isInUse() 1380 { 1381 SolarMutexGuard aGuard; 1382 if(!m_pBasePool) 1383 throw uno::RuntimeException(); 1384 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily, SfxStyleSearchBits::Used); 1385 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); 1386 return pBase && pBase->IsUsed(); 1387 } 1388 1389 OUString SwXStyle::getParentStyle() 1390 { 1391 SolarMutexGuard aGuard; 1392 if(!m_pBasePool) 1393 { 1394 if(!m_bIsDescriptor) 1395 throw uno::RuntimeException(); 1396 return m_sParentStyleName; 1397 } 1398 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 1399 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); 1400 OUString aString; 1401 if(pBase) 1402 aString = pBase->GetParent(); 1403 SwStyleNameMapper::FillProgName(aString, aString, lcl_GetSwEnumFromSfxEnum(m_rEntry.m_eFamily)); 1404 return aString; 1405 } 1406 1407 void SwXStyle::setParentStyle(const OUString& rParentStyle) 1408 { 1409 SolarMutexGuard aGuard; 1410 OUString sParentStyle; 1411 SwStyleNameMapper::FillUIName(rParentStyle, sParentStyle, lcl_GetSwEnumFromSfxEnum ( m_rEntry.m_eFamily ) ); 1412 if(!m_pBasePool) 1413 { 1414 if(!m_bIsDescriptor) 1415 throw uno::RuntimeException(); 1416 m_sParentStyleName = sParentStyle; 1417 try 1418 { 1419 const auto aAny = m_xStyleFamily->getByName(sParentStyle); 1420 m_xStyleData = aAny.get<decltype(m_xStyleData)>(); 1421 } 1422 catch(...) 1423 { } 1424 return; 1425 } 1426 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 1427 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); 1428 if(!pBase) 1429 throw uno::RuntimeException(); 1430 rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 1431 //make it a 'real' style - necessary for pooled styles 1432 xBase->GetItemSet(); 1433 if(xBase->GetParent() != sParentStyle) 1434 { 1435 if(!xBase->SetParent(sParentStyle)) 1436 throw uno::RuntimeException(); 1437 } 1438 } 1439 1440 uno::Reference<beans::XPropertySetInfo> SwXStyle::getPropertySetInfo() 1441 { 1442 if(m_bIsConditional) 1443 { 1444 assert(m_rEntry.m_eFamily == SfxStyleFamily::Para); 1445 static uno::Reference<beans::XPropertySetInfo> xCondParaRef; 1446 xCondParaRef = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CONDITIONAL_PARA_STYLE)->getPropertySetInfo(); 1447 return xCondParaRef; 1448 } 1449 return m_rEntry.m_xPSInfo; 1450 } 1451 1452 void SwXStyle::ApplyDescriptorProperties() 1453 { 1454 m_bIsDescriptor = false; 1455 m_xStyleData.clear(); 1456 m_xStyleFamily.clear(); 1457 m_pPropertiesImpl->Apply(*this); 1458 } 1459 1460 class SwStyleBase_Impl 1461 { 1462 private: 1463 SwDoc& m_rDoc; 1464 const SwPageDesc* m_pOldPageDesc; 1465 rtl::Reference<SwDocStyleSheet> m_xNewBase; 1466 SfxItemSet* m_pItemSet; 1467 std::unique_ptr<SfxItemSet> m_pMyItemSet; 1468 OUString const m_rStyleName; 1469 const SwAttrSet* m_pParentStyle; 1470 public: 1471 SwStyleBase_Impl(SwDoc& rSwDoc, const OUString& rName, const SwAttrSet* pParentStyle) 1472 : m_rDoc(rSwDoc) 1473 , m_pOldPageDesc(nullptr) 1474 , m_pItemSet(nullptr) 1475 , m_rStyleName(rName) 1476 , m_pParentStyle(pParentStyle) 1477 { } 1478 1479 rtl::Reference<SwDocStyleSheet>& getNewBase() 1480 { 1481 return m_xNewBase; 1482 } 1483 1484 void setNewBase(SwDocStyleSheet* pNew) 1485 { 1486 m_xNewBase = pNew; 1487 } 1488 1489 bool HasItemSet() const 1490 { 1491 return m_xNewBase.is(); 1492 } 1493 1494 SfxItemSet& GetItemSet() 1495 { 1496 assert(m_xNewBase.is()); 1497 if(!m_pItemSet) 1498 { 1499 m_pMyItemSet.reset(new SfxItemSet(m_xNewBase->GetItemSet())); 1500 m_pItemSet = m_pMyItemSet.get(); 1501 1502 // set parent style to have the correct XFillStyle setting as XFILL_NONE 1503 if(!m_pItemSet->GetParent() && m_pParentStyle) 1504 m_pItemSet->SetParent(m_pParentStyle); 1505 } 1506 return *m_pItemSet; 1507 } 1508 1509 const SwPageDesc* GetOldPageDesc(); 1510 1511 // still a hack, but a bit more explicit and with a proper scope 1512 struct ItemSetOverrider 1513 { 1514 SwStyleBase_Impl& m_rStyleBase; 1515 SfxItemSet* const m_pOldSet; 1516 ItemSetOverrider(SwStyleBase_Impl& rStyleBase, SfxItemSet* pTemp) 1517 : m_rStyleBase(rStyleBase) 1518 , m_pOldSet(m_rStyleBase.m_pItemSet) 1519 { m_rStyleBase.m_pItemSet = pTemp; } 1520 ~ItemSetOverrider() 1521 { m_rStyleBase.m_pItemSet = m_pOldSet; }; 1522 }; 1523 }; 1524 1525 namespace 1526 { 1527 const char* STR_POOLPAGE_ARY[] = 1528 { 1529 // Page styles 1530 STR_POOLPAGE_STANDARD, 1531 STR_POOLPAGE_FIRST, 1532 STR_POOLPAGE_LEFT, 1533 STR_POOLPAGE_RIGHT, 1534 STR_POOLPAGE_JAKET, 1535 STR_POOLPAGE_REGISTER, 1536 STR_POOLPAGE_HTML, 1537 STR_POOLPAGE_FOOTNOTE, 1538 STR_POOLPAGE_ENDNOTE, 1539 STR_POOLPAGE_LANDSCAPE 1540 }; 1541 } 1542 1543 const SwPageDesc* SwStyleBase_Impl::GetOldPageDesc() 1544 { 1545 if(!m_pOldPageDesc) 1546 { 1547 SwPageDesc *pd = m_rDoc.FindPageDesc(m_rStyleName); 1548 if(pd) 1549 m_pOldPageDesc = pd; 1550 1551 if(!m_pOldPageDesc) 1552 { 1553 for (size_t i = 0; i < SAL_N_ELEMENTS(STR_POOLPAGE_ARY); ++i) 1554 { 1555 if (SwResId(STR_POOLPAGE_ARY[i]) == m_rStyleName) 1556 { 1557 m_pOldPageDesc = m_rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_BEGIN + i); 1558 break; 1559 } 1560 } 1561 } 1562 } 1563 return m_pOldPageDesc; 1564 } 1565 1566 1567 1568 static sal_uInt8 lcl_TranslateMetric(const SfxItemPropertySimpleEntry& rEntry, SwDoc* pDoc, uno::Any& o_aValue) 1569 { 1570 // check for needed metric translation 1571 if(!(rEntry.nMoreFlags & PropertyMoreFlags::METRIC_ITEM)) 1572 return rEntry.nMemberId; 1573 // exception: If these ItemTypes are used, do not convert when these are negative 1574 // since this means they are intended as percent values 1575 if((XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID) 1576 && o_aValue.has<sal_Int32>() 1577 && o_aValue.get<sal_Int32>() < 0) 1578 return rEntry.nMemberId; 1579 if(!pDoc) 1580 return rEntry.nMemberId; 1581 1582 const SfxItemPool& rPool = pDoc->GetAttrPool(); 1583 const MapUnit eMapUnit(rPool.GetMetric(rEntry.nWID)); 1584 if(eMapUnit != MapUnit::Map100thMM) 1585 SvxUnoConvertFromMM(eMapUnit, o_aValue); 1586 return rEntry.nMemberId; 1587 } 1588 template<> 1589 void SwXStyle::SetPropertyValue<HINT_BEGIN>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1590 { 1591 // default ItemSet handling 1592 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); 1593 SfxItemSet aSet(*rStyleSet.GetPool(), {{rEntry.nWID, rEntry.nWID}}); 1594 aSet.SetParent(&rStyleSet); 1595 rPropSet.setPropertyValue(rEntry, rValue, aSet); 1596 rStyleSet.Put(aSet); 1597 } 1598 template<> 1599 void SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1600 { 1601 bool bHidden = false; 1602 if(rValue >>= bHidden) 1603 { 1604 //make it a 'real' style - necessary for pooled styles 1605 o_rStyleBase.getNewBase()->GetItemSet(); 1606 o_rStyleBase.getNewBase()->SetHidden(bHidden); 1607 } 1608 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase); 1609 } 1610 template<> 1611 void SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1612 { 1613 o_rStyleBase.getNewBase()->GetItemSet(); 1614 o_rStyleBase.getNewBase()->SetGrabBagItem(rValue); 1615 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase); 1616 } 1617 template<> 1618 void SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1619 { 1620 uno::Any aValue(rValue); 1621 const auto nMemberId(lcl_TranslateMetric(rEntry, m_pDoc, aValue)); 1622 if(MID_NAME == nMemberId) 1623 { 1624 // add set commands for FillName items 1625 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); 1626 if(!aValue.has<OUString>()) 1627 throw lang::IllegalArgumentException(); 1628 SvxShape::SetFillAttribute(rEntry.nWID, aValue.get<OUString>(), rStyleSet); 1629 } 1630 else if(MID_BITMAP == nMemberId) 1631 { 1632 if(sal_uInt16(XATTR_FILLBITMAP) == rEntry.nWID) 1633 { 1634 const Graphic aNullGraphic; 1635 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); 1636 XFillBitmapItem aXFillBitmapItem(aNullGraphic); 1637 aXFillBitmapItem.PutValue(aValue, nMemberId); 1638 rStyleSet.Put(aXFillBitmapItem); 1639 } 1640 } 1641 else 1642 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, o_rStyleBase); 1643 } 1644 template<> 1645 void SwXStyle::SetPropertyValue<sal_uInt16(RES_BACKGROUND)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1646 { 1647 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); 1648 const SvxBrushItem aOriginalBrushItem(getSvxBrushItemFromSourceSet(rStyleSet, RES_BACKGROUND, true, m_pDoc->IsInXMLImport())); 1649 SvxBrushItem aChangedBrushItem(aOriginalBrushItem); 1650 1651 uno::Any aValue(rValue); 1652 const auto nMemberId(lcl_TranslateMetric(rEntry, m_pDoc, aValue)); 1653 aChangedBrushItem.PutValue(aValue, nMemberId); 1654 1655 // 0xff is already the default - but if BackTransparent is set 1656 // to true, it must be applied in the item set on ODF import 1657 // to potentially override parent style, which is unknown yet 1658 if(aChangedBrushItem == aOriginalBrushItem && (MID_GRAPHIC_TRANSPARENT != nMemberId || !aValue.has<bool>() || !aValue.get<bool>())) 1659 return; 1660 1661 setSvxBrushItemAsFillAttributesToTargetSet(aChangedBrushItem, rStyleSet); 1662 } 1663 template<> 1664 void SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1665 { 1666 drawing::BitmapMode eMode; 1667 if(!(rValue >>= eMode)) 1668 { 1669 if(!rValue.has<sal_Int32>()) 1670 throw lang::IllegalArgumentException(); 1671 eMode = static_cast<drawing::BitmapMode>(rValue.get<sal_Int32>()); 1672 } 1673 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); 1674 rStyleSet.Put(XFillBmpStretchItem(drawing::BitmapMode_STRETCH == eMode)); 1675 rStyleSet.Put(XFillBmpTileItem(drawing::BitmapMode_REPEAT == eMode)); 1676 } 1677 template<> 1678 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PAPER_BIN)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1679 { 1680 if(!rValue.has<OUString>()) 1681 throw lang::IllegalArgumentException(); 1682 SfxPrinter* pPrinter = m_pDoc->getIDocumentDeviceAccess().getPrinter(true); 1683 OUString sValue(rValue.get<OUString>()); 1684 using printeridx_t = decltype(pPrinter->GetPaperBinCount()); 1685 printeridx_t nBin = std::numeric_limits<printeridx_t>::max(); 1686 if(sValue == "[From printer settings]") 1687 nBin = std::numeric_limits<printeridx_t>::max()-1; 1688 else if(pPrinter) 1689 { 1690 for(sal_uInt16 i=0, nEnd = pPrinter->GetPaperBinCount(); i < nEnd; ++i) 1691 { 1692 if (sValue == pPrinter->GetPaperBinName(i)) 1693 { 1694 nBin = i; 1695 break; 1696 } 1697 } 1698 } 1699 if(nBin == std::numeric_limits<printeridx_t>::max()) 1700 throw lang::IllegalArgumentException(); 1701 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); 1702 SfxItemSet aSet(*rStyleSet.GetPool(), {{rEntry.nWID, rEntry.nWID}}); 1703 aSet.SetParent(&rStyleSet); 1704 rPropSet.setPropertyValue(rEntry, uno::makeAny(static_cast<sal_Int8>(nBin == std::numeric_limits<printeridx_t>::max()-1 ? -1 : nBin)), aSet); 1705 rStyleSet.Put(aSet); 1706 } 1707 template<> 1708 void SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1709 { 1710 if(!rValue.has<uno::Reference<container::XIndexReplace>>() || !rValue.has<uno::Reference<lang::XUnoTunnel>>()) 1711 throw lang::IllegalArgumentException(); 1712 auto xNumberTunnel(rValue.get<uno::Reference<lang::XUnoTunnel>>()); 1713 SwXNumberingRules* pSwXRules = reinterpret_cast<SwXNumberingRules*>(sal::static_int_cast<sal_IntPtr>(xNumberTunnel->getSomething(SwXNumberingRules::getUnoTunnelId()))); 1714 if(!pSwXRules) 1715 return; 1716 SwNumRule aSetRule(*pSwXRules->GetNumRule()); 1717 for(sal_uInt16 i = 0; i < MAXLEVEL; ++i) 1718 { 1719 const SwNumFormat* pFormat = aSetRule.GetNumFormat(i); 1720 if(!pFormat) 1721 continue; 1722 SwNumFormat aFormat(*pFormat); 1723 const auto& rCharName(pSwXRules->GetNewCharStyleNames()[i]); 1724 if(!rCharName.isEmpty() 1725 && !SwXNumberingRules::isInvalidStyle(rCharName) 1726 && (!pFormat->GetCharFormat() || pFormat->GetCharFormat()->GetName() != rCharName)) 1727 { 1728 auto pCharFormatIt(std::find_if(m_pDoc->GetCharFormats()->begin(), m_pDoc->GetCharFormats()->end(), 1729 [&rCharName] (SwCharFormat* pF) { return pF->GetName() == rCharName; })); 1730 if(pCharFormatIt != m_pDoc->GetCharFormats()->end()) 1731 aFormat.SetCharFormat(*pCharFormatIt); 1732 else if(m_pBasePool) 1733 { 1734 auto pBase(m_pBasePool->Find(rCharName, SfxStyleFamily::Char)); 1735 if(!pBase) 1736 pBase = &m_pBasePool->Make(rCharName, SfxStyleFamily::Char); 1737 aFormat.SetCharFormat(static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat()); 1738 } 1739 else 1740 aFormat.SetCharFormat(nullptr); 1741 } 1742 // same for fonts: 1743 const auto& rBulletName(pSwXRules->GetBulletFontNames()[i]); 1744 if(!rBulletName.isEmpty() 1745 && !SwXNumberingRules::isInvalidStyle(rBulletName) 1746 && (!pFormat->GetBulletFont() || pFormat->GetBulletFont()->GetFamilyName() != rBulletName)) 1747 { 1748 const auto pFontListItem(static_cast<const SvxFontListItem*>(m_pDoc->GetDocShell()->GetItem(SID_ATTR_CHAR_FONTLIST))); 1749 const auto pList(pFontListItem->GetFontList()); 1750 FontMetric aFontInfo(pList->Get(rBulletName, WEIGHT_NORMAL, ITALIC_NONE)); 1751 vcl::Font aFont(aFontInfo); 1752 aFormat.SetBulletFont(&aFont); 1753 } 1754 aSetRule.Set(i, &aFormat); 1755 } 1756 o_rStyleBase.getNewBase()->SetNumRule(aSetRule); 1757 } 1758 template<> 1759 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_OUTLINELEVEL)>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1760 { 1761 if(!rValue.has<sal_Int16>()) 1762 return; 1763 const auto nLevel(rValue.get<sal_Int16>()); 1764 if(0 <= nLevel && nLevel <= MAXLEVEL) 1765 o_rStyleBase.getNewBase()->GetCollection()->SetAttrOutlineLevel(nLevel); 1766 } 1767 template<> 1768 void SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1769 { 1770 if(!rValue.has<OUString>()) 1771 return; 1772 const auto sValue(rValue.get<OUString>()); 1773 OUString aString; 1774 SwStyleNameMapper::FillUIName(sValue, aString, m_rEntry.m_aPoolId); 1775 o_rStyleBase.getNewBase()->SetFollow(aString); 1776 } 1777 template<> 1778 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PAGEDESC)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1779 { 1780 if(MID_PAGEDESC_PAGEDESCNAME != rEntry.nMemberId) 1781 { 1782 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase); 1783 return; 1784 } 1785 if(!rValue.has<OUString>()) 1786 throw lang::IllegalArgumentException(); 1787 // special handling for RES_PAGEDESC 1788 SfxItemSet& rStyleSet = o_rStyleBase.GetItemSet(); 1789 std::unique_ptr<SwFormatPageDesc> pNewDesc; 1790 const SfxPoolItem* pItem; 1791 if(SfxItemState::SET == rStyleSet.GetItemState(RES_PAGEDESC, true, &pItem)) 1792 pNewDesc.reset(new SwFormatPageDesc(*static_cast<const SwFormatPageDesc*>(pItem))); 1793 else 1794 pNewDesc.reset(new SwFormatPageDesc); 1795 const auto sValue(rValue.get<OUString>()); 1796 OUString sDescName; 1797 SwStyleNameMapper::FillUIName(sValue, sDescName, SwGetPoolIdFromName::PageDesc); 1798 if(pNewDesc->GetPageDesc() && pNewDesc->GetPageDesc()->GetName() == sDescName) 1799 return; 1800 if(sDescName.isEmpty()) 1801 { 1802 rStyleSet.ClearItem(RES_BREAK); 1803 rStyleSet.Put(SwFormatPageDesc()); 1804 } 1805 else 1806 { 1807 SwPageDesc* pPageDesc(SwPageDesc::GetByName(*m_pDoc, sDescName)); 1808 if(!pPageDesc) 1809 throw lang::IllegalArgumentException(); 1810 pNewDesc->RegisterToPageDesc(*pPageDesc); 1811 rStyleSet.Put(*pNewDesc); 1812 } 1813 } 1814 template<> 1815 void SwXStyle::SetPropertyValue<sal_uInt16(RES_TEXT_VERT_ADJUST)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1816 { 1817 if(m_rEntry.m_eFamily != SfxStyleFamily::Page) 1818 { 1819 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase); 1820 return; 1821 } 1822 if(!m_pDoc || !rValue.has<drawing::TextVerticalAdjust>() || !o_rStyleBase.GetOldPageDesc()) 1823 return; 1824 SwPageDesc* pPageDesc = m_pDoc->FindPageDesc(o_rStyleBase.GetOldPageDesc()->GetName()); 1825 if(pPageDesc) 1826 pPageDesc->SetVerticalAdjustment(rValue.get<drawing::TextVerticalAdjust>()); 1827 } 1828 template<> 1829 void SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1830 { 1831 if(!rValue.has<bool>()) 1832 throw lang::IllegalArgumentException(); 1833 const bool bAuto(rValue.get<bool>()); 1834 if(SfxStyleFamily::Para == m_rEntry.m_eFamily) 1835 o_rStyleBase.getNewBase()->GetCollection()->SetAutoUpdateFormat(bAuto); 1836 else if(SfxStyleFamily::Frame == m_rEntry.m_eFamily) 1837 o_rStyleBase.getNewBase()->GetFrameFormat()->SetAutoUpdateFormat(bAuto); 1838 } 1839 template<> 1840 void SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1841 { 1842 static_assert(COND_COMMAND_COUNT == 28, "invalid size of command count?"); 1843 using expectedarg_t = uno::Sequence<beans::NamedValue>; 1844 if(!rValue.has<expectedarg_t>() || !m_pBasePool) 1845 throw lang::IllegalArgumentException(); 1846 SwCondCollItem aCondItem; 1847 for(auto& rNamedValue : rValue.get<expectedarg_t>()) 1848 { 1849 if(!rNamedValue.Value.has<OUString>()) 1850 throw lang::IllegalArgumentException(); 1851 1852 const OUString sValue(rNamedValue.Value.get<OUString>()); 1853 // get UI style name from programmatic style name 1854 OUString aStyleName; 1855 SwStyleNameMapper::FillUIName(sValue, aStyleName, lcl_GetSwEnumFromSfxEnum(m_rEntry.m_eFamily)); 1856 1857 // check for correct context and style name 1858 const auto nIdx(GetCommandContextIndex(rNamedValue.Name)); 1859 if (nIdx == -1) 1860 throw lang::IllegalArgumentException(); 1861 m_pBasePool->SetSearchMask(SfxStyleFamily::Para); 1862 bool bStyleFound = false; 1863 for(auto pBase = m_pBasePool->First(); pBase; pBase = m_pBasePool->Next()) 1864 { 1865 bStyleFound = pBase->GetName() == aStyleName; 1866 if (bStyleFound) 1867 break; 1868 } 1869 if (!bStyleFound) 1870 throw lang::IllegalArgumentException(); 1871 aCondItem.SetStyle(&aStyleName, nIdx); 1872 } 1873 o_rStyleBase.GetItemSet().Put(aCondItem); 1874 } 1875 template<> 1876 void SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1877 { 1878 if(!o_rStyleBase.getNewBase()->IsUserDefined() || !rValue.has<paragraphstyle_t>()) 1879 throw lang::IllegalArgumentException(); 1880 static std::unique_ptr<std::map<paragraphstyle_t, SfxStyleSearchBits>> pUnoToCore; 1881 if(!pUnoToCore) 1882 { 1883 pUnoToCore.reset(new std::map<paragraphstyle_t, SfxStyleSearchBits>); 1884 auto pEntries = lcl_GetParagraphStyleCategoryEntries(); 1885 std::transform(pEntries->begin(), pEntries->end(), std::inserter(*pUnoToCore, pUnoToCore->end()), 1886 [] (const ParagraphStyleCategoryEntry& rEntry) { return std::pair<paragraphstyle_t, SfxStyleSearchBits>(rEntry.m_eCategory, rEntry.m_nSwStyleBits); }); 1887 } 1888 const auto pUnoToCoreIt(pUnoToCore->find(rValue.get<paragraphstyle_t>())); 1889 if(pUnoToCoreIt == pUnoToCore->end()) 1890 throw lang::IllegalArgumentException(); 1891 o_rStyleBase.getNewBase()->SetMask( pUnoToCoreIt->second|SfxStyleSearchBits::UserDefined ); 1892 } 1893 template<> 1894 void SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1895 { 1896 OUString sName; 1897 rValue >>= sName; 1898 SwRegisterItem aReg(!sName.isEmpty()); 1899 aReg.SetWhich(SID_SWREGISTER_MODE); 1900 o_rStyleBase.GetItemSet().Put(aReg); 1901 OUString aString; 1902 SwStyleNameMapper::FillUIName(sName, aString, SwGetPoolIdFromName::TxtColl); 1903 o_rStyleBase.GetItemSet().Put(SfxStringItem(SID_SWREGISTER_COLLECTION, aString ) ); 1904 } 1905 template<> 1906 void SwXStyle::SetPropertyValue<sal_uInt16(RES_TXTATR_CJK_RUBY)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1907 { 1908 if(MID_RUBY_CHARSTYLE != rEntry.nMemberId) 1909 return; 1910 if(!rValue.has<OUString>()) 1911 throw lang::IllegalArgumentException(); 1912 const auto sValue(rValue.get<OUString>()); 1913 SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet()); 1914 std::unique_ptr<SwFormatRuby> pRuby; 1915 const SfxPoolItem* pItem; 1916 if(SfxItemState::SET == rStyleSet.GetItemState(RES_TXTATR_CJK_RUBY, true, &pItem)) 1917 pRuby.reset(new SwFormatRuby(*static_cast<const SwFormatRuby*>(pItem))); 1918 else 1919 pRuby.reset(new SwFormatRuby(OUString())); 1920 OUString sStyle; 1921 SwStyleNameMapper::FillUIName(sValue, sStyle, SwGetPoolIdFromName::ChrFmt); 1922 pRuby->SetCharFormatName(sValue); 1923 pRuby->SetCharFormatId(0); 1924 if(!sValue.isEmpty()) 1925 { 1926 const sal_uInt16 nId(SwStyleNameMapper::GetPoolIdFromUIName(sValue, SwGetPoolIdFromName::ChrFmt)); 1927 pRuby->SetCharFormatId(nId); 1928 } 1929 rStyleSet.Put(*pRuby); 1930 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase); 1931 } 1932 template<> 1933 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_DROP)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1934 { 1935 if(MID_DROPCAP_CHAR_STYLE_NAME != rEntry.nMemberId) 1936 { 1937 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, rValue, o_rStyleBase); 1938 return; 1939 } 1940 if(!rValue.has<OUString>()) 1941 throw lang::IllegalArgumentException(); 1942 SfxItemSet& rStyleSet(o_rStyleBase.GetItemSet()); 1943 std::unique_ptr<SwFormatDrop> pDrop; 1944 const SfxPoolItem* pItem; 1945 if(SfxItemState::SET == rStyleSet.GetItemState(RES_PARATR_DROP, true, &pItem)) 1946 pDrop.reset(new SwFormatDrop(*static_cast<const SwFormatDrop*>(pItem))); 1947 else 1948 pDrop.reset(new SwFormatDrop); 1949 const auto sValue(rValue.get<OUString>()); 1950 OUString sStyle; 1951 SwStyleNameMapper::FillUIName(sValue, sStyle, SwGetPoolIdFromName::ChrFmt); 1952 auto pStyle(static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char))); 1953 //default character style must not be set as default format 1954 if(!pStyle || pStyle->GetCharFormat() == m_pDoc->GetDfltCharFormat() ) 1955 { 1956 throw lang::IllegalArgumentException(); 1957 } 1958 pDrop->SetCharFormat(pStyle->GetCharFormat()); 1959 rStyleSet.Put(*pDrop); 1960 } 1961 template<> 1962 void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_NUMRULE)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& o_rStyleBase) 1963 { 1964 uno::Any aValue(rValue); 1965 lcl_TranslateMetric(rEntry, m_pDoc, aValue); 1966 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, o_rStyleBase); 1967 // --> OD 2006-10-18 #i70223# 1968 if(SfxStyleFamily::Para == m_rEntry.m_eFamily && 1969 o_rStyleBase.getNewBase().is() && o_rStyleBase.getNewBase()->GetCollection() && 1970 //rBase.getNewBase()->GetCollection()->GetOutlineLevel() < MAXLEVEL /* assigned to list level of outline style */) //#outline level,removed by zhaojianwei 1971 o_rStyleBase.getNewBase()->GetCollection()->IsAssignedToListLevelOfOutlineStyle()) ////<-end,add by zhaojianwei 1972 { 1973 OUString sNewNumberingRuleName; 1974 aValue >>= sNewNumberingRuleName; 1975 if(sNewNumberingRuleName.isEmpty() || sNewNumberingRuleName != m_pDoc->GetOutlineNumRule()->GetName()) 1976 o_rStyleBase.getNewBase()->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle(); 1977 } 1978 } 1979 1980 void SwXStyle::SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, const uno::Any& rValue, SwStyleBase_Impl& rBase) 1981 { 1982 using propertytype_t = decltype(rEntry.nWID); 1983 using coresetter_t = std::function<void(SwXStyle&, const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, const uno::Any&, SwStyleBase_Impl&)>; 1984 static std::unique_ptr<std::map<propertytype_t, coresetter_t>> pUnoToCore; 1985 if(!pUnoToCore) 1986 { 1987 pUnoToCore.reset(new std::map<propertytype_t, coresetter_t> { 1988 // these explicit std::mem_fn() calls shouldn't be needed, but apparently MSVC is currently too stupid for C++11 again 1989 { FN_UNO_HIDDEN, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_HIDDEN>) }, 1990 { FN_UNO_STYLE_INTEROP_GRAB_BAG, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_STYLE_INTEROP_GRAB_BAG>) }, 1991 { XATTR_FILLGRADIENT, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) }, 1992 { XATTR_FILLHATCH, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) }, 1993 { XATTR_FILLBITMAP, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) }, 1994 { XATTR_FILLFLOATTRANSPARENCE, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(XATTR_FILLGRADIENT)>) }, 1995 { RES_BACKGROUND, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_BACKGROUND)>) }, 1996 { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::SetPropertyValue<OWN_ATTR_FILLBMP_MODE>) }, 1997 { RES_PAPER_BIN, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PAPER_BIN)>) }, 1998 { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>) }, 1999 { RES_PARATR_OUTLINELEVEL, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_OUTLINELEVEL)>) }, 2000 { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_FOLLOW_STYLE>) }, 2001 { RES_PAGEDESC, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PAGEDESC)>) }, 2002 { RES_TEXT_VERT_ADJUST, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_TEXT_VERT_ADJUST)>) }, 2003 { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_IS_AUTO_UPDATE>) }, 2004 { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_PARA_STYLE_CONDITIONS>) }, 2005 { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::SetPropertyValue<FN_UNO_CATEGORY>) }, 2006 { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::SetPropertyValue<SID_SWREGISTER_COLLECTION>) }, 2007 { RES_TXTATR_CJK_RUBY, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_TXTATR_CJK_RUBY)>) }, 2008 { RES_PARATR_DROP, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_DROP)>) }, 2009 { RES_PARATR_NUMRULE, std::mem_fn(&SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_NUMRULE)>) } 2010 }); 2011 } 2012 const auto pUnoToCoreIt(pUnoToCore->find(rEntry.nWID)); 2013 if(pUnoToCoreIt != pUnoToCore->end()) 2014 pUnoToCoreIt->second(*this, rEntry, rPropSet, rValue, rBase); 2015 else 2016 { 2017 // adapted switch logic to a more readable state; removed goto's and made 2018 // execution of standard setting of property in ItemSet dependent of this variable 2019 uno::Any aValue(rValue); 2020 lcl_TranslateMetric(rEntry, m_pDoc, aValue); 2021 SetPropertyValue<HINT_BEGIN>(rEntry, rPropSet, aValue, rBase); 2022 } 2023 } 2024 2025 void SwXStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues) 2026 { 2027 if(!m_pDoc) 2028 throw uno::RuntimeException(); 2029 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.m_nPropMapType; 2030 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); 2031 const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap(); 2032 if(rPropertyNames.getLength() != rValues.getLength()) 2033 throw lang::IllegalArgumentException(); 2034 2035 SwStyleBase_Impl aBaseImpl(*m_pDoc, m_sStyleName, &GetDoc()->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent 2036 if(m_pBasePool) 2037 { 2038 const SfxStyleSearchBits nSaveMask = m_pBasePool->GetSearchMask(); 2039 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 2040 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); 2041 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily, nSaveMask); 2042 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?"); 2043 if(!pBase) 2044 throw uno::RuntimeException(); 2045 aBaseImpl.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 2046 } 2047 if(!aBaseImpl.getNewBase().is() && !m_bIsDescriptor) 2048 throw uno::RuntimeException(); 2049 2050 const OUString* pNames = rPropertyNames.getConstArray(); 2051 const uno::Any* pValues = rValues.getConstArray(); 2052 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp) 2053 { 2054 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(pNames[nProp]); 2055 if(!pEntry || (!m_bIsConditional && pNames[nProp] == UNO_NAME_PARA_STYLE_CONDITIONS)) 2056 throw beans::UnknownPropertyException("Unknown property: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this)); 2057 if(pEntry->nFlags & beans::PropertyAttribute::READONLY) 2058 throw beans::PropertyVetoException ("Property is read-only: " + pNames[nProp], static_cast<cppu::OWeakObject*>(this)); 2059 if(aBaseImpl.getNewBase().is()) 2060 SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); 2061 else if(!m_pPropertiesImpl->SetProperty(pNames[nProp], pValues[nProp])) 2062 throw lang::IllegalArgumentException(); 2063 } 2064 2065 if(aBaseImpl.HasItemSet()) 2066 aBaseImpl.getNewBase()->SetItemSet(aBaseImpl.GetItemSet()); 2067 } 2068 2069 void SwXStyle::setPropertyValues(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues) 2070 { 2071 SolarMutexGuard aGuard; 2072 // workaround for bad designed API 2073 try 2074 { 2075 SetPropertyValues_Impl( rPropertyNames, rValues ); 2076 } 2077 catch (const beans::UnknownPropertyException &rException) 2078 { 2079 // wrap the original (here not allowed) exception in 2080 // a lang::WrappedTargetException that gets thrown instead. 2081 lang::WrappedTargetException aWExc; 2082 aWExc.TargetException <<= rException; 2083 throw aWExc; 2084 } 2085 } 2086 2087 SfxStyleSheetBase* SwXStyle::GetStyleSheetBase() 2088 { 2089 if(!m_pBasePool) 2090 return nullptr; 2091 const SfxStyleSearchBits nSaveMask = m_pBasePool->GetSearchMask(); 2092 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 2093 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); 2094 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily, nSaveMask ); 2095 return pBase; 2096 } 2097 void SwXStyle::PrepareStyleBase(SwStyleBase_Impl& rBase) 2098 { 2099 SfxStyleSheetBase* pBase(GetStyleSheetBase()); 2100 if(!pBase) 2101 throw uno::RuntimeException(); 2102 if(!rBase.getNewBase().is()) 2103 rBase.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 2104 } 2105 2106 template<> 2107 uno::Any SwXStyle::GetStyleProperty<HINT_BEGIN>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase); 2108 template<> 2109 uno::Any SwXStyle::GetStyleProperty<FN_UNO_IS_PHYSICAL>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&) 2110 { 2111 SfxStyleSheetBase* pBase(GetStyleSheetBase()); 2112 if(!pBase) 2113 return uno::makeAny(false); 2114 bool bPhys = static_cast<SwDocStyleSheet*>(pBase)->IsPhysical(); 2115 // The standard character format is not existing physically 2116 if( bPhys && SfxStyleFamily::Char == GetFamily() && 2117 static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat() && 2118 static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat()->IsDefault() ) 2119 bPhys = false; 2120 return uno::makeAny<bool>(bPhys); 2121 } 2122 template<> 2123 uno::Any SwXStyle::GetStyleProperty<FN_UNO_HIDDEN>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&) 2124 { 2125 SfxStyleSheetBase* pBase(GetStyleSheetBase()); 2126 if(!pBase) 2127 return uno::makeAny(false); 2128 rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 2129 return uno::makeAny(xBase->IsHidden()); 2130 } 2131 template<> 2132 uno::Any SwXStyle::GetStyleProperty<FN_UNO_STYLE_INTEROP_GRAB_BAG>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&) 2133 { 2134 SfxStyleSheetBase* pBase(GetStyleSheetBase()); 2135 if(!pBase) 2136 return uno::Any(); 2137 uno::Any aRet; 2138 rtl::Reference<SwDocStyleSheet> xBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 2139 xBase->GetGrabBagItem(aRet); 2140 return aRet; 2141 } 2142 template<> 2143 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PAPER_BIN)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase) 2144 { 2145 PrepareStyleBase(rBase); 2146 SfxItemSet& rSet = rBase.GetItemSet(); 2147 uno::Any aValue; 2148 rPropSet.getPropertyValue(rEntry, rSet, aValue); 2149 sal_Int8 nBin(aValue.get<sal_Int8>()); 2150 if(nBin == -1) 2151 return uno::makeAny<OUString>("[From printer settings]"); 2152 SfxPrinter* pPrinter = GetDoc()->getIDocumentDeviceAccess().getPrinter(false); 2153 if(!pPrinter) 2154 return uno::Any(); 2155 return uno::makeAny(pPrinter->GetPaperBinName(nBin)); 2156 } 2157 template<> 2158 uno::Any SwXStyle::GetStyleProperty<FN_UNO_NUM_RULES>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) 2159 { 2160 PrepareStyleBase(rBase); 2161 const SwNumRule* pRule = rBase.getNewBase()->GetNumRule(); 2162 assert(pRule && "Where is the NumRule?"); 2163 uno::Reference<container::XIndexReplace> xRules(new SwXNumberingRules(*pRule, GetDoc())); 2164 return uno::makeAny<uno::Reference<container::XIndexReplace>>(xRules); 2165 } 2166 template<> 2167 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PARATR_OUTLINELEVEL)>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) 2168 { 2169 PrepareStyleBase(rBase); 2170 SAL_WARN_IF(SfxStyleFamily::Para != GetFamily(), "sw.uno", "only paras"); 2171 return uno::makeAny<sal_Int16>(rBase.getNewBase()->GetCollection()->GetAttrOutlineLevel()); 2172 } 2173 template<> 2174 uno::Any SwXStyle::GetStyleProperty<FN_UNO_FOLLOW_STYLE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) 2175 { 2176 PrepareStyleBase(rBase); 2177 OUString aString; 2178 SwStyleNameMapper::FillProgName(rBase.getNewBase()->GetFollow(), aString, lcl_GetSwEnumFromSfxEnum(GetFamily())); 2179 return uno::makeAny(aString); 2180 } 2181 template<> 2182 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_PAGEDESC)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase) 2183 { 2184 PrepareStyleBase(rBase); 2185 if(MID_PAGEDESC_PAGEDESCNAME != rEntry.nMemberId) 2186 return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase); 2187 // special handling for RES_PAGEDESC 2188 const SfxPoolItem* pItem; 2189 if(SfxItemState::SET != rBase.GetItemSet().GetItemState(RES_PAGEDESC, true, &pItem)) 2190 return uno::Any(); 2191 const SwPageDesc* pDesc = static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc(); 2192 if(!pDesc) 2193 return uno::Any(); 2194 OUString aString; 2195 SwStyleNameMapper::FillProgName(pDesc->GetName(), aString, SwGetPoolIdFromName::PageDesc); 2196 return uno::makeAny(aString); 2197 } 2198 template<> 2199 uno::Any SwXStyle::GetStyleProperty<FN_UNO_IS_AUTO_UPDATE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) 2200 { 2201 PrepareStyleBase(rBase); 2202 switch(GetFamily()) 2203 { 2204 case SfxStyleFamily::Para : return uno::makeAny<bool>(rBase.getNewBase()->GetCollection()->IsAutoUpdateFormat()); 2205 case SfxStyleFamily::Frame: return uno::makeAny<bool>(rBase.getNewBase()->GetFrameFormat()->IsAutoUpdateFormat()); 2206 default: return uno::Any(); 2207 } 2208 } 2209 template<> 2210 uno::Any SwXStyle::GetStyleProperty<FN_UNO_DISPLAY_NAME>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) 2211 { 2212 PrepareStyleBase(rBase); 2213 return uno::makeAny(rBase.getNewBase()->GetName()); 2214 } 2215 template<> 2216 uno::Any SwXStyle::GetStyleProperty<FN_UNO_PARA_STYLE_CONDITIONS>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) 2217 { 2218 PrepareStyleBase(rBase); 2219 static_assert(COND_COMMAND_COUNT == 28, "invalid size of command count?"); 2220 uno::Sequence<beans::NamedValue> aSeq(COND_COMMAND_COUNT); 2221 sal_uInt16 nIndex = 0; 2222 for(auto& rNV : aSeq) 2223 { 2224 rNV.Name = GetCommandContextByIndex(nIndex++); 2225 rNV.Value <<= OUString(); 2226 } 2227 SwFormat* pFormat = static_cast<SwDocStyleSheet*>(GetStyleSheetBase())->GetCollection(); 2228 if(pFormat && RES_CONDTXTFMTCOLL == pFormat->Which()) 2229 { 2230 const CommandStruct* pCmds = SwCondCollItem::GetCmds(); 2231 beans::NamedValue* pSeq = aSeq.getArray(); 2232 for(sal_uInt16 n = 0; n < COND_COMMAND_COUNT; ++n) 2233 { 2234 const SwCollCondition* pCond = static_cast<SwConditionTextFormatColl*>(pFormat)->HasCondition(SwCollCondition(nullptr, pCmds[n].nCnd, pCmds[n].nSubCond)); 2235 if(!pCond || !pCond->GetTextFormatColl()) 2236 continue; 2237 // get programmatic style name from UI style name 2238 OUString aStyleName = pCond->GetTextFormatColl()->GetName(); 2239 SwStyleNameMapper::FillProgName(aStyleName, aStyleName, lcl_GetSwEnumFromSfxEnum(GetFamily())); 2240 pSeq[n].Value <<= aStyleName; 2241 } 2242 } 2243 return uno::makeAny(aSeq); 2244 } 2245 template<> 2246 uno::Any SwXStyle::GetStyleProperty<FN_UNO_CATEGORY>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) 2247 { 2248 PrepareStyleBase(rBase); 2249 static std::unique_ptr<std::map<collectionbits_t, paragraphstyle_t>> pUnoToCore; 2250 if(!pUnoToCore) 2251 { 2252 pUnoToCore.reset(new std::map<collectionbits_t, paragraphstyle_t>); 2253 auto pEntries = lcl_GetParagraphStyleCategoryEntries(); 2254 std::transform(pEntries->begin(), pEntries->end(), std::inserter(*pUnoToCore, pUnoToCore->end()), 2255 [] (const ParagraphStyleCategoryEntry& rEntry) { return std::pair<collectionbits_t, paragraphstyle_t>(rEntry.m_nCollectionBits, rEntry.m_eCategory); }); 2256 } 2257 const sal_uInt16 nPoolId = rBase.getNewBase()->GetCollection()->GetPoolFormatId(); 2258 const auto pUnoToCoreIt(pUnoToCore->find(COLL_GET_RANGE_BITS & nPoolId)); 2259 if(pUnoToCoreIt == pUnoToCore->end()) 2260 return uno::makeAny<sal_Int16>(-1); 2261 return uno::makeAny(pUnoToCoreIt->second); 2262 } 2263 template<> 2264 uno::Any SwXStyle::GetStyleProperty<SID_SWREGISTER_COLLECTION>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) 2265 { 2266 PrepareStyleBase(rBase); 2267 const SwPageDesc *pPageDesc = rBase.getNewBase()->GetPageDesc(); 2268 if(!pPageDesc) 2269 return uno::makeAny(OUString()); 2270 const SwTextFormatColl* pCol = pPageDesc->GetRegisterFormatColl(); 2271 if(!pCol) 2272 return uno::makeAny(OUString()); 2273 OUString aName; 2274 SwStyleNameMapper::FillProgName(pCol->GetName(), aName, SwGetPoolIdFromName::TxtColl); 2275 return uno::makeAny(aName); 2276 } 2277 template<> 2278 uno::Any SwXStyle::GetStyleProperty<sal_uInt16(RES_BACKGROUND)>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) 2279 { 2280 PrepareStyleBase(rBase); 2281 const SfxItemSet& rSet = rBase.GetItemSet(); 2282 const SvxBrushItem aOriginalBrushItem(getSvxBrushItemFromSourceSet(rSet, RES_BACKGROUND)); 2283 uno::Any aResult; 2284 if(!aOriginalBrushItem.QueryValue(aResult, rEntry.nMemberId)) 2285 SAL_WARN("sw.uno", "error getting attribute from RES_BACKGROUND."); 2286 return aResult; 2287 } 2288 template<> 2289 uno::Any SwXStyle::GetStyleProperty<OWN_ATTR_FILLBMP_MODE>(const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl& rBase) 2290 { 2291 PrepareStyleBase(rBase); 2292 const SfxItemSet& rSet = rBase.GetItemSet(); 2293 if (rSet.Get(XATTR_FILLBMP_TILE).GetValue()) 2294 return uno::makeAny(drawing::BitmapMode_REPEAT); 2295 if (rSet.Get(XATTR_FILLBMP_STRETCH).GetValue()) 2296 return uno::makeAny(drawing::BitmapMode_STRETCH); 2297 return uno::makeAny(drawing::BitmapMode_NO_REPEAT); 2298 } 2299 template<> 2300 uno::Any SwXStyle::GetStyleProperty<HINT_BEGIN>(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase) 2301 { 2302 PrepareStyleBase(rBase); 2303 SfxItemSet& rSet = rBase.GetItemSet(); 2304 uno::Any aResult; 2305 rPropSet.getPropertyValue(rEntry, rSet, aResult); 2306 // 2307 // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here 2308 if(rEntry.aType == cppu::UnoType<sal_Int16>::get() && aResult.getValueType() == cppu::UnoType<sal_Int32>::get()) 2309 aResult <<= static_cast<sal_Int16>(aResult.get<sal_Int32>()); 2310 // check for needed metric translation 2311 if(rEntry.nMoreFlags & PropertyMoreFlags::METRIC_ITEM && GetDoc()) 2312 { 2313 const SfxItemPool& rPool = GetDoc()->GetAttrPool(); 2314 const MapUnit eMapUnit(rPool.GetMetric(rEntry.nWID)); 2315 bool bAllowedConvert(true); 2316 // exception: If these ItemTypes are used, do not convert when these are negative 2317 // since this means they are intended as percent values 2318 if(XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID) 2319 bAllowedConvert = !aResult.has<sal_Int32>() || aResult.get<sal_Int32>() > 0; 2320 if(eMapUnit != MapUnit::Map100thMM && bAllowedConvert) 2321 SvxUnoConvertToMM(eMapUnit, aResult); 2322 } 2323 return aResult; 2324 } 2325 2326 uno::Any SwXStyle::GetStyleProperty_Impl(const SfxItemPropertySimpleEntry& rEntry, const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase) 2327 { 2328 using propertytype_t = decltype(rEntry.nWID); 2329 using coresetter_t = std::function<uno::Any(SwXStyle&, const SfxItemPropertySimpleEntry&, const SfxItemPropertySet&, SwStyleBase_Impl&)>; 2330 static std::unique_ptr<std::map<propertytype_t, coresetter_t>> pUnoToCore; 2331 if(!pUnoToCore) 2332 { 2333 pUnoToCore.reset(new std::map<propertytype_t, coresetter_t> { 2334 // these explicit std::mem_fn() calls shouldn't be needed, but apparently MSVC is currently too stupid for C++11 again 2335 { FN_UNO_IS_PHYSICAL, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_IS_PHYSICAL>) }, 2336 { FN_UNO_HIDDEN, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_HIDDEN>) }, 2337 { FN_UNO_STYLE_INTEROP_GRAB_BAG, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_STYLE_INTEROP_GRAB_BAG>) }, 2338 { RES_PAPER_BIN, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PAPER_BIN)>) }, 2339 { FN_UNO_NUM_RULES, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_NUM_RULES>) }, 2340 { RES_PARATR_OUTLINELEVEL, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PARATR_OUTLINELEVEL)>) }, 2341 { FN_UNO_FOLLOW_STYLE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_FOLLOW_STYLE>) }, 2342 { RES_PAGEDESC, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_PAGEDESC)>) }, 2343 { FN_UNO_IS_AUTO_UPDATE, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_IS_AUTO_UPDATE>) }, 2344 { FN_UNO_DISPLAY_NAME, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_DISPLAY_NAME>) }, 2345 { FN_UNO_PARA_STYLE_CONDITIONS, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_PARA_STYLE_CONDITIONS>) }, 2346 { FN_UNO_CATEGORY, std::mem_fn(&SwXStyle::GetStyleProperty<FN_UNO_CATEGORY>) }, 2347 { SID_SWREGISTER_COLLECTION, std::mem_fn(&SwXStyle::GetStyleProperty<SID_SWREGISTER_COLLECTION>) }, 2348 { RES_BACKGROUND, std::mem_fn(&SwXStyle::GetStyleProperty<sal_uInt16(RES_BACKGROUND)>) }, 2349 { OWN_ATTR_FILLBMP_MODE, std::mem_fn(&SwXStyle::GetStyleProperty<OWN_ATTR_FILLBMP_MODE>) } 2350 }); 2351 } 2352 const auto pUnoToCoreIt(pUnoToCore->find(rEntry.nWID)); 2353 if(pUnoToCoreIt != pUnoToCore->end()) 2354 return pUnoToCoreIt->second(*this, rEntry, rPropSet, rBase); 2355 return GetStyleProperty<HINT_BEGIN>(rEntry, rPropSet, rBase); 2356 } 2357 2358 uno::Any SwXStyle::GetPropertyValue_Impl(const SfxItemPropertySet* pPropSet, SwStyleBase_Impl& rBase, const OUString& rPropertyName) 2359 { 2360 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap(); 2361 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rPropertyName); 2362 if(!pEntry || (!m_bIsConditional && rPropertyName == UNO_NAME_PARA_STYLE_CONDITIONS)) 2363 throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast<cppu::OWeakObject*>(this)); 2364 if(m_pBasePool) 2365 return GetStyleProperty_Impl(*pEntry, *pPropSet, rBase); 2366 const uno::Any* pAny = nullptr; 2367 m_pPropertiesImpl->GetProperty(rPropertyName, pAny); 2368 if(pAny->hasValue()) 2369 return *pAny; 2370 uno::Any aValue; 2371 switch(m_rEntry.m_eFamily) 2372 { 2373 case SfxStyleFamily::Pseudo: 2374 throw uno::RuntimeException("No default value for: " + rPropertyName); 2375 break; 2376 case SfxStyleFamily::Para: 2377 case SfxStyleFamily::Page: 2378 SwStyleProperties_Impl::GetProperty(rPropertyName, m_xStyleData, aValue); 2379 break; 2380 case SfxStyleFamily::Char: 2381 case SfxStyleFamily::Frame: 2382 { 2383 if(pEntry->nWID < POOLATTR_BEGIN || pEntry->nWID >= RES_UNKNOWNATR_END) 2384 throw uno::RuntimeException("No default value for: " + rPropertyName); 2385 SwFormat* pFormat; 2386 if(m_rEntry.m_eFamily == SfxStyleFamily::Char) 2387 pFormat = m_pDoc->GetDfltCharFormat(); 2388 else 2389 pFormat = m_pDoc->GetDfltFrameFormat(); 2390 const SwAttrPool* pPool = pFormat->GetAttrSet().GetPool(); 2391 const SfxPoolItem& rItem = pPool->GetDefaultItem(pEntry->nWID); 2392 rItem.QueryValue(aValue, pEntry->nMemberId); 2393 } 2394 break; 2395 default: 2396 ; 2397 } 2398 return aValue; 2399 } 2400 2401 uno::Any SwXStyle::getPropertyValue(const OUString& rPropertyName) 2402 { 2403 SolarMutexGuard aGuard; 2404 if(!m_pDoc) 2405 throw uno::RuntimeException(); 2406 if(!m_pBasePool && !m_bIsDescriptor) 2407 throw uno::RuntimeException(); 2408 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.m_nPropMapType; 2409 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); 2410 SwStyleBase_Impl aBase(*m_pDoc, m_sStyleName, &m_pDoc->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent 2411 return GetPropertyValue_Impl(pPropSet, aBase, rPropertyName); 2412 } 2413 2414 uno::Sequence<uno::Any> SwXStyle::getPropertyValues(const uno::Sequence<OUString>& rPropertyNames) 2415 { 2416 SolarMutexGuard aGuard; 2417 if(!m_pDoc) 2418 throw uno::RuntimeException(); 2419 if(!m_pBasePool && !m_bIsDescriptor) 2420 throw uno::RuntimeException(); 2421 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.m_nPropMapType; 2422 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); 2423 SwStyleBase_Impl aBase(*m_pDoc, m_sStyleName, &m_pDoc->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent 2424 uno::Sequence<uno::Any> aValues(rPropertyNames.getLength()); 2425 // workaround for bad designed API 2426 try 2427 { 2428 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp) 2429 aValues[nProp] = GetPropertyValue_Impl(pPropSet, aBase, rPropertyNames[nProp]); 2430 } 2431 catch(beans::UnknownPropertyException&) 2432 { 2433 css::uno::Any anyEx = cppu::getCaughtException(); 2434 throw css::lang::WrappedTargetRuntimeException("Unknown property exception caught", 2435 static_cast < cppu::OWeakObject * > ( this ), anyEx ); 2436 } 2437 catch(lang::WrappedTargetException&) 2438 { 2439 css::uno::Any anyEx = cppu::getCaughtException(); 2440 throw lang::WrappedTargetRuntimeException("WrappedTargetException caught", 2441 static_cast < cppu::OWeakObject * > ( this ), anyEx ); 2442 } 2443 return aValues; 2444 } 2445 2446 void SwXStyle::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue) 2447 { 2448 SolarMutexGuard aGuard; 2449 const uno::Sequence<OUString> aProperties(&rPropertyName, 1); 2450 const uno::Sequence<uno::Any> aValues(&rValue, 1); 2451 SetPropertyValues_Impl(aProperties, aValues); 2452 } 2453 2454 beans::PropertyState SwXStyle::getPropertyState(const OUString& rPropertyName) 2455 { 2456 SolarMutexGuard aGuard; 2457 uno::Sequence<OUString> aNames{rPropertyName}; 2458 uno::Sequence<beans::PropertyState> aStates = getPropertyStates(aNames); 2459 return aStates.getConstArray()[0]; 2460 } 2461 2462 // allow to retarget the SfxItemSet working on, default correctly. Only 2463 // use pSourceSet below this point (except in header/footer processing) 2464 static const SfxItemSet* lcl_GetItemsetForProperty(const SfxItemSet& rSet, SfxStyleFamily eFamily, const OUString& rPropertyName) 2465 { 2466 if(eFamily != SfxStyleFamily::Page) 2467 return &rSet; 2468 const bool isFooter = rPropertyName.startsWith("Footer"); 2469 if(!isFooter && !rPropertyName.startsWith("Header") && rPropertyName != UNO_NAME_FIRST_IS_SHARED) 2470 return &rSet; 2471 const SvxSetItem* pSetItem; 2472 if(!lcl_GetHeaderFooterItem(rSet, rPropertyName, isFooter, pSetItem)) 2473 return nullptr; 2474 return &pSetItem->GetItemSet(); 2475 } 2476 uno::Sequence<beans::PropertyState> SwXStyle::getPropertyStates(const uno::Sequence<OUString>& rPropertyNames) 2477 { 2478 SolarMutexGuard aGuard; 2479 uno::Sequence<beans::PropertyState> aRet(rPropertyNames.getLength()); 2480 beans::PropertyState* pStates = aRet.getArray(); 2481 2482 if(!m_pBasePool) 2483 throw uno::RuntimeException(); 2484 m_pBasePool->SetSearchMask(m_rEntry.m_eFamily); 2485 SfxStyleSheetBase* pBase = m_pBasePool->Find(m_sStyleName); 2486 2487 SAL_WARN_IF(!pBase, "sw.uno", "where is the style?"); 2488 if(!pBase) 2489 throw uno::RuntimeException(); 2490 2491 const OUString* pNames = rPropertyNames.getConstArray(); 2492 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 2493 sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.m_nPropMapType; 2494 2495 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); 2496 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap(); 2497 const SfxItemSet& rSet = xStyle->GetItemSet(); 2498 2499 for(sal_Int32 i = 0; i < rPropertyNames.getLength(); ++i) 2500 { 2501 const OUString sPropName = pNames[i]; 2502 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(sPropName); 2503 2504 if(!pEntry) 2505 throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast<cppu::OWeakObject*>(this)); 2506 2507 if(FN_UNO_NUM_RULES == pEntry->nWID || FN_UNO_FOLLOW_STYLE == pEntry->nWID) 2508 { 2509 // handle NumRules first, done 2510 pStates[i] = beans::PropertyState_DIRECT_VALUE; 2511 continue; 2512 } 2513 const SfxItemSet* pSourceSet = lcl_GetItemsetForProperty(rSet, m_rEntry.m_eFamily, sPropName); 2514 if(!pSourceSet) 2515 { 2516 // if no SetItem, value is ambiguous and we are done 2517 pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE; 2518 continue; 2519 } 2520 switch(pEntry->nWID) 2521 { 2522 case OWN_ATTR_FILLBMP_MODE: 2523 { 2524 if(SfxItemState::SET == pSourceSet->GetItemState(XATTR_FILLBMP_STRETCH, false) 2525 || SfxItemState::SET == pSourceSet->GetItemState(XATTR_FILLBMP_TILE, false)) 2526 { 2527 pStates[i] = beans::PropertyState_DIRECT_VALUE; 2528 } 2529 else 2530 { 2531 pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE; 2532 } 2533 } 2534 break; 2535 case RES_BACKGROUND: 2536 { 2537 // for FlyFrames we need to mark the used properties from type RES_BACKGROUND 2538 // as beans::PropertyState_DIRECT_VALUE to let users of this property call 2539 // getPropertyValue where the member properties will be mapped from the 2540 // fill attributes to the according SvxBrushItem entries 2541 if (SWUnoHelper::needToMapFillItemsToSvxBrushItemTypes(*pSourceSet, pEntry->nMemberId)) 2542 { 2543 pStates[i] = beans::PropertyState_DIRECT_VALUE; 2544 } 2545 else 2546 { 2547 pStates[i] = beans::PropertyState_DEFAULT_VALUE; 2548 } 2549 } 2550 break; 2551 default: 2552 { 2553 pStates[i] = pPropSet->getPropertyState(*pEntry, *pSourceSet); 2554 2555 if(SfxStyleFamily::Page == m_rEntry.m_eFamily && SID_ATTR_PAGE_SIZE == pEntry->nWID && beans::PropertyState_DIRECT_VALUE == pStates[i]) 2556 { 2557 const SvxSizeItem& rSize = rSet.Get(SID_ATTR_PAGE_SIZE); 2558 sal_uInt8 nMemberId = pEntry->nMemberId & 0x7f; 2559 2560 if((LONG_MAX == rSize.GetSize().Width() && (MID_SIZE_WIDTH == nMemberId || MID_SIZE_SIZE == nMemberId)) || 2561 (LONG_MAX == rSize.GetSize().Height() && MID_SIZE_HEIGHT == nMemberId)) 2562 { 2563 pStates[i] = beans::PropertyState_DEFAULT_VALUE; 2564 } 2565 } 2566 } 2567 } 2568 } 2569 return aRet; 2570 } 2571 2572 void SwXStyle::setPropertyToDefault(const OUString& rPropertyName) 2573 { 2574 const uno::Sequence<OUString> aSequence(&rPropertyName, 1); 2575 setPropertiesToDefault(aSequence); 2576 } 2577 2578 static SwFormat* lcl_GetFormatForStyle(SwDoc const * pDoc, const rtl::Reference<SwDocStyleSheet>& xStyle, const SfxStyleFamily eFamily) 2579 { 2580 if(!xStyle.is()) 2581 return nullptr; 2582 switch(eFamily) 2583 { 2584 case SfxStyleFamily::Char: return xStyle->GetCharFormat(); 2585 case SfxStyleFamily::Para: return xStyle->GetCollection(); 2586 case SfxStyleFamily::Frame: return xStyle->GetFrameFormat(); 2587 case SfxStyleFamily::Page: 2588 { 2589 SwPageDesc* pDesc(pDoc->FindPageDesc(xStyle->GetPageDesc()->GetName())); 2590 if(pDesc) 2591 return &pDesc->GetMaster(); 2592 } 2593 break; 2594 default: ; 2595 } 2596 return nullptr; 2597 } 2598 2599 void SAL_CALL SwXStyle::setPropertiesToDefault(const uno::Sequence<OUString>& aPropertyNames) 2600 { 2601 SolarMutexGuard aGuard; 2602 const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(GetStyleSheetBase()))); 2603 SwFormat* pTargetFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.m_eFamily); 2604 if(!pTargetFormat) 2605 { 2606 if(!m_bIsDescriptor) 2607 return; 2608 for(const auto& rName : aPropertyNames) 2609 m_pPropertiesImpl->ClearProperty(rName); 2610 return; 2611 } 2612 const sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.m_nPropMapType; 2613 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); 2614 const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap(); 2615 for(const auto& rName : aPropertyNames) 2616 { 2617 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rName); 2618 if(!pEntry) 2619 throw beans::UnknownPropertyException("Unknown property: " + rName, static_cast<cppu::OWeakObject*>(this)); 2620 if(pEntry->nWID == FN_UNO_FOLLOW_STYLE || pEntry->nWID == FN_UNO_NUM_RULES) 2621 throw uno::RuntimeException("Cannot reset: " + rName, static_cast<cppu::OWeakObject*>(this)); 2622 if(pEntry->nFlags & beans::PropertyAttribute::READONLY) 2623 throw uno::RuntimeException("setPropertiesToDefault: property is read-only: " + rName, static_cast<cppu::OWeakObject*>(this)); 2624 if(pEntry->nWID == RES_PARATR_OUTLINELEVEL) 2625 { 2626 static_cast<SwTextFormatColl*>(pTargetFormat)->DeleteAssignmentToListLevelOfOutlineStyle(); 2627 continue; 2628 } 2629 pTargetFormat->ResetFormatAttr(pEntry->nWID); 2630 if(OWN_ATTR_FILLBMP_MODE == pEntry->nWID) 2631 { 2632 // 2633 SwDoc* pDoc = pTargetFormat->GetDoc(); 2634 SfxItemSet aSet(pDoc->GetAttrPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}); 2635 aSet.SetParent(&pTargetFormat->GetAttrSet()); 2636 2637 aSet.ClearItem(XATTR_FILLBMP_STRETCH); 2638 aSet.ClearItem(XATTR_FILLBMP_TILE); 2639 2640 pTargetFormat->SetFormatAttr(aSet); 2641 } 2642 } 2643 } 2644 2645 void SAL_CALL SwXStyle::setAllPropertiesToDefault() 2646 { 2647 SolarMutexGuard aGuard; 2648 if(!m_pBasePool) 2649 { 2650 if(!m_bIsDescriptor) 2651 throw uno::RuntimeException(); 2652 m_pPropertiesImpl->ClearAllProperties(); 2653 return; 2654 } 2655 const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(GetStyleSheetBase()))); 2656 if(!xStyle.is()) 2657 throw uno::RuntimeException(); 2658 if(SfxStyleFamily::Page == m_rEntry.m_eFamily) 2659 { 2660 size_t nPgDscPos(0); 2661 SwPageDesc* pDesc = m_pDoc->FindPageDesc(xStyle->GetPageDesc()->GetName(), &nPgDscPos); 2662 SwFormat* pPageFormat(nullptr); 2663 if(pDesc) 2664 { 2665 pPageFormat = &pDesc->GetMaster(); 2666 pDesc->SetUseOn(UseOnPage::All); 2667 } 2668 else 2669 pPageFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.m_eFamily); 2670 SwPageDesc& rPageDesc = m_pDoc->GetPageDesc(nPgDscPos); 2671 rPageDesc.ResetAllMasterAttr(); 2672 2673 SvxLRSpaceItem aLR(RES_LR_SPACE); 2674 sal_Int32 nSize = GetMetricVal(CM_1) * 2; 2675 aLR.SetLeft(nSize); 2676 aLR.SetLeft(nSize); 2677 SvxULSpaceItem aUL(RES_UL_SPACE); 2678 aUL.SetUpper(static_cast<sal_uInt16>(nSize)); 2679 aUL.SetLower(static_cast<sal_uInt16>(nSize)); 2680 pPageFormat->SetFormatAttr(aLR); 2681 pPageFormat->SetFormatAttr(aUL); 2682 SwPageDesc* pStdPgDsc = m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD); 2683 SwFormatFrameSize aFrameSz(ATT_FIX_SIZE); 2684 2685 if(RES_POOLPAGE_STANDARD == rPageDesc.GetPoolFormatId()) 2686 { 2687 if(m_pDoc->getIDocumentDeviceAccess().getPrinter(false)) 2688 { 2689 const Size aPhysSize( SvxPaperInfo::GetPaperSize( 2690 static_cast<Printer*>(m_pDoc->getIDocumentDeviceAccess().getPrinter(false)))); 2691 aFrameSz.SetSize(aPhysSize); 2692 } 2693 else 2694 { 2695 aFrameSz.SetSize(SvxPaperInfo::GetDefaultPaperSize()); 2696 } 2697 2698 } 2699 else 2700 { 2701 aFrameSz = pStdPgDsc->GetMaster().GetFrameSize(); 2702 } 2703 2704 if(pStdPgDsc->GetLandscape()) 2705 { 2706 SwTwips nTmp = aFrameSz.GetHeight(); 2707 aFrameSz.SetHeight(aFrameSz.GetWidth()); 2708 aFrameSz.SetWidth(nTmp); 2709 } 2710 2711 pPageFormat->SetFormatAttr(aFrameSz); 2712 m_pDoc->ChgPageDesc(nPgDscPos, m_pDoc->GetPageDesc(nPgDscPos)); 2713 return; 2714 } 2715 if(SfxStyleFamily::Para == m_rEntry.m_eFamily) 2716 { 2717 if(xStyle->GetCollection()) 2718 xStyle->GetCollection()->DeleteAssignmentToListLevelOfOutlineStyle(); 2719 } 2720 SwFormat* const pTargetFormat = lcl_GetFormatForStyle(m_pDoc, xStyle, m_rEntry.m_eFamily); 2721 if(!pTargetFormat) 2722 return; 2723 pTargetFormat->ResetAllFormatAttr(); 2724 } 2725 2726 uno::Sequence<uno::Any> SAL_CALL SwXStyle::getPropertyDefaults(const uno::Sequence<OUString>& aPropertyNames) 2727 { 2728 SolarMutexGuard aGuard; 2729 sal_Int32 nCount = aPropertyNames.getLength(); 2730 uno::Sequence<uno::Any> aRet(nCount); 2731 if(!nCount) 2732 return aRet; 2733 SfxStyleSheetBase* pBase = GetStyleSheetBase(); 2734 if(!pBase) 2735 throw uno::RuntimeException(); 2736 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 2737 const sal_Int8 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.m_nPropMapType; 2738 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); 2739 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap(); 2740 2741 const SfxItemSet &rSet = xStyle->GetItemSet(), *pParentSet = rSet.GetParent(); 2742 for(sal_Int32 i = 0; i < nCount; ++i) 2743 { 2744 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(aPropertyNames[i]); 2745 2746 if(!pEntry) 2747 throw beans::UnknownPropertyException("Unknown property: " + aPropertyNames[i], static_cast < cppu::OWeakObject * >(this)); 2748 // these cannot be in an item set, especially not the 2749 // parent set, so the default value is void 2750 if (pEntry->nWID >= RES_UNKNOWNATR_END) 2751 continue; 2752 2753 if(pParentSet) 2754 { 2755 aSwMapProvider.GetPropertySet(nPropSetId)->getPropertyValue(aPropertyNames[i], *pParentSet, aRet[i]); 2756 } 2757 else if(pEntry->nWID != rSet.GetPool()->GetSlotId(pEntry->nWID)) 2758 { 2759 const SfxPoolItem& rItem = rSet.GetPool()->GetDefaultItem(pEntry->nWID); 2760 rItem.QueryValue(aRet[i], pEntry->nMemberId); 2761 } 2762 } 2763 return aRet; 2764 } 2765 2766 uno::Any SwXStyle::getPropertyDefault(const OUString& rPropertyName) 2767 { 2768 const uno::Sequence<OUString> aSequence(&rPropertyName, 1); 2769 return getPropertyDefaults(aSequence)[0]; 2770 } 2771 2772 void SwXStyle::Notify(SfxBroadcaster& rBC, const SfxHint& rHint) 2773 { 2774 if((rHint.GetId() == SfxHintId::Dying) || (rHint.GetId() == SfxHintId::StyleSheetErased)) 2775 { 2776 m_pBasePool = nullptr; 2777 SfxListener::EndListening(rBC); 2778 } 2779 else if(rHint.GetId() == SfxHintId::StyleSheetChanged) 2780 { 2781 static_cast<SfxStyleSheetBasePool&>(rBC).SetSearchMask(m_rEntry.m_eFamily); 2782 SfxStyleSheetBase* pOwnBase = static_cast<SfxStyleSheetBasePool&>(rBC).Find(m_sStyleName); 2783 if(!pOwnBase) 2784 { 2785 SfxListener::EndListening(rBC); 2786 Invalidate(); 2787 } 2788 } 2789 } 2790 2791 void SwXStyle::Invalidate() 2792 { 2793 m_sStyleName.clear(); 2794 m_pBasePool = nullptr; 2795 m_pDoc = nullptr; 2796 m_xStyleData.clear(); 2797 m_xStyleFamily.clear(); 2798 } 2799 2800 SwXPageStyle::SwXPageStyle(SfxStyleSheetBasePool& rPool, SwDocShell* pDocSh, const OUString& rStyleName) 2801 : SwXStyle(&rPool, SfxStyleFamily::Page, pDocSh->GetDoc(), rStyleName) 2802 { } 2803 2804 SwXPageStyle::SwXPageStyle(SwDocShell* pDocSh) 2805 : SwXStyle(pDocSh->GetDoc(), SfxStyleFamily::Page) 2806 { } 2807 2808 void SwXStyle::PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet, const SfxItemPropertySimpleEntry& rEntry, const uno::Any& rVal, SwStyleBase_Impl& rBaseImpl) 2809 { 2810 // create a new SvxSetItem and get it's ItemSet as new target 2811 const std::unique_ptr<SvxSetItem> pNewSetItem(static_cast<SvxSetItem*>(pSetItem->Clone())); 2812 SfxItemSet& rSetSet = pNewSetItem->GetItemSet(); 2813 2814 // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem 2815 rSetSet.SetParent(&m_pDoc->GetDfltFrameFormat()->GetAttrSet()); 2816 2817 // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the 2818 // default method to set the property 2819 { 2820 SwStyleBase_Impl::ItemSetOverrider o(rBaseImpl, &rSetSet); 2821 SetStyleProperty(rEntry, rPropSet, rVal, rBaseImpl); 2822 } 2823 2824 // reset paret at ItemSet from SetItem 2825 rSetSet.SetParent(nullptr); 2826 2827 // set the new SvxSetItem at the real target and delete it 2828 rBaseImpl.GetItemSet().Put(*pNewSetItem); 2829 } 2830 2831 void SwXPageStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues) 2832 { 2833 if(!GetDoc()) 2834 throw uno::RuntimeException(); 2835 2836 if(rPropertyNames.getLength() != rValues.getLength()) 2837 throw lang::IllegalArgumentException(); 2838 2839 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_PAGE_STYLE); 2840 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap(); 2841 SwStyleBase_Impl aBaseImpl(*GetDoc(), GetStyleName(), &GetDoc()->GetDfltFrameFormat()->GetAttrSet()); // add pDfltFrameFormat as parent 2842 if(!m_pBasePool) 2843 { 2844 if(!IsDescriptor()) 2845 throw uno::RuntimeException(); 2846 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp) 2847 if(!m_pPropertiesImpl->SetProperty(rPropertyNames[nProp], rValues[nProp])) 2848 throw lang::IllegalArgumentException(); 2849 return; 2850 } 2851 SfxStyleSheetBase* pBase = GetStyleSheetBase(); 2852 if(!pBase) 2853 throw uno::RuntimeException(); 2854 aBaseImpl.setNewBase(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 2855 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp) 2856 { 2857 const OUString& rPropName = rPropertyNames[nProp]; 2858 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rPropName); 2859 2860 if(!pEntry) 2861 throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast<cppu::OWeakObject*>(this)); 2862 if(pEntry->nFlags & beans::PropertyAttribute::READONLY) 2863 throw beans::PropertyVetoException("Property is read-only: " + rPropName, static_cast<cppu::OWeakObject*>(this)); 2864 2865 const bool bHeader(rPropName.startsWith("Header")); 2866 const bool bFooter(rPropName.startsWith("Footer")); 2867 const bool bFirstIsShared(rPropName == UNO_NAME_FIRST_IS_SHARED); 2868 if(bHeader || bFooter || bFirstIsShared) 2869 { 2870 switch(pEntry->nWID) 2871 { 2872 case SID_ATTR_PAGE_ON: 2873 case RES_BACKGROUND: 2874 case RES_BOX: 2875 case RES_LR_SPACE: 2876 case RES_SHADOW: 2877 case RES_UL_SPACE: 2878 case SID_ATTR_PAGE_DYNAMIC: 2879 case SID_ATTR_PAGE_SHARED: 2880 case SID_ATTR_PAGE_SHARED_FIRST: 2881 case SID_ATTR_PAGE_SIZE: 2882 case RES_HEADER_FOOTER_EAT_SPACING: 2883 { 2884 // it is a Header/Footer entry, access the SvxSetItem containing it's information 2885 const SvxSetItem* pSetItem = nullptr; 2886 if (lcl_GetHeaderFooterItem(aBaseImpl.GetItemSet(), rPropName, bFooter, pSetItem)) 2887 { 2888 PutItemToSet(pSetItem, *pPropSet, *pEntry, rValues[nProp], aBaseImpl); 2889 2890 if (pEntry->nWID == SID_ATTR_PAGE_SHARED_FIRST) 2891 { 2892 // Need to add this to the other as well 2893 if (SfxItemState::SET == aBaseImpl.GetItemSet().GetItemState( 2894 bFooter ? SID_ATTR_PAGE_HEADERSET : SID_ATTR_PAGE_FOOTERSET, 2895 false, reinterpret_cast<const SfxPoolItem**>(&pSetItem))) 2896 { 2897 PutItemToSet(pSetItem, *pPropSet, *pEntry, rValues[nProp], aBaseImpl); 2898 } 2899 } 2900 } 2901 else if(pEntry->nWID == SID_ATTR_PAGE_ON && rValues[nProp].get<bool>()) 2902 { 2903 // Header/footer gets switched on, create defaults and the needed SfxSetItem 2904 SfxItemSet aTempSet(*aBaseImpl.GetItemSet().GetPool(), 2905 svl::Items<RES_FRMATR_BEGIN,RES_FRMATR_END - 1, // [82 2906 2907 // FillAttribute support 2908 XATTR_FILL_FIRST, XATTR_FILL_LAST, // [1014 2909 2910 SID_ATTR_BORDER_INNER,SID_ATTR_BORDER_INNER, // [10023 2911 SID_ATTR_PAGE_SIZE,SID_ATTR_PAGE_SIZE, // [10051 2912 SID_ATTR_PAGE_ON,SID_ATTR_PAGE_SHARED, // [10060 2913 SID_ATTR_PAGE_SHARED_FIRST,SID_ATTR_PAGE_SHARED_FIRST>{}); 2914 2915 // set correct parent to get the XFILL_NONE FillStyle as needed 2916 aTempSet.SetParent(&GetDoc()->GetDfltFrameFormat()->GetAttrSet()); 2917 2918 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_ON, true)); 2919 aTempSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(MM50, MM50))); 2920 aTempSet.Put(SvxLRSpaceItem(RES_LR_SPACE)); 2921 aTempSet.Put(SvxULSpaceItem(RES_UL_SPACE)); 2922 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_SHARED, true)); 2923 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_SHARED_FIRST, true)); 2924 aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_DYNAMIC, true)); 2925 2926 SvxSetItem aNewSetItem(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, aTempSet); 2927 aBaseImpl.GetItemSet().Put(aNewSetItem); 2928 } 2929 } 2930 continue; 2931 case XATTR_FILLBMP_SIZELOG: 2932 case XATTR_FILLBMP_TILEOFFSETX: 2933 case XATTR_FILLBMP_TILEOFFSETY: 2934 case XATTR_FILLBMP_POSOFFSETX: 2935 case XATTR_FILLBMP_POSOFFSETY: 2936 case XATTR_FILLBMP_POS: 2937 case XATTR_FILLBMP_SIZEX: 2938 case XATTR_FILLBMP_SIZEY: 2939 case XATTR_FILLBMP_STRETCH: 2940 case XATTR_FILLBMP_TILE: 2941 case OWN_ATTR_FILLBMP_MODE: 2942 case XATTR_FILLCOLOR: 2943 case XATTR_FILLBACKGROUND: 2944 case XATTR_FILLBITMAP: 2945 case XATTR_GRADIENTSTEPCOUNT: 2946 case XATTR_FILLGRADIENT: 2947 case XATTR_FILLHATCH: 2948 case XATTR_FILLSTYLE: 2949 case XATTR_FILLTRANSPARENCE: 2950 case XATTR_FILLFLOATTRANSPARENCE: 2951 case XATTR_SECONDARYFILLCOLOR: 2952 if(bFirstIsShared) // only special handling for headers/footers here 2953 break; 2954 { 2955 const SvxSetItem* pSetItem = nullptr; 2956 2957 if(SfxItemState::SET == aBaseImpl.GetItemSet().GetItemState(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false, reinterpret_cast<const SfxPoolItem**>(&pSetItem))) 2958 { 2959 // create a new SvxSetItem and get it's ItemSet as new target 2960 std::unique_ptr<SvxSetItem> pNewSetItem(static_cast<SvxSetItem*>(pSetItem->Clone())); 2961 SfxItemSet& rSetSet = pNewSetItem->GetItemSet(); 2962 2963 // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem 2964 rSetSet.SetParent(&GetDoc()->GetDfltFrameFormat()->GetAttrSet()); 2965 2966 // replace the used SfxItemSet at the SwStyleBase_Impl temporarily and use the 2967 // default method to set the property 2968 { 2969 SwStyleBase_Impl::ItemSetOverrider o(aBaseImpl, &rSetSet); 2970 SetStyleProperty(*pEntry, *pPropSet, rValues[nProp], aBaseImpl); 2971 } 2972 2973 // reset paret at ItemSet from SetItem 2974 rSetSet.SetParent(nullptr); 2975 2976 // set the new SvxSetItem at the real target and delete it 2977 aBaseImpl.GetItemSet().Put(*pNewSetItem); 2978 } 2979 } 2980 continue; 2981 default: ; 2982 } 2983 } 2984 switch(pEntry->nWID) 2985 { 2986 case SID_ATTR_PAGE_DYNAMIC: 2987 case SID_ATTR_PAGE_SHARED: 2988 case SID_ATTR_PAGE_SHARED_FIRST: 2989 case SID_ATTR_PAGE_ON: 2990 case RES_HEADER_FOOTER_EAT_SPACING: 2991 // these slots are exclusive to Header/Footer, thus this is an error 2992 throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast<cppu::OWeakObject*>(this)); 2993 case FN_UNO_HEADER: 2994 case FN_UNO_HEADER_LEFT: 2995 case FN_UNO_HEADER_RIGHT: 2996 case FN_UNO_HEADER_FIRST: 2997 case FN_UNO_FOOTER: 2998 case FN_UNO_FOOTER_LEFT: 2999 case FN_UNO_FOOTER_RIGHT: 3000 case FN_UNO_FOOTER_FIRST: 3001 throw lang::IllegalArgumentException(); 3002 case FN_PARAM_FTN_INFO: 3003 { 3004 const SfxPoolItem& rItem = aBaseImpl.GetItemSet().Get(FN_PARAM_FTN_INFO); 3005 const std::unique_ptr<SfxPoolItem> pNewFootnoteItem(rItem.Clone()); 3006 if(!pNewFootnoteItem->PutValue(rValues[nProp], pEntry->nMemberId)) 3007 throw lang::IllegalArgumentException(); 3008 aBaseImpl.GetItemSet().Put(*pNewFootnoteItem); 3009 break; 3010 } 3011 default: 3012 { 3013 SetStyleProperty(*pEntry, *pPropSet, rValues[nProp], aBaseImpl); 3014 break; 3015 } 3016 } 3017 } 3018 3019 if(aBaseImpl.HasItemSet()) 3020 { 3021 ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo()); 3022 3023 if (undoGuard.UndoWasEnabled()) 3024 { 3025 // Fix i64460: as long as Undo of page styles with header/footer causes trouble... 3026 GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj(); 3027 } 3028 3029 aBaseImpl.getNewBase()->SetItemSet(aBaseImpl.GetItemSet()); 3030 } 3031 } 3032 3033 void SwXPageStyle::setPropertyValues(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues) 3034 { 3035 SolarMutexGuard aGuard; 3036 3037 // workaround for bad designed API 3038 try 3039 { 3040 SetPropertyValues_Impl(rPropertyNames, rValues); 3041 } 3042 catch (const beans::UnknownPropertyException &rException) 3043 { 3044 // wrap the original (here not allowed) exception in 3045 // a lang::WrappedTargetException that gets thrown instead. 3046 lang::WrappedTargetException aWExc; 3047 aWExc.TargetException <<= rException; 3048 throw aWExc; 3049 } 3050 } 3051 3052 static uno::Reference<text::XText> lcl_makeHeaderFooter(const sal_uInt16 nRes, const bool bHeader, SwFrameFormat const*const pFrameFormat) 3053 { 3054 if (!pFrameFormat) 3055 return nullptr; 3056 const SfxItemSet& rSet = pFrameFormat->GetAttrSet(); 3057 const SfxPoolItem* pItem; 3058 if(SfxItemState::SET != rSet.GetItemState(nRes, true, &pItem)) 3059 return nullptr; 3060 SwFrameFormat* const pHeadFootFormat = bHeader 3061 ? static_cast<SwFormatHeader*>(const_cast<SfxPoolItem*>(pItem))->GetHeaderFormat() 3062 : static_cast<SwFormatFooter*>(const_cast<SfxPoolItem*>(pItem))->GetFooterFormat(); 3063 if(!pHeadFootFormat) 3064 return nullptr; 3065 return SwXHeadFootText::CreateXHeadFootText(*pHeadFootFormat, bHeader); 3066 } 3067 3068 uno::Sequence<uno::Any> SwXPageStyle::GetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames) 3069 { 3070 if(!GetDoc()) 3071 throw uno::RuntimeException(); 3072 3073 sal_Int32 nLength = rPropertyNames.getLength(); 3074 uno::Sequence<uno::Any> aRet (nLength); 3075 if(!m_pBasePool) 3076 { 3077 if(!IsDescriptor()) 3078 throw uno::RuntimeException(); 3079 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp) 3080 { 3081 const uno::Any* pAny = nullptr; 3082 m_pPropertiesImpl->GetProperty(rPropertyNames[nProp], pAny); 3083 if (!pAny->hasValue()) 3084 SwStyleProperties_Impl::GetProperty(rPropertyNames[nProp], m_xStyleData, aRet[nProp]); 3085 else 3086 aRet[nProp] = *pAny; 3087 } 3088 return aRet; 3089 } 3090 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_PAGE_STYLE); 3091 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap(); 3092 SwStyleBase_Impl aBase(*GetDoc(), GetStyleName(), &GetDoc()->GetDfltFrameFormat()->GetAttrSet()); // add pDfltFrameFormat as parent 3093 SfxStyleSheetBase* pBase = GetStyleSheetBase(); 3094 if(!pBase) 3095 throw uno::RuntimeException(); 3096 for(sal_Int32 nProp = 0; nProp < nLength; ++nProp) 3097 { 3098 const OUString& rPropName = rPropertyNames[nProp]; 3099 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rPropName); 3100 3101 if (!pEntry) 3102 throw beans::UnknownPropertyException("Unknown property: " + rPropName, static_cast < cppu::OWeakObject * > ( this ) ); 3103 const bool bHeader(rPropName.startsWith("Header")); 3104 const bool bFooter(rPropName.startsWith("Footer")); 3105 const bool bFirstIsShared(rPropName == UNO_NAME_FIRST_IS_SHARED); 3106 if(bHeader || bFooter || bFirstIsShared) 3107 { 3108 switch(pEntry->nWID) 3109 { 3110 case SID_ATTR_PAGE_ON: 3111 case RES_BACKGROUND: 3112 case RES_BOX: 3113 case RES_LR_SPACE: 3114 case RES_SHADOW: 3115 case RES_UL_SPACE: 3116 case SID_ATTR_PAGE_DYNAMIC: 3117 case SID_ATTR_PAGE_SHARED: 3118 case SID_ATTR_PAGE_SHARED_FIRST: 3119 case SID_ATTR_PAGE_SIZE: 3120 case RES_HEADER_FOOTER_EAT_SPACING: 3121 { 3122 // slot is a Header/Footer slot 3123 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) ) ); 3124 const SfxItemSet& rSet = xStyle->GetItemSet(); 3125 const SvxSetItem* pSetItem; 3126 3127 if (lcl_GetHeaderFooterItem(rSet, rPropName, bFooter, pSetItem)) 3128 { 3129 // get from SfxItemSet of the corresponding SfxSetItem 3130 const SfxItemSet& rSetSet = pSetItem->GetItemSet(); 3131 { 3132 SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast< SfxItemSet& >(rSetSet)); 3133 aRet[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase); 3134 } 3135 } 3136 else if(pEntry->nWID == SID_ATTR_PAGE_ON) 3137 { 3138 // header/footer is not available, thus off. Default is <false>, though 3139 aRet[nProp] <<= false; 3140 } 3141 } 3142 continue; 3143 case XATTR_FILLBMP_SIZELOG: 3144 case XATTR_FILLBMP_TILEOFFSETX: 3145 case XATTR_FILLBMP_TILEOFFSETY: 3146 case XATTR_FILLBMP_POSOFFSETX: 3147 case XATTR_FILLBMP_POSOFFSETY: 3148 case XATTR_FILLBMP_POS: 3149 case XATTR_FILLBMP_SIZEX: 3150 case XATTR_FILLBMP_SIZEY: 3151 case XATTR_FILLBMP_STRETCH: 3152 case XATTR_FILLBMP_TILE: 3153 case OWN_ATTR_FILLBMP_MODE: 3154 case XATTR_FILLCOLOR: 3155 case XATTR_FILLBACKGROUND: 3156 case XATTR_FILLBITMAP: 3157 case XATTR_GRADIENTSTEPCOUNT: 3158 case XATTR_FILLGRADIENT: 3159 case XATTR_FILLHATCH: 3160 case XATTR_FILLSTYLE: 3161 case XATTR_FILLTRANSPARENCE: 3162 case XATTR_FILLFLOATTRANSPARENCE: 3163 case XATTR_SECONDARYFILLCOLOR: 3164 if(bFirstIsShared) // only special handling for headers/footers here 3165 break; 3166 { 3167 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pBase) ) ); 3168 const SfxItemSet& rSet = xStyle->GetItemSet(); 3169 const SvxSetItem* pSetItem; 3170 if(SfxItemState::SET == rSet.GetItemState(bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, false, reinterpret_cast<const SfxPoolItem**>(&pSetItem))) 3171 { 3172 // set at SfxItemSet of the corresponding SfxSetItem 3173 const SfxItemSet& rSetSet = pSetItem->GetItemSet(); 3174 { 3175 SwStyleBase_Impl::ItemSetOverrider o(aBase, &const_cast<SfxItemSet&>(rSetSet)); 3176 aRet[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase); 3177 } 3178 } 3179 } 3180 continue; 3181 default: ; 3182 } 3183 } 3184 switch(pEntry->nWID) 3185 { 3186 // these slots are exclusive to Header/Footer, thus this is an error 3187 case SID_ATTR_PAGE_DYNAMIC: 3188 case SID_ATTR_PAGE_SHARED: 3189 case SID_ATTR_PAGE_SHARED_FIRST: 3190 case SID_ATTR_PAGE_ON: 3191 case RES_HEADER_FOOTER_EAT_SPACING: 3192 throw beans::UnknownPropertyException( "Unknown property: " + rPropName, static_cast < cppu::OWeakObject * > ( this ) ); 3193 case FN_UNO_HEADER: 3194 case FN_UNO_HEADER_LEFT: 3195 case FN_UNO_HEADER_FIRST: 3196 case FN_UNO_HEADER_RIGHT: 3197 case FN_UNO_FOOTER: 3198 case FN_UNO_FOOTER_LEFT: 3199 case FN_UNO_FOOTER_FIRST: 3200 case FN_UNO_FOOTER_RIGHT: 3201 { 3202 bool bLeft(false); 3203 bool bFirst(false); 3204 sal_uInt16 nRes = 0; 3205 switch(pEntry->nWID) 3206 { 3207 case FN_UNO_HEADER: nRes = RES_HEADER; break; 3208 case FN_UNO_HEADER_LEFT: nRes = RES_HEADER; bLeft = true; break; 3209 case FN_UNO_HEADER_FIRST: nRes = RES_HEADER; bFirst = true; break; 3210 case FN_UNO_HEADER_RIGHT: nRes = RES_HEADER; break; 3211 case FN_UNO_FOOTER: nRes = RES_FOOTER; break; 3212 case FN_UNO_FOOTER_LEFT: nRes = RES_FOOTER; bLeft = true; break; 3213 case FN_UNO_FOOTER_FIRST: nRes = RES_FOOTER; bFirst = true; break; 3214 case FN_UNO_FOOTER_RIGHT: nRes = RES_FOOTER; break; 3215 default: ; 3216 } 3217 3218 const SwPageDesc* pDesc = aBase.GetOldPageDesc(); 3219 assert(pDesc); 3220 const SwFrameFormat* pFrameFormat = nullptr; 3221 bool bShare = (nRes == RES_HEADER && pDesc->IsHeaderShared()) || (nRes == RES_FOOTER && pDesc->IsFooterShared()); 3222 bool bShareFirst = pDesc->IsFirstShared(); 3223 // TextLeft returns the left content if there is one, 3224 // Text and TextRight return the master content. 3225 // TextRight does the same as Text and is for 3226 // compatibility only. 3227 if(bLeft && !bShare) 3228 pFrameFormat = &pDesc->GetLeft(); 3229 else if(bFirst && !bShareFirst) 3230 { 3231 pFrameFormat = &pDesc->GetFirstMaster(); 3232 // no need to make GetFirstLeft() accessible 3233 // since it is always shared 3234 } 3235 else 3236 pFrameFormat = &pDesc->GetMaster(); 3237 const uno::Reference<text::XText> xRet = lcl_makeHeaderFooter(nRes, nRes == RES_HEADER, pFrameFormat); 3238 if (xRet.is()) 3239 aRet[nProp] <<= xRet; 3240 } 3241 break; 3242 case FN_PARAM_FTN_INFO: 3243 { 3244 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 3245 const SfxItemSet& rSet = xStyle->GetItemSet(); 3246 const SfxPoolItem& rItem = rSet.Get(FN_PARAM_FTN_INFO); 3247 rItem.QueryValue(aRet[nProp], pEntry->nMemberId); 3248 } 3249 break; 3250 default: 3251 aRet[nProp] = GetStyleProperty_Impl(*pEntry, *pPropSet, aBase); 3252 } 3253 } 3254 return aRet; 3255 } 3256 3257 uno::Sequence<uno::Any> SwXPageStyle::getPropertyValues(const uno::Sequence<OUString>& rPropertyNames) 3258 { 3259 SolarMutexGuard aGuard; 3260 uno::Sequence<uno::Any> aValues; 3261 3262 // workaround for bad designed API 3263 try 3264 { 3265 aValues = GetPropertyValues_Impl(rPropertyNames); 3266 } 3267 catch(beans::UnknownPropertyException &) 3268 { 3269 css::uno::Any anyEx = cppu::getCaughtException(); 3270 throw lang::WrappedTargetRuntimeException("Unknown property exception caught", 3271 static_cast < cppu::OWeakObject * > ( this ), anyEx ); 3272 } 3273 catch(lang::WrappedTargetException &) 3274 { 3275 css::uno::Any anyEx = cppu::getCaughtException(); 3276 throw lang::WrappedTargetRuntimeException("WrappedTargetException caught", 3277 static_cast < cppu::OWeakObject * > ( this ), anyEx ); 3278 } 3279 3280 return aValues; 3281 } 3282 3283 uno::Any SwXPageStyle::getPropertyValue(const OUString& rPropertyName) 3284 { 3285 SolarMutexGuard aGuard; 3286 const uno::Sequence<OUString> aProperties(&rPropertyName, 1); 3287 return GetPropertyValues_Impl(aProperties)[0]; 3288 } 3289 3290 void SwXPageStyle::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue) 3291 { 3292 SolarMutexGuard aGuard; 3293 const uno::Sequence<OUString> aProperties(&rPropertyName, 1); 3294 const uno::Sequence<uno::Any> aValues(&rValue, 1); 3295 SetPropertyValues_Impl(aProperties, aValues); 3296 } 3297 3298 SwXFrameStyle::SwXFrameStyle(SwDoc *pDoc) 3299 : SwXStyle(pDoc, SfxStyleFamily::Frame, false) 3300 { } 3301 3302 void SwXFrameStyle::SetItem(sal_uInt16 eAtr, const SfxPoolItem& rItem) 3303 { 3304 assert(eAtr >= RES_FRMATR_BEGIN && eAtr < RES_FRMATR_END); 3305 SfxStyleSheetBase* pBase = GetStyleSheetBase(); 3306 if(!pBase) 3307 return; 3308 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 3309 SfxItemSet& rStyleSet = xStyle->GetItemSet(); 3310 SfxItemSet aSet(*rStyleSet.GetPool(), {{sal_uInt16(eAtr), sal_uInt16(eAtr)}}); 3311 aSet.Put(rItem); 3312 xStyle->SetItemSet(aSet); 3313 } 3314 3315 const SfxPoolItem* SwXFrameStyle::GetItem(sal_uInt16 eAtr) 3316 { 3317 assert(eAtr >= RES_FRMATR_BEGIN && eAtr < RES_FRMATR_END); 3318 SfxStyleSheetBase* pBase = GetStyleSheetBase(); 3319 if(!pBase) 3320 return nullptr; 3321 rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pBase))); 3322 return &xStyle->GetItemSet().Get(eAtr); 3323 } 3324 3325 uno::Sequence<uno::Type> SwXFrameStyle::getTypes() 3326 { 3327 uno::Sequence<uno::Type> aTypes = SwXStyle::getTypes(); 3328 sal_Int32 nLen = aTypes.getLength(); 3329 aTypes.realloc(nLen + 1); 3330 aTypes[nLen] = cppu::UnoType<XEventsSupplier>::get(); 3331 return aTypes; 3332 } 3333 3334 uno::Any SwXFrameStyle::queryInterface(const uno::Type& rType) 3335 { 3336 if(rType == cppu::UnoType<XEventsSupplier>::get()) 3337 return uno::makeAny(uno::Reference<XEventsSupplier>(this)); 3338 return SwXStyle::queryInterface(rType); 3339 } 3340 3341 uno::Reference<container::XNameReplace> SwXFrameStyle::getEvents() 3342 { 3343 return new SwFrameStyleEventDescriptor(*this); 3344 } 3345 3346 // Already implemented autostyle families: 3 3347 #define AUTOSTYLE_FAMILY_COUNT 3 3348 const IStyleAccess::SwAutoStyleFamily aAutoStyleByIndex[] = 3349 { 3350 IStyleAccess::AUTO_STYLE_CHAR, 3351 IStyleAccess::AUTO_STYLE_RUBY, 3352 IStyleAccess::AUTO_STYLE_PARA 3353 }; 3354 3355 class SwAutoStylesEnumImpl 3356 { 3357 std::vector<std::shared_ptr<SfxItemSet>> mAutoStyles; 3358 std::vector<std::shared_ptr<SfxItemSet>>::iterator aIter; 3359 SwDoc* pDoc; 3360 IStyleAccess::SwAutoStyleFamily const eFamily; 3361 public: 3362 SwAutoStylesEnumImpl( SwDoc* pInitDoc, IStyleAccess::SwAutoStyleFamily eFam ); 3363 bool hasMoreElements() { return aIter != mAutoStyles.end(); } 3364 std::shared_ptr<SfxItemSet> const & nextElement() { return *(aIter++); } 3365 IStyleAccess::SwAutoStyleFamily getFamily() const { return eFamily; } 3366 SwDoc* getDoc() const { return pDoc; } 3367 }; 3368 3369 SwXAutoStyles::SwXAutoStyles(SwDocShell& rDocShell) : 3370 SwUnoCollection(rDocShell.GetDoc()), m_pDocShell( &rDocShell ) 3371 { 3372 } 3373 3374 SwXAutoStyles::~SwXAutoStyles() 3375 { 3376 } 3377 3378 sal_Int32 SwXAutoStyles::getCount() 3379 { 3380 return AUTOSTYLE_FAMILY_COUNT; 3381 } 3382 3383 uno::Any SwXAutoStyles::getByIndex(sal_Int32 nIndex) 3384 { 3385 SolarMutexGuard aGuard; 3386 uno::Any aRet; 3387 if(nIndex < 0 || nIndex >= AUTOSTYLE_FAMILY_COUNT) 3388 throw lang::IndexOutOfBoundsException(); 3389 if(!IsValid()) 3390 throw uno::RuntimeException(); 3391 3392 uno::Reference< style::XAutoStyleFamily > aRef; 3393 IStyleAccess::SwAutoStyleFamily nType = aAutoStyleByIndex[nIndex]; 3394 switch( nType ) 3395 { 3396 case IStyleAccess::AUTO_STYLE_CHAR: 3397 { 3398 if(!m_xAutoCharStyles.is()) 3399 m_xAutoCharStyles = new SwXAutoStyleFamily(m_pDocShell, nType); 3400 aRef = m_xAutoCharStyles; 3401 } 3402 break; 3403 case IStyleAccess::AUTO_STYLE_RUBY: 3404 { 3405 if(!m_xAutoRubyStyles.is()) 3406 m_xAutoRubyStyles = new SwXAutoStyleFamily(m_pDocShell, nType ); 3407 aRef = m_xAutoRubyStyles; 3408 } 3409 break; 3410 case IStyleAccess::AUTO_STYLE_PARA: 3411 { 3412 if(!m_xAutoParaStyles.is()) 3413 m_xAutoParaStyles = new SwXAutoStyleFamily(m_pDocShell, nType ); 3414 aRef = m_xAutoParaStyles; 3415 } 3416 break; 3417 3418 default: 3419 ; 3420 } 3421 aRet <<= aRef; 3422 3423 return aRet; 3424 } 3425 3426 uno::Type SwXAutoStyles::getElementType( ) 3427 { 3428 return cppu::UnoType<style::XAutoStyleFamily>::get(); 3429 } 3430 3431 sal_Bool SwXAutoStyles::hasElements( ) 3432 { 3433 return true; 3434 } 3435 3436 uno::Any SwXAutoStyles::getByName(const OUString& Name) 3437 { 3438 uno::Any aRet; 3439 if(Name == "CharacterStyles") 3440 aRet = getByIndex(0); 3441 else if(Name == "RubyStyles") 3442 aRet = getByIndex(1); 3443 else if(Name == "ParagraphStyles") 3444 aRet = getByIndex(2); 3445 else 3446 throw container::NoSuchElementException(); 3447 return aRet; 3448 } 3449 3450 uno::Sequence< OUString > SwXAutoStyles::getElementNames() 3451 { 3452 uno::Sequence< OUString > aNames(AUTOSTYLE_FAMILY_COUNT); 3453 OUString* pNames = aNames.getArray(); 3454 pNames[0] = "CharacterStyles"; 3455 pNames[1] = "RubyStyles"; 3456 pNames[2] = "ParagraphStyles"; 3457 return aNames; 3458 } 3459 3460 sal_Bool SwXAutoStyles::hasByName(const OUString& Name) 3461 { 3462 if( Name == "CharacterStyles" || 3463 Name == "RubyStyles" || 3464 Name == "ParagraphStyles" ) 3465 return true; 3466 else 3467 return false; 3468 } 3469 3470 SwXAutoStyleFamily::SwXAutoStyleFamily(SwDocShell* pDocSh, IStyleAccess::SwAutoStyleFamily nFamily) : 3471 m_pDocShell( pDocSh ), m_eFamily(nFamily) 3472 { 3473 // Register ourselves as a listener to the document (via the page descriptor) 3474 StartListening(pDocSh->GetDoc()->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); 3475 } 3476 3477 SwXAutoStyleFamily::~SwXAutoStyleFamily() 3478 { 3479 } 3480 3481 void SwXAutoStyleFamily::Notify(const SfxHint& rHint) 3482 { 3483 if(rHint.GetId() == SfxHintId::Dying) 3484 m_pDocShell = nullptr; 3485 } 3486 3487 uno::Reference< style::XAutoStyle > SwXAutoStyleFamily::insertStyle( 3488 const uno::Sequence< beans::PropertyValue >& Values ) 3489 { 3490 if (!m_pDocShell) 3491 { 3492 throw uno::RuntimeException(); 3493 } 3494 3495 const sal_uInt16* pRange = nullptr; 3496 const SfxItemPropertySet* pPropSet = nullptr; 3497 switch( m_eFamily ) 3498 { 3499 case IStyleAccess::AUTO_STYLE_CHAR: 3500 { 3501 pRange = aCharAutoFormatSetRange; 3502 pPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CHAR_AUTO_STYLE); 3503 break; 3504 } 3505 case IStyleAccess::AUTO_STYLE_RUBY: 3506 { 3507 pRange = nullptr;//aTextNodeSetRange; 3508 pPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_RUBY_AUTO_STYLE); 3509 break; 3510 } 3511 case IStyleAccess::AUTO_STYLE_PARA: 3512 { 3513 pRange = aTextNodeSetRange; // checked, already added support for [XATTR_FILL_FIRST, XATTR_FILL_LAST] 3514 pPropSet = aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARA_AUTO_STYLE); 3515 break; 3516 } 3517 default: ; 3518 } 3519 3520 if( !pPropSet) 3521 throw uno::RuntimeException(); 3522 3523 SwAttrSet aSet( m_pDocShell->GetDoc()->GetAttrPool(), pRange ); 3524 const beans::PropertyValue* pSeq = Values.getConstArray(); 3525 sal_Int32 nLen = Values.getLength(); 3526 const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == m_eFamily); 3527 3528 if(!bTakeCareOfDrawingLayerFillStyle) 3529 { 3530 for( sal_Int32 i = 0; i < nLen; ++i ) 3531 { 3532 try 3533 { 3534 pPropSet->setPropertyValue( pSeq[i].Name, pSeq[i].Value, aSet ); 3535 } 3536 catch (const beans::UnknownPropertyException &) 3537 { 3538 OSL_FAIL( "Unknown property" ); 3539 } 3540 catch (const lang::IllegalArgumentException &) 3541 { 3542 OSL_FAIL( "Illegal argument" ); 3543 } 3544 } 3545 } 3546 else 3547 { 3548 // set parent to ItemSet to ensure XFILL_NONE as XFillStyleItem 3549 // to make cases in RES_BACKGROUND work correct; target *is* a style 3550 // where this is the case 3551 aSet.SetParent(&m_pDocShell->GetDoc()->GetDfltTextFormatColl()->GetAttrSet()); 3552 3553 // here the used DrawingLayer FillStyles are imported when family is 3554 // equal to IStyleAccess::AUTO_STYLE_PARA, thus we will need to serve the 3555 // used slots functionality here to do this correctly 3556 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap(); 3557 3558 for( sal_Int32 i = 0; i < nLen; ++i ) 3559 { 3560 const OUString& rPropName = pSeq[i].Name; 3561 uno::Any aValue(pSeq[i].Value); 3562 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rPropName); 3563 3564 if (!pEntry) 3565 { 3566 SAL_WARN("sw.core", "SwXAutoStyleFamily::insertStyle: Unknown property: " << rPropName); 3567 continue; 3568 } 3569 3570 const sal_uInt8 nMemberId(pEntry->nMemberId); 3571 bool bDone(false); 3572 3573 // check for needed metric translation 3574 if(pEntry->nMoreFlags & PropertyMoreFlags::METRIC_ITEM) 3575 { 3576 bool bDoIt(true); 3577 3578 if(XATTR_FILLBMP_SIZEX == pEntry->nWID || XATTR_FILLBMP_SIZEY == pEntry->nWID) 3579 { 3580 // exception: If these ItemTypes are used, do not convert when these are negative 3581 // since this means they are intended as percent values 3582 sal_Int32 nValue = 0; 3583 3584 if(aValue >>= nValue) 3585 { 3586 bDoIt = nValue > 0; 3587 } 3588 } 3589 3590 if(bDoIt) 3591 { 3592 const SfxItemPool& rPool = m_pDocShell->GetDoc()->GetAttrPool(); 3593 const MapUnit eMapUnit(rPool.GetMetric(pEntry->nWID)); 3594 3595 if(eMapUnit != MapUnit::Map100thMM) 3596 { 3597 SvxUnoConvertFromMM(eMapUnit, aValue); 3598 } 3599 } 3600 } 3601 3602 switch(pEntry->nWID) 3603 { 3604 case XATTR_FILLGRADIENT: 3605 case XATTR_FILLHATCH: 3606 case XATTR_FILLBITMAP: 3607 case XATTR_FILLFLOATTRANSPARENCE: 3608 // not yet needed; activate when LineStyle support may be added 3609 // case XATTR_LINESTART: 3610 // case XATTR_LINEEND: 3611 // case XATTR_LINEDASH: 3612 { 3613 if(MID_NAME == nMemberId) 3614 { 3615 // add set commands for FillName items 3616 OUString aTempName; 3617 3618 if(!(aValue >>= aTempName)) 3619 { 3620 throw lang::IllegalArgumentException(); 3621 } 3622 3623 SvxShape::SetFillAttribute(pEntry->nWID, aTempName, aSet); 3624 bDone = true; 3625 } 3626 else if (MID_BITMAP == nMemberId) 3627 { 3628 if(XATTR_FILLBITMAP == pEntry->nWID) 3629 { 3630 const Graphic aNullGraphic; 3631 XFillBitmapItem aXFillBitmapItem(aNullGraphic); 3632 3633 aXFillBitmapItem.PutValue(aValue, nMemberId); 3634 aSet.Put(aXFillBitmapItem); 3635 bDone = true; 3636 } 3637 } 3638 3639 break; 3640 } 3641 case RES_BACKGROUND: 3642 { 3643 const SvxBrushItem aOriginalBrushItem(getSvxBrushItemFromSourceSet(aSet, RES_BACKGROUND, true, m_pDocShell->GetDoc()->IsInXMLImport())); 3644 SvxBrushItem aChangedBrushItem(aOriginalBrushItem); 3645 3646 aChangedBrushItem.PutValue(aValue, nMemberId); 3647 3648 if(aChangedBrushItem != aOriginalBrushItem) 3649 { 3650 setSvxBrushItemAsFillAttributesToTargetSet(aChangedBrushItem, aSet); 3651 } 3652 3653 bDone = true; 3654 break; 3655 } 3656 case OWN_ATTR_FILLBMP_MODE: 3657 { 3658 drawing::BitmapMode eMode; 3659 3660 if(!(aValue >>= eMode)) 3661 { 3662 sal_Int32 nMode = 0; 3663 3664 if(!(aValue >>= nMode)) 3665 { 3666 throw lang::IllegalArgumentException(); 3667 } 3668 3669 eMode = static_cast<drawing::BitmapMode>(nMode); 3670 } 3671 3672 aSet.Put(XFillBmpStretchItem(drawing::BitmapMode_STRETCH == eMode)); 3673 aSet.Put(XFillBmpTileItem(drawing::BitmapMode_REPEAT == eMode)); 3674 3675 bDone = true; 3676 break; 3677 } 3678 default: break; 3679 } 3680 3681 if(!bDone) 3682 { 3683 try 3684 { 3685 pPropSet->setPropertyValue( rPropName, aValue, aSet ); 3686 } 3687 catch (const beans::UnknownPropertyException &) 3688 { 3689 OSL_FAIL( "Unknown property" ); 3690 } 3691 catch (const lang::IllegalArgumentException &) 3692 { 3693 OSL_FAIL( "Illegal argument" ); 3694 } 3695 } 3696 } 3697 3698 // clear parent again 3699 aSet.SetParent(nullptr); 3700 } 3701 3702 // need to ensure uniqueness of evtl. added NameOrIndex items 3703 // currently in principle only needed when bTakeCareOfDrawingLayerFillStyle, 3704 // but does not hurt and is easily forgotten later eventually, so keep it 3705 // as common case 3706 m_pDocShell->GetDoc()->CheckForUniqueItemForLineFillNameOrIndex(aSet); 3707 3708 // AutomaticStyle creation 3709 std::shared_ptr<SfxItemSet> pSet = m_pDocShell->GetDoc()->GetIStyleAccess().cacheAutomaticStyle( aSet, m_eFamily ); 3710 uno::Reference<style::XAutoStyle> xRet = new SwXAutoStyle(m_pDocShell->GetDoc(), pSet, m_eFamily); 3711 3712 return xRet; 3713 } 3714 3715 uno::Reference< container::XEnumeration > SwXAutoStyleFamily::createEnumeration( ) 3716 { 3717 if( !m_pDocShell ) 3718 throw uno::RuntimeException(); 3719 return uno::Reference< container::XEnumeration > 3720 (new SwXAutoStylesEnumerator( m_pDocShell->GetDoc(), m_eFamily )); 3721 } 3722 3723 uno::Type SwXAutoStyleFamily::getElementType( ) 3724 { 3725 return cppu::UnoType<style::XAutoStyle>::get(); 3726 } 3727 3728 sal_Bool SwXAutoStyleFamily::hasElements( ) 3729 { 3730 return false; 3731 } 3732 3733 SwAutoStylesEnumImpl::SwAutoStylesEnumImpl( SwDoc* pInitDoc, IStyleAccess::SwAutoStyleFamily eFam ) 3734 : pDoc( pInitDoc ), eFamily( eFam ) 3735 { 3736 // special case for ruby auto styles: 3737 if ( IStyleAccess::AUTO_STYLE_RUBY == eFam ) 3738 { 3739 std::set< std::pair< sal_uInt16, text::RubyAdjust > > aRubyMap; 3740 SwAttrPool& rAttrPool = pDoc->GetAttrPool(); 3741 sal_uInt32 nCount = rAttrPool.GetItemCount2( RES_TXTATR_CJK_RUBY ); 3742 3743 for ( sal_uInt32 nI = 0; nI < nCount; ++nI ) 3744 { 3745 const SwFormatRuby* pItem = rAttrPool.GetItem2( RES_TXTATR_CJK_RUBY, nI ); 3746 if ( pItem && pItem->GetTextRuby() ) 3747 { 3748 std::pair< sal_uInt16, text::RubyAdjust > aPair( pItem->GetPosition(), pItem->GetAdjustment() ); 3749 if ( aRubyMap.find( aPair ) == aRubyMap.end() ) 3750 { 3751 aRubyMap.insert( aPair ); 3752 std::shared_ptr<SfxItemSet> pItemSet( new SfxItemSet( rAttrPool, svl::Items<RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY>{} ) ); 3753 pItemSet->Put( *pItem ); 3754 mAutoStyles.push_back( pItemSet ); 3755 } 3756 } 3757 } 3758 } 3759 else 3760 { 3761 pDoc->GetIStyleAccess().getAllStyles( mAutoStyles, eFamily ); 3762 } 3763 3764 aIter = mAutoStyles.begin(); 3765 } 3766 3767 SwXAutoStylesEnumerator::SwXAutoStylesEnumerator( SwDoc* pDoc, IStyleAccess::SwAutoStyleFamily eFam ) 3768 : m_pImpl( new SwAutoStylesEnumImpl( pDoc, eFam ) ) 3769 { 3770 // Register ourselves as a listener to the document (via the page descriptor) 3771 StartListening(pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); 3772 } 3773 3774 SwXAutoStylesEnumerator::~SwXAutoStylesEnumerator() 3775 { 3776 } 3777 3778 void SwXAutoStylesEnumerator::Notify( const SfxHint& rHint) 3779 { 3780 if(rHint.GetId() == SfxHintId::Dying) 3781 m_pImpl.reset(); 3782 } 3783 3784 sal_Bool SwXAutoStylesEnumerator::hasMoreElements( ) 3785 { 3786 if( !m_pImpl ) 3787 throw uno::RuntimeException(); 3788 return m_pImpl->hasMoreElements(); 3789 } 3790 3791 uno::Any SwXAutoStylesEnumerator::nextElement( ) 3792 { 3793 if( !m_pImpl ) 3794 throw uno::RuntimeException(); 3795 uno::Any aRet; 3796 if( m_pImpl->hasMoreElements() ) 3797 { 3798 std::shared_ptr<SfxItemSet> pNextSet = m_pImpl->nextElement(); 3799 uno::Reference< style::XAutoStyle > xAutoStyle = new SwXAutoStyle(m_pImpl->getDoc(), 3800 pNextSet, m_pImpl->getFamily()); 3801 aRet <<= xAutoStyle; 3802 } 3803 return aRet; 3804 } 3805 3806 // SwXAutoStyle with the family IStyleAccess::AUTO_STYLE_PARA (or 3807 // PROPERTY_MAP_PARA_AUTO_STYLE) now uses DrawingLayer FillStyles to allow 3808 // unified paragraph background fill, thus the UNO API implementation has to 3809 // support the needed slots for these. This seems to be used only for reading 3810 // (no setPropertyValue implementation here), so maybe specialized for saving 3811 // the Writer Doc to ODF 3812 3813 SwXAutoStyle::SwXAutoStyle( 3814 SwDoc* pDoc, 3815 std::shared_ptr<SfxItemSet> const & pInitSet, 3816 IStyleAccess::SwAutoStyleFamily eFam) 3817 : mpSet(pInitSet), 3818 meFamily(eFam), 3819 mrDoc(*pDoc) 3820 { 3821 // Register ourselves as a listener to the document (via the page descriptor) 3822 //StartListening(mrDoc.getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); 3823 } 3824 3825 SwXAutoStyle::~SwXAutoStyle() 3826 { 3827 } 3828 3829 void SwXAutoStyle::Notify(const SfxHint& rHint) 3830 { 3831 if(rHint.GetId() == SfxHintId::Dying) 3832 mpSet.reset(); 3833 } 3834 3835 uno::Reference< beans::XPropertySetInfo > SwXAutoStyle::getPropertySetInfo( ) 3836 { 3837 uno::Reference< beans::XPropertySetInfo > xRet; 3838 switch( meFamily ) 3839 { 3840 case IStyleAccess::AUTO_STYLE_CHAR: 3841 { 3842 static uno::Reference< beans::XPropertySetInfo > xCharRef; 3843 if(!xCharRef.is()) 3844 { 3845 xCharRef = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CHAR_AUTO_STYLE)->getPropertySetInfo(); 3846 } 3847 xRet = xCharRef; 3848 } 3849 break; 3850 case IStyleAccess::AUTO_STYLE_RUBY: 3851 { 3852 static uno::Reference< beans::XPropertySetInfo > xRubyRef; 3853 if(!xRubyRef.is()) 3854 { 3855 const sal_uInt16 nMapId = PROPERTY_MAP_RUBY_AUTO_STYLE; 3856 xRubyRef = aSwMapProvider.GetPropertySet(nMapId)->getPropertySetInfo(); 3857 } 3858 xRet = xRubyRef; 3859 } 3860 break; 3861 case IStyleAccess::AUTO_STYLE_PARA: 3862 { 3863 static uno::Reference< beans::XPropertySetInfo > xParaRef; 3864 if(!xParaRef.is()) 3865 { 3866 const sal_uInt16 nMapId = PROPERTY_MAP_PARA_AUTO_STYLE; 3867 xParaRef = aSwMapProvider.GetPropertySet(nMapId)->getPropertySetInfo(); 3868 } 3869 xRet = xParaRef; 3870 } 3871 break; 3872 3873 default: 3874 ; 3875 } 3876 3877 return xRet; 3878 } 3879 3880 void SwXAutoStyle::setPropertyValue( const OUString& /*rPropertyName*/, const uno::Any& /*rValue*/ ) 3881 { 3882 } 3883 3884 uno::Any SwXAutoStyle::getPropertyValue( const OUString& rPropertyName ) 3885 { 3886 SolarMutexGuard aGuard; 3887 const uno::Sequence<OUString> aProperties(&rPropertyName, 1); 3888 return GetPropertyValues_Impl(aProperties).getConstArray()[0]; 3889 } 3890 3891 void SwXAutoStyle::addPropertyChangeListener( const OUString& /*aPropertyName*/, 3892 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) 3893 { 3894 } 3895 3896 void SwXAutoStyle::removePropertyChangeListener( const OUString& /*aPropertyName*/, 3897 const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) 3898 { 3899 } 3900 3901 void SwXAutoStyle::addVetoableChangeListener( const OUString& /*PropertyName*/, 3902 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) 3903 { 3904 } 3905 3906 void SwXAutoStyle::removeVetoableChangeListener( const OUString& /*PropertyName*/, 3907 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) 3908 { 3909 } 3910 3911 void SwXAutoStyle::setPropertyValues( 3912 const uno::Sequence< OUString >& /*aPropertyNames*/, 3913 const uno::Sequence< uno::Any >& /*aValues*/ ) 3914 { 3915 } 3916 3917 uno::Sequence< uno::Any > SwXAutoStyle::GetPropertyValues_Impl( 3918 const uno::Sequence< OUString > & rPropertyNames ) 3919 { 3920 if( !mpSet.get() ) 3921 { 3922 throw uno::RuntimeException(); 3923 } 3924 3925 // query_item 3926 sal_Int8 nPropSetId = PROPERTY_MAP_CHAR_AUTO_STYLE; 3927 switch(meFamily) 3928 { 3929 case IStyleAccess::AUTO_STYLE_CHAR : nPropSetId = PROPERTY_MAP_CHAR_AUTO_STYLE; break; 3930 case IStyleAccess::AUTO_STYLE_RUBY : nPropSetId = PROPERTY_MAP_RUBY_AUTO_STYLE; break; 3931 case IStyleAccess::AUTO_STYLE_PARA : nPropSetId = PROPERTY_MAP_PARA_AUTO_STYLE; break; 3932 default: ; 3933 } 3934 3935 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); 3936 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap(); 3937 const OUString* pNames = rPropertyNames.getConstArray(); 3938 3939 const sal_Int32 nLen(rPropertyNames.getLength()); 3940 uno::Sequence< uno::Any > aRet( nLen ); 3941 uno::Any* pValues = aRet.getArray(); 3942 const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == meFamily); 3943 3944 for( sal_Int32 i = 0; i < nLen; ++i ) 3945 { 3946 const OUString sPropName = pNames[i]; 3947 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(sPropName); 3948 if(!pEntry) 3949 { 3950 throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast < cppu::OWeakObject * > ( this ) ); 3951 } 3952 3953 uno::Any aTarget; 3954 bool bDone(false); 3955 3956 if ( RES_TXTATR_AUTOFMT == pEntry->nWID || RES_AUTO_STYLE == pEntry->nWID ) 3957 { 3958 OUString sName(StylePool::nameOf( mpSet )); 3959 aTarget <<= sName; 3960 bDone = true; 3961 } 3962 else if(bTakeCareOfDrawingLayerFillStyle) 3963 { 3964 // add support for DrawingLayer FillStyle slots 3965 switch(pEntry->nWID) 3966 { 3967 case RES_BACKGROUND: 3968 { 3969 const SvxBrushItem aOriginalBrushItem(getSvxBrushItemFromSourceSet(*mpSet, RES_BACKGROUND)); 3970 3971 if(!aOriginalBrushItem.QueryValue(aTarget, pEntry->nMemberId)) 3972 { 3973 OSL_ENSURE(false, "Error getting attribute from RES_BACKGROUND (!)"); 3974 } 3975 3976 bDone = true; 3977 break; 3978 } 3979 case OWN_ATTR_FILLBMP_MODE: 3980 { 3981 if (mpSet->Get(XATTR_FILLBMP_TILE).GetValue()) 3982 { 3983 aTarget <<= drawing::BitmapMode_REPEAT; 3984 } 3985 else if (mpSet->Get(XATTR_FILLBMP_STRETCH).GetValue()) 3986 { 3987 aTarget <<= drawing::BitmapMode_STRETCH; 3988 } 3989 else 3990 { 3991 aTarget <<= drawing::BitmapMode_NO_REPEAT; 3992 } 3993 3994 bDone = true; 3995 break; 3996 } 3997 } 3998 } 3999 4000 if(!bDone) 4001 { 4002 pPropSet->getPropertyValue( *pEntry, *mpSet, aTarget ); 4003 } 4004 4005 if(bTakeCareOfDrawingLayerFillStyle) 4006 { 4007 if(pEntry->aType == cppu::UnoType<sal_Int16>::get() && pEntry->aType != aTarget.getValueType()) 4008 { 4009 // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here 4010 sal_Int32 nValue = 0; 4011 if (aTarget >>= nValue) 4012 { 4013 aTarget <<= static_cast<sal_Int16>(nValue); 4014 } 4015 } 4016 4017 // check for needed metric translation 4018 if(pEntry->nMoreFlags & PropertyMoreFlags::METRIC_ITEM) 4019 { 4020 bool bDoIt(true); 4021 4022 if(XATTR_FILLBMP_SIZEX == pEntry->nWID || XATTR_FILLBMP_SIZEY == pEntry->nWID) 4023 { 4024 // exception: If these ItemTypes are used, do not convert when these are negative 4025 // since this means they are intended as percent values 4026 sal_Int32 nValue = 0; 4027 4028 if(aTarget >>= nValue) 4029 { 4030 bDoIt = nValue > 0; 4031 } 4032 } 4033 4034 if(bDoIt) 4035 { 4036 const SfxItemPool& rPool = mrDoc.GetAttrPool(); 4037 const MapUnit eMapUnit(rPool.GetMetric(pEntry->nWID)); 4038 4039 if(eMapUnit != MapUnit::Map100thMM) 4040 { 4041 SvxUnoConvertToMM(eMapUnit, aTarget); 4042 } 4043 } 4044 } 4045 } 4046 4047 // add value 4048 pValues[i] = aTarget; 4049 } 4050 4051 return aRet; 4052 } 4053 4054 uno::Sequence< uno::Any > SwXAutoStyle::getPropertyValues ( 4055 const uno::Sequence< OUString >& rPropertyNames ) 4056 { 4057 SolarMutexGuard aGuard; 4058 uno::Sequence< uno::Any > aValues; 4059 4060 // workaround for bad designed API 4061 try 4062 { 4063 aValues = GetPropertyValues_Impl( rPropertyNames ); 4064 } 4065 catch (beans::UnknownPropertyException &) 4066 { 4067 css::uno::Any exc = cppu::getCaughtException(); 4068 throw lang::WrappedTargetRuntimeException("Unknown property exception caught", static_cast < cppu::OWeakObject * > ( this ), exc ); 4069 } 4070 catch (lang::WrappedTargetException &) 4071 { 4072 css::uno::Any exc = cppu::getCaughtException(); 4073 throw lang::WrappedTargetRuntimeException("WrappedTargetException caught", static_cast < cppu::OWeakObject * > ( this ), exc ); 4074 } 4075 4076 return aValues; 4077 } 4078 4079 void SwXAutoStyle::addPropertiesChangeListener( 4080 const uno::Sequence< OUString >& /*aPropertyNames*/, 4081 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ ) 4082 { 4083 } 4084 4085 void SwXAutoStyle::removePropertiesChangeListener( 4086 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ ) 4087 { 4088 } 4089 4090 void SwXAutoStyle::firePropertiesChangeEvent( 4091 const uno::Sequence< OUString >& /*aPropertyNames*/, 4092 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ ) 4093 { 4094 } 4095 4096 beans::PropertyState SwXAutoStyle::getPropertyState( const OUString& rPropertyName ) 4097 { 4098 SolarMutexGuard aGuard; 4099 4100 uno::Sequence< OUString > aNames { rPropertyName }; 4101 uno::Sequence< beans::PropertyState > aStates = getPropertyStates(aNames); 4102 return aStates.getConstArray()[0]; 4103 } 4104 4105 void SwXAutoStyle::setPropertyToDefault( const OUString& /*PropertyName*/ ) 4106 { 4107 } 4108 4109 uno::Any SwXAutoStyle::getPropertyDefault( const OUString& rPropertyName ) 4110 { 4111 const uno::Sequence < OUString > aSequence ( &rPropertyName, 1 ); 4112 return getPropertyDefaults ( aSequence ).getConstArray()[0]; 4113 } 4114 4115 uno::Sequence< beans::PropertyState > SwXAutoStyle::getPropertyStates( 4116 const uno::Sequence< OUString >& rPropertyNames ) 4117 { 4118 if (!mpSet.get()) 4119 { 4120 throw uno::RuntimeException(); 4121 } 4122 4123 SolarMutexGuard aGuard; 4124 uno::Sequence< beans::PropertyState > aRet(rPropertyNames.getLength()); 4125 beans::PropertyState* pStates = aRet.getArray(); 4126 const OUString* pNames = rPropertyNames.getConstArray(); 4127 4128 sal_Int8 nPropSetId = PROPERTY_MAP_CHAR_AUTO_STYLE; 4129 switch(meFamily) 4130 { 4131 case IStyleAccess::AUTO_STYLE_CHAR : nPropSetId = PROPERTY_MAP_CHAR_AUTO_STYLE; break; 4132 case IStyleAccess::AUTO_STYLE_RUBY : nPropSetId = PROPERTY_MAP_RUBY_AUTO_STYLE; break; 4133 case IStyleAccess::AUTO_STYLE_PARA : nPropSetId = PROPERTY_MAP_PARA_AUTO_STYLE; break; 4134 default: ; 4135 } 4136 4137 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); 4138 const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap(); 4139 const bool bTakeCareOfDrawingLayerFillStyle(IStyleAccess::AUTO_STYLE_PARA == meFamily); 4140 4141 for(sal_Int32 i = 0; i < rPropertyNames.getLength(); i++) 4142 { 4143 const OUString sPropName = pNames[i]; 4144 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(sPropName); 4145 if(!pEntry) 4146 { 4147 throw beans::UnknownPropertyException("Unknown property: " + sPropName, static_cast < cppu::OWeakObject * > ( this ) ); 4148 } 4149 4150 bool bDone(false); 4151 4152 if(bTakeCareOfDrawingLayerFillStyle) 4153 { 4154 // DrawingLayer PropertyStyle support 4155 switch(pEntry->nWID) 4156 { 4157 case OWN_ATTR_FILLBMP_MODE: 4158 { 4159 if(SfxItemState::SET == mpSet->GetItemState(XATTR_FILLBMP_STRETCH, false) 4160 || SfxItemState::SET == mpSet->GetItemState(XATTR_FILLBMP_TILE, false)) 4161 { 4162 pStates[i] = beans::PropertyState_DIRECT_VALUE; 4163 } 4164 else 4165 { 4166 pStates[i] = beans::PropertyState_AMBIGUOUS_VALUE; 4167 } 4168 4169 bDone = true; 4170 break; 4171 } 4172 case RES_BACKGROUND: 4173 { 4174 if (SWUnoHelper::needToMapFillItemsToSvxBrushItemTypes(*mpSet, 4175 pEntry->nMemberId)) 4176 { 4177 pStates[i] = beans::PropertyState_DIRECT_VALUE; 4178 } 4179 else 4180 { 4181 pStates[i] = beans::PropertyState_DEFAULT_VALUE; 4182 } 4183 bDone = true; 4184 4185 break; 4186 } 4187 } 4188 } 4189 4190 if(!bDone) 4191 { 4192 pStates[i] = pPropSet->getPropertyState(*pEntry, *mpSet ); 4193 } 4194 } 4195 4196 return aRet; 4197 } 4198 4199 void SwXAutoStyle::setAllPropertiesToDefault( ) 4200 { 4201 } 4202 4203 void SwXAutoStyle::setPropertiesToDefault( 4204 const uno::Sequence< OUString >& /*rPropertyNames*/ ) 4205 { 4206 } 4207 4208 uno::Sequence< uno::Any > SwXAutoStyle::getPropertyDefaults( 4209 const uno::Sequence< OUString >& /*aPropertyNames*/ ) 4210 { 4211 uno::Sequence< uno::Any > aRet(0); 4212 return aRet; 4213 } 4214 4215 uno::Sequence< beans::PropertyValue > SwXAutoStyle::getProperties() 4216 { 4217 if( !mpSet.get() ) 4218 throw uno::RuntimeException(); 4219 SolarMutexGuard aGuard; 4220 std::vector< beans::PropertyValue > aPropertyVector; 4221 4222 sal_Int8 nPropSetId = 0; 4223 switch(meFamily) 4224 { 4225 case IStyleAccess::AUTO_STYLE_CHAR : nPropSetId = PROPERTY_MAP_CHAR_AUTO_STYLE; break; 4226 case IStyleAccess::AUTO_STYLE_RUBY : nPropSetId = PROPERTY_MAP_RUBY_AUTO_STYLE; break; 4227 case IStyleAccess::AUTO_STYLE_PARA : nPropSetId = PROPERTY_MAP_PARA_AUTO_STYLE; break; 4228 default: ; 4229 } 4230 4231 const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); 4232 const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap(); 4233 PropertyEntryVector_t aPropVector = rMap.getPropertyEntries(); 4234 4235 SfxItemSet& rSet = *mpSet; 4236 SfxItemIter aIter(rSet); 4237 const SfxPoolItem* pItem = aIter.FirstItem(); 4238 4239 while ( pItem ) 4240 { 4241 const sal_uInt16 nWID = pItem->Which(); 4242 4243 // TODO: Optimize - and fix! the old iteration filled each WhichId 4244 // only once but there are more properties than WhichIds 4245 for( const auto& rProp : aPropVector ) 4246 { 4247 if ( rProp.nWID == nWID ) 4248 { 4249 beans::PropertyValue aPropertyValue; 4250 aPropertyValue.Name = rProp.sName; 4251 pItem->QueryValue( aPropertyValue.Value, rProp.nMemberId ); 4252 aPropertyVector.push_back( aPropertyValue ); 4253 } 4254 } 4255 pItem = aIter.NextItem(); 4256 } 4257 4258 const sal_Int32 nCount = aPropertyVector.size(); 4259 uno::Sequence< beans::PropertyValue > aRet( nCount ); 4260 beans::PropertyValue* pProps = aRet.getArray(); 4261 4262 for ( int i = 0; i < nCount; ++i, pProps++ ) 4263 { 4264 *pProps = aPropertyVector[i]; 4265 } 4266 4267 return aRet; 4268 } 4269 4270 SwXTextTableStyle::SwXTextTableStyle(SwDocShell* pDocShell, SwTableAutoFormat* pTableAutoFormat) : 4271 m_pDocShell(pDocShell), m_pTableAutoFormat(pTableAutoFormat), m_bPhysical(true) 4272 { 4273 UpdateCellStylesMapping(); 4274 } 4275 4276 SwXTextTableStyle::SwXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName) : 4277 m_pDocShell(pDocShell), m_pTableAutoFormat_Impl(new SwTableAutoFormat(rTableAutoFormatName)), m_bPhysical(false) 4278 { 4279 m_pTableAutoFormat = m_pTableAutoFormat_Impl.get(); 4280 UpdateCellStylesMapping(); 4281 } 4282 4283 uno::Reference<style::XStyle> SwXTextTableStyle::CreateXTextTableStyle(SwDocShell* pDocShell, const OUString& rTableAutoFormatName) 4284 { 4285 SolarMutexGuard aGuard; 4286 uno::Reference<style::XStyle> xTextTableStyle; 4287 SwTableAutoFormat* pAutoFormat = GetTableAutoFormat(pDocShell, rTableAutoFormatName); 4288 if (pAutoFormat && pAutoFormat->GetName() == rTableAutoFormatName) 4289 { 4290 xTextTableStyle.set(pAutoFormat->GetXObject(), uno::UNO_QUERY); 4291 if (!xTextTableStyle.is()) 4292 { 4293 xTextTableStyle.set(new SwXTextTableStyle(pDocShell, pAutoFormat)); 4294 pAutoFormat->SetXObject(xTextTableStyle); 4295 } 4296 } 4297 4298 // If corresponding AutoFormat doesn't exist create a non physical style. 4299 if (!xTextTableStyle.is()) 4300 { 4301 xTextTableStyle.set(new SwXTextTableStyle(pDocShell, rTableAutoFormatName)); 4302 SAL_INFO("sw.uno", "creating SwXTextTableStyle for non existing SwTableAutoFormat"); 4303 } 4304 4305 return xTextTableStyle; 4306 } 4307 4308 void SwXTextTableStyle::UpdateCellStylesMapping() 4309 { 4310 const std::vector<sal_Int32> aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap(); 4311 assert(aTableTemplateMap.size() == STYLE_COUNT && "can not map SwTableAutoFormat to a SwXTextTableStyle"); 4312 for (sal_Int32 i=0; i<STYLE_COUNT; ++i) 4313 { 4314 SwBoxAutoFormat* pBoxFormat = &m_pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]); 4315 uno::Reference<style::XStyle> xCellStyle(pBoxFormat->GetXObject(), uno::UNO_QUERY); 4316 if (!xCellStyle.is()) 4317 { 4318 xCellStyle.set(new SwXTextCellStyle(m_pDocShell, pBoxFormat, m_pTableAutoFormat->GetName())); 4319 pBoxFormat->SetXObject(xCellStyle); 4320 } 4321 m_aCellStyles[i] = xCellStyle; 4322 } 4323 } 4324 4325 const CellStyleNameMap& SwXTextTableStyle::GetCellStyleNameMap() 4326 { 4327 static CellStyleNameMap const aMap 4328 { 4329 { "first-row" , FIRST_ROW_STYLE }, 4330 { "last-row" , LAST_ROW_STYLE }, 4331 { "first-column" , FIRST_COLUMN_STYLE }, 4332 { "last-column" , LAST_COLUMN_STYLE }, 4333 { "body" , BODY_STYLE }, 4334 { "even-rows" , EVEN_ROWS_STYLE }, 4335 { "odd-rows" , ODD_ROWS_STYLE }, 4336 { "even-columns" , EVEN_COLUMNS_STYLE }, 4337 { "odd-columns" , ODD_COLUMNS_STYLE }, 4338 { "background" , BACKGROUND_STYLE }, 4339 // loext namespace 4340 { "first-row-start-column" , FIRST_ROW_START_COLUMN_STYLE }, 4341 { "first-row-end-column" , FIRST_ROW_END_COLUMN_STYLE }, 4342 { "last-row-start-column" , LAST_ROW_START_COLUMN_STYLE }, 4343 { "last-row-end-column" , LAST_ROW_END_COLUMN_STYLE }, 4344 { "first-row-even-column" , FIRST_ROW_EVEN_COLUMN_STYLE }, 4345 { "last-row-even-column" , LAST_ROW_EVEN_COLUMN_STYLE }, 4346 }; 4347 return aMap; 4348 } 4349 4350 SwTableAutoFormat* SwXTextTableStyle::GetTableFormat() 4351 { 4352 return m_pTableAutoFormat; 4353 } 4354 4355 SwTableAutoFormat* SwXTextTableStyle::GetTableAutoFormat(SwDocShell* pDocShell, const OUString& sName) 4356 { 4357 const size_t nStyles = pDocShell->GetDoc()->GetTableStyles().size(); 4358 for(size_t i=0; i < nStyles; ++i) 4359 { 4360 SwTableAutoFormat* pAutoFormat = &pDocShell->GetDoc()->GetTableStyles()[i]; 4361 if (pAutoFormat->GetName() == sName) 4362 { 4363 return pAutoFormat; 4364 } 4365 } 4366 // not found 4367 return nullptr; 4368 } 4369 4370 void SwXTextTableStyle::SetPhysical() 4371 { 4372 if (!m_bPhysical) 4373 { 4374 // find table format in doc 4375 SwTableAutoFormat* pTableAutoFormat = GetTableAutoFormat(m_pDocShell, m_pTableAutoFormat->GetName()); 4376 if (pTableAutoFormat) 4377 { 4378 m_bPhysical = true; 4379 /// take care of children, make SwXTextCellStyles use new core SwBoxAutoFormats 4380 const std::vector<sal_Int32> aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap(); 4381 for (size_t i=0; i<aTableTemplateMap.size(); ++i) 4382 { 4383 SwBoxAutoFormat* pOldBoxFormat = &m_pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]); 4384 uno::Reference<style::XStyle> xCellStyle(pOldBoxFormat->GetXObject(), uno::UNO_QUERY); 4385 if (!xCellStyle.is()) 4386 continue; 4387 SwXTextCellStyle& rStyle = dynamic_cast<SwXTextCellStyle&>(*xCellStyle); 4388 SwBoxAutoFormat& rNewBoxFormat = pTableAutoFormat->GetBoxFormat(aTableTemplateMap[i]); 4389 rStyle.SetBoxFormat(&rNewBoxFormat); 4390 rNewBoxFormat.SetXObject(xCellStyle); 4391 } 4392 m_pTableAutoFormat_Impl = nullptr; 4393 m_pTableAutoFormat = pTableAutoFormat; 4394 m_pTableAutoFormat->SetXObject(uno::Reference<style::XStyle>(this)); 4395 } 4396 else 4397 SAL_WARN("sw.uno", "setting style physical, but SwTableAutoFormat in document not found"); 4398 } 4399 else 4400 SAL_WARN("sw.uno", "calling SetPhysical on a physical SwXTextTableStyle"); 4401 } 4402 4403 // XStyle 4404 sal_Bool SAL_CALL SwXTextTableStyle::isUserDefined() 4405 { 4406 SolarMutexGuard aGuard; 4407 // only first style is not user defined 4408 if (m_pDocShell->GetDoc()->GetTableStyles()[0].GetName() == m_pTableAutoFormat->GetName()) 4409 return false; 4410 4411 return true; 4412 } 4413 4414 sal_Bool SAL_CALL SwXTextTableStyle::isInUse() 4415 { 4416 SolarMutexGuard aGuard; 4417 if (!m_bPhysical) 4418 return false; 4419 4420 SwAutoFormatGetDocNode aGetHt( &m_pDocShell->GetDoc()->GetNodes() ); 4421 4422 for (SwFrameFormat* const & pFormat : *m_pDocShell->GetDoc()->GetTableFrameFormats()) 4423 { 4424 if (!pFormat->GetInfo(aGetHt)) 4425 { 4426 uno::Reference<text::XTextTable> xTable = SwXTextTables::GetObject(*pFormat); 4427 if (xTable.is()) 4428 { 4429 uno::Reference<beans::XPropertySet> xTablePropertySet(xTable, uno::UNO_QUERY); 4430 OUString sTableTemplateName; 4431 if (xTablePropertySet.is() && (xTablePropertySet->getPropertyValue("TableTemplateName") >>= sTableTemplateName) 4432 && sTableTemplateName == m_pTableAutoFormat->GetName()) 4433 { 4434 return true; 4435 } 4436 } 4437 } 4438 } 4439 4440 return false; 4441 } 4442 4443 OUString SAL_CALL SwXTextTableStyle::getParentStyle() 4444 { 4445 return OUString(); 4446 } 4447 4448 void SAL_CALL SwXTextTableStyle::setParentStyle(const OUString& /*aParentStyle*/) 4449 { } 4450 4451 //XNamed 4452 OUString SAL_CALL SwXTextTableStyle::getName() 4453 { 4454 SolarMutexGuard aGuard; 4455 OUString sProgName; 4456 SwStyleNameMapper::FillProgName(m_pTableAutoFormat->GetName(), sProgName, SwGetPoolIdFromName::TabStyle); 4457 return sProgName; 4458 } 4459 4460 void SAL_CALL SwXTextTableStyle::setName(const OUString& rName) 4461 { 4462 SolarMutexGuard aGuard; 4463 m_pTableAutoFormat->SetName(rName); 4464 } 4465 4466 //XPropertySet 4467 css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL SwXTextTableStyle::getPropertySetInfo() 4468 { 4469 static uno::Reference<beans::XPropertySetInfo> xRef(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_STYLE)->getPropertySetInfo()); 4470 return xRef; 4471 } 4472 4473 void SAL_CALL SwXTextTableStyle::setPropertyValue(const OUString& /*rPropertyName*/, const css::uno::Any& /*aValue*/) 4474 { 4475 SAL_WARN("sw.uno", "not implemented"); 4476 } 4477 4478 css::uno::Any SAL_CALL SwXTextTableStyle::getPropertyValue(const OUString& rPropertyName) 4479 { 4480 SolarMutexGuard aGuard; 4481 bool bIsRow = false; 4482 4483 if (rPropertyName == UNO_NAME_TABLE_FIRST_ROW_END_COLUMN) 4484 bIsRow = m_pTableAutoFormat->FirstRowEndColumnIsRow(); 4485 else if (rPropertyName == UNO_NAME_TABLE_FIRST_ROW_START_COLUMN) 4486 bIsRow = m_pTableAutoFormat->FirstRowStartColumnIsRow(); 4487 else if (rPropertyName == UNO_NAME_TABLE_LAST_ROW_END_COLUMN) 4488 bIsRow = m_pTableAutoFormat->LastRowEndColumnIsRow(); 4489 else if (rPropertyName == UNO_NAME_TABLE_LAST_ROW_START_COLUMN) 4490 bIsRow = m_pTableAutoFormat->LastRowStartColumnIsRow(); 4491 else if (rPropertyName == UNO_NAME_DISPLAY_NAME) 4492 return uno::makeAny(m_pTableAutoFormat->GetName()); 4493 else 4494 throw css::beans::UnknownPropertyException(); 4495 4496 return uno::makeAny(bIsRow ? OUString("row") : OUString("column")); 4497 } 4498 4499 void SAL_CALL SwXTextTableStyle::addPropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ ) 4500 { 4501 SAL_WARN("sw.uno", "not implemented"); 4502 } 4503 4504 void SAL_CALL SwXTextTableStyle::removePropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*aListener*/ ) 4505 { 4506 SAL_WARN("sw.uno", "not implemented"); 4507 } 4508 4509 void SAL_CALL SwXTextTableStyle::addVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ ) 4510 { 4511 SAL_WARN("sw.uno", "not implemented"); 4512 } 4513 4514 void SAL_CALL SwXTextTableStyle::removeVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ ) 4515 { 4516 SAL_WARN("sw.uno", "not implemented"); 4517 } 4518 4519 //XNameAccess 4520 uno::Any SAL_CALL SwXTextTableStyle::getByName(const OUString& rName) 4521 { 4522 SolarMutexGuard aGuard; 4523 const CellStyleNameMap& rMap = GetCellStyleNameMap(); 4524 CellStyleNameMap::const_iterator iter = rMap.find(rName); 4525 if(iter == rMap.end()) 4526 throw css::container::NoSuchElementException(); 4527 4528 return css::uno::Any(m_aCellStyles[(*iter).second]); 4529 } 4530 4531 css::uno::Sequence<OUString> SAL_CALL SwXTextTableStyle::getElementNames() 4532 { 4533 SolarMutexGuard aGuard; 4534 return comphelper::mapKeysToSequence(GetCellStyleNameMap()); 4535 } 4536 4537 sal_Bool SAL_CALL SwXTextTableStyle::hasByName(const OUString& rName) 4538 { 4539 SolarMutexGuard aGuard; 4540 const CellStyleNameMap& rMap = GetCellStyleNameMap(); 4541 CellStyleNameMap::const_iterator iter = rMap.find(rName); 4542 return iter != rMap.end(); 4543 } 4544 4545 //XNameContainer 4546 void SAL_CALL SwXTextTableStyle::insertByName(const OUString& /*Name*/, const uno::Any& /*Element*/) 4547 { 4548 SAL_WARN("sw.uno", "not implemented"); 4549 } 4550 4551 void SAL_CALL SwXTextTableStyle::replaceByName(const OUString& rName, const uno::Any& rElement) 4552 { 4553 SolarMutexGuard aGuard; 4554 const CellStyleNameMap& rMap = GetCellStyleNameMap(); 4555 CellStyleNameMap::const_iterator iter = rMap.find(rName); 4556 if(iter == rMap.end()) 4557 throw container::NoSuchElementException(); 4558 const sal_Int32 nCellStyle = iter->second; 4559 4560 uno::Reference<style::XStyle> xStyle = rElement.get<uno::Reference<style::XStyle>>(); 4561 if (!xStyle.is()) 4562 throw lang::IllegalArgumentException(); 4563 4564 SwXTextCellStyle* pStyleToReplaceWith = dynamic_cast<SwXTextCellStyle*>(xStyle.get()); 4565 if (!pStyleToReplaceWith) 4566 throw lang::IllegalArgumentException(); 4567 4568 // replace only with physical ... 4569 if (!pStyleToReplaceWith->IsPhysical()) 4570 throw lang::IllegalArgumentException(); 4571 4572 const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap(); 4573 const sal_Int32 nBoxFormat = rTableTemplateMap[nCellStyle]; 4574 4575 // move SwBoxAutoFormat to dest. SwTableAutoFormat 4576 m_pTableAutoFormat->SetBoxFormat(*pStyleToReplaceWith->GetBoxFormat(), nBoxFormat); 4577 // make SwXTextCellStyle use new, moved SwBoxAutoFormat 4578 pStyleToReplaceWith->SetBoxFormat(&m_pTableAutoFormat->GetBoxFormat(nBoxFormat)); 4579 m_pTableAutoFormat->GetBoxFormat(nBoxFormat).SetXObject(xStyle); 4580 // remove unassigned SwBoxAutoFormat, which is not anymore in use anyways 4581 m_pDocShell->GetDoc()->GetCellStyles().RemoveBoxFormat(xStyle->getName()); 4582 // make this SwXTextTableStyle use new SwXTextCellStyle 4583 m_aCellStyles[nCellStyle] = xStyle; 4584 } 4585 4586 void SAL_CALL SwXTextTableStyle::removeByName(const OUString& /*Name*/) 4587 { 4588 SAL_WARN("sw.uno", "not implemented"); 4589 } 4590 4591 //XElementAccess 4592 uno::Type SAL_CALL SAL_CALL SwXTextTableStyle::getElementType() 4593 { 4594 return cppu::UnoType<style::XStyle>::get(); 4595 } 4596 4597 sal_Bool SAL_CALL SAL_CALL SwXTextTableStyle::hasElements() 4598 { 4599 return true; 4600 } 4601 4602 //XServiceInfo 4603 OUString SAL_CALL SwXTextTableStyle::getImplementationName() 4604 { 4605 return {"SwXTextTableStyle"}; 4606 } 4607 4608 sal_Bool SAL_CALL SwXTextTableStyle::supportsService(const OUString& rServiceName) 4609 { 4610 return cppu::supportsService(this, rServiceName); 4611 } 4612 4613 css::uno::Sequence<OUString> SAL_CALL SwXTextTableStyle::getSupportedServiceNames() 4614 { 4615 return {"com.sun.star.style.Style"}; 4616 } 4617 4618 // SwXTextCellStyle 4619 SwXTextCellStyle::SwXTextCellStyle(SwDocShell* pDocShell, SwBoxAutoFormat* pBoxAutoFormat, const OUString& sParentStyle) : 4620 m_pDocShell(pDocShell), 4621 m_pBoxAutoFormat(pBoxAutoFormat), 4622 m_sParentStyle(sParentStyle), 4623 m_bPhysical(true) 4624 { } 4625 4626 SwXTextCellStyle::SwXTextCellStyle(SwDocShell* pDocShell, const OUString& sName) : 4627 m_pDocShell(pDocShell), 4628 m_pBoxAutoFormat_Impl(new SwBoxAutoFormat()), 4629 m_sName(sName), 4630 m_bPhysical(false) 4631 { 4632 m_pBoxAutoFormat = m_pBoxAutoFormat_Impl.get(); 4633 } 4634 4635 SwBoxAutoFormat* SwXTextCellStyle::GetBoxFormat() 4636 { 4637 return m_pBoxAutoFormat; 4638 } 4639 4640 void SwXTextCellStyle::SetBoxFormat(SwBoxAutoFormat* pBoxFormat) 4641 { 4642 if (m_bPhysical) 4643 m_pBoxAutoFormat = pBoxFormat; 4644 else 4645 SAL_INFO("sw.uno", "trying to call SwXTextCellStyle::SetBoxFormat on non physical style"); 4646 } 4647 4648 void SwXTextCellStyle::SetPhysical() 4649 { 4650 if (!m_bPhysical) 4651 { 4652 SwBoxAutoFormat* pBoxAutoFormat = GetBoxAutoFormat(m_pDocShell, m_sName, &m_sParentStyle); 4653 if (pBoxAutoFormat) 4654 { 4655 m_bPhysical = true; 4656 m_pBoxAutoFormat_Impl = nullptr; 4657 m_pBoxAutoFormat = pBoxAutoFormat; 4658 m_pBoxAutoFormat->SetXObject(uno::Reference<style::XStyle>(this)); 4659 } 4660 else 4661 SAL_WARN("sw.uno", "setting style physical, but SwBoxAutoFormat in document not found"); 4662 } 4663 else 4664 SAL_WARN("sw.uno", "calling SetPhysical on a physical SwXTextCellStyle"); 4665 } 4666 4667 bool SwXTextCellStyle::IsPhysical() 4668 { 4669 return m_bPhysical; 4670 } 4671 4672 SwBoxAutoFormat* SwXTextCellStyle::GetBoxAutoFormat(SwDocShell* pDocShell, const OUString& sName, OUString* pParentName) 4673 { 4674 if (sName.isEmpty()) 4675 return nullptr; 4676 4677 SwBoxAutoFormat* pBoxAutoFormat = pDocShell->GetDoc()->GetCellStyles().GetBoxFormat(sName); 4678 if (!pBoxAutoFormat) 4679 { 4680 sal_Int32 nSeparatorIndex, nTemplateIndex; 4681 OUString sParentName, sCellSubName; 4682 4683 nSeparatorIndex = sName.lastIndexOf('.'); 4684 if (0 >= nSeparatorIndex) 4685 return nullptr; 4686 4687 sParentName = sName.copy(0, nSeparatorIndex); 4688 sCellSubName = sName.copy(nSeparatorIndex+1); 4689 nTemplateIndex = sCellSubName.toInt32()-1; // -1 because cell styles names start from 1, but internally are indexed from 0 4690 if (0 > nTemplateIndex) 4691 return nullptr; 4692 4693 const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap(); 4694 if (rTableTemplateMap.size() <= static_cast<size_t>(nTemplateIndex)) 4695 return nullptr; 4696 4697 SwTableAutoFormat* pTableAutoFormat = pDocShell->GetDoc()->GetTableStyles().FindAutoFormat(sParentName); 4698 if (!pTableAutoFormat) 4699 return nullptr; 4700 4701 if (pParentName) 4702 *pParentName = sParentName; 4703 sal_uInt32 nBoxIndex = rTableTemplateMap[nTemplateIndex]; 4704 pBoxAutoFormat = &pTableAutoFormat->GetBoxFormat(nBoxIndex); 4705 } 4706 4707 return pBoxAutoFormat; 4708 } 4709 4710 css::uno::Reference<css::style::XStyle> SwXTextCellStyle::CreateXTextCellStyle(SwDocShell* pDocShell, const OUString& sName) 4711 { 4712 uno::Reference<style::XStyle> xTextCellStyle; 4713 4714 if (!sName.isEmpty()) // create a cell style for a physical box 4715 { 4716 OUString sParentName; 4717 SwBoxAutoFormat* pBoxFormat = GetBoxAutoFormat(pDocShell, sName, &sParentName); 4718 4719 // something went wrong but we don't want a crash 4720 if (!pBoxFormat) 4721 { 4722 // return a default-dummy style to prevent crash 4723 static SwBoxAutoFormat aDefaultBoxFormat; 4724 pBoxFormat = &aDefaultBoxFormat; 4725 } 4726 4727 xTextCellStyle.set(pBoxFormat->GetXObject(), uno::UNO_QUERY); 4728 if (!xTextCellStyle.is()) 4729 { 4730 xTextCellStyle.set(new SwXTextCellStyle(pDocShell, pBoxFormat, sParentName)); 4731 pBoxFormat->SetXObject(xTextCellStyle); 4732 } 4733 } 4734 else // create a non physical style 4735 xTextCellStyle.set(new SwXTextCellStyle(pDocShell, sName)); 4736 4737 return xTextCellStyle; 4738 } 4739 4740 // XStyle 4741 sal_Bool SAL_CALL SwXTextCellStyle::isUserDefined() 4742 { 4743 SolarMutexGuard aGuard; 4744 // if this cell belong to first table style then its default style 4745 if (&m_pDocShell->GetDoc()->GetTableStyles()[0] == m_pDocShell->GetDoc()->GetTableStyles().FindAutoFormat(m_sParentStyle)) 4746 return false; 4747 4748 return true; 4749 } 4750 4751 sal_Bool SAL_CALL SwXTextCellStyle::isInUse() 4752 { 4753 SolarMutexGuard aGuard; 4754 uno::Reference<style::XStyleFamiliesSupplier> xFamiliesSupplier(m_pDocShell->GetModel(), uno::UNO_QUERY); 4755 if (!xFamiliesSupplier.is()) 4756 return false; 4757 4758 uno::Reference<container::XNameAccess> xFamilies(xFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY); 4759 if (!xFamilies.is()) 4760 return false; 4761 4762 uno::Reference<container::XNameAccess> xTableStyles; 4763 xFamilies->getByName("TableStyles") >>= xTableStyles; 4764 if (!xTableStyles.is()) 4765 return false; 4766 4767 uno::Reference<style::XStyle> xStyle; 4768 xTableStyles->getByName(m_sParentStyle) >>= xStyle; 4769 if (!xStyle.is()) 4770 return false; 4771 4772 return xStyle->isInUse(); 4773 } 4774 4775 OUString SAL_CALL SwXTextCellStyle::getParentStyle() 4776 { 4777 // Do not return name of the parent (which is a table style) because the parent should be a cell style. 4778 return OUString(); 4779 } 4780 4781 void SAL_CALL SwXTextCellStyle::setParentStyle(const OUString& /*sParentStyle*/) 4782 { 4783 SolarMutexGuard aGuard; 4784 // Changing parent to one which is unaware of it will lead to a something unexpected. getName() rely on a parent. 4785 SAL_INFO("sw.uno", "Changing SwXTextCellStyle parent"); 4786 } 4787 4788 //XNamed 4789 OUString SAL_CALL SwXTextCellStyle::getName() 4790 { 4791 SolarMutexGuard aGuard; 4792 OUString sName; 4793 4794 // if style is physical then we request a name from doc 4795 if (m_bPhysical) 4796 { 4797 OUString sParentStyle; 4798 SwStyleNameMapper::FillUIName(m_sParentStyle, sParentStyle, SwGetPoolIdFromName::TabStyle); 4799 SwTableAutoFormat* pTableFormat = m_pDocShell->GetDoc()->GetTableStyles().FindAutoFormat(sParentStyle); 4800 if (!pTableFormat) 4801 { 4802 // if auto format is not found as a child of table formats, look in SwDoc cellstyles 4803 sName = m_pDocShell->GetDoc()->GetCellStyles().GetBoxFormatName(*m_pBoxAutoFormat); 4804 } 4805 else 4806 sName = sParentStyle + pTableFormat->GetTableTemplateCellSubName(*m_pBoxAutoFormat); 4807 } 4808 else 4809 sName = m_sName; 4810 4811 return sName; 4812 } 4813 4814 void SAL_CALL SwXTextCellStyle::setName(const OUString& sName) 4815 { 4816 SolarMutexGuard aGuard; 4817 // if style is physical then we can not rename it. 4818 if (!m_bPhysical) 4819 m_sName = sName; 4820 // change name if style is unassigned (name is not generated automatically) 4821 m_pDocShell->GetDoc()->GetCellStyles().ChangeBoxFormatName(getName(), sName); 4822 } 4823 4824 //XPropertySet 4825 css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL SwXTextCellStyle::getPropertySetInfo() 4826 { 4827 static uno::Reference<beans::XPropertySetInfo> xRef(aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertySetInfo()); 4828 return xRef; 4829 } 4830 4831 void SAL_CALL SwXTextCellStyle::setPropertyValue(const OUString& rPropertyName, const css::uno::Any& aValue) 4832 { 4833 SolarMutexGuard aGuard; 4834 const SfxItemPropertySimpleEntry *const pEntry = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertyMap().getByName(rPropertyName); 4835 if(pEntry) 4836 { 4837 switch(pEntry->nWID) 4838 { 4839 case RES_BACKGROUND: 4840 { 4841 SvxBrushItem rBrush = m_pBoxAutoFormat->GetBackground(); 4842 rBrush.PutValue(aValue, 0); 4843 m_pBoxAutoFormat->SetBackground(rBrush); 4844 return; 4845 } 4846 case RES_BOX: 4847 { 4848 SvxBoxItem rBox = m_pBoxAutoFormat->GetBox(); 4849 rBox.PutValue(aValue, pEntry->nMemberId); 4850 m_pBoxAutoFormat->SetBox(rBox); 4851 return; 4852 } 4853 case RES_VERT_ORIENT: 4854 { 4855 SwFormatVertOrient rVertOrient = m_pBoxAutoFormat->GetVerticalAlignment(); 4856 rVertOrient.PutValue(aValue, pEntry->nMemberId); 4857 m_pBoxAutoFormat->SetVerticalAlignment(rVertOrient); 4858 return; 4859 } 4860 case RES_FRAMEDIR: 4861 { 4862 SvxFrameDirectionItem rDirItem = m_pBoxAutoFormat->GetTextOrientation(); 4863 rDirItem.PutValue(aValue, pEntry->nMemberId); 4864 m_pBoxAutoFormat->SetTextOrientation(rDirItem); 4865 return; 4866 } 4867 case RES_BOXATR_FORMAT: 4868 { 4869 sal_uInt32 nKey; 4870 if (aValue >>= nKey) 4871 { 4872 // FIXME: It's not working for old "automatic" currency formats, which are still in use by autotbl.fmt. 4873 // Scenario: 4874 // 1) Mark all styles present by default in autotbl.fmt as default. 4875 // 2) convert all currencies present in autotbl.fmt before calling this code 4876 const SvNumberformat* pNumFormat = m_pDocShell->GetDoc()->GetNumberFormatter()->GetEntry(nKey); 4877 if (pNumFormat) 4878 m_pBoxAutoFormat->SetValueFormat(pNumFormat->GetFormatstring(), pNumFormat->GetLanguage(), GetAppLanguage()); 4879 } 4880 return; 4881 } 4882 // Paragraph attributes 4883 case RES_PARATR_ADJUST: 4884 { 4885 SvxAdjustItem rAdjustItem = m_pBoxAutoFormat->GetAdjust(); 4886 rAdjustItem.PutValue(aValue, pEntry->nMemberId); 4887 m_pBoxAutoFormat->SetAdjust(rAdjustItem); 4888 return; 4889 } 4890 case RES_CHRATR_COLOR: 4891 { 4892 SvxColorItem rColorItem = m_pBoxAutoFormat->GetColor(); 4893 rColorItem.PutValue(aValue, pEntry->nMemberId); 4894 m_pBoxAutoFormat->SetColor(rColorItem); 4895 return; 4896 } 4897 case RES_CHRATR_SHADOWED: 4898 { 4899 SvxShadowedItem rShadowedItem = m_pBoxAutoFormat->GetShadowed(); 4900 bool bValue = false; aValue >>= bValue; 4901 rShadowedItem.SetValue(bValue); 4902 m_pBoxAutoFormat->SetShadowed(rShadowedItem); 4903 return; 4904 } 4905 case RES_CHRATR_CONTOUR: 4906 { 4907 SvxContourItem rContourItem = m_pBoxAutoFormat->GetContour(); 4908 bool bValue = false; aValue >>= bValue; 4909 rContourItem.SetValue(bValue); 4910 m_pBoxAutoFormat->SetContour(rContourItem); 4911 return; 4912 } 4913 case RES_CHRATR_CROSSEDOUT: 4914 { 4915 SvxCrossedOutItem rCrossedOutItem = m_pBoxAutoFormat->GetCrossedOut(); 4916 rCrossedOutItem.PutValue(aValue, pEntry->nMemberId); 4917 m_pBoxAutoFormat->SetCrossedOut(rCrossedOutItem); 4918 return; 4919 } 4920 case RES_CHRATR_UNDERLINE: 4921 { 4922 SvxUnderlineItem rUnderlineItem = m_pBoxAutoFormat->GetUnderline(); 4923 rUnderlineItem.PutValue(aValue, pEntry->nMemberId); 4924 m_pBoxAutoFormat->SetUnderline(rUnderlineItem); 4925 return; 4926 } 4927 case RES_CHRATR_FONTSIZE: 4928 { 4929 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetHeight(); 4930 rFontHeightItem.PutValue(aValue, pEntry->nMemberId); 4931 m_pBoxAutoFormat->SetHeight(rFontHeightItem); 4932 return; 4933 } 4934 case RES_CHRATR_WEIGHT: 4935 { 4936 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetWeight(); 4937 rWeightItem.PutValue(aValue, pEntry->nMemberId); 4938 m_pBoxAutoFormat->SetWeight(rWeightItem); 4939 return; 4940 } 4941 case RES_CHRATR_POSTURE: 4942 { 4943 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetPosture(); 4944 rPostureItem.PutValue(aValue, pEntry->nMemberId); 4945 m_pBoxAutoFormat->SetPosture(rPostureItem); 4946 return; 4947 } 4948 case RES_CHRATR_FONT: 4949 { 4950 SvxFontItem rFontItem = m_pBoxAutoFormat->GetFont(); 4951 rFontItem.PutValue(aValue, pEntry->nMemberId); 4952 m_pBoxAutoFormat->SetFont(rFontItem); 4953 return; 4954 } 4955 case RES_CHRATR_CJK_FONTSIZE: 4956 { 4957 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCJKHeight(); 4958 rFontHeightItem.PutValue(aValue, pEntry->nMemberId); 4959 m_pBoxAutoFormat->SetCJKHeight(rFontHeightItem); 4960 return; 4961 } 4962 case RES_CHRATR_CJK_WEIGHT: 4963 { 4964 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetCJKWeight(); 4965 rWeightItem.PutValue(aValue, pEntry->nMemberId); 4966 m_pBoxAutoFormat->SetCJKWeight(rWeightItem); 4967 return; 4968 } 4969 case RES_CHRATR_CJK_POSTURE: 4970 { 4971 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetCJKPosture(); 4972 rPostureItem.PutValue(aValue, pEntry->nMemberId); 4973 m_pBoxAutoFormat->SetCJKPosture(rPostureItem); 4974 return; 4975 } 4976 case RES_CHRATR_CJK_FONT: 4977 { 4978 SvxFontItem rFontItem = m_pBoxAutoFormat->GetCJKFont(); 4979 rFontItem.PutValue(aValue, pEntry->nMemberId); 4980 m_pBoxAutoFormat->SetCJKFont(rFontItem); 4981 return; 4982 } 4983 case RES_CHRATR_CTL_FONTSIZE: 4984 { 4985 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCTLHeight(); 4986 rFontHeightItem.PutValue(aValue, pEntry->nMemberId); 4987 m_pBoxAutoFormat->SetCTLHeight(rFontHeightItem); 4988 return; 4989 } 4990 case RES_CHRATR_CTL_WEIGHT: 4991 { 4992 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetCTLWeight(); 4993 rWeightItem.PutValue(aValue, pEntry->nMemberId); 4994 m_pBoxAutoFormat->SetCTLWeight(rWeightItem); 4995 return; 4996 } 4997 case RES_CHRATR_CTL_POSTURE: 4998 { 4999 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetCTLPosture(); 5000 rPostureItem.PutValue(aValue, pEntry->nMemberId); 5001 m_pBoxAutoFormat->SetCTLPosture(rPostureItem); 5002 return; 5003 } 5004 case RES_CHRATR_CTL_FONT: 5005 { 5006 SvxFontItem rFontItem = m_pBoxAutoFormat->GetCTLFont(); 5007 rFontItem.PutValue(aValue, pEntry->nMemberId); 5008 m_pBoxAutoFormat->SetCTLFont(rFontItem); 5009 return; 5010 } 5011 default: 5012 SAL_WARN("sw.uno", "SwXTextCellStyle unknown nWID"); 5013 throw css::uno::RuntimeException(); 5014 } 5015 } 5016 5017 throw css::beans::UnknownPropertyException(); 5018 } 5019 5020 css::uno::Any SAL_CALL SwXTextCellStyle::getPropertyValue(const OUString& rPropertyName) 5021 { 5022 SolarMutexGuard aGuard; 5023 uno::Any aRet; 5024 const SfxItemPropertySimpleEntry *const pEntry = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertyMap().getByName(rPropertyName); 5025 if(pEntry) 5026 { 5027 switch(pEntry->nWID) 5028 { 5029 case RES_BACKGROUND: 5030 { 5031 const SvxBrushItem& rBrush = m_pBoxAutoFormat->GetBackground(); 5032 rBrush.QueryValue(aRet); 5033 return aRet; 5034 } 5035 case RES_BOX: 5036 { 5037 const SvxBoxItem& rBox = m_pBoxAutoFormat->GetBox(); 5038 rBox.QueryValue(aRet, pEntry->nMemberId); 5039 return aRet; 5040 } 5041 case RES_VERT_ORIENT: 5042 { 5043 const SwFormatVertOrient& rVertOrient = m_pBoxAutoFormat->GetVerticalAlignment(); 5044 rVertOrient.QueryValue(aRet, pEntry->nMemberId); 5045 return aRet; 5046 } 5047 case RES_FRAMEDIR: 5048 { 5049 const SvxFrameDirectionItem& rDirItem = m_pBoxAutoFormat->GetTextOrientation(); 5050 rDirItem.QueryValue(aRet, pEntry->nMemberId); 5051 return aRet; 5052 } 5053 case RES_BOXATR_FORMAT: 5054 { 5055 OUString sFormat; 5056 LanguageType eLng, eSys; 5057 m_pBoxAutoFormat->GetValueFormat(sFormat, eLng, eSys); 5058 if(!sFormat.isEmpty()) 5059 { 5060 SvNumFormatType nType; bool bNew; sal_Int32 nCheckPos; 5061 sal_uInt32 nKey = m_pDocShell->GetDoc()->GetNumberFormatter()->GetIndexPuttingAndConverting(sFormat, eLng, eSys, nType, bNew, nCheckPos); 5062 aRet <<= nKey; 5063 } 5064 return aRet; 5065 } 5066 // Paragraph attributes 5067 case RES_PARATR_ADJUST: 5068 { 5069 const SvxAdjustItem& rAdjustItem = m_pBoxAutoFormat->GetAdjust(); 5070 rAdjustItem.QueryValue(aRet, pEntry->nMemberId); 5071 return aRet; 5072 } 5073 case RES_CHRATR_COLOR: 5074 { 5075 const SvxColorItem& rColorItem = m_pBoxAutoFormat->GetColor(); 5076 rColorItem.QueryValue(aRet, pEntry->nMemberId); 5077 return aRet; 5078 } 5079 case RES_CHRATR_SHADOWED: 5080 { 5081 const SvxShadowedItem& rShadowedItem = m_pBoxAutoFormat->GetShadowed(); 5082 aRet <<= rShadowedItem.GetValue(); 5083 return aRet; 5084 } 5085 case RES_CHRATR_CONTOUR: 5086 { 5087 const SvxContourItem& rContourItem = m_pBoxAutoFormat->GetContour(); 5088 aRet <<= rContourItem.GetValue(); 5089 return aRet; 5090 } 5091 case RES_CHRATR_CROSSEDOUT: 5092 { 5093 const SvxCrossedOutItem& rCrossedOutItem = m_pBoxAutoFormat->GetCrossedOut(); 5094 rCrossedOutItem.QueryValue(aRet, pEntry->nMemberId); 5095 return aRet; 5096 } 5097 case RES_CHRATR_UNDERLINE: 5098 { 5099 const SvxUnderlineItem& rUnderlineItem = m_pBoxAutoFormat->GetUnderline(); 5100 rUnderlineItem.QueryValue(aRet, pEntry->nMemberId); 5101 return aRet; 5102 } 5103 case RES_CHRATR_FONTSIZE: 5104 { 5105 const SvxFontHeightItem& rFontHeightItem = m_pBoxAutoFormat->GetHeight(); 5106 rFontHeightItem.QueryValue(aRet, pEntry->nMemberId); 5107 return aRet; 5108 } 5109 case RES_CHRATR_WEIGHT: 5110 { 5111 const SvxWeightItem& rWeightItem = m_pBoxAutoFormat->GetWeight(); 5112 rWeightItem.QueryValue(aRet, pEntry->nMemberId); 5113 return aRet; 5114 } 5115 case RES_CHRATR_POSTURE: 5116 { 5117 const SvxPostureItem& rPostureItem = m_pBoxAutoFormat->GetPosture(); 5118 rPostureItem.QueryValue(aRet, pEntry->nMemberId); 5119 return aRet; 5120 } 5121 case RES_CHRATR_FONT: 5122 { 5123 const SvxFontItem rFontItem = m_pBoxAutoFormat->GetFont(); 5124 rFontItem.QueryValue(aRet, pEntry->nMemberId); 5125 return aRet; 5126 } 5127 case RES_CHRATR_CJK_FONTSIZE: 5128 { 5129 const SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCJKHeight(); 5130 rFontHeightItem.QueryValue(aRet, pEntry->nMemberId); 5131 return aRet; 5132 } 5133 case RES_CHRATR_CJK_WEIGHT: 5134 { 5135 const SvxWeightItem& rWeightItem = m_pBoxAutoFormat->GetCJKWeight(); 5136 rWeightItem.QueryValue(aRet, pEntry->nMemberId); 5137 return aRet; 5138 } 5139 case RES_CHRATR_CJK_POSTURE: 5140 { 5141 const SvxPostureItem& rPostureItem = m_pBoxAutoFormat->GetCJKPosture(); 5142 rPostureItem.QueryValue(aRet, pEntry->nMemberId); 5143 return aRet; 5144 } 5145 case RES_CHRATR_CJK_FONT: 5146 { 5147 const SvxFontItem rFontItem = m_pBoxAutoFormat->GetCJKFont(); 5148 rFontItem.QueryValue(aRet, pEntry->nMemberId); 5149 return aRet; 5150 } 5151 case RES_CHRATR_CTL_FONTSIZE: 5152 { 5153 const SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCTLHeight(); 5154 rFontHeightItem.QueryValue(aRet, pEntry->nMemberId); 5155 return aRet; 5156 } 5157 case RES_CHRATR_CTL_WEIGHT: 5158 { 5159 const SvxWeightItem& rWeightItem = m_pBoxAutoFormat->GetCTLWeight(); 5160 rWeightItem.QueryValue(aRet, pEntry->nMemberId); 5161 return aRet; 5162 } 5163 case RES_CHRATR_CTL_POSTURE: 5164 { 5165 const SvxPostureItem& rPostureItem = m_pBoxAutoFormat->GetCTLPosture(); 5166 rPostureItem.QueryValue(aRet, pEntry->nMemberId); 5167 return aRet; 5168 } 5169 case RES_CHRATR_CTL_FONT: 5170 { 5171 const SvxFontItem rFontItem = m_pBoxAutoFormat->GetCTLFont(); 5172 rFontItem.QueryValue(aRet, pEntry->nMemberId); 5173 return aRet; 5174 } 5175 default: 5176 SAL_WARN("sw.uno", "SwXTextCellStyle unknown nWID"); 5177 throw css::uno::RuntimeException(); 5178 } 5179 } 5180 5181 throw css::beans::UnknownPropertyException(); 5182 } 5183 5184 void SAL_CALL SwXTextCellStyle::addPropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ ) 5185 { 5186 SAL_WARN("sw.uno", "not implemented"); 5187 } 5188 5189 void SAL_CALL SwXTextCellStyle::removePropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*aListener*/ ) 5190 { 5191 SAL_WARN("sw.uno", "not implemented"); 5192 } 5193 5194 void SAL_CALL SwXTextCellStyle::addVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ ) 5195 { 5196 SAL_WARN("sw.uno", "not implemented"); 5197 } 5198 5199 void SAL_CALL SwXTextCellStyle::removeVetoableChangeListener( const OUString& /*PropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*aListener*/ ) 5200 { 5201 SAL_WARN("sw.uno", "not implemented"); 5202 } 5203 5204 //XPropertyState 5205 css::beans::PropertyState SAL_CALL SwXTextCellStyle::getPropertyState(const OUString& rPropertyName) 5206 { 5207 SolarMutexGuard aGuard; 5208 uno::Sequence<OUString> aNames { rPropertyName }; 5209 uno::Sequence<beans::PropertyState> aStates = getPropertyStates(aNames); 5210 return aStates.getConstArray()[0]; 5211 } 5212 5213 css::uno::Sequence<css::beans::PropertyState> SAL_CALL SwXTextCellStyle::getPropertyStates(const css::uno::Sequence<OUString>& aPropertyNames) 5214 { 5215 SolarMutexGuard aGuard; 5216 uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength()); 5217 beans::PropertyState* pStates = aRet.getArray(); 5218 const SwBoxAutoFormat& rDefaultBoxFormat = SwTableAutoFormat::GetDefaultBoxFormat(); 5219 const SfxItemPropertyMap& rMap = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertyMap(); 5220 const OUString* pNames = aPropertyNames.getConstArray(); 5221 for(sal_Int32 i=0; i < aPropertyNames.getLength(); ++i) 5222 { 5223 const OUString sPropName = pNames[i]; 5224 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(sPropName); 5225 if(pEntry) 5226 { 5227 uno::Any aAny1, aAny2; 5228 switch(pEntry->nWID) 5229 { 5230 case RES_BACKGROUND: 5231 m_pBoxAutoFormat->GetBackground().QueryValue(aAny1, pEntry->nMemberId); 5232 rDefaultBoxFormat.GetBackground().QueryValue(aAny2, pEntry->nMemberId); 5233 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5234 break; 5235 case RES_BOX: 5236 m_pBoxAutoFormat->GetBox().QueryValue(aAny1, pEntry->nMemberId); 5237 rDefaultBoxFormat.GetBox().QueryValue(aAny2, pEntry->nMemberId); 5238 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5239 break; 5240 case RES_VERT_ORIENT: 5241 m_pBoxAutoFormat->GetVerticalAlignment().QueryValue(aAny1, pEntry->nMemberId); 5242 rDefaultBoxFormat.GetVerticalAlignment().QueryValue(aAny2, pEntry->nMemberId); 5243 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5244 break; 5245 case RES_FRAMEDIR: 5246 m_pBoxAutoFormat->GetTextOrientation().QueryValue(aAny1, pEntry->nMemberId); 5247 rDefaultBoxFormat.GetTextOrientation().QueryValue(aAny2, pEntry->nMemberId); 5248 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5249 break; 5250 case RES_BOXATR_FORMAT: 5251 { 5252 OUString sFormat; 5253 LanguageType eLng, eSys; 5254 m_pBoxAutoFormat->GetValueFormat(sFormat, eLng, eSys); 5255 pStates[i] = sFormat.isEmpty() ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5256 break; 5257 } 5258 case RES_PARATR_ADJUST: 5259 m_pBoxAutoFormat->GetAdjust().QueryValue(aAny1, pEntry->nMemberId); 5260 rDefaultBoxFormat.GetAdjust().QueryValue(aAny2, pEntry->nMemberId); 5261 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5262 break; 5263 case RES_CHRATR_COLOR: 5264 m_pBoxAutoFormat->GetColor().QueryValue(aAny1, pEntry->nMemberId); 5265 rDefaultBoxFormat.GetColor().QueryValue(aAny2, pEntry->nMemberId); 5266 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5267 break; 5268 case RES_CHRATR_SHADOWED: 5269 m_pBoxAutoFormat->GetShadowed().QueryValue(aAny1, pEntry->nMemberId); 5270 rDefaultBoxFormat.GetShadowed().QueryValue(aAny2, pEntry->nMemberId); 5271 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5272 break; 5273 case RES_CHRATR_CONTOUR: 5274 m_pBoxAutoFormat->GetContour().QueryValue(aAny1, pEntry->nMemberId); 5275 rDefaultBoxFormat.GetContour().QueryValue(aAny2, pEntry->nMemberId); 5276 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5277 break; 5278 case RES_CHRATR_CROSSEDOUT: 5279 m_pBoxAutoFormat->GetCrossedOut().QueryValue(aAny1, pEntry->nMemberId); 5280 rDefaultBoxFormat.GetCrossedOut().QueryValue(aAny2, pEntry->nMemberId); 5281 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5282 break; 5283 case RES_CHRATR_UNDERLINE: 5284 m_pBoxAutoFormat->GetUnderline().QueryValue(aAny1, pEntry->nMemberId); 5285 rDefaultBoxFormat.GetUnderline().QueryValue(aAny2, pEntry->nMemberId); 5286 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5287 break; 5288 case RES_CHRATR_FONTSIZE: 5289 m_pBoxAutoFormat->GetHeight().QueryValue(aAny1, pEntry->nMemberId); 5290 rDefaultBoxFormat.GetHeight().QueryValue(aAny2, pEntry->nMemberId); 5291 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5292 break; 5293 case RES_CHRATR_WEIGHT: 5294 m_pBoxAutoFormat->GetWeight().QueryValue(aAny1, pEntry->nMemberId); 5295 rDefaultBoxFormat.GetWeight().QueryValue(aAny2, pEntry->nMemberId); 5296 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5297 break; 5298 case RES_CHRATR_POSTURE: 5299 m_pBoxAutoFormat->GetPosture().QueryValue(aAny1, pEntry->nMemberId); 5300 rDefaultBoxFormat.GetPosture().QueryValue(aAny2, pEntry->nMemberId); 5301 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5302 break; 5303 case RES_CHRATR_FONT: 5304 m_pBoxAutoFormat->GetFont().QueryValue(aAny1, pEntry->nMemberId); 5305 rDefaultBoxFormat.GetFont().QueryValue(aAny2, pEntry->nMemberId); 5306 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5307 break; 5308 case RES_CHRATR_CJK_FONTSIZE: 5309 m_pBoxAutoFormat->GetCJKHeight().QueryValue(aAny1, pEntry->nMemberId); 5310 rDefaultBoxFormat.GetCJKHeight().QueryValue(aAny2, pEntry->nMemberId); 5311 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5312 break; 5313 case RES_CHRATR_CJK_WEIGHT: 5314 m_pBoxAutoFormat->GetCJKWeight().QueryValue(aAny1, pEntry->nMemberId); 5315 rDefaultBoxFormat.GetCJKWeight().QueryValue(aAny2, pEntry->nMemberId); 5316 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5317 break; 5318 case RES_CHRATR_CJK_POSTURE: 5319 m_pBoxAutoFormat->GetCJKPosture().QueryValue(aAny1, pEntry->nMemberId); 5320 rDefaultBoxFormat.GetCJKPosture().QueryValue(aAny2, pEntry->nMemberId); 5321 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5322 break; 5323 case RES_CHRATR_CJK_FONT: 5324 m_pBoxAutoFormat->GetCJKFont().QueryValue(aAny1, pEntry->nMemberId); 5325 rDefaultBoxFormat.GetCJKFont().QueryValue(aAny2, pEntry->nMemberId); 5326 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5327 break; 5328 case RES_CHRATR_CTL_FONTSIZE: 5329 m_pBoxAutoFormat->GetCTLHeight().QueryValue(aAny1, pEntry->nMemberId); 5330 rDefaultBoxFormat.GetCTLHeight().QueryValue(aAny2, pEntry->nMemberId); 5331 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5332 break; 5333 case RES_CHRATR_CTL_WEIGHT: 5334 m_pBoxAutoFormat->GetCTLWeight().QueryValue(aAny1, pEntry->nMemberId); 5335 rDefaultBoxFormat.GetCTLWeight().QueryValue(aAny2, pEntry->nMemberId); 5336 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5337 break; 5338 case RES_CHRATR_CTL_POSTURE: 5339 m_pBoxAutoFormat->GetCTLPosture().QueryValue(aAny1, pEntry->nMemberId); 5340 rDefaultBoxFormat.GetCTLPosture().QueryValue(aAny2, pEntry->nMemberId); 5341 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5342 break; 5343 case RES_CHRATR_CTL_FONT: 5344 m_pBoxAutoFormat->GetCTLFont().QueryValue(aAny1, pEntry->nMemberId); 5345 rDefaultBoxFormat.GetCTLFont().QueryValue(aAny2, pEntry->nMemberId); 5346 pStates[i] = aAny1 == aAny2 ? beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; 5347 break; 5348 default: 5349 // fallthrough to DIRECT_VALUE, to export properties for which getPropertyStates is not implemented 5350 pStates[i] = beans::PropertyState_DIRECT_VALUE; 5351 SAL_WARN("sw.uno", "SwXTextCellStyle getPropertyStates unknown nWID"); 5352 } 5353 } 5354 else 5355 { 5356 SAL_WARN("sw.uno", "SwXTextCellStyle unknown property:" + sPropName); 5357 throw css::beans::UnknownPropertyException(); 5358 } 5359 } 5360 return aRet; 5361 } 5362 5363 void SAL_CALL SwXTextCellStyle::setPropertyToDefault(const OUString& rPropertyName) 5364 { 5365 SolarMutexGuard aGuard; 5366 const SwBoxAutoFormat& rDefaultBoxFormat = SwTableAutoFormat::GetDefaultBoxFormat(); 5367 const SfxItemPropertyMap& rMap = aSwMapProvider.GetPropertySet(PROPERTY_MAP_CELL_STYLE)->getPropertyMap(); 5368 const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(rPropertyName); 5369 if(pEntry) 5370 { 5371 uno::Any aAny; 5372 switch(pEntry->nWID) 5373 { 5374 case RES_BACKGROUND: 5375 { 5376 SvxBrushItem rBrush = m_pBoxAutoFormat->GetBackground(); 5377 rDefaultBoxFormat.GetBackground().QueryValue(aAny, pEntry->nMemberId); 5378 rBrush.PutValue(aAny, pEntry->nMemberId); 5379 m_pBoxAutoFormat->SetBackground(rBrush); 5380 break; 5381 } 5382 case RES_BOX: 5383 { 5384 SvxBoxItem rBox = m_pBoxAutoFormat->GetBox(); 5385 rDefaultBoxFormat.GetBox().QueryValue(aAny, pEntry->nMemberId); 5386 rBox.PutValue(aAny, pEntry->nMemberId); 5387 m_pBoxAutoFormat->SetBox(rBox); 5388 break; 5389 } 5390 case RES_VERT_ORIENT: 5391 { 5392 SwFormatVertOrient rVertOrient = m_pBoxAutoFormat->GetVerticalAlignment(); 5393 rDefaultBoxFormat.GetVerticalAlignment().QueryValue(aAny, pEntry->nMemberId); 5394 rVertOrient.PutValue(aAny, pEntry->nMemberId); 5395 m_pBoxAutoFormat->SetVerticalAlignment(rVertOrient); 5396 break; 5397 } 5398 case RES_FRAMEDIR: 5399 { 5400 SvxFrameDirectionItem rFrameDirectionItem = m_pBoxAutoFormat->GetTextOrientation(); 5401 rDefaultBoxFormat.GetTextOrientation().QueryValue(aAny, pEntry->nMemberId); 5402 rFrameDirectionItem.PutValue(aAny, pEntry->nMemberId); 5403 m_pBoxAutoFormat->SetTextOrientation(rFrameDirectionItem); 5404 break; 5405 } 5406 case RES_BOXATR_FORMAT: 5407 { 5408 OUString sFormat; 5409 LanguageType eLng, eSys; 5410 rDefaultBoxFormat.GetValueFormat(sFormat, eLng, eSys); 5411 m_pBoxAutoFormat->SetValueFormat(sFormat, eLng, eSys); 5412 break; 5413 } 5414 case RES_PARATR_ADJUST: 5415 { 5416 SvxAdjustItem rAdjustItem = m_pBoxAutoFormat->GetAdjust(); 5417 rDefaultBoxFormat.GetAdjust().QueryValue(aAny, pEntry->nMemberId); 5418 rAdjustItem.PutValue(aAny, pEntry->nMemberId); 5419 m_pBoxAutoFormat->SetAdjust(rAdjustItem); 5420 break; 5421 } 5422 case RES_CHRATR_COLOR: 5423 { 5424 SvxColorItem rColorItem = m_pBoxAutoFormat->GetColor(); 5425 rDefaultBoxFormat.GetColor().QueryValue(aAny, pEntry->nMemberId); 5426 rColorItem.PutValue(aAny, pEntry->nMemberId); 5427 m_pBoxAutoFormat->SetColor(rColorItem); 5428 break; 5429 } 5430 case RES_CHRATR_SHADOWED: 5431 { 5432 SvxShadowedItem rShadowedItem = m_pBoxAutoFormat->GetShadowed(); 5433 rDefaultBoxFormat.GetShadowed().QueryValue(aAny, pEntry->nMemberId); 5434 rShadowedItem.PutValue(aAny, pEntry->nMemberId); 5435 m_pBoxAutoFormat->SetShadowed(rShadowedItem); 5436 break; 5437 } 5438 case RES_CHRATR_CONTOUR: 5439 { 5440 SvxContourItem rContourItem = m_pBoxAutoFormat->GetContour(); 5441 rDefaultBoxFormat.GetContour().QueryValue(aAny, pEntry->nMemberId); 5442 rContourItem.PutValue(aAny, pEntry->nMemberId); 5443 m_pBoxAutoFormat->SetContour(rContourItem); 5444 break; 5445 } 5446 case RES_CHRATR_CROSSEDOUT: 5447 { 5448 SvxCrossedOutItem rCrossedOutItem = m_pBoxAutoFormat->GetCrossedOut(); 5449 rDefaultBoxFormat.GetCrossedOut().QueryValue(aAny, pEntry->nMemberId); 5450 rCrossedOutItem.PutValue(aAny, pEntry->nMemberId); 5451 m_pBoxAutoFormat->SetCrossedOut(rCrossedOutItem); 5452 break; 5453 } 5454 case RES_CHRATR_UNDERLINE: 5455 { 5456 SvxUnderlineItem rUnderlineItem = m_pBoxAutoFormat->GetUnderline(); 5457 rDefaultBoxFormat.GetUnderline().QueryValue(aAny, pEntry->nMemberId); 5458 rUnderlineItem.PutValue(aAny, pEntry->nMemberId); 5459 m_pBoxAutoFormat->SetUnderline(rUnderlineItem); 5460 break; 5461 } 5462 case RES_CHRATR_FONTSIZE: 5463 { 5464 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetHeight(); 5465 rDefaultBoxFormat.GetHeight().QueryValue(aAny, pEntry->nMemberId); 5466 rFontHeightItem.PutValue(aAny, pEntry->nMemberId); 5467 m_pBoxAutoFormat->SetHeight(rFontHeightItem); 5468 break; 5469 } 5470 case RES_CHRATR_WEIGHT: 5471 { 5472 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetWeight(); 5473 rDefaultBoxFormat.GetWeight().QueryValue(aAny, pEntry->nMemberId); 5474 rWeightItem.PutValue(aAny, pEntry->nMemberId); 5475 m_pBoxAutoFormat->SetWeight(rWeightItem); 5476 break; 5477 } 5478 case RES_CHRATR_POSTURE: 5479 { 5480 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetPosture(); 5481 rDefaultBoxFormat.GetPosture().QueryValue(aAny, pEntry->nMemberId); 5482 rPostureItem.PutValue(aAny, pEntry->nMemberId); 5483 m_pBoxAutoFormat->SetPosture(rPostureItem); 5484 break; 5485 } 5486 case RES_CHRATR_FONT: 5487 { 5488 SvxFontItem rFontItem = m_pBoxAutoFormat->GetFont(); 5489 rDefaultBoxFormat.GetFont().QueryValue(aAny, pEntry->nMemberId); 5490 rFontItem.PutValue(aAny, pEntry->nMemberId); 5491 m_pBoxAutoFormat->SetFont(rFontItem); 5492 break; 5493 } 5494 case RES_CHRATR_CJK_FONTSIZE: 5495 { 5496 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCJKHeight(); 5497 rDefaultBoxFormat.GetCJKHeight().QueryValue(aAny, pEntry->nMemberId); 5498 rFontHeightItem.PutValue(aAny, pEntry->nMemberId); 5499 m_pBoxAutoFormat->SetCJKHeight(rFontHeightItem); 5500 break; 5501 } 5502 case RES_CHRATR_CJK_WEIGHT: 5503 { 5504 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetCJKWeight(); 5505 rDefaultBoxFormat.GetCJKWeight().QueryValue(aAny, pEntry->nMemberId); 5506 rWeightItem.PutValue(aAny, pEntry->nMemberId); 5507 m_pBoxAutoFormat->SetCJKWeight(rWeightItem); 5508 break; 5509 } 5510 case RES_CHRATR_CJK_POSTURE: 5511 { 5512 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetCJKPosture(); 5513 rDefaultBoxFormat.GetCJKPosture().QueryValue(aAny, pEntry->nMemberId); 5514 rPostureItem.PutValue(aAny, pEntry->nMemberId); 5515 m_pBoxAutoFormat->SetCJKPosture(rPostureItem); 5516 break; 5517 } 5518 case RES_CHRATR_CJK_FONT: 5519 { 5520 SvxFontItem rFontItem = m_pBoxAutoFormat->GetCJKFont(); 5521 rDefaultBoxFormat.GetCJKFont().QueryValue(aAny, pEntry->nMemberId); 5522 rFontItem.PutValue(aAny, pEntry->nMemberId); 5523 m_pBoxAutoFormat->SetCJKFont(rFontItem); 5524 break; 5525 } 5526 case RES_CHRATR_CTL_FONTSIZE: 5527 { 5528 SvxFontHeightItem rFontHeightItem = m_pBoxAutoFormat->GetCTLHeight(); 5529 rDefaultBoxFormat.GetCTLHeight().QueryValue(aAny, pEntry->nMemberId); 5530 rFontHeightItem.PutValue(aAny, pEntry->nMemberId); 5531 m_pBoxAutoFormat->SetCTLHeight(rFontHeightItem); 5532 break; 5533 } 5534 case RES_CHRATR_CTL_WEIGHT: 5535 { 5536 SvxWeightItem rWeightItem = m_pBoxAutoFormat->GetCTLWeight(); 5537 rDefaultBoxFormat.GetCTLWeight().QueryValue(aAny, pEntry->nMemberId); 5538 rWeightItem.PutValue(aAny, pEntry->nMemberId); 5539 m_pBoxAutoFormat->SetCTLWeight(rWeightItem); 5540 break; 5541 } 5542 case RES_CHRATR_CTL_POSTURE: 5543 { 5544 SvxPostureItem rPostureItem = m_pBoxAutoFormat->GetCTLPosture(); 5545 rDefaultBoxFormat.GetCTLPosture().QueryValue(aAny, pEntry->nMemberId); 5546 rPostureItem.PutValue(aAny, pEntry->nMemberId); 5547 m_pBoxAutoFormat->SetCTLPosture(rPostureItem); 5548 break; 5549 } 5550 case RES_CHRATR_CTL_FONT: 5551 { 5552 SvxFontItem rFontItem = m_pBoxAutoFormat->GetCTLFont(); 5553 rDefaultBoxFormat.GetCTLFont().QueryValue(aAny, pEntry->nMemberId); 5554 rFontItem.PutValue(aAny, pEntry->nMemberId); 5555 m_pBoxAutoFormat->SetCTLFont(rFontItem); 5556 break; 5557 } 5558 default: 5559 SAL_WARN("sw.uno", "SwXTextCellStyle setPropertyToDefault unknown nWID"); 5560 } 5561 } 5562 } 5563 5564 css::uno::Any SAL_CALL SwXTextCellStyle::getPropertyDefault(const OUString& /*aPropertyName*/) 5565 { 5566 SAL_WARN("sw.uno", "not implemented"); 5567 uno::Any aRet; 5568 return aRet; 5569 } 5570 5571 //XServiceInfo 5572 OUString SAL_CALL SwXTextCellStyle::getImplementationName() 5573 { 5574 return {"SwXTextCellStyle"}; 5575 } 5576 5577 sal_Bool SAL_CALL SwXTextCellStyle::supportsService(const OUString& rServiceName) 5578 { 5579 return cppu::supportsService(this, rServiceName); 5580 } 5581 5582 css::uno::Sequence<OUString> SAL_CALL SwXTextCellStyle::getSupportedServiceNames() 5583 { 5584 return {"com.sun.star.style.Style"}; 5585 } 5586 5587 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 5588
