update dev300-m58
[ooovba.git] / extensions / source / propctrlr / eventhandler.hxx
blob41446e140a756d2d08ca87cca53dec93c3fc8dfe
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?
111 public:
112 // XServiceInfo - static versions
113 static ::rtl::OUString SAL_CALL getImplementationName_static( ) throw (::com::sun::star::uno::RuntimeException);
114 static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static( ) throw (::com::sun::star::uno::RuntimeException);
115 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > Create( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
117 protected:
118 EventHandler(
119 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext
122 ~EventHandler();
124 protected:
125 // XPropertyHandler overridables
126 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);
127 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
128 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);
129 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);
130 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);
131 virtual ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
132 virtual void SAL_CALL addPropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
133 virtual void SAL_CALL removePropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
134 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >
135 SAL_CALL getSupportedProperties() throw (::com::sun::star::uno::RuntimeException);
136 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupersededProperties( ) throw (::com::sun::star::uno::RuntimeException);
137 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getActuatingProperties( ) throw (::com::sun::star::uno::RuntimeException);
138 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);
139 virtual ::sal_Bool SAL_CALL isComposable( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
140 virtual ::com::sun::star::inspection::InteractiveSelectionResult
141 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);
142 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);
143 virtual sal_Bool SAL_CALL suspend( sal_Bool _bSuspend ) throw (::com::sun::star::uno::RuntimeException);
145 // XComponent
146 DECLARE_XCOMPONENT()
147 virtual void SAL_CALL disposing();
149 // XServiceInfo
150 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
151 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
152 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
154 private:
155 /** returns the script events associated with our introspectee
156 @param _out_rEvents
157 Takes, upon successfull return, the events currently associated with the introspectee
158 @precond
159 Our introspectee is a form component
161 void impl_getFormComponentScriptEvents_nothrow(
162 ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents
163 ) const;
165 /** returns the script events associated with our introspectee
166 @param _out_rEvents
167 Takes, upon successfull return, the events currently associated with the introspectee
168 @precond
169 Our introspectee is a dialog element
171 void impl_getDialogElementScriptEvents_nothrow(
172 ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents
173 ) const;
175 /** returns the script events associated with our introspectee
176 @param _out_rEvents
177 Takes, the events currently associated with the introspectee
179 inline void impl_getComponentScriptEvents_nothrow(
180 ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents
181 ) const
183 if ( m_bIsDialogElement )
184 impl_getDialogElementScriptEvents_nothrow( _out_rEvents );
185 else
186 impl_getFormComponentScriptEvents_nothrow( _out_rEvents );
189 /** returns the types of the listeners which can be registered at our introspectee
190 @param _out_rTypes
191 Takes, upon successfull return, the types of possible listeners at the introspectee
193 void impl_getCopmonentListenerTypes_nothrow(
194 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >& _out_rTypes
195 ) const;
197 /** returns a secondary component to be used for event inspection
199 In the UI, we want to mix events for the control model with events for the control.
200 Since our introspectee is a model, this method creates a control for it (if possible).
202 @return
203 the secondary component whose events should be mixed with the introspectee's events
204 The caller takes the ownership of the component (if not <NULL/>).
206 @throws
207 if an unexpected error occurs during creation of the secondary component.
208 A <NULL/> component to be returned is not unexpected, but allowed
210 @precond
211 ->m_xComponent is not <NULL/>
213 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
214 impl_getSecondaryComponentForEventInspection_throw( ) const;
216 /** returns the event description for the given (programmatic) property name
217 @param _rPropertyName
218 the name whose event description should be looked up
219 @return
220 the event description for the property name
221 @throws ::com::sun::star::beans::UnknownPropertyException
222 if our introspectee does not have an event with the given logical name (see ->getSupportedProperties)
224 const EventDescription&
225 impl_getEventForName_throw( const ::rtl::OUString& _rPropertyName ) const;
227 /** returns the index of our component within its parent, if this parent can be
228 obtained (XChild::getParent) and supports an ->XIndexAccess interface
230 sal_Int32 impl_getComponentIndexInParent_throw() const;
232 /** sets a given script event as event handler at a form component
234 @param _rScriptEvent
235 the script event to set
237 void impl_setFormComponentScriptEvent_nothrow( const ::com::sun::star::script::ScriptEventDescriptor& _rScriptEvent );
239 /** sets a given script event as event handler at a dialog component
241 @param _rScriptEvent
242 the script event to set
244 void impl_setDialogElementScriptEvent_nothrow( const ::com::sun::star::script::ScriptEventDescriptor& _rScriptEvent );
246 /** returns the frame associated with our context document
248 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >
249 impl_getContextFrame_nothrow() const;
251 private:
252 EventHandler(); // never implemented
253 EventHandler( const EventHandler& ); // never implemented
254 EventHandler& operator=( const EventHandler& ); // never implemented
257 //........................................................................
258 } // namespace pcr
259 //........................................................................
261 #endif // EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX