1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_UNOCONTROLMODEL_HXX
21 #define INCLUDED_TOOLKIT_CONTROLS_UNOCONTROLMODEL_HXX
23 #include <com/sun/star/awt/XControlModel.hpp>
24 #include <com/sun/star/lang/XComponent.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/beans/XPropertyState.hpp>
27 #include <com/sun/star/io/XPersistObject.hpp>
28 #include <com/sun/star/util/XCloneable.hpp>
29 #include <cppuhelper/weakagg.hxx>
31 #include <comphelper/broadcasthelper.hxx>
32 #include <toolkit/helper/listenermultiplexer.hxx>
34 #include <comphelper/propshlp.hxx>
35 #include <cppuhelper/implbase6.hxx>
36 #include <comphelper/uno3.hxx>
37 #include <rtl/ref.hxx>
42 namespace com::sun::star::uno
{ class XComponentContext
; }
44 typedef std::map
<sal_uInt16
, css::uno::Any
> ImplPropertyTable
;
46 typedef ::cppu::WeakAggImplHelper6
< css::awt::XControlModel
47 , css::beans::XPropertyState
48 , css::io::XPersistObject
49 , css::lang::XComponent
50 , css::lang::XServiceInfo
51 , css::util::XCloneable
52 > UnoControlModel_Base
;
54 class UnoControlModel
: public UnoControlModel_Base
55 ,public ::comphelper::OPropertySetHelper
58 ImplPropertyTable maData
;
59 EventListenerMultiplexer maDisposeListeners
;
62 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
65 void ImplRegisterProperty( sal_uInt16 nPropType
);
66 void ImplRegisterProperties( const std::vector
< sal_uInt16
> &rIds
);
67 void ImplRegisterProperty( sal_uInt16 nPropId
, const css::uno::Any
& rDefault
);
68 css::uno::Sequence
<sal_Int32
> ImplGetPropertyIds() const;
69 virtual css::uno::Any
ImplGetDefaultValue( sal_uInt16 nPropId
) const;
70 bool ImplHasProperty( sal_uInt16 nPropId
) const;
72 /** called before setting multiple properties, allows to care for property dependencies
74 <p>When multiple property values are set (e.g. XPropertySet::setPropertyValues), it may happen that some
75 of them are dependent. For this, derivees which know such dependencies can affect the order in which
76 the properties are internally really set.</p>
78 virtual void ImplNormalizePropertySequence(
79 const sal_Int32 _nCount
, /// the number of entries in the arrays
80 sal_Int32
* _pHandles
, /// the handles of the properties to set
81 css::uno::Any
* _pValues
, /// the values of the properties to set
82 sal_Int32
* _pValidHandles
/// pointer to the valid handles, allowed to be adjusted
85 /// ensures that two property values in a sequence have a certain order
86 static void ImplEnsureHandleOrder(
87 const sal_Int32 _nCount
, /// number of entries in the array
88 sal_Int32
* _pHandles
, /// pointer to the handles
89 css::uno::Any
* _pValues
, /// pointer to the values
90 sal_Int32 _nFirstHandle
, /// first handle, which should precede _nSecondHandle in the sequence
91 sal_Int32 _nSecondHandle
/// second handle, which should supersede _nFirstHandle in the sequence
94 template<typename T
> void UNO_CONTROL_MODEL_REGISTER_PROPERTIES() {
95 std::vector
< sal_uInt16
> aIds
;
96 T::ImplGetPropertyIds( aIds
);
97 ImplRegisterProperties( aIds
);
102 UnoControlModel() //do not use! needed by MSVC at compile time to satisfy WeakAggImplHelper7
103 : UnoControlModel_Base()
104 , OPropertySetHelper()
105 , maDisposeListeners( *this )
106 , m_xContext( css::uno::Reference
< css::uno::XComponentContext
>() )
113 UnoControlModel( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
114 UnoControlModel( const UnoControlModel
& rModel
);
116 virtual rtl::Reference
<UnoControlModel
> Clone() const = 0;
118 // css::uno::XInterface
119 css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
{ return OWeakAggObject::queryInterface(rType
); }
120 void SAL_CALL
acquire() noexcept override
;
121 void SAL_CALL
release() noexcept override
;
123 // css::uno::XAggregation
124 css::uno::Any SAL_CALL
queryAggregation( const css::uno::Type
& rType
) override
;
126 // css::util::XCloneable
127 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone() override
;
129 // css::lang::XTypeProvider
130 DECLARE_XTYPEPROVIDER()
132 // css::lang::XComponent
133 void SAL_CALL
dispose( ) override
;
134 void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
135 void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
137 // css::beans::XPropertyState
138 css::beans::PropertyState SAL_CALL
getPropertyState( const OUString
& PropertyName
) override
;
139 css::uno::Sequence
< css::beans::PropertyState
> SAL_CALL
getPropertyStates( const css::uno::Sequence
< OUString
>& aPropertyName
) override
;
140 void SAL_CALL
setPropertyToDefault( const OUString
& PropertyName
) override
;
141 css::uno::Any SAL_CALL
getPropertyDefault( const OUString
& aPropertyName
) override
;
143 // css::io::XPersistObject
144 OUString SAL_CALL
getServiceName() override
;
145 void SAL_CALL
write( const css::uno::Reference
< css::io::XObjectOutputStream
>& OutStream
) override
;
146 void SAL_CALL
read( const css::uno::Reference
< css::io::XObjectInputStream
>& InStream
) override
;
148 // css::lang::XServiceInfo
149 OUString SAL_CALL
getImplementationName( ) override
;
150 sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
151 css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
153 // ::cppu::OPropertySetHelper
154 ::cppu::IPropertyArrayHelper
& getInfoHelper() override
= 0;
155 bool convertFastPropertyValue( std::unique_lock
<std::mutex
>& rGuard
, css::uno::Any
& rConvertedValue
, css::uno::Any
& rOldValue
, sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
156 void setFastPropertyValue_NoBroadcast(
157 std::unique_lock
<std::mutex
>& rGuard
,
158 sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
159 using comphelper::OPropertySetHelper::getFastPropertyValue
;
160 void getFastPropertyValue( std::unique_lock
<std::mutex
>& rGuard
, css::uno::Any
& rValue
, sal_Int32 nHandle
) const override
;
162 // css::beans::XMultiPropertySet
163 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
164 void SAL_CALL
setPropertyValues( const css::uno::Sequence
< OUString
>& PropertyNames
, const css::uno::Sequence
< css::uno::Any
>& Values
) override
;
166 // override setValue methods to handle properties of FontDescriptor
167 // css::beans::XFastPropertySet
168 void setFastPropertyValueImpl( std::unique_lock
<std::mutex
>& rGuard
, sal_Int32 nHandle
, const css::uno::Any
& aValue
) override
;
169 css::beans::PropertyState
getPropertyStateImpl( std::unique_lock
<std::mutex
>& rGuard
, const OUString
& PropertyName
);
170 void setPropertyValuesImpl( std::unique_lock
<std::mutex
>& rGuard
, const css::uno::Sequence
< OUString
>& PropertyNames
, const css::uno::Sequence
< css::uno::Any
>& Values
);
173 #endif // INCLUDED_TOOLKIT_CONTROLS_UNOCONTROLMODEL_HXX
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */