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