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>
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;
55 bool operator()(
const Reference< XPropertyHandler >& lhs,
const Reference< XPropertyHandler >& rhs)
const
57 return lhs.get() < rhs.get();
63 typedef std::map< sal_Int16, StringBag > MapIntToStringBag;
71 typedef ::cppu::WeakImplHelper < css::inspection::XObjectInspectorUI
101 MapIntToStringBag aEnabledElements;
102 MapIntToStringBag aDisabledElements;
105 typedef StringBag& (CachedInspectorUI::*FGetStringBag)();
108 StringBag& getEnabledProperties() {
return aEnabledProperties; }
109 StringBag& getDisabledProperties() {
return aDisabledProperties; }
112 StringBag& getShownProperties() {
return aShownProperties; }
113 StringBag& getHiddenProperties() {
return aHiddenProperties; }
116 StringBag& getRebuiltProperties() {
return aRebuiltProperties; }
119 StringBag& getShownCategories() {
return aShownCategories; }
120 StringBag& getHiddenCategories() {
return aHiddenCategories; }
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 ]; }
132 CachedInspectorUI(
const CachedInspectorUI&) =
delete;
133 CachedInspectorUI& operator=(
const CachedInspectorUI&) =
delete;
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;
151 virtual ~CachedInspectorUI()
override;
157 void impl_markElementEnabledOrDisabled(
const OUString& _rPropertyName, sal_Int16 _nElementIdOrZero,
bool _bEnable );
161 void impl_notifySingleUIChange()
const;
165 friend class MethodGuard;
166 class MethodGuard :
public ::osl::MutexGuard
169 explicit MethodGuard( CachedInspectorUI& rInstance )
170 : ::osl::MutexGuard( rInstance.m_aMutex )
172 rInstance.checkDisposed();
179 CachedInspectorUI::CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster,
FNotifySingleUIChange _pUIChangeNotification )
181 ,m_rMaster( _rMaster )
182 ,m_pUIChangeNotification( _pUIChangeNotification )
187 CachedInspectorUI::~CachedInspectorUI()
192 void CachedInspectorUI::dispose()
194 ::osl::MutexGuard aGuard(
m_aMutex );
209 void CachedInspectorUI::checkDisposed()
const
212 throw DisposedException();
218 void lcl_markStringKeyPositiveOrNegative(
const OUString& _rKeyName,
StringBag& _rPositives,
StringBag& _rNegatives,
bool _bMarkPositive )
220 if ( _bMarkPositive )
222 _rPositives.insert( _rKeyName );
224 _rNegatives.erase( _rKeyName );
227 _rNegatives.insert( _rKeyName );
232 void CachedInspectorUI::enablePropertyUI(
const OUString& _rPropertyName,
sal_Bool _bEnable )
234 MethodGuard aGuard( *
this );
235 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
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 )
248 lcl_markStringKeyPositiveOrNegative(
250 aEnabledElements[ _nElementIdOrZero ],
251 aDisabledElements[ _nElementIdOrZero ],
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 ) )
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 ) )
283 aRebuiltProperties.insert( _rPropertyName );
285 impl_notifySingleUIChange();
289 void CachedInspectorUI::showPropertyUI(
const OUString& _rPropertyName )
291 MethodGuard aGuard( *
this );
292 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
295 aShownProperties.insert( _rPropertyName );
297 aHiddenProperties.erase( _rPropertyName );
299 impl_notifySingleUIChange();
303 void CachedInspectorUI::hidePropertyUI(
const OUString& _rPropertyName )
305 MethodGuard aGuard( *
this );
306 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
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!" );
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!" );
347 m_rMaster.getDelegatorUI()->revokeControlObserver( Observer );
351 void SAL_CALL CachedInspectorUI::setHelpSectionText(
const OUString& HelpText )
353 m_rMaster.getDelegatorUI()->setHelpSectionText( HelpText );
359 typedef std::map < Reference< XPropertyHandler >
368 ComposedPropertyUIUpdate::ComposedPropertyUIUpdate(
const Reference< XObjectInspectorUI >& _rxDelegatorUI,
371 ,m_xDelegatorUI( _rxDelegatorUI )
372 ,m_nSuspendCounter( 0 )
373 ,m_pPropertyCheck( _pPropertyCheck )
375 if ( !m_xDelegatorUI.is() )
376 throw NullPointerException();
400 struct StringBagCollector
404 CachedInspectorUI::FGetStringBag m_pGetter;
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() );
417 std::for_each( _rMap.begin(), _rMap.end(), StringBagCollector( _rAll, _pGetter ) );
423 struct StringBagClearer
426 CachedInspectorUI::FGetStringBag m_pGetter;
429 explicit StringBagClearer( CachedInspectorUI::FGetStringBag _pGetter ) :m_pGetter( _pGetter ) { }
431 void operator()(
const ImplMapHandlerToUI::value_type& _rUI )
436 static void clearAll(
const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
438 std::for_each( _rMap.begin(), _rMap.end(), StringBagClearer( _pGetter ) );
443 typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUISetter )(
const OUString& );
448 struct PropertyUIOperator
451 Reference< XObjectInspectorUI > m_xUpdater;
452 FPropertyUISetter m_pSetter;
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 ) );
475 class IStringKeyBooleanUIUpdate
478 virtual void updateUIForKey(
const OUString& _rKey,
bool _bFlag )
const = 0;
480 virtual ~IStringKeyBooleanUIUpdate() { }
491 class EnablePropertyUIElement :
public IStringKeyBooleanUIUpdate
494 Reference< XObjectInspectorUI > m_xUIUpdate;
495 sal_Int16 m_nElement;
498 EnablePropertyUIElement(
const Reference< XObjectInspectorUI >& _rxUIUpdate, sal_Int16 _nElement )
499 :m_xUIUpdate( _rxUIUpdate )
500 ,m_nElement( _nElement )
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 );
515 typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUIFlagSetter )(
const OUString&,
sal_Bool );
520 class DefaultStringKeyBooleanUIUpdate :
public IStringKeyBooleanUIUpdate
523 Reference< XObjectInspectorUI > m_xUIUpdate;
524 FPropertyUIFlagSetter m_pSetter;
527 DefaultStringKeyBooleanUIUpdate(
const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter );
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 );
548 struct BooleanUIAspectUpdate
551 const IStringKeyBooleanUIUpdate& m_rUpdater;
555 BooleanUIAspectUpdate(
const IStringKeyBooleanUIUpdate& _rUpdater,
bool _bFlag )
556 :m_rUpdater( _rUpdater )
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 ) );
576 struct StringBagComplement
582 explicit StringBagComplement(
StringBag& _rMinuend ) :m_rMinuend( _rMinuend ) { }
584 void operator()(
const OUString& _rPropertyToSubtract )
586 m_rMinuend.erase( _rPropertyToSubtract );
591 std::for_each( _rSubtrahend.begin(), _rSubtrahend.end(), StringBagComplement( _rMinuend ) );
598 void lcl_fireUIStateFlag(
599 const IStringKeyBooleanUIUpdate& _rUIUpdate,
601 CachedInspectorUI::FGetStringBag _pGetPositives,
602 CachedInspectorUI::FGetStringBag _pGetNegatives
607 StringBagCollector::collectAll( aAllPositives, _rHandlerUIs, _pGetPositives );
611 StringBagCollector::collectAll( aAllNegatives, _rHandlerUIs, _pGetNegatives );
614 BooleanUIAspectUpdate::forEach( aAllNegatives, _rUIUpdate,
false );
618 StringBagComplement::subtract( aAllPositives, aAllNegatives );
619 BooleanUIAspectUpdate::forEach( aAllPositives, _rUIUpdate,
true );
623 StringBagClearer::clearAll( _rHandlerUIs, _pGetPositives );
631 DefaultStringKeyBooleanUIUpdate(
m_xDelegatorUI, &XObjectInspectorUI::enablePropertyUI ),
633 &CachedInspectorUI::getEnabledProperties,
634 &CachedInspectorUI::getDisabledProperties
643 StringBagCollector::collectAll( aAllRebuilt,
m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
646 PropertyUIOperator::forEach( aAllRebuilt,
m_xDelegatorUI, &XObjectInspectorUI::rebuildPropertyUI );
649 StringBagClearer::clearAll(
m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
657 StringBagCollector::collectAll( aAllShown,
m_pCollectedUIs->aHandlers, &CachedInspectorUI::getShownProperties );
660 StringBagCollector::collectAll( aAllHidden,
m_pCollectedUIs->aHandlers, &CachedInspectorUI::getHiddenProperties );
663 PropertyUIOperator::forEach( aAllHidden,
m_xDelegatorUI, &XObjectInspectorUI::hidePropertyUI );
666 StringBagComplement::subtract( aAllShown, aAllHidden );
669 PropertyUIOperator::forEach( aAllShown,
m_xDelegatorUI, &XObjectInspectorUI::showPropertyUI );
676 DefaultStringKeyBooleanUIUpdate(
m_xDelegatorUI, &XObjectInspectorUI::showCategory ),
678 &CachedInspectorUI::getShownCategories,
679 &CachedInspectorUI::getHiddenCategories
687 EnablePropertyUIElement(
m_xDelegatorUI, PropertyLineElement::InputControl ),
689 &CachedInspectorUI::getEnabledInputControls,
690 &CachedInspectorUI::getDisabledInputControls
694 EnablePropertyUIElement(
m_xDelegatorUI, PropertyLineElement::PrimaryButton ),
696 &CachedInspectorUI::getEnabledPrimaryButtons,
697 &CachedInspectorUI::getDisabledPrimaryButtons
701 EnablePropertyUIElement(
m_xDelegatorUI, PropertyLineElement::SecondaryButton ),
703 &CachedInspectorUI::getEnabledSecondaryButtons,
704 &CachedInspectorUI::getDisabledSecondaryButtons
711 OSL_PRECOND( !
impl_isDisposed(),
"ComposedPropertyUIUpdate::impl_fireAll_throw: already disposed, this will crash!" );
739 throw DisposedException();
762 OSL_ENSURE(
m_nSuspendCounter == 0,
"ComposedPropertyUIUpdate::dispose: still suspended, the changes will be lost!" );
766 singleUI.second->dispose();
helper class composing requests to a ->XObjectInspectorUI interface, coming from multiple sources
void resumeAutoFire()
Suspends automatic firing of UI changes.
bool shouldContinuePropertyHandling(const OUString &_rName) const
invokes m_pPropertyCheck to check whether a given property should be handled
css::uno::Reference< css::inspection::XObjectInspectorUI > m_xDelegatorUI
void impl_checkDisposed() const
throws an exception if the component is already disposed
bool impl_isDisposed() const
determines whether the instance is already disposed
std::unique_ptr< MapHandlerToUI > m_pCollectedUIs
void impl_fireShowCategory_throw()
fires the combination of ->XObjectInspectorUI::showCategory calls
void dispose()
disposes the instance, so it becomes non-functional.
void impl_fireEnablePropertyUIElements_throw()
fires the combination of ->XObjectInspectorUI::enablePropertyUIElements calls
void impl_fireRebuildPropertyUI_throw()
fires the combination of ->XObjectInspectorUI::rebuildPropertyUI calls
oslInterlockedCount m_nSuspendCounter
void suspendAutoFire()
Suspends automatic firing of UI changes.
void callback_inspectorUIChanged_throw()
callback for when a single property handler requested any change in the inspector UI
IPropertyExistenceCheck * m_pPropertyCheck
css::uno::Reference< css::inspection::XObjectInspectorUI > getUIForPropertyHandler(const css::uno::Reference< css::inspection::XPropertyHandler > &_rxHandler)
returns a ->XObjectInspectorUI instance belonging to a given property handler
css::uno::Reference< css::inspection::XObjectInspectorUI > const & getDelegatorUI() const
returns the delegator UI
void impl_fireEnablePropertyUI_throw()
fires the combination of ->XObjectInspectorUI::enablePropertyUI calls
void impl_fireShowHidePropertyUI_throw()
fires the combination of ->XObjectInspectorUI::showPropertyUI and ->XObjectInspectorUI::hidePropertyU...
~ComposedPropertyUIUpdate()
void impl_fireAll_throw()
fires the collected UI changes to our delegator UI
callback for a ComposedPropertyUIUpdate checking a given property for existence
virtual bool hasPropertyByName(const OUString &_rName)=0
void checkDisposed(bool _bThrow)
a property handler for any virtual string properties
std::map< Reference< XPropertyHandler >, ::rtl::Reference< CachedInspectorUI >, HandlerLess > ImplMapHandlerToUI
::cppu::WeakImplHelper< css::inspection::XObjectInspectorUI > CachedInspectorUI_Base
void clearContainer(CONTAINER &_rContainer)
void(ComposedPropertyUIUpdate::* FNotifySingleUIChange)()
std::set< OUString > StringBag
ImplMapHandlerToUI aHandlers