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