1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _TOOLKIT_AWT_UNOCONTROLMODEL_HXX_ 25 #define _TOOLKIT_AWT_UNOCONTROLMODEL_HXX_ 26 27 #include <com/sun/star/awt/XControlModel.hpp> 28 #include <com/sun/star/lang/XComponent.hpp> 29 #include <com/sun/star/lang/XServiceInfo.hpp> 30 #include <com/sun/star/beans/XPropertyState.hpp> 31 #include <com/sun/star/io/XPersistObject.hpp> 32 #include <com/sun/star/lang/XTypeProvider.hpp> 33 #include <com/sun/star/lang/XUnoTunnel.hpp> 34 #include <com/sun/star/util/XCloneable.hpp> 35 #include <cppuhelper/weakagg.hxx> 36 #include <osl/mutex.hxx> 37 38 #include <toolkit/helper/mutexandbroadcasthelper.hxx> 39 #include <toolkit/helper/listenermultiplexer.hxx> 40 41 #include <cppuhelper/propshlp.hxx> 42 #include <cppuhelper/interfacecontainer.hxx> 43 #include <cppuhelper/implbase7.hxx> 44 #include <comphelper/componentcontext.hxx> 45 #include <comphelper/uno3.hxx> 46 47 #include <list> 48 49 class ImplPropertyTable; 50 51 // ---------------------------------------------------- 52 // class UnoControlModel 53 // ---------------------------------------------------- 54 55 typedef ::cppu::WeakAggImplHelper7 < ::com::sun::star::awt::XControlModel 56 , ::com::sun::star::beans::XPropertyState 57 , ::com::sun::star::io::XPersistObject 58 , ::com::sun::star::lang::XComponent 59 , ::com::sun::star::lang::XServiceInfo 60 , ::com::sun::star::lang::XUnoTunnel 61 , ::com::sun::star::util::XCloneable 62 > UnoControlModel_Base; 63 64 class TOOLKIT_DLLPUBLIC UnoControlModel :public UnoControlModel_Base 65 ,public MutexAndBroadcastHelper 66 ,public ::cppu::OPropertySetHelper 67 { 68 private: 69 ImplPropertyTable* mpData; 70 EventListenerMultiplexer maDisposeListeners; 71 72 protected: 73 const ::comphelper::ComponentContext maContext; 74 75 protected: 76 void ImplRegisterProperty( sal_uInt16 nPropType ); 77 void ImplRegisterProperties( const std::list< sal_uInt16 > &rIds ); 78 void ImplRegisterProperty( sal_uInt16 nPropId, const ::com::sun::star::uno::Any& rDefault ); 79 ::com::sun::star::uno::Sequence<sal_Int32> ImplGetPropertyIds() const; 80 virtual ::com::sun::star::uno::Any ImplGetDefaultValue( sal_uInt16 nPropId ) const; 81 sal_Bool ImplHasProperty( sal_uInt16 nPropId ) const; 82 83 /** called before setting multiple properties, allows to care for property dependencies 84 85 <p>When multiple property values are set (e.g. XPropertySet::setPropertyValues), it may happen that some 86 of them are dependent. For this, derivees which know such dependencies can affect the order in which 87 the properties are internally really set.</p> 88 */ 89 virtual void ImplNormalizePropertySequence( 90 const sal_Int32 _nCount, /// the number of entries in the arrays 91 sal_Int32* _pHandles, /// the handles of the properties to set 92 ::com::sun::star::uno::Any* _pValues, /// the values of the properties to set 93 sal_Int32* _pValidHandles /// pointer to the valid handles, allowed to be adjusted 94 ) const SAL_THROW(()); 95 96 /// ensures that two property values in a sequence have a certain order 97 void ImplEnsureHandleOrder( 98 const sal_Int32 _nCount, /// number of entries in the array 99 sal_Int32* _pHandles, /// pointer to the handles 100 ::com::sun::star::uno::Any* _pValues, /// pointer to the values 101 sal_Int32 _nFirstHandle, /// first handle, which should precede _nSecondHandle in the sequence 102 sal_Int32 _nSecondHandle /// second handle, which should supersede _nFirstHandle in the sequence 103 ) const; 104 105 protected: 106 UnoControlModel(); 107 public: 108 UnoControlModel( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory ); 109 UnoControlModel( const UnoControlModel& rModel ); 110 ~UnoControlModel(); 111 112 virtual UnoControlModel* Clone() const = 0; 113 114 // ::com::sun::star::uno::XInterface queryInterface(const::com::sun::star::uno::Type & rType)115 ::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); } 116 void SAL_CALL acquire() throw(); 117 void SAL_CALL release() throw(); 118 119 // ::com::sun::star::uno::XAggregation 120 ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 121 122 // ::com::sun::star::lang::XUnoTunnel 123 static const ::com::sun::star::uno::Sequence< sal_Int8 >& GetUnoTunnelId() throw(); 124 static UnoControlModel* GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) throw(); 125 sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier ) throw(::com::sun::star::uno::RuntimeException); 126 127 // ::com::sun::star::util::XCloneable 128 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() throw(::com::sun::star::uno::RuntimeException); 129 130 // ::com::sun::star::lang::XTypeProvider 131 DECLARE_XTYPEPROVIDER() 132 133 // ::com::sun::star::lang::XComponent 134 void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException); 135 void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw(::com::sun::star::uno::RuntimeException); 136 void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException); 137 138 // ::com::sun::star::beans::XPropertyState 139 ::com::sun::star::beans::PropertyState SAL_CALL getPropertyState( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); 140 ::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); 141 void SAL_CALL setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException); 142 ::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); 143 144 // ::com::sun::star::io::XPersistObject 145 ::rtl::OUString SAL_CALL getServiceName() throw(::com::sun::star::uno::RuntimeException); 146 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); 147 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); 148 149 // ::com::sun::star::lang::XServiceInfo 150 ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 151 sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 152 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); 153 154 // ::cppu::OPropertySetHelper 155 ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() = 0; 156 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); 157 void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception); 158 using cppu::OPropertySetHelper::getFastPropertyValue; 159 void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; 160 161 // setValue-Methoden ueberladen, um die Einzelproperties des FontDescriptors abzufangen 162 // ::com::sun::star::beans::XPropertySet 163 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); 164 // ::com::sun::star::beans::XFastPropertySet 165 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); 166 // ::com::sun::star::beans::XMultiPropertySet 167 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); 168 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); 169 }; 170 171 #define UNO_CONTROL_MODEL_REGISTER_PROPERTIES(a) \ 172 do { \ 173 std::list< sal_uInt16 > aIds; \ 174 a::ImplGetPropertyIds( aIds ); \ 175 ImplRegisterProperties( aIds ); \ 176 } while (0) 177 178 #endif // _TOOLKIT_AWT_UNOCONTROLMODEL_HXX_ 179 180