Version 24.2.2.2, tag libreoffice-24.2.2.2
[LibreOffice.git] / toolkit / inc / controls / geometrycontrolmodel.hxx
blobc2dc13b49f3fd01d67a07266fda7537b1f3cee78
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 #pragma once
22 #include <comphelper/broadcasthelper.hxx>
23 #include <comphelper/propagg.hxx>
24 #include <comphelper/proparrhlp.hxx>
25 #include <comphelper/propertycontainer.hxx>
26 #include <cppuhelper/compbase2.hxx>
27 #include <com/sun/star/util/XCloneable.hpp>
28 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
29 #include <comphelper/IdPropArrayHelper.hxx>
30 #include <rtl/ref.hxx>
32 namespace com::sun::star::resource { class XStringResourceResolver; }
34 namespace com::sun::star {
35 namespace uno {
36 class XComponentContext;
41 // namespace toolkit
42 // {
45 //= OGeometryControlModel_Base
47 typedef ::cppu::WeakAggComponentImplHelper2 < css::util::XCloneable
48 , css::script::XScriptEventsSupplier
49 > OGCM_Base;
50 class OGeometryControlModel_Base
51 :public ::comphelper::OMutexAndBroadcastHelper
52 ,public ::comphelper::OPropertySetAggregationHelper
53 ,public ::comphelper::OPropertyContainer
54 ,public OGCM_Base
56 protected:
57 css::uno::Reference< css::uno::XAggregation >
58 m_xAggregate;
59 css::uno::Reference< css::container::XNameContainer >
60 mxEventContainer;
62 // <properties>
63 sal_Int32 m_nPosX;
64 sal_Int32 m_nPosY;
65 sal_Int32 m_nWidth;
66 sal_Int32 m_nHeight;
67 OUString m_aName;
68 sal_Int16 m_nTabIndex;
69 sal_Int32 m_nStep;
70 OUString m_aTag;
71 css::uno::Reference< css::resource::XStringResourceResolver > m_xStrResolver;
72 // </properties>
74 bool m_bCloneable;
76 protected:
77 static css::uno::Any ImplGetDefaultValueByHandle(sal_Int32 nHandle);
78 css::uno::Any ImplGetPropertyValueByHandle(sal_Int32 nHandle) const;
79 void ImplSetPropertyValueByHandle(sal_Int32 nHandle, const css::uno::Any& aValue);
81 protected:
82 /**
83 @param _pAggregateInstance
84 the object to be aggregated. The refcount of the instance given MUST be 0!
86 OGeometryControlModel_Base(css::uno::XAggregation* _pAggregateInstance);
88 /**
89 @param _rxAggregateInstance
90 is the object to be aggregated. Must be acquired exactly once (by the reference object given).<br/>
91 Will be reset to NULL upon leaving
93 OGeometryControlModel_Base(css::uno::Reference< css::util::XCloneable >& _rxAggregateInstance);
95 /** releases the aggregation
96 <p>Can be used if in a derived class, an exception has to be thrown after this base class here already
97 did the aggregation</p>
99 void releaseAggregation();
101 protected:
102 virtual ~OGeometryControlModel_Base() override;
104 // XAggregation
105 css::uno::Any SAL_CALL queryAggregation( const css::uno::Type& _aType ) override;
107 public:
108 // XInterface
109 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
110 virtual void SAL_CALL acquire( ) noexcept override;
111 virtual void SAL_CALL release( ) noexcept override;
113 protected:
114 // XTypeProvider
115 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
117 // OPropertySetHelper overridables
118 virtual sal_Bool SAL_CALL convertFastPropertyValue(
119 css::uno::Any& _rConvertedValue, css::uno::Any& _rOldValue,
120 sal_Int32 _nHandle, const css::uno::Any& _rValue ) override;
122 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
123 sal_Int32 _nHandle, const css::uno::Any& _rValue) override;
125 using comphelper::OPropertySetAggregationHelper::getFastPropertyValue;
126 virtual void SAL_CALL getFastPropertyValue(
127 css::uno::Any& _rValue, sal_Int32 _nHandle) const override;
129 // OPropertyStateHelper overridables
130 virtual css::beans::PropertyState getPropertyStateByHandle(sal_Int32 nHandle) override;
131 virtual void setPropertyToDefaultByHandle(sal_Int32 nHandle) override;
132 virtual css::uno::Any getPropertyDefaultByHandle(sal_Int32 nHandle) const override;
134 // XPropertySet
135 virtual css::uno::Reference< css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
137 // OPropertySetAggregationHelper overridables
138 using OPropertySetAggregationHelper::getInfoHelper;
140 // XCloneable
141 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) override;
143 //XScriptEventsSupplier
144 virtual css::uno::Reference< css::container::XNameContainer >
145 SAL_CALL getEvents( ) override;
147 // XCloneable implementation - to be overwritten
148 virtual rtl::Reference<OGeometryControlModel_Base> createClone_Impl(
149 css::uno::Reference< css::util::XCloneable >& _rxAggregateInstance) = 0;
151 // XComponent
152 using comphelper::OPropertySetAggregationHelper::disposing;
153 virtual void SAL_CALL disposing() override;
155 private:
156 void registerProperties();
160 //= OTemplateInstanceDisambiguation
162 template <class CONTROLMODEL>
163 class OTemplateInstanceDisambiguation
168 //= OGeometryControlModel
170 /* example for usage:
171 Reference< XAggregation > xIFace = new ::toolkit::OGeometryControlModel< UnoControlButtonModel > ();
173 template <class CONTROLMODEL>
174 class OGeometryControlModel final
175 :public OGeometryControlModel_Base
176 ,public ::comphelper::OAggregationArrayUsageHelper< OTemplateInstanceDisambiguation< CONTROLMODEL > >
178 public:
179 OGeometryControlModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory );
181 private:
182 OGeometryControlModel(css::uno::Reference< css::util::XCloneable >& _rxAggregateInstance);
184 // OAggregationArrayUsageHelper overridables
185 virtual void fillProperties(
186 css::uno::Sequence< css::beans::Property >& _rProps,
187 css::uno::Sequence< css::beans::Property >& _rAggregateProps
188 ) const override;
190 // OPropertySetAggregationHelper overridables
191 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
193 // OGeometryControlModel_Base
194 virtual rtl::Reference<OGeometryControlModel_Base> createClone_Impl(
195 css::uno::Reference< css::util::XCloneable >& _rxAggregateInstance) override;
197 // XTypeProvider
198 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
202 //= OCommonGeometryControlModel
204 /** allows to extend an arbitrary com.sun.star.awt::UnoControlModel with geometry
205 information.
207 class OCommonGeometryControlModel final
208 :public OGeometryControlModel_Base
209 ,public ::comphelper::OIdPropertyArrayUsageHelper< OCommonGeometryControlModel >
211 private:
212 OUString m_sServiceSpecifier; // the service specifier of our aggregate
213 sal_Int32 m_nPropertyMapId; // our unique property info id, used to look up in s_aAggregateProperties
215 public:
216 /** instantiate the model
218 @param _rxAgg
219 the instance to aggregate. Must support the com.sun.star.awt::UnoControlModel
220 (this is not checked here)
222 OCommonGeometryControlModel(
223 css::uno::Reference< css::util::XCloneable >& _rxAgg,
224 OUString _aServiceSpecifier
227 // OIdPropertyArrayUsageHelper overridables
228 virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const override;
230 // OPropertySetAggregationHelper overridables
231 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
233 // OGeometryControlModel_Base
234 virtual rtl::Reference<OGeometryControlModel_Base> createClone_Impl(
235 css::uno::Reference< css::util::XCloneable >& _rxAggregateInstance) override;
237 // XTypeProvider
238 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
240 private:
241 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
242 sal_Int32 _nHandle, const css::uno::Any& _rValue) override;
245 #include <controls/geometrycontrolmodel_impl.hxx>
248 // } // namespace toolkit
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */