Bump for 3.6-28
[LibreOffice.git] / extensions / source / propctrlr / composeduiupdate.cxx
bloba3e06f6f4d23e6bb2d94f1fe37d1afc7e69a37b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "composeduiupdate.hxx"
31 /** === begin UNO includes === **/
32 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include <com/sun/star/inspection/PropertyLineElement.hpp>
35 /** === end UNO includes === **/
36 #include <osl/mutex.hxx>
37 #include <rtl/ref.hxx>
39 #include <algorithm>
41 //........................................................................
42 namespace pcr
44 //........................................................................
46 /** === begin UNO using === **/
47 using ::com::sun::star::uno::Exception;
48 using ::com::sun::star::lang::DisposedException;
49 using ::com::sun::star::lang::NullPointerException;
50 using ::com::sun::star::inspection::XPropertyHandler;
51 using ::com::sun::star::uno::Reference;
52 using ::com::sun::star::inspection::XObjectInspectorUI;
53 using ::com::sun::star::inspection::XPropertyControl;
54 using ::com::sun::star::uno::RuntimeException;
55 using ::com::sun::star::lang::NoSupportException;
56 using ::com::sun::star::inspection::XPropertyControlObserver;
57 /** === end UNO using === **/
59 namespace PropertyLineElement = ::com::sun::star::inspection::PropertyLineElement;
61 //====================================================================
62 //= helper
63 //====================================================================
64 namespace
66 struct HandlerLess : public ::std::binary_function < Reference< XPropertyHandler >
67 , Reference< XPropertyHandler >
68 , bool
71 bool operator()( const Reference< XPropertyHandler >& lhs, const Reference< XPropertyHandler >& rhs) const
73 return lhs.get() < rhs.get();
77 //================================================================
78 typedef ::std::set< ::rtl::OUString > StringBag;
79 typedef ::std::map< sal_Int16, StringBag > MapIntToStringBag;
82 //====================================================================
83 //= callbacks for CachedInspectorUI
84 //====================================================================
85 typedef void (ComposedPropertyUIUpdate::*FNotifySingleUIChange)();
87 //====================================================================
88 //= CachedInspectorUI
89 //====================================================================
90 typedef ::cppu::WeakImplHelper1 < ::com::sun::star::inspection::XObjectInspectorUI
91 > CachedInspectorUI_Base;
92 struct CachedInspectorUI : public CachedInspectorUI_Base
94 private:
95 ::osl::Mutex m_aMutex;
96 oslInterlockedCount m_refCount;
97 bool m_bDisposed;
98 ComposedPropertyUIUpdate&
99 m_rMaster;
100 FNotifySingleUIChange m_pUIChangeNotification;
102 // enablePropertyUI cache
103 StringBag aEnabledProperties;
104 StringBag aDisabledProperties;
106 // show/hidePropertyUI cache
107 StringBag aShownProperties;
108 StringBag aHiddenProperties;
110 // rebuildPropertyUI cache
111 StringBag aRebuiltProperties;
113 // showCategory cache
114 StringBag aShownCategories;
115 StringBag aHiddenCategories;
117 // enablePropertyUIElements cache
118 MapIntToStringBag aEnabledElements;
119 MapIntToStringBag aDisabledElements;
121 public:
122 typedef StringBag& (CachedInspectorUI::*FGetStringBag)();
124 // enablePropertyUI cache
125 StringBag& getEnabledProperties() { return aEnabledProperties; }
126 StringBag& getDisabledProperties() { return aDisabledProperties; }
128 // show/hidePropertyUI cache
129 StringBag& getShownProperties() { return aShownProperties; }
130 StringBag& getHiddenProperties() { return aHiddenProperties; }
132 // rebuildPropertyUI cache
133 StringBag& getRebuiltProperties() { return aRebuiltProperties; }
135 // showCategory cache
136 StringBag& getShownCategories() { return aShownCategories; }
137 StringBag& getHiddenCategories() { return aHiddenCategories; }
139 // enablePropertyUIElements
140 StringBag& getEnabledInputControls() { return aEnabledElements[ PropertyLineElement::InputControl ]; }
141 StringBag& getDisabledInputControls() { return aDisabledElements[ PropertyLineElement::InputControl ]; }
142 StringBag& getEnabledPrimaryButtons() { return aEnabledElements[ PropertyLineElement::PrimaryButton ]; }
143 StringBag& getDisabledPrimaryButtons() { return aDisabledElements[ PropertyLineElement::PrimaryButton ]; }
144 StringBag& getEnabledSecondaryButtons() { return aEnabledElements[ PropertyLineElement::SecondaryButton ]; }
145 StringBag& getDisabledSecondaryButtons() { return aDisabledElements[ PropertyLineElement::SecondaryButton ]; }
147 public:
148 CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster, FNotifySingleUIChange _pUIChangeNotification );
150 /// disposes the instance
151 void dispose();
153 // XObjectInspectorUI overridables
154 virtual void SAL_CALL enablePropertyUI( const ::rtl::OUString& _rPropertyName, ::sal_Bool _bEnable ) throw (RuntimeException);
155 virtual void SAL_CALL enablePropertyUIElements( const ::rtl::OUString& _rPropertyName, ::sal_Int16 _nElements, ::sal_Bool _bEnable ) throw (RuntimeException);
156 virtual void SAL_CALL rebuildPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException);
157 virtual void SAL_CALL showPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException);
158 virtual void SAL_CALL hidePropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException);
159 virtual void SAL_CALL showCategory( const ::rtl::OUString& _rCategory, ::sal_Bool _bShow ) throw (RuntimeException);
160 virtual Reference< XPropertyControl > SAL_CALL getPropertyControl( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException);
161 virtual void SAL_CALL registerControlObserver( const Reference< XPropertyControlObserver >& Observer ) throw (RuntimeException);
162 virtual void SAL_CALL revokeControlObserver( const Reference< XPropertyControlObserver >& Observer ) throw (RuntimeException);
163 virtual void SAL_CALL setHelpSectionText( const ::rtl::OUString& _HelpText ) throw (NoSupportException, RuntimeException);
165 // UNOCompatibleNonUNOReference overridables
166 virtual void SAL_CALL acquire() throw();
167 virtual void SAL_CALL release() throw();
169 protected:
170 ~CachedInspectorUI();
172 /// determines whether the instance is already disposed
173 inline bool isDisposed() const { return m_bDisposed; }
175 /// throws an exception if the component is already disposed
176 void checkDisposed() const;
178 private:
179 void impl_markElementEnabledOrDisabled( const ::rtl::OUString& _rPropertyName, sal_Int16 _nElementIdOrZero, sal_Bool _bEnable );
181 /** calls <member>m_pUIChangeNotification</member> at <member>m_rMaster</member>
183 void impl_notifySingleUIChange() const;
185 private:
186 CachedInspectorUI( const CachedInspectorUI& ); // never implemented
187 CachedInspectorUI& operator=( const CachedInspectorUI& ); // never implemented
189 private:
190 class MethodGuard;
191 friend class MethodGuard;
192 class MethodGuard : public ::osl::MutexGuard
194 public:
195 MethodGuard( CachedInspectorUI& rInstance )
196 : ::osl::MutexGuard( rInstance.m_aMutex )
198 rInstance.checkDisposed();
203 //----------------------------------------------------------------
204 CachedInspectorUI::CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster, FNotifySingleUIChange _pUIChangeNotification )
205 :m_refCount( 0 )
206 ,m_bDisposed( false )
207 ,m_rMaster( _rMaster )
208 ,m_pUIChangeNotification( _pUIChangeNotification )
212 //----------------------------------------------------------------
213 CachedInspectorUI::~CachedInspectorUI()
217 //----------------------------------------------------------------
218 void CachedInspectorUI::dispose()
220 ::osl::MutexGuard aGuard( m_aMutex );
221 m_bDisposed = true;
223 clearContainer( aEnabledProperties );
224 clearContainer( aDisabledProperties );
225 clearContainer( aRebuiltProperties );
226 clearContainer( aShownProperties );
227 clearContainer( aHiddenProperties );
228 clearContainer( aShownCategories );
229 clearContainer( aHiddenCategories );
230 clearContainer( aEnabledElements );
231 clearContainer( aDisabledElements );
234 //----------------------------------------------------------------
235 void SAL_CALL CachedInspectorUI::acquire() throw()
237 osl_incrementInterlockedCount( &m_refCount );
240 //----------------------------------------------------------------
241 void SAL_CALL CachedInspectorUI::release() throw()
243 if ( 0 == osl_decrementInterlockedCount( &m_refCount ) )
244 delete this;
248 //----------------------------------------------------------------
249 void CachedInspectorUI::checkDisposed() const
251 if ( isDisposed() )
252 throw DisposedException();
255 //----------------------------------------------------------------
256 namespace
258 void lcl_markStringKeyPositiveOrNegative( const ::rtl::OUString& _rKeyName, StringBag& _rPositives, StringBag& _rNegatives, sal_Bool _bMarkPositive )
260 if ( _bMarkPositive )
262 _rPositives.insert( _rKeyName );
263 // if the same key has been remember as in the "negative" list before, clear this information, since it's overruled
264 _rNegatives.erase( _rKeyName );
266 else
267 _rNegatives.insert( _rKeyName );
271 //----------------------------------------------------------------
272 void CachedInspectorUI::enablePropertyUI( const ::rtl::OUString& _rPropertyName, sal_Bool _bEnable ) throw (RuntimeException)
274 MethodGuard aGuard( *this );
275 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
276 return;
278 lcl_markStringKeyPositiveOrNegative( _rPropertyName, aEnabledProperties, aDisabledProperties, _bEnable );
279 impl_notifySingleUIChange();
282 //----------------------------------------------------------------
283 void CachedInspectorUI::impl_markElementEnabledOrDisabled( const ::rtl::OUString& _rPropertyName, sal_Int16 _nElementIdOrZero, sal_Bool _bEnable )
285 if ( _nElementIdOrZero == 0 )
286 return;
288 lcl_markStringKeyPositiveOrNegative(
289 _rPropertyName,
290 aEnabledElements[ _nElementIdOrZero ],
291 aDisabledElements[ _nElementIdOrZero ],
292 _bEnable
296 //----------------------------------------------------------------
297 void CachedInspectorUI::impl_notifySingleUIChange() const
299 (m_rMaster.*m_pUIChangeNotification)();
302 //----------------------------------------------------------------
303 void CachedInspectorUI::enablePropertyUIElements( const ::rtl::OUString& _rPropertyName, sal_Int16 _nElements, sal_Bool _bEnable ) throw (RuntimeException)
305 MethodGuard aGuard( *this );
306 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
307 return;
309 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::InputControl, _bEnable );
310 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::PrimaryButton, _bEnable );
311 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::SecondaryButton, _bEnable );
313 impl_notifySingleUIChange();
316 //----------------------------------------------------------------
317 void CachedInspectorUI::rebuildPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
319 MethodGuard aGuard( *this );
320 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
321 return;
323 aRebuiltProperties.insert( _rPropertyName );
325 impl_notifySingleUIChange();
328 //----------------------------------------------------------------
329 void CachedInspectorUI::showPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
331 MethodGuard aGuard( *this );
332 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
333 return;
335 aShownProperties.insert( _rPropertyName );
336 // if the same category has been hidden before, clear this information, since it's overruled
337 aHiddenProperties.erase( _rPropertyName );
339 impl_notifySingleUIChange();
342 //----------------------------------------------------------------
343 void CachedInspectorUI::hidePropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
345 MethodGuard aGuard( *this );
346 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
347 return;
349 aHiddenProperties.insert( _rPropertyName );
350 impl_notifySingleUIChange();
353 //----------------------------------------------------------------
354 void CachedInspectorUI::showCategory( const ::rtl::OUString& _rCategory, sal_Bool _bShow ) throw (RuntimeException)
356 MethodGuard aGuard( *this );
358 lcl_markStringKeyPositiveOrNegative( _rCategory, aShownCategories, aHiddenCategories, _bShow );
359 impl_notifySingleUIChange();
362 //----------------------------------------------------------------
363 Reference< XPropertyControl > SAL_CALL CachedInspectorUI::getPropertyControl( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
365 MethodGuard aGuard( *this );
366 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
367 return Reference< XPropertyControl >();
369 return m_rMaster.getDelegatorUI()->getPropertyControl( _rPropertyName );
372 //--------------------------------------------------------------------
373 void SAL_CALL CachedInspectorUI::registerControlObserver( const Reference< XPropertyControlObserver >& _Observer ) throw (RuntimeException)
375 OSL_FAIL( "CachedInspectorUI::registerControlObserver: not expected to be called!" );
376 // CachedInspectorUI is used as context for the controls, and we don't expect them to
377 // register listeners themself
378 m_rMaster.getDelegatorUI()->registerControlObserver( _Observer );
381 //--------------------------------------------------------------------
382 void SAL_CALL CachedInspectorUI::revokeControlObserver( const Reference< XPropertyControlObserver >& _Observer ) throw (RuntimeException)
384 OSL_FAIL( "CachedInspectorUI::revokeControlObserver: not expected to be called!" );
385 // CachedInspectorUI is used as context for the controls, and we don't expect them to
386 // register listeners themself
387 m_rMaster.getDelegatorUI()->revokeControlObserver( _Observer );
390 //----------------------------------------------------------------
391 void SAL_CALL CachedInspectorUI::setHelpSectionText( const ::rtl::OUString& _HelpText ) throw (NoSupportException, RuntimeException)
393 m_rMaster.getDelegatorUI()->setHelpSectionText( _HelpText );
396 //====================================================================
397 //= HandlerMap
398 //====================================================================
399 typedef ::std::map < Reference< XPropertyHandler >
400 , ::rtl::Reference< CachedInspectorUI >
401 , HandlerLess
402 > ImplMapHandlerToUI;
403 struct MapHandlerToUI
405 ImplMapHandlerToUI aHandlers;
408 //====================================================================
409 //= ComposedPropertyUIUpdate
410 //====================================================================
411 //----------------------------------------------------------------
412 ComposedPropertyUIUpdate::ComposedPropertyUIUpdate( const Reference< XObjectInspectorUI >& _rxDelegatorUI,
413 IPropertyExistenceCheck* _pPropertyCheck )
414 :m_pCollectedUIs( new MapHandlerToUI )
415 ,m_xDelegatorUI( _rxDelegatorUI )
416 ,m_nSuspendCounter( 0 )
417 ,m_pPropertyCheck( _pPropertyCheck )
419 if ( !m_xDelegatorUI.is() )
420 throw NullPointerException();
423 //----------------------------------------------------------------
424 ComposedPropertyUIUpdate::~ComposedPropertyUIUpdate( )
428 //----------------------------------------------------------------
429 Reference< XObjectInspectorUI > ComposedPropertyUIUpdate::getUIForPropertyHandler( const Reference< XPropertyHandler >& _rxHandler )
431 impl_checkDisposed();
433 ::rtl::Reference< CachedInspectorUI >& rUI = m_pCollectedUIs->aHandlers[ _rxHandler ];
434 if ( !rUI.is() )
435 rUI = new CachedInspectorUI( *this, &ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw );
436 return rUI.get();
439 //----------------------------------------------------------------
440 namespace
442 //============================================================
443 //= StringBagCollector
444 //============================================================
445 /** an STL-compatible structure which collects strings from a CachedInspectorUI instances
447 struct StringBagCollector : public ::std::unary_function< ImplMapHandlerToUI::value_type, void >
449 private:
450 StringBag& m_rBag;
451 CachedInspectorUI::FGetStringBag m_pGetter;
453 public:
454 StringBagCollector( StringBag& _rBag, CachedInspectorUI::FGetStringBag _pGetter ) :m_rBag( _rBag ), m_pGetter( _pGetter ) { }
456 void operator()( const ImplMapHandlerToUI::value_type& _rUI )
458 StringBag& rBag( ((_rUI.second.get())->*m_pGetter)() );
459 m_rBag.insert( rBag.begin(), rBag.end() );
462 static void collectAll( StringBag& _rAll, const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
464 ::std::for_each( _rMap.begin(), _rMap.end(), StringBagCollector( _rAll, _pGetter ) );
468 //============================================================
469 //= StringBagClearer
470 //============================================================
471 /** an STL-compatible structure which cleans a certain string bag in a CachedInspectorUI instances
473 struct StringBagClearer : public ::std::unary_function< ImplMapHandlerToUI::value_type, void >
475 private:
476 CachedInspectorUI::FGetStringBag m_pGetter;
478 public:
479 StringBagClearer( CachedInspectorUI::FGetStringBag _pGetter ) :m_pGetter( _pGetter ) { }
481 void operator()( const ImplMapHandlerToUI::value_type& _rUI )
483 clearContainer( ((_rUI.second.get())->*m_pGetter)() );
486 static void clearAll( const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
488 ::std::for_each( _rMap.begin(), _rMap.end(), StringBagClearer( _pGetter ) );
492 //============================================================
493 //= FPropertyUISetter
494 //============================================================
495 /** a typedef for a ->XObjectInspectorUI member function taking a string
497 typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUISetter )( const ::rtl::OUString& );
499 //============================================================
500 //= PropertyUIOperator
501 //============================================================
502 /** an STL-compatible struct which calls a certain member method (taking a string) at a
503 given ->XObjectInspectorUI instance
505 struct PropertyUIOperator : public ::std::unary_function< ::rtl::OUString, void >
507 private:
508 Reference< XObjectInspectorUI > m_xUpdater;
509 FPropertyUISetter m_pSetter;
511 public:
512 PropertyUIOperator( const Reference< XObjectInspectorUI >& _rxInspectorUI, FPropertyUISetter _pSetter )
513 :m_xUpdater( _rxInspectorUI )
514 ,m_pSetter( _pSetter )
518 void operator()( const ::rtl::OUString& _rPropertyName )
520 ((m_xUpdater.get())->*m_pSetter)( _rPropertyName );
523 static void forEach( const StringBag& _rProperties, const Reference< XObjectInspectorUI >& _rxDelegatorUI, FPropertyUISetter _pSetter )
525 ::std::for_each( _rProperties.begin(), _rProperties.end(), PropertyUIOperator( _rxDelegatorUI, _pSetter ) );
529 //============================================================
530 //= IStringKeyBooleanUIUpdate
531 //============================================================
532 /** an interface which encapsulates access to a single aspect of the ->XObjectInspectorUI,
533 where this aspect is given by a string key, and has a boolean value.
535 class IStringKeyBooleanUIUpdate
537 public:
538 virtual void updateUIForKey( const ::rtl::OUString& _rKey, sal_Bool _bFlag ) const = 0;
540 virtual ~IStringKeyBooleanUIUpdate() { }
543 //============================================================
544 //= FPropertyUIFlagSetter
545 //============================================================
546 /** an implementation of the ->IStringKeyBooleanUIUpdate interface which,
547 for a fixed ->XObjectInspectorUI instance and a fixed UI element (->PropertyLineElement),
548 updates this element for a given property with a given boolean flag
549 (->XObjectInspectorUI::enablePropertyUIElements)
551 class EnablePropertyUIElement : public IStringKeyBooleanUIUpdate
553 private:
554 Reference< XObjectInspectorUI > m_xUIUpdate;
555 sal_Int16 m_nElement;
557 public:
558 EnablePropertyUIElement( const Reference< XObjectInspectorUI >& _rxUIUpdate, sal_Int16 _nElement )
559 :m_xUIUpdate( _rxUIUpdate )
560 ,m_nElement( _nElement )
563 // IStringKeyBooleanUIUpdate
564 virtual void updateUIForKey( const ::rtl::OUString& _rKey, sal_Bool _bFlag ) const;
567 //............................................................
568 void EnablePropertyUIElement::updateUIForKey( const ::rtl::OUString& _rKey, sal_Bool _bFlag ) const
570 m_xUIUpdate->enablePropertyUIElements( _rKey, m_nElement, _bFlag );
573 //============================================================
574 //= FPropertyUIFlagSetter
575 //============================================================
576 /** a ->XObjectInspectorUI method taking a string and a boolean
578 typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUIFlagSetter )( const ::rtl::OUString&, sal_Bool );
580 //============================================================
581 //= DefaultStringKeyBooleanUIUpdate
582 //============================================================
583 /** an implementaiton of the ->IStringKeyBooleanUIUpdate interface which calls
584 am arbitrary ->XObjectInspectorUI method taking a string and a boolean flag
586 class DefaultStringKeyBooleanUIUpdate : public IStringKeyBooleanUIUpdate
588 private:
589 Reference< XObjectInspectorUI > m_xUIUpdate;
590 FPropertyUIFlagSetter m_pSetter;
592 public:
593 DefaultStringKeyBooleanUIUpdate( const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter );
594 // IStringKeyBooleanUIUpdate
595 virtual void updateUIForKey( const ::rtl::OUString& _rKey, sal_Bool _bFlag ) const;
598 //............................................................
599 DefaultStringKeyBooleanUIUpdate::DefaultStringKeyBooleanUIUpdate( const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter )
600 :m_xUIUpdate( _rxUIUpdate )
601 ,m_pSetter( _pSetter )
605 //............................................................
606 void DefaultStringKeyBooleanUIUpdate::updateUIForKey( const ::rtl::OUString& _rKey, sal_Bool _bFlag ) const
608 ((m_xUIUpdate.get())->*m_pSetter)( _rKey, _bFlag );
611 //============================================================
612 //= BooleanUIAspectUpdate
613 //============================================================
614 /** an STL-compatible structure which applies a ->IStringKeyBooleanUIUpdate::updateUIForKey
615 operation with a fixed boolean value, for a given string value
617 struct BooleanUIAspectUpdate : public ::std::unary_function< ::rtl::OUString, void >
619 private:
620 const IStringKeyBooleanUIUpdate& m_rUpdater;
621 sal_Bool m_bFlag;
623 public:
624 BooleanUIAspectUpdate( const IStringKeyBooleanUIUpdate& _rUpdater, sal_Bool _bFlag )
625 :m_rUpdater( _rUpdater )
626 ,m_bFlag( _bFlag )
630 void operator()( const ::rtl::OUString& _rPropertyName )
632 m_rUpdater.updateUIForKey( _rPropertyName, m_bFlag );
635 static void forEach( const StringBag& _rProperties, const IStringKeyBooleanUIUpdate& _rUpdater, sal_Bool _bFlag )
637 ::std::for_each( _rProperties.begin(), _rProperties.end(), BooleanUIAspectUpdate( _rUpdater, _bFlag ) );
641 //============================================================
642 //= BooleanUIAspectUpdate
643 //============================================================
644 /** an STL-compatible structure subtracting a given string from a fixed ->StringBag
646 struct StringBagComplement : public ::std::unary_function< ::rtl::OUString, void >
648 private:
649 StringBag& m_rMinuend;
651 public:
652 StringBagComplement( StringBag& _rMinuend ) :m_rMinuend( _rMinuend ) { }
654 void operator()( const ::rtl::OUString& _rPropertyToSubtract )
656 m_rMinuend.erase( _rPropertyToSubtract );
659 static void subtract( StringBag& _rMinuend, const StringBag& _rSubtrahend )
661 ::std::for_each( _rSubtrahend.begin(), _rSubtrahend.end(), StringBagComplement( _rMinuend ) );
665 //============================================================
666 //= BooleanUIAspectUpdate
667 //============================================================
668 void lcl_fireUIStateFlag(
669 const IStringKeyBooleanUIUpdate& _rUIUpdate,
670 const ImplMapHandlerToUI& _rHandlerUIs,
671 CachedInspectorUI::FGetStringBag _pGetPositives,
672 CachedInspectorUI::FGetStringBag _pGetNegatives
675 // all strings which are in the "positive" list of one handler
676 StringBag aAllPositives;
677 StringBagCollector::collectAll( aAllPositives, _rHandlerUIs, _pGetPositives );
679 // all strings which are in the "negative" list of one handler
680 StringBag aAllNegatives;
681 StringBagCollector::collectAll( aAllNegatives, _rHandlerUIs, _pGetNegatives );
683 // propagate the "negative" flags to the delegator UI
684 BooleanUIAspectUpdate::forEach( aAllNegatives, _rUIUpdate, sal_False );
686 // propagate the "positive" flags to the delegator UI, for all elements where _no_
687 // "negative" flag exists
688 StringBagComplement::subtract( aAllPositives, aAllNegatives );
689 BooleanUIAspectUpdate::forEach( aAllPositives, _rUIUpdate, sal_True );
691 // the "positive" request can be cleared no, only negative requests
692 // (such as "disable a property" or "hide a category") need to be preserved for the next round
693 StringBagClearer::clearAll( _rHandlerUIs, _pGetPositives );
697 //----------------------------------------------------------------
698 void ComposedPropertyUIUpdate::impl_fireEnablePropertyUI_throw()
700 lcl_fireUIStateFlag(
701 DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI, &XObjectInspectorUI::enablePropertyUI ),
702 m_pCollectedUIs->aHandlers,
703 &CachedInspectorUI::getEnabledProperties,
704 &CachedInspectorUI::getDisabledProperties
708 //----------------------------------------------------------------
709 void ComposedPropertyUIUpdate::impl_fireRebuildPropertyUI_throw()
711 // collect all properties for which a rebuild request has been made
712 StringBag aAllRebuilt;
713 StringBagCollector::collectAll( aAllRebuilt, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
715 // rebuild all those properties
716 PropertyUIOperator::forEach( aAllRebuilt, m_xDelegatorUI, &XObjectInspectorUI::rebuildPropertyUI );
718 // clear the "properties to rebuild" at all handlers, since the request has been fulfilled now.
719 StringBagClearer::clearAll( m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
722 //----------------------------------------------------------------
723 void ComposedPropertyUIUpdate::impl_fireShowHidePropertyUI_throw()
725 // all properties which have been shown by at least one handler
726 StringBag aAllShown;
727 StringBagCollector::collectAll( aAllShown, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getShownProperties );
728 // all properties which have been hidden by at least one handler
729 StringBag aAllHidden;
730 StringBagCollector::collectAll( aAllHidden, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getHiddenProperties );
732 // hide properties as necessary
733 PropertyUIOperator::forEach( aAllHidden, m_xDelegatorUI, &XObjectInspectorUI::hidePropertyUI );
735 // for those properties which are hidden, ignore all "show" requests which other handlers might have had
736 StringBagComplement::subtract( aAllShown, aAllHidden );
738 // show properties
739 PropertyUIOperator::forEach( aAllShown, m_xDelegatorUI, &XObjectInspectorUI::showPropertyUI );
742 //----------------------------------------------------------------
743 void ComposedPropertyUIUpdate::impl_fireShowCategory_throw()
745 lcl_fireUIStateFlag(
746 DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI, &XObjectInspectorUI::showCategory ),
747 m_pCollectedUIs->aHandlers,
748 &CachedInspectorUI::getShownCategories,
749 &CachedInspectorUI::getHiddenCategories
753 //----------------------------------------------------------------
754 void ComposedPropertyUIUpdate::impl_fireEnablePropertyUIElements_throw()
756 lcl_fireUIStateFlag(
757 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::InputControl ),
758 m_pCollectedUIs->aHandlers,
759 &CachedInspectorUI::getEnabledInputControls,
760 &CachedInspectorUI::getDisabledInputControls
763 lcl_fireUIStateFlag(
764 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::PrimaryButton ),
765 m_pCollectedUIs->aHandlers,
766 &CachedInspectorUI::getEnabledPrimaryButtons,
767 &CachedInspectorUI::getDisabledPrimaryButtons
770 lcl_fireUIStateFlag(
771 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::SecondaryButton ),
772 m_pCollectedUIs->aHandlers,
773 &CachedInspectorUI::getEnabledSecondaryButtons,
774 &CachedInspectorUI::getDisabledSecondaryButtons
778 //--------------------------------------------------------------------
779 void ComposedPropertyUIUpdate::impl_fireAll_throw()
781 OSL_PRECOND( !impl_isDisposed(), "ComposedPropertyUIUpdate::impl_fireAll_throw: already disposed, this will crash!" );
783 impl_fireEnablePropertyUI_throw();
784 impl_fireShowHidePropertyUI_throw();
785 impl_fireRebuildPropertyUI_throw();
786 impl_fireShowCategory_throw();
787 impl_fireEnablePropertyUIElements_throw();
790 //--------------------------------------------------------------------
791 void SAL_CALL ComposedPropertyUIUpdate::suspendAutoFire()
793 impl_checkDisposed();
794 osl_incrementInterlockedCount( &m_nSuspendCounter );
797 //--------------------------------------------------------------------
798 void SAL_CALL ComposedPropertyUIUpdate::resumeAutoFire()
800 impl_checkDisposed();
801 if ( 0 == osl_decrementInterlockedCount( &m_nSuspendCounter ) )
802 impl_fireAll_throw();
805 //----------------------------------------------------------------
806 void ComposedPropertyUIUpdate::impl_checkDisposed() const
808 if ( impl_isDisposed() )
809 throw DisposedException();
812 //----------------------------------------------------------------
813 void ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw()
815 if ( 0 == m_nSuspendCounter )
816 impl_fireAll_throw();
819 //----------------------------------------------------------------
820 Reference< XObjectInspectorUI > ComposedPropertyUIUpdate::getDelegatorUI() const
822 impl_checkDisposed();
823 return m_xDelegatorUI;
826 //----------------------------------------------------------------
827 void SAL_CALL ComposedPropertyUIUpdate::dispose()
829 if ( impl_isDisposed() )
830 return;
832 OSL_ENSURE( m_nSuspendCounter == 0, "ComposedPropertyUIUpdate::dispose: still suspended, the changes will be lost!" );
834 for ( ImplMapHandlerToUI::const_iterator singleUI = m_pCollectedUIs->aHandlers.begin();
835 singleUI != m_pCollectedUIs->aHandlers.end();
836 ++singleUI
839 singleUI->second->dispose();
841 m_pCollectedUIs.reset( NULL );
842 m_xDelegatorUI.set( NULL );
845 //----------------------------------------------------------------
846 bool ComposedPropertyUIUpdate::shouldContinuePropertyHandling( const ::rtl::OUString& _rName ) const
848 if ( !m_pPropertyCheck )
849 return true;
850 if ( m_pPropertyCheck->hasPropertyByName( _rName ) )
851 return true;
852 return false;
855 //........................................................................
856 } // namespace pcr
857 //........................................................................
859 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */