bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / inc / txtvfldi.hxx
blob95f2391aa30cb4347c0c1eb44c3668597b209f47
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 _XMLOFF_TXTVFLDI_HXX
26 #define _XMLOFF_TXTVFLDI_HXX
28 #include "txtvfldi.hxx"
29 #include "txtfldi.hxx"
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/beans/XPropertySetInfo.hpp>
35 /// variable type (for XMLSetVarFieldImportContext)
36 enum VarType
38 VarTypeSimple,
39 VarTypeUserField,
40 VarTypeSequence
45 /** helper class: parses value-type and associated value attributes */
46 class XMLValueImportHelper
49 const OUString sPropertyContent;
50 const OUString sPropertyValue;
51 const OUString sPropertyFormula;
52 const OUString sPropertyNumberFormat;
53 const OUString sPropertyIsFixedLanguage;
55 SvXMLImport& rImport;
56 XMLTextImportHelper& rHelper;
58 OUString sValue; /// string value (only valid if bStringValueOK)
59 double fValue; /// double value (only valid if bFloatValueOK)
60 sal_Int32 nFormatKey; /// format key (only valid of bFormatOK)
61 OUString sFormula; /// formula string
62 OUString sDefault; /// default (see bStringDefault/bFormulaDef.)
63 sal_Bool bIsDefaultLanguage;/// format (of nFormatKey) has system language?
65 sal_Bool bStringType; /// is this a string (or a float) type?
66 sal_Bool bFormatOK; /// have we read a style:data-style-name attr.?
67 sal_Bool bTypeOK; /// have we read a value-type attribute?
68 sal_Bool bStringValueOK; /// have we read a string-value attr.?
69 sal_Bool bFloatValueOK; /// have we read any of the float attr.s?
70 sal_Bool bFormulaOK; /// have we read the formula attribute?
72 const sal_Bool bSetType; /// should PrepareField set the SetExp subtype?
73 const sal_Bool bSetValue; /// should PrepareField set content/value?
74 const sal_Bool bSetStyle; /// should PrepareField set NumberFormat?
75 const sal_Bool bSetFormula; /// should PrepareField set Formula?
77 const sal_Bool bStringDefault; /// default: string-value = content
78 const sal_Bool bFormulaDefault; /// default: formula = content
80 public:
81 XMLValueImportHelper(
82 SvXMLImport& rImprt, /// XML Import
83 XMLTextImportHelper& rHlp, /// text import helper
84 sal_Bool bType, /// process type (PrepareField)
85 sal_Bool bStyle, /// process data style (P.F.)
86 sal_Bool bValue, /// process value (Prep.Field)
87 sal_Bool bFormula); /// process formula (Prep.F.)
89 virtual ~XMLValueImportHelper();
91 /// process attribute values
92 virtual void ProcessAttribute( sal_uInt16 nAttrToken,
93 const OUString& sAttrValue );
95 /// prepare XTextField for insertion into document
96 virtual void PrepareField(
97 const ::com::sun::star::uno::Reference<
98 ::com::sun::star::beans::XPropertySet> & xPropertySet);
100 /// is value a string (rather than double)?
101 inline sal_Bool IsStringValue() { return bStringType; }
103 /// has format been read?
104 inline sal_Bool IsFormatOK() { return bFormatOK; }
106 inline void SetDefault(const OUString& sStr) { sDefault = sStr; }
112 * abstract parent class for all variable related fields
113 * - variable-set/get/decl (not -decls),
114 * - user-field-get/decl (not -decls),
115 * - sequence/-decl (not -decls),
116 * - expression,
117 * - text-input
119 * Processes the following attributes:
120 * - name
121 * - formula
122 * - display
123 * - value, value-type, data-style-name (via XMLValueImportHelper)
124 * - description.
126 * Each attribute has a corresponding member, a bool variable to indicate
127 * whether it was set or not, and a bool variable whether it should be set
128 * using the standard property name.
130 * bValid is set true, when name is found!
131 * (Most variable related fields are valid, if a name is
132 * found. However, some are always valid. In this case, setting bValid
133 * does not matter.)
135 class XMLVarFieldImportContext : public XMLTextFieldImportContext
137 protected:
138 const OUString sPropertyContent;
139 const OUString sPropertyHint;
140 const OUString sPropertyHelp;
141 const OUString sPropertyTooltip;
142 const OUString sPropertyIsVisible;
143 const OUString sPropertyIsDisplayFormula;
144 const OUString sPropertyCurrentPresentation;
146 private:
147 OUString sName; /// name attribute
148 OUString sFormula; /// formula attribute
149 OUString sDescription; /// description
150 OUString sHelp; /// help text
151 OUString sHint; /// hint
152 XMLValueImportHelper aValueHelper; /// value, value-type, and style
153 sal_Bool bDisplayFormula; /// display formula?(rather than value)
154 sal_Bool bDisplayNone; /// hide field?
156 sal_Bool bNameOK; /// sName was set
157 sal_Bool bFormulaOK; /// sFormula was set
158 sal_Bool bDescriptionOK; /// sDescription was set
159 sal_Bool bHelpOK; /// sHelp was set
160 sal_Bool bHintOK; /// sHint was set
161 sal_Bool bDisplayOK; /// sDisplayFormula/-None were set
163 sal_Bool bSetFormula; /// set Formula property
164 sal_Bool bSetFormulaDefault; /// use content as default for formula
165 sal_Bool bSetDescription; /// set sDescription with Hint-property
166 sal_Bool bSetHelp;
167 sal_Bool bSetHint;
168 sal_Bool bSetVisible; /// set IsVisible
169 sal_Bool bSetDisplayFormula; /// set DisplayFormula (sub type???)
170 sal_Bool bSetPresentation; /// set presentation frm elem. content?
172 public:
174 TYPEINFO();
176 XMLVarFieldImportContext(
177 // for XMLTextFieldImportContext:
178 SvXMLImport& rImport, /// XML Import
179 XMLTextImportHelper& rHlp, /// text import helper
180 const sal_Char* pServiceName, /// name of SO API service
181 sal_uInt16 nPrfx, /// namespace prefix
182 const OUString& rLocalName, /// element name w/o prefix
183 // config variables for PrepareField behavior:
184 sal_Bool bFormula, /// set Formula property
185 sal_Bool bFormulaDefault, /// use content as default for formula
186 sal_Bool bDescription, /// set sDescription with Hint-property
187 sal_Bool bHelp,
188 sal_Bool bHint,
189 sal_Bool bVisible, /// set IsVisible (display attr)
190 sal_Bool bDisplayFormula, /// set ??? (display attr.)
191 sal_Bool bType, /// set value type with ???-property
192 sal_Bool bStyle, /// set data style (NumberFormat-Prop.)
193 sal_Bool bValue, /// set value with Content/Value-Prop.
194 sal_Bool bPresentation); /// set presentation from elem. content
196 protected:
197 /// process attribute values
198 virtual void ProcessAttribute( sal_uInt16 nAttrToken,
199 const OUString& sAttrValue );
201 /// prepare XTextField for insertion into document
202 virtual void PrepareField(
203 const ::com::sun::star::uno::Reference<
204 ::com::sun::star::beans::XPropertySet> & xPropertySet);
206 // various accessor methods:
207 inline OUString GetName() { return sName; }
208 inline sal_Bool IsStringValue() { return aValueHelper.IsStringValue();}
209 inline sal_Bool IsNameOK() { return bNameOK; }
210 inline sal_Bool IsFormulaOK() { return bFormulaOK; }
211 inline sal_Bool IsDescriptionOK() { return bDescriptionOK; }
212 inline sal_Bool IsDisplayOK() { return bDisplayOK; }
217 /** import variable get fields (<text:variable-get>) */
218 class XMLVariableGetFieldImportContext : public XMLVarFieldImportContext
220 const OUString sPropertySubType;
222 public:
224 TYPEINFO();
226 XMLVariableGetFieldImportContext(
227 SvXMLImport& rImport, /// XML Import
228 XMLTextImportHelper& rHlp, /// Text import helper
229 sal_uInt16 nPrfx, /// namespace prefix
230 const OUString& rLocalName); /// element name w/o prefix
233 protected:
234 /// prepare XTextField for insertion into document
235 virtual void PrepareField(
236 const ::com::sun::star::uno::Reference<
237 ::com::sun::star::beans::XPropertySet> & xPropertySet);
242 /** import expression fields (<text:expression>) */
243 class XMLExpressionFieldImportContext : public XMLVarFieldImportContext
245 const OUString sPropertySubType;
247 public:
249 TYPEINFO();
251 XMLExpressionFieldImportContext(
252 SvXMLImport& rImport, /// XML Import
253 XMLTextImportHelper& rHlp, /// Text import helper
254 sal_uInt16 nPrfx, /// namespace prefix
255 const OUString& sLocalName); /// element name w/o prefix
257 protected:
258 virtual void PrepareField(
259 const ::com::sun::star::uno::Reference<
260 ::com::sun::star::beans::XPropertySet> & xPropertySet);
263 /*** import text input fields (<text:text-input>) */
264 class XMLTextInputFieldImportContext : public XMLVarFieldImportContext
266 const OUString sPropertyContent;
268 public:
270 TYPEINFO();
272 XMLTextInputFieldImportContext(
273 SvXMLImport& rImport, /// XML Import
274 XMLTextImportHelper& rHlp, /// Text import helper
275 sal_uInt16 nPrfx, /// namespace prefix
276 const OUString& sLocalName); /// element name w/o prefix
278 protected:
279 virtual void PrepareField(
280 const ::com::sun::star::uno::Reference<
281 ::com::sun::star::beans::XPropertySet> & xPropertySet);
290 * uperclass for variable/user-set, var/user-input, and sequence fields
291 * inds field master of appropriate type and attaches field to it.
293 class XMLSetVarFieldImportContext : public XMLVarFieldImportContext
295 const VarType eFieldType;
297 public:
299 TYPEINFO();
301 XMLSetVarFieldImportContext(
302 // for XMLTextFieldImportContext:
303 SvXMLImport& rImport, /// see XMLTextFieldImportContext
304 XMLTextImportHelper& rHlp, /// see XMLTextFieldImportContext
305 const sal_Char* pServiceName, /// see XMLTextFieldImportContext
306 sal_uInt16 nPrfx, /// see XMLTextFieldImportContext
307 const OUString& rLocalName, /// see XMLTextFieldImportContext
308 // for finding appropriate field master (see EndElement())
309 VarType eVarType, /// variable type
310 // config variables:
311 sal_Bool bFormula, /// see XMLTextFieldImportContext
312 sal_Bool bFormulaDefault, /// see XMLTextFieldImportContext
313 sal_Bool bDescription, /// see XMLTextFieldImportContext
314 sal_Bool bHelp, /// see XMLTextFieldImportContext
315 sal_Bool bHint, /// see XMLTextFieldImportContext
316 sal_Bool bVisible, /// see XMLTextFieldImportContext
317 sal_Bool bDisplayFormula, /// see XMLTextFieldImportContext
318 sal_Bool bType, /// see XMLTextFieldImportContext
319 sal_Bool bStyle, /// see XMLTextFieldImportContext
320 sal_Bool bValue, /// see XMLTextFieldImportContext
321 sal_Bool bPresentation); /// see XMLTextFieldImportContext
323 protected:
325 /// create XTextField, attach master and insert into document;
326 /// also calls PrepareTextField
327 virtual void EndElement();
329 /// find appropriate field master
330 sal_Bool FindFieldMaster(
331 ::com::sun::star::uno::Reference<
332 ::com::sun::star::beans::XPropertySet> & xMaster);
337 /** import variable set fields (<text:variable-set>) */
338 class XMLVariableSetFieldImportContext : public XMLSetVarFieldImportContext
340 const OUString sPropertySubType;
342 public:
344 TYPEINFO();
346 XMLVariableSetFieldImportContext(
347 SvXMLImport& rImport, /// XML Import
348 XMLTextImportHelper& rHlp, /// Text import helper
349 sal_uInt16 nPrfx, /// namespace prefix
350 const OUString& rLocalName); /// element name w/o prefix
352 protected:
353 /// prepare XTextField for insertion into document
354 virtual void PrepareField(
355 const ::com::sun::star::uno::Reference<
356 ::com::sun::star::beans::XPropertySet> & xPropertySet);
361 /** variable input fields (<text:variable-input>) */
362 class XMLVariableInputFieldImportContext : public XMLSetVarFieldImportContext
364 const OUString sPropertySubType;
365 const OUString sPropertyIsInput;
367 public:
369 TYPEINFO();
371 XMLVariableInputFieldImportContext(
372 SvXMLImport& rImport, /// XML Import
373 XMLTextImportHelper& rHlp, /// Text import helper
374 sal_uInt16 nPrfx, /// namespace prefix
375 const OUString& rLocalName); /// element name w/o prefix
377 protected:
379 /// prepare XTextField for insertion into document
380 virtual void PrepareField(
381 const ::com::sun::star::uno::Reference<
382 ::com::sun::star::beans::XPropertySet> & xPropertySet);
387 /** user fields (<text:user-field-get>) */
388 class XMLUserFieldImportContext : public XMLSetVarFieldImportContext
391 public:
393 TYPEINFO();
395 XMLUserFieldImportContext(
396 SvXMLImport& rImport, /// XML Import
397 XMLTextImportHelper& rHlp, /// Text import helper
398 sal_uInt16 nPrfx, /// namespace prefix
399 const OUString& rLocalName); /// element name w/o prefix
402 /** user input fields (<text:user-field-input>) */
403 class XMLUserFieldInputImportContext : public XMLVarFieldImportContext
406 public:
408 TYPEINFO();
410 XMLUserFieldInputImportContext(
411 SvXMLImport& rImport, /// XML Import
412 XMLTextImportHelper& rHlp, /// Text import helper
413 sal_uInt16 nPrfx, /// namespace prefix
414 const OUString& rLocalName); /// element name w/o prefix
416 virtual void PrepareField(
417 const ::com::sun::star::uno::Reference<
418 ::com::sun::star::beans::XPropertySet> & xPropertySet);
423 /** sequence fields (<text:sequence>) */
424 class XMLSequenceFieldImportContext : public XMLSetVarFieldImportContext
426 const OUString sPropertyFormula;
427 const OUString sPropertyNumberFormat;
428 const OUString sPropertySequenceValue;
429 OUString sFormula;
430 OUString sNumFormat;
431 OUString sNumFormatSync;
432 OUString sRefName;
434 sal_Bool bRefNameOK;
436 public:
438 TYPEINFO();
440 XMLSequenceFieldImportContext(
441 SvXMLImport& rImport, /// XML Import
442 XMLTextImportHelper& rHlp, /// Text import helper
443 sal_uInt16 nPrfx, /// namespace prefix
444 const OUString& rLocalName); /// element name w/o prefix
446 protected:
448 /// process attribute values
449 virtual void ProcessAttribute( sal_uInt16 nAttrToken,
450 const OUString& sAttrValue );
452 /// prepare XTextField for insertion into document
453 virtual void PrepareField(
454 const ::com::sun::star::uno::Reference<
455 ::com::sun::star::beans::XPropertySet> & xPropertySet);
464 * variable declaration container for all variable fields
465 * (variable-decls, user-field-decls, sequence-decls)
467 class XMLVariableDeclsImportContext : public SvXMLImportContext
469 enum VarType eVarDeclsContextType;
470 XMLTextImportHelper& rImportHelper;
472 public:
474 TYPEINFO();
476 XMLVariableDeclsImportContext(
477 SvXMLImport& rImport, /// XML Import
478 XMLTextImportHelper& rHlp, /// text import helper
479 sal_uInt16 nPrfx, /// namespace prefix
480 const OUString& rLocalName, /// element name w/o prefix
481 enum VarType eVarType); /// variable type
483 virtual SvXMLImportContext *CreateChildContext(
484 sal_uInt16 nPrefix,
485 const OUString& rLocalName,
486 const ::com::sun::star::uno::Reference<
487 ::com::sun::star::xml::sax::XAttributeList> & xAttrList );
491 * variable field declarations
492 * (variable-decl, user-field-decl, sequence-decl)
494 class XMLVariableDeclImportContext : public SvXMLImportContext
496 const OUString sPropertyName;
497 const OUString sPropertySubType;
498 const OUString sPropertyNumberingLevel;
499 const OUString sPropertyNumberingSeparator;
500 const OUString sPropertyIsExpression;
502 OUString sName;
503 XMLValueImportHelper aValueHelper;
504 sal_Int8 nNumLevel;
505 sal_Unicode cSeparationChar;
507 public:
509 TYPEINFO();
511 XMLVariableDeclImportContext(
512 SvXMLImport& rImport, /// XML Import
513 XMLTextImportHelper& rHlp, /// text import helper
514 sal_uInt16 nPrfx, /// namespace prefix
515 const OUString& rLocalName, /// element name w/o prefix
516 const ::com::sun::star::uno::Reference< /// list of element attributes
517 ::com::sun::star::xml::sax::XAttributeList> & xAttrList,
518 enum VarType eVarType); /// variable type
520 /// get field master for name and rename if appropriate
521 static sal_Bool FindFieldMaster(::com::sun::star::uno::Reference<
522 ::com::sun::star::beans::XPropertySet> & xMaster,
523 SvXMLImport& rImport,
524 XMLTextImportHelper& rHelper,
525 const OUString& sVarName,
526 enum VarType eVarType);
531 /** import table formula fields (deprecated; for Writer 2.0 compatibility) */
532 class XMLTableFormulaImportContext : public XMLTextFieldImportContext
534 const OUString sPropertyNumberFormat;
535 const OUString sPropertyContent;
536 const OUString sPropertyIsShowFormula;
537 const OUString sPropertyCurrentPresentation;
539 XMLValueImportHelper aValueHelper;
541 OUString sFormula;
543 sal_Bool bIsShowFormula;
545 public:
547 TYPEINFO();
549 XMLTableFormulaImportContext(
550 SvXMLImport& rImport, /// XML Import
551 XMLTextImportHelper& rHlp, /// text import helper
552 sal_uInt16 nPrfx, /// namespace prefix
553 const OUString& rLocalName); /// element name w/o prefix
554 virtual ~XMLTableFormulaImportContext();
556 protected:
558 /// process attribute values
559 virtual void ProcessAttribute( sal_uInt16 nAttrToken,
560 const OUString& sAttrValue );
562 /// prepare XTextField for insertion into document
563 virtual void PrepareField(
564 const ::com::sun::star::uno::Reference<
565 ::com::sun::star::beans::XPropertySet> & xPropertySet);
570 /** import database display fields (<text:database-display>) */
571 class XMLDatabaseDisplayImportContext : public XMLDatabaseFieldImportContext
573 const OUString sPropertyColumnName;
574 const OUString sPropertyDatabaseFormat;
575 const OUString sPropertyCurrentPresentation;
576 const OUString sPropertyIsVisible;
578 XMLValueImportHelper aValueHelper;
580 OUString sColumnName;
581 sal_Bool bColumnOK;
583 sal_Bool bDisplay;
584 sal_Bool bDisplayOK;
586 public:
588 TYPEINFO();
590 XMLDatabaseDisplayImportContext(
591 SvXMLImport& rImport, /// XML Import
592 XMLTextImportHelper& rHlp, /// text import helper
593 sal_uInt16 nPrfx, /// namespace prefix
594 const OUString& rLocalName); /// element name w/o prefix
596 protected:
598 /// process attribute values
599 virtual void ProcessAttribute( sal_uInt16 nAttrToken,
600 const OUString& sAttrValue );
602 /// create, prepare and insert database field master and database field
603 virtual void EndElement();
606 #endif
608 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */