LibreOffice Module forms (master) 1
datatypes.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <com/sun/star/beans/PropertyAttribute.hpp>
23#include <com/sun/star/util/Date.hpp>
24#include <com/sun/star/util/Time.hpp>
25#include <com/sun/star/util/DateTime.hpp>
26#include <com/sun/star/xsd/XDataType.hpp>
28#include <comphelper/uno3.hxx>
32#include <rtl/ref.hxx>
33#include <unotools/resmgr.hxx>
34
35#include <unicode/regex.h>
36
37#include <memory>
38
39#include <com/sun/star/util/URLTransformer.hpp>
40
41
42namespace xforms
43{
44
45
46 //= OXSDDataType
47
48 typedef ::cppu::WeakImplHelper < css::xsd::XDataType
52
54 ,public OXSDDataType_BBase // order matters: OMutexAndBroadcastHelper before
55 ,public OXSDDataType_PBase // OPropertyContainer
56 {
57 private:
58 // <properties>
60 sal_Int16 m_nTypeClass;
61 OUString m_sName;
62 OUString m_sPattern;
63 sal_uInt16 m_nWST;
64 // </properties>
65
66 ::std::unique_ptr< U_NAMESPACE_QUALIFIER RegexMatcher >
69
70 protected:
71 sal_Int16 getTypeClass() const { return m_nTypeClass; }
72
73 private:
74 OXSDDataType( const OXSDDataType& ) = delete;
75 OXSDDataType& operator=( const OXSDDataType& ) = delete;
76
77 protected:
78 // create basic data type
79 OXSDDataType( OUString _aName, sal_Int16 _nTypeClass );
80 virtual ~OXSDDataType() override;
81
82 public:
84 DECLARE_XTYPEPROVIDER()
85
86 virtual OUString SAL_CALL getName( ) override;
87 virtual void SAL_CALL setName( const OUString& aName ) override;
88 virtual OUString SAL_CALL getPattern() override;
89 virtual void SAL_CALL setPattern( const OUString& _pattern ) override;
90 virtual sal_Int16 SAL_CALL getWhiteSpaceTreatment() override;
91 virtual void SAL_CALL setWhiteSpaceTreatment( sal_Int16 _whitespacetreatment ) override;
92 virtual sal_Bool SAL_CALL getIsBasic() override;
93 virtual sal_Int16 SAL_CALL getTypeClass() override;
94
95 virtual sal_Bool SAL_CALL validate( const OUString& value ) override;
96 virtual OUString SAL_CALL explainInvalid( const OUString& value ) override;
97
98 // XPropertySet - is a base of XDataType and needs to be disambiguated
99 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
100 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
101 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
102 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
103 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
104 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
105
106 public:
107 rtl::Reference<OXSDDataType> clone( const OUString& _rNewName ) const;
108
109 protected:
110 // XPropertySet and friends
111 virtual sal_Bool SAL_CALL convertFastPropertyValue( css::uno::Any& _rConvertedValue, css::uno::Any& _rOldValue, sal_Int32 _nHandle, const css::uno::Any& _rValue ) override;
112 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
113 sal_Int32 nHandle,
114 const css::uno::Any& rValue
115 ) override;
116
117 // --- own overridables ---
118 // helper for implementing cloning of data types
119 virtual rtl::Reference<OXSDDataType> createClone( const OUString& _rName ) const = 0;
120 virtual void initializeClone( const OXSDDataType& _rCloneSource );
121
122 // helper method for validate and explainInvalid
123 virtual TranslateId _validate( const OUString& value );
124 virtual OUString _explainInvalid( TranslateId rReason );
125
126 // helper method for checking properties values which are to be set
127 virtual bool checkPropertySanity( sal_Int32 _nHandle, const css::uno::Any& _rNewValue, OUString& _rErrorMessage );
128
129 // register properties implemented by this instance - call the base class when overriding
130 virtual void registerProperties();
131 };
132
133
134 //= helper for deriving from OXSDDataType
135
137 {
138 protected:
139 css::uno::Any m_aMaxInclusive;
140 css::uno::Any m_aMaxExclusive;
141 css::uno::Any m_aMinInclusive;
142 css::uno::Any m_aMinExclusive;
143
148
149 protected:
150 OValueLimitedType_Base( const OUString& _rName, sal_Int16 _nTypeClass );
151
152 virtual void initializeClone( const OXSDDataType& _rCloneSource ) override;
153 void initializeTypedClone( const OValueLimitedType_Base& _rCloneSource );
154
155 // XPropertySet and friends
156 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
157 sal_Int32 nHandle,
158 const css::uno::Any& rValue
159 ) override;
160
161 // OXSDDataType overridables
162 virtual bool _getValue( const OUString& value, double& fValue );
163 virtual TranslateId _validate( const OUString& value ) override;
164 virtual OUString _explainInvalid( TranslateId rReason ) override;
165
166 // own overridables
171 virtual OUString typedValueAsHumanReadableString( const css::uno::Any& _rValue ) const = 0;
172
185 virtual void normalizeValue( const css::uno::Any& _rValue, double& _rDoubleValue ) const = 0;
186 };
187
188 template < typename VALUE_TYPE >
190 {
191 protected:
192 typedef VALUE_TYPE ValueType;
193 const css::uno::Type&
195
196 protected:
197 OValueLimitedType( const OUString& _rName, sal_Int16 _nTypeClass );
198
199 // OXSDDataType overridables
200 virtual void registerProperties() override;
201 };
202
205 template< typename CONCRETE_DATA_TYPE_IMPL, typename SUPERCLASS = OXSDDataType >
206 class ODerivedDataType :public SUPERCLASS
207 ,public ::comphelper::OPropertyArrayUsageHelper< CONCRETE_DATA_TYPE_IMPL >
208 {
209 private:
211
212 protected:
213 ODerivedDataType( const OUString& _rName, sal_Int16 _nTypeClass );
214
215 protected:
216 // OPropertyArrayUsageHelper
217 virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override;
218
219 // XPropertySet
220 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
221 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
222 };
223
224 class OBooleanType;
227 {
228 public:
229 explicit OBooleanType( const OUString& _rName );
230
231 protected:
232 virtual rtl::Reference<OXSDDataType> createClone(const OUString& _rName) const override;
233 virtual void initializeClone(const OXSDDataType& _rCloneSource) override;
234
235 // OXSDDataType overridables
236 virtual TranslateId _validate( const OUString& value ) override;
237 virtual OUString _explainInvalid( TranslateId rReason ) override;
238 };
239
240 class OStringType;
243 {
244 // <properties>
245 css::uno::Any m_aLength;
246 css::uno::Any m_aMinLength;
247 css::uno::Any m_aMaxLength;
248 // </properties>
249
250 public:
251 OStringType( const OUString& _rName, sal_Int16 _nTypeClass /* = css::xsd::DataTypeClass::STRING */ );
252
253 protected:
254 virtual rtl::Reference<OXSDDataType> createClone(const OUString& _rName) const override;
255 virtual void initializeClone(const OXSDDataType& _rCloneSource) override;
256 void initializeTypedClone( const OStringType& _rCloneSource );
257
258 // OXSDDataType overridables
259 virtual TranslateId _validate( const OUString& value ) override;
260 virtual OUString _explainInvalid( TranslateId rReason ) override;
261 virtual bool checkPropertySanity( sal_Int32 _nHandle, const css::uno::Any& _rNewValue, OUString& _rErrorMessage ) override;
262 virtual void registerProperties() override;
263 };
264
265 class OAnyURIType;
268 {
269 // <properties>
270 css::uno::Any m_aLength;
271 css::uno::Any m_aMinLength;
272 css::uno::Any m_aMaxLength;
273 // </properties>
274 // helper to check URL validity
275 css::uno::Reference<css::util::XURLTransformer> m_xURLTransformer;
276
277 public:
278 OAnyURIType( const OUString& _rName, sal_Int16 _nTypeClass /* = css::xsd::DataTypeClass::anyURI */ );
279
280 protected:
281 virtual rtl::Reference<OXSDDataType> createClone(const OUString& _rName) const override;
282 virtual void initializeClone(const OXSDDataType& _rCloneSource) override;
283 void initializeTypedClone( const OAnyURIType& _rCloneSource );
284
285 // OXSDDataType overridables
286 virtual TranslateId _validate( const OUString& value ) override;
287 virtual OUString _explainInvalid( TranslateId rReason ) override;
288 virtual bool checkPropertySanity( sal_Int32 _nHandle, const css::uno::Any& _rNewValue, OUString& _rErrorMessage ) override;
289 virtual void registerProperties() override;
290 };
291
292 class ODecimalType;
295 {
296 css::uno::Any m_aTotalDigits;
297 css::uno::Any m_aFractionDigits;
298
299 public:
300 ODecimalType( const OUString& _rName, sal_Int16 _nTypeClass /* = css::xsd::DataTypeClass::DECIMAL */ );
301
302 protected:
303 virtual rtl::Reference<OXSDDataType> createClone(const OUString& _rName) const override;
304 virtual void initializeClone(const OXSDDataType& _rCloneSource) override;
305 void initializeTypedClone( const ODecimalType& _rCloneSource );
306
307 // OXSDDataType overridables
308 virtual TranslateId _validate( const OUString& value ) override;
309 virtual OUString _explainInvalid( TranslateId rReason ) override;
310 virtual void registerProperties() override;
311
312 // OValueLimitedType overridables
313 virtual OUString typedValueAsHumanReadableString( const css::uno::Any& _rValue ) const override;
314 virtual void normalizeValue( const css::uno::Any& _rValue, double& _rDoubleValue ) const override;
315
316 private:
317 using ODecimalType_Base::initializeTypedClone;
318 };
319
320
321 //=
322
323 class ODateType;
326 {
327 public:
328 explicit ODateType( const OUString& _rName );
329
330 protected:
331 virtual rtl::Reference<OXSDDataType> createClone(const OUString& _rName) const override;
332 virtual void initializeClone(const OXSDDataType& _rCloneSource) override;
333
334 /* OXSDDataType overridables */
335 virtual TranslateId _validate( const OUString& value ) override;
336 virtual bool _getValue( const OUString& value, double& fValue ) override;
337
338 /* OValueLimitedType overridables */
339 virtual OUString typedValueAsHumanReadableString( const css::uno::Any& _rValue ) const override;
340 virtual void normalizeValue( const css::uno::Any& _rValue, double& _rDoubleValue ) const override;
341
342 private:
343 using ODateType_Base::initializeTypedClone;
344 };
345
346
347 class OTimeType;
350 {
351 public:
352 explicit OTimeType( const OUString& _rName );
353
354 protected:
355 virtual rtl::Reference<OXSDDataType> createClone(const OUString& _rName) const override;
356 virtual void initializeClone(const OXSDDataType& _rCloneSource) override;
357
358 /* OXSDDataType overridables */
359 virtual TranslateId _validate( const OUString& value ) override;
360 virtual bool _getValue( const OUString& value, double& fValue ) override;
361
362 /* OValueLimitedType overridables */
363 virtual OUString typedValueAsHumanReadableString( const css::uno::Any& _rValue ) const override;
364 virtual void normalizeValue( const css::uno::Any& _rValue, double& _rDoubleValue ) const override;
365
366 private:
367 using OTimeType_Base::initializeTypedClone;
368 };
369
370
371
372 class ODateTimeType;
375 {
376 public:
377 explicit ODateTimeType( const OUString& _rName );
378
379 protected:
380 virtual rtl::Reference<OXSDDataType> createClone(const OUString& _rName) const override;
381 virtual void initializeClone(const OXSDDataType& _rCloneSource) override;
382
383 /* OXSDDataType overridables */
384 virtual TranslateId _validate( const OUString& value ) override;
385 virtual bool _getValue( const OUString& value, double& fValue ) override;
386
387 /* OValueLimitedType overridables */
388 virtual OUString typedValueAsHumanReadableString( const css::uno::Any& _rValue ) const override;
389 virtual void normalizeValue( const css::uno::Any& _rValue, double& _rDoubleValue ) const override;
390
391 private:
392 using ODateTimeType_Base::initializeTypedClone;
393 };
394
395
396 class OShortIntegerType;
399 {
400 public:
401 OShortIntegerType( const OUString& _rName, sal_Int16 _nTypeClass );
402
403 protected:
404 virtual rtl::Reference<OXSDDataType> createClone(const OUString& _rName) const override;
405 virtual void initializeClone(const OXSDDataType& _rCloneSource) override;
406
407 // OXSDDataType overridables
408 virtual bool _getValue( const OUString& value, double& fValue ) override;
409
410 // OValueLimitedType overridables
411 virtual OUString typedValueAsHumanReadableString( const css::uno::Any& _rValue ) const override;
412 virtual void normalizeValue( const css::uno::Any& _rValue, double& _rDoubleValue ) const override;
413
414 private:
415 using OShortIntegerType_Base::initializeTypedClone;
416 };
417
418
419} // namespace xforms
420
421
422/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Type const & get()
css::uno::Any m_aLength
Definition: datatypes.hxx:270
css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer
Definition: datatypes.hxx:275
css::uno::Any m_aMinLength
Definition: datatypes.hxx:271
css::uno::Any m_aMaxLength
Definition: datatypes.hxx:272
css::uno::Any m_aFractionDigits
Definition: datatypes.hxx:297
css::uno::Any m_aTotalDigits
Definition: datatypes.hxx:296
helper class for implementing interfaces derived from XDataType
Definition: datatypes.hxx:208
css::uno::Any m_aLength
Definition: datatypes.hxx:245
css::uno::Any m_aMinLength
Definition: datatypes.hxx:246
css::uno::Any m_aMaxLength
Definition: datatypes.hxx:247
virtual void normalizeValue(const css::uno::Any &_rValue, double &_rDoubleValue) const =0
translates a <member>ValueType</member> value into a double value
virtual OUString typedValueAsHumanReadableString(const css::uno::Any &_rValue) const =0
translate a given value into a human-readable string
const css::uno::Type & getCppuType() const
Definition: datatypes.hxx:194
virtual void registerProperties() override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: datatypes.cxx:290
rtl::Reference< OXSDDataType > clone(const OUString &_rNewName) const
Definition: datatypes.cxx:94
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: datatypes.cxx:296
virtual sal_Bool SAL_CALL getIsBasic() override
Definition: datatypes.cxx:147
virtual TranslateId _validate(const OUString &value)
Definition: datatypes.cxx:215
sal_Int16 getTypeClass() const
Definition: datatypes.hxx:71
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: datatypes.cxx:256
virtual OUString SAL_CALL explainInvalid(const OUString &value) override
Definition: datatypes.cxx:165
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: datatypes.cxx:302
virtual bool checkPropertySanity(sal_Int32 _nHandle, const css::uno::Any &_rNewValue, OUString &_rErrorMessage)
Definition: datatypes.cxx:264
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: datatypes.cxx:314
::std::unique_ptr< U_NAMESPACE_QUALIFIER RegexMatcher > m_pPatternMatcher
Definition: datatypes.hxx:67
OXSDDataType(const OXSDDataType &)=delete
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: datatypes.cxx:308
virtual ~OXSDDataType() override
Definition: datatypes.cxx:69
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &_rConvertedValue, css::uno::Any &_rOldValue, sal_Int32 _nHandle, const css::uno::Any &_rValue) override
Definition: datatypes.cxx:236
virtual OUString SAL_CALL getName() override
Definition: datatypes.cxx:107
virtual void initializeClone(const OXSDDataType &_rCloneSource)
Definition: datatypes.cxx:85
virtual OUString SAL_CALL getPattern() override
Definition: datatypes.cxx:121
virtual OUString _explainInvalid(TranslateId rReason)
Definition: datatypes.cxx:177
virtual sal_Bool SAL_CALL validate(const OUString &value) override
Definition: datatypes.cxx:159
OXSDDataType & operator=(const OXSDDataType &)=delete
virtual rtl::Reference< OXSDDataType > createClone(const OUString &_rName) const =0
virtual sal_Int16 SAL_CALL getWhiteSpaceTreatment() override
Definition: datatypes.cxx:134
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: datatypes.cxx:284
virtual void registerProperties()
Definition: datatypes.cxx:74
virtual void SAL_CALL setPattern(const OUString &_pattern) override
Definition: datatypes.cxx:127
virtual void SAL_CALL setName(const OUString &aName) override
Definition: datatypes.cxx:113
virtual void SAL_CALL setWhiteSpaceTreatment(sal_Int16 _whitespacetreatment) override
Definition: datatypes.cxx:140
sal_Int16 m_nTypeClass
Definition: datatypes.hxx:60
Any value
ODerivedDataType< OShortIntegerType, OValueLimitedType< sal_Int16 > > OShortIntegerType_Base
Definition: datatypes.hxx:396
::comphelper::OMutexAndBroadcastHelper OXSDDataType_BBase
Definition: datatypes.hxx:50
ODerivedDataType< OAnyURIType > OAnyURIType_Base
Definition: datatypes.hxx:265
ODerivedDataType< ODecimalType, OValueLimitedType< double > > ODecimalType_Base
Definition: datatypes.hxx:292
::cppu::WeakImplHelper< css::xsd::XDataType > OXSDDataType_Base
Definition: datatypes.hxx:49
ODerivedDataType< OBooleanType > OBooleanType_Base
Definition: datatypes.hxx:224
::comphelper::OPropertyContainer OXSDDataType_PBase
Definition: datatypes.hxx:51
ODerivedDataType< OStringType > OStringType_Base
Definition: datatypes.hxx:240
ODerivedDataType< OTimeType, OValueLimitedType< css::util::Time > > OTimeType_Base
Definition: datatypes.hxx:347
ODerivedDataType< OTimeType, OValueLimitedType< css::util::DateTime > > ODateTimeType_Base
Definition: datatypes.hxx:372
ODerivedDataType< ODateType, OValueLimitedType< css::util::Date > > ODateType_Base
Definition: datatypes.hxx:323
unsigned char sal_Bool
#define DECLARE_XINTERFACE()