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