Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / extensions / source / propctrlr / composeduiupdate.cxx
blobc438f320740089966509c3899b2d8f66ef0beb78
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"
22 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
23 #include <com/sun/star/lang/DisposedException.hpp>
24 #include <com/sun/star/lang/NullPointerException.hpp>
25 #include <com/sun/star/inspection/PropertyLineElement.hpp>
26 #include <osl/mutex.hxx>
27 #include <rtl/ref.hxx>
28 #include <cppuhelper/implbase.hxx>
30 #include <algorithm>
33 namespace pcr
37 using ::com::sun::star::lang::DisposedException;
38 using ::com::sun::star::lang::NullPointerException;
39 using ::com::sun::star::inspection::XPropertyHandler;
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::inspection::XObjectInspectorUI;
42 using ::com::sun::star::inspection::XPropertyControl;
43 using ::com::sun::star::uno::RuntimeException;
44 using ::com::sun::star::inspection::XPropertyControlObserver;
46 namespace PropertyLineElement = ::com::sun::star::inspection::PropertyLineElement;
48 namespace
50 struct HandlerLess : public std::binary_function < Reference< XPropertyHandler >
51 , Reference< XPropertyHandler >
52 , bool
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;
73 struct CachedInspectorUI : public CachedInspectorUI_Base
75 private:
76 ::osl::Mutex m_aMutex;
77 bool m_bDisposed;
78 ComposedPropertyUIUpdate&
79 m_rMaster;
80 FNotifySingleUIChange m_pUIChangeNotification;
82 // enablePropertyUI cache
83 StringBag aEnabledProperties;
84 StringBag aDisabledProperties;
86 // show/hidePropertyUI cache
87 StringBag aShownProperties;
88 StringBag aHiddenProperties;
90 // rebuildPropertyUI cache
91 StringBag aRebuiltProperties;
93 // showCategory cache
94 StringBag aShownCategories;
95 StringBag aHiddenCategories;
97 // enablePropertyUIElements cache
98 MapIntToStringBag aEnabledElements;
99 MapIntToStringBag aDisabledElements;
101 public:
102 typedef StringBag& (CachedInspectorUI::*FGetStringBag)();
104 // enablePropertyUI cache
105 StringBag& getEnabledProperties() { return aEnabledProperties; }
106 StringBag& getDisabledProperties() { return aDisabledProperties; }
108 // show/hidePropertyUI cache
109 StringBag& getShownProperties() { return aShownProperties; }
110 StringBag& getHiddenProperties() { return aHiddenProperties; }
112 // rebuildPropertyUI cache
113 StringBag& getRebuiltProperties() { return aRebuiltProperties; }
115 // showCategory cache
116 StringBag& getShownCategories() { return aShownCategories; }
117 StringBag& getHiddenCategories() { return aHiddenCategories; }
119 // enablePropertyUIElements
120 StringBag& getEnabledInputControls() { return aEnabledElements[ PropertyLineElement::InputControl ]; }
121 StringBag& getDisabledInputControls() { return aDisabledElements[ PropertyLineElement::InputControl ]; }
122 StringBag& getEnabledPrimaryButtons() { return aEnabledElements[ PropertyLineElement::PrimaryButton ]; }
123 StringBag& getDisabledPrimaryButtons() { return aDisabledElements[ PropertyLineElement::PrimaryButton ]; }
124 StringBag& getEnabledSecondaryButtons() { return aEnabledElements[ PropertyLineElement::SecondaryButton ]; }
125 StringBag& getDisabledSecondaryButtons() { return aDisabledElements[ PropertyLineElement::SecondaryButton ]; }
127 public:
128 CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster, FNotifySingleUIChange _pUIChangeNotification );
129 CachedInspectorUI(const CachedInspectorUI&) = delete;
130 CachedInspectorUI& operator=(const CachedInspectorUI&) = delete;
132 /// disposes the instance
133 void dispose();
135 // XObjectInspectorUI overridables
136 virtual void SAL_CALL enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable ) override;
137 virtual void SAL_CALL enablePropertyUIElements( const OUString& _rPropertyName, ::sal_Int16 _nElements, sal_Bool _bEnable ) override;
138 virtual void SAL_CALL rebuildPropertyUI( const OUString& _rPropertyName ) override;
139 virtual void SAL_CALL showPropertyUI( const OUString& _rPropertyName ) override;
140 virtual void SAL_CALL hidePropertyUI( const OUString& _rPropertyName ) override;
141 virtual void SAL_CALL showCategory( const OUString& _rCategory, sal_Bool _bShow ) override;
142 virtual Reference< XPropertyControl > SAL_CALL getPropertyControl( const OUString& _rPropertyName ) override;
143 virtual void SAL_CALL registerControlObserver( const Reference< XPropertyControlObserver >& Observer ) override;
144 virtual void SAL_CALL revokeControlObserver( const Reference< XPropertyControlObserver >& Observer ) override;
145 virtual void SAL_CALL setHelpSectionText( const OUString& HelpText ) override;
147 protected:
148 virtual ~CachedInspectorUI() override;
150 /// throws an exception if the component is already disposed
151 void checkDisposed() const;
153 private:
154 void impl_markElementEnabledOrDisabled( const OUString& _rPropertyName, sal_Int16 _nElementIdOrZero, bool _bEnable );
156 /** calls <member>m_pUIChangeNotification</member> at <member>m_rMaster</member>
158 void impl_notifySingleUIChange() const;
160 private:
161 class MethodGuard;
162 friend class MethodGuard;
163 class MethodGuard : public ::osl::MutexGuard
165 public:
166 explicit MethodGuard( CachedInspectorUI& rInstance )
167 : ::osl::MutexGuard( rInstance.m_aMutex )
169 rInstance.checkDisposed();
175 CachedInspectorUI::CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster, FNotifySingleUIChange _pUIChangeNotification )
176 :m_bDisposed( false )
177 ,m_rMaster( _rMaster )
178 ,m_pUIChangeNotification( _pUIChangeNotification )
183 CachedInspectorUI::~CachedInspectorUI()
188 void CachedInspectorUI::dispose()
190 ::osl::MutexGuard aGuard( m_aMutex );
191 m_bDisposed = true;
193 clearContainer( aEnabledProperties );
194 clearContainer( aDisabledProperties );
195 clearContainer( aRebuiltProperties );
196 clearContainer( aShownProperties );
197 clearContainer( aHiddenProperties );
198 clearContainer( aShownCategories );
199 clearContainer( aHiddenCategories );
200 clearContainer( aEnabledElements );
201 clearContainer( aDisabledElements );
205 void CachedInspectorUI::checkDisposed() const
207 if (m_bDisposed)
208 throw DisposedException();
212 namespace
214 void lcl_markStringKeyPositiveOrNegative( const OUString& _rKeyName, StringBag& _rPositives, StringBag& _rNegatives, bool _bMarkPositive )
216 if ( _bMarkPositive )
218 _rPositives.insert( _rKeyName );
219 // if the same key has been remember as in the "negative" list before, clear this information, since it's overruled
220 _rNegatives.erase( _rKeyName );
222 else
223 _rNegatives.insert( _rKeyName );
228 void CachedInspectorUI::enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable )
230 MethodGuard aGuard( *this );
231 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
232 return;
234 lcl_markStringKeyPositiveOrNegative( _rPropertyName, aEnabledProperties, aDisabledProperties, _bEnable );
235 impl_notifySingleUIChange();
239 void CachedInspectorUI::impl_markElementEnabledOrDisabled( const OUString& _rPropertyName, sal_Int16 _nElementIdOrZero, bool _bEnable )
241 if ( _nElementIdOrZero == 0 )
242 return;
244 lcl_markStringKeyPositiveOrNegative(
245 _rPropertyName,
246 aEnabledElements[ _nElementIdOrZero ],
247 aDisabledElements[ _nElementIdOrZero ],
248 _bEnable
253 void CachedInspectorUI::impl_notifySingleUIChange() const
255 (m_rMaster.*m_pUIChangeNotification)();
259 void CachedInspectorUI::enablePropertyUIElements( const OUString& _rPropertyName, sal_Int16 _nElements, sal_Bool _bEnable )
261 MethodGuard aGuard( *this );
262 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
263 return;
265 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::InputControl, _bEnable );
266 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::PrimaryButton, _bEnable );
267 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::SecondaryButton, _bEnable );
269 impl_notifySingleUIChange();
273 void CachedInspectorUI::rebuildPropertyUI( const OUString& _rPropertyName )
275 MethodGuard aGuard( *this );
276 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
277 return;
279 aRebuiltProperties.insert( _rPropertyName );
281 impl_notifySingleUIChange();
285 void CachedInspectorUI::showPropertyUI( const OUString& _rPropertyName )
287 MethodGuard aGuard( *this );
288 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
289 return;
291 aShownProperties.insert( _rPropertyName );
292 // if the same category has been hidden before, clear this information, since it's overruled
293 aHiddenProperties.erase( _rPropertyName );
295 impl_notifySingleUIChange();
299 void CachedInspectorUI::hidePropertyUI( const OUString& _rPropertyName )
301 MethodGuard aGuard( *this );
302 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
303 return;
305 aHiddenProperties.insert( _rPropertyName );
306 impl_notifySingleUIChange();
310 void CachedInspectorUI::showCategory( const OUString& _rCategory, sal_Bool _bShow )
312 MethodGuard aGuard( *this );
314 lcl_markStringKeyPositiveOrNegative( _rCategory, aShownCategories, aHiddenCategories, _bShow );
315 impl_notifySingleUIChange();
319 Reference< XPropertyControl > SAL_CALL CachedInspectorUI::getPropertyControl( const OUString& _rPropertyName )
321 MethodGuard aGuard( *this );
322 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
323 return Reference< XPropertyControl >();
325 return m_rMaster.getDelegatorUI()->getPropertyControl( _rPropertyName );
329 void SAL_CALL CachedInspectorUI::registerControlObserver( const Reference< XPropertyControlObserver >& Observer )
331 OSL_FAIL( "CachedInspectorUI::registerControlObserver: not expected to be called!" );
332 // CachedInspectorUI is used as context for the controls, and we don't expect them to
333 // register listeners themself
334 m_rMaster.getDelegatorUI()->registerControlObserver( Observer );
338 void SAL_CALL CachedInspectorUI::revokeControlObserver( const Reference< XPropertyControlObserver >& Observer )
340 OSL_FAIL( "CachedInspectorUI::revokeControlObserver: not expected to be called!" );
341 // CachedInspectorUI is used as context for the controls, and we don't expect them to
342 // register listeners themself
343 m_rMaster.getDelegatorUI()->revokeControlObserver( Observer );
347 void SAL_CALL CachedInspectorUI::setHelpSectionText( const OUString& HelpText )
349 m_rMaster.getDelegatorUI()->setHelpSectionText( HelpText );
353 // HandlerMap
355 typedef std::map < Reference< XPropertyHandler >
356 , ::rtl::Reference< CachedInspectorUI >
357 , HandlerLess
358 > ImplMapHandlerToUI;
359 struct MapHandlerToUI
361 ImplMapHandlerToUI aHandlers;
364 ComposedPropertyUIUpdate::ComposedPropertyUIUpdate( const Reference< XObjectInspectorUI >& _rxDelegatorUI,
365 IPropertyExistenceCheck* _pPropertyCheck )
366 :m_pCollectedUIs( new MapHandlerToUI )
367 ,m_xDelegatorUI( _rxDelegatorUI )
368 ,m_nSuspendCounter( 0 )
369 ,m_pPropertyCheck( _pPropertyCheck )
371 if ( !m_xDelegatorUI.is() )
372 throw NullPointerException();
376 ComposedPropertyUIUpdate::~ComposedPropertyUIUpdate( )
381 Reference< XObjectInspectorUI > ComposedPropertyUIUpdate::getUIForPropertyHandler( const Reference< XPropertyHandler >& _rxHandler )
383 impl_checkDisposed();
385 ::rtl::Reference< CachedInspectorUI >& rUI = m_pCollectedUIs->aHandlers[ _rxHandler ];
386 if ( !rUI.is() )
387 rUI = new CachedInspectorUI( *this, &ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw );
388 return rUI.get();
392 namespace
395 // an STL-compatible structure which collects strings from a CachedInspectorUI instances
396 struct StringBagCollector : public std::unary_function< ImplMapHandlerToUI::value_type, void >
398 private:
399 StringBag& m_rBag;
400 CachedInspectorUI::FGetStringBag m_pGetter;
402 public:
403 StringBagCollector( StringBag& _rBag, CachedInspectorUI::FGetStringBag _pGetter ) :m_rBag( _rBag ), m_pGetter( _pGetter ) { }
405 void operator()( const ImplMapHandlerToUI::value_type& _rUI )
407 StringBag& rBag( ((_rUI.second.get())->*m_pGetter)() );
408 m_rBag.insert( rBag.begin(), rBag.end() );
411 static void collectAll( StringBag& _rAll, const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
413 std::for_each( _rMap.begin(), _rMap.end(), StringBagCollector( _rAll, _pGetter ) );
418 // an STL-compatible structure which cleans a certain string bag in a CachedInspectorUI instances
419 struct StringBagClearer : public std::unary_function< ImplMapHandlerToUI::value_type, void >
421 private:
422 CachedInspectorUI::FGetStringBag m_pGetter;
424 public:
425 explicit StringBagClearer( CachedInspectorUI::FGetStringBag _pGetter ) :m_pGetter( _pGetter ) { }
427 void operator()( const ImplMapHandlerToUI::value_type& _rUI )
429 clearContainer( ((_rUI.second.get())->*m_pGetter)() );
432 static void clearAll( const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
434 std::for_each( _rMap.begin(), _rMap.end(), StringBagClearer( _pGetter ) );
438 // a typedef for a ->XObjectInspectorUI member function taking a string
439 typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUISetter )( const OUString& );
442 // an STL-compatible struct which calls a certain member method (taking a string) at a
443 // given ->XObjectInspectorUI instance
444 struct PropertyUIOperator : public std::unary_function< OUString, void >
446 private:
447 Reference< XObjectInspectorUI > m_xUpdater;
448 FPropertyUISetter m_pSetter;
450 public:
451 PropertyUIOperator( const Reference< XObjectInspectorUI >& _rxInspectorUI, FPropertyUISetter _pSetter )
452 :m_xUpdater( _rxInspectorUI )
453 ,m_pSetter( _pSetter )
457 void operator()( const OUString& _rPropertyName )
459 ((m_xUpdater.get())->*m_pSetter)( _rPropertyName );
462 static void forEach( const StringBag& _rProperties, const Reference< XObjectInspectorUI >& _rxDelegatorUI, FPropertyUISetter _pSetter )
464 std::for_each( _rProperties.begin(), _rProperties.end(), PropertyUIOperator( _rxDelegatorUI, _pSetter ) );
469 // an interface which encapsulates access to a single aspect of the ->XObjectInspectorUI,
470 // where this aspect is given by a string key, and has a boolean value.
471 class IStringKeyBooleanUIUpdate
473 public:
474 virtual void updateUIForKey( const OUString& _rKey, bool _bFlag ) const = 0;
476 virtual ~IStringKeyBooleanUIUpdate() { }
480 // FPropertyUIFlagSetter
482 /** an implementation of the ->IStringKeyBooleanUIUpdate interface which,
483 for a fixed ->XObjectInspectorUI instance and a fixed UI element (->PropertyLineElement),
484 updates this element for a given property with a given boolean flag
485 (->XObjectInspectorUI::enablePropertyUIElements)
487 class EnablePropertyUIElement : public IStringKeyBooleanUIUpdate
489 private:
490 Reference< XObjectInspectorUI > m_xUIUpdate;
491 sal_Int16 m_nElement;
493 public:
494 EnablePropertyUIElement( const Reference< XObjectInspectorUI >& _rxUIUpdate, sal_Int16 _nElement )
495 :m_xUIUpdate( _rxUIUpdate )
496 ,m_nElement( _nElement )
499 // IStringKeyBooleanUIUpdate
500 virtual void updateUIForKey( const OUString& _rKey, bool _bFlag ) const override;
504 void EnablePropertyUIElement::updateUIForKey( const OUString& _rKey, bool _bFlag ) const
506 m_xUIUpdate->enablePropertyUIElements( _rKey, m_nElement, _bFlag );
510 // a ->XObjectInspectorUI method taking a string and a boolean
511 typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUIFlagSetter )( const OUString&, sal_Bool );
514 // an implementation of the ->IStringKeyBooleanUIUpdate interface which calls
515 // am arbitrary ->XObjectInspectorUI method taking a string and a boolean flag
516 class DefaultStringKeyBooleanUIUpdate : public IStringKeyBooleanUIUpdate
518 private:
519 Reference< XObjectInspectorUI > m_xUIUpdate;
520 FPropertyUIFlagSetter m_pSetter;
522 public:
523 DefaultStringKeyBooleanUIUpdate( const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter );
524 // IStringKeyBooleanUIUpdate
525 virtual void updateUIForKey( const OUString& _rKey, bool _bFlag ) const override;
529 DefaultStringKeyBooleanUIUpdate::DefaultStringKeyBooleanUIUpdate( const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter )
530 :m_xUIUpdate( _rxUIUpdate )
531 ,m_pSetter( _pSetter )
536 void DefaultStringKeyBooleanUIUpdate::updateUIForKey( const OUString& _rKey, bool _bFlag ) const
538 ((m_xUIUpdate.get())->*m_pSetter)( _rKey, _bFlag );
542 // an STL-compatible structure which applies a ->IStringKeyBooleanUIUpdate::updateUIForKey
543 // operation with a fixed boolean value, for a given string value
544 struct BooleanUIAspectUpdate : public std::unary_function< OUString, void >
546 private:
547 const IStringKeyBooleanUIUpdate& m_rUpdater;
548 bool m_bFlag;
550 public:
551 BooleanUIAspectUpdate( const IStringKeyBooleanUIUpdate& _rUpdater, bool _bFlag )
552 :m_rUpdater( _rUpdater )
553 ,m_bFlag( _bFlag )
557 void operator()( const OUString& _rPropertyName )
559 m_rUpdater.updateUIForKey( _rPropertyName, m_bFlag );
562 static void forEach( const StringBag& _rProperties, const IStringKeyBooleanUIUpdate& _rUpdater, bool _bFlag )
564 std::for_each( _rProperties.begin(), _rProperties.end(), BooleanUIAspectUpdate( _rUpdater, _bFlag ) );
569 // BooleanUIAspectUpdate
571 // an STL-compatible structure subtracting a given string from a fixed ->StringBag
572 struct StringBagComplement : public std::unary_function< OUString, void >
574 private:
575 StringBag& m_rMinuend;
577 public:
578 explicit StringBagComplement( StringBag& _rMinuend ) :m_rMinuend( _rMinuend ) { }
580 void operator()( const OUString& _rPropertyToSubtract )
582 m_rMinuend.erase( _rPropertyToSubtract );
585 static void subtract( StringBag& _rMinuend, const StringBag& _rSubtrahend )
587 std::for_each( _rSubtrahend.begin(), _rSubtrahend.end(), StringBagComplement( _rMinuend ) );
592 // BooleanUIAspectUpdate
594 void lcl_fireUIStateFlag(
595 const IStringKeyBooleanUIUpdate& _rUIUpdate,
596 const ImplMapHandlerToUI& _rHandlerUIs,
597 CachedInspectorUI::FGetStringBag _pGetPositives,
598 CachedInspectorUI::FGetStringBag _pGetNegatives
601 // all strings which are in the "positive" list of one handler
602 StringBag aAllPositives;
603 StringBagCollector::collectAll( aAllPositives, _rHandlerUIs, _pGetPositives );
605 // all strings which are in the "negative" list of one handler
606 StringBag aAllNegatives;
607 StringBagCollector::collectAll( aAllNegatives, _rHandlerUIs, _pGetNegatives );
609 // propagate the "negative" flags to the delegator UI
610 BooleanUIAspectUpdate::forEach( aAllNegatives, _rUIUpdate, false );
612 // propagate the "positive" flags to the delegator UI, for all elements where _no_
613 // "negative" flag exists
614 StringBagComplement::subtract( aAllPositives, aAllNegatives );
615 BooleanUIAspectUpdate::forEach( aAllPositives, _rUIUpdate, true );
617 // the "positive" request can be cleared no, only negative requests
618 // (such as "disable a property" or "hide a category") need to be preserved for the next round
619 StringBagClearer::clearAll( _rHandlerUIs, _pGetPositives );
624 void ComposedPropertyUIUpdate::impl_fireEnablePropertyUI_throw()
626 lcl_fireUIStateFlag(
627 DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI, &XObjectInspectorUI::enablePropertyUI ),
628 m_pCollectedUIs->aHandlers,
629 &CachedInspectorUI::getEnabledProperties,
630 &CachedInspectorUI::getDisabledProperties
635 void ComposedPropertyUIUpdate::impl_fireRebuildPropertyUI_throw()
637 // collect all properties for which a rebuild request has been made
638 StringBag aAllRebuilt;
639 StringBagCollector::collectAll( aAllRebuilt, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
641 // rebuild all those properties
642 PropertyUIOperator::forEach( aAllRebuilt, m_xDelegatorUI, &XObjectInspectorUI::rebuildPropertyUI );
644 // clear the "properties to rebuild" at all handlers, since the request has been fulfilled now.
645 StringBagClearer::clearAll( m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
649 void ComposedPropertyUIUpdate::impl_fireShowHidePropertyUI_throw()
651 // all properties which have been shown by at least one handler
652 StringBag aAllShown;
653 StringBagCollector::collectAll( aAllShown, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getShownProperties );
654 // all properties which have been hidden by at least one handler
655 StringBag aAllHidden;
656 StringBagCollector::collectAll( aAllHidden, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getHiddenProperties );
658 // hide properties as necessary
659 PropertyUIOperator::forEach( aAllHidden, m_xDelegatorUI, &XObjectInspectorUI::hidePropertyUI );
661 // for those properties which are hidden, ignore all "show" requests which other handlers might have had
662 StringBagComplement::subtract( aAllShown, aAllHidden );
664 // show properties
665 PropertyUIOperator::forEach( aAllShown, m_xDelegatorUI, &XObjectInspectorUI::showPropertyUI );
669 void ComposedPropertyUIUpdate::impl_fireShowCategory_throw()
671 lcl_fireUIStateFlag(
672 DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI, &XObjectInspectorUI::showCategory ),
673 m_pCollectedUIs->aHandlers,
674 &CachedInspectorUI::getShownCategories,
675 &CachedInspectorUI::getHiddenCategories
680 void ComposedPropertyUIUpdate::impl_fireEnablePropertyUIElements_throw()
682 lcl_fireUIStateFlag(
683 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::InputControl ),
684 m_pCollectedUIs->aHandlers,
685 &CachedInspectorUI::getEnabledInputControls,
686 &CachedInspectorUI::getDisabledInputControls
689 lcl_fireUIStateFlag(
690 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::PrimaryButton ),
691 m_pCollectedUIs->aHandlers,
692 &CachedInspectorUI::getEnabledPrimaryButtons,
693 &CachedInspectorUI::getDisabledPrimaryButtons
696 lcl_fireUIStateFlag(
697 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::SecondaryButton ),
698 m_pCollectedUIs->aHandlers,
699 &CachedInspectorUI::getEnabledSecondaryButtons,
700 &CachedInspectorUI::getDisabledSecondaryButtons
705 void ComposedPropertyUIUpdate::impl_fireAll_throw()
707 OSL_PRECOND( !impl_isDisposed(), "ComposedPropertyUIUpdate::impl_fireAll_throw: already disposed, this will crash!" );
709 impl_fireEnablePropertyUI_throw();
710 impl_fireShowHidePropertyUI_throw();
711 impl_fireRebuildPropertyUI_throw();
712 impl_fireShowCategory_throw();
713 impl_fireEnablePropertyUIElements_throw();
717 void SAL_CALL ComposedPropertyUIUpdate::suspendAutoFire()
719 impl_checkDisposed();
720 osl_atomic_increment( &m_nSuspendCounter );
724 void SAL_CALL ComposedPropertyUIUpdate::resumeAutoFire()
726 impl_checkDisposed();
727 if ( 0 == osl_atomic_decrement( &m_nSuspendCounter ) )
728 impl_fireAll_throw();
732 void ComposedPropertyUIUpdate::impl_checkDisposed() const
734 if ( impl_isDisposed() )
735 throw DisposedException();
739 void ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw()
741 if ( 0 == m_nSuspendCounter )
742 impl_fireAll_throw();
746 Reference< XObjectInspectorUI > const & ComposedPropertyUIUpdate::getDelegatorUI() const
748 impl_checkDisposed();
749 return m_xDelegatorUI;
753 void SAL_CALL ComposedPropertyUIUpdate::dispose()
755 if ( impl_isDisposed() )
756 return;
758 OSL_ENSURE( m_nSuspendCounter == 0, "ComposedPropertyUIUpdate::dispose: still suspended, the changes will be lost!" );
760 for ( ImplMapHandlerToUI::const_iterator singleUI = m_pCollectedUIs->aHandlers.begin();
761 singleUI != m_pCollectedUIs->aHandlers.end();
762 ++singleUI
765 singleUI->second->dispose();
767 m_pCollectedUIs.reset();
768 m_xDelegatorUI.set( nullptr );
772 bool ComposedPropertyUIUpdate::shouldContinuePropertyHandling( const OUString& _rName ) const
774 if ( !m_pPropertyCheck )
775 return true;
776 if ( m_pPropertyCheck->hasPropertyByName( _rName ) )
777 return true;
778 return false;
782 } // namespace pcr
785 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */