1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYEXPORT_HXX
21 #define INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYEXPORT_HXX
23 #include <sal/config.h>
27 #include "formattributes.hxx"
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/beans/XPropertyState.hpp>
30 #include <xmloff/xmlexp.hxx>
31 #include "callbacks.hxx"
32 #include "strings.hxx"
37 #define BOOLATTR_DEFAULT_FALSE 0x00
38 #define BOOLATTR_DEFAULT_TRUE 0x01
39 #define BOOLATTR_DEFAULT_VOID 0x02
40 #define BOOLATTR_DEFAULT_MASK 0x03
42 #define BOOLATTR_INVERSE_SEMANTICS 0x04
43 // if sal_True, indicates that the semantic of the property referred by <arg>_pPropertyName</arg>
44 // is inverse to the semantic of the XML attribute.<br/>
45 // I.e. if the property value is <TRUE/>, <FALSE/> has to be written and vice versa.
46 // <p>Be careful with <arg>_bDefault</arg> and <arg>_bInverseSemantics</arg>: if <arg>_bInverseSemantics</arg>
47 // is <TRUE/>, the current property value is inverted <em>before</em> comparing it to the default.</p>
49 class IFormsExportContext
;
51 /** provides export related tools for attribute handling
53 <p>(The name is somewhat misleading. It's not only a PropertyExport, but in real a ElementExport.
59 typedef std::set
<OUString
> StringSet
;
60 StringSet m_aRemainingProps
;
61 // see examinePersistence
63 void exportRelativeTargetLocation(const OUString
& _sPropertyName
,sal_Int32 _nProperty
,bool _bAddType
);
66 IFormsExportContext
& m_rContext
;
68 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>
70 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
>
72 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyState
>
76 OUString m_sValueTrue
;
77 OUString m_sValueFalse
;
80 /** constructs an object capable of handling attributes for export
82 the export context to which's attribute list the property translation should be added
84 the property set to be exported
86 OPropertyExport(IFormsExportContext
& _rContext
,
87 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxProps
);
90 /** examines a property set given for all properties which's value are to made persistent
92 <p>upon return the <method>m_aRemainingProps</method> will be filled with the names of all properties
93 which need to be stored</p>
95 void examinePersistence();
97 template< typename T
> void exportRemainingPropertiesSequence(
98 com::sun::star::uno::Any
const & value
,
99 token::XMLTokenEnum eValueAttName
);
101 void exportRemainingProperties();
103 /** indicates that a property has been handled by a derived class, without using the helper methods of this
106 <p>Calling this method is necessary in case you use the suggested mechanism for the generic export of
107 properties. This means that you want to use <method>exportRemainingProperties</method>, which exports
108 all properties which need to ('cause they haven't been exported with one of the other type-specific
111 <p>In this case you should call exportedProperty for every property you export yourself, so the property
112 will be flagged as <em>already handled</em></p>
114 void exportedProperty(const OUString
& _rPropertyName
)
115 { m_aRemainingProps
.erase(_rPropertyName
); }
117 /** add an attribute which is represented by a string property to the export context
119 @param _nNamespaceKey
120 the key of the namespace to use for the attribute name. Is used with the namespace map
121 provided by the export context.
122 @param _pAttributeName
123 the name of the attribute to add. Must not contain any namespace
124 @param _pPropertyName
125 the name of the property to ask the control for
127 void exportStringPropertyAttribute(
128 const sal_uInt16 _nNamespaceKey
,
129 const sal_Char
* _pAttributeName
,
130 const OUString
& _rPropertyName
133 /** add an attribute which is represented by a boolean property to the export context
135 @param _nNamespaceKey
136 the key of the namespace to use for the attribute name. Is used with the namespace map
137 provided by the export context.
138 @param _pAttributeName
139 the name of the attribute to add. Must not contain any namespace (it's added automatically)
140 @param _pPropertyName
141 the name of the property to ask the control for
142 @param _nBooleanAttributeFlags
143 specifies the default and the "alignment" (inverse semantics) of the boolean property
145 void exportBooleanPropertyAttribute(
146 const sal_uInt16 _nNamespaceKey
,
147 const sal_Char
* _pAttributeName
,
148 const OUString
& _rPropertyName
,
149 const sal_Int8 _nBooleanAttributeFlags
);
151 /** add an attribute which is represented by a sal_Int16 property to the export context
153 @param _nNamespaceKey
154 the key of the namespace to use for the attribute name. Is used with the namespace map
155 provided by the export context.
156 @param _pAttributeName
157 the name of the attribute to add. Must not contain any namespace (it's added automatically)
158 @param _pPropertyName
159 the name of the property to ask the control for
161 the default of the attribute. See force parameter.
163 if true and the property is not set or does not contain a sal_Int16,
164 then _nDefault is written out.
165 if false and the current property value equals _nDefault,
166 then no attribute is added.
168 void exportInt16PropertyAttribute(
169 const sal_uInt16 _nNamespaceKey
,
170 const sal_Char
* _pAttributeName
,
171 const OUString
& _rPropertyName
,
172 const sal_Int16 _nDefault
,
173 const bool force
= false);
175 /** add an attribute which is represented by a sal_Int32 property to the export context
177 @param _nNamespaceKey
178 the key of the namespace to use for the attribute name. Is used with the namespace map
179 provided by the export context.
180 @param _pAttributeName
181 the name of the attribute to add. Must not contain any namespace (it's added automatically)
182 @param _pPropertyName
183 the name of the property to ask the control for
185 the default of the attribute. If the current property value equals this default, no
188 void exportInt32PropertyAttribute(
189 const sal_uInt16 _nNamespaceKey
,
190 const sal_Char
* _pAttributeName
,
191 const OUString
& _rPropertyName
,
192 const sal_Int32 _nDefault
);
194 /** add an attribute which is represented by a enum property to the export context
196 @param _nNamespaceKey
197 the key of the namespace to use for the attribute name. Is used with the namespace map
198 provided by the export context.
199 @param _pAttributeName
200 the name of the attribute to add. Must not contain any namespace (it's added automatically)
201 @param _pPropertyName
202 the name of the property to ask the control for
204 the map to use when converting the property value to an attribute value
206 the default of the attribute. If the current property value equals this default, no
209 void exportEnumPropertyAttribute(
210 const sal_uInt16 _nNamespaceKey
,
211 const sal_Char
* _pAttributeName
,
212 const OUString
& _rPropertyName
,
213 const SvXMLEnumMapEntry
* _pValueMap
,
214 const sal_Int32 _nDefault
,
215 const bool _bVoidDefault
= false);
217 // some very special methods for some very special attribute/property pairs
219 /** add the hlink:target-frame attribute to the export context.
221 <p>The value of this attribute is extracted from the TargetFrame property of the object given.</p>
223 <p>The property needs a special handling because conflicts between the default values for the attribute
224 and the property.</p>
226 void exportTargetFrameAttribute();
228 /** add the form:href attribute to the export context.
230 <p>The value of this attribute is extracted from the TargetURL property of the object given.</p>
232 <p>The property needs a special handling because the URL's need to be made relative</p>
234 <p>If _bAddType is set, an additional xlink:type="simple" attribute is also added.</p>
236 inline void exportTargetLocationAttribute(bool _bAddType
) { exportRelativeTargetLocation(PROPERTY_TARGETURL
,CCA_TARGET_LOCATION
,_bAddType
); }
238 /** add the form:image attribute to the export context.
240 <p>The value of this attribute is extracted from the ImageURL property of the object given.</p>
242 <p>The property needs a special handling because the URL's need to be made relative</p>
244 inline void exportImageDataAttribute() { exportRelativeTargetLocation(PROPERTY_IMAGEURL
,CCA_IMAGE_DATA
,false); }
246 /** flag the style properties as 'already exported'
248 <p>We don't have style support right now, so the only thing the method does is removing the style-relevant
249 properties from the list of yet-to-be-exported properties (<member>m_aRemainingProps</member>)</p>
251 void flagStyleProperties();
253 /** add an arbitrary attribute extracted from an arbitrary property to the export context
255 <p>The current value of the property specified with <arg>_pPropertyName</arg> is taken and converted
256 into a string, no matter what type it has. (Okay, there are the usual limitations: We know Date, Datetime,
257 double, integer ... to name just a few).</p>
259 <p>In case the property value is <NULL/> (void), no attribute is added</p>
261 <p>In case the property value is an empty string, and the property is a not allowed to be <NULL/> (void),
262 no attribute is added</p>
264 <p>In case the property value is a sequence of any type, no attribute is added, 'cause sequences can't be
265 transported as attribute. In the debug version, an additional assertion will occur if you nonetheless try
268 @param _nNamespaceKey
269 the key of the namespace to use for the attribute name. Is used with the namespace map
270 provided by the export context.
271 @param _pAttributeName
272 the name of the attribute to add. Must not contain any namespace (it's added automatically)
273 @param _pPropertyName
274 the name of the property to ask the object for
276 void exportGenericPropertyAttribute(
277 const sal_uInt16 _nAttributeNamespaceKey
,
278 const sal_Char
* _pAttributeName
,
279 const sal_Char
* _pPropertyName
);
281 /** exports a property value, which is a string sequence, as attribute
283 <p>The elements of the string sequence given are quoted and concatenated, with the characters used for
284 this to be chosen by the caller</p>
286 <p>If you use the quote character, no check (except assertions) is made if one of the list items
287 contains the quote character</p>
289 <p>If you don't use the quote character, no check (except assertions) is made if one of the list items
290 contains the separator character (which would be deadly when reimporting the string)</p>
292 @param _nNamespaceKey
293 the key of the namespace to use for the attribute name. Is used with the namespace map
294 provided by the export context.
295 @param _pAttributeName
296 the name of the attribute to add. Must not contain any namespace (it's added automatically)
297 @param _pPropertyName
298 the name of the property to ask the object for
299 @param _aQuoteCharacter
300 the character to use to quote the sequence elements with. May be 0, in this case no quoting happens
301 @param _aListSeparator
302 the character to use to separate the list entries
304 void exportStringSequenceAttribute(
305 const sal_uInt16 _nAttributeNamespaceKey
,
306 const sal_Char
* _pAttributeName
,
307 const OUString
& _rPropertyName
,
308 const sal_Unicode _aQuoteCharacter
= '"',
309 const sal_Unicode _aListSeparator
= ',');
311 /** determines whether the given property is to be exported
313 <p>Currently, the method simply checks whether the property's state is <em>not</em> PropertyState.DEFAULT,
314 or whether the property is a dynamic property (i.e. added via an <code>XPropertyContainer</code>).
315 So, take care when using the method - the heuristics is not applicable for all properties.</p>
317 bool shouldExportProperty( const OUString
& i_propertyName
) const;
319 /** tries to convert an arbitrary <type scope="com.sun:star.uno">Any</type> into an string
321 <p>If the type contained in the Any is not supported, the returned string will be empty. In the
322 debug version, an additional assertion occurs.</p>
327 OUString
implConvertAny(
328 const ::com::sun::star::uno::Any
& _rValue
);
332 token which can be used in the <code>form:property</code> element's <code>type</code> attribute
333 to describe the type of a value.<br/>
334 Possible types returned are
336 <li><b>boolean</b>: <arg>_rValue</arg> was interpreted as boolean value before converting
337 it into a string</li>
338 <li><b>float</b>: <arg>_rValue</arg> was interpreted as 64 bit floating point 16bit integer, 32bit integer or 64 bit integer value before
339 converting it into a string</li>
340 <li><b>string</b>: <arg>_rValue</arg> did not need any conversion as it already was a string</li>
342 If the type is not convertible, float is returned
344 static ::xmloff::token::XMLTokenEnum
implGetPropertyXMLType(const ::com::sun::star::uno::Type
& _rType
);
347 void AddAttribute(sal_uInt16 _nPrefix
, const sal_Char
* _pName
, const OUString
& _rValue
);
348 void AddAttribute( sal_uInt16 _nPrefix
, const OUString
& _rName
, const OUString
& _rValue
);
349 void AddAttributeASCII( sal_uInt16 nPrefix
, const sal_Char
*pName
, const sal_Char
*pValue
);
350 void AddAttribute(sal_uInt16 _nPrefix
, ::xmloff::token::XMLTokenEnum _eName
, const OUString
& _rValue
);
351 void AddAttribute(sal_uInt16 _nPrefix
, ::xmloff::token::XMLTokenEnum _eName
, ::xmloff::token::XMLTokenEnum _eValue
);
353 // in the product version, inline this, so it does not cost us extra time calling into our method
354 inline void AddAttribute(sal_uInt16 _nPrefix
, const sal_Char
* _pName
, const OUString
& _rValue
)
355 { m_rContext
.getGlobalContext().AddAttribute(_nPrefix
, _pName
, _rValue
); }
356 inline void AddAttribute( sal_uInt16 _nPrefix
, const OUString
& _rName
, const OUString
& _rValue
)
357 { m_rContext
.getGlobalContext().AddAttribute( _nPrefix
, _rName
, _rValue
); }
358 inline void AddAttributeASCII( sal_uInt16 _nPrefix
, const sal_Char
* _pName
, const sal_Char
*pValue
)
359 { m_rContext
.getGlobalContext().AddAttributeASCII(_nPrefix
, _pName
, pValue
); }
360 inline void AddAttribute(sal_uInt16 _nPrefix
, ::xmloff::token::XMLTokenEnum _eName
, const OUString
& _rValue
)
361 { m_rContext
.getGlobalContext().AddAttribute(_nPrefix
, _eName
, _rValue
); }
362 inline void AddAttribute(sal_uInt16 _nPrefix
, ::xmloff::token::XMLTokenEnum _eName
, ::xmloff::token::XMLTokenEnum _eValue
)
363 { m_rContext
.getGlobalContext().AddAttribute(_nPrefix
, _eName
, _eValue
); }
368 /** check a given property set for the existence and type correctness of a given property
370 <p>This method is available in the non-product version only.</p>
372 @param _rPropertyName
373 the name of the property to ask the control model for
375 the expected type of the property. May be NULL, in this case no type check is made.
376 @return sal_True, if the property exists and is of the correct type
378 void dbg_implCheckProperty(
379 const OUString
& _rPropertyName
,
380 const ::com::sun::star::uno::Type
* _pType
);
382 // void dbg_implCheckProperty(
383 // const sal_Char* _rPropertyName,
384 // const ::com::sun::star::uno::Type* _pType)
386 // dbg_implCheckProperty(OUString::createFromAscii(_rPropertyName), _pType);
393 #define DBG_CHECK_PROPERTY(name, type) \
394 dbg_implCheckProperty(name, &cppu::UnoType<type>::get())
396 #define DBG_CHECK_PROPERTY_NO_TYPE(name) \
397 dbg_implCheckProperty(name, NULL)
399 #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name ) \
400 dbg_implCheckProperty( OUString::createFromAscii( name ), NULL )
402 #define DBG_CHECK_PROPERTY(name, type)
403 #define DBG_CHECK_PROPERTY_NO_TYPE(name)
404 #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name )
407 } // namespace xmloff
409 #endif // INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYEXPORT_HXX
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */