LibreOffice Module extensions (master) 1
propertyhandler.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include "pcrcommon.hxx"
23
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>
40#include <comphelper/uno3.hxx>
41
42#include <memory>
43#include <vector>
44
45namespace com::sun::star {
46 namespace inspection {
47 struct LineDescriptor;
48 class XPropertyControlFactory;
49 }
50}
51
52namespace weld { class Window; }
53
54namespace pcr
55{
56
57
58 typedef sal_Int32 PropertyId;
59
60
61 //= PropertyHandler
62
64 typedef ::cppu::WeakComponentImplHelper < css::inspection::XPropertyHandler
70 {
71 private:
76
77 private:
80
81 protected:
83 css::uno::Reference< css::uno::XComponentContext > m_xContext;
85 css::uno::Reference< css::beans::XPropertySet > m_xComponent;
87 css::uno::Reference< css::beans::XPropertySetInfo > m_xComponentPropertyInfo;
89 css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
91 std::unique_ptr< OPropertyInfoService > m_pInfoService;
92
93 protected:
95 const css::uno::Reference< css::uno::XComponentContext >& _rxContext
96 );
97 virtual ~PropertyHandler() override;
98
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;
114
115 // XComponent
117 virtual void SAL_CALL disposing() override;
118
119 // own overridables
120 virtual css::uno::Sequence< css::beans::Property >
122
124 virtual void onNewComponent();
125
126 protected:
130 void firePropertyChange( const OUString& _rPropName, PropertyId _nPropId,
131 const css::uno::Any& _rOldValue, const css::uno::Any& _rNewValue );
132
136
141 PropertyId impl_getPropertyId_throwUnknownProperty( const OUString& _rPropertyName ) const;
142
147 PropertyId impl_getPropertyId_throwRuntime( const OUString& _rPropertyName ) const;
148
149
154 PropertyId impl_getPropertyId_nothrow( const OUString& _rPropertyName ) const;
155
156 // helper for implementing doDescribeSupportedProperties
161 std::vector< css::beans::Property >& _rProperties,
162 const OUString& _rPropertyName
163 ) const;
164
167 inline void addInt32PropertyDescription(
168 std::vector< css::beans::Property >& _rProperties,
169 const OUString& _rPropertyName,
170 sal_Int16 _nAttribs = 0
171 ) const;
172
175 inline void addInt16PropertyDescription(
176 std::vector< css::beans::Property >& _rProperties,
177 const OUString& _rPropertyName,
178 sal_Int16 _nAttribs = 0
179 ) const;
180
184 std::vector< css::beans::Property >& _rProperties,
185 const OUString& _rPropertyName,
186 sal_Int16 _nAttribs
187 ) const;
188
191 inline void addDatePropertyDescription(
192 std::vector< css::beans::Property >& _rProperties,
193 const OUString& _rPropertyName,
194 sal_Int16 _nAttribs
195 ) const;
196
199 inline void addTimePropertyDescription(
200 std::vector< css::beans::Property >& _rProperties,
201 const OUString& _rPropertyName,
202 sal_Int16 _nAttribs
203 ) const;
204
208 std::vector< css::beans::Property >& _rProperties,
209 const OUString& _rPropertyName,
210 sal_Int16 _nAttribs
211 ) const;
212
215 std::vector< css::beans::Property >& _rProperties,
216 const OUString& _rPropertyName,
217 const css::uno::Type& _rType,
218 sal_Int16 _nAttribs = 0
219 ) const;
220
221
222 // helper for accessing and maintaining meta data about our supported properties
223
233 const css::beans::Property*
235
244 const css::beans::Property&
246
252 {
253 return impl_getPropertyFromId_nothrow( _nPropId ) != nullptr;
254 }
255
263 const css::beans::Property&
264 impl_getPropertyFromName_throw( const OUString& _rPropertyName ) const;
265
268 inline OUString
270
274 css::uno::Reference< css::frame::XModel >
276 {
277 return css::uno::Reference< css::frame::XModel >(
278 m_xContext->getValueByName( "ContextDocument" ), css::uno::UNO_QUERY );
279 }
280
286
288 bool impl_componentHasProperty_throw( const OUString& _rPropName ) const;
289
293
294 private:
297 };
298
299
300 inline void PropertyHandler::addStringPropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName ) const
301 {
302 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<OUString>::get() );
303 }
304
305 inline void PropertyHandler::addInt32PropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
306 {
307 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<sal_Int32>::get(), _nAttribs );
308 }
309
310 inline void PropertyHandler::addInt16PropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
311 {
312 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<sal_Int16>::get(), _nAttribs );
313 }
314
315 inline void PropertyHandler::addDoublePropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
316 {
317 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<double>::get(), _nAttribs );
318 }
319
320 inline void PropertyHandler::addDatePropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
321 {
322 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<css::util::Date>::get(), _nAttribs );
323 }
324
325 inline void PropertyHandler::addTimePropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
326 {
327 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<css::util::Time>::get(), _nAttribs );
328 }
329
330 inline void PropertyHandler::addDateTimePropertyDescription( std::vector< css::beans::Property >& _rProperties, const OUString& _rPropertyName, sal_Int16 _nAttribs ) const
331 {
332 implAddPropertyDescription( _rProperties, _rPropertyName, ::cppu::UnoType<css::util::DateTime>::get(), _nAttribs );
333 }
334
336 {
337 const css::beans::Property* pProp = impl_getPropertyFromId_nothrow( _nPropId );
338 return pProp ? pProp->Name : OUString();
339 }
340
341
342 //= PropertyHandlerComponent
343
344 typedef ::cppu::ImplHelper1 < css::lang::XServiceInfo
350 {
351 protected:
353 const css::uno::Reference< css::uno::XComponentContext >& _rxContext
354 );
355
358
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;
363 };
364
365
366} // namespace pcr
367
368
369/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertyHandler implementation which additionally supports XServiceInfo.
virtual OUString SAL_CALL getImplementationName() override=0
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) final override
PropertyHandlerComponent(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override=0
the base class for property handlers
void addInt16PropertyDescription(std::vector< css::beans::Property > &_rProperties, const OUString &_rPropertyName, sal_Int16 _nAttribs=0) const
adds a description for the given int16 property to the given property vector
virtual css::uno::Sequence< css::beans::Property > SAL_CALL getSupportedProperties() override
std::unique_ptr< OPropertyInfoService > m_pInfoService
access to property meta data
PropertyHandler & operator=(const PropertyHandler &)=delete
PropertyId impl_getPropertyId_nothrow(const OUString &_rPropertyName) const
retrieves the property id for a given property name
void addDoublePropertyDescription(std::vector< css::beans::Property > &_rProperties, const OUString &_rPropertyName, sal_Int16 _nAttribs) const
adds a description for the given double property to the given property vector
css::uno::Reference< css::uno::XComponentContext > m_xContext
the context in which the instance was created
PropertyHandler(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
void addDatePropertyDescription(std::vector< css::beans::Property > &_rProperties, const OUString &_rPropertyName, sal_Int16 _nAttribs) const
adds a description for the given date property to the given property vector
virtual css::uno::Sequence< OUString > SAL_CALL getSupersededProperties() override
const css::beans::Property * impl_getPropertyFromId_nothrow(PropertyId _nPropId) const
retrieves a property given by handle
css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter
type converter, needed on various occasions
virtual void onNewComponent()
called when XPropertyHandler::inspect has been called, and we thus have a new component to inspect
virtual void SAL_CALL addPropertyChangeListener(const css::uno::Reference< css::beans::XPropertyChangeListener > &_rxListener) override
virtual css::uno::Sequence< css::beans::Property > doDescribeSupportedProperties() const =0
bool impl_isSupportedProperty_nothrow(PropertyId _nPropId) const
determines whether a given property id is part of our supported properties
void addTimePropertyDescription(std::vector< css::beans::Property > &_rProperties, const OUString &_rPropertyName, sal_Int16 _nAttribs) const
adds a description for the given time property to the given property vector
StlSyntaxSequence< css::beans::Property > m_aSupportedProperties
cache for getSupportedProperties
virtual css::uno::Any SAL_CALL convertToPropertyValue(const OUString &_rPropertyName, const css::uno::Any &_rControlValue) override
void addStringPropertyDescription(std::vector< css::beans::Property > &_rProperties, const OUString &_rPropertyName) const
adds a description for the given string property to the given property vector Most probably to be cal...
css::uno::Reference< css::beans::XPropertySetInfo > m_xComponentPropertyInfo
info about our component's properties
virtual css::uno::Sequence< OUString > SAL_CALL getActuatingProperties() override
void firePropertyChange(const OUString &_rPropName, PropertyId _nPropId, const css::uno::Any &_rOldValue, const css::uno::Any &_rNewValue)
fires the change in a property value to our listener (if any)
bool impl_componentHasProperty_throw(const OUString &_rPropName) const
determines whether our component has a given property
virtual void SAL_CALL disposing() override
const css::beans::Property & impl_getPropertyFromName_throw(const OUString &_rPropertyName) const
retrieves a property given by name
virtual void SAL_CALL inspect(const css::uno::Reference< css::uno::XInterface > &_rxIntrospectee) override
virtual css::uno::Any SAL_CALL convertToControlValue(const OUString &_rPropertyName, const css::uno::Any &_rPropertyValue, const css::uno::Type &_rControlValueType) override
PropertyId impl_getPropertyId_throwUnknownProperty(const OUString &_rPropertyName) const
retrieves the property id for a given property name
virtual sal_Bool SAL_CALL suspend(sal_Bool _bSuspend) override
weld::Window * impl_getDefaultDialogFrame_nothrow() const
retrieves a window which can be used as parent for dialogs
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &_rPropertyName) override
void addDateTimePropertyDescription(std::vector< css::beans::Property > &_rProperties, const OUString &_rPropertyName, sal_Int16 _nAttribs) const
adds a description for the given DateTime property to the given property vector
virtual void SAL_CALL removePropertyChangeListener(const css::uno::Reference< css::beans::XPropertyChangeListener > &_rxListener) override
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
void addInt32PropertyDescription(std::vector< css::beans::Property > &_rProperties, const OUString &_rPropertyName, sal_Int16 _nAttribs=0) const
adds a description for the given int32 property to the given property vector
sal_Int16 impl_getDocumentMeasurementUnit_throw() const
determines the default measure unit for the document in which our component lives
virtual ~PropertyHandler() override
css::uno::Reference< css::beans::XPropertySet > m_xComponent
the component we're inspecting
OUString impl_getPropertyNameFromId_nothrow(PropertyId _nPropId) const
get the name of a property given by handle
PropertyId impl_getPropertyId_throwRuntime(const OUString &_rPropertyName) const
retrieves the property id for a given property name
virtual sal_Bool SAL_CALL isComposable(const OUString &_rPropertyName) override
void impl_setContextDocumentModified_nothrow() const
marks the context document as modified
PropertyHandler(const PropertyHandler &)=delete
css::uno::Reference< css::frame::XModel > impl_getContextDocument_nothrow() const
returns the value of the ContextDocument property in the ComponentContext which was used to create th...
const css::beans::Property & impl_getPropertyFromId_throw(PropertyId _nPropId) const
retrieves a property given by handle
void implAddPropertyDescription(std::vector< css::beans::Property > &_rProperties, const OUString &_rPropertyName, const css::uno::Type &_rType, sal_Int16 _nAttribs=0) const
adds a Property, given by name only, to a given vector of Properties
PropertyChangeListeners m_aPropertyListeners
the property listener which has been registered
virtual css::inspection::LineDescriptor SAL_CALL describePropertyLine(const OUString &_rPropertyName, const css::uno::Reference< css::inspection::XPropertyControlFactory > &_rxControlFactory) override
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
Type
a property handler for any virtual string properties
Definition: browserline.cxx:39
sal_Int32 PropertyId
::cppu::ImplHelper1< css::lang::XServiceInfo > PropertyHandlerComponent_Base
::cppu::WeakComponentImplHelper< css::inspection::XPropertyHandler > PropertyHandler_Base
#define DECLARE_XCOMPONENT()
Definition: pcrcommon.hxx:100
unsigned char sal_Bool
#define DECLARE_XTYPEPROVIDER()
#define DECLARE_XINTERFACE()