android: Update app-specific/MIME type icons
[LibreOffice.git] / writerfilter / source / dmapper / SdtHelper.hxx
blob6803db16ef06e9bf66a258a41c4019f02fa3c366
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/.
8 */
10 #pragma once
12 #include <vector>
13 #include <optional>
14 #include <unordered_map>
16 #include <com/sun/star/beans/PropertyValue.hpp>
17 #include <com/sun/star/text/XTextRange.hpp>
18 #include <com/sun/star/uno/Sequence.hxx>
19 #include <com/sun/star/xml/dom/XDocument.hpp>
21 #include <rtl/ustrbuf.hxx>
22 #include <tools/ref.hxx>
24 namespace com::sun::star
26 namespace uno
28 class XComponentContext;
30 namespace awt
32 struct Size;
33 class XControlModel;
37 namespace writerfilter::dmapper
39 class DomainMapper_Impl;
41 enum class SdtControlType
43 datePicker,
44 dropDown,
45 plainText,
46 richText,
47 checkBox,
48 picture,
49 comboBox,
50 unsupported, // Sdt block is defined, but we still do not support such type of field
51 unknown
54 /**
55 * Helper to create form controls from w:sdt tokens.
57 * w:sdt tokens can't be imported as form fields, as w:sdt supports
58 * e.g. date picking as well.
60 class SdtHelper final : public virtual SvRefBase
62 DomainMapper_Impl& m_rDM_Impl;
63 css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
65 /// Items of the drop-down control: <w:listItem w:value="...">.
66 std::vector<OUString> m_aDropDownItems;
67 /// Display texts of a drop-down control: <w:listItem w:displayText="...">.
68 std::vector<OUString> m_aDropDownDisplayTexts;
69 /// Type of sdt control
70 SdtControlType m_aControlType;
71 sal_uInt32 m_nSdtType = 0;
72 /// Pieces of the default text -- currently used only by the dropdown control.
73 OUStringBuffer m_aSdtTexts;
74 /// Date ISO string contained in the w:date element, used by the date control.
75 OUStringBuffer m_sDate;
76 /// Date format string as it comes from the ooxml document.
77 OUStringBuffer m_sDateFormat;
79 /// <w:dataBinding w:prefixMappings="">
80 OUString m_sDataBindingPrefixMapping;
81 /// <w:dataBinding w:xpath="">
82 OUString m_sDataBindingXPath;
83 /// <w:dataBinding w:storeItemID="">
84 OUString m_sDataBindingStoreItemID;
86 /// Start range of the date field
87 css::uno::Reference<css::text::XTextRange> m_xDateFieldStartRange;
88 /// Locale string as it comes from the ooxml document.
89 OUStringBuffer m_sLocale;
90 /// Grab bag to store unsupported SDTs, aiming to save them back on export.
91 std::vector<css::beans::PropertyValue> m_aGrabBag;
93 bool m_bHasElements;
94 /// The last stored SDT element is outside paragraphs.
95 bool m_bOutsideAParagraph;
97 /// Storage for all properties documents as xml::dom::XDocument for later querying xpath for data
98 std::unordered_map<OUString, css::uno::Reference<css::xml::dom::XDocument>> m_xPropertiesXMLs;
100 /// Check if m_xPropertiesXMLs is initialized and loaded (need extra flag to distinguish
101 /// empty sequence from not yet initialized)
102 bool m_bPropertiesXMLsLoaded;
104 /// Current contents are placeholder text.
105 bool m_bShowingPlcHdr = false;
107 /// If this is a checkbox, is the checkbox checked?
108 bool m_bChecked = false;
110 /// If this is a checkbox, the value of a checked checkbox.
111 OUString m_aCheckedState;
113 /// If this is a checkbox, the value of an unchecked checkbox.
114 OUString m_aUncheckedState;
116 /// Create and append the drawing::XControlShape, containing the various models.
117 void createControlShape(css::awt::Size aSize,
118 css::uno::Reference<css::awt::XControlModel> const& xControlModel,
119 const css::uno::Sequence<css::beans::PropertyValue>& rGrabBag);
121 void loadPropertiesXMLs();
123 /// <w:placeholder>'s <w:docPart w:val="...">.
124 OUString m_aPlaceholderDocPart;
126 /// <w:sdtPr>'s <w15:color w:val="...">.
127 OUString m_aColor;
129 /// <w:sdtPr>'s <w15:appearance w:val="...">.
130 OUString m_aAppearance;
132 /// <w:sdtPr>'s <w:alias w:val="...">.
133 OUString m_aAlias;
135 /// <w:sdtPr>'s <w:tag w:val="...">.
136 OUString m_aTag;
138 /// <w:sdtPr>'s <w:id w:val="...">.
139 sal_Int32 m_nId = 0;
141 /// <w:sdtPr>'s <w:tabIndex w:val="...">.
142 sal_uInt32 m_nTabIndex = 0;
144 /// <w:sdtPr>'s <w:lock w:val="...">.
145 OUString m_aLock;
147 public:
148 explicit SdtHelper(DomainMapper_Impl& rDM_Impl,
149 css::uno::Reference<css::uno::XComponentContext> xContext);
150 ~SdtHelper() override;
152 std::vector<OUString>& getDropDownItems() { return m_aDropDownItems; }
153 std::vector<OUString>& getDropDownDisplayTexts() { return m_aDropDownDisplayTexts; }
154 OUStringBuffer& getSdtTexts() { return m_aSdtTexts; }
156 OUStringBuffer& getDate() { return m_sDate; }
158 OUStringBuffer& getDateFormat() { return m_sDateFormat; }
160 void setDataBindingPrefixMapping(const OUString& sValue)
162 m_sDataBindingPrefixMapping = sValue;
164 const OUString& GetDataBindingPrefixMapping() const { return m_sDataBindingPrefixMapping; }
166 void setDataBindingXPath(const OUString& sValue) { m_sDataBindingXPath = sValue; }
167 const OUString& GetDataBindingXPath() const { return m_sDataBindingXPath; }
169 void setDataBindingStoreItemID(const OUString& sValue) { m_sDataBindingStoreItemID = sValue; }
170 const OUString& GetDataBindingStoreItemID() const { return m_sDataBindingStoreItemID; }
172 void setDateFieldStartRange(const css::uno::Reference<css::text::XTextRange>& xStartRange)
174 m_xDateFieldStartRange = xStartRange;
177 OUStringBuffer& getLocale() { return m_sLocale; }
178 /// If createControlShape() was ever called.
179 bool hasElements() const { return m_bHasElements; }
181 void setOutsideAParagraph(bool bOutsideAParagraph)
183 m_bOutsideAParagraph = bOutsideAParagraph;
186 bool isOutsideAParagraph() const { return m_bOutsideAParagraph; }
188 SdtControlType getControlType() { return m_aControlType; }
189 void setControlType(SdtControlType aType) { m_aControlType = aType; }
191 void SetSdtType(sal_uInt32 nSdtType) { m_nSdtType = nSdtType; }
192 sal_uInt32 GetSdtType() const { return m_nSdtType; }
194 /// Create drop-down control from w:sdt's w:dropDownList.
195 void createDropDownControl();
196 /// Create date control from w:sdt's w:date.
197 void createDateContentControl();
199 void createPlainTextControl();
201 void appendToInteropGrabBag(const css::beans::PropertyValue& rValue);
202 css::uno::Sequence<css::beans::PropertyValue> getInteropGrabBagAndClear();
203 bool isInteropGrabBagEmpty() const;
204 bool containedInInteropGrabBag(const OUString& rValueName);
205 sal_Int32 getInteropGrabBagSize() const;
207 void SetShowingPlcHdr();
208 bool GetShowingPlcHdr() const;
210 void SetChecked();
211 bool GetChecked() const;
212 void SetCheckedState(const OUString& rCheckedState);
213 const OUString& GetCheckedState() const;
214 void SetUncheckedState(const OUString& rUncheckedState);
215 const OUString& GetUncheckedState() const;
217 /// Clear all collected attributes for further reuse
218 void clear();
220 void SetPlaceholderDocPart(const OUString& rPlaceholderDocPart);
221 const OUString& GetPlaceholderDocPart() const;
223 void SetColor(const OUString& rColor);
224 const OUString& GetColor() const;
226 void SetAppearance(const OUString& rAppearance);
227 const OUString& GetAppearance() const;
229 void SetAlias(const OUString& rAlias);
230 const OUString& GetAlias() const;
232 void SetTag(const OUString& rTag);
233 const OUString& GetTag() const;
235 void SetId(sal_Int32 nId);
236 sal_Int32 GetId() const;
238 void SetTabIndex(sal_uInt32 nTabIndex);
239 sal_uInt32 GetTabIndex() const;
241 void SetLock(const OUString& rLock);
242 const OUString& GetLock() const;
244 std::optional<OUString> getValueFromDataBinding();
247 } // namespace writerfilter::dmapper
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */