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 <toolkit/helper/listenermultiplexer.hxx>
33 #include <comphelper/propshlp.hxx>
34 #include <cppuhelper/implbase6.hxx>
35 #include <comphelper/uno3.hxx>
36 #include <rtl/ref.hxx>
41 namespace com::sun::star::uno
{ class XComponentContext
; }
43 typedef std::map
<sal_uInt16
, css::uno::Any
> ImplPropertyTable
;
45 typedef ::cppu::WeakAggImplHelper6
< css::awt::XControlModel
46 , css::beans::XPropertyState
47 , css::io::XPersistObject
48 , css::lang::XComponent
49 , css::lang::XServiceInfo
50 , css::util::XCloneable
51 > UnoControlModel_Base
;
53 class UnoControlModel
: public UnoControlModel_Base
54 ,public ::comphelper::OPropertySetHelper
57 ImplPropertyTable maData
;
58 EventListenerMultiplexer maDisposeListeners
;
61 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
64 void ImplRegisterProperty( sal_uInt16 nPropType
);
65 void ImplRegisterProperties( const std::vector
< sal_uInt16
> &rIds
);
66 void ImplRegisterProperty( sal_uInt16 nPropId
, const css::uno::Any
& rDefault
);
67 css::uno::Sequence
<sal_Int32
> ImplGetPropertyIds() const;
68 virtual css::uno::Any
ImplGetDefaultValue( sal_uInt16 nPropId
) const;
69 bool ImplHasProperty( sal_uInt16 nPropId
) const;
71 /** called before setting multiple properties, allows to care for property dependencies
73 <p>When multiple property values are set (e.g. XPropertySet::setPropertyValues), it may happen that some
74 of them are dependent. For this, derivees which know such dependencies can affect the order in which
75 the properties are internally really set.</p>
77 virtual void ImplNormalizePropertySequence(
78 const sal_Int32 _nCount
, /// the number of entries in the arrays
79 sal_Int32
* _pHandles
, /// the handles of the properties to set
80 css::uno::Any
* _pValues
, /// the values of the properties to set
81 sal_Int32
* _pValidHandles
/// pointer to the valid handles, allowed to be adjusted
84 /// ensures that two property values in a sequence have a certain order
85 static void ImplEnsureHandleOrder(
86 const sal_Int32 _nCount
, /// number of entries in the array
87 sal_Int32
* _pHandles
, /// pointer to the handles
88 css::uno::Any
* _pValues
, /// pointer to the values
89 sal_Int32 _nFirstHandle
, /// first handle, which should precede _nSecondHandle in the sequence
90 sal_Int32 _nSecondHandle
/// second handle, which should supersede _nFirstHandle in the sequence
93 template<typename T
> void UNO_CONTROL_MODEL_REGISTER_PROPERTIES() {
94 std::vector
< sal_uInt16
> aIds
;
95 T::ImplGetPropertyIds( aIds
);
96 ImplRegisterProperties( aIds
);
101 UnoControlModel() //do not use! needed by MSVC at compile time to satisfy WeakAggImplHelper7
102 : UnoControlModel_Base()
103 , OPropertySetHelper()
104 , maDisposeListeners( *this )
105 , m_xContext( css::uno::Reference
< css::uno::XComponentContext
>() )
112 UnoControlModel( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
113 UnoControlModel( const UnoControlModel
& rModel
);
115 virtual rtl::Reference
<UnoControlModel
> Clone() const = 0;
117 // css::uno::XInterface
118 css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
{ return OWeakAggObject::queryInterface(rType
); }
119 void SAL_CALL
acquire() noexcept override
;
120 void SAL_CALL
release() noexcept override
;
122 // css::uno::XAggregation
123 css::uno::Any SAL_CALL
queryAggregation( const css::uno::Type
& rType
) override
;
125 // css::util::XCloneable
126 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone() override
;
128 // css::lang::XTypeProvider
129 DECLARE_XTYPEPROVIDER()
131 // css::lang::XComponent
132 void SAL_CALL
dispose( ) override
;
133 void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
134 void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
136 // css::beans::XPropertyState
137 css::beans::PropertyState SAL_CALL
getPropertyState( const OUString
& PropertyName
) override
;
138 css::uno::Sequence
< css::beans::PropertyState
> SAL_CALL
getPropertyStates( const css::uno::Sequence
< OUString
>& aPropertyName
) override
;
139 void SAL_CALL
setPropertyToDefault( const OUString
& PropertyName
) override
;
140 css::uno::Any SAL_CALL
getPropertyDefault( const OUString
& aPropertyName
) override
;
142 // css::io::XPersistObject
143 OUString SAL_CALL
getServiceName() override
;
144 void SAL_CALL
write( const css::uno::Reference
< css::io::XObjectOutputStream
>& OutStream
) override
;
145 void SAL_CALL
read( const css::uno::Reference
< css::io::XObjectInputStream
>& InStream
) override
;
147 // css::lang::XServiceInfo
148 OUString SAL_CALL
getImplementationName( ) override
;
149 sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
150 css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
152 // ::cppu::OPropertySetHelper
153 ::cppu::IPropertyArrayHelper
& getInfoHelper() override
= 0;
154 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
;
155 void setFastPropertyValue_NoBroadcast(
156 std::unique_lock
<std::mutex
>& rGuard
,
157 sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
158 using comphelper::OPropertySetHelper::getFastPropertyValue
;
159 void getFastPropertyValue( std::unique_lock
<std::mutex
>& rGuard
, css::uno::Any
& rValue
, sal_Int32 nHandle
) const override
;
161 // css::beans::XMultiPropertySet
162 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
163 void SAL_CALL
setPropertyValues( const css::uno::Sequence
< OUString
>& PropertyNames
, const css::uno::Sequence
< css::uno::Any
>& Values
) override
;
165 // override setValue methods to handle properties of FontDescriptor
166 // css::beans::XFastPropertySet
167 void setFastPropertyValueImpl( std::unique_lock
<std::mutex
>& rGuard
, sal_Int32 nHandle
, const css::uno::Any
& aValue
) override
;
168 css::beans::PropertyState
getPropertyStateImpl( std::unique_lock
<std::mutex
>& rGuard
, const OUString
& PropertyName
);
169 void setPropertyValuesImpl( std::unique_lock
<std::mutex
>& rGuard
, const css::uno::Sequence
< OUString
>& PropertyNames
, const css::uno::Sequence
< css::uno::Any
>& Values
);
172 #endif // INCLUDED_TOOLKIT_CONTROLS_UNOCONTROLMODEL_HXX
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */