Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / propctrlr / eventhandler.hxx
blob7c461c6e0bc4f1acf819a8418ee6494b63580e82
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/compbase.hxx>
35 namespace pcr
39 //= EventDescription
41 typedef sal_Int32 EventId;
42 struct EventDescription
44 public:
45 OUString sDisplayName;
46 OUString sListenerClassName;
47 OUString sListenerMethodName;
48 OString sHelpId;
49 OString sUniqueBrowseId;
50 EventId nId;
52 EventDescription()
53 :nId( 0 )
57 EventDescription(
58 EventId _nId,
59 const sal_Char* _pListenerNamespaceAscii,
60 const sal_Char* _pListenerClassAsciiName,
61 const sal_Char* _pListenerMethodAsciiName,
62 const char* pDisplayNameResId,
63 const OString& _sHelpId,
64 const OString& _sUniqueBrowseId );
67 typedef std::unordered_map< OUString, EventDescription > EventMap;
70 //= EventHandler
72 typedef ::cppu::WeakComponentImplHelper < css::inspection::XPropertyHandler
73 , css::lang::XServiceInfo
74 > EventHandler_Base;
75 class EventHandler final : public EventHandler_Base
77 private:
78 mutable ::osl::Mutex m_aMutex;
80 /// the context in which the instance was created
81 css::uno::Reference< css::uno::XComponentContext > m_xContext;
82 /// the properties of the object we're handling
83 css::uno::Reference< css::beans::XPropertySet > m_xComponent;
84 /// our XPropertyChangeListener(s)
85 PropertyChangeListeners m_aPropertyListeners;
86 /// cache of the events we found at our introspectee
87 EventMap m_aEvents;
88 /// has m_aEvents been initialized?
89 bool m_bEventsMapInitialized;
90 /// is our introspectee a dialog element?
91 bool m_bIsDialogElement;
92 // TODO: move different handling into different derived classes?
93 /// (FormComponent) type of the grid column being inspected, or -1 if we're not inspecting a grid column
94 sal_Int16 m_nGridColumnType;
96 public:
97 // XServiceInfo - static versions
98 /// @throws css::uno::RuntimeException
99 static OUString getImplementationName_static( );
100 /// @throws css::uno::RuntimeException
101 static css::uno::Sequence< OUString > getSupportedServiceNames_static( );
102 static css::uno::Reference< css::uno::XInterface > Create( const css::uno::Reference< css::uno::XComponentContext >& _rxContext );
104 private:
105 explicit EventHandler(
106 const css::uno::Reference< css::uno::XComponentContext >& _rxContext
109 virtual ~EventHandler() override;
111 // XPropertyHandler overridables
112 virtual void SAL_CALL inspect( const css::uno::Reference< css::uno::XInterface >& _rxIntrospectee ) override;
113 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& _rPropertyName ) override;
114 virtual void SAL_CALL setPropertyValue( const OUString& _rPropertyName, const css::uno::Any& _rValue ) override;
115 virtual css::uno::Any SAL_CALL convertToPropertyValue( const OUString& _rPropertyName, const css::uno::Any& _rControlValue ) override;
116 virtual css::uno::Any SAL_CALL convertToControlValue( const OUString& _rPropertyName, const css::uno::Any& _rPropertyValue, const css::uno::Type& _rControlValueType ) override;
117 virtual css::beans::PropertyState SAL_CALL getPropertyState( const OUString& _rPropertyName ) override;
118 virtual void SAL_CALL addPropertyChangeListener( const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxListener ) override;
119 virtual void SAL_CALL removePropertyChangeListener( const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxListener ) override;
120 virtual css::uno::Sequence< css::beans::Property > SAL_CALL getSupportedProperties() override;
121 virtual css::uno::Sequence< OUString > SAL_CALL getSupersededProperties( ) override;
122 virtual css::uno::Sequence< OUString > SAL_CALL getActuatingProperties( ) override;
123 virtual css::inspection::LineDescriptor SAL_CALL describePropertyLine( const OUString& _rPropertyName, const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory ) override;
124 virtual sal_Bool SAL_CALL isComposable( const OUString& _rPropertyName ) override;
125 virtual css::inspection::InteractiveSelectionResult SAL_CALL onInteractivePropertySelection( const OUString& _rPropertyName, sal_Bool _bPrimary, css::uno::Any& _rData, const css::uno::Reference< css::inspection::XObjectInspectorUI >& _rxInspectorUI ) override;
126 virtual void SAL_CALL actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const css::uno::Any& _rNewValue, const css::uno::Any& _rOldValue, const css::uno::Reference< css::inspection::XObjectInspectorUI >& _rxInspectorUI, sal_Bool _bFirstTimeInit ) override;
127 virtual sal_Bool SAL_CALL suspend( sal_Bool _bSuspend ) override;
129 // XComponent
130 DECLARE_XCOMPONENT()
131 virtual void SAL_CALL disposing() override;
133 // XServiceInfo
134 virtual OUString SAL_CALL getImplementationName( ) override;
135 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
136 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
138 /** returns the script events associated with our introspectee
139 @param _out_rEvents
140 Takes, upon successful return, the events currently associated with the introspectee
141 @precond
142 Our introspectee is a form component
144 void impl_getFormComponentScriptEvents_nothrow(
145 std::vector< css::script::ScriptEventDescriptor >& _out_rEvents
146 ) const;
148 /** returns the script events associated with our introspectee
149 @param _out_rEvents
150 Takes, upon successful return, the events currently associated with the introspectee
151 @precond
152 Our introspectee is a dialog element
154 void impl_getDialogElementScriptEvents_nothrow(
155 std::vector< css::script::ScriptEventDescriptor >& _out_rEvents
156 ) const;
158 /** returns the script events associated with our introspectee
159 @param _out_rEvents
160 Takes, the events currently associated with the introspectee
162 void impl_getComponentScriptEvents_nothrow(
163 std::vector< css::script::ScriptEventDescriptor >& _out_rEvents
164 ) const
166 if ( m_bIsDialogElement )
167 impl_getDialogElementScriptEvents_nothrow( _out_rEvents );
168 else
169 impl_getFormComponentScriptEvents_nothrow( _out_rEvents );
172 /** returns the types of the listeners which can be registered at our introspectee
173 @param _out_rTypes
174 Takes, upon successful return, the types of possible listeners at the introspectee
176 void impl_getComponentListenerTypes_nothrow(
177 std::vector< css::uno::Type >& _out_rTypes
178 ) const;
180 /** returns a secondary component to be used for event inspection
182 In the UI, we want to mix events for the control model with events for the control.
183 Since our introspectee is a model, this method creates a control for it (if possible).
185 @return
186 the secondary component whose events should be mixed with the introspectee's events
187 The caller takes the ownership of the component (if not <NULL/>).
189 @throws
190 if an unexpected error occurs during creation of the secondary component.
191 A <NULL/> component to be returned is not unexpected, but allowed
193 @precond
194 ->m_xComponent is not <NULL/>
196 css::uno::Reference< css::uno::XInterface >
197 impl_getSecondaryComponentForEventInspection_throw( ) const;
199 /** returns the event description for the given (programmatic) property name
200 @param _rPropertyName
201 the name whose event description should be looked up
202 @return
203 the event description for the property name
204 @throws css::beans::UnknownPropertyException
205 if our introspectee does not have an event with the given logical name (see ->getSupportedProperties)
207 const EventDescription&
208 impl_getEventForName_throw( const OUString& _rPropertyName ) const;
210 /** returns the index of our component within its parent, if this parent can be
211 obtained (XChild::getParent) and supports an ->XIndexAccess interface
213 sal_Int32 impl_getComponentIndexInParent_throw() const;
215 /** sets a given script event as event handler at a form component
217 @param _rScriptEvent
218 the script event to set
220 void impl_setFormComponentScriptEvent_nothrow( const css::script::ScriptEventDescriptor& _rScriptEvent );
222 /** sets a given script event as event handler at a dialog component
224 @param _rScriptEvent
225 the script event to set
227 void impl_setDialogElementScriptEvent_nothrow( const css::script::ScriptEventDescriptor& _rScriptEvent );
229 /** returns the frame associated with our context document
231 css::uno::Reference< css::frame::XFrame >
232 impl_getContextFrame_nothrow() const;
234 /** approves or denies a certain method to be included in the UI
235 @return
236 <TRUE/> if and only if the given method is allowed.
238 bool impl_filterMethod_nothrow( const EventDescription& _rEvent ) const;
240 EventHandler( const EventHandler& ) = delete;
241 EventHandler& operator=( const EventHandler& ) = delete;
245 } // namespace pcr
248 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */