merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / propctrlr / eventhandler.hxx
blobb8b50e4b4a5fcd06237cc1a3ac8e42d8853ac2b3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX
29 #define EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX
31 #include "pcrcomponentcontext.hxx"
32 #include "pcrcommontypes.hxx"
33 #include "pcrcommon.hxx"
35 /** === begin UNO includes === **/
36 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/inspection/XPropertyHandler.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/frame/XFrame.hpp>
41 /** === end UNO includes === **/
42 #include <cppuhelper/compbase2.hxx>
43 #include <comphelper/listenernotification.hxx>
45 //........................................................................
46 namespace pcr
48 //........................................................................
50 //====================================================================
51 //= EventDescription
52 //====================================================================
53 typedef sal_Int32 EventId;
54 struct EventDescription
56 public:
57 ::rtl::OUString sDisplayName;
58 ::rtl::OUString sListenerClassName;
59 ::rtl::OUString sListenerMethodName;
60 sal_Int32 nHelpId;
61 sal_Int32 nUniqueBrowseId;
62 EventId nId;
64 EventDescription()
65 :nHelpId( 0 )
66 ,nUniqueBrowseId( 0 )
67 ,nId( 0 )
71 EventDescription(
72 EventId _nId,
73 const sal_Char* _pListenerNamespaceAscii,
74 const sal_Char* _pListenerClassAsciiName,
75 const sal_Char* _pListenerMethodAsciiName,
76 sal_uInt16 _nDisplayNameResId,
77 sal_Int32 _nHelpId,
78 sal_Int32 _nUniqueBrowseId );
81 typedef ::std::hash_map< ::rtl::OUString, EventDescription, ::rtl::OUStringHash > EventMap;
83 //====================================================================
84 //= EventHandler
85 //====================================================================
86 typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::inspection::XPropertyHandler
87 , ::com::sun::star::lang::XServiceInfo
88 > EventHandler_Base;
89 class EventHandler : public EventHandler_Base
91 private:
92 mutable ::osl::Mutex m_aMutex;
94 /// the context in which the instance was created
95 ComponentContext m_aContext;
96 /// the properties of the object we're handling
97 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xComponent;
98 /// our XPropertyChangeListener(s)
99 PropertyChangeListeners m_aPropertyListeners;
100 /// cache of the events we found at our introspectee
101 EventMap m_aEvents;
102 /// has m_aEvents been initialized?
103 bool m_bEventsMapInitialized;
104 /// is our introspectee a dialog element?
105 bool m_bIsDialogElement;
106 // TODO: move different handling into different derived classes?
107 /// (FormComponent) type of the grid column being inspected, or -1 if we're not inspecting a grid column
108 sal_Int16 m_nGridColumnType;
110 public:
111 // XServiceInfo - static versions
112 static ::rtl::OUString SAL_CALL getImplementationName_static( ) throw (::com::sun::star::uno::RuntimeException);
113 static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static( ) throw (::com::sun::star::uno::RuntimeException);
114 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > Create( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
116 protected:
117 EventHandler(
118 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext
121 ~EventHandler();
123 protected:
124 // XPropertyHandler overridables
125 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);
126 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
127 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);
128 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);
129 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);
130 virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
131 virtual void SAL_CALL addPropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
132 virtual void SAL_CALL removePropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
133 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >
134 SAL_CALL getSupportedProperties() throw (::com::sun::star::uno::RuntimeException);
135 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupersededProperties( ) throw (::com::sun::star::uno::RuntimeException);
136 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getActuatingProperties( ) throw (::com::sun::star::uno::RuntimeException);
137 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);
138 virtual ::sal_Bool SAL_CALL isComposable( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
139 virtual ::com::sun::star::inspection::InteractiveSelectionResult
140 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);
141 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);
142 virtual sal_Bool SAL_CALL suspend( sal_Bool _bSuspend ) throw (::com::sun::star::uno::RuntimeException);
144 // XComponent
145 DECLARE_XCOMPONENT()
146 virtual void SAL_CALL disposing();
148 // XServiceInfo
149 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
150 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
151 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
153 private:
154 /** returns the script events associated with our introspectee
155 @param _out_rEvents
156 Takes, upon successfull return, the events currently associated with the introspectee
157 @precond
158 Our introspectee is a form component
160 void impl_getFormComponentScriptEvents_nothrow(
161 ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents
162 ) const;
164 /** returns the script events associated with our introspectee
165 @param _out_rEvents
166 Takes, upon successfull return, the events currently associated with the introspectee
167 @precond
168 Our introspectee is a dialog element
170 void impl_getDialogElementScriptEvents_nothrow(
171 ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents
172 ) const;
174 /** returns the script events associated with our introspectee
175 @param _out_rEvents
176 Takes, the events currently associated with the introspectee
178 inline void impl_getComponentScriptEvents_nothrow(
179 ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents
180 ) const
182 if ( m_bIsDialogElement )
183 impl_getDialogElementScriptEvents_nothrow( _out_rEvents );
184 else
185 impl_getFormComponentScriptEvents_nothrow( _out_rEvents );
188 /** returns the types of the listeners which can be registered at our introspectee
189 @param _out_rTypes
190 Takes, upon successfull return, the types of possible listeners at the introspectee
192 void impl_getCopmonentListenerTypes_nothrow(
193 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >& _out_rTypes
194 ) const;
196 /** returns a secondary component to be used for event inspection
198 In the UI, we want to mix events for the control model with events for the control.
199 Since our introspectee is a model, this method creates a control for it (if possible).
201 @return
202 the secondary component whose events should be mixed with the introspectee's events
203 The caller takes the ownership of the component (if not <NULL/>).
205 @throws
206 if an unexpected error occurs during creation of the secondary component.
207 A <NULL/> component to be returned is not unexpected, but allowed
209 @precond
210 ->m_xComponent is not <NULL/>
212 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
213 impl_getSecondaryComponentForEventInspection_throw( ) const;
215 /** returns the event description for the given (programmatic) property name
216 @param _rPropertyName
217 the name whose event description should be looked up
218 @return
219 the event description for the property name
220 @throws ::com::sun::star::beans::UnknownPropertyException
221 if our introspectee does not have an event with the given logical name (see ->getSupportedProperties)
223 const EventDescription&
224 impl_getEventForName_throw( const ::rtl::OUString& _rPropertyName ) const;
226 /** returns the index of our component within its parent, if this parent can be
227 obtained (XChild::getParent) and supports an ->XIndexAccess interface
229 sal_Int32 impl_getComponentIndexInParent_throw() const;
231 /** sets a given script event as event handler at a form component
233 @param _rScriptEvent
234 the script event to set
236 void impl_setFormComponentScriptEvent_nothrow( const ::com::sun::star::script::ScriptEventDescriptor& _rScriptEvent );
238 /** sets a given script event as event handler at a dialog component
240 @param _rScriptEvent
241 the script event to set
243 void impl_setDialogElementScriptEvent_nothrow( const ::com::sun::star::script::ScriptEventDescriptor& _rScriptEvent );
245 /** returns the frame associated with our context document
247 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >
248 impl_getContextFrame_nothrow() const;
250 /** approves or denies a certain method to be included in the UI
251 @return
252 <TRUE/> if and only if the given method is allowed.
254 bool impl_filterMethod_nothrow( const EventDescription& _rEvent ) const;
256 private:
257 EventHandler(); // never implemented
258 EventHandler( const EventHandler& ); // never implemented
259 EventHandler& operator=( const EventHandler& ); // never implemented
262 //........................................................................
263 } // namespace pcr
264 //........................................................................
266 #endif // EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX