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