Line data Source code
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 : #ifndef EXTENSIONS_SOURCE_PROPCTRLR_HANDLERHELPER_HXX
21 : #define EXTENSIONS_SOURCE_PROPCTRLR_HANDLERHELPER_HXX
22 :
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>
30 :
31 : #include <vector>
32 :
33 : class Window;
34 : namespace com { namespace sun { namespace star {
35 : namespace inspection {
36 : struct LineDescriptor;
37 : }
38 : } } }
39 : //........................................................................
40 : namespace pcr
41 : {
42 : //........................................................................
43 :
44 : class ComponentContext;
45 :
46 : //====================================================================
47 : //= PropertyHandlerHelper
48 : //====================================================================
49 : class PropertyHandlerHelper
50 : {
51 : public:
52 : /** helper for implementing XPropertyHandler::describePropertyLine in a generic way
53 : */
54 : static void describePropertyLine(
55 : const ::com::sun::star::beans::Property& _rProperty,
56 : ::com::sun::star::inspection::LineDescriptor& /* [out] */ _out_rDescriptor,
57 : const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory
58 : );
59 :
60 : /** helper for implementing XPropertyHandler::convertToPropertyValue
61 : */
62 : static ::com::sun::star::uno::Any convertToPropertyValue(
63 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
64 : const ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter >& _rxTypeConverter,
65 : const ::com::sun::star::beans::Property& _rProperty,
66 : const ::com::sun::star::uno::Any& _rControlValue
67 : );
68 :
69 : /// helper for implementing XPropertyHandler::convertToControlValue
70 : static ::com::sun::star::uno::Any convertToControlValue(
71 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
72 : const ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter >& _rxTypeConverter,
73 : const ::com::sun::star::uno::Any& _rPropertyValue,
74 : const ::com::sun::star::uno::Type& _rControlValueType
75 : );
76 :
77 : /** creates an <member scope="com::sun::star::inspection">PropertyControlType::ListBox</member>-type control
78 : and fills it with initial values
79 :
80 : @param _rxControlFactory
81 : A control factory. Must not be <NULL/>.
82 :
83 : @param _rInitialListEntries
84 : the initial values of the control
85 :
86 : @param _bReadOnlyControl
87 : determines whether the control should be read-only
88 :
89 : @param _bSorted
90 : determines whether the list entries should be sorted
91 :
92 : @return
93 : the newly created control
94 : */
95 : static ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >
96 : createListBoxControl(
97 : const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory,
98 : const ::std::vector< ::rtl::OUString >& _rInitialListEntries,
99 : sal_Bool _bReadOnlyControl,
100 : sal_Bool _bSorted
101 : );
102 :
103 : /** creates an <member scope="com::sun::star::inspection">PropertyControlType::ComboBox</member>-type control
104 : and fills it with initial values
105 :
106 : @param _rxControlFactory
107 : A control factory. Must not be <NULL/>.
108 :
109 : @param _rInitialListEntries
110 : the initial values of the control
111 :
112 : @param _bReadOnlyControl
113 : determines whether the control should be read-only
114 :
115 : @param _bSorted
116 : determines whether the list entries should be sorted
117 :
118 : @return
119 : the newly created control
120 : */
121 : static ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >
122 : createComboBoxControl(
123 : const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory,
124 : const ::std::vector< ::rtl::OUString >& _rInitialListEntries,
125 : sal_Bool _bReadOnlyControl,
126 : sal_Bool _bSorted
127 : );
128 :
129 : /** creates an <member scope="com::sun::star::inspection">PropertyControlType::NumericField</member>-type control
130 : and initializes it
131 :
132 : @param _rxControlFactory
133 : A control factory. Must not be <NULL/>.
134 : @param _nDigits
135 : number of decimal digits for the control
136 : (<member scope="com::sun::star::inspection">XNumericControl::DecimalDigits</member>)
137 : @param _rMinValue
138 : minimum value which can be entered in the control
139 : (<member scope="com::sun::star::inspection">XNumericControl::MinValue</member>)
140 : @param _rMaxValue
141 : maximum value which can be entered in the control
142 : (<member scope="com::sun::star::inspection">XNumericControl::MaxValue</member>)
143 : @param _bReadOnlyControl
144 : determines whether the control should be read-only
145 :
146 : @return
147 : the newly created control
148 : */
149 : static ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >
150 : createNumericControl(
151 : const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory,
152 : sal_Int16 _nDigits,
153 : const ::com::sun::star::beans::Optional< double >& _rMinValue,
154 : const ::com::sun::star::beans::Optional< double >& _rMaxValue,
155 : sal_Bool _bReadOnlyControl
156 : );
157 :
158 : /** marks the document passed in our UNO context as modified
159 :
160 : The method looks up a value called "ContextDocument" in the given UNO component context,
161 : queries it for the ->com::sun::star::util::XModifiable interface, and calls its
162 : setModified method. If either of those steps fails, this is asserted in a non-product
163 : version, and silently ignore otherwise.
164 :
165 : @param _rContext
166 : the component context which was used to create the component calling this method
167 : */
168 : static void setContextDocumentModified(
169 : const ComponentContext& _rContext
170 : );
171 :
172 : /** gets the window of the ObjectInspector in which an property handler lives
173 :
174 : The method looks up a value called "DialogParentWindow" in the given UNO copmonent context,
175 : queries it for XWindow, and returns the respective Window*. If either of those steps fails,
176 : this is asserted in a non-product version, and silently ignore otherwise.
177 :
178 : @param _rContext
179 : the component context which was used to create the component calling this method
180 : */
181 : static Window* getDialogParentWindow( const ComponentContext& _rContext );
182 :
183 :
184 : /** determines whether given PropertyAttributes require a to-be-created
185 : <type scope="com::sun::star::inspection">XPropertyControl</type> to be read-only
186 :
187 : @param _nPropertyAttributes
188 : the attributes of the property which should be reflected by a to-be-created
189 : <type scope="com::sun::star::inspection">XPropertyControl</type>
190 : */
191 0 : inline static sal_Bool requiresReadOnlyControl( sal_Int16 _nPropertyAttributes )
192 : {
193 0 : return ( _nPropertyAttributes & ::com::sun::star::beans::PropertyAttribute::READONLY ) != 0;
194 : }
195 :
196 : private:
197 : PropertyHandlerHelper(); // never implemented
198 : PropertyHandlerHelper( const PropertyHandlerHelper& ); // never implemented
199 : PropertyHandlerHelper& operator=( const PropertyHandlerHelper& ); // never implemented
200 : };
201 :
202 : //........................................................................
203 : } // namespace pcr
204 : //........................................................................
205 :
206 : #endif // EXTENSIONS_SOURCE_PROPCTRLR_HANDLERHELPER_HXX
207 :
208 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|