Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / extensions / source / propctrlr / handlerhelper.hxx
blob5d4ad7cbfa43242ac819810541ccc6d98e687708
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_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>
31 #include <vector>
33 namespace vcl { class Window; }
34 namespace com { namespace sun { namespace star {
35 namespace inspection {
36 struct LineDescriptor;
38 } } }
40 class ResStringArray;
42 namespace pcr
46 //= PropertyHandlerHelper
48 class PropertyHandlerHelper
50 public:
51 /** helper for implementing XPropertyHandler::describePropertyLine in a generic way
53 static void describePropertyLine(
54 const css::beans::Property& _rProperty,
55 css::inspection::LineDescriptor& /* [out] */ _out_rDescriptor,
56 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory
59 /** helper for implementing XPropertyHandler::convertToPropertyValue
61 static css::uno::Any convertToPropertyValue(
62 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
63 const css::uno::Reference< css::script::XTypeConverter >& _rxTypeConverter,
64 const css::beans::Property& _rProperty,
65 const css::uno::Any& _rControlValue
68 /// helper for implementing XPropertyHandler::convertToControlValue
69 static css::uno::Any convertToControlValue(
70 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
71 const css::uno::Reference< css::script::XTypeConverter >& _rxTypeConverter,
72 const css::uno::Any& _rPropertyValue,
73 const css::uno::Type& _rControlValueType
76 /** creates an <member scope="css::inspection">PropertyControlType::ListBox</member>-type control
77 and fills it with initial values
79 @param _rxControlFactory
80 A control factory. Must not be <NULL/>.
82 @param _rInitialListEntries
83 the initial values of the control
85 @param _bReadOnlyControl
86 determines whether the control should be read-only
88 @param _bSorted
89 determines whether the list entries should be sorted
91 @return
92 the newly created control
94 static css::uno::Reference< css::inspection::XPropertyControl >
95 createListBoxControl(
96 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory,
97 const std::vector< OUString >& _rInitialListEntries,
98 bool _bReadOnlyControl,
99 bool _bSorted
102 /** creates an <member scope="css::inspection">PropertyControlType::ListBox</member>-type control
103 and fills it with initial values
105 @param _rxControlFactory
106 A control factory. Must not be <NULL/>.
108 @param _rInitialListEntries
109 the initial values of the control
111 @param _bReadOnlyControl
112 determines whether the control should be read-only
114 @param _bSorted
115 determines whether the list entries should be sorted
117 @return
118 the newly created control
120 static css::uno::Reference< css::inspection::XPropertyControl >
121 createListBoxControl(
122 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory,
123 const ResStringArray& _rInitialListEntries,
124 bool _bReadOnlyControl,
125 bool _bSorted
128 /** creates an <member scope="css::inspection">PropertyControlType::ComboBox</member>-type control
129 and fills it with initial values
131 @param _rxControlFactory
132 A control factory. Must not be <NULL/>.
134 @param _rInitialListEntries
135 the initial values of the control
137 @param _bReadOnlyControl
138 determines whether the control should be read-only
140 @param _bSorted
141 determines whether the list entries should be sorted
143 @return
144 the newly created control
146 static css::uno::Reference< css::inspection::XPropertyControl >
147 createComboBoxControl(
148 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory,
149 const std::vector< OUString >& _rInitialListEntries,
150 bool _bReadOnlyControl,
151 bool _bSorted
154 /** creates an <member scope="css::inspection">PropertyControlType::NumericField</member>-type control
155 and initializes it
157 @param _rxControlFactory
158 A control factory. Must not be <NULL/>.
159 @param _nDigits
160 number of decimal digits for the control
161 (<member scope="css::inspection">XNumericControl::DecimalDigits</member>)
162 @param _rMinValue
163 minimum value which can be entered in the control
164 (<member scope="css::inspection">XNumericControl::MinValue</member>)
165 @param _rMaxValue
166 maximum value which can be entered in the control
167 (<member scope="css::inspection">XNumericControl::MaxValue</member>)
168 @param _bReadOnlyControl
169 determines whether the control should be read-only
171 @return
172 the newly created control
174 static css::uno::Reference< css::inspection::XPropertyControl >
175 createNumericControl(
176 const css::uno::Reference< css::inspection::XPropertyControlFactory >& _rxControlFactory,
177 sal_Int16 _nDigits,
178 const css::beans::Optional< double >& _rMinValue,
179 const css::beans::Optional< double >& _rMaxValue,
180 bool _bReadOnlyControl
183 /** marks the document passed in our UNO context as modified
185 The method looks up a value called "ContextDocument" in the given UNO component context,
186 queries it for the ->css::util::XModifiable interface, and calls its
187 setModified method. If either of those steps fails, this is asserted in a non-product
188 version, and silently ignore otherwise.
190 @param _rContext
191 the component context which was used to create the component calling this method
193 static void setContextDocumentModified(
194 const css::uno::Reference< css::uno::XComponentContext > & _rContext
197 static css::uno::Reference< css::uno::XInterface > getContextDocument( const css::uno::Reference<css::uno::XComponentContext> & _rContext );
199 /// @throws css::uno::RuntimeException
200 static css::uno::Reference< css::uno::XInterface > getContextDocument_throw( const css::uno::Reference<css::uno::XComponentContext> & _rContext );
202 /** gets the window of the ObjectInspector in which an property handler lives
204 The method looks up a value called "DialogParentWindow" in the given UNO component context,
205 queries it for XWindow, and returns the respective vcl::Window*. If either of those steps fails,
206 this is asserted in a non-product version, and silently ignore otherwise.
208 @param _rContext
209 the component context which was used to create the component calling this method
211 static vcl::Window* getDialogParentWindow( const css::uno::Reference< css::uno::XComponentContext > & _rContext );
214 /** determines whether given PropertyAttributes require a to-be-created
215 <type scope="css::inspection">XPropertyControl</type> to be read-only
217 @param _nPropertyAttributes
218 the attributes of the property which should be reflected by a to-be-created
219 <type scope="css::inspection">XPropertyControl</type>
221 static bool requiresReadOnlyControl( sal_Int16 _nPropertyAttributes )
223 return ( _nPropertyAttributes & css::beans::PropertyAttribute::READONLY ) != 0;
226 private:
227 PropertyHandlerHelper( const PropertyHandlerHelper& ) = delete;
228 PropertyHandlerHelper& operator=( const PropertyHandlerHelper& ) = delete;
232 } // namespace pcr
235 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_HANDLERHELPER_HXX
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */