add a SwFrameDeleteGuard to SwSaveFootnoteHeight
[LibreOffice.git] / xmloff / inc / txtvfldi.hxx
blobd5a4176d5dd2c9834af093db2a7003ffea2569bf
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 #pragma once
27 #include "txtfldi.hxx"
28 #include <com/sun/star/beans/XPropertySet.hpp>
31 /** helper class: parses value-type and associated value attributes */
32 class XMLValueImportHelper final
34 SvXMLImport& rImport;
35 XMLTextImportHelper& rHelper;
37 OUString sValue; /// string value (only valid if bStringValueOK)
38 double fValue; /// double value (only valid if bFloatValueOK)
39 sal_Int32 nFormatKey; /// format key (only valid of bFormatOK)
40 OUString sFormula; /// formula string
41 OUString sDefault; /// default (see bStringDefault/bFormulaDef.)
42 bool bIsDefaultLanguage;/// format (of nFormatKey) has system language?
44 bool bStringType; /// is this a string (or a float) type?
45 bool bFormatOK; /// have we read a style:data-style-name attr.?
46 bool bStringValueOK; /// have we read a string-value attr.?
47 bool bFormulaOK; /// have we read the formula attribute?
49 const bool bSetType; /// should PrepareField set the SetExp subtype?
50 const bool bSetValue; /// should PrepareField set content/value?
51 const bool bSetStyle; /// should PrepareField set NumberFormat?
52 const bool bSetFormula; /// should PrepareField set Formula?
54 public:
55 XMLValueImportHelper(
56 SvXMLImport& rImprt, /// XML Import
57 XMLTextImportHelper& rHlp, /// text import helper
58 bool bType, /// process type (PrepareField)
59 bool bStyle, /// process data style (P.F.)
60 bool bValue, /// process value (Prep.Field)
61 bool bFormula); /// process formula (Prep.F.)
63 /// process attribute values
64 void ProcessAttribute( sal_Int32 nAttrToken,
65 std::string_view sAttrValue );
67 /// prepare XTextField for insertion into document
68 void PrepareField(
69 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet);
71 /// is value a string (rather than double)?
72 bool IsStringValue() const { return bStringType; }
74 /// has format been read?
75 bool IsFormatOK() const { return bFormatOK; }
77 void SetDefault(const OUString& sStr) { sDefault = sStr; }
81 /**
82 * abstract parent class for all variable related fields
83 * - variable-set/get/decl (not -decls),
84 * - user-field-get/decl (not -decls),
85 * - sequence/-decl (not -decls),
86 * - expression,
87 * - text-input
89 * Processes the following attributes:
90 * - name
91 * - formula
92 * - display
93 * - value, value-type, data-style-name (via XMLValueImportHelper)
94 * - description.
96 * Each attribute has a corresponding member, a bool variable to indicate
97 * whether it was set or not, and a bool variable whether it should be set
98 * using the standard property name.
100 * bValid is set true, when name is found!
101 * (Most variable related fields are valid, if a name is
102 * found. However, some are always valid. In this case, setting bValid
103 * does not matter.)
105 class XMLVarFieldImportContext : public XMLTextFieldImportContext
107 private:
108 OUString sName; /// name attribute
109 OUString sFormula; /// formula attribute
110 OUString sDescription; /// description
111 OUString sHelp; /// help text
112 OUString sHint; /// hint
113 XMLValueImportHelper aValueHelper; /// value, value-type, and style
114 bool bDisplayFormula; /// display formula?(rather than value)
115 bool bDisplayNone; /// hide field?
117 bool bFormulaOK; /// sFormula was set
118 bool bDescriptionOK; /// sDescription was set
119 bool bHelpOK; /// sHelp was set
120 bool bHintOK; /// sHint was set
121 bool bDisplayOK; /// sDisplayFormula/-None were set
123 bool bSetFormula; /// set Formula property
124 bool bSetFormulaDefault; /// use content as default for formula
125 bool bSetDescription; /// set sDescription with Hint-property
126 bool bSetHelp;
127 bool bSetHint;
128 bool bSetVisible; /// set IsVisible
129 bool bSetDisplayFormula; /// set DisplayFormula (sub type???)
130 bool bSetPresentation; /// set presentation frm elem. content?
132 public:
135 XMLVarFieldImportContext(
136 // for XMLTextFieldImportContext:
137 SvXMLImport& rImport, /// XML Import
138 XMLTextImportHelper& rHlp, /// text import helper
139 const OUString& pServiceName, /// name of SO API service
140 // config variables for PrepareField behavior:
141 bool bFormula, /// set Formula property
142 bool bFormulaDefault, /// use content as default for formula
143 bool bDescription, /// set sDescription with Hint-property
144 bool bHelp,
145 bool bHint,
146 bool bVisible, /// set IsVisible (display attr)
147 bool bDisplayFormula, /// set ??? (display attr.)
148 bool bType, /// set value type with ???-property
149 bool bStyle, /// set data style (NumberFormat-Prop.)
150 bool bValue, /// set value with Content/Value-Prop.
151 bool bPresentation); /// set presentation from elem. content
153 protected:
154 /// process attribute values
155 virtual void ProcessAttribute( sal_Int32 nAttrToken,
156 std::string_view sAttrValue ) override;
158 /// prepare XTextField for insertion into document
159 virtual void PrepareField(
160 const css::uno::Reference<
161 css::beans::XPropertySet> & xPropertySet) override;
163 // various accessor methods:
164 const OUString& GetName() const { return sName; }
165 bool IsStringValue() const { return aValueHelper.IsStringValue();}
169 /** import variable get fields (<text:variable-get>) */
170 class XMLVariableGetFieldImportContext final : public XMLVarFieldImportContext
172 public:
175 XMLVariableGetFieldImportContext(
176 SvXMLImport& rImport, /// XML Import
177 XMLTextImportHelper& rHlp); /// Text import helper
180 private:
181 /// prepare XTextField for insertion into document
182 virtual void PrepareField(
183 const css::uno::Reference<
184 css::beans::XPropertySet> & xPropertySet) override;
188 /** import expression fields (<text:expression>) */
189 class XMLExpressionFieldImportContext final : public XMLVarFieldImportContext
191 public:
193 XMLExpressionFieldImportContext(
194 SvXMLImport& rImport, /// XML Import
195 XMLTextImportHelper& rHlp); /// Text import helper
197 private:
198 virtual void PrepareField(
199 const css::uno::Reference<
200 css::beans::XPropertySet> & xPropertySet) override;
203 /*** import text input fields (<text:text-input>) */
204 class XMLTextInputFieldImportContext final : public XMLVarFieldImportContext
206 public:
208 XMLTextInputFieldImportContext(
209 SvXMLImport& rImport, /// XML Import
210 XMLTextImportHelper& rHlp); /// Text import helper
212 private:
213 virtual void PrepareField(
214 const css::uno::Reference<
215 css::beans::XPropertySet> & xPropertySet) override;
220 * upperclass for variable/user-set, var/user-input, and sequence fields
221 * inds field master of appropriate type and attaches field to it.
223 class XMLSetVarFieldImportContext : public XMLVarFieldImportContext
225 const VarType eFieldType;
227 public:
230 XMLSetVarFieldImportContext(
231 // for XMLTextFieldImportContext:
232 SvXMLImport& rImport, /// see XMLTextFieldImportContext
233 XMLTextImportHelper& rHlp, /// see XMLTextFieldImportContext
234 const OUString& pServiceName, /// see XMLTextFieldImportContext
235 // for finding appropriate field master (see endFastElement())
236 VarType eVarType, /// variable type
237 // config variables:
238 bool bFormula, /// see XMLTextFieldImportContext
239 bool bFormulaDefault, /// see XMLTextFieldImportContext
240 bool bDescription, /// see XMLTextFieldImportContext
241 bool bHelp, /// see XMLTextFieldImportContext
242 bool bHint, /// see XMLTextFieldImportContext
243 bool bVisible, /// see XMLTextFieldImportContext
244 bool bDisplayFormula, /// see XMLTextFieldImportContext
245 bool bType, /// see XMLTextFieldImportContext
246 bool bStyle, /// see XMLTextFieldImportContext
247 bool bValue, /// see XMLTextFieldImportContext
248 bool bPresentation); /// see XMLTextFieldImportContext
250 protected:
252 /// create XTextField, attach master and insert into document;
253 /// also calls PrepareTextField
254 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
256 /// find appropriate field master
257 bool FindFieldMaster(
258 css::uno::Reference<
259 css::beans::XPropertySet> & xMaster);
263 /** import variable set fields (<text:variable-set>) */
264 class XMLVariableSetFieldImportContext final : public XMLSetVarFieldImportContext
266 public:
268 XMLVariableSetFieldImportContext(
269 SvXMLImport& rImport, /// XML Import
270 XMLTextImportHelper& rHlp); /// Text import helper
272 private:
273 /// prepare XTextField for insertion into document
274 virtual void PrepareField(
275 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
279 /** variable input fields (<text:variable-input>) */
280 class XMLVariableInputFieldImportContext final : public XMLSetVarFieldImportContext
282 public:
285 XMLVariableInputFieldImportContext(
286 SvXMLImport& rImport, /// XML Import
287 XMLTextImportHelper& rHlp); /// Text import helper
289 private:
291 /// prepare XTextField for insertion into document
292 virtual void PrepareField(
293 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
297 /** user fields (<text:user-field-get>) */
298 class XMLUserFieldImportContext final : public XMLSetVarFieldImportContext
301 public:
304 XMLUserFieldImportContext(
305 SvXMLImport& rImport, /// XML Import
306 XMLTextImportHelper& rHlp); /// Text import helper
309 /** user input fields (<text:user-field-input>) */
310 class XMLUserFieldInputImportContext final : public XMLVarFieldImportContext
313 public:
316 XMLUserFieldInputImportContext(
317 SvXMLImport& rImport, /// XML Import
318 XMLTextImportHelper& rHlp); /// Text import helper
320 virtual void PrepareField(
321 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
325 /** sequence fields (<text:sequence>) */
326 class XMLSequenceFieldImportContext final : public XMLSetVarFieldImportContext
328 OUString sNumFormat;
329 OUString sNumFormatSync;
330 OUString sRefName;
332 bool bRefNameOK;
334 public:
337 XMLSequenceFieldImportContext(
338 SvXMLImport& rImport, /// XML Import
339 XMLTextImportHelper& rHlp); /// Text import helper
341 private:
343 /// process attribute values
344 virtual void ProcessAttribute( sal_Int32 nAttrToken,
345 std::string_view sAttrValue ) override;
347 /// prepare XTextField for insertion into document
348 virtual void PrepareField(
349 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
354 * variable declaration container for all variable fields
355 * (variable-decls, user-field-decls, sequence-decls)
357 class XMLVariableDeclsImportContext final : public SvXMLImportContext
359 enum VarType eVarDeclsContextType;
360 XMLTextImportHelper& rImportHelper;
362 public:
364 XMLVariableDeclsImportContext(
365 SvXMLImport& rImport, /// XML Import
366 XMLTextImportHelper& rHlp, /// text import helper
367 enum VarType eVarType); /// variable type
369 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
370 sal_Int32 nElement,
371 const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
375 * variable field declarations
376 * (variable-decl, user-field-decl, sequence-decl)
378 class XMLVariableDeclImportContext final : public SvXMLImportContext
380 public:
383 XMLVariableDeclImportContext(
384 SvXMLImport& rImport, /// XML Import
385 XMLTextImportHelper& rHlp, /// text import helper
386 sal_Int32 nElement,
387 const css::uno::Reference< css::xml::sax::XFastAttributeList> & xAttrList,/// list of element attributes
388 enum VarType eVarType); /// variable type
390 /// get field master for name and rename if appropriate
391 static bool FindFieldMaster(css::uno::Reference<css::beans::XPropertySet> & xMaster,
392 SvXMLImport& rImport,
393 XMLTextImportHelper& rHelper,
394 const OUString& sVarName,
395 enum VarType eVarType);
399 /** import table formula fields (deprecated; for Writer 2.0 compatibility) */
400 class XMLTableFormulaImportContext final : public XMLTextFieldImportContext
402 XMLValueImportHelper aValueHelper;
404 bool bIsShowFormula;
406 public:
408 XMLTableFormulaImportContext(
409 SvXMLImport& rImport, /// XML Import
410 XMLTextImportHelper& rHlp); /// text import helper
412 private:
414 /// process attribute values
415 virtual void ProcessAttribute( sal_Int32 nAttrToken,
416 std::string_view sAttrValue ) override;
418 /// prepare XTextField for insertion into document
419 virtual void PrepareField(
420 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
424 /** import database display fields (<text:database-display>) */
425 class XMLDatabaseDisplayImportContext final : public XMLDatabaseFieldImportContext
427 XMLValueImportHelper aValueHelper;
429 OUString sColumnName;
430 bool bColumnOK;
432 bool bDisplay;
433 bool bDisplayOK;
435 public:
438 XMLDatabaseDisplayImportContext(
439 SvXMLImport& rImport, /// XML Import
440 XMLTextImportHelper& rHlp); /// text import helper
442 private:
444 /// process attribute values
445 virtual void ProcessAttribute( sal_Int32 nAttrToken,
446 std::string_view sAttrValue ) override;
448 /// create, prepare and insert database field master and database field
449 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
452 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */