cid#1636693 COPY_INSTEAD_OF_MOVE
[LibreOffice.git] / extensions / source / propctrlr / composeduiupdate.cxx
blob247dd4ab3e71086ade953b19b7b240a418d31821
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "composeduiupdate.hxx"
21 #include "pcrcommon.hxx"
23 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include <com/sun/star/lang/NullPointerException.hpp>
26 #include <com/sun/star/inspection/PropertyLineElement.hpp>
27 #include <osl/diagnose.h>
28 #include <osl/mutex.hxx>
29 #include <rtl/ref.hxx>
30 #include <cppuhelper/implbase.hxx>
32 #include <algorithm>
33 #include <map>
34 #include <set>
37 namespace pcr
41 using ::com::sun::star::lang::DisposedException;
42 using ::com::sun::star::lang::NullPointerException;
43 using ::com::sun::star::inspection::XPropertyHandler;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::inspection::XObjectInspectorUI;
46 using ::com::sun::star::inspection::XPropertyControl;
47 using ::com::sun::star::inspection::XPropertyControlObserver;
49 namespace PropertyLineElement = ::com::sun::star::inspection::PropertyLineElement;
51 namespace
53 struct HandlerLess
55 bool operator()( const Reference< XPropertyHandler >& lhs, const Reference< XPropertyHandler >& rhs) const
57 return lhs.get() < rhs.get();
62 typedef std::set< OUString > StringBag;
63 typedef std::map< sal_Int16, StringBag > MapIntToStringBag;
67 // callbacks for CachedInspectorUI
69 typedef void (ComposedPropertyUIUpdate::*FNotifySingleUIChange)();
71 typedef ::cppu::WeakImplHelper < css::inspection::XObjectInspectorUI
72 > CachedInspectorUI_Base;
74 namespace {
76 struct CachedInspectorUI : public CachedInspectorUI_Base
78 private:
79 ::osl::Mutex m_aMutex;
80 bool m_bDisposed;
81 ComposedPropertyUIUpdate&
82 m_rMaster;
83 FNotifySingleUIChange m_pUIChangeNotification;
85 // enablePropertyUI cache
86 StringBag aEnabledProperties;
87 StringBag aDisabledProperties;
89 // show/hidePropertyUI cache
90 StringBag aShownProperties;
91 StringBag aHiddenProperties;
93 // rebuildPropertyUI cache
94 StringBag aRebuiltProperties;
96 // showCategory cache
97 StringBag aShownCategories;
98 StringBag aHiddenCategories;
100 // enablePropertyUIElements cache
101 MapIntToStringBag aEnabledElements;
102 MapIntToStringBag aDisabledElements;
104 public:
105 typedef StringBag& (CachedInspectorUI::*FGetStringBag)();
107 // enablePropertyUI cache
108 StringBag& getEnabledProperties() { return aEnabledProperties; }
109 StringBag& getDisabledProperties() { return aDisabledProperties; }
111 // show/hidePropertyUI cache
112 StringBag& getShownProperties() { return aShownProperties; }
113 StringBag& getHiddenProperties() { return aHiddenProperties; }
115 // rebuildPropertyUI cache
116 StringBag& getRebuiltProperties() { return aRebuiltProperties; }
118 // showCategory cache
119 StringBag& getShownCategories() { return aShownCategories; }
120 StringBag& getHiddenCategories() { return aHiddenCategories; }
122 // enablePropertyUIElements
123 StringBag& getEnabledInputControls() { return aEnabledElements[ PropertyLineElement::InputControl ]; }
124 StringBag& getDisabledInputControls() { return aDisabledElements[ PropertyLineElement::InputControl ]; }
125 StringBag& getEnabledPrimaryButtons() { return aEnabledElements[ PropertyLineElement::PrimaryButton ]; }
126 StringBag& getDisabledPrimaryButtons() { return aDisabledElements[ PropertyLineElement::PrimaryButton ]; }
127 StringBag& getEnabledSecondaryButtons() { return aEnabledElements[ PropertyLineElement::SecondaryButton ]; }
128 StringBag& getDisabledSecondaryButtons() { return aDisabledElements[ PropertyLineElement::SecondaryButton ]; }
130 public:
131 CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster, FNotifySingleUIChange _pUIChangeNotification );
132 CachedInspectorUI(const CachedInspectorUI&) = delete;
133 CachedInspectorUI& operator=(const CachedInspectorUI&) = delete;
135 /// disposes the instance
136 void dispose();
138 // XObjectInspectorUI overridables
139 virtual void SAL_CALL enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable ) override;
140 virtual void SAL_CALL enablePropertyUIElements( const OUString& _rPropertyName, ::sal_Int16 _nElements, sal_Bool _bEnable ) override;
141 virtual void SAL_CALL rebuildPropertyUI( const OUString& _rPropertyName ) override;
142 virtual void SAL_CALL showPropertyUI( const OUString& _rPropertyName ) override;
143 virtual void SAL_CALL hidePropertyUI( const OUString& _rPropertyName ) override;
144 virtual void SAL_CALL showCategory( const OUString& _rCategory, sal_Bool _bShow ) override;
145 virtual Reference< XPropertyControl > SAL_CALL getPropertyControl( const OUString& _rPropertyName ) override;
146 virtual void SAL_CALL registerControlObserver( const Reference< XPropertyControlObserver >& Observer ) override;
147 virtual void SAL_CALL revokeControlObserver( const Reference< XPropertyControlObserver >& Observer ) override;
148 virtual void SAL_CALL setHelpSectionText( const OUString& HelpText ) override;
150 protected:
151 virtual ~CachedInspectorUI() override;
153 /// throws an exception if the component is already disposed
154 void checkDisposed() const;
156 private:
157 void impl_markElementEnabledOrDisabled( const OUString& _rPropertyName, sal_Int16 _nElementIdOrZero, bool _bEnable );
159 /** calls <member>m_pUIChangeNotification</member> at <member>m_rMaster</member>
161 void impl_notifySingleUIChange() const;
163 private:
164 class MethodGuard;
165 friend class MethodGuard;
166 class MethodGuard : public ::osl::MutexGuard
168 public:
169 explicit MethodGuard( CachedInspectorUI& rInstance )
170 : ::osl::MutexGuard( rInstance.m_aMutex )
172 rInstance.checkDisposed();
179 CachedInspectorUI::CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster, FNotifySingleUIChange _pUIChangeNotification )
180 :m_bDisposed( false )
181 ,m_rMaster( _rMaster )
182 ,m_pUIChangeNotification( _pUIChangeNotification )
187 CachedInspectorUI::~CachedInspectorUI()
192 void CachedInspectorUI::dispose()
194 ::osl::MutexGuard aGuard( m_aMutex );
195 m_bDisposed = true;
197 clearContainer( aEnabledProperties );
198 clearContainer( aDisabledProperties );
199 clearContainer( aRebuiltProperties );
200 clearContainer( aShownProperties );
201 clearContainer( aHiddenProperties );
202 clearContainer( aShownCategories );
203 clearContainer( aHiddenCategories );
204 clearContainer( aEnabledElements );
205 clearContainer( aDisabledElements );
209 void CachedInspectorUI::checkDisposed() const
211 if (m_bDisposed)
212 throw DisposedException();
216 namespace
218 void lcl_markStringKeyPositiveOrNegative( const OUString& _rKeyName, StringBag& _rPositives, StringBag& _rNegatives, bool _bMarkPositive )
220 if ( _bMarkPositive )
222 _rPositives.insert( _rKeyName );
223 // if the same key has been remember as in the "negative" list before, clear this information, since it's overruled
224 _rNegatives.erase( _rKeyName );
226 else
227 _rNegatives.insert( _rKeyName );
232 void CachedInspectorUI::enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable )
234 MethodGuard aGuard( *this );
235 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
236 return;
238 lcl_markStringKeyPositiveOrNegative( _rPropertyName, aEnabledProperties, aDisabledProperties, _bEnable );
239 impl_notifySingleUIChange();
243 void CachedInspectorUI::impl_markElementEnabledOrDisabled( const OUString& _rPropertyName, sal_Int16 _nElementIdOrZero, bool _bEnable )
245 if ( _nElementIdOrZero == 0 )
246 return;
248 lcl_markStringKeyPositiveOrNegative(
249 _rPropertyName,
250 aEnabledElements[ _nElementIdOrZero ],
251 aDisabledElements[ _nElementIdOrZero ],
252 _bEnable
257 void CachedInspectorUI::impl_notifySingleUIChange() const
259 (m_rMaster.*m_pUIChangeNotification)();
263 void CachedInspectorUI::enablePropertyUIElements( const OUString& _rPropertyName, sal_Int16 _nElements, sal_Bool _bEnable )
265 MethodGuard aGuard( *this );
266 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
267 return;
269 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::InputControl, _bEnable );
270 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::PrimaryButton, _bEnable );
271 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::SecondaryButton, _bEnable );
273 impl_notifySingleUIChange();
277 void CachedInspectorUI::rebuildPropertyUI( const OUString& _rPropertyName )
279 MethodGuard aGuard( *this );
280 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
281 return;
283 aRebuiltProperties.insert( _rPropertyName );
285 impl_notifySingleUIChange();
289 void CachedInspectorUI::showPropertyUI( const OUString& _rPropertyName )
291 MethodGuard aGuard( *this );
292 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
293 return;
295 aShownProperties.insert( _rPropertyName );
296 // if the same category has been hidden before, clear this information, since it's overruled
297 aHiddenProperties.erase( _rPropertyName );
299 impl_notifySingleUIChange();
303 void CachedInspectorUI::hidePropertyUI( const OUString& _rPropertyName )
305 MethodGuard aGuard( *this );
306 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
307 return;
309 aHiddenProperties.insert( _rPropertyName );
310 impl_notifySingleUIChange();
314 void CachedInspectorUI::showCategory( const OUString& _rCategory, sal_Bool _bShow )
316 MethodGuard aGuard( *this );
318 lcl_markStringKeyPositiveOrNegative( _rCategory, aShownCategories, aHiddenCategories, _bShow );
319 impl_notifySingleUIChange();
323 Reference< XPropertyControl > SAL_CALL CachedInspectorUI::getPropertyControl( const OUString& _rPropertyName )
325 MethodGuard aGuard( *this );
326 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
327 return Reference< XPropertyControl >();
329 return m_rMaster.getDelegatorUI()->getPropertyControl( _rPropertyName );
333 void SAL_CALL CachedInspectorUI::registerControlObserver( const Reference< XPropertyControlObserver >& Observer )
335 OSL_FAIL( "CachedInspectorUI::registerControlObserver: not expected to be called!" );
336 // CachedInspectorUI is used as context for the controls, and we don't expect them to
337 // register listeners themself
338 m_rMaster.getDelegatorUI()->registerControlObserver( Observer );
342 void SAL_CALL CachedInspectorUI::revokeControlObserver( const Reference< XPropertyControlObserver >& Observer )
344 OSL_FAIL( "CachedInspectorUI::revokeControlObserver: not expected to be called!" );
345 // CachedInspectorUI is used as context for the controls, and we don't expect them to
346 // register listeners themself
347 m_rMaster.getDelegatorUI()->revokeControlObserver( Observer );
351 void SAL_CALL CachedInspectorUI::setHelpSectionText( const OUString& HelpText )
353 m_rMaster.getDelegatorUI()->setHelpSectionText( HelpText );
357 // HandlerMap
359 typedef std::map < Reference< XPropertyHandler >
360 , ::rtl::Reference< CachedInspectorUI >
361 , HandlerLess
362 > ImplMapHandlerToUI;
363 struct MapHandlerToUI
365 ImplMapHandlerToUI aHandlers;
368 ComposedPropertyUIUpdate::ComposedPropertyUIUpdate( const Reference< XObjectInspectorUI >& _rxDelegatorUI,
369 IPropertyExistenceCheck* _pPropertyCheck )
370 :m_pCollectedUIs( new MapHandlerToUI )
371 ,m_xDelegatorUI( _rxDelegatorUI )
372 ,m_nSuspendCounter( 0 )
373 ,m_pPropertyCheck( _pPropertyCheck )
375 if ( !m_xDelegatorUI.is() )
376 throw NullPointerException();
380 ComposedPropertyUIUpdate::~ComposedPropertyUIUpdate( )
385 Reference< XObjectInspectorUI > ComposedPropertyUIUpdate::getUIForPropertyHandler( const Reference< XPropertyHandler >& _rxHandler )
387 impl_checkDisposed();
389 ::rtl::Reference< CachedInspectorUI >& rUI = m_pCollectedUIs->aHandlers[ _rxHandler ];
390 if ( !rUI.is() )
391 rUI = new CachedInspectorUI( *this, &ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw );
392 return rUI;
396 namespace
399 // an STL-compatible structure which collects strings from a CachedInspectorUI instances
400 struct StringBagCollector
402 private:
403 StringBag& m_rBag;
404 CachedInspectorUI::FGetStringBag m_pGetter;
406 public:
407 StringBagCollector( StringBag& _rBag, CachedInspectorUI::FGetStringBag _pGetter ) :m_rBag( _rBag ), m_pGetter( _pGetter ) { }
409 void operator()( const ImplMapHandlerToUI::value_type& _rUI )
411 StringBag& rBag( ((_rUI.second.get())->*m_pGetter)() );
412 m_rBag.insert( rBag.begin(), rBag.end() );
415 static void collectAll( StringBag& _rAll, const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
417 std::for_each( _rMap.begin(), _rMap.end(), StringBagCollector( _rAll, _pGetter ) );
422 // an STL-compatible structure which cleans a certain string bag in a CachedInspectorUI instances
423 struct StringBagClearer
425 private:
426 CachedInspectorUI::FGetStringBag m_pGetter;
428 public:
429 explicit StringBagClearer( CachedInspectorUI::FGetStringBag _pGetter ) :m_pGetter( _pGetter ) { }
431 void operator()( const ImplMapHandlerToUI::value_type& _rUI )
433 clearContainer( ((_rUI.second.get())->*m_pGetter)() );
436 static void clearAll( const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
438 std::for_each( _rMap.begin(), _rMap.end(), StringBagClearer( _pGetter ) );
442 // a typedef for a ->XObjectInspectorUI member function taking a string
443 typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUISetter )( const OUString& );
446 // an STL-compatible struct which calls a certain member method (taking a string) at a
447 // given ->XObjectInspectorUI instance
448 struct PropertyUIOperator
450 private:
451 Reference< XObjectInspectorUI > m_xUpdater;
452 FPropertyUISetter m_pSetter;
454 public:
455 PropertyUIOperator( const Reference< XObjectInspectorUI >& _rxInspectorUI, FPropertyUISetter _pSetter )
456 :m_xUpdater( _rxInspectorUI )
457 ,m_pSetter( _pSetter )
461 void operator()( const OUString& _rPropertyName )
463 ((m_xUpdater.get())->*m_pSetter)( _rPropertyName );
466 static void forEach( const StringBag& _rProperties, const Reference< XObjectInspectorUI >& _rxDelegatorUI, FPropertyUISetter _pSetter )
468 std::for_each( _rProperties.begin(), _rProperties.end(), PropertyUIOperator( _rxDelegatorUI, _pSetter ) );
473 // an interface which encapsulates access to a single aspect of the ->XObjectInspectorUI,
474 // where this aspect is given by a string key, and has a boolean value.
475 class IStringKeyBooleanUIUpdate
477 public:
478 virtual void updateUIForKey( const OUString& _rKey, bool _bFlag ) const = 0;
480 virtual ~IStringKeyBooleanUIUpdate() { }
484 // FPropertyUIFlagSetter
486 /** an implementation of the ->IStringKeyBooleanUIUpdate interface which,
487 for a fixed ->XObjectInspectorUI instance and a fixed UI element (->PropertyLineElement),
488 updates this element for a given property with a given boolean flag
489 (->XObjectInspectorUI::enablePropertyUIElements)
491 class EnablePropertyUIElement : public IStringKeyBooleanUIUpdate
493 private:
494 Reference< XObjectInspectorUI > m_xUIUpdate;
495 sal_Int16 m_nElement;
497 public:
498 EnablePropertyUIElement( const Reference< XObjectInspectorUI >& _rxUIUpdate, sal_Int16 _nElement )
499 :m_xUIUpdate( _rxUIUpdate )
500 ,m_nElement( _nElement )
503 // IStringKeyBooleanUIUpdate
504 virtual void updateUIForKey( const OUString& _rKey, bool _bFlag ) const override;
508 void EnablePropertyUIElement::updateUIForKey( const OUString& _rKey, bool _bFlag ) const
510 m_xUIUpdate->enablePropertyUIElements( _rKey, m_nElement, _bFlag );
514 // a ->XObjectInspectorUI method taking a string and a boolean
515 typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUIFlagSetter )( const OUString&, sal_Bool );
518 // an implementation of the ->IStringKeyBooleanUIUpdate interface which calls
519 // an arbitrary ->XObjectInspectorUI method taking a string and a boolean flag
520 class DefaultStringKeyBooleanUIUpdate : public IStringKeyBooleanUIUpdate
522 private:
523 Reference< XObjectInspectorUI > m_xUIUpdate;
524 FPropertyUIFlagSetter m_pSetter;
526 public:
527 DefaultStringKeyBooleanUIUpdate( const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter );
528 // IStringKeyBooleanUIUpdate
529 virtual void updateUIForKey( const OUString& _rKey, bool _bFlag ) const override;
533 DefaultStringKeyBooleanUIUpdate::DefaultStringKeyBooleanUIUpdate( const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter )
534 :m_xUIUpdate( _rxUIUpdate )
535 ,m_pSetter( _pSetter )
540 void DefaultStringKeyBooleanUIUpdate::updateUIForKey( const OUString& _rKey, bool _bFlag ) const
542 ((m_xUIUpdate.get())->*m_pSetter)( _rKey, _bFlag );
546 // an STL-compatible structure which applies a ->IStringKeyBooleanUIUpdate::updateUIForKey
547 // operation with a fixed boolean value, for a given string value
548 struct BooleanUIAspectUpdate
550 private:
551 const IStringKeyBooleanUIUpdate& m_rUpdater;
552 bool m_bFlag;
554 public:
555 BooleanUIAspectUpdate( const IStringKeyBooleanUIUpdate& _rUpdater, bool _bFlag )
556 :m_rUpdater( _rUpdater )
557 ,m_bFlag( _bFlag )
561 void operator()( const OUString& _rPropertyName )
563 m_rUpdater.updateUIForKey( _rPropertyName, m_bFlag );
566 static void forEach( const StringBag& _rProperties, const IStringKeyBooleanUIUpdate& _rUpdater, bool _bFlag )
568 std::for_each( _rProperties.begin(), _rProperties.end(), BooleanUIAspectUpdate( _rUpdater, _bFlag ) );
573 // BooleanUIAspectUpdate
575 // an STL-compatible structure subtracting a given string from a fixed ->StringBag
576 struct StringBagComplement
578 private:
579 StringBag& m_rMinuend;
581 public:
582 explicit StringBagComplement( StringBag& _rMinuend ) :m_rMinuend( _rMinuend ) { }
584 void operator()( const OUString& _rPropertyToSubtract )
586 m_rMinuend.erase( _rPropertyToSubtract );
589 static void subtract( StringBag& _rMinuend, const StringBag& _rSubtrahend )
591 std::for_each( _rSubtrahend.begin(), _rSubtrahend.end(), StringBagComplement( _rMinuend ) );
596 // BooleanUIAspectUpdate
598 void lcl_fireUIStateFlag(
599 const IStringKeyBooleanUIUpdate& _rUIUpdate,
600 const ImplMapHandlerToUI& _rHandlerUIs,
601 CachedInspectorUI::FGetStringBag _pGetPositives,
602 CachedInspectorUI::FGetStringBag _pGetNegatives
605 // all strings which are in the "positive" list of one handler
606 StringBag aAllPositives;
607 StringBagCollector::collectAll( aAllPositives, _rHandlerUIs, _pGetPositives );
609 // all strings which are in the "negative" list of one handler
610 StringBag aAllNegatives;
611 StringBagCollector::collectAll( aAllNegatives, _rHandlerUIs, _pGetNegatives );
613 // propagate the "negative" flags to the delegator UI
614 BooleanUIAspectUpdate::forEach( aAllNegatives, _rUIUpdate, false );
616 // propagate the "positive" flags to the delegator UI, for all elements where _no_
617 // "negative" flag exists
618 StringBagComplement::subtract( aAllPositives, aAllNegatives );
619 BooleanUIAspectUpdate::forEach( aAllPositives, _rUIUpdate, true );
621 // the "positive" request can be cleared no, only negative requests
622 // (such as "disable a property" or "hide a category") need to be preserved for the next round
623 StringBagClearer::clearAll( _rHandlerUIs, _pGetPositives );
628 void ComposedPropertyUIUpdate::impl_fireEnablePropertyUI_throw()
630 lcl_fireUIStateFlag(
631 DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI, &XObjectInspectorUI::enablePropertyUI ),
632 m_pCollectedUIs->aHandlers,
633 &CachedInspectorUI::getEnabledProperties,
634 &CachedInspectorUI::getDisabledProperties
639 void ComposedPropertyUIUpdate::impl_fireRebuildPropertyUI_throw()
641 // collect all properties for which a rebuild request has been made
642 StringBag aAllRebuilt;
643 StringBagCollector::collectAll( aAllRebuilt, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
645 // rebuild all those properties
646 PropertyUIOperator::forEach( aAllRebuilt, m_xDelegatorUI, &XObjectInspectorUI::rebuildPropertyUI );
648 // clear the "properties to rebuild" at all handlers, since the request has been fulfilled now.
649 StringBagClearer::clearAll( m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
653 void ComposedPropertyUIUpdate::impl_fireShowHidePropertyUI_throw()
655 // all properties which have been shown by at least one handler
656 StringBag aAllShown;
657 StringBagCollector::collectAll( aAllShown, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getShownProperties );
658 // all properties which have been hidden by at least one handler
659 StringBag aAllHidden;
660 StringBagCollector::collectAll( aAllHidden, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getHiddenProperties );
662 // hide properties as necessary
663 PropertyUIOperator::forEach( aAllHidden, m_xDelegatorUI, &XObjectInspectorUI::hidePropertyUI );
665 // for those properties which are hidden, ignore all "show" requests which other handlers might have had
666 StringBagComplement::subtract( aAllShown, aAllHidden );
668 // show properties
669 PropertyUIOperator::forEach( aAllShown, m_xDelegatorUI, &XObjectInspectorUI::showPropertyUI );
673 void ComposedPropertyUIUpdate::impl_fireShowCategory_throw()
675 lcl_fireUIStateFlag(
676 DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI, &XObjectInspectorUI::showCategory ),
677 m_pCollectedUIs->aHandlers,
678 &CachedInspectorUI::getShownCategories,
679 &CachedInspectorUI::getHiddenCategories
684 void ComposedPropertyUIUpdate::impl_fireEnablePropertyUIElements_throw()
686 lcl_fireUIStateFlag(
687 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::InputControl ),
688 m_pCollectedUIs->aHandlers,
689 &CachedInspectorUI::getEnabledInputControls,
690 &CachedInspectorUI::getDisabledInputControls
693 lcl_fireUIStateFlag(
694 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::PrimaryButton ),
695 m_pCollectedUIs->aHandlers,
696 &CachedInspectorUI::getEnabledPrimaryButtons,
697 &CachedInspectorUI::getDisabledPrimaryButtons
700 lcl_fireUIStateFlag(
701 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::SecondaryButton ),
702 m_pCollectedUIs->aHandlers,
703 &CachedInspectorUI::getEnabledSecondaryButtons,
704 &CachedInspectorUI::getDisabledSecondaryButtons
709 void ComposedPropertyUIUpdate::impl_fireAll_throw()
711 OSL_PRECOND( !impl_isDisposed(), "ComposedPropertyUIUpdate::impl_fireAll_throw: already disposed, this will crash!" );
713 impl_fireEnablePropertyUI_throw();
714 impl_fireShowHidePropertyUI_throw();
715 impl_fireRebuildPropertyUI_throw();
716 impl_fireShowCategory_throw();
717 impl_fireEnablePropertyUIElements_throw();
721 void ComposedPropertyUIUpdate::suspendAutoFire()
723 impl_checkDisposed();
724 osl_atomic_increment( &m_nSuspendCounter );
728 void ComposedPropertyUIUpdate::resumeAutoFire()
730 impl_checkDisposed();
731 if ( 0 == osl_atomic_decrement( &m_nSuspendCounter ) )
732 impl_fireAll_throw();
736 void ComposedPropertyUIUpdate::impl_checkDisposed() const
738 if ( impl_isDisposed() )
739 throw DisposedException();
743 void ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw()
745 if ( 0 == m_nSuspendCounter )
746 impl_fireAll_throw();
750 Reference< XObjectInspectorUI > const & ComposedPropertyUIUpdate::getDelegatorUI() const
752 impl_checkDisposed();
753 return m_xDelegatorUI;
757 void ComposedPropertyUIUpdate::dispose()
759 if ( impl_isDisposed() )
760 return;
762 OSL_ENSURE( m_nSuspendCounter == 0, "ComposedPropertyUIUpdate::dispose: still suspended, the changes will be lost!" );
764 for (auto const& singleUI : m_pCollectedUIs->aHandlers)
766 singleUI.second->dispose();
768 m_pCollectedUIs.reset();
769 m_xDelegatorUI.clear();
773 bool ComposedPropertyUIUpdate::shouldContinuePropertyHandling( const OUString& _rName ) const
775 if ( !m_pPropertyCheck )
776 return true;
777 if ( m_pPropertyCheck->hasPropertyByName( _rName ) )
778 return true;
779 return false;
783 } // namespace pcr
786 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */