12a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52a97ec55SAndrew Rist  * distributed with this work for additional information
62a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
82a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
92a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
102a97ec55SAndrew Rist  *
112a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122a97ec55SAndrew Rist  *
132a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
142a97ec55SAndrew Rist  * software distributed under the License is distributed on an
152a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
172a97ec55SAndrew Rist  * specific language governing permissions and limitations
182a97ec55SAndrew Rist  * under the License.
192a97ec55SAndrew Rist  *
202a97ec55SAndrew Rist  *************************************************************/
212a97ec55SAndrew Rist 
222a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include "composeduiupdate.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir /** === begin UNO includes === **/
29cdf0e10cSrcweir #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
31cdf0e10cSrcweir #include <com/sun/star/inspection/PropertyLineElement.hpp>
32cdf0e10cSrcweir /** === end UNO includes === **/
33cdf0e10cSrcweir #include <osl/mutex.hxx>
34cdf0e10cSrcweir #include <rtl/ref.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <algorithm>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //........................................................................
39cdf0e10cSrcweir namespace pcr
40cdf0e10cSrcweir {
41cdf0e10cSrcweir //........................................................................
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     /** === begin UNO using === **/
44cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
45cdf0e10cSrcweir     using ::com::sun::star::lang::DisposedException;
46cdf0e10cSrcweir     using ::com::sun::star::lang::NullPointerException;
47cdf0e10cSrcweir     using ::com::sun::star::inspection::XPropertyHandler;
48cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
49cdf0e10cSrcweir     using ::com::sun::star::inspection::XObjectInspectorUI;
50cdf0e10cSrcweir     using ::com::sun::star::inspection::XPropertyControl;
51cdf0e10cSrcweir     using ::com::sun::star::uno::RuntimeException;
52cdf0e10cSrcweir     using ::com::sun::star::lang::NoSupportException;
53cdf0e10cSrcweir     using ::com::sun::star::inspection::XPropertyControlObserver;
54cdf0e10cSrcweir     /** === end UNO using === **/
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     namespace PropertyLineElement = ::com::sun::star::inspection::PropertyLineElement;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     //====================================================================
59cdf0e10cSrcweir 	//= helper
60cdf0e10cSrcweir 	//====================================================================
61cdf0e10cSrcweir     namespace
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir         struct HandlerLess : public ::std::binary_function  <	Reference< XPropertyHandler >
64cdf0e10cSrcweir 									                        ,   Reference< XPropertyHandler >
65cdf0e10cSrcweir 									                        ,	bool
66cdf0e10cSrcweir                                                             >
67cdf0e10cSrcweir         {
operator ()pcr::__anon771a32c90111::HandlerLess68cdf0e10cSrcweir 	        bool operator()( const Reference< XPropertyHandler >& lhs, const Reference< XPropertyHandler >& rhs) const
69cdf0e10cSrcweir 	        {
70cdf0e10cSrcweir 		        return lhs.get() < rhs.get();
71cdf0e10cSrcweir             }
72cdf0e10cSrcweir         };
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         //================================================================
75cdf0e10cSrcweir         typedef ::std::set< ::rtl::OUString >       StringBag;
76cdf0e10cSrcweir         typedef ::std::map< sal_Int16, StringBag >  MapIntToStringBag;
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     //====================================================================
80cdf0e10cSrcweir 	//= callbacks for CachedInspectorUI
81cdf0e10cSrcweir 	//====================================================================
82cdf0e10cSrcweir     typedef void (ComposedPropertyUIUpdate::*FNotifySingleUIChange)();
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     //====================================================================
85cdf0e10cSrcweir 	//= CachedInspectorUI
86cdf0e10cSrcweir 	//====================================================================
87cdf0e10cSrcweir     typedef ::cppu::WeakImplHelper1 <   ::com::sun::star::inspection::XObjectInspectorUI
88cdf0e10cSrcweir                                     >   CachedInspectorUI_Base;
89cdf0e10cSrcweir     struct CachedInspectorUI : public CachedInspectorUI_Base
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir     private:
92cdf0e10cSrcweir         ::osl::Mutex            m_aMutex;
93cdf0e10cSrcweir         oslInterlockedCount     m_refCount;
94cdf0e10cSrcweir         bool                    m_bDisposed;
95cdf0e10cSrcweir         ComposedPropertyUIUpdate&
96cdf0e10cSrcweir                                 m_rMaster;
97cdf0e10cSrcweir         FNotifySingleUIChange   m_pUIChangeNotification;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         // enablePropertyUI cache
100cdf0e10cSrcweir         StringBag               aEnabledProperties;
101cdf0e10cSrcweir         StringBag               aDisabledProperties;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         // show/hidePropertyUI cache
104cdf0e10cSrcweir         StringBag               aShownProperties;
105cdf0e10cSrcweir         StringBag               aHiddenProperties;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         // rebuildPropertyUI cache
108cdf0e10cSrcweir         StringBag               aRebuiltProperties;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         // showCategory cache
111cdf0e10cSrcweir         StringBag               aShownCategories;
112cdf0e10cSrcweir         StringBag               aHiddenCategories;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         // enablePropertyUIElements cache
115cdf0e10cSrcweir         MapIntToStringBag       aEnabledElements;
116cdf0e10cSrcweir         MapIntToStringBag       aDisabledElements;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     public:
119cdf0e10cSrcweir         typedef StringBag& (CachedInspectorUI::*FGetStringBag)();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         // enablePropertyUI cache
getEnabledPropertiespcr::CachedInspectorUI122cdf0e10cSrcweir         StringBag&  getEnabledProperties()          { return aEnabledProperties; }
getDisabledPropertiespcr::CachedInspectorUI123cdf0e10cSrcweir         StringBag&  getDisabledProperties()         { return aDisabledProperties; }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         // show/hidePropertyUI cache
getShownPropertiespcr::CachedInspectorUI126cdf0e10cSrcweir         StringBag&  getShownProperties()            { return aShownProperties; }
getHiddenPropertiespcr::CachedInspectorUI127cdf0e10cSrcweir         StringBag&  getHiddenProperties()           { return aHiddenProperties; }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         // rebuildPropertyUI cache
getRebuiltPropertiespcr::CachedInspectorUI130cdf0e10cSrcweir         StringBag&  getRebuiltProperties()          { return aRebuiltProperties; }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         // showCategory cache
getShownCategoriespcr::CachedInspectorUI133cdf0e10cSrcweir         StringBag&  getShownCategories()            { return aShownCategories; }
getHiddenCategoriespcr::CachedInspectorUI134cdf0e10cSrcweir         StringBag&  getHiddenCategories()           { return aHiddenCategories; }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         // enablePropertyUIElements
getEnabledInputControlspcr::CachedInspectorUI137cdf0e10cSrcweir         StringBag&  getEnabledInputControls()       { return aEnabledElements[ PropertyLineElement::InputControl ]; }
getDisabledInputControlspcr::CachedInspectorUI138cdf0e10cSrcweir         StringBag&  getDisabledInputControls()      { return aDisabledElements[ PropertyLineElement::InputControl ]; }
getEnabledPrimaryButtonspcr::CachedInspectorUI139cdf0e10cSrcweir         StringBag&  getEnabledPrimaryButtons()      { return aEnabledElements[ PropertyLineElement::PrimaryButton ]; }
getDisabledPrimaryButtonspcr::CachedInspectorUI140cdf0e10cSrcweir         StringBag&  getDisabledPrimaryButtons()     { return aDisabledElements[ PropertyLineElement::PrimaryButton ]; }
getEnabledSecondaryButtonspcr::CachedInspectorUI141cdf0e10cSrcweir         StringBag&  getEnabledSecondaryButtons()    { return aEnabledElements[ PropertyLineElement::SecondaryButton ]; }
getDisabledSecondaryButtonspcr::CachedInspectorUI142cdf0e10cSrcweir         StringBag&  getDisabledSecondaryButtons()   { return aDisabledElements[ PropertyLineElement::SecondaryButton ]; }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     public:
145cdf0e10cSrcweir         CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster, FNotifySingleUIChange _pUIChangeNotification );
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         /// disposes the instance
148cdf0e10cSrcweir         void dispose();
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         // XObjectInspectorUI overridables
151cdf0e10cSrcweir         virtual void SAL_CALL enablePropertyUI( const ::rtl::OUString& _rPropertyName, ::sal_Bool _bEnable ) throw (RuntimeException);
152cdf0e10cSrcweir         virtual void SAL_CALL enablePropertyUIElements( const ::rtl::OUString& _rPropertyName, ::sal_Int16 _nElements, ::sal_Bool _bEnable ) throw (RuntimeException);
153cdf0e10cSrcweir         virtual void SAL_CALL rebuildPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException);
154cdf0e10cSrcweir         virtual void SAL_CALL showPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException);
155cdf0e10cSrcweir         virtual void SAL_CALL hidePropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException);
156cdf0e10cSrcweir         virtual void SAL_CALL showCategory( const ::rtl::OUString& _rCategory, ::sal_Bool _bShow ) throw (RuntimeException);
157cdf0e10cSrcweir         virtual Reference< XPropertyControl > SAL_CALL getPropertyControl( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException);
158cdf0e10cSrcweir         virtual void SAL_CALL registerControlObserver( const Reference< XPropertyControlObserver >& Observer ) throw (RuntimeException);
159cdf0e10cSrcweir         virtual void SAL_CALL revokeControlObserver( const Reference< XPropertyControlObserver >& Observer ) throw (RuntimeException);
160cdf0e10cSrcweir         virtual void SAL_CALL setHelpSectionText( const ::rtl::OUString& _HelpText ) throw (NoSupportException, RuntimeException);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         // UNOCompatibleNonUNOReference overridables
163cdf0e10cSrcweir 		virtual void SAL_CALL acquire() throw();
164cdf0e10cSrcweir 		virtual void SAL_CALL release() throw();
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     protected:
167cdf0e10cSrcweir         ~CachedInspectorUI();
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         /// determines whether the instance is already disposed
isDisposedpcr::CachedInspectorUI170cdf0e10cSrcweir         inline bool isDisposed() const { return m_bDisposed; }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         /// throws an exception if the component is already disposed
173cdf0e10cSrcweir         void checkDisposed() const;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     private:
176cdf0e10cSrcweir         void    impl_markElementEnabledOrDisabled( const ::rtl::OUString& _rPropertyName, sal_Int16 _nElementIdOrZero, sal_Bool _bEnable );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         /** calls <member>m_pUIChangeNotification</member> at <member>m_rMaster</member>
179cdf0e10cSrcweir         */
180cdf0e10cSrcweir         void    impl_notifySingleUIChange() const;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     private:
183cdf0e10cSrcweir         CachedInspectorUI( const CachedInspectorUI& );              // never implemented
184cdf0e10cSrcweir         CachedInspectorUI& operator=( const CachedInspectorUI& );   // never implemented
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     private:
187cdf0e10cSrcweir         class MethodGuard;
188cdf0e10cSrcweir         friend class MethodGuard;
189cdf0e10cSrcweir         class MethodGuard : public ::osl::MutexGuard
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir         public:
MethodGuard(CachedInspectorUI & rInstance)192cdf0e10cSrcweir             MethodGuard( CachedInspectorUI& rInstance )
193cdf0e10cSrcweir                 : ::osl::MutexGuard( rInstance.m_aMutex )
194cdf0e10cSrcweir             {
195cdf0e10cSrcweir                 rInstance.checkDisposed();
196cdf0e10cSrcweir             }
197cdf0e10cSrcweir         };
198cdf0e10cSrcweir     };
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     //----------------------------------------------------------------
CachedInspectorUI(ComposedPropertyUIUpdate & _rMaster,FNotifySingleUIChange _pUIChangeNotification)201cdf0e10cSrcweir     CachedInspectorUI::CachedInspectorUI( ComposedPropertyUIUpdate& _rMaster, FNotifySingleUIChange _pUIChangeNotification )
202cdf0e10cSrcweir         :m_refCount( 0 )
203cdf0e10cSrcweir         ,m_bDisposed( false )
204cdf0e10cSrcweir         ,m_rMaster( _rMaster )
205cdf0e10cSrcweir         ,m_pUIChangeNotification( _pUIChangeNotification )
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir     }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     //----------------------------------------------------------------
~CachedInspectorUI()210cdf0e10cSrcweir     CachedInspectorUI::~CachedInspectorUI()
211cdf0e10cSrcweir     {
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     //----------------------------------------------------------------
dispose()215cdf0e10cSrcweir     void CachedInspectorUI::dispose()
216cdf0e10cSrcweir     {
217cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
218cdf0e10cSrcweir         m_bDisposed = true;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         clearContainer( aEnabledProperties );
221cdf0e10cSrcweir         clearContainer( aDisabledProperties );
222cdf0e10cSrcweir         clearContainer( aRebuiltProperties );
223cdf0e10cSrcweir         clearContainer( aShownProperties );
224cdf0e10cSrcweir         clearContainer( aHiddenProperties );
225cdf0e10cSrcweir         clearContainer( aShownCategories );
226cdf0e10cSrcweir         clearContainer( aHiddenCategories );
227cdf0e10cSrcweir         clearContainer( aEnabledElements );
228cdf0e10cSrcweir         clearContainer( aDisabledElements );
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     //----------------------------------------------------------------
acquire()232cdf0e10cSrcweir     void SAL_CALL CachedInspectorUI::acquire() throw()
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     //----------------------------------------------------------------
release()238cdf0e10cSrcweir     void SAL_CALL CachedInspectorUI::release() throw()
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir         if ( 0 == osl_decrementInterlockedCount( &m_refCount ) )
241cdf0e10cSrcweir             delete this;
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	//----------------------------------------------------------------
checkDisposed() const246cdf0e10cSrcweir     void CachedInspectorUI::checkDisposed() const
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir         if ( isDisposed() )
249cdf0e10cSrcweir             throw DisposedException();
250cdf0e10cSrcweir     }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     //----------------------------------------------------------------
253cdf0e10cSrcweir     namespace
254cdf0e10cSrcweir     {
lcl_markStringKeyPositiveOrNegative(const::rtl::OUString & _rKeyName,StringBag & _rPositives,StringBag & _rNegatives,sal_Bool _bMarkPositive)255cdf0e10cSrcweir         void lcl_markStringKeyPositiveOrNegative( const ::rtl::OUString& _rKeyName, StringBag& _rPositives, StringBag& _rNegatives, sal_Bool _bMarkPositive )
256cdf0e10cSrcweir         {
257cdf0e10cSrcweir             if ( _bMarkPositive )
258cdf0e10cSrcweir             {
259cdf0e10cSrcweir                 _rPositives.insert( _rKeyName );
260cdf0e10cSrcweir                 // if the same key has been remember as in the "negative" list before, clear this information, since it's overruled
261cdf0e10cSrcweir                 _rNegatives.erase( _rKeyName );
262cdf0e10cSrcweir             }
263cdf0e10cSrcweir             else
264cdf0e10cSrcweir                 _rNegatives.insert( _rKeyName );
265cdf0e10cSrcweir         }
266cdf0e10cSrcweir     }
267cdf0e10cSrcweir 
268cdf0e10cSrcweir     //----------------------------------------------------------------
enablePropertyUI(const::rtl::OUString & _rPropertyName,sal_Bool _bEnable)269cdf0e10cSrcweir     void CachedInspectorUI::enablePropertyUI( const ::rtl::OUString& _rPropertyName, sal_Bool _bEnable ) throw (RuntimeException)
270cdf0e10cSrcweir     {
271cdf0e10cSrcweir         MethodGuard aGuard( *this );
272cdf0e10cSrcweir         if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
273cdf0e10cSrcweir             return;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         lcl_markStringKeyPositiveOrNegative( _rPropertyName, aEnabledProperties, aDisabledProperties, _bEnable );
276cdf0e10cSrcweir         impl_notifySingleUIChange();
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     //----------------------------------------------------------------
impl_markElementEnabledOrDisabled(const::rtl::OUString & _rPropertyName,sal_Int16 _nElementIdOrZero,sal_Bool _bEnable)280cdf0e10cSrcweir     void CachedInspectorUI::impl_markElementEnabledOrDisabled( const ::rtl::OUString& _rPropertyName, sal_Int16 _nElementIdOrZero, sal_Bool _bEnable )
281cdf0e10cSrcweir     {
282cdf0e10cSrcweir         if ( _nElementIdOrZero == 0 )
283cdf0e10cSrcweir             return;
284cdf0e10cSrcweir 
285cdf0e10cSrcweir         lcl_markStringKeyPositiveOrNegative(
286cdf0e10cSrcweir             _rPropertyName,
287cdf0e10cSrcweir             aEnabledElements[ _nElementIdOrZero ],
288cdf0e10cSrcweir             aDisabledElements[ _nElementIdOrZero ],
289cdf0e10cSrcweir             _bEnable
290cdf0e10cSrcweir         );
291cdf0e10cSrcweir     }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir     //----------------------------------------------------------------
impl_notifySingleUIChange() const294cdf0e10cSrcweir     void CachedInspectorUI::impl_notifySingleUIChange() const
295cdf0e10cSrcweir     {
296cdf0e10cSrcweir         (m_rMaster.*m_pUIChangeNotification)();
297cdf0e10cSrcweir     }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir     //----------------------------------------------------------------
enablePropertyUIElements(const::rtl::OUString & _rPropertyName,sal_Int16 _nElements,sal_Bool _bEnable)300cdf0e10cSrcweir     void CachedInspectorUI::enablePropertyUIElements( const ::rtl::OUString& _rPropertyName, sal_Int16 _nElements, sal_Bool _bEnable ) throw (RuntimeException)
301cdf0e10cSrcweir     {
302cdf0e10cSrcweir         MethodGuard aGuard( *this );
303cdf0e10cSrcweir         if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
304cdf0e10cSrcweir             return;
305cdf0e10cSrcweir 
306cdf0e10cSrcweir         impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::InputControl,    _bEnable );
307cdf0e10cSrcweir         impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::PrimaryButton,   _bEnable );
308cdf0e10cSrcweir         impl_markElementEnabledOrDisabled( _rPropertyName, _nElements & PropertyLineElement::SecondaryButton, _bEnable );
309cdf0e10cSrcweir 
310cdf0e10cSrcweir         impl_notifySingleUIChange();
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir     //----------------------------------------------------------------
rebuildPropertyUI(const::rtl::OUString & _rPropertyName)314cdf0e10cSrcweir     void CachedInspectorUI::rebuildPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         MethodGuard aGuard( *this );
317cdf0e10cSrcweir         if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
318cdf0e10cSrcweir             return;
319cdf0e10cSrcweir 
320cdf0e10cSrcweir         aRebuiltProperties.insert( _rPropertyName );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir         impl_notifySingleUIChange();
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir     //----------------------------------------------------------------
showPropertyUI(const::rtl::OUString & _rPropertyName)326cdf0e10cSrcweir     void CachedInspectorUI::showPropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
327cdf0e10cSrcweir     {
328cdf0e10cSrcweir         MethodGuard aGuard( *this );
329cdf0e10cSrcweir         if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
330cdf0e10cSrcweir             return;
331cdf0e10cSrcweir 
332cdf0e10cSrcweir         aShownProperties.insert( _rPropertyName );
333cdf0e10cSrcweir         // if the same category has been hidden before, clear this information, since it's overruled
334cdf0e10cSrcweir         aHiddenProperties.erase( _rPropertyName );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir         impl_notifySingleUIChange();
337cdf0e10cSrcweir     }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     //----------------------------------------------------------------
hidePropertyUI(const::rtl::OUString & _rPropertyName)340cdf0e10cSrcweir     void CachedInspectorUI::hidePropertyUI( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir         MethodGuard aGuard( *this );
343cdf0e10cSrcweir         if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
344cdf0e10cSrcweir             return;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir         aHiddenProperties.insert( _rPropertyName );
347cdf0e10cSrcweir         impl_notifySingleUIChange();
348cdf0e10cSrcweir     }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     //----------------------------------------------------------------
showCategory(const::rtl::OUString & _rCategory,sal_Bool _bShow)351cdf0e10cSrcweir     void CachedInspectorUI::showCategory( const ::rtl::OUString& _rCategory, sal_Bool _bShow ) throw (RuntimeException)
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         MethodGuard aGuard( *this );
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         lcl_markStringKeyPositiveOrNegative( _rCategory, aShownCategories, aHiddenCategories, _bShow );
356cdf0e10cSrcweir         impl_notifySingleUIChange();
357cdf0e10cSrcweir     }
358cdf0e10cSrcweir 
359cdf0e10cSrcweir     //----------------------------------------------------------------
getPropertyControl(const::rtl::OUString & _rPropertyName)360cdf0e10cSrcweir     Reference< XPropertyControl > SAL_CALL CachedInspectorUI::getPropertyControl( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
361cdf0e10cSrcweir     {
362cdf0e10cSrcweir         MethodGuard aGuard( *this );
363cdf0e10cSrcweir         if ( !m_rMaster.shouldContinuePropertyHandling( _rPropertyName ) )
364cdf0e10cSrcweir             return Reference< XPropertyControl >();
365cdf0e10cSrcweir 
366cdf0e10cSrcweir         return m_rMaster.getDelegatorUI()->getPropertyControl( _rPropertyName );
367cdf0e10cSrcweir     }
368cdf0e10cSrcweir 
369cdf0e10cSrcweir     //--------------------------------------------------------------------
registerControlObserver(const Reference<XPropertyControlObserver> & _Observer)370cdf0e10cSrcweir     void SAL_CALL CachedInspectorUI::registerControlObserver( const Reference< XPropertyControlObserver >& _Observer ) throw (RuntimeException)
371cdf0e10cSrcweir     {
372cdf0e10cSrcweir         OSL_ENSURE( false, "CachedInspectorUI::registerControlObserver: not expected to be called!" );
373cdf0e10cSrcweir             // CachedInspectorUI is used as context for the controls, and we don't expect them to
374cdf0e10cSrcweir             // register listeners themself
375cdf0e10cSrcweir         m_rMaster.getDelegatorUI()->registerControlObserver( _Observer );
376cdf0e10cSrcweir     }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir     //--------------------------------------------------------------------
revokeControlObserver(const Reference<XPropertyControlObserver> & _Observer)379cdf0e10cSrcweir     void SAL_CALL CachedInspectorUI::revokeControlObserver( const Reference< XPropertyControlObserver >& _Observer ) throw (RuntimeException)
380cdf0e10cSrcweir     {
381cdf0e10cSrcweir         OSL_ENSURE( false, "CachedInspectorUI::revokeControlObserver: not expected to be called!" );
382cdf0e10cSrcweir             // CachedInspectorUI is used as context for the controls, and we don't expect them to
383cdf0e10cSrcweir             // register listeners themself
384cdf0e10cSrcweir         m_rMaster.getDelegatorUI()->revokeControlObserver( _Observer );
385cdf0e10cSrcweir     }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir     //----------------------------------------------------------------
setHelpSectionText(const::rtl::OUString & _HelpText)388cdf0e10cSrcweir     void SAL_CALL CachedInspectorUI::setHelpSectionText( const ::rtl::OUString& _HelpText ) throw (NoSupportException, RuntimeException)
389cdf0e10cSrcweir     {
390cdf0e10cSrcweir         m_rMaster.getDelegatorUI()->setHelpSectionText( _HelpText );
391cdf0e10cSrcweir     }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     //====================================================================
394cdf0e10cSrcweir 	//= HandlerMap
395cdf0e10cSrcweir 	//====================================================================
396cdf0e10cSrcweir     typedef ::std::map  <   Reference< XPropertyHandler >
397cdf0e10cSrcweir                         ,   ::rtl::Reference< CachedInspectorUI >
398cdf0e10cSrcweir                         ,   HandlerLess
399cdf0e10cSrcweir                         >   ImplMapHandlerToUI;
400cdf0e10cSrcweir     struct MapHandlerToUI
401cdf0e10cSrcweir     {
402cdf0e10cSrcweir         ImplMapHandlerToUI aHandlers;
403cdf0e10cSrcweir     };
404cdf0e10cSrcweir 
405cdf0e10cSrcweir     //====================================================================
406cdf0e10cSrcweir 	//= ComposedPropertyUIUpdate
407cdf0e10cSrcweir 	//====================================================================
408cdf0e10cSrcweir 	//----------------------------------------------------------------
ComposedPropertyUIUpdate(const Reference<XObjectInspectorUI> & _rxDelegatorUI,IPropertyExistenceCheck * _pPropertyCheck)409cdf0e10cSrcweir     ComposedPropertyUIUpdate::ComposedPropertyUIUpdate( const Reference< XObjectInspectorUI >& _rxDelegatorUI,
410cdf0e10cSrcweir         IPropertyExistenceCheck* _pPropertyCheck )
411cdf0e10cSrcweir         :m_pCollectedUIs( new MapHandlerToUI )
412cdf0e10cSrcweir         ,m_xDelegatorUI( _rxDelegatorUI )
413cdf0e10cSrcweir         ,m_nSuspendCounter( 0 )
414cdf0e10cSrcweir         ,m_pPropertyCheck( _pPropertyCheck )
415cdf0e10cSrcweir     {
416cdf0e10cSrcweir         if ( !m_xDelegatorUI.is() )
417cdf0e10cSrcweir             throw NullPointerException();
418cdf0e10cSrcweir     }
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 	//----------------------------------------------------------------
~ComposedPropertyUIUpdate()421cdf0e10cSrcweir     ComposedPropertyUIUpdate::~ComposedPropertyUIUpdate( )
422cdf0e10cSrcweir     {
423cdf0e10cSrcweir     }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 	//----------------------------------------------------------------
getUIForPropertyHandler(const Reference<XPropertyHandler> & _rxHandler)426cdf0e10cSrcweir     Reference< XObjectInspectorUI > ComposedPropertyUIUpdate::getUIForPropertyHandler( const Reference< XPropertyHandler >& _rxHandler )
427cdf0e10cSrcweir     {
428cdf0e10cSrcweir         impl_checkDisposed();
429cdf0e10cSrcweir 
430cdf0e10cSrcweir         ::rtl::Reference< CachedInspectorUI >& rUI = m_pCollectedUIs->aHandlers[ _rxHandler ];
431cdf0e10cSrcweir         if ( !rUI.is() )
432cdf0e10cSrcweir             rUI = new CachedInspectorUI( *this, &ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw );
433cdf0e10cSrcweir         return rUI.get();
434cdf0e10cSrcweir     }
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 	//----------------------------------------------------------------
437cdf0e10cSrcweir     namespace
438cdf0e10cSrcweir     {
439cdf0e10cSrcweir         //============================================================
440cdf0e10cSrcweir 	    //= StringBagCollector
441cdf0e10cSrcweir 	    //============================================================
442cdf0e10cSrcweir         /** an STL-compatible structure which collects strings from a CachedInspectorUI instances
443cdf0e10cSrcweir         */
444cdf0e10cSrcweir         struct StringBagCollector : public ::std::unary_function< ImplMapHandlerToUI::value_type, void >
445cdf0e10cSrcweir         {
446cdf0e10cSrcweir         private:
447cdf0e10cSrcweir             StringBag&                      m_rBag;
448cdf0e10cSrcweir             CachedInspectorUI::FGetStringBag  m_pGetter;
449cdf0e10cSrcweir 
450cdf0e10cSrcweir         public:
StringBagCollectorpcr::__anon771a32c90311::StringBagCollector451cdf0e10cSrcweir             StringBagCollector( StringBag& _rBag, CachedInspectorUI::FGetStringBag _pGetter ) :m_rBag( _rBag ), m_pGetter( _pGetter ) { }
452cdf0e10cSrcweir 
operator ()pcr::__anon771a32c90311::StringBagCollector453cdf0e10cSrcweir             void operator()( const ImplMapHandlerToUI::value_type& _rUI )
454cdf0e10cSrcweir             {
455cdf0e10cSrcweir                 StringBag& rBag( ((_rUI.second.get())->*m_pGetter)() );
456cdf0e10cSrcweir                 m_rBag.insert( rBag.begin(), rBag.end() );
457cdf0e10cSrcweir             }
458cdf0e10cSrcweir 
collectAllpcr::__anon771a32c90311::StringBagCollector459cdf0e10cSrcweir             static void collectAll( StringBag& _rAll, const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
460cdf0e10cSrcweir             {
461cdf0e10cSrcweir                 ::std::for_each( _rMap.begin(), _rMap.end(), StringBagCollector( _rAll, _pGetter ) );
462cdf0e10cSrcweir             }
463cdf0e10cSrcweir         };
464cdf0e10cSrcweir 
465cdf0e10cSrcweir         //============================================================
466cdf0e10cSrcweir 	    //= StringBagClearer
467cdf0e10cSrcweir 	    //============================================================
468cdf0e10cSrcweir         /** an STL-compatible structure which cleans a certain string bag in a CachedInspectorUI instances
469cdf0e10cSrcweir         */
470cdf0e10cSrcweir         struct StringBagClearer : public ::std::unary_function< ImplMapHandlerToUI::value_type, void >
471cdf0e10cSrcweir         {
472cdf0e10cSrcweir         private:
473cdf0e10cSrcweir             CachedInspectorUI::FGetStringBag  m_pGetter;
474cdf0e10cSrcweir 
475cdf0e10cSrcweir         public:
StringBagClearerpcr::__anon771a32c90311::StringBagClearer476cdf0e10cSrcweir             StringBagClearer( CachedInspectorUI::FGetStringBag _pGetter ) :m_pGetter( _pGetter ) { }
477cdf0e10cSrcweir 
operator ()pcr::__anon771a32c90311::StringBagClearer478cdf0e10cSrcweir             void operator()( const ImplMapHandlerToUI::value_type& _rUI )
479cdf0e10cSrcweir             {
480cdf0e10cSrcweir                 clearContainer( ((_rUI.second.get())->*m_pGetter)() );
481cdf0e10cSrcweir             }
482cdf0e10cSrcweir 
clearAllpcr::__anon771a32c90311::StringBagClearer483cdf0e10cSrcweir             static void clearAll( const ImplMapHandlerToUI& _rMap, CachedInspectorUI::FGetStringBag _pGetter )
484cdf0e10cSrcweir             {
485cdf0e10cSrcweir                 ::std::for_each( _rMap.begin(), _rMap.end(), StringBagClearer( _pGetter ) );
486cdf0e10cSrcweir             }
487cdf0e10cSrcweir         };
488cdf0e10cSrcweir 
489cdf0e10cSrcweir         //============================================================
490cdf0e10cSrcweir 	    //= FPropertyUISetter
491cdf0e10cSrcweir 	    //============================================================
492cdf0e10cSrcweir         /** a typedef for a ->XObjectInspectorUI member function taking a string
493cdf0e10cSrcweir         */
494cdf0e10cSrcweir         typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUISetter )( const ::rtl::OUString& );
495cdf0e10cSrcweir 
496cdf0e10cSrcweir         //============================================================
497cdf0e10cSrcweir 	    //= PropertyUIOperator
498cdf0e10cSrcweir 	    //============================================================
499cdf0e10cSrcweir         /** an STL-compatible struct which calls a certain member method (taking a string) at a
500cdf0e10cSrcweir             given ->XObjectInspectorUI instance
501cdf0e10cSrcweir         */
502cdf0e10cSrcweir         struct PropertyUIOperator : public ::std::unary_function< ::rtl::OUString, void >
503cdf0e10cSrcweir         {
504cdf0e10cSrcweir         private:
505cdf0e10cSrcweir             Reference< XObjectInspectorUI > m_xUpdater;
506cdf0e10cSrcweir             FPropertyUISetter               m_pSetter;
507cdf0e10cSrcweir 
508cdf0e10cSrcweir         public:
PropertyUIOperatorpcr::__anon771a32c90311::PropertyUIOperator509cdf0e10cSrcweir             PropertyUIOperator( const Reference< XObjectInspectorUI >& _rxInspectorUI, FPropertyUISetter _pSetter )
510cdf0e10cSrcweir                 :m_xUpdater( _rxInspectorUI )
511cdf0e10cSrcweir                 ,m_pSetter( _pSetter )
512cdf0e10cSrcweir             {
513cdf0e10cSrcweir             }
514cdf0e10cSrcweir 
operator ()pcr::__anon771a32c90311::PropertyUIOperator515cdf0e10cSrcweir             void operator()( const ::rtl::OUString& _rPropertyName )
516cdf0e10cSrcweir             {
517cdf0e10cSrcweir                 ((m_xUpdater.get())->*m_pSetter)( _rPropertyName );
518cdf0e10cSrcweir             }
519cdf0e10cSrcweir 
forEachpcr::__anon771a32c90311::PropertyUIOperator520cdf0e10cSrcweir             static void forEach( const StringBag& _rProperties, const Reference< XObjectInspectorUI >& _rxDelegatorUI, FPropertyUISetter _pSetter )
521cdf0e10cSrcweir             {
522cdf0e10cSrcweir                 ::std::for_each( _rProperties.begin(), _rProperties.end(), PropertyUIOperator( _rxDelegatorUI, _pSetter ) );
523cdf0e10cSrcweir             }
524cdf0e10cSrcweir         };
525cdf0e10cSrcweir 
526cdf0e10cSrcweir         //============================================================
527cdf0e10cSrcweir 	    //= IStringKeyBooleanUIUpdate
528cdf0e10cSrcweir 	    //============================================================
529cdf0e10cSrcweir         /** an interface which encapsulates access to a single aspect of the ->XObjectInspectorUI,
530cdf0e10cSrcweir             where this aspect is given by a string key, and has a boolean value.
531cdf0e10cSrcweir         */
532cdf0e10cSrcweir         class IStringKeyBooleanUIUpdate
533cdf0e10cSrcweir         {
534cdf0e10cSrcweir         public:
535cdf0e10cSrcweir             virtual void updateUIForKey( const ::rtl::OUString& _rKey, sal_Bool _bFlag ) const = 0;
536cdf0e10cSrcweir 
~IStringKeyBooleanUIUpdate()537cdf0e10cSrcweir             virtual ~IStringKeyBooleanUIUpdate() { }
538cdf0e10cSrcweir         };
539cdf0e10cSrcweir 
540cdf0e10cSrcweir         //============================================================
541cdf0e10cSrcweir 	    //= FPropertyUIFlagSetter
542cdf0e10cSrcweir 	    //============================================================
543cdf0e10cSrcweir         /** an implementation of the ->IStringKeyBooleanUIUpdate interface which,
544cdf0e10cSrcweir             for a fixed ->XObjectInspectorUI instance and a fixed UI element (->PropertyLineElement),
545cdf0e10cSrcweir             updates this element for a given property with a given boolean flag
546cdf0e10cSrcweir             (->XObjectInspectorUI::enablePropertyUIElements)
547cdf0e10cSrcweir         */
548cdf0e10cSrcweir         class EnablePropertyUIElement : public IStringKeyBooleanUIUpdate
549cdf0e10cSrcweir         {
550cdf0e10cSrcweir         private:
551cdf0e10cSrcweir             Reference< XObjectInspectorUI > m_xUIUpdate;
552cdf0e10cSrcweir             sal_Int16                       m_nElement;
553cdf0e10cSrcweir 
554cdf0e10cSrcweir         public:
EnablePropertyUIElement(const Reference<XObjectInspectorUI> & _rxUIUpdate,sal_Int16 _nElement)555cdf0e10cSrcweir             EnablePropertyUIElement( const Reference< XObjectInspectorUI >& _rxUIUpdate, sal_Int16 _nElement )
556cdf0e10cSrcweir                 :m_xUIUpdate( _rxUIUpdate )
557cdf0e10cSrcweir                 ,m_nElement( _nElement )
558cdf0e10cSrcweir             {
559cdf0e10cSrcweir             }
560cdf0e10cSrcweir             // IStringKeyBooleanUIUpdate
561cdf0e10cSrcweir             virtual void updateUIForKey( const ::rtl::OUString& _rKey, sal_Bool _bFlag ) const;
562cdf0e10cSrcweir         };
563cdf0e10cSrcweir 
564cdf0e10cSrcweir         //............................................................
updateUIForKey(const::rtl::OUString & _rKey,sal_Bool _bFlag) const565cdf0e10cSrcweir         void EnablePropertyUIElement::updateUIForKey( const ::rtl::OUString& _rKey, sal_Bool _bFlag ) const
566cdf0e10cSrcweir         {
567cdf0e10cSrcweir             m_xUIUpdate->enablePropertyUIElements( _rKey, m_nElement, _bFlag );
568cdf0e10cSrcweir         }
569cdf0e10cSrcweir 
570cdf0e10cSrcweir         //============================================================
571cdf0e10cSrcweir 	    //= FPropertyUIFlagSetter
572cdf0e10cSrcweir 	    //============================================================
573cdf0e10cSrcweir         /** a ->XObjectInspectorUI method taking a string and a boolean
574cdf0e10cSrcweir         */
575cdf0e10cSrcweir         typedef void ( SAL_CALL XObjectInspectorUI::*FPropertyUIFlagSetter )( const ::rtl::OUString&, sal_Bool );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir         //============================================================
578cdf0e10cSrcweir 	    //= DefaultStringKeyBooleanUIUpdate
579cdf0e10cSrcweir 	    //============================================================
580cdf0e10cSrcweir         /** an implementaiton of the ->IStringKeyBooleanUIUpdate interface which calls
581cdf0e10cSrcweir             am arbitrary ->XObjectInspectorUI method taking a string and a boolean flag
582cdf0e10cSrcweir         */
583cdf0e10cSrcweir         class DefaultStringKeyBooleanUIUpdate : public IStringKeyBooleanUIUpdate
584cdf0e10cSrcweir         {
585cdf0e10cSrcweir         private:
586cdf0e10cSrcweir             Reference< XObjectInspectorUI > m_xUIUpdate;
587cdf0e10cSrcweir             FPropertyUIFlagSetter           m_pSetter;
588cdf0e10cSrcweir 
589cdf0e10cSrcweir         public:
590cdf0e10cSrcweir             DefaultStringKeyBooleanUIUpdate( const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter );
591cdf0e10cSrcweir             // IStringKeyBooleanUIUpdate
592cdf0e10cSrcweir             virtual void updateUIForKey( const ::rtl::OUString& _rKey, sal_Bool _bFlag ) const;
593cdf0e10cSrcweir         };
594cdf0e10cSrcweir 
595cdf0e10cSrcweir         //............................................................
DefaultStringKeyBooleanUIUpdate(const Reference<XObjectInspectorUI> & _rxUIUpdate,FPropertyUIFlagSetter _pSetter)596cdf0e10cSrcweir         DefaultStringKeyBooleanUIUpdate::DefaultStringKeyBooleanUIUpdate( const Reference< XObjectInspectorUI >& _rxUIUpdate, FPropertyUIFlagSetter _pSetter )
597cdf0e10cSrcweir             :m_xUIUpdate( _rxUIUpdate )
598cdf0e10cSrcweir             ,m_pSetter( _pSetter )
599cdf0e10cSrcweir         {
600cdf0e10cSrcweir         }
601cdf0e10cSrcweir 
602cdf0e10cSrcweir         //............................................................
updateUIForKey(const::rtl::OUString & _rKey,sal_Bool _bFlag) const603cdf0e10cSrcweir         void DefaultStringKeyBooleanUIUpdate::updateUIForKey( const ::rtl::OUString& _rKey, sal_Bool _bFlag ) const
604cdf0e10cSrcweir         {
605cdf0e10cSrcweir             ((m_xUIUpdate.get())->*m_pSetter)( _rKey, _bFlag );
606cdf0e10cSrcweir         }
607cdf0e10cSrcweir 
608cdf0e10cSrcweir         //============================================================
609cdf0e10cSrcweir 	    //= BooleanUIAspectUpdate
610cdf0e10cSrcweir 	    //============================================================
611cdf0e10cSrcweir         /** an STL-compatible structure which applies a ->IStringKeyBooleanUIUpdate::updateUIForKey
612cdf0e10cSrcweir             operation with a fixed boolean value, for a given string value
613cdf0e10cSrcweir         */
614cdf0e10cSrcweir         struct BooleanUIAspectUpdate : public ::std::unary_function< ::rtl::OUString, void >
615cdf0e10cSrcweir         {
616cdf0e10cSrcweir         private:
617cdf0e10cSrcweir             const IStringKeyBooleanUIUpdate&    m_rUpdater;
618cdf0e10cSrcweir             sal_Bool                            m_bFlag;
619cdf0e10cSrcweir 
620cdf0e10cSrcweir         public:
BooleanUIAspectUpdatepcr::__anon771a32c90311::BooleanUIAspectUpdate621cdf0e10cSrcweir             BooleanUIAspectUpdate( const IStringKeyBooleanUIUpdate& _rUpdater, sal_Bool _bFlag )
622cdf0e10cSrcweir                 :m_rUpdater( _rUpdater )
623cdf0e10cSrcweir                 ,m_bFlag( _bFlag )
624cdf0e10cSrcweir             {
625cdf0e10cSrcweir             }
626cdf0e10cSrcweir 
operator ()pcr::__anon771a32c90311::BooleanUIAspectUpdate627cdf0e10cSrcweir             void operator()( const ::rtl::OUString& _rPropertyName )
628cdf0e10cSrcweir             {
629cdf0e10cSrcweir                 m_rUpdater.updateUIForKey( _rPropertyName, m_bFlag );
630cdf0e10cSrcweir             }
631cdf0e10cSrcweir 
forEachpcr::__anon771a32c90311::BooleanUIAspectUpdate632cdf0e10cSrcweir             static void forEach( const StringBag& _rProperties, const IStringKeyBooleanUIUpdate& _rUpdater, sal_Bool _bFlag )
633cdf0e10cSrcweir             {
634cdf0e10cSrcweir                 ::std::for_each( _rProperties.begin(), _rProperties.end(), BooleanUIAspectUpdate( _rUpdater, _bFlag ) );
635cdf0e10cSrcweir             }
636cdf0e10cSrcweir         };
637cdf0e10cSrcweir 
638cdf0e10cSrcweir         //============================================================
639cdf0e10cSrcweir 	    //= BooleanUIAspectUpdate
640cdf0e10cSrcweir 	    //============================================================
641cdf0e10cSrcweir         /** an STL-compatible structure subtracting a given string from a fixed ->StringBag
642cdf0e10cSrcweir         */
643cdf0e10cSrcweir         struct StringBagComplement : public ::std::unary_function< ::rtl::OUString, void >
644cdf0e10cSrcweir         {
645cdf0e10cSrcweir         private:
646cdf0e10cSrcweir             StringBag&  m_rMinuend;
647cdf0e10cSrcweir 
648cdf0e10cSrcweir         public:
StringBagComplementpcr::__anon771a32c90311::StringBagComplement649cdf0e10cSrcweir             StringBagComplement( StringBag& _rMinuend ) :m_rMinuend( _rMinuend ) { }
650cdf0e10cSrcweir 
operator ()pcr::__anon771a32c90311::StringBagComplement651cdf0e10cSrcweir             void operator()( const ::rtl::OUString& _rPropertyToSubtract )
652cdf0e10cSrcweir             {
653cdf0e10cSrcweir                 m_rMinuend.erase( _rPropertyToSubtract );
654cdf0e10cSrcweir             }
655cdf0e10cSrcweir 
subtractpcr::__anon771a32c90311::StringBagComplement656cdf0e10cSrcweir             static void subtract( StringBag& _rMinuend, const StringBag& _rSubtrahend )
657cdf0e10cSrcweir             {
658cdf0e10cSrcweir                 ::std::for_each( _rSubtrahend.begin(), _rSubtrahend.end(), StringBagComplement( _rMinuend ) );
659cdf0e10cSrcweir             }
660cdf0e10cSrcweir         };
661cdf0e10cSrcweir 
662cdf0e10cSrcweir         //============================================================
663cdf0e10cSrcweir 	    //= BooleanUIAspectUpdate
664cdf0e10cSrcweir 	    //============================================================
lcl_fireUIStateFlag(const IStringKeyBooleanUIUpdate & _rUIUpdate,const ImplMapHandlerToUI & _rHandlerUIs,CachedInspectorUI::FGetStringBag _pGetPositives,CachedInspectorUI::FGetStringBag _pGetNegatives)665cdf0e10cSrcweir         void lcl_fireUIStateFlag(
666cdf0e10cSrcweir                 const IStringKeyBooleanUIUpdate& _rUIUpdate,
667cdf0e10cSrcweir                 const ImplMapHandlerToUI& _rHandlerUIs,
668cdf0e10cSrcweir                 CachedInspectorUI::FGetStringBag _pGetPositives,
669cdf0e10cSrcweir                 CachedInspectorUI::FGetStringBag _pGetNegatives
670cdf0e10cSrcweir             )
671cdf0e10cSrcweir         {
672cdf0e10cSrcweir             // all strings which are in the "positive" list of one handler
673cdf0e10cSrcweir             StringBag aAllPositives;
674cdf0e10cSrcweir             StringBagCollector::collectAll( aAllPositives, _rHandlerUIs, _pGetPositives );
675cdf0e10cSrcweir 
676cdf0e10cSrcweir             // all strings which are in the "negative" list of one handler
677cdf0e10cSrcweir             StringBag aAllNegatives;
678cdf0e10cSrcweir             StringBagCollector::collectAll( aAllNegatives, _rHandlerUIs, _pGetNegatives );
679cdf0e10cSrcweir 
680cdf0e10cSrcweir             // propagate the "negative" flags to the delegator UI
681cdf0e10cSrcweir             BooleanUIAspectUpdate::forEach( aAllNegatives, _rUIUpdate, sal_False );
682cdf0e10cSrcweir 
683cdf0e10cSrcweir             // propagate the "positive" flags to the delegator UI, for all elements where _no_
684cdf0e10cSrcweir             // "negative" flag exists
685cdf0e10cSrcweir             StringBagComplement::subtract( aAllPositives, aAllNegatives );
686cdf0e10cSrcweir             BooleanUIAspectUpdate::forEach( aAllPositives, _rUIUpdate, sal_True );
687cdf0e10cSrcweir 
688cdf0e10cSrcweir             // the "positive" request can be cleared no, only negative requests
689cdf0e10cSrcweir             // (such as "disable a property" or "hide a category") need to be preserved for the next round
690cdf0e10cSrcweir             StringBagClearer::clearAll( _rHandlerUIs, _pGetPositives );
691cdf0e10cSrcweir         }
692cdf0e10cSrcweir     }
693cdf0e10cSrcweir 
694cdf0e10cSrcweir 	//----------------------------------------------------------------
impl_fireEnablePropertyUI_throw()695cdf0e10cSrcweir     void ComposedPropertyUIUpdate::impl_fireEnablePropertyUI_throw()
696cdf0e10cSrcweir     {
697cdf0e10cSrcweir         lcl_fireUIStateFlag(
698cdf0e10cSrcweir             DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI, &XObjectInspectorUI::enablePropertyUI ),
699cdf0e10cSrcweir             m_pCollectedUIs->aHandlers,
700cdf0e10cSrcweir             &CachedInspectorUI::getEnabledProperties,
701cdf0e10cSrcweir             &CachedInspectorUI::getDisabledProperties
702cdf0e10cSrcweir         );
703cdf0e10cSrcweir     }
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 	//----------------------------------------------------------------
impl_fireRebuildPropertyUI_throw()706cdf0e10cSrcweir     void ComposedPropertyUIUpdate::impl_fireRebuildPropertyUI_throw()
707cdf0e10cSrcweir     {
708cdf0e10cSrcweir         // collect all properties for which a rebuild request has been made
709cdf0e10cSrcweir         StringBag aAllRebuilt;
710cdf0e10cSrcweir         StringBagCollector::collectAll( aAllRebuilt, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
711cdf0e10cSrcweir 
712cdf0e10cSrcweir         // rebuild all those properties
713cdf0e10cSrcweir         PropertyUIOperator::forEach( aAllRebuilt, m_xDelegatorUI, &XObjectInspectorUI::rebuildPropertyUI );
714cdf0e10cSrcweir 
715cdf0e10cSrcweir         // clear the "properties to rebuild" at all handlers, since the request has been fulfilled now.
716cdf0e10cSrcweir         StringBagClearer::clearAll( m_pCollectedUIs->aHandlers, &CachedInspectorUI::getRebuiltProperties );
717cdf0e10cSrcweir     }
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 	//----------------------------------------------------------------
impl_fireShowHidePropertyUI_throw()720cdf0e10cSrcweir     void ComposedPropertyUIUpdate::impl_fireShowHidePropertyUI_throw()
721cdf0e10cSrcweir     {
722cdf0e10cSrcweir         // all properties which have been shown by at least one handler
723cdf0e10cSrcweir         StringBag aAllShown;
724cdf0e10cSrcweir         StringBagCollector::collectAll( aAllShown, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getShownProperties );
725cdf0e10cSrcweir         // all properties which have been hidden by at least one handler
726cdf0e10cSrcweir         StringBag aAllHidden;
727cdf0e10cSrcweir         StringBagCollector::collectAll( aAllHidden, m_pCollectedUIs->aHandlers, &CachedInspectorUI::getHiddenProperties );
728cdf0e10cSrcweir 
729cdf0e10cSrcweir         // hide properties as necessary
730cdf0e10cSrcweir         PropertyUIOperator::forEach( aAllHidden, m_xDelegatorUI, &XObjectInspectorUI::hidePropertyUI );
731cdf0e10cSrcweir 
732cdf0e10cSrcweir         // for those properties which are hidden, ignore all "show" requests which other handlers might have had
733cdf0e10cSrcweir         StringBagComplement::subtract( aAllShown, aAllHidden );
734cdf0e10cSrcweir 
735cdf0e10cSrcweir         // show properties
736cdf0e10cSrcweir         PropertyUIOperator::forEach( aAllShown, m_xDelegatorUI, &XObjectInspectorUI::showPropertyUI );
737cdf0e10cSrcweir     }
738cdf0e10cSrcweir 
739cdf0e10cSrcweir 	//----------------------------------------------------------------
impl_fireShowCategory_throw()740cdf0e10cSrcweir     void ComposedPropertyUIUpdate::impl_fireShowCategory_throw()
741cdf0e10cSrcweir     {
742cdf0e10cSrcweir         lcl_fireUIStateFlag(
743cdf0e10cSrcweir             DefaultStringKeyBooleanUIUpdate( m_xDelegatorUI, &XObjectInspectorUI::showCategory ),
744cdf0e10cSrcweir             m_pCollectedUIs->aHandlers,
745cdf0e10cSrcweir             &CachedInspectorUI::getShownCategories,
746cdf0e10cSrcweir             &CachedInspectorUI::getHiddenCategories
747cdf0e10cSrcweir         );
748cdf0e10cSrcweir     }
749cdf0e10cSrcweir 
750cdf0e10cSrcweir 	//----------------------------------------------------------------
impl_fireEnablePropertyUIElements_throw()751cdf0e10cSrcweir     void ComposedPropertyUIUpdate::impl_fireEnablePropertyUIElements_throw()
752cdf0e10cSrcweir     {
753cdf0e10cSrcweir         lcl_fireUIStateFlag(
754cdf0e10cSrcweir             EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::InputControl ),
755cdf0e10cSrcweir             m_pCollectedUIs->aHandlers,
756cdf0e10cSrcweir             &CachedInspectorUI::getEnabledInputControls,
757cdf0e10cSrcweir             &CachedInspectorUI::getDisabledInputControls
758cdf0e10cSrcweir         );
759cdf0e10cSrcweir 
760cdf0e10cSrcweir         lcl_fireUIStateFlag(
761cdf0e10cSrcweir             EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::PrimaryButton ),
762cdf0e10cSrcweir             m_pCollectedUIs->aHandlers,
763cdf0e10cSrcweir             &CachedInspectorUI::getEnabledPrimaryButtons,
764cdf0e10cSrcweir             &CachedInspectorUI::getDisabledPrimaryButtons
765cdf0e10cSrcweir         );
766cdf0e10cSrcweir 
767cdf0e10cSrcweir         lcl_fireUIStateFlag(
768cdf0e10cSrcweir             EnablePropertyUIElement( m_xDelegatorUI, PropertyLineElement::SecondaryButton ),
769cdf0e10cSrcweir             m_pCollectedUIs->aHandlers,
770cdf0e10cSrcweir             &CachedInspectorUI::getEnabledSecondaryButtons,
771cdf0e10cSrcweir             &CachedInspectorUI::getDisabledSecondaryButtons
772cdf0e10cSrcweir         );
773cdf0e10cSrcweir     }
774cdf0e10cSrcweir 
775cdf0e10cSrcweir     //--------------------------------------------------------------------
impl_fireAll_throw()776cdf0e10cSrcweir     void ComposedPropertyUIUpdate::impl_fireAll_throw()
777cdf0e10cSrcweir     {
778cdf0e10cSrcweir         OSL_PRECOND( !impl_isDisposed(), "ComposedPropertyUIUpdate::impl_fireAll_throw: already disposed, this will crash!" );
779cdf0e10cSrcweir 
780cdf0e10cSrcweir         impl_fireEnablePropertyUI_throw();
781cdf0e10cSrcweir         impl_fireShowHidePropertyUI_throw();
782cdf0e10cSrcweir         impl_fireRebuildPropertyUI_throw();
783cdf0e10cSrcweir         impl_fireShowCategory_throw();
784cdf0e10cSrcweir         impl_fireEnablePropertyUIElements_throw();
785cdf0e10cSrcweir     }
786cdf0e10cSrcweir 
787cdf0e10cSrcweir     //--------------------------------------------------------------------
suspendAutoFire()788cdf0e10cSrcweir     void SAL_CALL ComposedPropertyUIUpdate::suspendAutoFire()
789cdf0e10cSrcweir     {
790cdf0e10cSrcweir         impl_checkDisposed();
791cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_nSuspendCounter );
792cdf0e10cSrcweir     }
793cdf0e10cSrcweir 
794cdf0e10cSrcweir     //--------------------------------------------------------------------
resumeAutoFire()795cdf0e10cSrcweir     void SAL_CALL ComposedPropertyUIUpdate::resumeAutoFire()
796cdf0e10cSrcweir     {
797cdf0e10cSrcweir         impl_checkDisposed();
798cdf0e10cSrcweir         if ( 0 == osl_decrementInterlockedCount( &m_nSuspendCounter ) )
799cdf0e10cSrcweir             impl_fireAll_throw();
800cdf0e10cSrcweir     }
801cdf0e10cSrcweir 
802cdf0e10cSrcweir 	//----------------------------------------------------------------
impl_checkDisposed() const803cdf0e10cSrcweir     void ComposedPropertyUIUpdate::impl_checkDisposed() const
804cdf0e10cSrcweir     {
805cdf0e10cSrcweir         if ( impl_isDisposed() )
806cdf0e10cSrcweir             throw DisposedException();
807cdf0e10cSrcweir     }
808cdf0e10cSrcweir 
809cdf0e10cSrcweir 	//----------------------------------------------------------------
callback_inspectorUIChanged_throw()810cdf0e10cSrcweir     void ComposedPropertyUIUpdate::callback_inspectorUIChanged_throw()
811cdf0e10cSrcweir     {
812cdf0e10cSrcweir         if ( 0 == m_nSuspendCounter )
813cdf0e10cSrcweir             impl_fireAll_throw();
814cdf0e10cSrcweir     }
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 	//----------------------------------------------------------------
getDelegatorUI() const817cdf0e10cSrcweir     Reference< XObjectInspectorUI > ComposedPropertyUIUpdate::getDelegatorUI() const
818cdf0e10cSrcweir     {
819cdf0e10cSrcweir         impl_checkDisposed();
820cdf0e10cSrcweir         return m_xDelegatorUI;
821cdf0e10cSrcweir     }
822cdf0e10cSrcweir 
823cdf0e10cSrcweir     //----------------------------------------------------------------
dispose()824cdf0e10cSrcweir     void SAL_CALL ComposedPropertyUIUpdate::dispose()
825cdf0e10cSrcweir     {
826cdf0e10cSrcweir         if ( impl_isDisposed() )
827cdf0e10cSrcweir             return;
828cdf0e10cSrcweir 
829cdf0e10cSrcweir         OSL_ENSURE( m_nSuspendCounter == 0, "ComposedPropertyUIUpdate::dispose: still suspended, the changes will be lost!" );
830cdf0e10cSrcweir 
831cdf0e10cSrcweir         for ( ImplMapHandlerToUI::const_iterator singleUI = m_pCollectedUIs->aHandlers.begin();
832cdf0e10cSrcweir               singleUI != m_pCollectedUIs->aHandlers.end();
833cdf0e10cSrcweir               ++singleUI
834cdf0e10cSrcweir             )
835cdf0e10cSrcweir         {
836cdf0e10cSrcweir             singleUI->second->dispose();
837cdf0e10cSrcweir         }
838*3d762826SHerbert Dürr         m_pCollectedUIs.reset();
839cdf0e10cSrcweir         m_xDelegatorUI.set( NULL );
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir 
842cdf0e10cSrcweir     //----------------------------------------------------------------
shouldContinuePropertyHandling(const::rtl::OUString & _rName) const843cdf0e10cSrcweir     bool ComposedPropertyUIUpdate::shouldContinuePropertyHandling( const ::rtl::OUString& _rName ) const
844cdf0e10cSrcweir     {
845cdf0e10cSrcweir         if ( !m_pPropertyCheck )
846cdf0e10cSrcweir             return true;
847cdf0e10cSrcweir         if ( m_pPropertyCheck->hasPropertyByName( _rName ) )
848cdf0e10cSrcweir             return true;
849cdf0e10cSrcweir         return false;
850cdf0e10cSrcweir     }
851cdf0e10cSrcweir 
852cdf0e10cSrcweir //........................................................................
853cdf0e10cSrcweir } // namespace pcr
854cdf0e10cSrcweir //........................................................................
855cdf0e10cSrcweir 
856