146dbaceeSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 346dbaceeSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 446dbaceeSAndrew Rist * or more contributor license agreements. See the NOTICE file 546dbaceeSAndrew Rist * distributed with this work for additional information 646dbaceeSAndrew Rist * regarding copyright ownership. The ASF licenses this file 746dbaceeSAndrew Rist * to you under the Apache License, Version 2.0 (the 846dbaceeSAndrew Rist * "License"); you may not use this file except in compliance 946dbaceeSAndrew Rist * with the License. You may obtain a copy of the License at 1046dbaceeSAndrew Rist * 1146dbaceeSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1246dbaceeSAndrew Rist * 1346dbaceeSAndrew Rist * Unless required by applicable law or agreed to in writing, 1446dbaceeSAndrew Rist * software distributed under the License is distributed on an 1546dbaceeSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1646dbaceeSAndrew Rist * KIND, either express or implied. See the License for the 1746dbaceeSAndrew Rist * specific language governing permissions and limitations 1846dbaceeSAndrew Rist * under the License. 1946dbaceeSAndrew Rist * 2046dbaceeSAndrew Rist *************************************************************/ 2146dbaceeSAndrew Rist 2246dbaceeSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX 25cdf0e10cSrcweir #define EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "pcrcomponentcontext.hxx" 28cdf0e10cSrcweir #include "pcrcommontypes.hxx" 29cdf0e10cSrcweir #include "pcrcommon.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir /** === begin UNO includes === **/ 32cdf0e10cSrcweir #include <com/sun/star/script/ScriptEventDescriptor.hpp> 33cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 34cdf0e10cSrcweir #include <com/sun/star/inspection/XPropertyHandler.hpp> 35cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 36cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 37cdf0e10cSrcweir /** === end UNO includes === **/ 38cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx> 39cdf0e10cSrcweir #include <comphelper/listenernotification.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir //........................................................................ 42cdf0e10cSrcweir namespace pcr 43cdf0e10cSrcweir { 44cdf0e10cSrcweir //........................................................................ 45cdf0e10cSrcweir 46cdf0e10cSrcweir //==================================================================== 47cdf0e10cSrcweir //= EventDescription 48cdf0e10cSrcweir //==================================================================== 49cdf0e10cSrcweir typedef sal_Int32 EventId; 50cdf0e10cSrcweir struct EventDescription 51cdf0e10cSrcweir { 52cdf0e10cSrcweir public: 53cdf0e10cSrcweir ::rtl::OUString sDisplayName; 54cdf0e10cSrcweir ::rtl::OUString sListenerClassName; 55cdf0e10cSrcweir ::rtl::OUString sListenerMethodName; 56cdf0e10cSrcweir ::rtl::OString sHelpId; 57cdf0e10cSrcweir ::rtl::OString sUniqueBrowseId; 58cdf0e10cSrcweir EventId nId; 59cdf0e10cSrcweir EventDescriptionpcr::EventDescription60cdf0e10cSrcweir EventDescription() 61cdf0e10cSrcweir :nId( 0 ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir EventDescription( 66cdf0e10cSrcweir EventId _nId, 67cdf0e10cSrcweir const sal_Char* _pListenerNamespaceAscii, 68cdf0e10cSrcweir const sal_Char* _pListenerClassAsciiName, 69cdf0e10cSrcweir const sal_Char* _pListenerMethodAsciiName, 70cdf0e10cSrcweir sal_uInt16 _nDisplayNameResId, 71cdf0e10cSrcweir const rtl::OString& _sHelpId, 72cdf0e10cSrcweir const rtl::OString& _sUniqueBrowseId ); 73cdf0e10cSrcweir }; 74cdf0e10cSrcweir 75cdf0e10cSrcweir typedef ::std::hash_map< ::rtl::OUString, EventDescription, ::rtl::OUStringHash > EventMap; 76cdf0e10cSrcweir 77cdf0e10cSrcweir //==================================================================== 78cdf0e10cSrcweir //= EventHandler 79cdf0e10cSrcweir //==================================================================== 80cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::inspection::XPropertyHandler 81cdf0e10cSrcweir , ::com::sun::star::lang::XServiceInfo 82cdf0e10cSrcweir > EventHandler_Base; 83cdf0e10cSrcweir class EventHandler : public EventHandler_Base 84cdf0e10cSrcweir { 85cdf0e10cSrcweir private: 86cdf0e10cSrcweir mutable ::osl::Mutex m_aMutex; 87cdf0e10cSrcweir 88cdf0e10cSrcweir /// the context in which the instance was created 89cdf0e10cSrcweir ComponentContext m_aContext; 90cdf0e10cSrcweir /// the properties of the object we're handling 91cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xComponent; 92cdf0e10cSrcweir /// our XPropertyChangeListener(s) 93cdf0e10cSrcweir PropertyChangeListeners m_aPropertyListeners; 94cdf0e10cSrcweir /// cache of the events we found at our introspectee 95cdf0e10cSrcweir EventMap m_aEvents; 96cdf0e10cSrcweir /// has m_aEvents been initialized? 97cdf0e10cSrcweir bool m_bEventsMapInitialized; 98cdf0e10cSrcweir /// is our introspectee a dialog element? 99cdf0e10cSrcweir bool m_bIsDialogElement; 100cdf0e10cSrcweir // TODO: move different handling into different derived classes? 101cdf0e10cSrcweir /// (FormComponent) type of the grid column being inspected, or -1 if we're not inspecting a grid column 102cdf0e10cSrcweir sal_Int16 m_nGridColumnType; 103cdf0e10cSrcweir 104cdf0e10cSrcweir public: 105cdf0e10cSrcweir // XServiceInfo - static versions 106cdf0e10cSrcweir static ::rtl::OUString SAL_CALL getImplementationName_static( ) throw (::com::sun::star::uno::RuntimeException); 107cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static( ) throw (::com::sun::star::uno::RuntimeException); 108cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > Create( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir protected: 111cdf0e10cSrcweir EventHandler( 112cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext 113cdf0e10cSrcweir ); 114cdf0e10cSrcweir 115cdf0e10cSrcweir ~EventHandler(); 116cdf0e10cSrcweir 117cdf0e10cSrcweir protected: 118cdf0e10cSrcweir // XPropertyHandler overridables 119cdf0e10cSrcweir virtual void SAL_CALL inspect( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxIntrospectee ) throw (::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException); 120cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); 121cdf0e10cSrcweir virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); 122cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL convertToPropertyValue( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rControlValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); 123cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL convertToControlValue( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rPropertyValue, const ::com::sun::star::uno::Type& _rControlValueType ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); 124cdf0e10cSrcweir virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); 125cdf0e10cSrcweir virtual void SAL_CALL addPropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException); 126cdf0e10cSrcweir virtual void SAL_CALL removePropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException); 127cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > 128cdf0e10cSrcweir SAL_CALL getSupportedProperties() throw (::com::sun::star::uno::RuntimeException); 129cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupersededProperties( ) throw (::com::sun::star::uno::RuntimeException); 130cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getActuatingProperties( ) throw (::com::sun::star::uno::RuntimeException); 131cdf0e10cSrcweir virtual ::com::sun::star::inspection::LineDescriptor SAL_CALL describePropertyLine( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException); 132cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL isComposable( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); 133cdf0e10cSrcweir virtual ::com::sun::star::inspection::InteractiveSelectionResult 134cdf0e10cSrcweir SAL_CALL onInteractivePropertySelection( const ::rtl::OUString& _rPropertyName, sal_Bool _bPrimary, ::com::sun::star::uno::Any& _rData, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >& _rxInspectorUI ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException); 135cdf0e10cSrcweir virtual void SAL_CALL actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const ::com::sun::star::uno::Any& _rNewValue, const ::com::sun::star::uno::Any& _rOldValue, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >& _rxInspectorUI, sal_Bool _bFirstTimeInit ) throw (::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException); 136cdf0e10cSrcweir virtual sal_Bool SAL_CALL suspend( sal_Bool _bSuspend ) throw (::com::sun::star::uno::RuntimeException); 137cdf0e10cSrcweir 138cdf0e10cSrcweir // XComponent 139cdf0e10cSrcweir DECLARE_XCOMPONENT() 140cdf0e10cSrcweir virtual void SAL_CALL disposing(); 141cdf0e10cSrcweir 142cdf0e10cSrcweir // XServiceInfo 143cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); 144cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); 145cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); 146cdf0e10cSrcweir 147cdf0e10cSrcweir private: 148cdf0e10cSrcweir /** returns the script events associated with our introspectee 149cdf0e10cSrcweir @param _out_rEvents 150*07a3d7f1SPedro Giffuni Takes, upon successful return, the events currently associated with the introspectee 151cdf0e10cSrcweir @precond 152cdf0e10cSrcweir Our introspectee is a form component 153cdf0e10cSrcweir */ 154cdf0e10cSrcweir void impl_getFormComponentScriptEvents_nothrow( 155cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents 156cdf0e10cSrcweir ) const; 157cdf0e10cSrcweir 158cdf0e10cSrcweir /** returns the script events associated with our introspectee 159cdf0e10cSrcweir @param _out_rEvents 160*07a3d7f1SPedro Giffuni Takes, upon successful return, the events currently associated with the introspectee 161cdf0e10cSrcweir @precond 162cdf0e10cSrcweir Our introspectee is a dialog element 163cdf0e10cSrcweir */ 164cdf0e10cSrcweir void impl_getDialogElementScriptEvents_nothrow( 165cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents 166cdf0e10cSrcweir ) const; 167cdf0e10cSrcweir 168cdf0e10cSrcweir /** returns the script events associated with our introspectee 169cdf0e10cSrcweir @param _out_rEvents 170cdf0e10cSrcweir Takes, the events currently associated with the introspectee 171cdf0e10cSrcweir */ impl_getComponentScriptEvents_nothrow(::com::sun::star::uno::Sequence<::com::sun::star::script::ScriptEventDescriptor> & _out_rEvents) const172cdf0e10cSrcweir inline void impl_getComponentScriptEvents_nothrow( 173cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents 174cdf0e10cSrcweir ) const 175cdf0e10cSrcweir { 176cdf0e10cSrcweir if ( m_bIsDialogElement ) 177cdf0e10cSrcweir impl_getDialogElementScriptEvents_nothrow( _out_rEvents ); 178cdf0e10cSrcweir else 179cdf0e10cSrcweir impl_getFormComponentScriptEvents_nothrow( _out_rEvents ); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir /** returns the types of the listeners which can be registered at our introspectee 183cdf0e10cSrcweir @param _out_rTypes 184*07a3d7f1SPedro Giffuni Takes, upon successful return, the types of possible listeners at the introspectee 185cdf0e10cSrcweir */ 186cdf0e10cSrcweir void impl_getCopmonentListenerTypes_nothrow( 187cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >& _out_rTypes 188cdf0e10cSrcweir ) const; 189cdf0e10cSrcweir 190cdf0e10cSrcweir /** returns a secondary component to be used for event inspection 191cdf0e10cSrcweir 192cdf0e10cSrcweir In the UI, we want to mix events for the control model with events for the control. 193cdf0e10cSrcweir Since our introspectee is a model, this method creates a control for it (if possible). 194cdf0e10cSrcweir 195cdf0e10cSrcweir @return 196cdf0e10cSrcweir the secondary component whose events should be mixed with the introspectee's events 197cdf0e10cSrcweir The caller takes the ownership of the component (if not <NULL/>). 198cdf0e10cSrcweir 199cdf0e10cSrcweir @throws 200cdf0e10cSrcweir if an unexpected error occurs during creation of the secondary component. 201cdf0e10cSrcweir A <NULL/> component to be returned is not unexpected, but allowed 202cdf0e10cSrcweir 203cdf0e10cSrcweir @precond 204cdf0e10cSrcweir ->m_xComponent is not <NULL/> 205cdf0e10cSrcweir */ 206cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 207cdf0e10cSrcweir impl_getSecondaryComponentForEventInspection_throw( ) const; 208cdf0e10cSrcweir 209cdf0e10cSrcweir /** returns the event description for the given (programmatic) property name 210cdf0e10cSrcweir @param _rPropertyName 211cdf0e10cSrcweir the name whose event description should be looked up 212cdf0e10cSrcweir @return 213cdf0e10cSrcweir the event description for the property name 214cdf0e10cSrcweir @throws ::com::sun::star::beans::UnknownPropertyException 215cdf0e10cSrcweir if our introspectee does not have an event with the given logical name (see ->getSupportedProperties) 216cdf0e10cSrcweir */ 217cdf0e10cSrcweir const EventDescription& 218cdf0e10cSrcweir impl_getEventForName_throw( const ::rtl::OUString& _rPropertyName ) const; 219cdf0e10cSrcweir 220cdf0e10cSrcweir /** returns the index of our component within its parent, if this parent can be 221cdf0e10cSrcweir obtained (XChild::getParent) and supports an ->XIndexAccess interface 222cdf0e10cSrcweir */ 223cdf0e10cSrcweir sal_Int32 impl_getComponentIndexInParent_throw() const; 224cdf0e10cSrcweir 225cdf0e10cSrcweir /** sets a given script event as event handler at a form component 226cdf0e10cSrcweir 227cdf0e10cSrcweir @param _rScriptEvent 228cdf0e10cSrcweir the script event to set 229cdf0e10cSrcweir */ 230cdf0e10cSrcweir void impl_setFormComponentScriptEvent_nothrow( const ::com::sun::star::script::ScriptEventDescriptor& _rScriptEvent ); 231cdf0e10cSrcweir 232cdf0e10cSrcweir /** sets a given script event as event handler at a dialog component 233cdf0e10cSrcweir 234cdf0e10cSrcweir @param _rScriptEvent 235cdf0e10cSrcweir the script event to set 236cdf0e10cSrcweir */ 237cdf0e10cSrcweir void impl_setDialogElementScriptEvent_nothrow( const ::com::sun::star::script::ScriptEventDescriptor& _rScriptEvent ); 238cdf0e10cSrcweir 239cdf0e10cSrcweir /** returns the frame associated with our context document 240cdf0e10cSrcweir */ 241cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > 242cdf0e10cSrcweir impl_getContextFrame_nothrow() const; 243cdf0e10cSrcweir 244cdf0e10cSrcweir /** approves or denies a certain method to be included in the UI 245cdf0e10cSrcweir @return 246cdf0e10cSrcweir <TRUE/> if and only if the given method is allowed. 247cdf0e10cSrcweir */ 248cdf0e10cSrcweir bool impl_filterMethod_nothrow( const EventDescription& _rEvent ) const; 249cdf0e10cSrcweir 250cdf0e10cSrcweir private: 251cdf0e10cSrcweir EventHandler(); // never implemented 252cdf0e10cSrcweir EventHandler( const EventHandler& ); // never implemented 253cdf0e10cSrcweir EventHandler& operator=( const EventHandler& ); // never implemented 254cdf0e10cSrcweir }; 255cdf0e10cSrcweir 256cdf0e10cSrcweir //........................................................................ 257cdf0e10cSrcweir } // namespace pcr 258cdf0e10cSrcweir //........................................................................ 259cdf0e10cSrcweir 260cdf0e10cSrcweir #endif // EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX 261cdf0e10cSrcweir 262