1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: eventhandler.hxx,v $
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 //........................................................................
51 //........................................................................
53 //====================================================================
55 //====================================================================
56 typedef sal_Int32 EventId
;
57 struct EventDescription
60 ::rtl::OUString sDisplayName
;
61 ::rtl::OUString sListenerClassName
;
62 ::rtl::OUString sListenerMethodName
;
64 sal_Int32 nUniqueBrowseId
;
76 const sal_Char
* _pListenerNamespaceAscii
,
77 const sal_Char
* _pListenerClassAsciiName
,
78 const sal_Char
* _pListenerMethodAsciiName
,
79 sal_uInt16 _nDisplayNameResId
,
81 sal_Int32 _nUniqueBrowseId
);
84 typedef ::std::hash_map
< ::rtl::OUString
, EventDescription
, ::rtl::OUStringHash
> EventMap
;
86 //====================================================================
88 //====================================================================
89 typedef ::cppu::WeakComponentImplHelper2
< ::com::sun::star::inspection::XPropertyHandler
90 , ::com::sun::star::lang::XServiceInfo
92 class EventHandler
: public EventHandler_Base
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
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?
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
);
119 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
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
);
147 virtual void SAL_CALL
disposing();
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
);
155 /** returns the script events associated with our introspectee
157 Takes, upon successfull return, the events currently associated with the introspectee
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
165 /** returns the script events associated with our introspectee
167 Takes, upon successfull return, the events currently associated with the introspectee
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
175 /** returns the script events associated with our introspectee
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
183 if ( m_bIsDialogElement
)
184 impl_getDialogElementScriptEvents_nothrow( _out_rEvents
);
186 impl_getFormComponentScriptEvents_nothrow( _out_rEvents
);
189 /** returns the types of the listeners which can be registered at our introspectee
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
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).
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/>).
207 if an unexpected error occurs during creation of the secondary component.
208 A <NULL/> component to be returned is not unexpected, but allowed
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
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
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
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;
252 EventHandler(); // never implemented
253 EventHandler( const EventHandler
& ); // never implemented
254 EventHandler
& operator=( const EventHandler
& ); // never implemented
257 //........................................................................
259 //........................................................................
261 #endif // EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX