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_HANDLERHELPER_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_HANDLERHELPER_HXX
23 #include <com/sun/star/beans/Property.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <com/sun/star/script/XTypeConverter.hpp>
26 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
27 #include <com/sun/star/inspection/XPropertyControlFactory.hpp>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/beans/Optional.hpp>
33 namespace vcl
{ class Window
; }
34 namespace com
{ namespace sun
{ namespace star
{
35 namespace inspection
{
36 struct LineDescriptor
;
45 //= PropertyHandlerHelper
47 class PropertyHandlerHelper
50 /** helper for implementing XPropertyHandler::describePropertyLine in a generic way
52 static void describePropertyLine(
53 const ::com::sun::star::beans::Property
& _rProperty
,
54 ::com::sun::star::inspection::LineDescriptor
& /* [out] */ _out_rDescriptor
,
55 const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlFactory
>& _rxControlFactory
58 /** helper for implementing XPropertyHandler::convertToPropertyValue
60 static ::com::sun::star::uno::Any
convertToPropertyValue(
61 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
,
62 const ::com::sun::star::uno::Reference
< ::com::sun::star::script::XTypeConverter
>& _rxTypeConverter
,
63 const ::com::sun::star::beans::Property
& _rProperty
,
64 const ::com::sun::star::uno::Any
& _rControlValue
67 /// helper for implementing XPropertyHandler::convertToControlValue
68 static ::com::sun::star::uno::Any
convertToControlValue(
69 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
,
70 const ::com::sun::star::uno::Reference
< ::com::sun::star::script::XTypeConverter
>& _rxTypeConverter
,
71 const ::com::sun::star::uno::Any
& _rPropertyValue
,
72 const ::com::sun::star::uno::Type
& _rControlValueType
75 /** creates an <member scope="com::sun::star::inspection">PropertyControlType::ListBox</member>-type control
76 and fills it with initial values
78 @param _rxControlFactory
79 A control factory. Must not be <NULL/>.
81 @param _rInitialListEntries
82 the initial values of the control
84 @param _bReadOnlyControl
85 determines whether the control should be read-only
88 determines whether the list entries should be sorted
91 the newly created control
93 static ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControl
>
95 const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlFactory
>& _rxControlFactory
,
96 const ::std::vector
< OUString
>& _rInitialListEntries
,
97 bool _bReadOnlyControl
,
101 /** creates an <member scope="com::sun::star::inspection">PropertyControlType::ComboBox</member>-type control
102 and fills it with initial values
104 @param _rxControlFactory
105 A control factory. Must not be <NULL/>.
107 @param _rInitialListEntries
108 the initial values of the control
110 @param _bReadOnlyControl
111 determines whether the control should be read-only
114 determines whether the list entries should be sorted
117 the newly created control
119 static ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControl
>
120 createComboBoxControl(
121 const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlFactory
>& _rxControlFactory
,
122 const ::std::vector
< OUString
>& _rInitialListEntries
,
123 bool _bReadOnlyControl
,
127 /** creates an <member scope="com::sun::star::inspection">PropertyControlType::NumericField</member>-type control
130 @param _rxControlFactory
131 A control factory. Must not be <NULL/>.
133 number of decimal digits for the control
134 (<member scope="com::sun::star::inspection">XNumericControl::DecimalDigits</member>)
136 minimum value which can be entered in the control
137 (<member scope="com::sun::star::inspection">XNumericControl::MinValue</member>)
139 maximum value which can be entered in the control
140 (<member scope="com::sun::star::inspection">XNumericControl::MaxValue</member>)
141 @param _bReadOnlyControl
142 determines whether the control should be read-only
145 the newly created control
147 static ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControl
>
148 createNumericControl(
149 const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlFactory
>& _rxControlFactory
,
151 const ::com::sun::star::beans::Optional
< double >& _rMinValue
,
152 const ::com::sun::star::beans::Optional
< double >& _rMaxValue
,
153 bool _bReadOnlyControl
156 /** marks the document passed in our UNO context as modified
158 The method looks up a value called "ContextDocument" in the given UNO component context,
159 queries it for the ->com::sun::star::util::XModifiable interface, and calls its
160 setModified method. If either of those steps fails, this is asserted in a non-product
161 version, and silently ignore otherwise.
164 the component context which was used to create the component calling this method
166 static void setContextDocumentModified(
167 const css::uno::Reference
< css::uno::XComponentContext
> & _rContext
170 static css::uno::Reference
< css::uno::XInterface
> getContextDocument( const css::uno::Reference
<css::uno::XComponentContext
> & _rContext
);
172 static css::uno::Reference
< css::uno::XInterface
> getContextDocument_throw( const css::uno::Reference
<css::uno::XComponentContext
> & _rContext
) throw (css::uno::RuntimeException
);
174 /** gets the window of the ObjectInspector in which an property handler lives
176 The method looks up a value called "DialogParentWindow" in the given UNO copmonent context,
177 queries it for XWindow, and returns the respective vcl::Window*. If either of those steps fails,
178 this is asserted in a non-product version, and silently ignore otherwise.
181 the component context which was used to create the component calling this method
183 static vcl::Window
* getDialogParentWindow( const css::uno::Reference
< css::uno::XComponentContext
> & _rContext
);
186 /** determines whether given PropertyAttributes require a to-be-created
187 <type scope="com::sun::star::inspection">XPropertyControl</type> to be read-only
189 @param _nPropertyAttributes
190 the attributes of the property which should be reflected by a to-be-created
191 <type scope="com::sun::star::inspection">XPropertyControl</type>
193 inline static bool requiresReadOnlyControl( sal_Int16 _nPropertyAttributes
)
195 return ( _nPropertyAttributes
& ::com::sun::star::beans::PropertyAttribute::READONLY
) != 0;
199 PropertyHandlerHelper( const PropertyHandlerHelper
& ) SAL_DELETED_FUNCTION
;
200 PropertyHandlerHelper
& operator=( const PropertyHandlerHelper
& ) SAL_DELETED_FUNCTION
;
207 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_HANDLERHELPER_HXX
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */