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