LibreOffice Module extensions (master) 1
composeduiupdate.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "composeduiupdate.hxx"
21#include "pcrcommon.hxx"
22
23#include <com/sun/star/inspection/XObjectInspectorUI.hpp>
24#include <com/sun/star/lang/DisposedException.hpp>
25#include <com/sun/star/lang/NullPointerException.hpp>
26#include <com/sun/star/inspection/PropertyLineElement.hpp>
27#include <osl/diagnose.h>
28#include <osl/mutex.hxx>
29#include <rtl/ref.hxx>
31
32#include <algorithm>
33#include <map>
34#include <set>
35
36
37namespace pcr
38{
39
40
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;
48
49 namespace PropertyLineElement = ::com::sun::star::inspection::PropertyLineElement;
50
51 namespace
52 {
53 struct HandlerLess
54 {
55 bool operator()( const Reference< XPropertyHandler >& lhs, const Reference< XPropertyHandler >& rhs) const
56 {
57 return lhs.get() < rhs.get();
58 }
59 };
60
61
62 typedef std::set< OUString > StringBag;
63 typedef std::map< sal_Int16, StringBag > MapIntToStringBag;
64 }
65
66
67 // callbacks for CachedInspectorUI
68
70
71 typedef ::cppu::WeakImplHelper < css::inspection::XObjectInspectorUI
73
74 namespace {
75
76 struct CachedInspectorUI : public CachedInspectorUI_Base
77 {
78 private:
79 ::osl::Mutex m_aMutex;
80 bool m_bDisposed;
82 m_rMaster;
83 FNotifySingleUIChange m_pUIChangeNotification;
84
85 // enablePropertyUI cache
86 StringBag aEnabledProperties;
87 StringBag aDisabledProperties;
88
89 // show/hidePropertyUI cache
90 StringBag aShownProperties;
91 StringBag aHiddenProperties;
92
93 // rebuildPropertyUI cache
94 StringBag aRebuiltProperties;
95
96 // showCategory cache
97 StringBag aShownCategories;
98 StringBag aHiddenCategories;
99
100 // enablePropertyUIElements cache
101 MapIntToStringBag aEnabledElements;
102 MapIntToStringBag aDisabledElements;
103
104 public:
105 typedef StringBag& (CachedInspectorUI::*FGetStringBag)();
106
107 // enablePropertyUI cache
108 StringBag& getEnabledProperties() { return aEnabledProperties; }
109 StringBag& getDisabledProperties() { return aDisabledProperties; }
110
111 // show/hidePropertyUI cache
112 StringBag& getShownProperties() { return aShownProperties; }
113 StringBag& getHiddenProperties() { return aHiddenProperties; }
114
115 // rebuildPropertyUI cache
116 StringBag& getRebuiltProperties() { return aRebuiltProperties; }
117
118 // showCategory cache
119 StringBag& getShownCategories() { return aShownCategories; }
120 StringBag& getHiddenCategories() { return aHiddenCategories; }
121
122 // enablePropertyUIElements
123 StringBag& getEnabledInputControls() { return aEnabledElements[ PropertyLineElement::InputControl ]; }
124 StringBag& getDisabledInputControls() { return aDisabledElements[ PropertyLineElement::InputControl ]; }
125 StringBag& getEnabledPrimaryButtons() { return aEnabledElements[ PropertyLineElement::PrimaryButton ]; }
126 StringBag& getDisabledPrimaryButtons() { return aDisabledElements[ PropertyLineElement::PrimaryButton ]; }
127 StringBag& getEnabledSecondaryButtons() { return aEnabledElements[ PropertyLineElement::SecondaryButton ]; }
128 StringBag& getDisabledSecondaryButtons() { return aDisabledElements[ PropertyLineElement::SecondaryButton ]; }
129
130 public:
131 CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster, FNotifySingleUIChange _pUIChangeNotification );
132 CachedInspectorUI(const CachedInspectorUI&) = delete;
133 CachedInspectorUI& operator=(const CachedInspectorUI&) = delete;
134
136 void dispose();
137
138 // XObjectInspectorUI overridables
139 virtual void SAL_CALL enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable ) override;
140 virtual void SAL_CALL enablePropertyUIElements( const OUString& _rPropertyName, ::sal_Int16 _nElements, sal_Bool _bEnable ) override;
141 virtual void SAL_CALL rebuildPropertyUI( const OUString& _rPropertyName ) override;
142 virtual void SAL_CALL showPropertyUI( const OUString& _rPropertyName ) override;
143 virtual void SAL_CALL hidePropertyUI( const OUString& _rPropertyName ) override;
144 virtual void SAL_CALL showCategory( const OUString& _rCategory, sal_Bool _bShow ) override;
145 virtual Reference< XPropertyControl > SAL_CALL getPropertyControl( const OUString& _rPropertyName ) override;
146 virtual void SAL_CALL registerControlObserver( const Reference< XPropertyControlObserver >& Observer ) override;
147 virtual void SAL_CALL revokeControlObserver( const Reference< XPropertyControlObserver >& Observer ) override;
148 virtual void SAL_CALL setHelpSectionText( const OUString& HelpText ) override;
149
150 protected:
151 virtual ~CachedInspectorUI() override;
152
154 void checkDisposed() const;
155
156 private:
157 void impl_markElementEnabledOrDisabled( const OUString& _rPropertyName, sal_Int16 _nElementIdOrZero, bool _bEnable );
158
161 void impl_notifySingleUIChange() const;
162
163 private:
164 class MethodGuard;
165 friend class MethodGuard;
166 class MethodGuard : public ::osl::MutexGuard
167 {
168 public:
169 explicit MethodGuard( CachedInspectorUI& rInstance )
170 : ::osl::MutexGuard( rInstance.m_aMutex )
171 {
172 rInstance.checkDisposed();
173 }
174 };
175 };
176
177 }
178
179 CachedInspectorUI::CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster, FNotifySingleUIChange _pUIChangeNotification )
180 :m_bDisposed( false )
181 ,m_rMaster( _rMaster )
182 ,m_pUIChangeNotification( _pUIChangeNotification )
183 {
184 }
185
186
187 CachedInspectorUI::~CachedInspectorUI()
188 {
189 }
190
191
192 void CachedInspectorUI::dispose()
193 {
194 ::osl::MutexGuard aGuard( m_aMutex );
195 m_bDisposed = true;
196
197 clearContainer( aEnabledProperties );
198 clearContainer( aDisabledProperties );
199 clearContainer( aRebuiltProperties );
200 clearContainer( aShownProperties );
201 clearContainer( aHiddenProperties );
202 clearContainer( aShownCategories );
203 clearContainer( aHiddenCategories );
204 clearContainer( aEnabledElements );
205 clearContainer( aDisabledElements );
206 }
207
208
209 void CachedInspectorUI::checkDisposed() const
210 {
211 if (m_bDisposed)
212 throw DisposedException();
213 }
214
215
216 namespace
217 {
218 void lcl_markStringKeyPositiveOrNegative( const OUString& _rKeyName, StringBag& _rPositives, StringBag& _rNegatives, bool _bMarkPositive )
219 {
220 if ( _bMarkPositive )
221 {
222 _rPositives.insert( _rKeyName );
223 // if the same key has been remember as in the "negative" list before, clear this information, since it's overruled
224 _rNegatives.erase( _rKeyName );
225 }
226 else
227 _rNegatives.insert( _rKeyName );
228 }
229 }
230
231
232 void CachedInspectorUI::enablePropertyUI( const OUString& _rPropertyName, sal_Bool _bEnable )
233 {
234 MethodGuard aGuard( *this );
235 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
236 return;
237
238 lcl_markStringKeyPositiveOrNegative( _rPropertyName, aEnabledProperties, aDisabledProperties, _bEnable );
239 impl_notifySingleUIChange();
240 }
241
242
243 void CachedInspectorUI::impl_markElementEnabledOrDisabled( const OUString& _rPropertyName, sal_Int16 _nElementIdOrZero, bool _bEnable )
244 {
245 if ( _nElementIdOrZero == 0 )
246 return;
247
248 lcl_markStringKeyPositiveOrNegative(
249 _rPropertyName,
250 aEnabledElements[ _nElementIdOrZero ],
251 aDisabledElements[ _nElementIdOrZero ],
252 _bEnable
253 );
254 }
255
256
257 void CachedInspectorUI::impl_notifySingleUIChange() const
258 {
259 (m_rMaster.*m_pUIChangeNotification)();
260 }
261
262
263 void CachedInspectorUI::enablePropertyUIElements( const OUString& _rPropertyName, sal_Int16 _nElements, sal_Bool _bEnable )
264 {
265 MethodGuard aGuard( *this );
266 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
267 return;
268
269 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::InputControl, _bEnable );
270 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::PrimaryButton, _bEnable );
271 impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::SecondaryButton, _bEnable );
272
273 impl_notifySingleUIChange();
274 }
275
276
277 void CachedInspectorUI::rebuildPropertyUI( const OUString& _rPropertyName )
278 {
279 MethodGuard aGuard( *this );
280 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
281 return;
282
283 aRebuiltProperties.insert( _rPropertyName );
284
285 impl_notifySingleUIChange();
286 }
287
288
289 void CachedInspectorUI::showPropertyUI( const OUString& _rPropertyName )
290 {
291 MethodGuard aGuard( *this );
292 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
293 return;
294
295 aShownProperties.insert( _rPropertyName );
296 // if the same category has been hidden before, clear this information, since it's overruled
297 aHiddenProperties.erase( _rPropertyName );
298
299 impl_notifySingleUIChange();
300 }
301
302
303 void CachedInspectorUI::hidePropertyUI( const OUString& _rPropertyName )
304 {
305 MethodGuard aGuard( *this );
306 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
307 return;
308
309 aHiddenProperties.insert( _rPropertyName );
310 impl_notifySingleUIChange();
311 }
312
313
314 void CachedInspectorUI::showCategory( const OUString& _rCategory, sal_Bool _bShow )
315 {
316 MethodGuard aGuard( *this );
317
318 lcl_markStringKeyPositiveOrNegative( _rCategory, aShownCategories, aHiddenCategories, _bShow );
319 impl_notifySingleUIChange();
320 }
321
322
323 Reference< XPropertyControl > SAL_CALL CachedInspectorUI::getPropertyControl( const OUString& _rPropertyName )
324 {
325 MethodGuard aGuard( *this );
326 if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
327 return Reference< XPropertyControl >();
328
329 return m_rMaster.getDelegatorUI()->getPropertyControl( _rPropertyName );
330 }
331
332
333 void SAL_CALL CachedInspectorUI::registerControlObserver( const Reference< XPropertyControlObserver >& Observer )
334 {
335 OSL_FAIL( "CachedInspectorUI::registerControlObserver: not expected to be called!" );
336 // CachedInspectorUI is used as context for the controls, and we don't expect them to
337 // register listeners themself
338 m_rMaster.getDelegatorUI()->registerControlObserver( Observer );
339 }
340
341
342 void SAL_CALL CachedInspectorUI::revokeControlObserver( const Reference< XPropertyControlObserver >& Observer )
343 {
344 OSL_FAIL( "CachedInspectorUI::revokeControlObserver: not expected to be called!" );
345 // CachedInspectorUI is used as context for the controls, and we don't expect them to
346 // register listeners themself
347 m_rMaster.getDelegatorUI()->revokeControlObserver( Observer );
348 }
349
350
351 void SAL_CALL CachedInspectorUI::setHelpSectionText( const OUString& HelpText )
352 {
353 m_rMaster.getDelegatorUI()->setHelpSectionText( HelpText );
354 }
355
356
357 // HandlerMap
358
359 typedef std::map < Reference< XPropertyHandler >
361 , HandlerLess
364 {
366 };
367
368 ComposedPropertyUIUpdate::ComposedPropertyUIUpdate( const Reference< XObjectInspectorUI >& _rxDelegatorUI,
369 IPropertyExistenceCheck* _pPropertyCheck )
370 :m_pCollectedUIs( new MapHandlerToUI )
371 ,m_xDelegatorUI( _rxDelegatorUI )
372 ,m_nSuspendCounter( 0 )
373 ,m_pPropertyCheck( _pPropertyCheck )
374 {
375 if ( !m_xDelegatorUI.is() )
376 throw NullPointerException();
377 }
378
379
381 {
382 }
383
384
385 Reference< XObjectInspectorUI > ComposedPropertyUIUpdate::getUIForPropertyHandler( const Reference< XPropertyHandler >& _rxHandler )
386 {
388
389 ::rtl::Reference< CachedInspectorUI >& rUI = m_pCollectedUIs->aHandlers[ _rxHandler ];
390 if ( !rUI.is() )
391 rUI = new CachedInspectorUI( *this, &ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw );
392 return rUI;
393 }
394
395
396 namespace
397 {
398
399 // an STL-compatible structure which collects strings from a CachedInspectorUI instances
400 struct StringBagCollector
401 {
402 private:
403 StringBag& m_rBag;
404 CachedInspectorUI::FGetStringBag m_pGetter;
405
406 public:
407 StringBagCollector( StringBag& _rBag, CachedInspectorUI::FGetStringBag _pGetter ) :m_rBag( _rBag ), m_pGetter( _pGetter ) { }
408
409 void operator()( const ImplMapHandlerToUI::value_type& _rUI )
410 {
411 StringBag& rBag( ((_rUI.second.get())->*m_pGetter)() );
412 m_rBag.insert( rBag.begin(), rBag.end() );
413 }
414
415 static void collectAll( StringBag& _rAll, const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
416 {
417 std::for_each( _rMap.begin(), _rMap.end(), StringBagCollector( _rAll, _pGetter ) );
418 }
419 };
420
421
422 // an STL-compatible structure which cleans a certain string bag in a CachedInspectorUI instances
423 struct StringBagClearer
424 {
425 private:
426 CachedInspectorUI::FGetStringBag m_pGetter;
427
428 public:
429 explicit StringBagClearer( CachedInspectorUI::FGetStringBag _pGetter ) :m_pGetter( _pGetter ) { }
430
431 void operator()( const ImplMapHandlerToUI::value_type& _rUI )
432 {
433 clearContainer( ((_rUI.second.get())->*m_pGetter)() );
434 }
435
436 static void clearAll( const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
437 {
438 std::for_each( _rMap.begin(), _rMap.end(), StringBagClearer( _pGetter ) );
439 }
440 };
441
442 // a typedef for a ->XObjectInspectorUI member function taking a string
443 typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUISetter )( const OUString& );
444
445
446 // an STL-compatible struct which calls a certain member method (taking a string) at a
447 // given ->XObjectInspectorUI instance
448 struct PropertyUIOperator
449 {
450 private:
451 Reference< XObjectInspectorUI > m_xUpdater;
452 FPropertyUISetter m_pSetter;
453
454 public:
455 PropertyUIOperator( const Reference< XObjectInspectorUI >& _rxInspectorUI, FPropertyUISetter _pSetter )
456 :m_xUpdater( _rxInspectorUI )
457 ,m_pSetter( _pSetter )
458 {
459 }
460
461 void operator()( const OUString& _rPropertyName )
462 {
463 ((m_xUpdater.get())->*m_pSetter)( _rPropertyName );
464 }
465
466 static void forEach( const StringBag& _rProperties, const Reference< XObjectInspectorUI >& _rxDelegatorUI, FPropertyUISetter _pSetter )
467 {
468 std::for_each( _rProperties.begin(), _rProperties.end(), PropertyUIOperator( _rxDelegatorUI, _pSetter ) );
469 }
470 };
471
472
473 // an interface which encapsulates access to a single aspect of the ->XObjectInspectorUI,
474 // where this aspect is given by a string key, and has a boolean value.
475 class IStringKeyBooleanUIUpdate
476 {
477 public:
478 virtual void updateUIForKey( const OUString& _rKey, bool _bFlag ) const = 0;
479
480 virtual ~IStringKeyBooleanUIUpdate() { }
481 };
482
483
484 // FPropertyUIFlagSetter
485
491 class EnablePropertyUIElement : public IStringKeyBooleanUIUpdate
492 {
493 private:
494 Reference< XObjectInspectorUI > m_xUIUpdate;
495 sal_Int16 m_nElement;
496
497 public:
498 EnablePropertyUIElement( const Reference< XObjectInspectorUI >& _rxUIUpdate, sal_Int16 _nElement )
499 :m_xUIUpdate( _rxUIUpdate )
500 ,m_nElement( _nElement )
501 {
502 }
503 // IStringKeyBooleanUIUpdate
504 virtual void updateUIForKey( const OUString& _rKey, bool _bFlag ) const override;
505 };
506
507
508 void EnablePropertyUIElement::updateUIForKey( const OUString& _rKey, bool _bFlag ) const
509 {
510 m_xUIUpdate->enablePropertyUIElements( _rKey, m_nElement, _bFlag );
511 }
512
513
514 // a ->XObjectInspectorUI method taking a string and a boolean
515 typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUIFlagSetter )( const OUString&, sal_Bool );
516
517
518 // an implementation of the ->IStringKeyBooleanUIUpdate interface which calls
519 // an arbitrary ->XObjectInspectorUI method taking a string and a boolean flag
520 class DefaultStringKeyBooleanUIUpdate : public IStringKeyBooleanUIUpdate
521 {
522 private:
523 Reference< XObjectInspectorUI > m_xUIUpdate;
524 FPropertyUIFlagSetter m_pSetter;
525
526 public:
527 DefaultStringKeyBooleanUIUpdate( const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter );
528 // IStringKeyBooleanUIUpdate
529 virtual void updateUIForKey( const OUString& _rKey, bool _bFlag ) const override;
530 };
531
532
533 DefaultStringKeyBooleanUIUpdate::DefaultStringKeyBooleanUIUpdate( const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter )
534 :m_xUIUpdate( _rxUIUpdate )
535 ,m_pSetter( _pSetter )
536 {
537 }
538
539
540 void DefaultStringKeyBooleanUIUpdate::updateUIForKey( const OUString& _rKey, bool _bFlag ) const
541 {
542 ((m_xUIUpdate.get())->*m_pSetter)( _rKey, _bFlag );
543 }
544
545
546 // an STL-compatible structure which applies a ->IStringKeyBooleanUIUpdate::updateUIForKey
547 // operation with a fixed boolean value, for a given string value
548 struct BooleanUIAspectUpdate
549 {
550 private:
551 const IStringKeyBooleanUIUpdate& m_rUpdater;
552 bool m_bFlag;
553
554 public:
555 BooleanUIAspectUpdate( const IStringKeyBooleanUIUpdate& _rUpdater, bool _bFlag )
556 :m_rUpdater( _rUpdater )
557 ,m_bFlag( _bFlag )
558 {
559 }
560
561 void operator()( const OUString& _rPropertyName )
562 {
563 m_rUpdater.updateUIForKey( _rPropertyName, m_bFlag );
564 }
565
566 static void forEach( const StringBag& _rProperties, const IStringKeyBooleanUIUpdate& _rUpdater, bool _bFlag )
567 {
568 std::for_each( _rProperties.begin(), _rProperties.end(), BooleanUIAspectUpdate( _rUpdater, _bFlag ) );
569 }
570 };
571
572
573 // BooleanUIAspectUpdate
574
575 // an STL-compatible structure subtracting a given string from a fixed ->StringBag
576 struct StringBagComplement
577 {
578 private:
579 StringBag& m_rMinuend;
580
581 public:
582 explicit StringBagComplement( StringBag& _rMinuend ) :m_rMinuend( _rMinuend ) { }
583
584 void operator()( const OUString& _rPropertyToSubtract )
585 {
586 m_rMinuend.erase( _rPropertyToSubtract );
587 }
588
589 static void subtract( StringBag& _rMinuend, const StringBag& _rSubtrahend )
590 {
591 std::for_each( _rSubtrahend.begin(), _rSubtrahend.end(), StringBagComplement( _rMinuend ) );
592 }
593 };
594
595
596 // BooleanUIAspectUpdate
597
598 void lcl_fireUIStateFlag(
599 const IStringKeyBooleanUIUpdate& _rUIUpdate,
600 const ImplMapHandlerToUI& _rHandlerUIs,
601 CachedInspectorUI::FGetStringBag _pGetPositives,
602 CachedInspectorUI::FGetStringBag _pGetNegatives
603 )
604 {
605 // all strings which are in the "positive" list of one handler
606 StringBag aAllPositives;
607 StringBagCollector::collectAll( aAllPositives, _rHandlerUIs, _pGetPositives );
608
609 // all strings which are in the "negative" list of one handler
610 StringBag aAllNegatives;
611 StringBagCollector::collectAll( aAllNegatives, _rHandlerUIs, _pGetNegatives );
612
613 // propagate the "negative" flags to the delegator UI
614 BooleanUIAspectUpdate::forEach( aAllNegatives, _rUIUpdate, false );
615
616 // propagate the "positive" flags to the delegator UI, for all elements where _no_
617 // "negative" flag exists
618 StringBagComplement::subtract( aAllPositives, aAllNegatives );
619 BooleanUIAspectUpdate::forEach( aAllPositives, _rUIUpdate, true );
620
621 // the "positive" request can be cleared no, only negative requests
622 // (such as "disable a property" or "hide a category") need to be preserved for the next round
623 StringBagClearer::clearAll( _rHandlerUIs, _pGetPositives );
624 }
625 }
626
627
629 {
630 lcl_fireUIStateFlag(
631 DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI, &XObjectInspectorUI::enablePropertyUI ),
632 m_pCollectedUIs->aHandlers,
633 &CachedInspectorUI::getEnabledProperties,
634 &CachedInspectorUI::getDisabledProperties
635 );
636 }
637
638
640 {
641 // collect all properties for which a rebuild request has been made
642 StringBag aAllRebuilt;
643 StringBagCollector::collectAll( aAllRebuilt, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
644
645 // rebuild all those properties
646 PropertyUIOperator::forEach( aAllRebuilt, m_xDelegatorUI, &XObjectInspectorUI::rebuildPropertyUI );
647
648 // clear the "properties to rebuild" at all handlers, since the request has been fulfilled now.
649 StringBagClearer::clearAll( m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
650 }
651
652
654 {
655 // all properties which have been shown by at least one handler
656 StringBag aAllShown;
657 StringBagCollector::collectAll( aAllShown, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getShownProperties );
658 // all properties which have been hidden by at least one handler
659 StringBag aAllHidden;
660 StringBagCollector::collectAll( aAllHidden, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getHiddenProperties );
661
662 // hide properties as necessary
663 PropertyUIOperator::forEach( aAllHidden, m_xDelegatorUI, &XObjectInspectorUI::hidePropertyUI );
664
665 // for those properties which are hidden, ignore all "show" requests which other handlers might have had
666 StringBagComplement::subtract( aAllShown, aAllHidden );
667
668 // show properties
669 PropertyUIOperator::forEach( aAllShown, m_xDelegatorUI, &XObjectInspectorUI::showPropertyUI );
670 }
671
672
674 {
675 lcl_fireUIStateFlag(
676 DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI, &XObjectInspectorUI::showCategory ),
677 m_pCollectedUIs->aHandlers,
678 &CachedInspectorUI::getShownCategories,
679 &CachedInspectorUI::getHiddenCategories
680 );
681 }
682
683
685 {
686 lcl_fireUIStateFlag(
687 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::InputControl ),
688 m_pCollectedUIs->aHandlers,
689 &CachedInspectorUI::getEnabledInputControls,
690 &CachedInspectorUI::getDisabledInputControls
691 );
692
693 lcl_fireUIStateFlag(
694 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::PrimaryButton ),
695 m_pCollectedUIs->aHandlers,
696 &CachedInspectorUI::getEnabledPrimaryButtons,
697 &CachedInspectorUI::getDisabledPrimaryButtons
698 );
699
700 lcl_fireUIStateFlag(
701 EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::SecondaryButton ),
702 m_pCollectedUIs->aHandlers,
703 &CachedInspectorUI::getEnabledSecondaryButtons,
704 &CachedInspectorUI::getDisabledSecondaryButtons
705 );
706 }
707
708
710 {
711 OSL_PRECOND( !impl_isDisposed(), "ComposedPropertyUIUpdate::impl_fireAll_throw: already disposed, this will crash!" );
712
718 }
719
720
722 {
724 osl_atomic_increment( &m_nSuspendCounter );
725 }
726
727
729 {
731 if ( 0 == osl_atomic_decrement( &m_nSuspendCounter ) )
733 }
734
735
737 {
738 if ( impl_isDisposed() )
739 throw DisposedException();
740 }
741
742
744 {
745 if ( 0 == m_nSuspendCounter )
747 }
748
749
750 Reference< XObjectInspectorUI > const & ComposedPropertyUIUpdate::getDelegatorUI() const
751 {
753 return m_xDelegatorUI;
754 }
755
756
758 {
759 if ( impl_isDisposed() )
760 return;
761
762 OSL_ENSURE( m_nSuspendCounter == 0, "ComposedPropertyUIUpdate::dispose: still suspended, the changes will be lost!" );
763
764 for (auto const& singleUI : m_pCollectedUIs->aHandlers)
765 {
766 singleUI.second->dispose();
767 }
768 m_pCollectedUIs.reset();
769 m_xDelegatorUI.set( nullptr );
770 }
771
772
774 {
775 if ( !m_pPropertyCheck )
776 return true;
777 if ( m_pPropertyCheck->hasPropertyByName( _rName ) )
778 return true;
779 return false;
780 }
781
782
783} // namespace pcr
784
785
786/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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...
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
bool m_bDisposed
::osl::Mutex m_aMutex
Definition: logger.cxx:98
void checkDisposed(bool _bThrow)
a property handler for any virtual string properties
Definition: browserline.cxx:39
std::map< Reference< XPropertyHandler >, ::rtl::Reference< CachedInspectorUI >, HandlerLess > ImplMapHandlerToUI
::cppu::WeakImplHelper< css::inspection::XObjectInspectorUI > CachedInspectorUI_Base
void clearContainer(CONTAINER &_rContainer)
Definition: pcrcommon.hxx:54
void(ComposedPropertyUIUpdate::* FNotifySingleUIChange)()
std::set< OUString > StringBag
void dispose()
ImplMapHandlerToUI aHandlers
unsigned char sal_Bool