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_HELPERS_GEOMETRYCONTROLMODEL_HXX_ 25 #define _TOOLKIT_HELPERS_GEOMETRYCONTROLMODEL_HXX_ 26 27 #include <comphelper/broadcasthelper.hxx> 28 #include <comphelper/uno3.hxx> 29 #include <comphelper/propagg.hxx> 30 #include <comphelper/proparrhlp.hxx> 31 #include <comphelper/propertycontainer.hxx> 32 #include <cppuhelper/weakagg.hxx> 33 #include <cppuhelper/compbase2.hxx> 34 #include <com/sun/star/util/XCloneable.hpp> 35 #include <com/sun/star/script/XScriptEventsSupplier.hpp> 36 #include <com/sun/star/resource/XStringResourceResolver.hpp> 37 #include <cppuhelper/typeprovider.hxx> 38 #include <comphelper/IdPropArrayHelper.hxx> 39 #include <comphelper/stl_types.hxx> 40 41 FORWARD_DECLARE_INTERFACE( lang, XMultiServiceFactory ) 42 FORWARD_DECLARE_INTERFACE( script, XNameContainer ) 43 44 //........................................................................ 45 // namespace toolkit 46 // { 47 //........................................................................ 48 49 //==================================================================== 50 //= OGeometryControlModel_Base 51 //==================================================================== 52 typedef ::cppu::WeakAggComponentImplHelper2 < ::com::sun::star::util::XCloneable 53 , ::com::sun::star::script::XScriptEventsSupplier 54 > OGCM_Base; 55 class OGeometryControlModel_Base 56 :public ::comphelper::OMutexAndBroadcastHelper 57 ,public ::comphelper::OPropertySetAggregationHelper 58 ,public ::comphelper::OPropertyContainer 59 ,public OGCM_Base 60 { 61 protected: 62 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > 63 m_xAggregate; 64 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > 65 mxEventContainer; 66 67 // <properties> 68 sal_Int32 m_nPosX; 69 sal_Int32 m_nPosY; 70 sal_Int32 m_nWidth; 71 sal_Int32 m_nHeight; 72 ::rtl::OUString m_aName; 73 sal_Int16 m_nTabIndex; 74 sal_Int32 m_nStep; 75 ::rtl::OUString m_aTag; 76 ::com::sun::star::uno::Reference< ::com::sun::star::resource::XStringResourceResolver > m_xStrResolver; 77 // </properties> 78 79 sal_Bool m_bCloneable; 80 81 protected: 82 virtual ::com::sun::star::uno::Any ImplGetDefaultValueByHandle(sal_Int32 nHandle) const; 83 virtual ::com::sun::star::uno::Any ImplGetPropertyValueByHandle(sal_Int32 nHandle) const; 84 virtual void ImplSetPropertyValueByHandle(sal_Int32 nHandle, const :: com::sun::star::uno::Any& aValue); 85 86 protected: 87 /** 88 @param _pAggregateInstance 89 the object to be aggregated. The refcount of the instance given MUST be 0! 90 */ 91 OGeometryControlModel_Base(::com::sun::star::uno::XAggregation* _pAggregateInstance); 92 93 /** 94 @param _rxAggregateInstance 95 is the object to be aggregated. Must be aquired excatly once (by the reference object given).<br/> 96 Will be reset to NULL upon leaving 97 */ 98 OGeometryControlModel_Base(::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance); 99 100 /** releases the aggregation 101 <p>Can be used if in a derived class, an exception has to be thrown after this base class here already 102 did the aggregation</p> 103 */ 104 void releaseAggregation(); 105 106 protected: 107 ~OGeometryControlModel_Base(); 108 109 // XAggregation 110 ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _aType ) throw(::com::sun::star::uno::RuntimeException); 111 112 // XInterface 113 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException); 114 virtual void SAL_CALL acquire( ) throw(); 115 virtual void SAL_CALL release( ) throw(); 116 117 // XTypeProvider 118 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException); 119 120 // OPropertySetHelper overridables 121 virtual sal_Bool SAL_CALL convertFastPropertyValue( 122 ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, 123 sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue ) 124 throw (::com::sun::star::lang::IllegalArgumentException); 125 126 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( 127 sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue) 128 throw (::com::sun::star::uno::Exception); 129 130 using comphelper::OPropertySetAggregationHelper::getFastPropertyValue; 131 virtual void SAL_CALL getFastPropertyValue( 132 ::com::sun::star::uno::Any& _rValue, sal_Int32 _nHandle) const; 133 134 // OPropertyStateHelper overridables 135 virtual ::com::sun::star::beans::PropertyState getPropertyStateByHandle(sal_Int32 nHandle); 136 virtual void setPropertyToDefaultByHandle(sal_Int32 nHandle); 137 virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle(sal_Int32 nHandle) const; 138 139 // XPropertySet 140 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException); 141 142 // OPropertySetAggregationHelper overridables 143 using OPropertySetAggregationHelper::getInfoHelper; 144 145 // XCloneable 146 virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone( ) throw(::com::sun::star::uno::RuntimeException); 147 148 //XScriptEventsSupplier 149 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > 150 SAL_CALL getEvents( ) throw(::com::sun::star::uno::RuntimeException); 151 152 // XCloneable implementation - to be overwritten 153 virtual OGeometryControlModel_Base* createClone_Impl( 154 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance) = 0; 155 156 // XComponent 157 using comphelper::OPropertySetAggregationHelper::disposing; 158 virtual void SAL_CALL disposing(); 159 160 private: 161 void registerProperties(); 162 }; 163 164 //==================================================================== 165 //= OTemplateInstanceDisambiguation 166 //==================================================================== 167 template <class CONTROLMODEL> 168 class OTemplateInstanceDisambiguation 169 { 170 }; 171 172 //==================================================================== 173 //= OGeometryControlModel 174 //==================================================================== 175 /* example for usage: 176 Reference< XAggregation > xIFace = new ::toolkit::OGeometryControlModel< UnoControlButtonModel > (); 177 */ 178 template <class CONTROLMODEL> 179 class OGeometryControlModel 180 :public OGeometryControlModel_Base 181 ,public ::comphelper::OAggregationArrayUsageHelper< OTemplateInstanceDisambiguation< CONTROLMODEL > > 182 { 183 public: 184 OGeometryControlModel( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory ); 185 186 private: 187 OGeometryControlModel(::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance); 188 189 protected: 190 // OAggregationArrayUsageHelper overridables 191 virtual void fillProperties( 192 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _rProps, 193 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& _rAggregateProps 194 ) const; 195 196 // OPropertySetAggregationHelper overridables 197 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 198 199 // OGeometryControlModel_Base 200 virtual OGeometryControlModel_Base* createClone_Impl( 201 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance); 202 203 // XTypeProvider 204 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException); 205 }; 206 207 //==================================================================== 208 //= OCommonGeometryControlModel 209 //==================================================================== 210 /** allows to extend an arbitrary <type scope="com.sun.star.awt">UnoControlModel</type> with geometry 211 information. 212 */ 213 class OCommonGeometryControlModel 214 :public OGeometryControlModel_Base 215 ,public ::comphelper::OIdPropertyArrayUsageHelper< OCommonGeometryControlModel > 216 { 217 private: 218 ::rtl::OUString m_sServiceSpecifier; // the service specifier of our aggregate 219 sal_Int32 m_nPropertyMapId; // our unique property info id, used to look up in s_aAggregateProperties 220 221 public: 222 /** instantiate the model 223 224 @param _rxAgg 225 the instance to aggregate. Must support the <type scope="com.sun.star.awt">UnoControlModel</type> 226 (this is not checked here) 227 */ 228 OCommonGeometryControlModel( 229 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAgg, 230 const ::rtl::OUString& _rxServiceSpecifier 231 ); 232 233 // OIdPropertyArrayUsageHelper overridables 234 virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const; 235 236 // OPropertySetAggregationHelper overridables 237 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 238 239 // OGeometryControlModel_Base 240 virtual OGeometryControlModel_Base* createClone_Impl( 241 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >& _rxAggregateInstance); 242 243 // XTypeProvider 244 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException); 245 246 private: 247 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( 248 sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue) 249 throw (::com::sun::star::uno::Exception); 250 }; 251 252 #include "toolkit/controls/geometrycontrolmodel_impl.hxx" 253 254 //........................................................................ 255 // } // namespace toolkit 256 //........................................................................ 257 258 #endif // _TOOLKIT_HELPERS_GEOMETRYCONTROLMODEL_HXX_ 259