1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_HANDLERHELPER_HXX
25 #define EXTENSIONS_SOURCE_PROPCTRLR_HANDLERHELPER_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/beans/Property.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/script/XTypeConverter.hpp>
31 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
32 #include <com/sun/star/inspection/XPropertyControlFactory.hpp>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/beans/Optional.hpp>
35 /** === end UNO includes === **/
36 
37 #include <vector>
38 
39 class Window;
40 namespace com { namespace sun { namespace star {
41     namespace inspection {
42         struct LineDescriptor;
43     }
44 } } }
45 //........................................................................
46 namespace pcr
47 {
48 //........................................................................
49 
50     class ComponentContext;
51 
52 	//====================================================================
53 	//= PropertyHandlerHelper
54 	//====================================================================
55 	class PropertyHandlerHelper
56 	{
57     public:
58         /** helper for implementing XPropertyHandler::describePropertyLine in a generic way
59         */
60         static  void describePropertyLine(
61                 const ::com::sun::star::beans::Property& _rProperty,
62                 ::com::sun::star::inspection::LineDescriptor& /* [out] */ _out_rDescriptor,
63                 const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory
64             );
65 
66         /** helper for implementing XPropertyHandler::convertToPropertyValue
67         */
68         static ::com::sun::star::uno::Any convertToPropertyValue(
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::beans::Property& _rProperty,
72                 const ::com::sun::star::uno::Any& _rControlValue
73             );
74 
75         /// helper for implementing XPropertyHandler::convertToControlValue
76         static ::com::sun::star::uno::Any convertToControlValue(
77 				const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
78                 const ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter >& _rxTypeConverter,
79                 const ::com::sun::star::uno::Any& _rPropertyValue,
80                 const ::com::sun::star::uno::Type& _rControlValueType
81             );
82 
83         /** creates an <member scope="com::sun::star::inspection">PropertyControlType::ListBox</member>-type control
84             and fills it with initial values
85 
86             @param _rxControlFactory
87                 A control factory. Must not be <NULL/>.
88 
89             @param  _rInitialListEntries
90                 the initial values of the control
91 
92             @param _bReadOnlyControl
93                 determines whether the control should be read-only
94 
95             @param _bSorted
96                 determines whether the list entries should be sorted
97 
98             @return
99                 the newly created control
100         */
101         static ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >
102             createListBoxControl(
103                 const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory,
104                 const ::std::vector< ::rtl::OUString >& _rInitialListEntries,
105                 sal_Bool _bReadOnlyControl,
106                 sal_Bool _bSorted
107             );
108 
109         /** creates an <member scope="com::sun::star::inspection">PropertyControlType::ComboBox</member>-type control
110             and fills it with initial values
111 
112             @param _rxControlFactory
113                 A control factory. Must not be <NULL/>.
114 
115             @param  _rInitialListEntries
116                 the initial values of the control
117 
118             @param _bReadOnlyControl
119                 determines whether the control should be read-only
120 
121             @param _bSorted
122                 determines whether the list entries should be sorted
123 
124             @return
125                 the newly created control
126         */
127         static ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >
128             createComboBoxControl(
129                 const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory,
130                 const ::std::vector< ::rtl::OUString >& _rInitialListEntries,
131                 sal_Bool _bReadOnlyControl,
132                 sal_Bool _bSorted
133             );
134 
135         /** creates an <member scope="com::sun::star::inspection">PropertyControlType::NumericField</member>-type control
136             and initializes it
137 
138             @param _rxControlFactory
139                 A control factory. Must not be <NULL/>.
140             @param _nDigits
141                 number of decimal digits for the control
142                 (<member scope="com::sun::star::inspection">XNumericControl::DecimalDigits</member>)
143             @param _rMinValue
144                 minimum value which can be entered in the control
145                 (<member scope="com::sun::star::inspection">XNumericControl::MinValue</member>)
146             @param _rMaxValue
147                 maximum value which can be entered in the control
148                 (<member scope="com::sun::star::inspection">XNumericControl::MaxValue</member>)
149             @param _bReadOnlyControl
150                 determines whether the control should be read-only
151 
152             @return
153                 the newly created control
154         */
155         static ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >
156             createNumericControl(
157                 const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory,
158                 sal_Int16 _nDigits,
159                 const ::com::sun::star::beans::Optional< double >& _rMinValue,
160                 const ::com::sun::star::beans::Optional< double >& _rMaxValue,
161                 sal_Bool _bReadOnlyControl
162             );
163 
164         /** marks the document passed in our UNO context as modified
165 
166             The method looks up a value called "ContextDocument" in the given UNO component context,
167             queries it for the ->com::sun::star::util::XModifiable interface, and calls its
168             setModified method. If either of those steps fails, this is asserted in a non-product
169             version, and silently ignore otherwise.
170 
171             @param _rContext
172                 the component context which was used to create the component calling this method
173         */
174         static void setContextDocumentModified(
175                 const ComponentContext& _rContext
176             );
177 
178         /** gets the window of the ObjectInspector in which an property handler lives
179 
180             The method looks up a value called "DialogParentWindow" in the given UNO copmonent context,
181             queries it for XWindow, and returns the respective Window*. If either of those steps fails,
182             this is asserted in a non-product version, and silently ignore otherwise.
183 
184             @param  _rContext
185                 the component context which was used to create the component calling this method
186         */
187         static Window* getDialogParentWindow( const ComponentContext& _rContext );
188 
189 
190         /** determines whether given PropertyAttributes require a to-be-created
191             <type scope="com::sun::star::inspection">XPropertyControl</type> to be read-only
192 
193             @param  _nPropertyAttributes
194                 the attributes of the property which should be reflected by a to-be-created
195                 <type scope="com::sun::star::inspection">XPropertyControl</type>
196         */
requiresReadOnlyControl(sal_Int16 _nPropertyAttributes)197         inline static sal_Bool requiresReadOnlyControl( sal_Int16 _nPropertyAttributes )
198         {
199             return ( _nPropertyAttributes & ::com::sun::star::beans::PropertyAttribute::READONLY ) != 0;
200         }
201 
202     private:
203         PropertyHandlerHelper();                                            // never implemented
204         PropertyHandlerHelper( const PropertyHandlerHelper& );              // never implemented
205         PropertyHandlerHelper& operator=( const PropertyHandlerHelper& );   // never implemented
206 	};
207 
208 //........................................................................
209 } // namespace pcr
210 //........................................................................
211 
212 #endif // EXTENSIONS_SOURCE_PROPCTRLR_HANDLERHELPER_HXX
213 
214