cid#1640468 Dereference after null check
[LibreOffice.git] / extensions / source / propctrlr / eventhandler.hxx
blob4fa5c85d2ed5ffc1d9d870372580c27bbdacb104
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 #pragma once
22 #include "pcrcommon.hxx"
24 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/inspection/XPropertyHandler.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/frame/XFrame.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <cppuhelper/compbase.hxx>
31 #include <unotools/resmgr.hxx>
33 #include <unordered_map>
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 OUString sHelpId;
49 OString sUniqueBrowseId;
50 EventId nId;
52 EventDescription()
53 :nId( 0 )
57 EventDescription(
58 EventId _nId,
59 std::u16string_view listenerClassName,
60 std::u16string_view listenerMethodName,
61 TranslateId pDisplayNameResId,
62 OUString _sHelpId,
63 OString _sUniqueBrowseId );
66 typedef std::unordered_map< OUString, EventDescription > EventMap;
69 //= EventHandler
71 typedef ::cppu::WeakComponentImplHelper < css::inspection::XPropertyHandler
72 , css::lang::XServiceInfo
73 > EventHandler_Base;
74 class EventHandler final : public EventHandler_Base
76 private:
77 mutable ::osl::Mutex m_aMutex;
79 /// the context in which the instance was created
80 css::uno::Reference< css::uno::XComponentContext > m_xContext;
81 /// the properties of the object we're handling
82 css::uno::Reference< css::beans::XPropertySet > m_xComponent;
83 /// our XPropertyChangeListener(s)
84 PropertyChangeListeners m_aPropertyListeners;
85 /// cache of the events we found at our introspectee
86 EventMap m_aEvents;
87 /// has m_aEvents been initialized?
88 bool m_bEventsMapInitialized;
89 /// is our introspectee a dialog element?
90 bool m_bIsDialogElement;
91 // TODO: move different handling into different derived classes?
92 /// (FormComponent) type of the grid column being inspected, or -1 if we're not inspecting a grid column
93 sal_Int16 m_nGridColumnType;
95 public:
96 explicit EventHandler(
97 const css::uno::Reference< css::uno::XComponentContext >& _rxContext
100 virtual ~EventHandler() override;
102 private:
103 // XPropertyHandler overridables
104 virtual void SAL_CALL inspect( const css::uno::Reference< css::uno::XInterface >& _rxIntrospectee ) override;
105 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& _rPropertyName ) override;
106 virtual void SAL_CALL setPropertyValue( const OUString& _rPropertyName, const css::uno::Any& _rValue ) override;
107 virtual css::uno::Any SAL_CALL convertToPropertyValue( const OUString& _rPropertyName, const css::uno::Any& _rControlValue ) override;
108 virtual css::uno::Any SAL_CALL convertToControlValue( const OUString& _rPropertyName, const css::uno::Any& _rPropertyValue, const css::uno::Type& _rControlValueType ) override;
109 virtual css::beans::PropertyState SAL_CALL getPropertyState( const OUString& _rPropertyName ) override;
110 virtual void SAL_CALL addPropertyChangeListener( const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxListener ) override;
111 virtual void SAL_CALL removePropertyChangeListener( const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxListener ) override;
112 virtual css::uno::Sequence< css::beans::Property > SAL_CALL getSupportedProperties() override;
113 virtual css::uno::Sequence< OUString > SAL_CALL getSupersededProperties( ) override;
114 virtual css::uno::Sequence< OUString > SAL_CALL getActuatingProperties( ) override;
115 virtual css::inspection::LineDescriptor SAL_CALL describePropertyLine( const OUString& _rPropertyName, const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory ) override;
116 virtual sal_Bool SAL_CALL isComposable( const OUString& _rPropertyName ) override;
117 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;
118 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;
119 virtual sal_Bool SAL_CALL suspend( sal_Bool _bSuspend ) override;
121 // XComponent
122 DECLARE_XCOMPONENT()
123 virtual void SAL_CALL disposing() override;
125 // XServiceInfo
126 virtual OUString SAL_CALL getImplementationName( ) override;
127 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
128 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
130 /** returns the script events associated with our introspectee
131 @param _out_rEvents
132 Takes, upon successful return, the events currently associated with the introspectee
133 @precond
134 Our introspectee is a form component
136 void impl_getFormComponentScriptEvents_nothrow(
137 std::vector< css::script::ScriptEventDescriptor >& _out_rEvents
138 ) const;
140 /** returns the script events associated with our introspectee
141 @param _out_rEvents
142 Takes, upon successful return, the events currently associated with the introspectee
143 @precond
144 Our introspectee is a dialog element
146 void impl_getDialogElementScriptEvents_nothrow(
147 std::vector< css::script::ScriptEventDescriptor >& _out_rEvents
148 ) const;
150 /** returns the script events associated with our introspectee
151 @param _out_rEvents
152 Takes, the events currently associated with the introspectee
154 void impl_getComponentScriptEvents_nothrow(
155 std::vector< css::script::ScriptEventDescriptor >& _out_rEvents
156 ) const
158 if ( m_bIsDialogElement )
159 impl_getDialogElementScriptEvents_nothrow( _out_rEvents );
160 else
161 impl_getFormComponentScriptEvents_nothrow( _out_rEvents );
164 /** returns the types of the listeners which can be registered at our introspectee
165 @param _out_rTypes
166 Takes, upon successful return, the types of possible listeners at the introspectee
168 void impl_getComponentListenerTypes_nothrow(
169 std::vector< css::uno::Type >& _out_rTypes
170 ) const;
172 /** returns a secondary component to be used for event inspection
174 In the UI, we want to mix events for the control model with events for the control.
175 Since our introspectee is a model, this method creates a control for it (if possible).
177 @return
178 the secondary component whose events should be mixed with the introspectee's events
179 The caller takes the ownership of the component (if not <NULL/>).
181 @throws
182 if an unexpected error occurs during creation of the secondary component.
183 A <NULL/> component to be returned is not unexpected, but allowed
185 @precond
186 ->m_xComponent is not <NULL/>
188 css::uno::Reference< css::uno::XInterface >
189 impl_getSecondaryComponentForEventInspection_throw( ) const;
191 /** returns the event description for the given (programmatic) property name
192 @param _rPropertyName
193 the name whose event description should be looked up
194 @return
195 the event description for the property name
196 @throws css::beans::UnknownPropertyException
197 if our introspectee does not have an event with the given logical name (see ->getSupportedProperties)
199 const EventDescription&
200 impl_getEventForName_throw( const OUString& _rPropertyName ) const;
202 /** returns the index of our component within its parent, if this parent can be
203 obtained (XChild::getParent) and supports an ->XIndexAccess interface
205 sal_Int32 impl_getComponentIndexInParent_throw() const;
207 /** sets a given script event as event handler at a form component
209 @param _rScriptEvent
210 the script event to set
212 void impl_setFormComponentScriptEvent_nothrow( const css::script::ScriptEventDescriptor& _rScriptEvent );
214 /** sets a given script event as event handler at a dialog component
216 @param _rScriptEvent
217 the script event to set
219 void impl_setDialogElementScriptEvent_nothrow( const css::script::ScriptEventDescriptor& _rScriptEvent );
221 /** returns the frame associated with our context document
223 css::uno::Reference< css::frame::XFrame >
224 impl_getContextFrame_nothrow() const;
226 /** approves or denies a certain method to be included in the UI
227 @return
228 <TRUE/> if and only if the given method is allowed.
230 bool impl_filterMethod_nothrow( const EventDescription& _rEvent ) const;
232 EventHandler( const EventHandler& ) = delete;
233 EventHandler& operator=( const EventHandler& ) = delete;
237 } // namespace pcr
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */