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