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 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_extensions.hxx"
31 #include "composeduiupdate.hxx"
33 /** === begin UNO includes === **/
34 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <com/sun/star/inspection/PropertyLineElement.hpp>
37 /** === end UNO includes === **/
38 #include <osl/mutex.hxx>
39 #include <rtl/ref.hxx>
43 //........................................................................
46 //........................................................................
48 /** === begin UNO using === **/
49 using ::com::sun::star::uno::Exception
;
50 using ::com::sun::star::lang::DisposedException
;
51 using ::com::sun::star::lang::NullPointerException
;
52 using ::com::sun::star::inspection::XPropertyHandler
;
53 using ::com::sun::star::uno::Reference
;
54 using ::com::sun::star::inspection::XObjectInspectorUI
;
55 using ::com::sun::star::inspection::XPropertyControl
;
56 using ::com::sun::star::uno::RuntimeException
;
57 using ::com::sun::star::lang::NoSupportException
;
58 using ::com::sun::star::inspection::XPropertyControlObserver
;
59 /** === end UNO using === **/
61 namespace PropertyLineElement
= ::com::sun::star::inspection::PropertyLineElement
;
63 //====================================================================
65 //====================================================================
68 struct HandlerLess
: public ::std::binary_function
< Reference
< XPropertyHandler
>
69 , Reference
< XPropertyHandler
>
73 bool operator()( const Reference
< XPropertyHandler
>& lhs
, const Reference
< XPropertyHandler
>& rhs
) const
75 return lhs
.get() < rhs
.get();
79 //================================================================
80 typedef ::std::set
< ::rtl::OUString
> StringBag
;
81 typedef ::std::map
< sal_Int16
, StringBag
> MapIntToStringBag
;
84 //====================================================================
85 //= callbacks for CachedInspectorUI
86 //====================================================================
87 typedef void (ComposedPropertyUIUpdate::*FNotifySingleUIChange
)();
89 //====================================================================
91 //====================================================================
92 typedef ::cppu::WeakImplHelper1
< ::com::sun::star::inspection::XObjectInspectorUI
93 > CachedInspectorUI_Base
;
94 struct CachedInspectorUI
: public CachedInspectorUI_Base
97 ::osl::Mutex m_aMutex
;
98 oslInterlockedCount m_refCount
;
100 ComposedPropertyUIUpdate
&
102 FNotifySingleUIChange m_pUIChangeNotification
;
104 // enablePropertyUI cache
105 StringBag aEnabledProperties
;
106 StringBag aDisabledProperties
;
108 // show/hidePropertyUI cache
109 StringBag aShownProperties
;
110 StringBag aHiddenProperties
;
112 // rebuildPropertyUI cache
113 StringBag aRebuiltProperties
;
115 // showCategory cache
116 StringBag aShownCategories
;
117 StringBag aHiddenCategories
;
119 // enablePropertyUIElements cache
120 MapIntToStringBag aEnabledElements
;
121 MapIntToStringBag aDisabledElements
;
124 typedef StringBag
& (CachedInspectorUI::*FGetStringBag
)();
126 // enablePropertyUI cache
127 StringBag
& getEnabledProperties() { return aEnabledProperties
; }
128 StringBag
& getDisabledProperties() { return aDisabledProperties
; }
130 // show/hidePropertyUI cache
131 StringBag
& getShownProperties() { return aShownProperties
; }
132 StringBag
& getHiddenProperties() { return aHiddenProperties
; }
134 // rebuildPropertyUI cache
135 StringBag
& getRebuiltProperties() { return aRebuiltProperties
; }
137 // showCategory cache
138 StringBag
& getShownCategories() { return aShownCategories
; }
139 StringBag
& getHiddenCategories() { return aHiddenCategories
; }
141 // enablePropertyUIElements
142 StringBag
& getEnabledInputControls() { return aEnabledElements
[ PropertyLineElement::InputControl
]; }
143 StringBag
& getDisabledInputControls() { return aDisabledElements
[ PropertyLineElement::InputControl
]; }
144 StringBag
& getEnabledPrimaryButtons() { return aEnabledElements
[ PropertyLineElement::PrimaryButton
]; }
145 StringBag
& getDisabledPrimaryButtons() { return aDisabledElements
[ PropertyLineElement::PrimaryButton
]; }
146 StringBag
& getEnabledSecondaryButtons() { return aEnabledElements
[ PropertyLineElement::SecondaryButton
]; }
147 StringBag
& getDisabledSecondaryButtons() { return aDisabledElements
[ PropertyLineElement::SecondaryButton
]; }
150 CachedInspectorUI( ComposedPropertyUIUpdate
& _rMaster
, FNotifySingleUIChange _pUIChangeNotification
);
152 /// disposes the instance
155 // XObjectInspectorUI overridables
156 virtual void SAL_CALL
enablePropertyUI( const ::rtl::OUString
& _rPropertyName
, ::sal_Bool _bEnable
) throw (RuntimeException
);
157 virtual void SAL_CALL
enablePropertyUIElements( const ::rtl::OUString
& _rPropertyName
, ::sal_Int16 _nElements
, ::sal_Bool _bEnable
) throw (RuntimeException
);
158 virtual void SAL_CALL
rebuildPropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
);
159 virtual void SAL_CALL
showPropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
);
160 virtual void SAL_CALL
hidePropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
);
161 virtual void SAL_CALL
showCategory( const ::rtl::OUString
& _rCategory
, ::sal_Bool _bShow
) throw (RuntimeException
);
162 virtual Reference
< XPropertyControl
> SAL_CALL
getPropertyControl( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
);
163 virtual void SAL_CALL
registerControlObserver( const Reference
< XPropertyControlObserver
>& Observer
) throw (RuntimeException
);
164 virtual void SAL_CALL
revokeControlObserver( const Reference
< XPropertyControlObserver
>& Observer
) throw (RuntimeException
);
165 virtual void SAL_CALL
setHelpSectionText( const ::rtl::OUString
& _HelpText
) throw (NoSupportException
, RuntimeException
);
167 // UNOCompatibleNonUNOReference overridables
168 virtual void SAL_CALL
acquire() throw();
169 virtual void SAL_CALL
release() throw();
172 ~CachedInspectorUI();
174 /// determines whether the instance is already disposed
175 inline bool isDisposed() const { return m_bDisposed
; }
177 /// throws an exception if the component is already disposed
178 void checkDisposed() const;
181 void impl_markElementEnabledOrDisabled( const ::rtl::OUString
& _rPropertyName
, sal_Int16 _nElementIdOrZero
, sal_Bool _bEnable
);
183 /** calls <member>m_pUIChangeNotification</member> at <member>m_rMaster</member>
185 void impl_notifySingleUIChange() const;
188 CachedInspectorUI( const CachedInspectorUI
& ); // never implemented
189 CachedInspectorUI
& operator=( const CachedInspectorUI
& ); // never implemented
193 friend class MethodGuard
;
194 class MethodGuard
: public ::osl::MutexGuard
197 MethodGuard( CachedInspectorUI
& rInstance
)
198 : ::osl::MutexGuard( rInstance
.m_aMutex
)
200 rInstance
.checkDisposed();
205 //----------------------------------------------------------------
206 CachedInspectorUI::CachedInspectorUI( ComposedPropertyUIUpdate
& _rMaster
, FNotifySingleUIChange _pUIChangeNotification
)
208 ,m_bDisposed( false )
209 ,m_rMaster( _rMaster
)
210 ,m_pUIChangeNotification( _pUIChangeNotification
)
214 //----------------------------------------------------------------
215 CachedInspectorUI::~CachedInspectorUI()
219 //----------------------------------------------------------------
220 void CachedInspectorUI::dispose()
222 ::osl::MutexGuard
aGuard( m_aMutex
);
225 clearContainer( aEnabledProperties
);
226 clearContainer( aDisabledProperties
);
227 clearContainer( aRebuiltProperties
);
228 clearContainer( aShownProperties
);
229 clearContainer( aHiddenProperties
);
230 clearContainer( aShownCategories
);
231 clearContainer( aHiddenCategories
);
232 clearContainer( aEnabledElements
);
233 clearContainer( aDisabledElements
);
236 //----------------------------------------------------------------
237 void SAL_CALL
CachedInspectorUI::acquire() throw()
239 osl_incrementInterlockedCount( &m_refCount
);
242 //----------------------------------------------------------------
243 void SAL_CALL
CachedInspectorUI::release() throw()
245 if ( 0 == osl_decrementInterlockedCount( &m_refCount
) )
250 //----------------------------------------------------------------
251 void CachedInspectorUI::checkDisposed() const
254 throw DisposedException();
257 //----------------------------------------------------------------
260 void lcl_markStringKeyPositiveOrNegative( const ::rtl::OUString
& _rKeyName
, StringBag
& _rPositives
, StringBag
& _rNegatives
, sal_Bool _bMarkPositive
)
262 if ( _bMarkPositive
)
264 _rPositives
.insert( _rKeyName
);
265 // if the same key has been remember as in the "negative" list before, clear this information, since it's overruled
266 _rNegatives
.erase( _rKeyName
);
269 _rNegatives
.insert( _rKeyName
);
273 //----------------------------------------------------------------
274 void CachedInspectorUI::enablePropertyUI( const ::rtl::OUString
& _rPropertyName
, sal_Bool _bEnable
) throw (RuntimeException
)
276 MethodGuard
aGuard( *this );
277 if ( !m_rMaster
.shouldContinuePropertyHandling( _rPropertyName
) )
280 lcl_markStringKeyPositiveOrNegative( _rPropertyName
, aEnabledProperties
, aDisabledProperties
, _bEnable
);
281 impl_notifySingleUIChange();
284 //----------------------------------------------------------------
285 void CachedInspectorUI::impl_markElementEnabledOrDisabled( const ::rtl::OUString
& _rPropertyName
, sal_Int16 _nElementIdOrZero
, sal_Bool _bEnable
)
287 if ( _nElementIdOrZero
== 0 )
290 lcl_markStringKeyPositiveOrNegative(
292 aEnabledElements
[ _nElementIdOrZero
],
293 aDisabledElements
[ _nElementIdOrZero
],
298 //----------------------------------------------------------------
299 void CachedInspectorUI::impl_notifySingleUIChange() const
301 (m_rMaster
.*m_pUIChangeNotification
)();
304 //----------------------------------------------------------------
305 void CachedInspectorUI::enablePropertyUIElements( const ::rtl::OUString
& _rPropertyName
, sal_Int16 _nElements
, sal_Bool _bEnable
) throw (RuntimeException
)
307 MethodGuard
aGuard( *this );
308 if ( !m_rMaster
.shouldContinuePropertyHandling( _rPropertyName
) )
311 impl_markElementEnabledOrDisabled( _rPropertyName
, _nElements
& PropertyLineElement::InputControl
, _bEnable
);
312 impl_markElementEnabledOrDisabled( _rPropertyName
, _nElements
& PropertyLineElement::PrimaryButton
, _bEnable
);
313 impl_markElementEnabledOrDisabled( _rPropertyName
, _nElements
& PropertyLineElement::SecondaryButton
, _bEnable
);
315 impl_notifySingleUIChange();
318 //----------------------------------------------------------------
319 void CachedInspectorUI::rebuildPropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
321 MethodGuard
aGuard( *this );
322 if ( !m_rMaster
.shouldContinuePropertyHandling( _rPropertyName
) )
325 aRebuiltProperties
.insert( _rPropertyName
);
327 impl_notifySingleUIChange();
330 //----------------------------------------------------------------
331 void CachedInspectorUI::showPropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
333 MethodGuard
aGuard( *this );
334 if ( !m_rMaster
.shouldContinuePropertyHandling( _rPropertyName
) )
337 aShownProperties
.insert( _rPropertyName
);
338 // if the same category has been hidden before, clear this information, since it's overruled
339 aHiddenProperties
.erase( _rPropertyName
);
341 impl_notifySingleUIChange();
344 //----------------------------------------------------------------
345 void CachedInspectorUI::hidePropertyUI( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
347 MethodGuard
aGuard( *this );
348 if ( !m_rMaster
.shouldContinuePropertyHandling( _rPropertyName
) )
351 aHiddenProperties
.insert( _rPropertyName
);
352 impl_notifySingleUIChange();
355 //----------------------------------------------------------------
356 void CachedInspectorUI::showCategory( const ::rtl::OUString
& _rCategory
, sal_Bool _bShow
) throw (RuntimeException
)
358 MethodGuard
aGuard( *this );
360 lcl_markStringKeyPositiveOrNegative( _rCategory
, aShownCategories
, aHiddenCategories
, _bShow
);
361 impl_notifySingleUIChange();
364 //----------------------------------------------------------------
365 Reference
< XPropertyControl
> SAL_CALL
CachedInspectorUI::getPropertyControl( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
367 MethodGuard
aGuard( *this );
368 if ( !m_rMaster
.shouldContinuePropertyHandling( _rPropertyName
) )
369 return Reference
< XPropertyControl
>();
371 return m_rMaster
.getDelegatorUI()->getPropertyControl( _rPropertyName
);
374 //--------------------------------------------------------------------
375 void SAL_CALL
CachedInspectorUI::registerControlObserver( const Reference
< XPropertyControlObserver
>& _Observer
) throw (RuntimeException
)
377 OSL_ENSURE( false, "CachedInspectorUI::registerControlObserver: not expected to be called!" );
378 // CachedInspectorUI is used as context for the controls, and we don't expect them to
379 // register listeners themself
380 m_rMaster
.getDelegatorUI()->registerControlObserver( _Observer
);
383 //--------------------------------------------------------------------
384 void SAL_CALL
CachedInspectorUI::revokeControlObserver( const Reference
< XPropertyControlObserver
>& _Observer
) throw (RuntimeException
)
386 OSL_ENSURE( false, "CachedInspectorUI::revokeControlObserver: not expected to be called!" );
387 // CachedInspectorUI is used as context for the controls, and we don't expect them to
388 // register listeners themself
389 m_rMaster
.getDelegatorUI()->revokeControlObserver( _Observer
);
392 //----------------------------------------------------------------
393 void SAL_CALL
CachedInspectorUI::setHelpSectionText( const ::rtl::OUString
& _HelpText
) throw (NoSupportException
, RuntimeException
)
395 m_rMaster
.getDelegatorUI()->setHelpSectionText( _HelpText
);
398 //====================================================================
400 //====================================================================
401 typedef ::std::map
< Reference
< XPropertyHandler
>
402 , ::rtl::Reference
< CachedInspectorUI
>
404 > ImplMapHandlerToUI
;
405 struct MapHandlerToUI
407 ImplMapHandlerToUI aHandlers
;
410 //====================================================================
411 //= ComposedPropertyUIUpdate
412 //====================================================================
413 //----------------------------------------------------------------
414 ComposedPropertyUIUpdate::ComposedPropertyUIUpdate( const Reference
< XObjectInspectorUI
>& _rxDelegatorUI
,
415 IPropertyExistenceCheck
* _pPropertyCheck
)
416 :m_pCollectedUIs( new MapHandlerToUI
)
417 ,m_xDelegatorUI( _rxDelegatorUI
)
418 ,m_nSuspendCounter( 0 )
419 ,m_pPropertyCheck( _pPropertyCheck
)
421 if ( !m_xDelegatorUI
.is() )
422 throw NullPointerException();
425 //----------------------------------------------------------------
426 ComposedPropertyUIUpdate::~ComposedPropertyUIUpdate( )
430 //----------------------------------------------------------------
431 Reference
< XObjectInspectorUI
> ComposedPropertyUIUpdate::getUIForPropertyHandler( const Reference
< XPropertyHandler
>& _rxHandler
)
433 impl_checkDisposed();
435 ::rtl::Reference
< CachedInspectorUI
>& rUI
= m_pCollectedUIs
->aHandlers
[ _rxHandler
];
437 rUI
= new CachedInspectorUI( *this, &ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw
);
441 //----------------------------------------------------------------
444 //============================================================
445 //= StringBagCollector
446 //============================================================
447 /** an STL-compatible structure which collects strings from a CachedInspectorUI instances
449 struct StringBagCollector
: public ::std::unary_function
< ImplMapHandlerToUI::value_type
, void >
453 CachedInspectorUI::FGetStringBag m_pGetter
;
456 StringBagCollector( StringBag
& _rBag
, CachedInspectorUI::FGetStringBag _pGetter
) :m_rBag( _rBag
), m_pGetter( _pGetter
) { }
458 void operator()( const ImplMapHandlerToUI::value_type
& _rUI
)
460 StringBag
& rBag( ((_rUI
.second
.get())->*m_pGetter
)() );
461 m_rBag
.insert( rBag
.begin(), rBag
.end() );
464 static void collectAll( StringBag
& _rAll
, const ImplMapHandlerToUI
& _rMap
, CachedInspectorUI::FGetStringBag _pGetter
)
466 ::std::for_each( _rMap
.begin(), _rMap
.end(), StringBagCollector( _rAll
, _pGetter
) );
470 //============================================================
472 //============================================================
473 /** an STL-compatible structure which cleans a certain string bag in a CachedInspectorUI instances
475 struct StringBagClearer
: public ::std::unary_function
< ImplMapHandlerToUI::value_type
, void >
478 CachedInspectorUI::FGetStringBag m_pGetter
;
481 StringBagClearer( CachedInspectorUI::FGetStringBag _pGetter
) :m_pGetter( _pGetter
) { }
483 void operator()( const ImplMapHandlerToUI::value_type
& _rUI
)
485 clearContainer( ((_rUI
.second
.get())->*m_pGetter
)() );
488 static void clearAll( const ImplMapHandlerToUI
& _rMap
, CachedInspectorUI::FGetStringBag _pGetter
)
490 ::std::for_each( _rMap
.begin(), _rMap
.end(), StringBagClearer( _pGetter
) );
494 //============================================================
495 //= FPropertyUISetter
496 //============================================================
497 /** a typedef for a ->XObjectInspectorUI member function taking a string
499 typedef void ( SAL_CALL
XObjectInspectorUI::*FPropertyUISetter
)( const ::rtl::OUString
& );
501 //============================================================
502 //= PropertyUIOperator
503 //============================================================
504 /** an STL-compatible struct which calls a certain member method (taking a string) at a
505 given ->XObjectInspectorUI instance
507 struct PropertyUIOperator
: public ::std::unary_function
< ::rtl::OUString
, void >
510 Reference
< XObjectInspectorUI
> m_xUpdater
;
511 FPropertyUISetter m_pSetter
;
514 PropertyUIOperator( const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, FPropertyUISetter _pSetter
)
515 :m_xUpdater( _rxInspectorUI
)
516 ,m_pSetter( _pSetter
)
520 void operator()( const ::rtl::OUString
& _rPropertyName
)
522 ((m_xUpdater
.get())->*m_pSetter
)( _rPropertyName
);
525 static void forEach( const StringBag
& _rProperties
, const Reference
< XObjectInspectorUI
>& _rxDelegatorUI
, FPropertyUISetter _pSetter
)
527 ::std::for_each( _rProperties
.begin(), _rProperties
.end(), PropertyUIOperator( _rxDelegatorUI
, _pSetter
) );
531 //============================================================
532 //= IStringKeyBooleanUIUpdate
533 //============================================================
534 /** an interface which encapsulates access to a single aspect of the ->XObjectInspectorUI,
535 where this aspect is given by a string key, and has a boolean value.
537 class IStringKeyBooleanUIUpdate
540 virtual void updateUIForKey( const ::rtl::OUString
& _rKey
, sal_Bool _bFlag
) const = 0;
542 virtual ~IStringKeyBooleanUIUpdate() { }
545 //============================================================
546 //= FPropertyUIFlagSetter
547 //============================================================
548 /** an implementation of the ->IStringKeyBooleanUIUpdate interface which,
549 for a fixed ->XObjectInspectorUI instance and a fixed UI element (->PropertyLineElement),
550 updates this element for a given property with a given boolean flag
551 (->XObjectInspectorUI::enablePropertyUIElements)
553 class EnablePropertyUIElement
: public IStringKeyBooleanUIUpdate
556 Reference
< XObjectInspectorUI
> m_xUIUpdate
;
557 sal_Int16 m_nElement
;
560 EnablePropertyUIElement( const Reference
< XObjectInspectorUI
>& _rxUIUpdate
, sal_Int16 _nElement
)
561 :m_xUIUpdate( _rxUIUpdate
)
562 ,m_nElement( _nElement
)
565 // IStringKeyBooleanUIUpdate
566 virtual void updateUIForKey( const ::rtl::OUString
& _rKey
, sal_Bool _bFlag
) const;
569 //............................................................
570 void EnablePropertyUIElement::updateUIForKey( const ::rtl::OUString
& _rKey
, sal_Bool _bFlag
) const
572 m_xUIUpdate
->enablePropertyUIElements( _rKey
, m_nElement
, _bFlag
);
575 //============================================================
576 //= FPropertyUIFlagSetter
577 //============================================================
578 /** a ->XObjectInspectorUI method taking a string and a boolean
580 typedef void ( SAL_CALL
XObjectInspectorUI::*FPropertyUIFlagSetter
)( const ::rtl::OUString
&, sal_Bool
);
582 //============================================================
583 //= DefaultStringKeyBooleanUIUpdate
584 //============================================================
585 /** an implementaiton of the ->IStringKeyBooleanUIUpdate interface which calls
586 am arbitrary ->XObjectInspectorUI method taking a string and a boolean flag
588 class DefaultStringKeyBooleanUIUpdate
: public IStringKeyBooleanUIUpdate
591 Reference
< XObjectInspectorUI
> m_xUIUpdate
;
592 FPropertyUIFlagSetter m_pSetter
;
595 DefaultStringKeyBooleanUIUpdate( const Reference
< XObjectInspectorUI
>& _rxUIUpdate
, FPropertyUIFlagSetter _pSetter
);
596 // IStringKeyBooleanUIUpdate
597 virtual void updateUIForKey( const ::rtl::OUString
& _rKey
, sal_Bool _bFlag
) const;
600 //............................................................
601 DefaultStringKeyBooleanUIUpdate::DefaultStringKeyBooleanUIUpdate( const Reference
< XObjectInspectorUI
>& _rxUIUpdate
, FPropertyUIFlagSetter _pSetter
)
602 :m_xUIUpdate( _rxUIUpdate
)
603 ,m_pSetter( _pSetter
)
607 //............................................................
608 void DefaultStringKeyBooleanUIUpdate::updateUIForKey( const ::rtl::OUString
& _rKey
, sal_Bool _bFlag
) const
610 ((m_xUIUpdate
.get())->*m_pSetter
)( _rKey
, _bFlag
);
613 //============================================================
614 //= BooleanUIAspectUpdate
615 //============================================================
616 /** an STL-compatible structure which applies a ->IStringKeyBooleanUIUpdate::updateUIForKey
617 operation with a fixed boolean value, for a given string value
619 struct BooleanUIAspectUpdate
: public ::std::unary_function
< ::rtl::OUString
, void >
622 const IStringKeyBooleanUIUpdate
& m_rUpdater
;
626 BooleanUIAspectUpdate( const IStringKeyBooleanUIUpdate
& _rUpdater
, sal_Bool _bFlag
)
627 :m_rUpdater( _rUpdater
)
632 void operator()( const ::rtl::OUString
& _rPropertyName
)
634 m_rUpdater
.updateUIForKey( _rPropertyName
, m_bFlag
);
637 static void forEach( const StringBag
& _rProperties
, const IStringKeyBooleanUIUpdate
& _rUpdater
, sal_Bool _bFlag
)
639 ::std::for_each( _rProperties
.begin(), _rProperties
.end(), BooleanUIAspectUpdate( _rUpdater
, _bFlag
) );
643 //============================================================
644 //= BooleanUIAspectUpdate
645 //============================================================
646 /** an STL-compatible structure subtracting a given string from a fixed ->StringBag
648 struct StringBagComplement
: public ::std::unary_function
< ::rtl::OUString
, void >
651 StringBag
& m_rMinuend
;
654 StringBagComplement( StringBag
& _rMinuend
) :m_rMinuend( _rMinuend
) { }
656 void operator()( const ::rtl::OUString
& _rPropertyToSubtract
)
658 m_rMinuend
.erase( _rPropertyToSubtract
);
661 static void subtract( StringBag
& _rMinuend
, const StringBag
& _rSubtrahend
)
663 ::std::for_each( _rSubtrahend
.begin(), _rSubtrahend
.end(), StringBagComplement( _rMinuend
) );
667 //============================================================
668 //= BooleanUIAspectUpdate
669 //============================================================
670 void lcl_fireUIStateFlag(
671 const IStringKeyBooleanUIUpdate
& _rUIUpdate
,
672 const ImplMapHandlerToUI
& _rHandlerUIs
,
673 CachedInspectorUI::FGetStringBag _pGetPositives
,
674 CachedInspectorUI::FGetStringBag _pGetNegatives
677 // all strings which are in the "positive" list of one handler
678 StringBag aAllPositives
;
679 StringBagCollector::collectAll( aAllPositives
, _rHandlerUIs
, _pGetPositives
);
681 // all strings which are in the "negative" list of one handler
682 StringBag aAllNegatives
;
683 StringBagCollector::collectAll( aAllNegatives
, _rHandlerUIs
, _pGetNegatives
);
685 // propagate the "negative" flags to the delegator UI
686 BooleanUIAspectUpdate::forEach( aAllNegatives
, _rUIUpdate
, sal_False
);
688 // propagate the "positive" flags to the delegator UI, for all elements where _no_
689 // "negative" flag exists
690 StringBagComplement::subtract( aAllPositives
, aAllNegatives
);
691 BooleanUIAspectUpdate::forEach( aAllPositives
, _rUIUpdate
, sal_True
);
693 // the "positive" request can be cleared no, only negative requests
694 // (such as "disable a property" or "hide a category") need to be preserved for the next round
695 StringBagClearer::clearAll( _rHandlerUIs
, _pGetPositives
);
699 //----------------------------------------------------------------
700 void ComposedPropertyUIUpdate::impl_fireEnablePropertyUI_throw()
703 DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI
, &XObjectInspectorUI::enablePropertyUI
),
704 m_pCollectedUIs
->aHandlers
,
705 &CachedInspectorUI::getEnabledProperties
,
706 &CachedInspectorUI::getDisabledProperties
710 //----------------------------------------------------------------
711 void ComposedPropertyUIUpdate::impl_fireRebuildPropertyUI_throw()
713 // collect all properties for which a rebuild request has been made
714 StringBag aAllRebuilt
;
715 StringBagCollector::collectAll( aAllRebuilt
, m_pCollectedUIs
->aHandlers
, &CachedInspectorUI::getRebuiltProperties
);
717 // rebuild all those properties
718 PropertyUIOperator::forEach( aAllRebuilt
, m_xDelegatorUI
, &XObjectInspectorUI::rebuildPropertyUI
);
720 // clear the "properties to rebuild" at all handlers, since the request has been fulfilled now.
721 StringBagClearer::clearAll( m_pCollectedUIs
->aHandlers
, &CachedInspectorUI::getRebuiltProperties
);
724 //----------------------------------------------------------------
725 void ComposedPropertyUIUpdate::impl_fireShowHidePropertyUI_throw()
727 // all properties which have been shown by at least one handler
729 StringBagCollector::collectAll( aAllShown
, m_pCollectedUIs
->aHandlers
, &CachedInspectorUI::getShownProperties
);
730 // all properties which have been hidden by at least one handler
731 StringBag aAllHidden
;
732 StringBagCollector::collectAll( aAllHidden
, m_pCollectedUIs
->aHandlers
, &CachedInspectorUI::getHiddenProperties
);
734 // hide properties as necessary
735 PropertyUIOperator::forEach( aAllHidden
, m_xDelegatorUI
, &XObjectInspectorUI::hidePropertyUI
);
737 // for those properties which are hidden, ignore all "show" requests which other handlers might have had
738 StringBagComplement::subtract( aAllShown
, aAllHidden
);
741 PropertyUIOperator::forEach( aAllShown
, m_xDelegatorUI
, &XObjectInspectorUI::showPropertyUI
);
744 //----------------------------------------------------------------
745 void ComposedPropertyUIUpdate::impl_fireShowCategory_throw()
748 DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI
, &XObjectInspectorUI::showCategory
),
749 m_pCollectedUIs
->aHandlers
,
750 &CachedInspectorUI::getShownCategories
,
751 &CachedInspectorUI::getHiddenCategories
755 //----------------------------------------------------------------
756 void ComposedPropertyUIUpdate::impl_fireEnablePropertyUIElements_throw()
759 EnablePropertyUIElement( m_xDelegatorUI
, PropertyLineElement::InputControl
),
760 m_pCollectedUIs
->aHandlers
,
761 &CachedInspectorUI::getEnabledInputControls
,
762 &CachedInspectorUI::getDisabledInputControls
766 EnablePropertyUIElement( m_xDelegatorUI
, PropertyLineElement::PrimaryButton
),
767 m_pCollectedUIs
->aHandlers
,
768 &CachedInspectorUI::getEnabledPrimaryButtons
,
769 &CachedInspectorUI::getDisabledPrimaryButtons
773 EnablePropertyUIElement( m_xDelegatorUI
, PropertyLineElement::SecondaryButton
),
774 m_pCollectedUIs
->aHandlers
,
775 &CachedInspectorUI::getEnabledSecondaryButtons
,
776 &CachedInspectorUI::getDisabledSecondaryButtons
780 //--------------------------------------------------------------------
781 void ComposedPropertyUIUpdate::impl_fireAll_throw()
783 OSL_PRECOND( !impl_isDisposed(), "ComposedPropertyUIUpdate::impl_fireAll_throw: already disposed, this will crash!" );
785 impl_fireEnablePropertyUI_throw();
786 impl_fireShowHidePropertyUI_throw();
787 impl_fireRebuildPropertyUI_throw();
788 impl_fireShowCategory_throw();
789 impl_fireEnablePropertyUIElements_throw();
792 //--------------------------------------------------------------------
793 void SAL_CALL
ComposedPropertyUIUpdate::suspendAutoFire()
795 impl_checkDisposed();
796 osl_incrementInterlockedCount( &m_nSuspendCounter
);
799 //--------------------------------------------------------------------
800 void SAL_CALL
ComposedPropertyUIUpdate::resumeAutoFire()
802 impl_checkDisposed();
803 if ( 0 == osl_decrementInterlockedCount( &m_nSuspendCounter
) )
804 impl_fireAll_throw();
807 //----------------------------------------------------------------
808 void ComposedPropertyUIUpdate::impl_checkDisposed() const
810 if ( impl_isDisposed() )
811 throw DisposedException();
814 //----------------------------------------------------------------
815 void ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw()
817 if ( 0 == m_nSuspendCounter
)
818 impl_fireAll_throw();
821 //----------------------------------------------------------------
822 Reference
< XObjectInspectorUI
> ComposedPropertyUIUpdate::getDelegatorUI() const
824 impl_checkDisposed();
825 return m_xDelegatorUI
;
828 //----------------------------------------------------------------
829 void SAL_CALL
ComposedPropertyUIUpdate::dispose()
831 if ( impl_isDisposed() )
834 OSL_ENSURE( m_nSuspendCounter
== 0, "ComposedPropertyUIUpdate::dispose: still suspended, the changes will be lost!" );
836 for ( ImplMapHandlerToUI::const_iterator singleUI
= m_pCollectedUIs
->aHandlers
.begin();
837 singleUI
!= m_pCollectedUIs
->aHandlers
.end();
841 singleUI
->second
->dispose();
843 m_pCollectedUIs
.reset( NULL
);
844 m_xDelegatorUI
.set( NULL
);
847 //----------------------------------------------------------------
848 bool ComposedPropertyUIUpdate::shouldContinuePropertyHandling( const ::rtl::OUString
& _rName
) const
850 if ( !m_pPropertyCheck
)
852 if ( m_pPropertyCheck
->hasPropertyByName( _rName
) )
857 //........................................................................
859 //........................................................................
861 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */