xref: /trunk/main/toolkit/inc/toolkit/controls/geometrycontrolmodel.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 _TOOLKIT_HELPERS_GEOMETRYCONTROLMODEL_HXX_
25 #define _TOOLKIT_HELPERS_GEOMETRYCONTROLMODEL_HXX_
26 
27 #include <comphelper/broadcasthelper.hxx>
28 #include <comphelper/uno3.hxx>
29 #include <comphelper/propagg.hxx>
30 #include <comphelper/proparrhlp.hxx>
31 #include <comphelper/propertycontainer.hxx>
32 #include <cppuhelper/weakagg.hxx>
33 #include <cppuhelper/compbase2.hxx>
34 #include <com/sun/star/util/XCloneable.hpp>
35 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
36 #include <com/sun/star/resource/XStringResourceResolver.hpp>
37 #include <cppuhelper/typeprovider.hxx>
38 #include <comphelper/IdPropArrayHelper.hxx>
39 #include <comphelper/stl_types.hxx>
40 
41 FORWARD_DECLARE_INTERFACE( lang, XMultiServiceFactory )
42 FORWARD_DECLARE_INTERFACE( script, XNameContainer )
43 
44 //........................................................................
45 // namespace toolkit
46 // {
47 //........................................................................
48 
49     //====================================================================
50     //= OGeometryControlModel_Base
51     //====================================================================
52     typedef ::cppu::WeakAggComponentImplHelper2 <   ::com::sun::star::util::XCloneable
53                                                 ,   ::com::sun::star::script::XScriptEventsSupplier
54                                                 >   OGCM_Base;
55     class OGeometryControlModel_Base
56         :public ::comphelper::OMutexAndBroadcastHelper
57         ,public ::comphelper::OPropertySetAggregationHelper
58         ,public ::comphelper::OPropertyContainer
59         ,public OGCM_Base
60     {
61     protected:
62         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation >
63                     m_xAggregate;
64         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
65                     mxEventContainer;
66 
67         // <properties>
68         sal_Int32       m_nPosX;
69         sal_Int32       m_nPosY;
70         sal_Int32       m_nWidth;
71         sal_Int32       m_nHeight;
72         ::rtl::OUString m_aName;
73         sal_Int16       m_nTabIndex;
74         sal_Int32       m_nStep;
75         ::rtl::OUString m_aTag;
76         ::com::sun::star::uno::Reference< ::com::sun::star::resource::XStringResourceResolver > m_xStrResolver;
77         // </properties>
78 
79         sal_Bool        m_bCloneable;
80 
81     protected:
82         virtual ::com::sun::star::uno::Any          ImplGetDefaultValueByHandle(sal_Int32 nHandle) const;
83         virtual ::com::sun::star::uno::Any          ImplGetPropertyValueByHandle(sal_Int32 nHandle) const;
84         virtual void                                ImplSetPropertyValueByHandle(sal_Int32 nHandle, const :: com::sun::star::uno::Any& aValue);
85 
86     protected:
87         /**
88             @param _pAggregateInstance
89                 the object to be aggregated. The refcount of the instance given MUST be 0!
90         */
91         OGeometryControlModel_Base(::com::sun::star::uno::XAggregation* _pAggregateInstance);
92 
93         /**
94             @param _rxAggregateInstance
95                 is the object to be aggregated. Must be acquired excatly once (by the reference object given).<br/>
96                 Will be reset to NULL upon leaving
97         */
98         OGeometryControlModel_Base(::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance);
99 
100         /** releases the aggregation
101             <p>Can be used if in a derived class, an exception has to be thrown after this base class here already
102             did the aggregation</p>
103         */
104         void releaseAggregation();
105 
106     protected:
107         /*  Matches ~WeakAggComponentImplHelperBase(), which declares SAL_THROW( () )
108             explicitly: callers have always been promised that destroying one of
109             these does not throw. */
110         ~OGeometryControlModel_Base() SAL_THROW( () );
111 
112         // XAggregation
113         ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _aType );
114 
115         // XInterface
116         virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType );
117         virtual void SAL_CALL acquire(  ) throw();
118         virtual void SAL_CALL release(  ) throw();
119 
120         // XTypeProvider
121         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  );
122 
123         // OPropertySetHelper overridables
124         virtual sal_Bool SAL_CALL convertFastPropertyValue(
125                 ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue,
126                 sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue );
127 
128         virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
129                 sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue);
130 
131         using comphelper::OPropertySetAggregationHelper::getFastPropertyValue;
132         virtual void SAL_CALL getFastPropertyValue(
133             ::com::sun::star::uno::Any& _rValue, sal_Int32 _nHandle) const;
134 
135         // OPropertyStateHelper overridables
136         virtual ::com::sun::star::beans::PropertyState  getPropertyStateByHandle(sal_Int32 nHandle);
137         virtual void                                    setPropertyToDefaultByHandle(sal_Int32 nHandle);
138         virtual ::com::sun::star::uno::Any              getPropertyDefaultByHandle(sal_Int32 nHandle) const;
139 
140         // XPropertySet
141         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo();
142 
143         // OPropertySetAggregationHelper overridables
144         using OPropertySetAggregationHelper::getInfoHelper;
145 
146         // XCloneable
147         virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone(  );
148 
149         //XScriptEventsSupplier
150         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
151             SAL_CALL getEvents(  );
152 
153         // XCloneable implementation - to be overwritten
154         virtual OGeometryControlModel_Base* createClone_Impl(
155             ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance) = 0;
156 
157         // XComponent
158         using comphelper::OPropertySetAggregationHelper::disposing;
159         virtual void SAL_CALL disposing();
160 
161     private:
162         void registerProperties();
163     };
164 
165     //====================================================================
166     //= OTemplateInstanceDisambiguation
167     //====================================================================
168     template <class CONTROLMODEL>
169     class OTemplateInstanceDisambiguation
170     {
171     };
172 
173     //====================================================================
174     //= OGeometryControlModel
175     //====================================================================
176     /*  example for usage:
177             Reference< XAggregation > xIFace = new ::toolkit::OGeometryControlModel< UnoControlButtonModel > ();
178     */
179     template <class CONTROLMODEL>
180     class OGeometryControlModel
181         :public OGeometryControlModel_Base
182         ,public ::comphelper::OAggregationArrayUsageHelper< OTemplateInstanceDisambiguation< CONTROLMODEL > >
183     {
184     public:
185         OGeometryControlModel( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory );
186 
187     private:
188         OGeometryControlModel(::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance);
189 
190     protected:
191         // OAggregationArrayUsageHelper overridables
192         virtual void fillProperties(
193             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _rProps,
194             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _rAggregateProps
195             ) const;
196 
197         // OPropertySetAggregationHelper overridables
198         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
199 
200         // OGeometryControlModel_Base
201         virtual OGeometryControlModel_Base* createClone_Impl(
202             ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance);
203 
204         // XTypeProvider
205         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId(  );
206     };
207 
208     //====================================================================
209     //= OCommonGeometryControlModel
210     //====================================================================
211     /** allows to extend an arbitrary <type scope="com.sun.star.awt">UnoControlModel</type> with geometry
212         information.
213     */
214     class OCommonGeometryControlModel
215         :public OGeometryControlModel_Base
216         ,public ::comphelper::OIdPropertyArrayUsageHelper< OCommonGeometryControlModel >
217     {
218     private:
219         ::rtl::OUString m_sServiceSpecifier;        // the service specifier of our aggregate
220         sal_Int32       m_nPropertyMapId;           // our unique property info id, used to look up in s_aAggregateProperties
221 
222     public:
223         /** instantiate the model
224 
225             @param _rxAgg
226                 the instance to aggregate. Must support the <type scope="com.sun.star.awt">UnoControlModel</type>
227                 (this is not checked here)
228         */
229         OCommonGeometryControlModel(
230                     ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAgg,
231             const   ::rtl::OUString& _rxServiceSpecifier
232         );
233 
234         // OIdPropertyArrayUsageHelper overridables
235         virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const;
236 
237         // OPropertySetAggregationHelper overridables
238         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
239 
240         // OGeometryControlModel_Base
241         virtual OGeometryControlModel_Base* createClone_Impl(
242             ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance);
243 
244         // XTypeProvider
245         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId(  );
246 
247     private:
248         virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
249                 sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue);
250     };
251 
252 #include "toolkit/controls/geometrycontrolmodel_impl.hxx"
253 
254 //........................................................................
255 // }    // namespace toolkit
256 //........................................................................
257 
258 #endif // _TOOLKIT_HELPERS_GEOMETRYCONTROLMODEL_HXX_
259