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
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
53 switch (rIter.getToken())
54 {
56 {
57 if (sax::Converter::convertBool(bTmp, rIter.toView()))
58 {
60 }
61 break;
62 }
63 case XML_ELEMENT(LO_EXT, XML_CHECKBOX):
64 {
65 if (sax::Converter::convertBool(bTmp, rIter.toView()))
66 {
67 m_bCheckbox = bTmp;
68 }
69 break;
70 }
71 case XML_ELEMENT(LO_EXT, XML_CHECKED):
72 {
73 if (sax::Converter::convertBool(bTmp, rIter.toView()))
74 {
75 m_bChecked = bTmp;
76 }
77 break;
78 }
79 case XML_ELEMENT(LO_EXT, XML_CHECKED_STATE):
80 {
81 m_aCheckedState = rIter.toString();
82 break;
83 }
84 case XML_ELEMENT(LO_EXT, XML_UNCHECKED_STATE):
85 {
86 m_aUncheckedState = rIter.toString();
87 break;
88 }
89 case XML_ELEMENT(LO_EXT, XML_PICTURE):
90 {
91 if (sax::Converter::convertBool(bTmp, rIter.toView()))
92 {
93 m_bPicture = bTmp;
94 }
95 break;
96 }
97 case XML_ELEMENT(LO_EXT, XML_DATE):
98 {
99 if (sax::Converter::convertBool(bTmp, rIter.toView()))
100 {
101 m_bDate = bTmp;
102 }
103 break;
104 }
105 case XML_ELEMENT(LO_EXT, XML_DATE_FORMAT):
106 {
107 m_aDateFormat = rIter.toString();
108 break;
109 }
111 {
112 m_aDateLanguage = rIter.toString();
113 break;
114 }
115 case XML_ELEMENT(LO_EXT, XML_CURRENT_DATE):
116 {
117 m_aCurrentDate = rIter.toString();
118 break;
119 }
120 case XML_ELEMENT(LO_EXT, XML_PLAIN_TEXT):
121 {
122 if (sax::Converter::convertBool(bTmp, rIter.toView()))
123 {
124 m_bPlainText = bTmp;
125 }
126 break;
127 }
128 case XML_ELEMENT(LO_EXT, XML_COMBOBOX):
129 {
130 if (sax::Converter::convertBool(bTmp, rIter.toView()))
131 {
132 m_bComboBox = bTmp;
133 }
134 break;
135 }
136 case XML_ELEMENT(LO_EXT, XML_DROPDOWN):
137 {
138 if (sax::Converter::convertBool(bTmp, rIter.toView()))
139 {
140 m_bDropDown = bTmp;
141 }
142 break;
143 }
144 case XML_ELEMENT(LO_EXT, XML_ALIAS):
145 {
146 m_aAlias = rIter.toString();
147 break;
148 }
149 case XML_ELEMENT(LO_EXT, XML_TAG):
150 {
151 m_aTag = rIter.toString();
152 break;
153 }
154 default:
155 XMLOFF_WARN_UNKNOWN("xmloff", rIter);
156 }
157 }
158}
159
161{
162 if (!m_xStart.is())
163 {
164 SAL_WARN("xmloff.text", "XMLContentControlContext::endFastElement: no m_xStart");
165 return;
166 }
167
168 uno::Reference<text::XTextRange> xEndRange
169 = GetImport().GetTextImport()->GetCursorAsRange()->getStart();
170
171 // Create range for insertion.
172 uno::Reference<text::XTextCursor> xInsertionCursor
173 = GetImport().GetTextImport()->GetText()->createTextCursorByRange(xEndRange);
174 xInsertionCursor->gotoRange(m_xStart, /*bExpand=*/true);
175
176 uno::Reference<text::XTextContent> xContentControl
178 GetImport(), "com.sun.star.text.ContentControl", OUString(), xInsertionCursor);
179 if (!xContentControl.is())
180 {
181 SAL_WARN("xmloff.text", "cannot insert content control");
182 return;
183 }
184
185 uno::Reference<beans::XPropertySet> xPropertySet(xContentControl, uno::UNO_QUERY);
186 if (!xPropertySet.is())
187 {
188 return;
189 }
190
192 {
193 xPropertySet->setPropertyValue("ShowingPlaceHolder", uno::Any(m_bShowingPlaceHolder));
194 }
195
196 if (m_bCheckbox)
197 {
198 xPropertySet->setPropertyValue("Checkbox", uno::Any(m_bCheckbox));
199 }
200 if (m_bChecked)
201 {
202 xPropertySet->setPropertyValue("Checked", uno::Any(m_bChecked));
203 }
204 if (!m_aCheckedState.isEmpty())
205 {
206 xPropertySet->setPropertyValue("CheckedState", uno::Any(m_aCheckedState));
207 }
208 if (!m_aUncheckedState.isEmpty())
209 {
210 xPropertySet->setPropertyValue("UncheckedState", uno::Any(m_aUncheckedState));
211 }
212 if (!m_aListItems.empty())
213 {
214 xPropertySet->setPropertyValue("ListItems",
216 }
217
218 if (m_bPicture)
219 {
220 xPropertySet->setPropertyValue("Picture", uno::Any(m_bPicture));
221 }
222
223 if (m_bDate)
224 {
225 xPropertySet->setPropertyValue("Date", uno::Any(m_bDate));
226 }
227 if (!m_aDateFormat.isEmpty())
228 {
229 xPropertySet->setPropertyValue("DateFormat", uno::Any(m_aDateFormat));
230 }
231 if (!m_aDateLanguage.isEmpty())
232 {
233 xPropertySet->setPropertyValue("DateLanguage", uno::Any(m_aDateLanguage));
234 }
235 if (!m_aCurrentDate.isEmpty())
236 {
237 xPropertySet->setPropertyValue("CurrentDate", uno::Any(m_aCurrentDate));
238 }
239
240 if (m_bPlainText)
241 {
242 xPropertySet->setPropertyValue("PlainText", uno::Any(m_bPlainText));
243 }
244
245 if (m_bComboBox)
246 {
247 xPropertySet->setPropertyValue("ComboBox", uno::Any(m_bComboBox));
248 }
249
250 if (m_bDropDown)
251 {
252 xPropertySet->setPropertyValue("DropDown", uno::Any(m_bDropDown));
253 }
254
255 if (!m_aAlias.isEmpty())
256 {
257 xPropertySet->setPropertyValue("Alias", uno::Any(m_aAlias));
258 }
259
260 if (!m_aTag.isEmpty())
261 {
262 xPropertySet->setPropertyValue("Tag", uno::Any(m_aTag));
263 }
264}
265
266css::uno::Reference<css::xml::sax::XFastContextHandler>
268 sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
269{
270 switch (nElement)
271 {
272 case XML_ELEMENT(LO_EXT, XML_LIST_ITEM):
273 return new XMLListItemContext(GetImport(), *this);
274 break;
275 default:
276 break;
277 }
278
279 return XMLImpSpanContext_Impl::CreateSpanContext(GetImport(), nElement, xAttrList, m_rHints,
281}
282
283void XMLContentControlContext::characters(const OUString& rChars)
284{
285 GetImport().GetTextImport()->InsertString(rChars, m_rIgnoreLeadingSpace);
286}
287
288void XMLContentControlContext::AppendListItem(const css::beans::PropertyValues& rListItem)
289{
290 m_aListItems.push_back(rListItem);
291}
292
294 XMLContentControlContext& rContentControl)
295 : SvXMLImportContext(rImport)
296 , m_rContentControl(rContentControl)
297{
298}
299
301 sal_Int32 /*nElement*/, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
302{
303 OUString aDisplayText;
304 OUString aValue;
305
306 for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
307 {
308 switch (rIter.getToken())
309 {
310 case XML_ELEMENT(LO_EXT, XML_DISPLAY_TEXT):
311 {
312 aDisplayText = rIter.toString();
313 break;
314 }
315 case XML_ELEMENT(LO_EXT, XML_VALUE):
316 {
317 aValue = rIter.toString();
318 break;
319 }
320 default:
321 XMLOFF_WARN_UNKNOWN("xmloff", rIter);
322 }
323 }
324
325 uno::Sequence<beans::PropertyValue> aListItem = {
326 comphelper::makePropertyValue("DisplayText", uno::Any(aDisplayText)),
327 comphelper::makePropertyValue("Value", uno::Any(aValue)),
328 };
330}
331
332/* 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
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:602
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:1335
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 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:3503
@ XML_DATE_RFC_LANGUAGE_TAG
Definition: xmltoken.hxx:3509
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:98