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?
110 /// (FormComponent) type of the grid column being inspected, or -1 if we're not inspecting a grid column
111 sal_Int16 m_nGridColumnType
;
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
);
121 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
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
);
149 virtual void SAL_CALL
disposing();
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
);
157 /** returns the script events associated with our introspectee
159 Takes, upon successfull return, the events currently associated with the introspectee
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
167 /** returns the script events associated with our introspectee
169 Takes, upon successfull return, the events currently associated with the introspectee
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
177 /** returns the script events associated with our introspectee
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
185 if ( m_bIsDialogElement
)
186 impl_getDialogElementScriptEvents_nothrow( _out_rEvents
);
188 impl_getFormComponentScriptEvents_nothrow( _out_rEvents
);
191 /** returns the types of the listeners which can be registered at our introspectee
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
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).
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/>).
209 if an unexpected error occurs during creation of the secondary component.
210 A <NULL/> component to be returned is not unexpected, but allowed
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
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
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
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
255 <TRUE/> if and only if the given method is allowed.
257 bool impl_filterMethod_nothrow( const EventDescription
& _rEvent
) const;
260 EventHandler(); // never implemented
261 EventHandler( const EventHandler
& ); // never implemented
262 EventHandler
& operator=( const EventHandler
& ); // never implemented
265 //........................................................................
267 //........................................................................
269 #endif // EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX