bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / inc / txtflde.hxx
blob9cb74a7d963b74e09f2fab23f20f3c742b605f8f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 /** @#file
21 * XML export of all text fields
24 #ifndef INCLUDED_XMLOFF_INC_TXTFLDE_HXX
25 #define INCLUDED_XMLOFF_INC_TXTFLDE_HXX
27 #include <com/sun/star/uno/Reference.h>
28 #include <xmloff/xmlnmspe.hxx>
30 #include <rtl/ustring.hxx>
31 #include <xmloff/xmltoken.hxx>
33 #include <map>
34 #include <set>
37 class SvXMLExport;
38 struct XMLPropertyState;
40 namespace com { namespace sun { namespace star {
41 namespace util { struct DateTime; }
42 namespace util { struct Date; }
43 namespace text { class XTextField; }
44 namespace text { class XText; }
45 namespace beans { class XPropertySet; }
46 namespace beans { class XPropertySetInfo; }
47 namespace frame { class XModel; }
48 namespace uno { template<typename A> class Sequence; }
49 } } }
52 /// field IDs,
53 // including translation between UNO speak and XML speak if appropriate
55 enum FieldIdEnum {
56 FIELD_ID_SENDER, // sender == extended user
57 FIELD_ID_AUTHOR,
58 FIELD_ID_DATE, // current date
59 FIELD_ID_TIME, // current time (+date)
60 FIELD_ID_PAGENAME, // page/slide name
61 FIELD_ID_PAGENUMBER, // page number
62 FIELD_ID_PAGESTRING, // page contination string (page number string)
63 FIELD_ID_REFPAGE_SET, // set reference page
64 FIELD_ID_REFPAGE_GET, // get reference page number
66 FIELD_ID_PLACEHOLDER, // placeholder field == jump edit field
68 FIELD_ID_VARIABLE_DECL, // field type for set variable
69 FIELD_ID_VARIABLE_GET, // get variable == get expression
70 FIELD_ID_VARIABLE_SET, // set variable == set expression
71 FIELD_ID_VARIABLE_INPUT, // input field (variable)
72 FIELD_ID_USER_DECL, // field type for user field
73 FIELD_ID_USER_GET, // user field
74 FIELD_ID_USER_INPUT, // input field (user field)
75 FIELD_ID_TEXT_INPUT, // input field (text)
76 FIELD_ID_EXPRESSION, // expression field = formula field
77 FIELD_ID_SEQUENCE_DECL, // field type for sequence
78 FIELD_ID_SEQUENCE, // sequence field
80 FIELD_ID_DATABASE_NEXT, // select next row
81 FIELD_ID_DATABASE_SELECT, // select row # (NumSet)
82 FIELD_ID_DATABASE_DISPLAY, // display data (form letter field)
83 FIELD_ID_DATABASE_NAME, // display current db name (database name)
84 FIELD_ID_DATABASE_NUMBER, // display row # (SetNumber)
86 FIELD_ID_DOCINFO_CREATION_AUTHOR, // docinfo fields
87 FIELD_ID_DOCINFO_CREATION_TIME,
88 FIELD_ID_DOCINFO_CREATION_DATE,
89 FIELD_ID_DOCINFO_DESCRIPTION,
90 FIELD_ID_DOCINFO_CUSTOM,
91 FIELD_ID_DOCINFO_PRINT_TIME,
92 FIELD_ID_DOCINFO_PRINT_DATE,
93 FIELD_ID_DOCINFO_PRINT_AUTHOR,
94 FIELD_ID_DOCINFO_TITLE,
95 FIELD_ID_DOCINFO_SUBJECT,
96 FIELD_ID_DOCINFO_KEYWORDS,
97 FIELD_ID_DOCINFO_REVISION,
98 FIELD_ID_DOCINFO_EDIT_DURATION,
99 FIELD_ID_DOCINFO_SAVE_TIME,
100 FIELD_ID_DOCINFO_SAVE_DATE,
101 FIELD_ID_DOCINFO_SAVE_AUTHOR,
103 FIELD_ID_CONDITIONAL_TEXT, // conditionally choose between 2 texts
104 FIELD_ID_HIDDEN_TEXT, // conditionally hide a text
105 FIELD_ID_HIDDEN_PARAGRAPH, // conditionally hide a paragraph
107 FIELD_ID_TEMPLATE_NAME, // display name of template
108 FIELD_ID_CHAPTER, // display name/number of current chapter
109 FIELD_ID_FILE_NAME, // display name of current file
111 FIELD_ID_COUNT_PARAGRAPHS, // statistics fields: - paragraphs
112 FIELD_ID_COUNT_WORDS, // - words
113 FIELD_ID_COUNT_CHARACTERS, // - chars
114 FIELD_ID_COUNT_PAGES, // - pages
115 FIELD_ID_COUNT_TABLES, // - tables
116 FIELD_ID_COUNT_GRAPHICS, // - graphics
117 FIELD_ID_COUNT_OBJECTS, // - objects
119 FIELD_ID_MACRO, // macro fields
120 FIELD_ID_REF_REFERENCE, // get reference field (reference)
121 FIELD_ID_REF_SEQUENCE, // get reference field (sequence)
122 FIELD_ID_REF_BOOKMARK, // get reference field (bookmark)
123 FIELD_ID_REF_FOOTNOTE, // get reference field (footnote)
124 FIELD_ID_REF_ENDNOTE, // get reference field (endnote)
125 FIELD_ID_DDE, // DDE field
127 FIELD_ID_BIBLIOGRAPHY, // bibliography index entry
129 FIELD_ID_SHEET_NAME, // name of current (spread-)sheet
130 FIELD_ID_URL, // URL field (only Calc, Draw, Impress)
132 FIELD_ID_SCRIPT, // script fields (for HTML pages, mostly)
133 FIELD_ID_ANNOTATION, // annotation (notice) field
135 FIELD_ID_COMBINED_CHARACTERS, // combined characters (asian typography)
137 FIELD_ID_META, // text:meta-field (RDF metadata)
139 FIELD_ID_MEASURE, // for measure shapes
141 FIELD_ID_TABLE_FORMULA, // DEPRECATED: table formulas (Writer 2.0)
142 FIELD_ID_DROP_DOWN, // DEPRECATED: dropdown fields (WW8)
144 FIELD_ID_DRAW_HEADER,
145 FIELD_ID_DRAW_FOOTER,
146 FIELD_ID_DRAW_DATE_TIME,
148 FIELD_ID_UNKNOWN // invalid or unknown field type!
153 class XMLTextFieldExport
155 SvXMLExport& rExport;
157 /// store used text field master names (NULL means: don't collect)
158 ::std::map<
159 ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >,
160 ::std::set< OUString > > *
161 pUsedMasters;
163 public:
165 XMLTextFieldExport( SvXMLExport& rExp,
166 /// XMLPropertyState for the combined characters field
167 XMLPropertyState* pCombinedCharState = NULL );
168 virtual ~XMLTextFieldExport();
170 /// Export this field and the surrounding span element with the formatting.
171 /// To be called for every field in the document body.
172 void ExportField(const ::com::sun::star::uno::Reference <
173 ::com::sun::star::text::XTextField > & rTextField,
174 bool bProgress );
176 /// collect styles (character styles, data styles, ...) for this field
177 /// (if appropriate).
178 /// Also collect used field masters (if pUsedMasters is set)
179 /// to be called for every field during style export.
180 void ExportFieldAutoStyle(const ::com::sun::star::uno::Reference <
181 ::com::sun::star::text::XTextField > & rTextField,
182 const bool bProgress, const bool bRecursive );
184 /// export field declarations.
185 /// to be called once at beginning of document body.
186 void ExportFieldDeclarations();
188 /// export field declarations for fields used in the particular XText.
189 /// (Requires that a list of used field declarations has previously been
190 /// built-up in ExportFieldAutoStyle() )
191 void ExportFieldDeclarations(
192 const ::com::sun::star::uno::Reference <
193 ::com::sun::star::text::XText > & rText);
195 /// export all field declarations, or only those that have been used?
196 /// Calling this method will reset the list of used field declataions.
197 void SetExportOnlyUsedFieldDeclarations(
198 bool bExportOnlyUsed = true);
200 // determine element or attribute names
201 // (public, because they may be useful in related XML export classes)
202 static enum ::xmloff::token::XMLTokenEnum MapPlaceholderType(sal_uInt16 nType);
203 static enum ::xmloff::token::XMLTokenEnum MapTemplateDisplayFormat(sal_Int16 nType);
204 static enum ::xmloff::token::XMLTokenEnum MapChapterDisplayFormat(sal_Int16 nType);
205 static enum ::xmloff::token::XMLTokenEnum MapFilenameDisplayFormat(sal_Int16 nType);
206 static enum ::xmloff::token::XMLTokenEnum MapDocInfoFieldName(enum FieldIdEnum nToken);
207 static enum ::xmloff::token::XMLTokenEnum MapReferenceSource(sal_Int16 nType);
208 static enum ::xmloff::token::XMLTokenEnum MapReferenceType(sal_Int16 nType);
209 static enum ::xmloff::token::XMLTokenEnum MapCountFieldName(FieldIdEnum nToken);
210 static enum ::xmloff::token::XMLTokenEnum MapBibliographyFieldName(const OUString& sName);
211 static enum ::xmloff::token::XMLTokenEnum MapMeasureKind(sal_Int16 nKind);
212 enum ::xmloff::token::XMLTokenEnum MapPageNumberName(const ::com::sun::star::uno::Reference<
213 ::com::sun::star::beans::XPropertySet> & xPropSet,
214 sal_Int32& nOffset); /// also adjust page offset
215 enum ::xmloff::token::XMLTokenEnum MapAuthorFieldName(const ::com::sun::star::uno::Reference <
216 ::com::sun::star::beans::XPropertySet > & xPropSet);
217 enum ::xmloff::token::XMLTokenEnum MapSenderFieldName(const ::com::sun::star::uno::Reference <
218 ::com::sun::star::beans::XPropertySet > & xPropSet);
220 protected:
222 SvXMLExport& GetExport() { return rExport; }
224 /// export a field after <text:span> is already written
225 void ExportFieldHelper(
226 const ::com::sun::star::uno::Reference<
227 ::com::sun::star::text::XTextField> & rTextField,
228 const ::com::sun::star::uno::Reference<
229 ::com::sun::star::beans::XPropertySet> & rPropSet,
230 const ::com::sun::star::uno::Reference<
231 ::com::sun::star::beans::XPropertySet> & rRangePropSet,
232 enum FieldIdEnum nToken,
233 bool bProgress );
235 /// export an empty element
236 void ExportElement(enum ::xmloff::token::XMLTokenEnum eElement, /// element token
237 bool bAddSpace = false); /// add blanks around
238 /// element?
240 /// export an element with string content
241 void ExportElement(enum ::xmloff::token::XMLTokenEnum eElement, /// element token
242 const OUString& sContent, /// element content
243 bool bAddSpace = false); /// add blanks around
244 /// element?
246 /// export a macro (as used in the macro field)
247 void ExportMacro( const ::com::sun::star::uno::Reference<
248 ::com::sun::star::beans::XPropertySet> & rPropSet,
249 const OUString& rContent);
251 /// export text:meta-field (RDF metadata)
252 void ExportMetaField( const ::com::sun::star::uno::Reference<
253 ::com::sun::star::beans::XPropertySet> & i_xMeta,
254 bool i_bAutoStyles, bool i_bProgress );
256 /// export a boolean attribute
257 void ProcessBoolean(
258 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
259 bool bBool, /// attribute value
260 bool bDefault); /// attribute default; omit, if attribute differs
262 /// export an integer attribute
263 void ProcessInteger(
264 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
265 sal_Int32 nNum); /// attribute value
267 /// export an integer attribute, omit if default
268 void ProcessIntegerDef(
269 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
270 sal_Int32 nNum, /// attribute value
271 sal_Int32 nDefault); /// default value
273 /// export a string attribute
274 void ProcessString(
275 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
276 const OUString& sValue, /// attribute value
277 bool bOmitEmpty = false, /// omit attribute, if value is empty
278 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
280 /// export a string attribute that gets a QName value
281 void ProcessString(
282 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
283 sal_uInt16 nValuePrefix,
284 const OUString& sValue, /// attribute value
285 bool bOmitEmpty = false, /// omit attribute, if value is empty
286 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
289 /// export a string attribute, omit if default
290 void ProcessString(
291 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
292 const OUString& sValue, /// attribute value
293 const OUString& sDefault, /// default value; omit if equal
294 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
296 /// export a string attribute, omit if default
297 void ProcessString(
298 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
299 sal_uInt16 nValuePrefix,
300 const OUString& sValue, /// attribute value
301 const OUString& sDefault, /// default value; omit if equal
302 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
304 /// export a string attribute
305 void ProcessString(
306 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
307 enum ::xmloff::token::XMLTokenEnum eValue, /// attribute token
308 bool bOmitEmpty = false, /// omit attribute, if value is empty
309 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
311 /// export a string attribute, omit if default
312 void ProcessString(
313 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
314 enum ::xmloff::token::XMLTokenEnum eValue, /// attribute value token
315 enum ::xmloff::token::XMLTokenEnum eDefault, /// default value token
316 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
318 /// export a string as a sequence of paragraphs
319 void ProcessParagraphSequence(
320 /// string containing the paragraphs
321 const OUString& sParagraphSequence);
323 /// export a numbering format (numeric, roman, alphabetic, etc.)
324 void ProcessNumberingType(
325 sal_Int16 nNumberingType); /// numbering type key
327 /// export display attribute (value, formula, none)
328 void ProcessDisplay(bool bIsVisible, /// is visible?
329 bool bIsCommand, /// is show command/show name?
330 bool bDefault = true); /// omit, if default
332 /// export all data-style related attributes
333 void ProcessValueAndType(
334 bool bIsString, /// do we process a string or a number?
335 sal_Int32 nFormatKey, /// format key for NumberFormatter; possibly -1
336 const OUString& sContent, /// string content; possibly invalid
337 const OUString& sDefault, /// default string
338 double fValue, /// float content; possibly invalid
339 bool bExportValue, /// export value attribute?
340 bool bExportValueType, /// export value-type attribute?
341 bool bExportStyle, /// export style-sttribute?
342 bool bForceSystemLanguage, /// no style language export
343 bool bTimeStyle = false); /// exporting a time style?
345 /// export times, dates and durations according to ISO 8601
346 void ProcessDateTime(
347 enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
348 double dValue, /// date/time value
349 bool bIsDate, /// export as date (rather than date/time)?
350 bool bIsDuration = false, /// export as duration
351 bool bOmitDurationIfZero = true, /// omit zero-length durat.
352 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
354 /// export a date, time, or duration
355 void ProcessDateTime(
356 enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
357 sal_Int32 nMinutes, /// date/time value in minutes
358 bool bIsDate, /// export as date?
359 bool bIsDuration, /// export as duration?
360 bool bOmitDurationIfZero, /// omit zero-length durations
361 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
363 /// export times, dates and durations according to ISO 8601
364 void ProcessDateTime(
365 enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
366 const ::com::sun::star::util::DateTime& rTime, /// date/time value
367 bool bIsDate, /// export as date (rather than date/time)?
368 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
370 /// export time or dateTime
371 void ProcessTimeOrDateTime(
372 enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
373 const ::com::sun::star::util::DateTime& rTime, /// date/time value
374 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
376 /// export all attributes for bibliography data fields
377 void ProcessBibliographyData(
378 const ::com::sun::star::uno::Reference <
379 ::com::sun::star::beans::XPropertySet > & rPropertySet);
381 /// export CommandTypeAttribute
382 void ProcessCommandType(
383 sal_Int32 nCommandType); /// com::sun::star::sdb::CommandType
385 void ProcessStringSequence(
386 const ::com::sun::star::uno::Sequence<OUString>& rSequence,
387 const OUString& sSelected );
389 void ProcessStringSequence(
390 const ::com::sun::star::uno::Sequence<OUString>& rSequence,
391 sal_Int32 nSelected );
393 /// export attributes that describe a data source
394 void ExportDataBaseElement(
395 enum ::xmloff::token::XMLTokenEnum eElement,
396 const OUString& sContent,
397 const ::com::sun::star::uno::Reference <
398 ::com::sun::star::beans::XPropertySet > & rPropertySet,
399 const ::com::sun::star::uno::Reference <
400 ::com::sun::star::beans::XPropertySetInfo > & rPropertySetInfo );
402 /// for XDependentTextFields, get PropertySet of FieldMaster
403 static ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet >
404 GetMasterPropertySet(const ::com::sun::star::uno::Reference <
405 ::com::sun::star::text::XTextField > & rTextField);
407 /// get PropertySet of (any) DependentTextField for this FieldMaster
408 bool GetDependentFieldPropertySet(
409 const ::com::sun::star::uno::Reference<
410 ::com::sun::star::beans::XPropertySet> & xmaster,
411 ::com::sun::star::uno::Reference<
412 ::com::sun::star::beans::XPropertySet> & xField);
415 /// get field ID from XTextField (and it's Property-Set)
416 enum FieldIdEnum GetFieldID(const ::com::sun::star::uno::Reference <
417 ::com::sun::star::text::XTextField > & rTextField,
418 const ::com::sun::star::uno::Reference <
419 ::com::sun::star::beans::XPropertySet > & xPropSet);
421 /// get field ID from XTextField service name (and it's PropertySet)
422 enum FieldIdEnum MapFieldName(const OUString& sFieldName,
423 const ::com::sun::star::uno::Reference <
424 ::com::sun::star::beans::XPropertySet> & xPropSet);
426 /// determine, whether field has string or numeric content
427 bool IsStringField(FieldIdEnum nFieldType, /// field ID
428 const ::com::sun::star::uno::Reference <
429 ::com::sun::star::beans::XPropertySet > & xPropSet);
432 /// explode a field master name into field type and field name
433 bool ExplodeFieldMasterName(
434 const OUString& sMasterName, /// name as returned by SO API
435 OUString& sFieldType, /// out: field type
436 OUString& sVarName); /// out: variable name
438 /// make reference name for a foot- or endnote
439 static OUString MakeFootnoteRefName(sal_Int16 nSeqNo);
441 /// make reference name for a sequence field
442 static OUString MakeSequenceRefName(sal_Int16 nSeqNo,
443 const OUString& rSeqName);
445 private:
446 // constants
448 // service names
449 const OUString sServicePrefix;
450 const OUString sFieldMasterPrefix;
451 const OUString sPresentationServicePrefix;
453 // property names
454 const OUString sPropertyAdjust;
455 const OUString sPropertyAuthor;
456 const OUString sPropertyChapterFormat;
457 const OUString sPropertyChapterNumberingLevel;
458 const OUString sPropertyCharStyleNames;
459 const OUString sPropertyCondition;
460 const OUString sPropertyContent;
461 const OUString sPropertyDataBaseName;
462 const OUString sPropertyDataBaseURL;
463 const OUString sPropertyDataColumnName;
464 const OUString sPropertyDataCommandType;
465 const OUString sPropertyDataTableName;
466 const OUString sPropertyDateTime;
467 const OUString sPropertyDateTimeValue;
468 const OUString sPropertyDDECommandElement;
469 const OUString sPropertyDDECommandFile;
470 const OUString sPropertyDDECommandType;
471 const OUString sPropertyDependentTextFields;
472 const OUString sPropertyFalseContent;
473 const OUString sPropertyFields;
474 const OUString sPropertyFieldSubType;
475 const OUString sPropertyFileFormat;
476 const OUString sPropertyFullName;
477 const OUString sPropertyHint;
478 const OUString sPropertyInitials;
479 const OUString sPropertyInstanceName;
480 const OUString sPropertyIsAutomaticUpdate;
481 const OUString sPropertyIsConditionTrue;
482 const OUString sPropertyIsDataBaseFormat;
483 const OUString sPropertyIsDate;
484 const OUString sPropertyIsExpression;
485 const OUString sPropertyIsFixed;
486 const OUString sPropertyIsFixedLanguage;
487 const OUString sPropertyIsHidden;
488 const OUString sPropertyIsInput;
489 const OUString sPropertyIsShowFormula;
490 const OUString sPropertyIsVisible;
491 const OUString sPropertyItems;
492 const OUString sPropertyLevel;
493 const OUString sPropertyMeasureKind;
494 const OUString sPropertyName;
495 const OUString sPropertyNumberFormat;
496 const OUString sPropertyNumberingSeparator;
497 const OUString sPropertyNumberingType;
498 const OUString sPropertyOffset;
499 const OUString sPropertyOn;
500 const OUString sPropertyPlaceholderType;
501 const OUString sPropertyReferenceFieldPart;
502 const OUString sPropertyReferenceFieldSource;
503 const OUString sPropertyScriptType;
504 const OUString sPropertySelectedItem;
505 const OUString sPropertySequenceNumber;
506 const OUString sPropertySequenceValue;
507 const OUString sPropertySetNumber;
508 const OUString sPropertySourceName;
509 const OUString sPropertySubType;
510 const OUString sPropertyTargetFrame;
511 const OUString sPropertyTrueContent;
512 const OUString sPropertyURL;
513 const OUString sPropertyURLContent;
514 const OUString sPropertyUserText;
515 const OUString sPropertyValue;
516 const OUString sPropertyVariableName;
517 const OUString sPropertyHelp;
518 const OUString sPropertyTooltip;
519 const OUString sPropertyTextRange;
521 const OUString sEmpty;
523 XMLPropertyState* pCombinedCharactersPropertyState;
532 #endif
534 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */