LibreOffice Module writerfilter (master) 1
SdtHelper.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#pragma once
11
12#include <vector>
13#include <optional>
14#include <unordered_map>
15
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>
20
21#include <rtl/ustrbuf.hxx>
22#include <tools/ref.hxx>
23
24namespace com::sun::star
25{
26namespace uno
27{
28class XComponentContext;
29}
30namespace awt
31{
32struct Size;
33class XControlModel;
34}
35}
36
38{
39class DomainMapper_Impl;
40
42{
48 picture,
50 unsupported, // Sdt block is defined, but we still do not support such type of field
52};
53
60class SdtHelper final : public virtual SvRefBase
61{
63 css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
64
66 std::vector<OUString> m_aDropDownItems;
68 std::vector<OUString> m_aDropDownDisplayTexts;
71 sal_uInt32 m_nSdtType = 0;
73 OUStringBuffer m_aSdtTexts;
75 OUStringBuffer m_sDate;
77 OUStringBuffer m_sDateFormat;
78
85
87 css::uno::Reference<css::text::XTextRange> m_xDateFieldStartRange;
89 OUStringBuffer m_sLocale;
91 std::vector<css::beans::PropertyValue> m_aGrabBag;
92
96
98 std::unordered_map<OUString, css::uno::Reference<css::xml::dom::XDocument>> m_xPropertiesXMLs;
99
103
105 bool m_bShowingPlcHdr = false;
106
108 bool m_bChecked = false;
109
112
115
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);
120
121 void loadPropertiesXMLs();
122
125
127 OUString m_aColor;
128
131
133 OUString m_aAlias;
134
136 OUString m_aTag;
137
139 sal_Int32 m_nId = 0;
140
142 sal_uInt32 m_nTabIndex = 0;
143
145 OUString m_aLock;
146
147public:
148 explicit SdtHelper(DomainMapper_Impl& rDM_Impl,
149 css::uno::Reference<css::uno::XComponentContext> xContext);
150 ~SdtHelper() override;
151
152 std::vector<OUString>& getDropDownItems() { return m_aDropDownItems; }
153 std::vector<OUString>& getDropDownDisplayTexts() { return m_aDropDownDisplayTexts; }
154 OUStringBuffer& getSdtTexts() { return m_aSdtTexts; }
155
156 OUStringBuffer& getDate() { return m_sDate; }
157
158 OUStringBuffer& getDateFormat() { return m_sDateFormat; }
159
160 void setDataBindingPrefixMapping(const OUString& sValue)
161 {
163 }
165
166 void setDataBindingXPath(const OUString& sValue) { m_sDataBindingXPath = sValue; }
167 const OUString& GetDataBindingXPath() const { return m_sDataBindingXPath; }
168
169 void setDataBindingStoreItemID(const OUString& sValue) { m_sDataBindingStoreItemID = sValue; }
170 const OUString& GetDataBindingStoreItemID() const { return m_sDataBindingStoreItemID; }
171
172 void setDateFieldStartRange(const css::uno::Reference<css::text::XTextRange>& xStartRange)
173 {
174 m_xDateFieldStartRange = xStartRange;
175 }
176
177 OUStringBuffer& getLocale() { return m_sLocale; }
179 bool hasElements() const { return m_bHasElements; }
180
181 void setOutsideAParagraph(bool bOutsideAParagraph)
182 {
183 m_bOutsideAParagraph = bOutsideAParagraph;
184 }
185
187
190
191 void SetSdtType(sal_uInt32 nSdtType) { m_nSdtType = nSdtType; }
192 sal_uInt32 GetSdtType() const { return m_nSdtType; }
193
198
200
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;
206
207 void SetShowingPlcHdr();
208 bool GetShowingPlcHdr() const;
209
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;
216
218 void clear();
219
220 void SetPlaceholderDocPart(const OUString& rPlaceholderDocPart);
221 const OUString& GetPlaceholderDocPart() const;
222
223 void SetColor(const OUString& rColor);
224 const OUString& GetColor() const;
225
226 void SetAppearance(const OUString& rAppearance);
227 const OUString& GetAppearance() const;
228
229 void SetAlias(const OUString& rAlias);
230 const OUString& GetAlias() const;
231
232 void SetTag(const OUString& rTag);
233 const OUString& GetTag() const;
234
235 void SetId(sal_Int32 nId);
236 sal_Int32 GetId() const;
237
238 void SetTabIndex(sal_uInt32 nTabIndex);
239 sal_uInt32 GetTabIndex() const;
240
241 void SetLock(const OUString& rLock);
242 const OUString& GetLock() const;
243
244 std::optional<OUString> getValueFromDataBinding();
245};
246
247} // namespace writerfilter::dmapper
248
249/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper to create form controls from w:sdt tokens.
Definition: SdtHelper.hxx:61
void SetAlias(const OUString &rAlias)
Definition: SdtHelper.cxx:548
OUStringBuffer m_sDate
Date ISO string contained in the w:date element, used by the date control.
Definition: SdtHelper.hxx:75
OUString m_sDataBindingPrefixMapping
<w:dataBinding w:prefixMappings="">
Definition: SdtHelper.hxx:80
void SetSdtType(sal_uInt32 nSdtType)
Definition: SdtHelper.hxx:191
const OUString & GetColor() const
Definition: SdtHelper.cxx:542
void setDateFieldStartRange(const css::uno::Reference< css::text::XTextRange > &xStartRange)
Definition: SdtHelper.hxx:172
sal_uInt32 GetSdtType() const
Definition: SdtHelper.hxx:192
void setDataBindingPrefixMapping(const OUString &sValue)
Definition: SdtHelper.hxx:160
void SetCheckedState(const OUString &rCheckedState)
Definition: SdtHelper.cxx:499
const OUString & GetDataBindingXPath() const
Definition: SdtHelper.hxx:167
std::optional< OUString > getValueFromDataBinding()
Definition: SdtHelper.cxx:212
OUStringBuffer & getLocale()
Definition: SdtHelper.hxx:177
void setOutsideAParagraph(bool bOutsideAParagraph)
Definition: SdtHelper.hxx:181
void SetTabIndex(sal_uInt32 nTabIndex)
Definition: SdtHelper.cxx:560
bool m_bShowingPlcHdr
Current contents are placeholder text.
Definition: SdtHelper.hxx:105
const OUString & GetCheckedState() const
Definition: SdtHelper.cxx:501
std::unordered_map< OUString, css::uno::Reference< css::xml::dom::XDocument > > m_xPropertiesXMLs
Storage for all properties documents as xml::dom::XDocument for later querying xpath for data.
Definition: SdtHelper.hxx:98
sal_uInt32 m_nTabIndex
<w:sdtPr>'s <w:tabIndex w:val="...">.
Definition: SdtHelper.hxx:142
void SetAppearance(const OUString &rAppearance)
Definition: SdtHelper.cxx:544
void SetColor(const OUString &rColor)
Definition: SdtHelper.cxx:540
std::vector< OUString > m_aDropDownDisplayTexts
Display texts of a drop-down control: <w:listItem w:displayText="...">.
Definition: SdtHelper.hxx:68
const OUString & GetPlaceholderDocPart() const
Definition: SdtHelper.cxx:538
OUString m_aPlaceholderDocPart
<w:placeholder>'s <w:docPart w:val="...">.
Definition: SdtHelper.hxx:124
bool containedInInteropGrabBag(const OUString &rValueName)
Definition: SdtHelper.cxx:484
OUString m_aAlias
<w:sdtPr>'s <w:alias w:val="...">.
Definition: SdtHelper.hxx:133
std::vector< OUString > & getDropDownDisplayTexts()
Definition: SdtHelper.hxx:153
std::vector< css::beans::PropertyValue > m_aGrabBag
Grab bag to store unsupported SDTs, aiming to save them back on export.
Definition: SdtHelper.hxx:91
OUStringBuffer m_sDateFormat
Date format string as it comes from the ooxml document.
Definition: SdtHelper.hxx:77
std::vector< OUString > m_aDropDownItems
Items of the drop-down control: <w:listItem w:value="...">.
Definition: SdtHelper.hxx:66
const OUString & GetLock() const
Definition: SdtHelper.cxx:566
OUString m_aColor
<w:sdtPr>'s <w15:color w:val="...">.
Definition: SdtHelper.hxx:127
OUStringBuffer m_aSdtTexts
Pieces of the default text – currently used only by the dropdown control.
Definition: SdtHelper.hxx:73
void appendToInteropGrabBag(const css::beans::PropertyValue &rValue)
Definition: SdtHelper.cxx:468
void setDataBindingStoreItemID(const OUString &sValue)
Definition: SdtHelper.hxx:169
bool hasElements() const
If createControlShape() was ever called.
Definition: SdtHelper.hxx:179
const OUString & GetUncheckedState() const
Definition: SdtHelper.cxx:508
void createDateContentControl()
Create date control from w:sdt's w:date.
Definition: SdtHelper.cxx:364
bool m_bChecked
If this is a checkbox, is the checkbox checked?
Definition: SdtHelper.hxx:108
void createControlShape(css::awt::Size aSize, css::uno::Reference< css::awt::XControlModel > const &xControlModel, const css::uno::Sequence< css::beans::PropertyValue > &rGrabBag)
Create and append the drawing::XControlShape, containing the various models.
Definition: SdtHelper.cxx:447
void SetPlaceholderDocPart(const OUString &rPlaceholderDocPart)
Definition: SdtHelper.cxx:533
bool m_bPropertiesXMLsLoaded
Check if m_xPropertiesXMLs is initialized and loaded (need extra flag to distinguish empty sequence f...
Definition: SdtHelper.hxx:102
sal_Int32 getInteropGrabBagSize() const
Definition: SdtHelper.cxx:482
css::uno::Sequence< css::beans::PropertyValue > getInteropGrabBagAndClear()
Definition: SdtHelper.cxx:473
void SetTag(const OUString &rTag)
Definition: SdtHelper.cxx:552
OUStringBuffer m_sLocale
Locale string as it comes from the ooxml document.
Definition: SdtHelper.hxx:89
SdtHelper(DomainMapper_Impl &rDM_Impl, css::uno::Reference< css::uno::XComponentContext > xContext)
Definition: SdtHelper.cxx:81
void setControlType(SdtControlType aType)
Definition: SdtHelper.hxx:189
OUString m_sDataBindingStoreItemID
<w:dataBinding w:storeItemID="">
Definition: SdtHelper.hxx:84
OUString m_aLock
<w:sdtPr>'s <w:lock w:val="...">.
Definition: SdtHelper.hxx:145
OUStringBuffer & getSdtTexts()
Definition: SdtHelper.hxx:154
OUString m_sDataBindingXPath
<w:dataBinding w:xpath="">
Definition: SdtHelper.hxx:82
void setDataBindingXPath(const OUString &sValue)
Definition: SdtHelper.hxx:166
OUStringBuffer & getDateFormat()
Definition: SdtHelper.hxx:158
bool m_bOutsideAParagraph
The last stored SDT element is outside paragraphs.
Definition: SdtHelper.hxx:95
void clear()
Clear all collected attributes for further reuse.
Definition: SdtHelper.cxx:510
SdtControlType m_aControlType
Type of sdt control.
Definition: SdtHelper.hxx:70
const OUString & GetAlias() const
Definition: SdtHelper.cxx:550
DomainMapper_Impl & m_rDM_Impl
Definition: SdtHelper.hxx:62
const OUString & GetTag() const
Definition: SdtHelper.cxx:554
OUString m_aCheckedState
If this is a checkbox, the value of a checked checkbox.
Definition: SdtHelper.hxx:111
css::uno::Reference< css::text::XTextRange > m_xDateFieldStartRange
Start range of the date field.
Definition: SdtHelper.hxx:87
void SetUncheckedState(const OUString &rUncheckedState)
Definition: SdtHelper.cxx:503
sal_Int32 m_nId
<w:sdtPr>'s <w:id w:val="...">.
Definition: SdtHelper.hxx:139
OUString m_aTag
<w:sdtPr>'s <w:tag w:val="...">.
Definition: SdtHelper.hxx:136
std::vector< OUString > & getDropDownItems()
Definition: SdtHelper.hxx:152
const OUString & GetAppearance() const
Definition: SdtHelper.cxx:546
OUString m_aUncheckedState
If this is a checkbox, the value of an unchecked checkbox.
Definition: SdtHelper.hxx:114
const OUString & GetDataBindingStoreItemID() const
Definition: SdtHelper.hxx:170
void SetLock(const OUString &rLock)
Definition: SdtHelper.cxx:564
OUString m_aAppearance
<w:sdtPr>'s <w15:appearance w:val="...">.
Definition: SdtHelper.hxx:130
sal_uInt32 GetTabIndex() const
Definition: SdtHelper.cxx:562
void createDropDownControl()
Create drop-down control from w:sdt's w:dropDownList.
Definition: SdtHelper.cxx:273
const OUString & GetDataBindingPrefixMapping() const
Definition: SdtHelper.hxx:164
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
Definition: SdtHelper.hxx:63
@ picture