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 FORMS_SOURCE_XFORMS_DATATYPES_HXX 25 #define FORMS_SOURCE_XFORMS_DATATYPES_HXX 26 27 /** === begin UNO includes === **/ 28 #include <com/sun/star/beans/PropertyAttribute.hpp> 29 #include <com/sun/star/util/Date.hpp> 30 #include <com/sun/star/util/Time.hpp> 31 #include <com/sun/star/util/DateTime.hpp> 32 #include <com/sun/star/xsd/XDataType.hpp> 33 #include <com/sun/star/xsd/DataTypeClass.hpp> 34 /** === end UNO includes === **/ 35 #include <cppuhelper/implbase1.hxx> 36 #include <comphelper/uno3.hxx> 37 #include <comphelper/propertycontainer.hxx> 38 #include <comphelper/proparrhlp.hxx> 39 #include <comphelper/broadcasthelper.hxx> 40 #include "warnings_guard_unicode_regex.h" 41 42 #include <memory> 43 44 //........................................................................ 45 namespace xforms 46 { 47 //........................................................................ 48 49 //==================================================================== 50 //= OXSDDataType 51 //==================================================================== 52 typedef ::cppu::WeakImplHelper1 < ::com::sun::star::xsd::XDataType 53 > OXSDDataType_Base; 54 typedef ::comphelper::OMutexAndBroadcastHelper OXSDDataType_BBase; 55 typedef ::comphelper::OPropertyContainer OXSDDataType_PBase; 56 57 class OXSDDataType :public OXSDDataType_Base 58 ,public OXSDDataType_BBase // order matters: OMutexAndBroadcastHelper before 59 ,public OXSDDataType_PBase // OPropertyContainer 60 { 61 private: 62 // <properties> 63 sal_Bool m_bIsBasic; 64 sal_Int16 m_nTypeClass; 65 ::rtl::OUString m_sName; 66 ::rtl::OUString m_sPattern; 67 sal_uInt16 m_nWST; 68 // </properties> 69 70 ::std::auto_ptr< U_NAMESPACE_QUALIFIER RegexMatcher > 71 m_pPatternMatcher; 72 bool m_bPatternMatcherDirty; 73 74 protected: 75 isBasic() const76 sal_Bool isBasic() const { return m_bIsBasic; } getTypeClass() const77 sal_Int16 getTypeClass() const { return m_nTypeClass; } 78 const ::rtl::OUString& getName() const79 getName() const { return m_sName; } 80 81 private: 82 OXSDDataType( ); // never implemented 83 OXSDDataType( const OXSDDataType& ); // never implemented 84 OXSDDataType& operator=( const OXSDDataType& ); // never implemented 85 86 protected: 87 // create basic data type 88 OXSDDataType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass ); 89 ~OXSDDataType(); 90 91 public: 92 DECLARE_XINTERFACE() 93 DECLARE_XTYPEPROVIDER() 94 95 virtual ::rtl::OUString SAL_CALL getName( ); 96 virtual void SAL_CALL setName( const ::rtl::OUString& aName ); 97 virtual ::rtl::OUString SAL_CALL getPattern(); 98 virtual void SAL_CALL setPattern( const ::rtl::OUString& _pattern ); 99 virtual sal_Int16 SAL_CALL getWhiteSpaceTreatment(); 100 virtual void SAL_CALL setWhiteSpaceTreatment( sal_Int16 _whitespacetreatment ); 101 virtual sal_Bool SAL_CALL getIsBasic(); 102 virtual sal_Int16 SAL_CALL getTypeClass(); 103 104 virtual sal_Bool SAL_CALL validate( const ::rtl::OUString& value ); 105 virtual ::rtl::OUString SAL_CALL explainInvalid( const ::rtl::OUString& value ); 106 107 // XPropertySet - is a base of XDataType and needs to be disambiguated 108 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ); 109 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ); 110 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ); 111 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ); 112 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ); 113 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ); 114 115 public: 116 OXSDDataType* clone( const ::rtl::OUString& _rNewName ) const; 117 118 protected: 119 // XPropertySet and friends 120 virtual 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 ); 121 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( 122 sal_Int32 nHandle, 123 const ::com::sun::star::uno::Any& rValue 124 ); 125 126 // --- own overridables --- 127 // helper for implementing cloning of data types 128 virtual OXSDDataType* createClone( const ::rtl::OUString& _rName ) const = 0; 129 virtual void initializeClone( const OXSDDataType& _rCloneSource ); 130 131 // helper method for validate and explainInvalid 132 virtual sal_uInt16 _validate( const ::rtl::OUString& value ); 133 virtual ::rtl::OUString _explainInvalid( sal_uInt16 nReason ); 134 135 // helper method for checking properties values which are to be set 136 virtual bool checkPropertySanity( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rNewValue, ::rtl::OUString& _rErrorMessage ); 137 138 // register properties implemented by this instance - call the base class when overriding 139 virtual void registerProperties(); 140 }; 141 142 //==================================================================== 143 //= helper for deriving from OXSDDataType 144 //==================================================================== 145 #define DECLARE_DEFAULT_CLONING( classname ) \ 146 virtual OXSDDataType* createClone( const ::rtl::OUString& _rName ) const; \ 147 virtual void initializeClone( const OXSDDataType& _rCloneSource ); \ 148 void initializeTypedClone( const classname& _rCloneSource ); 149 150 #define IMPLEMENT_DEFAULT_CLONING( classname, baseclass ) \ 151 OXSDDataType* classname::createClone( const ::rtl::OUString& _rName ) const \ 152 { \ 153 return new classname( _rName ); \ 154 } \ 155 void classname::initializeClone( const OXSDDataType& _rCloneSource ) \ 156 { \ 157 baseclass::initializeClone( _rCloneSource ); \ 158 initializeTypedClone( static_cast< const classname& >( _rCloneSource ) ); \ 159 } \ 160 161 #define IMPLEMENT_DEFAULT_TYPED_CLONING( classname, baseclass ) \ 162 OXSDDataType* classname::createClone( const ::rtl::OUString& _rName ) const \ 163 { \ 164 return new classname( _rName, getTypeClass() ); \ 165 } \ 166 void classname::initializeClone( const OXSDDataType& _rCloneSource ) \ 167 { \ 168 baseclass::initializeClone( _rCloneSource ); \ 169 initializeTypedClone( static_cast< const classname& >( _rCloneSource ) ); \ 170 } \ 171 172 #define REGISTER_VOID_PROP( prop, memberAny, type ) \ 173 registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, ::com::sun::star::beans::PropertyAttribute::BOUND | ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, \ 174 &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) ); 175 176 //==================================================================== 177 //= OValueLimitedType_Base 178 //==================================================================== 179 class OValueLimitedType_Base : public OXSDDataType 180 { 181 protected: 182 ::com::sun::star::uno::Any m_aMaxInclusive; 183 ::com::sun::star::uno::Any m_aMaxExclusive; 184 ::com::sun::star::uno::Any m_aMinInclusive; 185 ::com::sun::star::uno::Any m_aMinExclusive; 186 187 double m_fCachedMaxInclusive; 188 double m_fCachedMaxExclusive; 189 double m_fCachedMinInclusive; 190 double m_fCachedMinExclusive; 191 192 protected: 193 OValueLimitedType_Base( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass ); 194 195 virtual void initializeClone( const OXSDDataType& _rCloneSource ); 196 void initializeTypedClone( const OValueLimitedType_Base& _rCloneSource ); 197 198 // XPropertySet and friends 199 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( 200 sal_Int32 nHandle, 201 const ::com::sun::star::uno::Any& rValue 202 ); 203 204 // OXSDDataType overridables 205 virtual bool _getValue( const ::rtl::OUString& value, double& fValue ); 206 virtual sal_uInt16 _validate( const ::rtl::OUString& value ); 207 virtual ::rtl::OUString _explainInvalid( sal_uInt16 nReason ); 208 209 // own overridables 210 /** translate a given value into a human-readable string 211 212 The value is guaranteed to be not <NULL/>, and is of type <member>ValueType</member> 213 */ 214 virtual ::rtl::OUString typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const = 0; 215 216 /** translates a <member>ValueType</member> value into a double value 217 218 The normalization must respect the "<" and "==" relations on the value 219 space. That is, if two values are equal, their normalizations must be equal, too. 220 Similarly, if <code>foo</code> is less than <code>bar</code>, the same 221 must hold for their normalizations. 222 223 @param _rValue 224 the value to translate. Guaranteed to be not <NULL/>, and of type <member>ValueType</member> 225 @param _rDoubleValue 226 output parameter to hold the resulting double value 227 */ 228 virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const = 0; 229 }; 230 231 //==================================================================== 232 //= OValueLimitedType 233 //==================================================================== 234 template < typename VALUE_TYPE > 235 class OValueLimitedType : public OValueLimitedType_Base 236 { 237 protected: 238 typedef VALUE_TYPE ValueType; 239 inline const ::com::sun::star::uno::Type& getCppuType() const240 getCppuType() const { return ::getCppuType( static_cast< ValueType* >( NULL ) ); } 241 242 protected: 243 OValueLimitedType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass ); 244 245 // OXSDDataType overridables 246 virtual void registerProperties(); 247 }; 248 249 //==================================================================== 250 //= ODerivedDataType 251 //==================================================================== 252 /** helper class for implementing interfaces derived from XDataType 253 */ 254 template< typename CONCRETE_DATA_TYPE_IMPL, typename SUPERCLASS = OXSDDataType > 255 class ODerivedDataType :public SUPERCLASS 256 ,::comphelper::OPropertyArrayUsageHelper< CONCRETE_DATA_TYPE_IMPL > 257 { 258 private: 259 bool m_bPropertiesRegistered; 260 261 protected: 262 ODerivedDataType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass ); 263 264 protected: 265 // OPropertyArrayUsageHelper 266 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; 267 268 // XPropertySet 269 virtual com::sun::star::uno::Reference<com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo(); 270 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 271 }; 272 273 //==================================================================== 274 //= OBooleanType 275 //==================================================================== 276 class OBooleanType; 277 typedef ODerivedDataType< OBooleanType > OBooleanType_Base; 278 class OBooleanType : public OBooleanType_Base 279 { 280 public: 281 OBooleanType( const ::rtl::OUString& _rName ); 282 283 protected: 284 DECLARE_DEFAULT_CLONING( OBooleanType ) 285 286 // OXSDDataType overridables 287 virtual sal_uInt16 _validate( const ::rtl::OUString& value ); 288 virtual ::rtl::OUString _explainInvalid( sal_uInt16 nReason ); 289 }; 290 291 //==================================================================== 292 //= OStringType 293 //==================================================================== 294 class OStringType; 295 typedef ODerivedDataType< OStringType > OStringType_Base; 296 class OStringType :public OStringType_Base 297 { 298 protected: 299 // <properties> 300 ::com::sun::star::uno::Any m_aLength; 301 ::com::sun::star::uno::Any m_aMinLength; 302 ::com::sun::star::uno::Any m_aMaxLength; 303 // </properties> 304 305 public: 306 OStringType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass /* = ::com::sun::star::xsd::DataTypeClass::STRING */ ); 307 308 protected: 309 DECLARE_DEFAULT_CLONING( OStringType ) 310 311 // OXSDDataType overridables 312 virtual sal_uInt16 _validate( const ::rtl::OUString& value ); 313 virtual ::rtl::OUString _explainInvalid( sal_uInt16 nReason ); 314 virtual bool checkPropertySanity( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rNewValue, ::rtl::OUString& _rErrorMessage ); 315 virtual void registerProperties(); 316 }; 317 318 //==================================================================== 319 //= ODecimalType 320 //==================================================================== 321 class ODecimalType; 322 typedef ODerivedDataType< ODecimalType, OValueLimitedType< double > > ODecimalType_Base; 323 class ODecimalType : public ODecimalType_Base 324 { 325 protected: 326 ::com::sun::star::uno::Any m_aTotalDigits; 327 ::com::sun::star::uno::Any m_aFractionDigits; 328 329 public: 330 ODecimalType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass /* = ::com::sun::star::xsd::DataTypeClass::DECIMAL */ ); 331 332 protected: 333 DECLARE_DEFAULT_CLONING( ODecimalType ) 334 335 // OXSDDataType overridables 336 virtual sal_uInt16 _validate( const ::rtl::OUString& value ); 337 virtual ::rtl::OUString _explainInvalid( sal_uInt16 nReason ); 338 virtual void registerProperties(); 339 340 // OValueLimitedType overridables 341 virtual ::rtl::OUString typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const; 342 virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const; 343 344 private: 345 using ODecimalType_Base::initializeTypedClone; 346 }; 347 348 //==================================================================== 349 //= 350 //==================================================================== 351 #define DEFAULT_DECLARE_SUBTYPE( classname, valuetype ) \ 352 class classname; \ 353 typedef ODerivedDataType< classname, OValueLimitedType< valuetype > > classname##_Base; \ 354 class classname : public classname##_Base \ 355 { \ 356 public: \ 357 classname( const ::rtl::OUString& _rName ); \ 358 \ 359 protected: \ 360 DECLARE_DEFAULT_CLONING( classname ) \ 361 \ 362 /* OXSDDataType overridables */ \ 363 virtual sal_uInt16 _validate( const ::rtl::OUString& value ); \ 364 virtual bool _getValue( const ::rtl::OUString& value, double& fValue ); \ 365 \ 366 /* OValueLimitedType overridables */ \ 367 virtual ::rtl::OUString typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const; \ 368 virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const; \ 369 \ 370 private: \ 371 using classname##_Base::initializeTypedClone; \ 372 }; 373 374 //==================================================================== 375 //= ODateType 376 //==================================================================== 377 DEFAULT_DECLARE_SUBTYPE( ODateType, ::com::sun::star::util::Date ) 378 379 //==================================================================== 380 //= OTimeType 381 //==================================================================== 382 DEFAULT_DECLARE_SUBTYPE( OTimeType, ::com::sun::star::util::Time ) 383 384 //==================================================================== 385 //= ODateTimeType 386 //==================================================================== 387 DEFAULT_DECLARE_SUBTYPE( ODateTimeType, ::com::sun::star::util::DateTime ) 388 389 //==================================================================== 390 //= OShortIntegerType 391 //==================================================================== 392 class OShortIntegerType; 393 typedef ODerivedDataType< OShortIntegerType, OValueLimitedType< sal_Int16 > > OShortIntegerType_Base; 394 class OShortIntegerType : public OShortIntegerType_Base 395 { 396 public: 397 OShortIntegerType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass ); 398 399 protected: 400 DECLARE_DEFAULT_CLONING( OShortIntegerType ) 401 402 // OXSDDataType overridables 403 virtual bool _getValue( const ::rtl::OUString& value, double& fValue ); 404 405 // OValueLimitedType overridables 406 virtual ::rtl::OUString typedValueAsHumanReadableString( const ::com::sun::star::uno::Any& _rValue ) const; 407 virtual void normalizeValue( const ::com::sun::star::uno::Any& _rValue, double& _rDoubleValue ) const; 408 409 private: 410 using OShortIntegerType_Base::initializeTypedClone; 411 }; 412 413 //........................................................................ 414 } // namespace xforms 415 //........................................................................ 416 417 #endif // FORMS_SOURCE_XFORMS_DATATYPES_HXX 418