Branch libreoffice-6-3
[LibreOffice.git] / xmloff / inc / txtvfldi.hxx
blob2ca6b213a23a7dcd383e44e63a53b28e6e227732
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
22 * XML import of all variable related text fields plus database display field
25 #ifndef INCLUDED_XMLOFF_INC_TXTVFLDI_HXX
26 #define INCLUDED_XMLOFF_INC_TXTVFLDI_HXX
28 #include "txtfldi.hxx"
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/beans/XPropertySetInfo.hpp>
33 /** helper class: parses value-type and associated value attributes */
34 class XMLValueImportHelper final
36 SvXMLImport& rImport;
37 XMLTextImportHelper& rHelper;
39 OUString sValue; /// string value (only valid if bStringValueOK)
40 double fValue; /// double value (only valid if bFloatValueOK)
41 sal_Int32 nFormatKey; /// format key (only valid of bFormatOK)
42 OUString sFormula; /// formula string
43 OUString sDefault; /// default (see bStringDefault/bFormulaDef.)
44 bool bIsDefaultLanguage;/// format (of nFormatKey) has system language?
46 bool bStringType; /// is this a string (or a float) type?
47 bool bFormatOK; /// have we read a style:data-style-name attr.?
48 bool bStringValueOK; /// have we read a string-value attr.?
49 bool bFormulaOK; /// have we read the formula attribute?
51 const bool bSetType; /// should PrepareField set the SetExp subtype?
52 const bool bSetValue; /// should PrepareField set content/value?
53 const bool bSetStyle; /// should PrepareField set NumberFormat?
54 const bool bSetFormula; /// should PrepareField set Formula?
56 public:
57 XMLValueImportHelper(
58 SvXMLImport& rImprt, /// XML Import
59 XMLTextImportHelper& rHlp, /// text import helper
60 bool bType, /// process type (PrepareField)
61 bool bStyle, /// process data style (P.F.)
62 bool bValue, /// process value (Prep.Field)
63 bool bFormula); /// process formula (Prep.F.)
65 /// process attribute values
66 void ProcessAttribute( sal_uInt16 nAttrToken,
67 const OUString& sAttrValue );
69 /// prepare XTextField for insertion into document
70 void PrepareField(
71 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet);
73 /// is value a string (rather than double)?
74 bool IsStringValue() { return bStringType; }
76 /// has format been read?
77 bool IsFormatOK() { return bFormatOK; }
79 void SetDefault(const OUString& sStr) { sDefault = sStr; }
83 /**
84 * abstract parent class for all variable related fields
85 * - variable-set/get/decl (not -decls),
86 * - user-field-get/decl (not -decls),
87 * - sequence/-decl (not -decls),
88 * - expression,
89 * - text-input
91 * Processes the following attributes:
92 * - name
93 * - formula
94 * - display
95 * - value, value-type, data-style-name (via XMLValueImportHelper)
96 * - description.
98 * Each attribute has a corresponding member, a bool variable to indicate
99 * whether it was set or not, and a bool variable whether it should be set
100 * using the standard property name.
102 * bValid is set true, when name is found!
103 * (Most variable related fields are valid, if a name is
104 * found. However, some are always valid. In this case, setting bValid
105 * does not matter.)
107 class XMLVarFieldImportContext : public XMLTextFieldImportContext
109 private:
110 OUString sName; /// name attribute
111 OUString sFormula; /// formula attribute
112 OUString sDescription; /// description
113 OUString sHelp; /// help text
114 OUString sHint; /// hint
115 XMLValueImportHelper aValueHelper; /// value, value-type, and style
116 bool bDisplayFormula; /// display formula?(rather than value)
117 bool bDisplayNone; /// hide field?
119 bool bFormulaOK; /// sFormula was set
120 bool bDescriptionOK; /// sDescription was set
121 bool bHelpOK; /// sHelp was set
122 bool bHintOK; /// sHint was set
123 bool bDisplayOK; /// sDisplayFormula/-None were set
125 bool const bSetFormula; /// set Formula property
126 bool const bSetFormulaDefault; /// use content as default for formula
127 bool const bSetDescription; /// set sDescription with Hint-property
128 bool const bSetHelp;
129 bool const bSetHint;
130 bool const bSetVisible; /// set IsVisible
131 bool bSetDisplayFormula; /// set DisplayFormula (sub type???)
132 bool const bSetPresentation; /// set presentation frm elem. content?
134 public:
137 XMLVarFieldImportContext(
138 // for XMLTextFieldImportContext:
139 SvXMLImport& rImport, /// XML Import
140 XMLTextImportHelper& rHlp, /// text import helper
141 const sal_Char* pServiceName, /// name of SO API service
142 sal_uInt16 nPrfx, /// namespace prefix
143 const OUString& rLocalName, /// element name w/o prefix
144 // config variables for PrepareField behavior:
145 bool bFormula, /// set Formula property
146 bool bFormulaDefault, /// use content as default for formula
147 bool bDescription, /// set sDescription with Hint-property
148 bool bHelp,
149 bool bHint,
150 bool bVisible, /// set IsVisible (display attr)
151 bool bDisplayFormula, /// set ??? (display attr.)
152 bool bType, /// set value type with ???-property
153 bool bStyle, /// set data style (NumberFormat-Prop.)
154 bool bValue, /// set value with Content/Value-Prop.
155 bool bPresentation); /// set presentation from elem. content
157 protected:
158 /// process attribute values
159 virtual void ProcessAttribute( sal_uInt16 nAttrToken,
160 const OUString& sAttrValue ) override;
162 /// prepare XTextField for insertion into document
163 virtual void PrepareField(
164 const css::uno::Reference<
165 css::beans::XPropertySet> & xPropertySet) override;
167 // various accessor methods:
168 const OUString& GetName() { return sName; }
169 bool IsStringValue() { return aValueHelper.IsStringValue();}
173 /** import variable get fields (<text:variable-get>) */
174 class XMLVariableGetFieldImportContext : public XMLVarFieldImportContext
176 public:
179 XMLVariableGetFieldImportContext(
180 SvXMLImport& rImport, /// XML Import
181 XMLTextImportHelper& rHlp, /// Text import helper
182 sal_uInt16 nPrfx, /// namespace prefix
183 const OUString& rLocalName); /// element name w/o prefix
186 protected:
187 /// prepare XTextField for insertion into document
188 virtual void PrepareField(
189 const css::uno::Reference<
190 css::beans::XPropertySet> & xPropertySet) override;
194 /** import expression fields (<text:expression>) */
195 class XMLExpressionFieldImportContext : public XMLVarFieldImportContext
197 public:
199 XMLExpressionFieldImportContext(
200 SvXMLImport& rImport, /// XML Import
201 XMLTextImportHelper& rHlp, /// Text import helper
202 sal_uInt16 nPrfx, /// namespace prefix
203 const OUString& sLocalName); /// element name w/o prefix
205 protected:
206 virtual void PrepareField(
207 const css::uno::Reference<
208 css::beans::XPropertySet> & xPropertySet) override;
211 /*** import text input fields (<text:text-input>) */
212 class XMLTextInputFieldImportContext : public XMLVarFieldImportContext
214 public:
216 XMLTextInputFieldImportContext(
217 SvXMLImport& rImport, /// XML Import
218 XMLTextImportHelper& rHlp, /// Text import helper
219 sal_uInt16 nPrfx, /// namespace prefix
220 const OUString& sLocalName); /// element name w/o prefix
222 protected:
223 virtual void PrepareField(
224 const css::uno::Reference<
225 css::beans::XPropertySet> & xPropertySet) override;
230 * upperclass for variable/user-set, var/user-input, and sequence fields
231 * inds field master of appropriate type and attaches field to it.
233 class XMLSetVarFieldImportContext : public XMLVarFieldImportContext
235 const VarType eFieldType;
237 public:
240 XMLSetVarFieldImportContext(
241 // for XMLTextFieldImportContext:
242 SvXMLImport& rImport, /// see XMLTextFieldImportContext
243 XMLTextImportHelper& rHlp, /// see XMLTextFieldImportContext
244 const sal_Char* pServiceName, /// see XMLTextFieldImportContext
245 sal_uInt16 nPrfx, /// see XMLTextFieldImportContext
246 const OUString& rLocalName, /// see XMLTextFieldImportContext
247 // for finding appropriate field master (see EndElement())
248 VarType eVarType, /// variable type
249 // config variables:
250 bool bFormula, /// see XMLTextFieldImportContext
251 bool bFormulaDefault, /// see XMLTextFieldImportContext
252 bool bDescription, /// see XMLTextFieldImportContext
253 bool bHelp, /// see XMLTextFieldImportContext
254 bool bHint, /// see XMLTextFieldImportContext
255 bool bVisible, /// see XMLTextFieldImportContext
256 bool bDisplayFormula, /// see XMLTextFieldImportContext
257 bool bType, /// see XMLTextFieldImportContext
258 bool bStyle, /// see XMLTextFieldImportContext
259 bool bValue, /// see XMLTextFieldImportContext
260 bool bPresentation); /// see XMLTextFieldImportContext
262 protected:
264 /// create XTextField, attach master and insert into document;
265 /// also calls PrepareTextField
266 virtual void EndElement() override;
268 /// find appropriate field master
269 bool FindFieldMaster(
270 css::uno::Reference<
271 css::beans::XPropertySet> & xMaster);
275 /** import variable set fields (<text:variable-set>) */
276 class XMLVariableSetFieldImportContext : public XMLSetVarFieldImportContext
278 public:
280 XMLVariableSetFieldImportContext(
281 SvXMLImport& rImport, /// XML Import
282 XMLTextImportHelper& rHlp, /// Text import helper
283 sal_uInt16 nPrfx, /// namespace prefix
284 const OUString& rLocalName); /// element name w/o prefix
286 protected:
287 /// prepare XTextField for insertion into document
288 virtual void PrepareField(
289 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
293 /** variable input fields (<text:variable-input>) */
294 class XMLVariableInputFieldImportContext : public XMLSetVarFieldImportContext
296 public:
299 XMLVariableInputFieldImportContext(
300 SvXMLImport& rImport, /// XML Import
301 XMLTextImportHelper& rHlp, /// Text import helper
302 sal_uInt16 nPrfx, /// namespace prefix
303 const OUString& rLocalName); /// element name w/o prefix
305 protected:
307 /// prepare XTextField for insertion into document
308 virtual void PrepareField(
309 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
313 /** user fields (<text:user-field-get>) */
314 class XMLUserFieldImportContext : public XMLSetVarFieldImportContext
317 public:
320 XMLUserFieldImportContext(
321 SvXMLImport& rImport, /// XML Import
322 XMLTextImportHelper& rHlp, /// Text import helper
323 sal_uInt16 nPrfx, /// namespace prefix
324 const OUString& rLocalName); /// element name w/o prefix
327 /** user input fields (<text:user-field-input>) */
328 class XMLUserFieldInputImportContext : public XMLVarFieldImportContext
331 public:
334 XMLUserFieldInputImportContext(
335 SvXMLImport& rImport, /// XML Import
336 XMLTextImportHelper& rHlp, /// Text import helper
337 sal_uInt16 nPrfx, /// namespace prefix
338 const OUString& rLocalName); /// element name w/o prefix
340 virtual void PrepareField(
341 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
345 /** sequence fields (<text:sequence>) */
346 class XMLSequenceFieldImportContext : public XMLSetVarFieldImportContext
348 OUString sNumFormat;
349 OUString sNumFormatSync;
350 OUString sRefName;
352 bool bRefNameOK;
354 public:
357 XMLSequenceFieldImportContext(
358 SvXMLImport& rImport, /// XML Import
359 XMLTextImportHelper& rHlp, /// Text import helper
360 sal_uInt16 nPrfx, /// namespace prefix
361 const OUString& rLocalName); /// element name w/o prefix
363 protected:
365 /// process attribute values
366 virtual void ProcessAttribute( sal_uInt16 nAttrToken,
367 const OUString& sAttrValue ) override;
369 /// prepare XTextField for insertion into document
370 virtual void PrepareField(
371 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
376 * variable declaration container for all variable fields
377 * (variable-decls, user-field-decls, sequence-decls)
379 class XMLVariableDeclsImportContext : public SvXMLImportContext
381 enum VarType const eVarDeclsContextType;
382 XMLTextImportHelper& rImportHelper;
384 public:
387 XMLVariableDeclsImportContext(
388 SvXMLImport& rImport, /// XML Import
389 XMLTextImportHelper& rHlp, /// text import helper
390 sal_uInt16 nPrfx, /// namespace prefix
391 const OUString& rLocalName, /// element name w/o prefix
392 enum VarType eVarType); /// variable type
394 virtual SvXMLImportContextRef CreateChildContext(
395 sal_uInt16 nPrefix,
396 const OUString& rLocalName,
397 const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList ) override;
401 * variable field declarations
402 * (variable-decl, user-field-decl, sequence-decl)
404 class XMLVariableDeclImportContext : public SvXMLImportContext
406 XMLValueImportHelper aValueHelper;
407 sal_Unicode cSeparationChar;
409 public:
412 XMLVariableDeclImportContext(
413 SvXMLImport& rImport, /// XML Import
414 XMLTextImportHelper& rHlp, /// text import helper
415 sal_uInt16 nPrfx, /// namespace prefix
416 const OUString& rLocalName, /// element name w/o prefix
417 const css::uno::Reference< css::xml::sax::XAttributeList> & xAttrList,/// list of element attributes
418 enum VarType eVarType); /// variable type
420 /// get field master for name and rename if appropriate
421 static bool FindFieldMaster(css::uno::Reference<css::beans::XPropertySet> & xMaster,
422 SvXMLImport& rImport,
423 XMLTextImportHelper& rHelper,
424 const OUString& sVarName,
425 enum VarType eVarType);
429 /** import table formula fields (deprecated; for Writer 2.0 compatibility) */
430 class XMLTableFormulaImportContext : public XMLTextFieldImportContext
432 XMLValueImportHelper aValueHelper;
434 bool bIsShowFormula;
436 public:
438 XMLTableFormulaImportContext(
439 SvXMLImport& rImport, /// XML Import
440 XMLTextImportHelper& rHlp, /// text import helper
441 sal_uInt16 nPrfx, /// namespace prefix
442 const OUString& rLocalName); /// element name w/o prefix
444 protected:
446 /// process attribute values
447 virtual void ProcessAttribute( sal_uInt16 nAttrToken,
448 const OUString& sAttrValue ) override;
450 /// prepare XTextField for insertion into document
451 virtual void PrepareField(
452 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
456 /** import database display fields (<text:database-display>) */
457 class XMLDatabaseDisplayImportContext : public XMLDatabaseFieldImportContext
459 XMLValueImportHelper aValueHelper;
461 OUString sColumnName;
462 bool bColumnOK;
464 bool bDisplay;
465 bool bDisplayOK;
467 public:
470 XMLDatabaseDisplayImportContext(
471 SvXMLImport& rImport, /// XML Import
472 XMLTextImportHelper& rHlp, /// text import helper
473 sal_uInt16 nPrfx, /// namespace prefix
474 const OUString& rLocalName); /// element name w/o prefix
476 protected:
478 /// process attribute values
479 virtual void ProcessAttribute( sal_uInt16 nAttrToken,
480 const OUString& sAttrValue ) override;
482 /// create, prepare and insert database field master and database field
483 virtual void EndElement() override;
486 #endif
488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */