1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _TOOLKIT_AWT_UNOCONTROLMODEL_HXX_
29 #define _TOOLKIT_AWT_UNOCONTROLMODEL_HXX_
30 
31 #include <com/sun/star/awt/XControlModel.hpp>
32 #include <com/sun/star/lang/XComponent.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/beans/XPropertyState.hpp>
35 #include <com/sun/star/io/XPersistObject.hpp>
36 #include <com/sun/star/lang/XTypeProvider.hpp>
37 #include <com/sun/star/lang/XUnoTunnel.hpp>
38 #include <com/sun/star/util/XCloneable.hpp>
39 #include <cppuhelper/weakagg.hxx>
40 #include <osl/mutex.hxx>
41 
42 #include <toolkit/helper/mutexandbroadcasthelper.hxx>
43 #include <toolkit/helper/listenermultiplexer.hxx>
44 
45 #include <cppuhelper/propshlp.hxx>
46 #include <cppuhelper/interfacecontainer.hxx>
47 #include <cppuhelper/implbase7.hxx>
48 #include <comphelper/componentcontext.hxx>
49 #include <comphelper/uno3.hxx>
50 
51 #include <list>
52 
53 class ImplPropertyTable;
54 
55 //	----------------------------------------------------
56 //	class UnoControlModel
57 //	----------------------------------------------------
58 
59 typedef ::cppu::WeakAggImplHelper7  <   ::com::sun::star::awt::XControlModel
60                                     ,   ::com::sun::star::beans::XPropertyState
61                                     ,   ::com::sun::star::io::XPersistObject
62                                     ,   ::com::sun::star::lang::XComponent
63                                     ,   ::com::sun::star::lang::XServiceInfo
64                                     ,   ::com::sun::star::lang::XUnoTunnel
65                                     ,   ::com::sun::star::util::XCloneable
66                                     >   UnoControlModel_Base;
67 
68 class TOOLKIT_DLLPUBLIC UnoControlModel :public UnoControlModel_Base
69 						                ,public MutexAndBroadcastHelper
70 						                ,public ::cppu::OPropertySetHelper
71 {
72 private:
73 	ImplPropertyTable*			            mpData;
74 	EventListenerMultiplexer	            maDisposeListeners;
75 
76 protected:
77     const ::comphelper::ComponentContext    maContext;
78 
79 protected:
80 	void										ImplRegisterProperty( sal_uInt16 nPropType );
81 	void										ImplRegisterProperties( const std::list< sal_uInt16 > &rIds );
82 	void										ImplRegisterProperty( sal_uInt16 nPropId, const ::com::sun::star::uno::Any& rDefault );
83 	::com::sun::star::uno::Sequence<sal_Int32>	ImplGetPropertyIds() const;
84 	virtual ::com::sun::star::uno::Any 			ImplGetDefaultValue( sal_uInt16 nPropId ) const;
85 	sal_Bool 									ImplHasProperty( sal_uInt16 nPropId ) const;
86 
87 	/** called before setting multiple properties, allows to care for property dependencies
88 
89 		<p>When multiple property values are set (e.g. XPropertySet::setPropertyValues), it may happen that some
90 		of them are dependent. For this, derivees which know such dependencies can affect the order in which
91 		the properties are internally really set.</p>
92 	*/
93 	virtual void ImplNormalizePropertySequence(
94 					const sal_Int32					_nCount,		/// the number of entries in the arrays
95 					sal_Int32*						_pHandles,		/// the handles of the properties to set
96 					::com::sun::star::uno::Any*		_pValues,		/// the values of the properties to set
97 					sal_Int32*						_pValidHandles	/// pointer to the valid handles, allowed to be adjusted
98 				)	const SAL_THROW(());
99 
100     /// ensures that two property values in a sequence have a certain order
101     void    ImplEnsureHandleOrder(
102                 const sal_Int32 _nCount,                /// number of entries in the array
103                 sal_Int32* _pHandles,                   /// pointer to the handles
104                 ::com::sun::star::uno::Any* _pValues,   /// pointer to the values
105                 sal_Int32 _nFirstHandle,                /// first handle, which should precede _nSecondHandle in the sequence
106                 sal_Int32 _nSecondHandle                /// second handle, which should supersede _nFirstHandle in the sequence
107             ) const;
108 
109 protected:
110                 UnoControlModel();
111 public:
112                 UnoControlModel( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory );
113 	            UnoControlModel( const UnoControlModel& rModel );
114 				~UnoControlModel();
115 
116 	virtual UnoControlModel*	Clone() const = 0;
117 
118 	// ::com::sun::star::uno::XInterface
119     ::com::sun::star::uno::Any	SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) { return OWeakAggObject::queryInterface(rType); }
120     void						SAL_CALL acquire() throw();
121     void						SAL_CALL release() throw();
122 
123 	// ::com::sun::star::uno::XAggregation
124     ::com::sun::star::uno::Any	SAL_CALL queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
125 
126 	// ::com::sun::star::lang::XUnoTunnel
127 	static const ::com::sun::star::uno::Sequence< sal_Int8 >&	GetUnoTunnelId() throw();
128 	static UnoControlModel*										GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) throw();
129 	sal_Int64													SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier ) throw(::com::sun::star::uno::RuntimeException);
130 
131 	// ::com::sun::star::util::XCloneable
132     ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() throw(::com::sun::star::uno::RuntimeException);
133 
134 	// ::com::sun::star::lang::XTypeProvider
135     DECLARE_XTYPEPROVIDER()
136 
137 	// ::com::sun::star::lang::XComponent
138     void SAL_CALL dispose(  ) throw(::com::sun::star::uno::RuntimeException);
139     void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
140     void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException);
141 
142 	// ::com::sun::star::beans::XPropertyState
143     ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
144     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > SAL_CALL getPropertyStates( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
145     void SAL_CALL setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
146     ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
147 
148 	// ::com::sun::star::io::XPersistObject
149     ::rtl::OUString SAL_CALL getServiceName() throw(::com::sun::star::uno::RuntimeException);
150     void SAL_CALL write( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream >& OutStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
151     void SAL_CALL read( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream >& InStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
152 
153     // ::com::sun::star::lang::XServiceInfo
154 	::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
155     sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
156     ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
157 
158 	// ::cppu::OPropertySetHelper
159 	::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() = 0;
160 	sal_Bool SAL_CALL convertFastPropertyValue( ::com::sun::star::uno::Any & rConvertedValue, ::com::sun::star::uno::Any & rOldValue, sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::lang::IllegalArgumentException);
161 	void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception);
162     using cppu::OPropertySetHelper::getFastPropertyValue;
163 	void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
164 
165 	// setValue-Methoden ueberladen, um die Einzelproperties des FontDescriptors abzufangen
166 	// ::com::sun::star::beans::XPropertySet
167     void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
168 	// ::com::sun::star::beans::XFastPropertySet
169     void SAL_CALL setFastPropertyValue( sal_Int32 nHandle, const ::com::sun::star::uno::Any& aValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
170 	// ::com::sun::star::beans::XMultiPropertySet
171     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
172     void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& PropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Values ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
173 };
174 
175 #define UNO_CONTROL_MODEL_REGISTER_PROPERTIES(a) \
176     do { \
177         std::list< sal_uInt16 > aIds; \
178         a::ImplGetPropertyIds( aIds ); \
179         ImplRegisterProperties( aIds ); \
180     } while (0)
181 
182 #endif // _TOOLKIT_AWT_UNOCONTROLMODEL_HXX_
183 
184