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/lang/XUnoTunnel.hpp>
29 #include <com/sun/star/util/XCloneable.hpp>
30 #include <cppuhelper/weakagg.hxx>
32 #include <toolkit/helper/mutexandbroadcasthelper.hxx>
33 #include <toolkit/helper/listenermultiplexer.hxx>
35 #include <cppuhelper/propshlp.hxx>
36 #include <cppuhelper/implbase7.hxx>
37 #include <comphelper/uno3.hxx>
38 #include <rtl/ref.hxx>
43 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{ class XComponentContext
; } } } }
45 typedef std::map
<sal_uInt16
, css::uno::Any
> ImplPropertyTable
;
48 // class UnoControlModel
51 typedef ::cppu::WeakAggImplHelper7
< css::awt::XControlModel
52 , css::beans::XPropertyState
53 , css::io::XPersistObject
54 , css::lang::XComponent
55 , css::lang::XServiceInfo
56 , css::lang::XUnoTunnel
57 , css::util::XCloneable
58 > UnoControlModel_Base
;
60 class TOOLKIT_DLLPUBLIC UnoControlModel
:public UnoControlModel_Base
61 ,public MutexAndBroadcastHelper
62 ,public ::cppu::OPropertySetHelper
65 ImplPropertyTable maData
;
66 EventListenerMultiplexer maDisposeListeners
;
69 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
72 void ImplRegisterProperty( sal_uInt16 nPropType
);
73 void ImplRegisterProperties( const std::vector
< sal_uInt16
> &rIds
);
74 void ImplRegisterProperty( sal_uInt16 nPropId
, const css::uno::Any
& rDefault
);
75 css::uno::Sequence
<sal_Int32
> ImplGetPropertyIds() const;
76 virtual css::uno::Any
ImplGetDefaultValue( sal_uInt16 nPropId
) const;
77 bool ImplHasProperty( sal_uInt16 nPropId
) const;
79 /** called before setting multiple properties, allows to care for property dependencies
81 <p>When multiple property values are set (e.g. XPropertySet::setPropertyValues), it may happen that some
82 of them are dependent. For this, derivees which know such dependencies can affect the order in which
83 the properties are internally really set.</p>
85 virtual void ImplNormalizePropertySequence(
86 const sal_Int32 _nCount
, /// the number of entries in the arrays
87 sal_Int32
* _pHandles
, /// the handles of the properties to set
88 css::uno::Any
* _pValues
, /// the values of the properties to set
89 sal_Int32
* _pValidHandles
/// pointer to the valid handles, allowed to be adjusted
92 /// ensures that two property values in a sequence have a certain order
93 static void ImplEnsureHandleOrder(
94 const sal_Int32 _nCount
, /// number of entries in the array
95 sal_Int32
* _pHandles
, /// pointer to the handles
96 css::uno::Any
* _pValues
, /// pointer to the values
97 sal_Int32 _nFirstHandle
, /// first handle, which should precede _nSecondHandle in the sequence
98 sal_Int32 _nSecondHandle
/// second handle, which should supersede _nFirstHandle in the sequence
101 template<typename T
> void UNO_CONTROL_MODEL_REGISTER_PROPERTIES() {
102 std::vector
< sal_uInt16
> aIds
;
103 T::ImplGetPropertyIds( aIds
);
104 ImplRegisterProperties( aIds
);
109 UnoControlModel() //do not use! needed by MSVC at compile time to satisfy WeakAggImplHelper7
110 : UnoControlModel_Base()
111 , MutexAndBroadcastHelper()
112 , OPropertySetHelper( BrdcstHelper
)
113 , maDisposeListeners( *this )
114 , m_xContext( css::uno::Reference
< css::uno::XComponentContext
>() )
121 UnoControlModel( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
122 UnoControlModel( const UnoControlModel
& rModel
);
124 virtual rtl::Reference
<UnoControlModel
> Clone() const = 0;
126 // css::uno::XInterface
127 css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
{ return OWeakAggObject::queryInterface(rType
); }
128 void SAL_CALL
acquire() throw() override
;
129 void SAL_CALL
release() throw() override
;
131 // css::uno::XAggregation
132 css::uno::Any SAL_CALL
queryAggregation( const css::uno::Type
& rType
) override
;
134 // css::lang::XUnoTunnel
135 static const css::uno::Sequence
< sal_Int8
>& getUnoTunnelId() throw();
136 sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& rIdentifier
) override
;
138 // css::util::XCloneable
139 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone() override
;
141 // css::lang::XTypeProvider
142 DECLARE_XTYPEPROVIDER()
144 // css::lang::XComponent
145 void SAL_CALL
dispose( ) override
;
146 void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
147 void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
149 // css::beans::XPropertyState
150 css::beans::PropertyState SAL_CALL
getPropertyState( const OUString
& PropertyName
) override
;
151 css::uno::Sequence
< css::beans::PropertyState
> SAL_CALL
getPropertyStates( const css::uno::Sequence
< OUString
>& aPropertyName
) override
;
152 void SAL_CALL
setPropertyToDefault( const OUString
& PropertyName
) override
;
153 css::uno::Any SAL_CALL
getPropertyDefault( const OUString
& aPropertyName
) override
;
155 // css::io::XPersistObject
156 OUString SAL_CALL
getServiceName() override
;
157 void SAL_CALL
write( const css::uno::Reference
< css::io::XObjectOutputStream
>& OutStream
) override
;
158 void SAL_CALL
read( const css::uno::Reference
< css::io::XObjectInputStream
>& InStream
) override
;
160 // css::lang::XServiceInfo
161 OUString SAL_CALL
getImplementationName( ) override
;
162 sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
163 css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
165 // ::cppu::OPropertySetHelper
166 ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
= 0;
167 sal_Bool SAL_CALL
convertFastPropertyValue( css::uno::Any
& rConvertedValue
, css::uno::Any
& rOldValue
, sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
168 void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
169 using cppu::OPropertySetHelper::getFastPropertyValue
;
170 void SAL_CALL
getFastPropertyValue( css::uno::Any
& rValue
, sal_Int32 nHandle
) const override
;
172 // override setValue methods to handle properties of FontDescriptor
173 // css::beans::XPropertySet
174 void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
175 // css::beans::XFastPropertySet
176 void SAL_CALL
setFastPropertyValue( sal_Int32 nHandle
, const css::uno::Any
& aValue
) override
;
177 // css::beans::XMultiPropertySet
178 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
179 void SAL_CALL
setPropertyValues( const css::uno::Sequence
< OUString
>& PropertyNames
, const css::uno::Sequence
< css::uno::Any
>& Values
) override
;
182 #endif // INCLUDED_TOOLKIT_CONTROLS_UNOCONTROLMODEL_HXX
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */