Branch libreoffice-5-0-4
[LibreOffice.git] / include / toolkit / controls / geometrycontrolmodel.hxx
blob72fc9ca0edf3b6ade8230e76ee47fe2b00d66e88
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_TOOLKIT_CONTROLS_GEOMETRYCONTROLMODEL_HXX
21 #define INCLUDED_TOOLKIT_CONTROLS_GEOMETRYCONTROLMODEL_HXX
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>
36 namespace com { namespace sun { namespace star {
37 namespace lang {
38 class XMultiServiceFactory;
40 namespace script {
41 class XNameContainer;
43 namespace uno {
44 class XComponentContext;
46 }}}
49 // namespace toolkit
50 // {
54 //= OGeometryControlModel_Base
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
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;
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>
83 bool m_bCloneable;
85 protected:
86 static ::com::sun::star::uno::Any ImplGetDefaultValueByHandle(sal_Int32 nHandle);
87 ::com::sun::star::uno::Any ImplGetPropertyValueByHandle(sal_Int32 nHandle) const;
88 void ImplSetPropertyValueByHandle(sal_Int32 nHandle, const :: com::sun::star::uno::Any& aValue);
90 protected:
91 /**
92 @param _pAggregateInstance
93 the object to be aggregated. The refcount of the instance given MUST be 0!
95 OGeometryControlModel_Base(::com::sun::star::uno::XAggregation* _pAggregateInstance);
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
102 OGeometryControlModel_Base(::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance);
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>
108 void releaseAggregation();
110 protected:
111 virtual ~OGeometryControlModel_Base();
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;
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;
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;
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;
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;
134 using comphelper::OPropertySetAggregationHelper::getFastPropertyValue;
135 virtual void SAL_CALL getFastPropertyValue(
136 ::com::sun::star::uno::Any& _rValue, sal_Int32 _nHandle) const SAL_OVERRIDE;
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;
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;
146 // OPropertySetAggregationHelper overridables
147 using OPropertySetAggregationHelper::getInfoHelper;
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;
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;
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;
160 // XComponent
161 using comphelper::OPropertySetAggregationHelper::disposing;
162 virtual void SAL_CALL disposing() SAL_OVERRIDE;
164 private:
165 void registerProperties();
169 //= OTemplateInstanceDisambiguation
171 template <class CONTROLMODEL>
172 class OTemplateInstanceDisambiguation
177 //= OGeometryControlModel
179 /* example for usage:
180 Reference< XAggregation > xIFace = new ::toolkit::OGeometryControlModel< UnoControlButtonModel > ();
182 template <class CONTROLMODEL>
183 class OGeometryControlModel
184 :public OGeometryControlModel_Base
185 ,public ::comphelper::OAggregationArrayUsageHelper< OTemplateInstanceDisambiguation< CONTROLMODEL > >
187 public:
188 OGeometryControlModel( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& i_factory );
190 private:
191 OGeometryControlModel(::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance);
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;
200 // OPropertySetAggregationHelper overridables
201 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE;
203 // OGeometryControlModel_Base
204 virtual OGeometryControlModel_Base* createClone_Impl(
205 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance) SAL_OVERRIDE;
207 // XTypeProvider
208 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
212 //= OCommonGeometryControlModel
214 /** allows to extend an arbitrary com.sun.star.awt::UnoControlModel with geometry
215 information.
217 class OCommonGeometryControlModel
218 :public OGeometryControlModel_Base
219 ,public ::comphelper::OIdPropertyArrayUsageHelper< OCommonGeometryControlModel >
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
225 public:
226 /** instantiate the model
228 @param _rxAgg
229 the instance to aggregate. Must support the com.sun.star.awt::UnoControlModel
230 (this is not checked here)
232 OCommonGeometryControlModel(
233 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAgg,
234 const OUString& _rxServiceSpecifier
237 // OIdPropertyArrayUsageHelper overridables
238 virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const SAL_OVERRIDE;
240 // OPropertySetAggregationHelper overridables
241 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE;
243 // OGeometryControlModel_Base
244 virtual OGeometryControlModel_Base* createClone_Impl(
245 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance) SAL_OVERRIDE;
247 // XTypeProvider
248 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
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;
256 #include <toolkit/controls/geometrycontrolmodel_impl.hxx>
259 // } // namespace toolkit
262 #endif // INCLUDED_TOOLKIT_CONTROLS_GEOMETRYCONTROLMODEL_HXX
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */