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