1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX
23 #include "pcrcommontypes.hxx"
24 #include "pcrcommon.hxx"
26 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/inspection/XPropertyHandler.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/frame/XFrame.hpp>
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <cppuhelper/compbase2.hxx>
33 #include <comphelper/listenernotification.hxx>
43 typedef sal_Int32 EventId
;
44 struct EventDescription
47 OUString sDisplayName
;
48 OUString sListenerClassName
;
49 OUString sListenerMethodName
;
51 OString sUniqueBrowseId
;
61 const sal_Char
* _pListenerNamespaceAscii
,
62 const sal_Char
* _pListenerClassAsciiName
,
63 const sal_Char
* _pListenerMethodAsciiName
,
64 sal_uInt16 _nDisplayNameResId
,
65 const OString
& _sHelpId
,
66 const OString
& _sUniqueBrowseId
);
69 typedef std::unordered_map
< OUString
, EventDescription
, OUStringHash
> EventMap
;
74 typedef ::cppu::WeakComponentImplHelper2
< ::com::sun::star::inspection::XPropertyHandler
75 , ::com::sun::star::lang::XServiceInfo
77 class EventHandler
: public EventHandler_Base
80 mutable ::osl::Mutex m_aMutex
;
82 /// the context in which the instance was created
83 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
84 /// the properties of the object we're handling
85 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xComponent
;
86 /// our XPropertyChangeListener(s)
87 PropertyChangeListeners m_aPropertyListeners
;
88 /// cache of the events we found at our introspectee
90 /// has m_aEvents been initialized?
91 bool m_bEventsMapInitialized
;
92 /// is our introspectee a dialog element?
93 bool m_bIsDialogElement
;
94 // TODO: move different handling into different derived classes?
95 /// (FormComponent) type of the grid column being inspected, or -1 if we're not inspecting a grid column
96 sal_Int16 m_nGridColumnType
;
99 // XServiceInfo - static versions
100 static OUString SAL_CALL
getImplementationName_static( ) throw (::com::sun::star::uno::RuntimeException
);
101 static ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames_static( ) throw (::com::sun::star::uno::RuntimeException
);
102 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> Create( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
106 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
109 virtual ~EventHandler();
112 // XPropertyHandler overridables
113 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
, std::exception
) SAL_OVERRIDE
;
114 virtual ::com::sun::star::uno::Any SAL_CALL
getPropertyValue( const OUString
& _rPropertyName
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
115 virtual void SAL_CALL
setPropertyValue( const OUString
& _rPropertyName
, const ::com::sun::star::uno::Any
& _rValue
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
116 virtual ::com::sun::star::uno::Any SAL_CALL
convertToPropertyValue( const OUString
& _rPropertyName
, const ::com::sun::star::uno::Any
& _rControlValue
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
117 virtual ::com::sun::star::uno::Any SAL_CALL
convertToControlValue( const 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
, std::exception
) SAL_OVERRIDE
;
118 virtual ::com::sun::star::beans::PropertyState SAL_CALL
getPropertyState( const OUString
& _rPropertyName
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
119 virtual void SAL_CALL
addPropertyChangeListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& _rxListener
) throw (::com::sun::star::lang::NullPointerException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
120 virtual void SAL_CALL
removePropertyChangeListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& _rxListener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
121 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::Property
>
122 SAL_CALL
getSupportedProperties() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
123 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupersededProperties( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
124 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getActuatingProperties( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
125 virtual ::com::sun::star::inspection::LineDescriptor SAL_CALL
describePropertyLine( const 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
, std::exception
) SAL_OVERRIDE
;
126 virtual sal_Bool SAL_CALL
isComposable( const OUString
& _rPropertyName
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
127 virtual ::com::sun::star::inspection::InteractiveSelectionResult
128 SAL_CALL
onInteractivePropertySelection( const 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
, std::exception
) SAL_OVERRIDE
;
129 virtual void SAL_CALL
actuatingPropertyChanged( const 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
, std::exception
) SAL_OVERRIDE
;
130 virtual sal_Bool SAL_CALL
suspend( sal_Bool _bSuspend
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
134 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
137 virtual OUString SAL_CALL
getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
138 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
139 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
142 /** returns the script events associated with our introspectee
144 Takes, upon successful return, the events currently associated with the introspectee
146 Our introspectee is a form component
148 void impl_getFormComponentScriptEvents_nothrow(
149 ::com::sun::star::uno::Sequence
< ::com::sun::star::script::ScriptEventDescriptor
>& _out_rEvents
152 /** returns the script events associated with our introspectee
154 Takes, upon successful return, the events currently associated with the introspectee
156 Our introspectee is a dialog element
158 void impl_getDialogElementScriptEvents_nothrow(
159 ::com::sun::star::uno::Sequence
< ::com::sun::star::script::ScriptEventDescriptor
>& _out_rEvents
162 /** returns the script events associated with our introspectee
164 Takes, the events currently associated with the introspectee
166 inline void impl_getComponentScriptEvents_nothrow(
167 ::com::sun::star::uno::Sequence
< ::com::sun::star::script::ScriptEventDescriptor
>& _out_rEvents
170 if ( m_bIsDialogElement
)
171 impl_getDialogElementScriptEvents_nothrow( _out_rEvents
);
173 impl_getFormComponentScriptEvents_nothrow( _out_rEvents
);
176 /** returns the types of the listeners which can be registered at our introspectee
178 Takes, upon successful return, the types of possible listeners at the introspectee
180 void impl_getCopmonentListenerTypes_nothrow(
181 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
>& _out_rTypes
184 /** returns a secondary component to be used for event inspection
186 In the UI, we want to mix events for the control model with events for the control.
187 Since our introspectee is a model, this method creates a control for it (if possible).
190 the secondary component whose events should be mixed with the introspectee's events
191 The caller takes the ownership of the component (if not <NULL/>).
194 if an unexpected error occurs during creation of the secondary component.
195 A <NULL/> component to be returned is not unexpected, but allowed
198 ->m_xComponent is not <NULL/>
200 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
201 impl_getSecondaryComponentForEventInspection_throw( ) const;
203 /** returns the event description for the given (programmatic) property name
204 @param _rPropertyName
205 the name whose event description should be looked up
207 the event description for the property name
208 @throws ::com::sun::star::beans::UnknownPropertyException
209 if our introspectee does not have an event with the given logical name (see ->getSupportedProperties)
211 const EventDescription
&
212 impl_getEventForName_throw( const OUString
& _rPropertyName
) const;
214 /** returns the index of our component within its parent, if this parent can be
215 obtained (XChild::getParent) and supports an ->XIndexAccess interface
217 sal_Int32
impl_getComponentIndexInParent_throw() const;
219 /** sets a given script event as event handler at a form component
222 the script event to set
224 void impl_setFormComponentScriptEvent_nothrow( const ::com::sun::star::script::ScriptEventDescriptor
& _rScriptEvent
);
226 /** sets a given script event as event handler at a dialog component
229 the script event to set
231 void impl_setDialogElementScriptEvent_nothrow( const ::com::sun::star::script::ScriptEventDescriptor
& _rScriptEvent
);
233 /** returns the frame associated with our context document
235 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>
236 impl_getContextFrame_nothrow() const;
238 /** approves or denies a certain method to be included in the UI
240 <TRUE/> if and only if the given method is allowed.
242 bool impl_filterMethod_nothrow( const EventDescription
& _rEvent
) const;
245 EventHandler( const EventHandler
& ) SAL_DELETED_FUNCTION
;
246 EventHandler
& operator=( const EventHandler
& ) SAL_DELETED_FUNCTION
;
253 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */