LibreOffice Module xmloff (master) 1
xmlcontentcontrolcontext.cxx
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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
22#include <com/sun/star/beans/XPropertySet.hpp>
23
25#include <xmloff/xmlimp.hxx>
27#include <xmloff/xmltoken.hxx>
30
32#include "txtparai.hxx"
33
34using namespace com::sun::star;
35using namespace xmloff::token;
36
37XMLContentControlContext::XMLContentControlContext(SvXMLImport& rImport, sal_Int32 /*nElement*/,
38 XMLHints_Impl& rHints, bool& rIgnoreLeadingSpace)
39 : SvXMLImportContext(rImport)
40 , m_rHints(rHints)
41 , m_rIgnoreLeadingSpace(rIgnoreLeadingSpace)
42 , m_xStart(GetImport().GetTextImport()->GetCursorAsRange()->getStart())
43{
44}
45
47 sal_Int32 /*nElement*/, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
48{
49 for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
50 {
51 bool bTmp = false;
52 sal_Int32 nTmp = 0;
53
54 switch (rIter.getToken())
55 {
57 {
58 if (sax::Converter::convertBool(bTmp, rIter.toView()))
59 {
61 }
62 break;
63 }
64 case XML_ELEMENT(LO_EXT, XML_CHECKBOX):
65 {
66 if (sax::Converter::convertBool(bTmp, rIter.toView()))
67 {
68 m_bCheckbox = bTmp;
69 }
70 break;
71 }
72 case XML_ELEMENT(LO_EXT, XML_CHECKED):
73 {
74 if (sax::Converter::convertBool(bTmp, rIter.toView()))
75 {
76 m_bChecked = bTmp;
77 }
78 break;
79 }
80 case XML_ELEMENT(LO_EXT, XML_CHECKED_STATE):
81 {
82 m_aCheckedState = rIter.toString();
83 break;
84 }
85 case XML_ELEMENT(LO_EXT, XML_UNCHECKED_STATE):
86 {
87 m_aUncheckedState = rIter.toString();
88 break;
89 }
90 case XML_ELEMENT(LO_EXT, XML_PICTURE):
91 {
92 if (sax::Converter::convertBool(bTmp, rIter.toView()))
93 {
94 m_bPicture = bTmp;
95 }
96 break;
97 }
98 case XML_ELEMENT(LO_EXT, XML_DATE):
99 {
100 if (sax::Converter::convertBool(bTmp, rIter.toView()))
101 {
102 m_bDate = bTmp;
103 }
104 break;
105 }
106 case XML_ELEMENT(LO_EXT, XML_DATE_FORMAT):
107 {
108 m_aDateFormat = rIter.toString();
109 break;
110 }
112 {
113 m_aDateLanguage = rIter.toString();
114 break;
115 }
116 case XML_ELEMENT(LO_EXT, XML_CURRENT_DATE):
117 {
118 m_aCurrentDate = rIter.toString();
119 break;
120 }
121 case XML_ELEMENT(LO_EXT, XML_PLAIN_TEXT):
122 {
123 if (sax::Converter::convertBool(bTmp, rIter.toView()))
124 {
125 m_bPlainText = bTmp;
126 }
127 break;
128 }
129 case XML_ELEMENT(LO_EXT, XML_COMBOBOX):
130 {
131 if (sax::Converter::convertBool(bTmp, rIter.toView()))
132 {
133 m_bComboBox = bTmp;
134 }
135 break;
136 }
137 case XML_ELEMENT(LO_EXT, XML_DROPDOWN):
138 {
139 if (sax::Converter::convertBool(bTmp, rIter.toView()))
140 {
141 m_bDropDown = bTmp;
142 }
143 break;
144 }
145 case XML_ELEMENT(LO_EXT, XML_ALIAS):
146 {
147 m_aAlias = rIter.toString();
148 break;
149 }
150 case XML_ELEMENT(LO_EXT, XML_TAG):
151 {
152 m_aTag = rIter.toString();
153 break;
154 }
155 case XML_ELEMENT(LO_EXT, XML_ID):
156 {
157 if (sax::Converter::convertNumber(nTmp, rIter.toView()))
158 {
159 m_nId = nTmp;
160 }
161 break;
162 }
163 case XML_ELEMENT(LO_EXT, XML_TAB_INDEX):
164 {
165 if (sax::Converter::convertNumber(nTmp, rIter.toView()))
166 {
167 m_nTabIndex = nTmp;
168 }
169 break;
170 }
171 case XML_ELEMENT(LO_EXT, XML_LOCK):
172 {
173 m_aLock = rIter.toString();
174 break;
175 }
176 default:
177 XMLOFF_WARN_UNKNOWN("xmloff", rIter);
178 }
179 }
180}
181
183{
184 if (!m_xStart.is())
185 {
186 SAL_WARN("xmloff.text", "XMLContentControlContext::endFastElement: no m_xStart");
187 return;
188 }
189
190 uno::Reference<text::XTextRange> xEndRange
191 = GetImport().GetTextImport()->GetCursorAsRange()->getStart();
192
193 // Create range for insertion.
194 uno::Reference<text::XTextCursor> xInsertionCursor
195 = GetImport().GetTextImport()->GetText()->createTextCursorByRange(xEndRange);
196 xInsertionCursor->gotoRange(m_xStart, /*bExpand=*/true);
197
198 uno::Reference<text::XTextContent> xContentControl
200 GetImport(), "com.sun.star.text.ContentControl", OUString(), xInsertionCursor);
201 if (!xContentControl.is())
202 {
203 SAL_WARN("xmloff.text", "cannot insert content control");
204 return;
205 }
206
207 uno::Reference<beans::XPropertySet> xPropertySet(xContentControl, uno::UNO_QUERY);
208 if (!xPropertySet.is())
209 {
210 return;
211 }
212
214 {
215 xPropertySet->setPropertyValue("ShowingPlaceHolder", uno::Any(m_bShowingPlaceHolder));
216 }
217
218 if (m_bCheckbox)
219 {
220 xPropertySet->setPropertyValue("Checkbox", uno::Any(m_bCheckbox));
221 }
222 if (m_bChecked)
223 {
224 xPropertySet->setPropertyValue("Checked", uno::Any(m_bChecked));
225 }
226 if (!m_aCheckedState.isEmpty())
227 {
228 xPropertySet->setPropertyValue("CheckedState", uno::Any(m_aCheckedState));
229 }
230 if (!m_aUncheckedState.isEmpty())
231 {
232 xPropertySet->setPropertyValue("UncheckedState", uno::Any(m_aUncheckedState));
233 }
234 if (!m_aListItems.empty())
235 {
236 xPropertySet->setPropertyValue("ListItems",
238 }
239
240 if (m_bPicture)
241 {
242 xPropertySet->setPropertyValue("Picture", uno::Any(m_bPicture));
243 }
244
245 if (m_bDate)
246 {
247 xPropertySet->setPropertyValue("Date", uno::Any(m_bDate));
248 }
249 if (!m_aDateFormat.isEmpty())
250 {
251 xPropertySet->setPropertyValue("DateFormat", uno::Any(m_aDateFormat));
252 }
253 if (!m_aDateLanguage.isEmpty())
254 {
255 xPropertySet->setPropertyValue("DateLanguage", uno::Any(m_aDateLanguage));
256 }
257 if (!m_aCurrentDate.isEmpty())
258 {
259 xPropertySet->setPropertyValue("CurrentDate", uno::Any(m_aCurrentDate));
260 }
261
262 if (m_bPlainText)
263 {
264 xPropertySet->setPropertyValue("PlainText", uno::Any(m_bPlainText));
265 }
266
267 if (m_bComboBox)
268 {
269 xPropertySet->setPropertyValue("ComboBox", uno::Any(m_bComboBox));
270 }
271
272 if (m_bDropDown)
273 {
274 xPropertySet->setPropertyValue("DropDown", uno::Any(m_bDropDown));
275 }
276
277 if (!m_aAlias.isEmpty())
278 {
279 xPropertySet->setPropertyValue("Alias", uno::Any(m_aAlias));
280 }
281
282 if (!m_aTag.isEmpty())
283 {
284 xPropertySet->setPropertyValue("Tag", uno::Any(m_aTag));
285 }
286
287 if (m_nId)
288 {
289 xPropertySet->setPropertyValue("Id", uno::Any(m_nId));
290 }
291
292 if (m_nTabIndex)
293 {
294 xPropertySet->setPropertyValue("TabIndex", uno::Any(m_nTabIndex));
295 }
296
297 if (!m_aLock.isEmpty())
298 {
299 xPropertySet->setPropertyValue("Lock", uno::Any(m_aLock));
300 }
301}
302
303css::uno::Reference<css::xml::sax::XFastContextHandler>
305 sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
306{
307 switch (nElement)
308 {
309 case XML_ELEMENT(LO_EXT, XML_LIST_ITEM):
310 return new XMLListItemContext(GetImport(), *this);
311 break;
312 default:
313 break;
314 }
315
316 return XMLImpSpanContext_Impl::CreateSpanContext(GetImport(), nElement, xAttrList, m_rHints,
318}
319
320void XMLContentControlContext::characters(const OUString& rChars)
321{
322 GetImport().GetTextImport()->InsertString(rChars, m_rIgnoreLeadingSpace);
323}
324
325void XMLContentControlContext::AppendListItem(const css::beans::PropertyValues& rListItem)
326{
327 m_aListItems.push_back(rListItem);
328}
329
331 XMLContentControlContext& rContentControl)
332 : SvXMLImportContext(rImport)
333 , m_rContentControl(rContentControl)
334{
335}
336
338 sal_Int32 /*nElement*/, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
339{
340 OUString aDisplayText;
341 OUString aValue;
342
343 for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
344 {
345 switch (rIter.getToken())
346 {
347 case XML_ELEMENT(LO_EXT, XML_DISPLAY_TEXT):
348 {
349 aDisplayText = rIter.toString();
350 break;
351 }
352 case XML_ELEMENT(LO_EXT, XML_VALUE):
353 {
354 aValue = rIter.toString();
355 break;
356 }
357 default:
358 XMLOFF_WARN_UNKNOWN("xmloff", rIter);
359 }
360 }
361
362 uno::Sequence<beans::PropertyValue> aListItem = {
363 comphelper::makePropertyValue("DisplayText", uno::Any(aDisplayText)),
364 comphelper::makePropertyValue("Value", uno::Any(aValue)),
365 };
367}
368
369/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
Imports <loext:content-control>.
void SAL_CALL characters(const OUString &rChars) override
This method is called for all characters that are contained in the current element.
css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &rAttrList) override
void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
void AppendListItem(const css::beans::PropertyValues &rListItem)
XMLContentControlContext(SvXMLImport &rImport, sal_Int32 nElement, XMLHints_Impl &rHints, bool &rIgnoreLeadingSpace)
std::vector< css::beans::PropertyValues > m_aListItems
void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
css::uno::Reference< css::text::XTextRange > m_xStart
static css::uno::Reference< css::xml::sax::XFastContextHandler > CreateSpanContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, XMLHints_Impl &rHints, bool &rIgnLeadSpace, sal_uInt8 nStarFontsConvFlags=0)
Definition: txtparai.cxx:1336
Imports <loext:list-item> inside <loext:content-control>.
XMLContentControlContext & m_rContentControl
XMLListItemContext(SvXMLImport &rImport, XMLContentControlContext &rContentControl)
void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
static css::uno::Reference< css::text::XTextContent > CreateAndInsertMark(SvXMLImport &rImport, const OUString &sServiceName, const OUString &sMarkName, const css::uno::Reference< css::text::XTextRange > &rRange, const OUString &i_rXmlId=OUString(), bool const isFieldmarkSeparatorMissing=false)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
static bool convertBool(bool &rBool, std::u16string_view rString)
#define SAL_WARN(area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_SHOWING_PLACE_HOLDER
Definition: xmltoken.hxx:3511
@ XML_DATE_RFC_LANGUAGE_TAG
Definition: xmltoken.hxx:3517
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97