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