nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / inc / txtflde.hxx
blob1e2d26229529e330941fc40e279c87cb08ded634
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/xmlnamespace.hxx>
30 #include <rtl/ustring.hxx>
31 #include <xmloff/xmltoken.hxx>
33 #include <map>
34 #include <set>
35 #include <memory>
38 class SvXMLExport;
39 struct XMLPropertyState;
41 namespace com::sun::star {
42 namespace util { struct DateTime; }
43 namespace util { struct Date; }
44 namespace text { class XTextField; }
45 namespace text { class XText; }
46 namespace beans { class XPropertySet; }
47 namespace beans { class XPropertySetInfo; }
48 namespace frame { class XModel; }
49 namespace uno { template<typename A> class Sequence; }
53 /// field IDs,
54 // including translation between UNO speak and XML speak if appropriate
56 enum FieldIdEnum {
57 FIELD_ID_SENDER, // sender == extended user
58 FIELD_ID_AUTHOR,
59 FIELD_ID_DATE, // current date
60 FIELD_ID_TIME, // current time (+date)
61 FIELD_ID_PAGENAME, // page/slide name
62 FIELD_ID_PAGENUMBER, // page number
63 FIELD_ID_PAGESTRING, // page continuation string (page number string)
64 FIELD_ID_REFPAGE_SET, // set reference page
65 FIELD_ID_REFPAGE_GET, // get reference page number
67 FIELD_ID_PLACEHOLDER, // placeholder field == jump edit field
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_GET, // user field
73 FIELD_ID_USER_INPUT, // input field (user field)
74 FIELD_ID_TEXT_INPUT, // input field (text)
75 FIELD_ID_EXPRESSION, // expression field = formula field
76 FIELD_ID_SEQUENCE, // sequence field
78 FIELD_ID_DATABASE_NEXT, // select next row
79 FIELD_ID_DATABASE_SELECT, // select row # (NumSet)
80 FIELD_ID_DATABASE_DISPLAY, // display data (form letter field)
81 FIELD_ID_DATABASE_NAME, // display current db name (database name)
82 FIELD_ID_DATABASE_NUMBER, // display row # (SetNumber)
84 FIELD_ID_DOCINFO_CREATION_AUTHOR, // docinfo fields
85 FIELD_ID_DOCINFO_CREATION_TIME,
86 FIELD_ID_DOCINFO_CREATION_DATE,
87 FIELD_ID_DOCINFO_DESCRIPTION,
88 FIELD_ID_DOCINFO_CUSTOM,
89 FIELD_ID_DOCINFO_PRINT_TIME,
90 FIELD_ID_DOCINFO_PRINT_DATE,
91 FIELD_ID_DOCINFO_PRINT_AUTHOR,
92 FIELD_ID_DOCINFO_TITLE,
93 FIELD_ID_DOCINFO_SUBJECT,
94 FIELD_ID_DOCINFO_KEYWORDS,
95 FIELD_ID_DOCINFO_REVISION,
96 FIELD_ID_DOCINFO_EDIT_DURATION,
97 FIELD_ID_DOCINFO_SAVE_TIME,
98 FIELD_ID_DOCINFO_SAVE_DATE,
99 FIELD_ID_DOCINFO_SAVE_AUTHOR,
101 FIELD_ID_CONDITIONAL_TEXT, // conditionally choose between 2 texts
102 FIELD_ID_HIDDEN_TEXT, // conditionally hide a text
103 FIELD_ID_HIDDEN_PARAGRAPH, // conditionally hide a paragraph
105 FIELD_ID_TEMPLATE_NAME, // display name of template
106 FIELD_ID_CHAPTER, // display name/number of current chapter
107 FIELD_ID_FILE_NAME, // display name of current file
109 FIELD_ID_COUNT_PARAGRAPHS, // statistics fields: - paragraphs
110 FIELD_ID_COUNT_WORDS, // - words
111 FIELD_ID_COUNT_CHARACTERS, // - chars
112 FIELD_ID_COUNT_PAGES, // - pages
113 FIELD_ID_COUNT_TABLES, // - tables
114 FIELD_ID_COUNT_GRAPHICS, // - graphics
115 FIELD_ID_COUNT_OBJECTS, // - objects
117 FIELD_ID_MACRO, // macro fields
118 FIELD_ID_REF_REFERENCE, // get reference field (reference)
119 FIELD_ID_REF_SEQUENCE, // get reference field (sequence)
120 FIELD_ID_REF_BOOKMARK, // get reference field (bookmark)
121 FIELD_ID_REF_FOOTNOTE, // get reference field (footnote)
122 FIELD_ID_REF_ENDNOTE, // get reference field (endnote)
123 FIELD_ID_DDE, // DDE field
125 FIELD_ID_BIBLIOGRAPHY, // bibliography index entry
127 FIELD_ID_SHEET_NAME, // name of current (spread-)sheet
128 FIELD_ID_URL, // URL field (only Calc, Draw, Impress)
130 FIELD_ID_SCRIPT, // script fields (for HTML pages, mostly)
131 FIELD_ID_ANNOTATION, // annotation (notice) field
133 FIELD_ID_COMBINED_CHARACTERS, // combined characters (asian typography)
135 FIELD_ID_META, // text:meta-field (RDF metadata)
137 FIELD_ID_MEASURE, // for measure shapes
139 FIELD_ID_TABLE_FORMULA, // DEPRECATED: table formulas (Writer 2.0)
140 FIELD_ID_DROP_DOWN, // DEPRECATED: dropdown fields (WW8)
142 FIELD_ID_DRAW_HEADER,
143 FIELD_ID_DRAW_FOOTER,
144 FIELD_ID_DRAW_DATE_TIME,
146 FIELD_ID_UNKNOWN // invalid or unknown field type!
150 class XMLTextFieldExport final
152 SvXMLExport& rExport;
154 /// store used text field master names (NULL means: don't collect)
155 std::unique_ptr< ::std::map<
156 css::uno::Reference< css::text::XText >,
157 ::std::set< OUString > > >
158 pUsedMasters;
160 public:
162 XMLTextFieldExport( SvXMLExport& rExp,
163 /// XMLPropertyState for the combined characters field
164 std::unique_ptr<XMLPropertyState> pCombinedCharState );
165 ~XMLTextFieldExport();
167 /// Export this field and the surrounding span element with the formatting.
168 /// To be called for every field in the document body.
169 void ExportField(const css::uno::Reference < css::text::XTextField > & rTextField,
170 bool bProgress, bool & rPrevCharIsSpace);
172 /// collect styles (character styles, data styles, ...) for this field
173 /// (if appropriate).
174 /// Also collect used field masters (if pUsedMasters is set)
175 /// to be called for every field during style export.
176 void ExportFieldAutoStyle(const css::uno::Reference < css::text::XTextField > & rTextField,
177 const bool bProgress, const bool bRecursive );
179 /// export field declarations.
180 /// to be called once at beginning of document body.
181 void ExportFieldDeclarations();
183 /// export field declarations for fields used in the particular XText.
184 /// (Requires that a list of used field declarations has previously been
185 /// built-up in ExportFieldAutoStyle() )
186 void ExportFieldDeclarations(
187 const css::uno::Reference < css::text::XText > & rText);
189 /// export all field declarations, or only those that have been used?
190 /// Calling this method will reset the list of used field declarations.
191 void SetExportOnlyUsedFieldDeclarations(
192 bool bExportOnlyUsed = true);
194 // determine element or attribute names
195 // (public, because they may be useful in related XML export classes)
196 static enum ::xmloff::token::XMLTokenEnum MapPlaceholderType(sal_uInt16 nType);
197 static enum ::xmloff::token::XMLTokenEnum MapTemplateDisplayFormat(sal_Int16 nType);
198 static enum ::xmloff::token::XMLTokenEnum MapChapterDisplayFormat(sal_Int16 nType);
199 static enum ::xmloff::token::XMLTokenEnum MapFilenameDisplayFormat(sal_Int16 nType);
200 static enum ::xmloff::token::XMLTokenEnum MapDocInfoFieldName(enum FieldIdEnum nToken);
201 static enum ::xmloff::token::XMLTokenEnum MapReferenceSource(sal_Int16 nType);
202 static enum ::xmloff::token::XMLTokenEnum MapReferenceType(sal_Int16 nType);
203 static enum ::xmloff::token::XMLTokenEnum MapCountFieldName(FieldIdEnum nToken);
204 static enum ::xmloff::token::XMLTokenEnum MapBibliographyFieldName(const OUString& sName);
205 static enum ::xmloff::token::XMLTokenEnum MapMeasureKind(sal_Int16 nKind);
206 static enum ::xmloff::token::XMLTokenEnum MapPageNumberName(const css::uno::Reference< css::beans::XPropertySet> & xPropSet,
207 sal_Int32& nOffset); /// also adjust page offset
208 static enum ::xmloff::token::XMLTokenEnum MapAuthorFieldName(const css::uno::Reference< css::beans::XPropertySet > & xPropSet);
209 static enum ::xmloff::token::XMLTokenEnum MapSenderFieldName(const css::uno::Reference< css::beans::XPropertySet > & xPropSet);
211 private:
213 SvXMLExport& GetExport() { return rExport; }
215 /// export a field after <text:span> is already written
216 void ExportFieldHelper(
217 const css::uno::Reference< css::text::XTextField> & rTextField,
218 const css::uno::Reference< css::beans::XPropertySet> & rPropSet,
219 const css::uno::Reference< css::beans::XPropertySet> & rRangePropSet,
220 enum FieldIdEnum nToken,
221 bool bProgress,
222 bool & rPrevCharIsSpace);
224 /// export an empty element
225 void ExportElement(enum ::xmloff::token::XMLTokenEnum eElement, /// element token
226 bool bAddSpace = false); /// add blanks around
227 /// element?
229 /// export an element with string content
230 void ExportElement(enum ::xmloff::token::XMLTokenEnum eElement, /// element token
231 const OUString& sContent); /// element content
233 /// export a macro (as used in the macro field)
234 void ExportMacro( const css::uno::Reference< css::beans::XPropertySet> & rPropSet,
235 const OUString& rContent);
237 /// export text:meta-field (RDF metadata)
238 void ExportMetaField( const css::uno::Reference< css::beans::XPropertySet> & i_xMeta,
239 bool i_bAutoStyles, bool i_bProgress,
240 bool & rPrevCharIsSpace);
242 /// export a boolean attribute
243 void ProcessBoolean(
244 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
245 bool bBool, /// attribute value
246 bool bDefault); /// attribute default; omit, if attribute differs
248 /// export an integer attribute
249 void ProcessInteger(
250 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
251 sal_Int32 nNum); /// attribute value
253 /// export an integer attribute, omit if default
254 void ProcessIntegerDef(
255 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
256 sal_Int32 nNum, /// attribute value
257 sal_Int32 nDefault); /// default value
259 /// export a string attribute
260 void ProcessString(
261 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
262 const OUString& sValue, /// attribute value
263 bool bOmitEmpty = false, /// omit attribute, if value is empty
264 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
266 /// export a string attribute that gets a QName value
267 void ProcessString(
268 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
269 sal_uInt16 nValuePrefix,
270 const OUString& sValue); /// attribute value
273 /// export a string attribute, omit if default
274 void ProcessString(
275 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
276 const OUString& sValue, /// attribute value
277 const OUString& sDefault); /// default value; omit if equal
279 /// export a string attribute, omit if default
280 void ProcessString(
281 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
282 sal_uInt16 nValuePrefix,
283 const OUString& sValue, /// attribute value
284 const OUString& sDefault); /// default value; omit if equal
286 /// export a string attribute
287 void ProcessString(
288 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
289 enum ::xmloff::token::XMLTokenEnum eValue, /// attribute token
290 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
292 /// export a string attribute, omit if default
293 void ProcessString(
294 enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
295 enum ::xmloff::token::XMLTokenEnum eValue, /// attribute value token
296 enum ::xmloff::token::XMLTokenEnum eDefault); /// default value token
298 /// export a string as a sequence of paragraphs
299 void ProcessParagraphSequence(
300 /// string containing the paragraphs
301 const OUString& sParagraphSequence);
303 /// export a numbering format (numeric, roman, alphabetic, etc.)
304 void ProcessNumberingType(
305 sal_Int16 nNumberingType); /// numbering type key
307 /// export display attribute (value, formula, none)
308 void ProcessDisplay(bool bIsVisible, /// is visible?
309 bool bIsCommand); /// is show command/show name?
311 /// export all data-style related attributes
312 void ProcessValueAndType(
313 bool bIsString, /// do we process a string or a number?
314 sal_Int32 nFormatKey, /// format key for NumberFormatter; possibly -1
315 const OUString& sContent, /// string content; possibly invalid
316 const OUString& sDefault, /// default string
317 double fValue, /// float content; possibly invalid
318 bool bExportValue, /// export value attribute?
319 bool bExportValueType, /// export value-type attribute?
320 bool bExportStyle, /// export style-attribute?
321 bool bForceSystemLanguage, /// no style language export
322 bool bTimeStyle = false); /// exporting a time style?
324 /// export times, dates and durations according to ISO 8601
325 void ProcessDateTime(
326 enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
327 double dValue, /// date/time value
328 bool bIsDate, /// export as date (rather than date/time)?
329 bool bIsDuration, /// export as duration
330 bool bOmitDurationIfZero = true, /// omit zero-length durat.
331 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
333 /// export a date, time, or duration
334 void ProcessDateTime(
335 enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
336 sal_Int32 nMinutes, /// date/time value in minutes
337 bool bIsDate, /// export as date?
338 bool bIsDuration); /// export as duration?
340 /// export times, dates and durations according to ISO 8601
341 void ProcessDateTime(
342 enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
343 const css::util::DateTime& rTime); /// date/time value
345 /// export time or dateTime
346 void ProcessTimeOrDateTime(
347 enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
348 const css::util::DateTime& rTime); /// date/time value
350 /// export all attributes for bibliography data fields
351 void ProcessBibliographyData(
352 const css::uno::Reference <
353 css::beans::XPropertySet > & rPropertySet);
355 /// export CommandTypeAttribute
356 void ProcessCommandType(
357 sal_Int32 nCommandType); /// css::sdb::CommandType
359 void ProcessStringSequence(
360 const css::uno::Sequence<OUString>& rSequence,
361 const OUString& sSelected );
363 void ProcessStringSequence(
364 const css::uno::Sequence<OUString>& rSequence,
365 sal_Int32 nSelected );
367 /// export attributes that describe a data source
368 void ExportDataBaseElement(
369 enum ::xmloff::token::XMLTokenEnum eElement,
370 const OUString& sContent,
371 const css::uno::Reference < css::beans::XPropertySet > & rPropertySet,
372 const css::uno::Reference < css::beans::XPropertySetInfo > & rPropertySetInfo );
374 /// for XDependentTextFields, get PropertySet of FieldMaster
375 static css::uno::Reference < css::beans::XPropertySet >
376 GetMasterPropertySet(const css::uno::Reference < css::text::XTextField > & rTextField);
378 /// get PropertySet of (any) DependentTextField for this FieldMaster
379 static bool GetDependentFieldPropertySet(
380 const css::uno::Reference< css::beans::XPropertySet> & xmaster,
381 css::uno::Reference< css::beans::XPropertySet> & xField);
384 /// get field ID from XTextField (and it's Property-Set)
385 static enum FieldIdEnum GetFieldID(const css::uno::Reference < css::text::XTextField > & rTextField,
386 const css::uno::Reference < css::beans::XPropertySet > & xPropSet);
388 /// get field ID from XTextField service name (and it's PropertySet)
389 static enum FieldIdEnum MapFieldName(const OUString& sFieldName,
390 const css::uno::Reference < css::beans::XPropertySet> & xPropSet);
392 /// determine, whether field has string or numeric content
393 static bool IsStringField(FieldIdEnum nFieldType, /// field ID
394 const css::uno::Reference < css::beans::XPropertySet > & xPropSet);
397 /// explode a field master name into field type and field name
398 static void ExplodeFieldMasterName(
399 const OUString& sMasterName, /// name as returned by SO API
400 OUString& sFieldType, /// out: field type
401 OUString& sVarName); /// out: variable name
403 /// make reference name for a foot- or endnote
404 static OUString MakeFootnoteRefName(sal_Int16 nSeqNo);
406 /// make reference name for a sequence field
407 static OUString MakeSequenceRefName(sal_Int16 nSeqNo,
408 const OUString& rSeqName);
410 std::unique_ptr<XMLPropertyState> pCombinedCharactersPropertyState;
415 #endif
417 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */