1*46dbaceeSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*46dbaceeSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*46dbaceeSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*46dbaceeSAndrew Rist  * distributed with this work for additional information
6*46dbaceeSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*46dbaceeSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*46dbaceeSAndrew Rist  * "License"); you may not use this file except in compliance
9*46dbaceeSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*46dbaceeSAndrew Rist  *
11*46dbaceeSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*46dbaceeSAndrew Rist  *
13*46dbaceeSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*46dbaceeSAndrew Rist  * software distributed under the License is distributed on an
15*46dbaceeSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*46dbaceeSAndrew Rist  * KIND, either express or implied.  See the License for the
17*46dbaceeSAndrew Rist  * specific language governing permissions and limitations
18*46dbaceeSAndrew Rist  * under the License.
19*46dbaceeSAndrew Rist  *
20*46dbaceeSAndrew Rist  *************************************************************/
21*46dbaceeSAndrew Rist 
22*46dbaceeSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef EXTENSIONS_SOURCE_PROPCTRLR_COMPOSEDUIUPDATE_HXX
25cdf0e10cSrcweir #define EXTENSIONS_SOURCE_PROPCTRLR_COMPOSEDUIUPDATE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "propertyhandler.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir /** === begin UNO includes === **/
30cdf0e10cSrcweir #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
31cdf0e10cSrcweir /** === end UNO includes === **/
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <map>
34cdf0e10cSrcweir #include <set>
35cdf0e10cSrcweir #include <memory>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //........................................................................
38cdf0e10cSrcweir namespace pcr
39cdf0e10cSrcweir {
40cdf0e10cSrcweir //........................................................................
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     //====================================================================
43cdf0e10cSrcweir 	//= some helper types
44cdf0e10cSrcweir 	//====================================================================
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     struct MapHandlerToUI;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     /** callback for an ComposedPropertyUIUpdate checking a given property for existence
49cdf0e10cSrcweir     */
50cdf0e10cSrcweir     class SAL_NO_VTABLE IPropertyExistenceCheck
51cdf0e10cSrcweir     {
52cdf0e10cSrcweir     public:
53cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& _rName ) throw (::com::sun::star::uno::RuntimeException) = 0;
54cdf0e10cSrcweir     };
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     //====================================================================
57cdf0e10cSrcweir 	//= ComposedPropertyUIUpdate
58cdf0e10cSrcweir 	//====================================================================
59cdf0e10cSrcweir     /** helper class composing requests to a ->XObjectInspectorUI interface, coming
60cdf0e10cSrcweir         from multiple sources
61cdf0e10cSrcweir 
62cdf0e10cSrcweir         Usually, a handler tells the browser UI to enable to disable, or show or hide, certain
63cdf0e10cSrcweir         elements. Now when multiple handlers do this, their instructions must be combined:
64cdf0e10cSrcweir         If one handler disables a certain element, but others enable it, it must in the
65cdf0e10cSrcweir         result still be disabled. Similar for showing/hiding elements.
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         ->ComposedPropertyUIUpdate implements this combination. It does so by providing a dedicated
68cdf0e10cSrcweir         ->XObjectInspectorUI instance for every participating handler, and remembering the UI
69cdf0e10cSrcweir         state on a per-handler basis. Upon request (->fire), the combined UI state is
70cdf0e10cSrcweir         forwarded to another ->XObjectInspectorUI instance, the so-called delegator UI.
71cdf0e10cSrcweir     */
72cdf0e10cSrcweir     class ComposedPropertyUIUpdate
73cdf0e10cSrcweir     {
74cdf0e10cSrcweir     private:
75cdf0e10cSrcweir         ::std::auto_ptr< MapHandlerToUI >       m_pCollectedUIs;
76cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >
77cdf0e10cSrcweir                                                 m_xDelegatorUI;
78cdf0e10cSrcweir         oslInterlockedCount                     m_nSuspendCounter;
79cdf0e10cSrcweir         IPropertyExistenceCheck*                m_pPropertyCheck;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     public:
82cdf0e10cSrcweir         /** constructs a ->ComposedPropertyUIUpdate instance
83cdf0e10cSrcweir             @param _rxDelegatorUI
84cdf0e10cSrcweir                 a ->XObjectInspectorUI instance to which composed UI requests should be forwarded. Must
85cdf0e10cSrcweir                 not be <NULL/>.
86cdf0e10cSrcweir             @param _pPropertyCheck
87cdf0e10cSrcweir                 an instance checking properties for existence. If this is not <NULL/>, it will be invoked
88cdf0e10cSrcweir                 whenever one of the ->XObjectInspectorUI methods is called, to check the passed property
89cdf0e10cSrcweir                 name.<br/>
90cdf0e10cSrcweir                 Beware of lifetime issues. The instance pointed to by <arg>_pPropertyCheck</arg> must
91cdf0e10cSrcweir                 live at least as long as the ->ComposedPropertyUIUpdate instance you're going to create.
92cdf0e10cSrcweir             @throws ::com::sun::star::lang::NullPointerException
93cdf0e10cSrcweir                 if ->_rxDelegatorUI is <NULL/>
94cdf0e10cSrcweir         */
95cdf0e10cSrcweir         ComposedPropertyUIUpdate(
96cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >& _rxDelegatorUI,
97cdf0e10cSrcweir             IPropertyExistenceCheck* _pPropertyCheck );
98cdf0e10cSrcweir         ~ComposedPropertyUIUpdate();
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         /** returns the delegator UI
101cdf0e10cSrcweir             @throw ::com::sun::star::lang::DisposedException
102cdf0e10cSrcweir         */
103cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI > getDelegatorUI() const;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         /** returns a ->XObjectInspectorUI instance belonging to a given property handler
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             In every call to an ->XPropertyHandler method which requires a ->XObjectInspectorUI,
108cdf0e10cSrcweir             the same UI instance should be used. The instance here will cache all requests passed
109cdf0e10cSrcweir             to it, and ->ComposedPropertyUIUpdate::fire will use the combination of all
110cdf0e10cSrcweir             cached UI states of all handlers to update the delegator UI.
111cdf0e10cSrcweir         */
112cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >
113cdf0e10cSrcweir             getUIForPropertyHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _rxHandler );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         /** Suspends automatic firing of UI changes
116cdf0e10cSrcweir 
117cdf0e10cSrcweir             normally, as soon as any of the property handlers does a request for an
118cdf0e10cSrcweir             arbitrary UI change, the set of collected UI changes is evaluated, and the combined
119cdf0e10cSrcweir             UI state is fired to the delegator UI.
120cdf0e10cSrcweir 
121cdf0e10cSrcweir             You can disable this automatic firing by calling ->suspendAutoFire. As longs as auto
122cdf0e10cSrcweir             firing is suspended, only explicit ->fire calls trigger the notification to the
123cdf0e10cSrcweir             delegator UI.
124cdf0e10cSrcweir 
125cdf0e10cSrcweir             Note that calls to ->suspendAutoFire are culmulative, that is, if you make multiple calls
126cdf0e10cSrcweir             they must be accompanied by an equal number of calls to ->resumeAutoFire, to enable
127cdf0e10cSrcweir             auto-firing again.
128cdf0e10cSrcweir 
129cdf0e10cSrcweir             @seealso resumeAutoFire
130cdf0e10cSrcweir         */
131cdf0e10cSrcweir         void SAL_CALL suspendAutoFire();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         /** Suspends automatic firing of UI changes
134cdf0e10cSrcweir 
135cdf0e10cSrcweir             @seealso suspendAutoFire
136cdf0e10cSrcweir         */
137cdf0e10cSrcweir         void SAL_CALL resumeAutoFire();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         /** disposes the instance, so it becomes non-functional.
140cdf0e10cSrcweir 
141cdf0e10cSrcweir             All cached handlers and cached ->XObjectInspectorUI instances will be released,
142cdf0e10cSrcweir             the latter will also be disposed, so that if anybody still holds a reference to them
143cdf0e10cSrcweir             and tries to operate them will get a DisposedException.
144cdf0e10cSrcweir         */
145cdf0e10cSrcweir         void SAL_CALL dispose();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         /** invokes m_pPropertyCheck to check whether a given property should be handled
148cdf0e10cSrcweir         */
149cdf0e10cSrcweir         bool shouldContinuePropertyHandling( const ::rtl::OUString& _rName ) const;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     private:
152cdf0e10cSrcweir         /// determines whether the instance is already disposed
impl_isDisposed() const153cdf0e10cSrcweir         inline  bool impl_isDisposed() const { return m_pCollectedUIs.get() == NULL; }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         /// throws an exception if the component is already disposed
156cdf0e10cSrcweir                 void impl_checkDisposed() const;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         /** fires the collected UI changes to our delegator UI
159cdf0e10cSrcweir 
160cdf0e10cSrcweir             All operations for any elements are forwarded:
161cdf0e10cSrcweir             <ul><li>If an element has been hidden at least once, it's also hidden at the delegator UI.</li>
162cdf0e10cSrcweir                 <li>If an element has been shown at least once, and never been hidden, it's also
163cdf0e10cSrcweir                     shown at the delegator UI.</li>
164cdf0e10cSrcweir                 <li>If an element has never been shown or hidden, it's also not touched at the delegator UI.</li>
165cdf0e10cSrcweir                 <li>The same holds if you replace "hidden" in the last three items with "disabled",
166cdf0e10cSrcweir                     and "shown" with "enabled".</li>
167cdf0e10cSrcweir                 <li>If an element should have been rebuilt (->XObjectInspectorUI::rebuiltPropertyUI)
168cdf0e10cSrcweir                     at least once, it's rebuilt at the delegator UI, too.<br/>
169cdf0e10cSrcweir                     After that, the request to rebuild the UI for this property is cleared, so subsequent
170cdf0e10cSrcweir                     calls to ->fire will not trigger an new rebuilt request.
171cdf0e10cSrcweir             </ul>
172cdf0e10cSrcweir 
173cdf0e10cSrcweir             @precond
174cdf0e10cSrcweir                 instance is not disposed
175cdf0e10cSrcweir         */
176cdf0e10cSrcweir         void    impl_fireAll_throw();
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         /// fires the combination of ->XObjectInspectorUI::enablePropertyUI calls
179cdf0e10cSrcweir         void    impl_fireEnablePropertyUI_throw();
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         /// fires the combination of ->XObjectInspectorUI::enablePropertyUIElements calls
182cdf0e10cSrcweir         void    impl_fireEnablePropertyUIElements_throw();
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         /// fires the combination of ->XObjectInspectorUI::rebuildPropertyUI calls
185cdf0e10cSrcweir         void    impl_fireRebuildPropertyUI_throw();
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         /// fires the combination of ->XObjectInspectorUI::showPropertyUI and ->XObjectInspectorUI::hidePropertyUI calls
188cdf0e10cSrcweir         void    impl_fireShowHidePropertyUI_throw();
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         /// fires the combination of ->XObjectInspectorUI::showCategory calls
191cdf0e10cSrcweir         void    impl_fireShowCategory_throw();
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         /** callback for when a single property handler requested any change in the inspector UI
194cdf0e10cSrcweir         */
195cdf0e10cSrcweir         void    callback_inspectorUIChanged_throw();
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     private:
198cdf0e10cSrcweir         ComposedPropertyUIUpdate();                                             // never implemented
199cdf0e10cSrcweir         ComposedPropertyUIUpdate( const ComposedPropertyUIUpdate& );            // never implemented
200cdf0e10cSrcweir         ComposedPropertyUIUpdate& operator=( const ComposedPropertyUIUpdate& ); // never implemented
201cdf0e10cSrcweir     };
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     //====================================================================
204cdf0e10cSrcweir 	//= ComposedUIAutoFireGuard
205cdf0e10cSrcweir 	//====================================================================
206cdf0e10cSrcweir     class ComposedUIAutoFireGuard
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir     private:
209cdf0e10cSrcweir         ComposedPropertyUIUpdate&   m_rUIUpdate;
210cdf0e10cSrcweir     public:
ComposedUIAutoFireGuard(ComposedPropertyUIUpdate & _rUIUpdate)211cdf0e10cSrcweir         ComposedUIAutoFireGuard( ComposedPropertyUIUpdate& _rUIUpdate )
212cdf0e10cSrcweir             :m_rUIUpdate( _rUIUpdate )
213cdf0e10cSrcweir         {
214cdf0e10cSrcweir             m_rUIUpdate.suspendAutoFire();
215cdf0e10cSrcweir         }
~ComposedUIAutoFireGuard()216cdf0e10cSrcweir         ~ComposedUIAutoFireGuard()
217cdf0e10cSrcweir         {
218cdf0e10cSrcweir             m_rUIUpdate.resumeAutoFire();
219cdf0e10cSrcweir         }
220cdf0e10cSrcweir     };
221cdf0e10cSrcweir 
222cdf0e10cSrcweir //........................................................................
223cdf0e10cSrcweir } // namespace pcr
224cdf0e10cSrcweir //........................................................................
225cdf0e10cSrcweir 
226cdf0e10cSrcweir #endif // EXTENSIONS_SOURCE_PROPCTRLR_COMPOSEDUIUPDATE_HXX
227cdf0e10cSrcweir 
228