tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / extensions / source / propctrlr / propertyhandler.hxx
blob1d80142bc45690ad26b727e622234fd282080c99
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/uno/XComponentContext.hpp>
25 #include <com/sun/star/beans/PropertyState.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/beans/Property.hpp>
28 #include <com/sun/star/script/XTypeConverter.hpp>
29 #include <com/sun/star/frame/XModel.hpp>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/uno/Any.hxx>
32 #include <com/sun/star/util/Date.hpp>
33 #include <com/sun/star/util/Time.hpp>
34 #include <com/sun/star/util/DateTime.hpp>
35 #include <com/sun/star/inspection/XPropertyHandler.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <cppuhelper/basemutex.hxx>
38 #include <cppuhelper/compbase.hxx>
39 #include <cppuhelper/implbase1.hxx>
40 #include <comphelper/uno3.hxx>
42 #include <memory>
43 #include <vector>
45 namespace com::sun::star {
46 namespace inspection {
47 struct LineDescriptor;
48 class XPropertyControlFactory;
52 namespace weld { class Window; }
54 namespace pcr
58 typedef sal_Int32 PropertyId;
61 //= PropertyHandler
63 class OPropertyInfoService;
64 typedef ::cppu::WeakComponentImplHelper < css::inspection::XPropertyHandler
65 > PropertyHandler_Base;
66 /** the base class for property handlers
68 class PropertyHandler : public ::cppu::BaseMutex
69 , public PropertyHandler_Base
71 private:
72 /// cache for getSupportedProperties
73 mutable StlSyntaxSequence< css::beans::Property >
74 m_aSupportedProperties;
75 mutable bool m_bSupportedPropertiesAreKnown;
77 private:
78 /// the property listener which has been registered
79 PropertyChangeListeners m_aPropertyListeners;
81 protected:
82 /// the context in which the instance was created
83 css::uno::Reference< css::uno::XComponentContext > m_xContext;
84 /// the component we're inspecting
85 css::uno::Reference< css::beans::XPropertySet > m_xComponent;
86 /// info about our component's properties
87 css::uno::Reference< css::beans::XPropertySetInfo > m_xComponentPropertyInfo;
88 /// type converter, needed on various occasions
89 css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
90 /// access to property meta data
91 std::unique_ptr< OPropertyInfoService > m_pInfoService;
93 protected:
94 explicit PropertyHandler(
95 const css::uno::Reference< css::uno::XComponentContext >& _rxContext
97 virtual ~PropertyHandler() override;
99 // default implementations for XPropertyHandler
100 virtual void SAL_CALL inspect( const css::uno::Reference< css::uno::XInterface >& _rxIntrospectee ) override;
101 virtual css::uno::Sequence< css::beans::Property > SAL_CALL getSupportedProperties() override;
102 virtual css::uno::Sequence< OUString > SAL_CALL getSupersededProperties( ) override;
103 virtual css::uno::Sequence< OUString > SAL_CALL getActuatingProperties( ) override;
104 virtual css::uno::Any SAL_CALL convertToPropertyValue( const OUString& _rPropertyName, const css::uno::Any& _rControlValue ) override;
105 virtual css::uno::Any SAL_CALL convertToControlValue( const OUString& _rPropertyName, const css::uno::Any& _rPropertyValue, const css::uno::Type& _rControlValueType ) override;
106 virtual css::beans::PropertyState SAL_CALL getPropertyState( const OUString& _rPropertyName ) override;
107 virtual css::inspection::LineDescriptor SAL_CALL describePropertyLine( const OUString& _rPropertyName, const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory ) override;
108 virtual sal_Bool SAL_CALL isComposable( const OUString& _rPropertyName ) override;
109 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;
110 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;
111 virtual void SAL_CALL addPropertyChangeListener( const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxListener ) override;
112 virtual void SAL_CALL removePropertyChangeListener( const css::uno::Reference< css::beans::XPropertyChangeListener >& _rxListener ) override;
113 virtual sal_Bool SAL_CALL suspend( sal_Bool _bSuspend ) override;
115 // XComponent
116 DECLARE_XCOMPONENT()
117 virtual void SAL_CALL disposing() override;
119 // own overridables
120 virtual css::uno::Sequence< css::beans::Property >
121 doDescribeSupportedProperties() const = 0;
123 /// called when XPropertyHandler::inspect has been called, and we thus have a new component to inspect
124 virtual void onNewComponent();
126 protected:
127 /** fires the change in a property value to our listener (if any)
128 @see addPropertyChangeListener
130 void firePropertyChange( const OUString& _rPropName, PropertyId _nPropId,
131 const css::uno::Any& _rOldValue, const css::uno::Any& _rNewValue );
133 /** retrieves a window which can be used as parent for dialogs
135 weld::Window* impl_getDefaultDialogFrame_nothrow() const;
137 /** retrieves the property id for a given property name
138 @throw css::beans::UnknownPropertyException
139 if the property name is not known to our ->m_pInfoService
141 PropertyId impl_getPropertyId_throwUnknownProperty( const OUString& _rPropertyName ) const;
143 /** retrieves the property id for a given property name
144 @throw css::uno::RuntimeException
145 if the property name is not known to our ->m_pInfoService
147 PropertyId impl_getPropertyId_throwRuntime( const OUString& _rPropertyName ) const;
150 /** retrieves the property id for a given property name
151 @returns -1
152 if the property name is not known to our ->m_pInfoService
154 PropertyId impl_getPropertyId_nothrow( const OUString& _rPropertyName ) const;
156 // helper for implementing doDescribeSupportedProperties
157 /** adds a description for the given string property to the given property vector
158 Most probably to be called from within getSupportedProperties
160 inline void addStringPropertyDescription(
161 std::vector< css::beans::Property >& _rProperties,
162 const OUString& _rPropertyName
163 ) const;
165 /** adds a description for the given int32 property to the given property vector
167 inline void addInt32PropertyDescription(
168 std::vector< css::beans::Property >& _rProperties,
169 const OUString& _rPropertyName,
170 sal_Int16 _nAttribs = 0
171 ) const;
173 /** adds a description for the given int16 property to the given property vector
175 inline void addInt16PropertyDescription(
176 std::vector< css::beans::Property >& _rProperties,
177 const OUString& _rPropertyName,
178 sal_Int16 _nAttribs = 0
179 ) const;
181 /** adds a description for the given double property to the given property vector
183 inline void addDoublePropertyDescription(
184 std::vector< css::beans::Property >& _rProperties,
185 const OUString& _rPropertyName,
186 sal_Int16 _nAttribs
187 ) const;
189 /** adds a description for the given date property to the given property vector
191 inline void addDatePropertyDescription(
192 std::vector< css::beans::Property >& _rProperties,
193 const OUString& _rPropertyName,
194 sal_Int16 _nAttribs
195 ) const;
197 /** adds a description for the given time property to the given property vector
199 inline void addTimePropertyDescription(
200 std::vector< css::beans::Property >& _rProperties,
201 const OUString& _rPropertyName,
202 sal_Int16 _nAttribs
203 ) const;
205 /** adds a description for the given DateTime property to the given property vector
207 inline void addDateTimePropertyDescription(
208 std::vector< css::beans::Property >& _rProperties,
209 const OUString& _rPropertyName,
210 sal_Int16 _nAttribs
211 ) const;
213 /// adds a Property, given by name only, to a given vector of Properties
214 void implAddPropertyDescription(
215 std::vector< css::beans::Property >& _rProperties,
216 const OUString& _rPropertyName,
217 const css::uno::Type& _rType,
218 sal_Int16 _nAttribs = 0
219 ) const;
222 // helper for accessing and maintaining meta data about our supported properties
224 /** retrieves a property given by handle
226 @return
227 a pointer to the descriptor for the given properties, if it is one of our
228 supported properties, <NULL/> else.
230 @see doDescribeSupportedProperties
231 @see impl_getPropertyFromId_throw
233 const css::beans::Property*
234 impl_getPropertyFromId_nothrow( PropertyId _nPropId ) const;
236 /** retrieves a property given by handle
238 @throws UnknownPropertyException
239 if the handler does not support a property with the given handle
241 @seealso doDescribeSupportedProperties
242 @see impl_getPropertyFromId_nothrow
244 const css::beans::Property&
245 impl_getPropertyFromId_throw( PropertyId _nPropId ) const;
247 /** determines whether a given property id is part of our supported properties
248 @see getSupportedProperties
249 @see doDescribeSupportedProperties
251 bool impl_isSupportedProperty_nothrow( PropertyId _nPropId ) const
253 return impl_getPropertyFromId_nothrow( _nPropId ) != nullptr;
256 /** retrieves a property given by name
258 @throws UnknownPropertyException
259 if the handler does not support a property with the given name
261 @seealso doDescribeSupportedProperties
263 const css::beans::Property&
264 impl_getPropertyFromName_throw( const OUString& _rPropertyName ) const;
266 /** get the name of a property given by handle
268 inline OUString
269 impl_getPropertyNameFromId_nothrow( PropertyId _nPropId ) const;
271 /** returns the value of the ContextDocument property in the ComponentContext which was used to create
272 this handler.
274 css::uno::Reference< css::frame::XModel >
275 impl_getContextDocument_nothrow() const
277 return css::uno::Reference< css::frame::XModel >(
278 m_xContext->getValueByName( u"ContextDocument"_ustr ), css::uno::UNO_QUERY );
281 /** marks the context document as modified
283 @see impl_getContextDocument_nothrow
285 void impl_setContextDocumentModified_nothrow() const;
287 /// determines whether our component has a given property
288 bool impl_componentHasProperty_throw( const OUString& _rPropName ) const;
290 /** determines the default measure unit for the document in which our component lives
292 sal_Int16 impl_getDocumentMeasurementUnit_throw() const;
294 private:
295 PropertyHandler( const PropertyHandler& ) = delete;
296 PropertyHandler& operator=( const PropertyHandler& ) = delete;
300 inline void PropertyHandler::addStringPropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName ) const
302 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<OUString>::get() );
305 inline void PropertyHandler::addInt32PropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
307 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<sal_Int32>::get(), _nAttribs );
310 inline void PropertyHandler::addInt16PropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
312 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<sal_Int16>::get(), _nAttribs );
315 inline void PropertyHandler::addDoublePropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
317 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<double>::get(), _nAttribs );
320 inline void PropertyHandler::addDatePropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
322 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<css::util::Date>::get(), _nAttribs );
325 inline void PropertyHandler::addTimePropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
327 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<css::util::Time>::get(), _nAttribs );
330 inline void PropertyHandler::addDateTimePropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
332 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<css::util::DateTime>::get(), _nAttribs );
335 inline OUString PropertyHandler::impl_getPropertyNameFromId_nothrow( PropertyId _nPropId ) const
337 const css::beans::Property* pProp = impl_getPropertyFromId_nothrow( _nPropId );
338 return pProp ? pProp->Name : OUString();
342 //= PropertyHandlerComponent
344 typedef ::cppu::ImplHelper1 < css::lang::XServiceInfo
345 > PropertyHandlerComponent_Base;
346 /** PropertyHandler implementation which additionally supports XServiceInfo
348 class PropertyHandlerComponent :public PropertyHandler
349 ,public PropertyHandlerComponent_Base
351 protected:
352 explicit PropertyHandlerComponent(
353 const css::uno::Reference< css::uno::XComponentContext >& _rxContext
356 DECLARE_XINTERFACE()
357 DECLARE_XTYPEPROVIDER()
359 // XServiceInfo
360 virtual OUString SAL_CALL getImplementationName( ) override = 0;
361 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) final override;
362 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override = 0;
366 } // namespace pcr
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */