/src/libreoffice/xmloff/source/draw/ximppage.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 <sal/config.h> |
21 | | |
22 | | #include <com/sun/star/frame/XModel.hpp> |
23 | | #include <com/sun/star/geometry/RealPoint2D.hpp> |
24 | | #include <com/sun/star/text/XTextCursor.hpp> |
25 | | #include <com/sun/star/util/DateTime.hpp> |
26 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
27 | | #include <com/sun/star/lang/XMultiServiceFactory.hpp> |
28 | | #include <cppuhelper/implbase.hxx> |
29 | | #include <sax/tools/converter.hxx> |
30 | | #include <XMLNumberStylesImport.hxx> |
31 | | #include <xmloff/xmlstyle.hxx> |
32 | | #include <xmloff/xmltoken.hxx> |
33 | | #include <xmloff/xmlnamespace.hxx> |
34 | | #include "ximppage.hxx" |
35 | | #include <animimp.hxx> |
36 | | #include <XMLStringBufferImportContext.hxx> |
37 | | #include <xmloff/xmlictxt.hxx> |
38 | | #include "ximpstyl.hxx" |
39 | | #include <xmloff/prstylei.hxx> |
40 | | #include <PropertySetMerger.hxx> |
41 | | #include <sal/log.hxx> |
42 | | #include <comphelper/diagnose_ex.hxx> |
43 | | |
44 | | #include <xmloff/unointerfacetouniqueidentifiermapper.hxx> |
45 | | #include <xmloff/xmluconv.hxx> |
46 | | |
47 | | using namespace ::com::sun::star; |
48 | | using namespace ::xmloff::token; |
49 | | using namespace ::com::sun::star::uno; |
50 | | using namespace ::com::sun::star::lang; |
51 | | using namespace ::com::sun::star::text; |
52 | | using namespace ::com::sun::star::util; |
53 | | using namespace ::com::sun::star::beans; |
54 | | using namespace ::com::sun::star::drawing; |
55 | | using namespace ::com::sun::star::container; |
56 | | using namespace ::com::sun::star::office; |
57 | | using namespace ::com::sun::star::xml::sax; |
58 | | using namespace ::com::sun::star::geometry; |
59 | | |
60 | | namespace { |
61 | | |
62 | | class DrawAnnotationContext : public SvXMLImportContext |
63 | | { |
64 | | |
65 | | public: |
66 | | DrawAnnotationContext( SvXMLImport& rImport, const Reference< xml::sax::XFastAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess ); |
67 | | |
68 | | virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( |
69 | | sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; |
70 | | virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; |
71 | | |
72 | | private: |
73 | | Reference< XAnnotation > mxAnnotation; |
74 | | Reference< XTextCursor > mxCursor; |
75 | | |
76 | | OUStringBuffer maAuthorBuffer; |
77 | | OUStringBuffer maInitialsBuffer; |
78 | | OUStringBuffer maDateBuffer; |
79 | | }; |
80 | | |
81 | | } |
82 | | |
83 | | DrawAnnotationContext::DrawAnnotationContext( SvXMLImport& rImport, const Reference< xml::sax::XFastAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess ) |
84 | 0 | : SvXMLImportContext( rImport ) |
85 | 0 | , mxAnnotation( xAnnotationAccess->createAndInsertAnnotation() ) |
86 | 0 | { |
87 | 0 | if( !mxAnnotation.is() ) |
88 | 0 | return; |
89 | | |
90 | 0 | RealPoint2D aPosition; |
91 | 0 | RealSize2D aSize; |
92 | |
|
93 | 0 | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
94 | 0 | { |
95 | 0 | switch( aIter.getToken() ) |
96 | 0 | { |
97 | 0 | case XML_ELEMENT(SVG, XML_X): |
98 | 0 | case XML_ELEMENT(SVG_COMPAT, XML_X): |
99 | 0 | { |
100 | 0 | sal_Int32 x; |
101 | 0 | GetImport().GetMM100UnitConverter().convertMeasureToCore( |
102 | 0 | x, aIter.toView()); |
103 | 0 | aPosition.X = static_cast<double>(x) / 100.0; |
104 | 0 | break; |
105 | 0 | } |
106 | 0 | case XML_ELEMENT(SVG, XML_Y): |
107 | 0 | case XML_ELEMENT(SVG_COMPAT, XML_Y): |
108 | 0 | { |
109 | 0 | sal_Int32 y; |
110 | 0 | GetImport().GetMM100UnitConverter().convertMeasureToCore( |
111 | 0 | y, aIter.toView()); |
112 | 0 | aPosition.Y = static_cast<double>(y) / 100.0; |
113 | 0 | break; |
114 | 0 | } |
115 | 0 | case XML_ELEMENT(SVG, XML_WIDTH): |
116 | 0 | case XML_ELEMENT(SVG_COMPAT, XML_WIDTH): |
117 | 0 | { |
118 | 0 | sal_Int32 w; |
119 | 0 | GetImport().GetMM100UnitConverter().convertMeasureToCore( |
120 | 0 | w, aIter.toView()); |
121 | 0 | aSize.Width = static_cast<double>(w) / 100.0; |
122 | 0 | break; |
123 | 0 | } |
124 | 0 | case XML_ELEMENT(SVG, XML_HEIGHT): |
125 | 0 | case XML_ELEMENT(SVG_COMPAT, XML_HEIGHT): |
126 | 0 | { |
127 | 0 | sal_Int32 h; |
128 | 0 | GetImport().GetMM100UnitConverter().convertMeasureToCore( |
129 | 0 | h, aIter.toView()); |
130 | 0 | aSize.Height = static_cast<double>(h) / 100.0; |
131 | 0 | } |
132 | 0 | break; |
133 | 0 | default: |
134 | 0 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
135 | 0 | } |
136 | 0 | } |
137 | | |
138 | 0 | mxAnnotation->setPosition( aPosition ); |
139 | 0 | mxAnnotation->setSize( aSize ); |
140 | 0 | } |
141 | | |
142 | | css::uno::Reference< css::xml::sax::XFastContextHandler > DrawAnnotationContext::createFastChildContext( |
143 | | sal_Int32 nElement, |
144 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
145 | 0 | { |
146 | 0 | if( mxAnnotation.is() ) |
147 | 0 | { |
148 | 0 | if (nElement == XML_ELEMENT(DC, XML_CREATOR) ) |
149 | 0 | return new XMLStringBufferImportContext(GetImport(), maAuthorBuffer); |
150 | 0 | else if( nElement == XML_ELEMENT(DC, XML_DATE) ) |
151 | 0 | return new XMLStringBufferImportContext(GetImport(), maDateBuffer); |
152 | 0 | else if ( nElement == XML_ELEMENT(TEXT, XML_SENDER_INITIALS) |
153 | 0 | || nElement == XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS) |
154 | 0 | || nElement == XML_ELEMENT(META, XML_CREATOR_INITIALS)) |
155 | 0 | { |
156 | 0 | return new XMLStringBufferImportContext(GetImport(), maInitialsBuffer); |
157 | 0 | } |
158 | 0 | else |
159 | 0 | { |
160 | | // create text cursor on demand |
161 | 0 | if( !mxCursor.is() ) |
162 | 0 | { |
163 | 0 | uno::Reference< text::XText > xText( mxAnnotation->getTextRange() ); |
164 | 0 | if( xText.is() ) |
165 | 0 | { |
166 | 0 | rtl::Reference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport(); |
167 | 0 | mxCursor = xText->createTextCursor(); |
168 | 0 | if( mxCursor.is() ) |
169 | 0 | xTxtImport->SetCursor( mxCursor ); |
170 | 0 | } |
171 | 0 | } |
172 | | |
173 | | // if we have a text cursor, let's try to import some text |
174 | 0 | if( mxCursor.is() ) |
175 | 0 | { |
176 | 0 | auto p = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nElement, xAttrList ); |
177 | 0 | if (p) |
178 | 0 | return p; |
179 | 0 | } |
180 | 0 | } |
181 | 0 | } |
182 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
183 | 0 | return nullptr; |
184 | 0 | } |
185 | | |
186 | | void DrawAnnotationContext::endFastElement(sal_Int32) |
187 | 0 | { |
188 | 0 | if(mxCursor.is()) |
189 | 0 | { |
190 | | // delete addition newline |
191 | 0 | mxCursor->gotoEnd( false ); |
192 | 0 | mxCursor->goLeft( 1, true ); |
193 | 0 | mxCursor->setString( u""_ustr ); |
194 | | |
195 | | // reset cursor |
196 | 0 | GetImport().GetTextImport()->ResetCursor(); |
197 | 0 | } |
198 | |
|
199 | 0 | if( mxAnnotation.is() ) |
200 | 0 | { |
201 | 0 | mxAnnotation->setAuthor( maAuthorBuffer.makeStringAndClear() ); |
202 | 0 | mxAnnotation->setInitials( maInitialsBuffer.makeStringAndClear() ); |
203 | |
|
204 | 0 | util::DateTime aDateTime; |
205 | 0 | if (::sax::Converter::parseDateTime(aDateTime, maDateBuffer)) |
206 | 0 | { |
207 | 0 | mxAnnotation->setDateTime(aDateTime); |
208 | 0 | } |
209 | 0 | maDateBuffer.setLength(0); |
210 | 0 | } |
211 | 0 | } |
212 | | |
213 | | |
214 | | SdXMLGenericPageContext::SdXMLGenericPageContext( |
215 | | SvXMLImport& rImport, |
216 | | const Reference< xml::sax::XFastAttributeList>& xAttrList, |
217 | | Reference< drawing::XShapes > const & rShapes) |
218 | 148 | : SvXMLImportContext( rImport ) |
219 | 148 | , mxShapes( rShapes ) |
220 | 148 | , mxAnnotationAccess( rShapes, UNO_QUERY ) |
221 | 148 | { |
222 | 148 | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
223 | 343 | { |
224 | 343 | if( aIter.getToken() == XML_ELEMENT(DRAW, XML_NAV_ORDER) ) |
225 | 0 | { |
226 | 0 | msNavOrder = aIter.toString(); |
227 | 0 | break; |
228 | 0 | } |
229 | 343 | } |
230 | 148 | } |
231 | | |
232 | | SdXMLGenericPageContext::SdXMLGenericPageContext( |
233 | | SvXMLImport& rImport, |
234 | | const Reference< xml::sax::XFastAttributeList>& xAttrList) |
235 | 44 | : SvXMLImportContext( rImport ) |
236 | 44 | { |
237 | 44 | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
238 | 132 | { |
239 | 132 | if( aIter.getToken() == XML_ELEMENT(DRAW, XML_NAV_ORDER) ) |
240 | 0 | { |
241 | 0 | msNavOrder = aIter.toString(); |
242 | 0 | break; |
243 | 0 | } |
244 | 132 | } |
245 | 44 | } |
246 | | |
247 | | void SdXMLGenericPageContext::SetShapes(Reference< drawing::XShapes > const & rShapes) |
248 | 44 | { |
249 | 44 | mxShapes = rShapes; |
250 | 44 | mxAnnotationAccess.set( rShapes, UNO_QUERY ); |
251 | 44 | } |
252 | | |
253 | | SdXMLGenericPageContext::~SdXMLGenericPageContext() |
254 | 192 | { |
255 | 192 | } |
256 | | |
257 | | void SdXMLGenericPageContext::startFastElement( sal_Int32 /*nElement*/, const Reference< css::xml::sax::XFastAttributeList >& ) |
258 | 192 | { |
259 | 192 | GetImport().GetShapeImport()->pushGroupForPostProcessing( mxShapes ); |
260 | | |
261 | 192 | if( GetImport().IsFormsSupported() ) |
262 | 192 | GetImport().GetFormImport()->startPage( Reference< drawing::XDrawPage >::query( mxShapes ) ); |
263 | 192 | } |
264 | | |
265 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLGenericPageContext::createFastChildContext( |
266 | | sal_Int32 nElement, |
267 | | const Reference< xml::sax::XFastAttributeList>& xAttrList ) |
268 | 1.07k | { |
269 | 1.07k | if( nElement == XML_ELEMENT(PRESENTATION, XML_ANIMATIONS) ) |
270 | 0 | { |
271 | 0 | return new XMLAnimationsContext( GetImport() ); |
272 | 0 | } |
273 | 1.07k | else if( nElement == XML_ELEMENT(OFFICE, XML_FORMS) ) |
274 | 0 | { |
275 | 0 | if( GetImport().IsFormsSupported() ) |
276 | 0 | return xmloff::OFormLayerXMLImport::createOfficeFormsContext( GetImport() ); |
277 | 0 | } |
278 | 1.07k | else if( nElement == XML_ELEMENT(OFFICE, XML_ANNOTATION) || nElement == XML_ELEMENT(OFFICE_EXT, XML_ANNOTATION) ) |
279 | 0 | { |
280 | 0 | if( mxAnnotationAccess.is() ) |
281 | 0 | return new DrawAnnotationContext( GetImport(), xAttrList, mxAnnotationAccess ); |
282 | 0 | } |
283 | 1.07k | else |
284 | 1.07k | { |
285 | | // call GroupChildContext function at common ShapeImport |
286 | 1.07k | auto p = XMLShapeImportHelper::CreateGroupChildContext(GetImport(), nElement, xAttrList, mxShapes); |
287 | 1.07k | if (p) |
288 | 1.07k | return p; |
289 | 1.07k | } |
290 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
291 | 0 | return nullptr; |
292 | 0 | } |
293 | | |
294 | | void SdXMLGenericPageContext::endFastElement(sal_Int32 ) |
295 | 125 | { |
296 | 125 | GetImport().GetShapeImport()->popGroupAndPostProcess(); |
297 | | |
298 | 125 | if( GetImport().IsFormsSupported() ) |
299 | 125 | GetImport().GetFormImport()->endPage(); |
300 | | |
301 | 125 | if( !maUseHeaderDeclName.isEmpty() || !maUseFooterDeclName.isEmpty() || !maUseDateTimeDeclName.isEmpty() ) |
302 | 10 | { |
303 | 10 | try |
304 | 10 | { |
305 | 10 | Reference <beans::XPropertySet> xSet(mxShapes, uno::UNO_QUERY_THROW ); |
306 | 10 | Reference< beans::XPropertySetInfo > xInfo( xSet->getPropertySetInfo() ); |
307 | | |
308 | 10 | if( !maUseHeaderDeclName.isEmpty() ) |
309 | 0 | { |
310 | 0 | static constexpr OUString aStrHeaderTextProp( u"HeaderText"_ustr ); |
311 | 0 | if( xInfo->hasPropertyByName( aStrHeaderTextProp ) ) |
312 | 0 | xSet->setPropertyValue( aStrHeaderTextProp, |
313 | 0 | Any( GetSdImport().GetHeaderDecl( maUseHeaderDeclName ) ) ); |
314 | 0 | } |
315 | | |
316 | 10 | if( !maUseFooterDeclName.isEmpty() ) |
317 | 10 | { |
318 | 10 | static constexpr OUString aStrFooterTextProp( u"FooterText"_ustr ); |
319 | 10 | if( xInfo->hasPropertyByName( aStrFooterTextProp ) ) |
320 | 10 | xSet->setPropertyValue( aStrFooterTextProp, |
321 | 10 | Any( GetSdImport().GetFooterDecl( maUseFooterDeclName ) ) ); |
322 | 10 | } |
323 | | |
324 | 10 | if( !maUseDateTimeDeclName.isEmpty() ) |
325 | 10 | { |
326 | 10 | static constexpr OUString aStrDateTimeTextProp( u"DateTimeText"_ustr ); |
327 | 10 | if( xInfo->hasPropertyByName( aStrDateTimeTextProp ) ) |
328 | 10 | { |
329 | 10 | bool bFixed; |
330 | 10 | OUString aDateTimeFormat; |
331 | 10 | const OUString aText( GetSdImport().GetDateTimeDecl( maUseDateTimeDeclName, bFixed, aDateTimeFormat ) ); |
332 | | |
333 | 10 | xSet->setPropertyValue(u"IsDateTimeFixed"_ustr, |
334 | 10 | Any( bFixed ) ); |
335 | | |
336 | 10 | if( bFixed ) |
337 | 10 | { |
338 | 10 | xSet->setPropertyValue( aStrDateTimeTextProp, Any( aText ) ); |
339 | 10 | } |
340 | 0 | else if( !aDateTimeFormat.isEmpty() ) |
341 | 0 | { |
342 | 0 | const SdXMLStylesContext* pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetStylesContext() ); |
343 | 0 | if( !pStyles ) |
344 | 0 | pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetAutoStylesContext() ); |
345 | |
|
346 | 0 | if( pStyles ) |
347 | 0 | { |
348 | 0 | const SdXMLNumberFormatImportContext* pSdNumStyle = |
349 | 0 | dynamic_cast< const SdXMLNumberFormatImportContext* >( pStyles->FindStyleChildContext( XmlStyleFamily::DATA_STYLE, aDateTimeFormat, true ) ); |
350 | |
|
351 | 0 | if( pSdNumStyle ) |
352 | 0 | { |
353 | 0 | xSet->setPropertyValue(u"DateTimeFormat"_ustr, |
354 | 0 | Any( pSdNumStyle->GetDrawKey() ) ); |
355 | 0 | } |
356 | 0 | } |
357 | 0 | } |
358 | 10 | } |
359 | 10 | } |
360 | 10 | } |
361 | 10 | catch(const uno::Exception&) |
362 | 10 | { |
363 | 0 | TOOLS_WARN_EXCEPTION("xmloff.draw", ""); |
364 | 0 | } |
365 | 10 | } |
366 | | |
367 | 125 | SetNavigationOrder(); |
368 | 125 | } |
369 | | |
370 | | void SdXMLGenericPageContext::SetStyle( OUString const & rStyleName ) |
371 | 192 | { |
372 | | // set PageProperties? |
373 | 192 | if(rStyleName.isEmpty()) |
374 | 67 | return; |
375 | | |
376 | 125 | try |
377 | 125 | { |
378 | 125 | const SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetAutoStylesContext(); |
379 | | |
380 | 125 | if (const SdXMLStylesContext* pStyles = dynamic_cast<const SdXMLStylesContext *>(pContext)) |
381 | 125 | { |
382 | 125 | const SvXMLStyleContext* pStyle = pStyles->FindStyleChildContext( |
383 | 125 | XmlStyleFamily::SD_DRAWINGPAGE_ID, rStyleName); |
384 | | |
385 | 125 | if (const XMLPropStyleContext* pPropStyle = dynamic_cast<const XMLPropStyleContext*>(pStyle)) |
386 | 120 | { |
387 | 120 | Reference <beans::XPropertySet> xPropSet1(mxShapes, uno::UNO_QUERY); |
388 | 120 | if(xPropSet1.is()) |
389 | 120 | { |
390 | 120 | Reference< beans::XPropertySet > xPropSet( xPropSet1 ); |
391 | 120 | Reference< beans::XPropertySet > xBackgroundSet; |
392 | | |
393 | 120 | static constexpr OUString aBackground(u"Background"_ustr); |
394 | 120 | if( xPropSet1->getPropertySetInfo()->hasPropertyByName( aBackground ) ) |
395 | 67 | { |
396 | 67 | Reference< beans::XPropertySetInfo > xInfo( xPropSet1->getPropertySetInfo() ); |
397 | 67 | if( xInfo.is() && xInfo->hasPropertyByName( aBackground ) ) |
398 | 67 | { |
399 | 67 | Reference< lang::XMultiServiceFactory > xServiceFact(GetSdImport().GetModel(), uno::UNO_QUERY); |
400 | 67 | if(xServiceFact.is()) |
401 | 67 | { |
402 | 67 | xBackgroundSet.set(xServiceFact->createInstance(u"com.sun.star.drawing.Background"_ustr), UNO_QUERY); |
403 | 67 | } |
404 | 67 | } |
405 | | |
406 | 67 | if( xBackgroundSet.is() ) |
407 | 67 | xPropSet = PropertySetMerger_CreateInstance( xPropSet1, xBackgroundSet ); |
408 | 67 | } |
409 | | |
410 | 120 | if(xPropSet.is()) |
411 | 120 | { |
412 | 120 | const_cast<XMLPropStyleContext*>(pPropStyle)->FillPropertySet(xPropSet); |
413 | | |
414 | 120 | if( xBackgroundSet.is() ) |
415 | 67 | xPropSet1->setPropertyValue( aBackground, uno::Any( xBackgroundSet ) ); |
416 | 120 | } |
417 | 120 | } |
418 | 120 | } |
419 | 125 | } |
420 | 125 | } |
421 | 125 | catch (const uno::Exception&) |
422 | 125 | { |
423 | 0 | TOOLS_WARN_EXCEPTION("xmloff.draw", ""); |
424 | 0 | } |
425 | 125 | } |
426 | | |
427 | | void SdXMLGenericPageContext::SetLayout() |
428 | 150 | { |
429 | | // set PresentationPageLayout? |
430 | 150 | if(!GetSdImport().IsImpress() || maPageLayoutName.isEmpty()) |
431 | 102 | return; |
432 | | |
433 | 48 | sal_Int32 nType = -1; |
434 | | |
435 | 48 | const SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext(); |
436 | | |
437 | 48 | if (const SdXMLStylesContext* pStyles = dynamic_cast<const SdXMLStylesContext *>(pContext)) |
438 | 48 | { |
439 | 48 | const SvXMLStyleContext* pStyle = pStyles->FindStyleChildContext( XmlStyleFamily::SD_PRESENTATIONPAGELAYOUT_ID, maPageLayoutName); |
440 | | |
441 | 48 | if (const SdXMLPresentationPageLayoutContext* pLayout = dynamic_cast<const SdXMLPresentationPageLayoutContext*>(pStyle)) |
442 | 47 | { |
443 | 47 | nType = pLayout->GetTypeId(); |
444 | 47 | } |
445 | 48 | } |
446 | | |
447 | 48 | if( -1 == nType ) |
448 | 1 | { |
449 | 1 | Reference< container::XNameAccess > xPageLayouts( GetSdImport().getPageLayouts() ); |
450 | 1 | if( xPageLayouts.is() ) |
451 | 0 | { |
452 | 0 | if( xPageLayouts->hasByName( maPageLayoutName ) ) |
453 | 0 | xPageLayouts->getByName( maPageLayoutName ) >>= nType; |
454 | 0 | } |
455 | | |
456 | 1 | } |
457 | | |
458 | 48 | if( -1 != nType ) |
459 | 47 | { |
460 | 47 | Reference <beans::XPropertySet> xPropSet(mxShapes, uno::UNO_QUERY); |
461 | 47 | if(xPropSet.is()) |
462 | 47 | { |
463 | 47 | OUString aPropName(u"Layout"_ustr); |
464 | 47 | Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() ); |
465 | 47 | if( xInfo.is() && xInfo->hasPropertyByName( aPropName ) ) |
466 | 47 | xPropSet->setPropertyValue(aPropName, uno::Any( static_cast<sal_Int16>(nType) ) ); |
467 | 47 | } |
468 | 47 | } |
469 | 48 | } |
470 | | |
471 | | void SdXMLGenericPageContext::DeleteAllShapes() |
472 | 150 | { |
473 | | // now delete all up-to-now contained shapes; they have been created |
474 | | // when setting the presentation page layout. |
475 | 907 | while(mxShapes->getCount()) |
476 | 757 | { |
477 | 757 | Reference< drawing::XShape > xShape; |
478 | 757 | uno::Any aAny(mxShapes->getByIndex(0)); |
479 | | |
480 | 757 | aAny >>= xShape; |
481 | | |
482 | 757 | if(xShape.is()) |
483 | 757 | { |
484 | 757 | mxShapes->remove(xShape); |
485 | 757 | } |
486 | 757 | } |
487 | 150 | } |
488 | | |
489 | | void SdXMLGenericPageContext::SetPageMaster( OUString const & rsPageMasterName ) |
490 | 115 | { |
491 | 115 | if (!GetSdImport().GetShapeImport()->GetStylesContext()) |
492 | 0 | return; |
493 | | |
494 | | // look for PageMaster with this name |
495 | | |
496 | | // #80012# GetStylesContext() replaced with GetAutoStylesContext() |
497 | 115 | const SvXMLStylesContext* pAutoStyles = GetSdImport().GetShapeImport()->GetAutoStylesContext(); |
498 | | |
499 | 115 | const SvXMLStyleContext* pStyle = pAutoStyles ? pAutoStyles->FindStyleChildContext(XmlStyleFamily::SD_PAGEMASTERCONTEXT_ID, rsPageMasterName) : nullptr; |
500 | | |
501 | 115 | const SdXMLPageMasterContext* pPageMaster = dynamic_cast<const SdXMLPageMasterContext*>(pStyle); |
502 | 115 | if (!pPageMaster) |
503 | 4 | return; |
504 | | |
505 | 111 | const SdXMLPageMasterStyleContext* pPageMasterContext = pPageMaster->GetPageMasterStyle(); |
506 | | |
507 | 111 | if (!pPageMasterContext) |
508 | 0 | return; |
509 | | |
510 | 111 | Reference< drawing::XDrawPage > xMasterPage(GetLocalShapesContext(), uno::UNO_QUERY); |
511 | 111 | if (!xMasterPage.is()) |
512 | 0 | return; |
513 | | |
514 | | // set sizes for this masterpage |
515 | 111 | Reference <beans::XPropertySet> xPropSet(xMasterPage, uno::UNO_QUERY); |
516 | 111 | if (xPropSet.is()) |
517 | 111 | { |
518 | 111 | xPropSet->setPropertyValue(u"BorderBottom"_ustr, Any(pPageMasterContext->GetBorderBottom())); |
519 | 111 | xPropSet->setPropertyValue(u"BorderLeft"_ustr, Any(pPageMasterContext->GetBorderLeft())); |
520 | 111 | xPropSet->setPropertyValue(u"BorderRight"_ustr, Any(pPageMasterContext->GetBorderRight())); |
521 | 111 | xPropSet->setPropertyValue(u"BorderTop"_ustr, Any(pPageMasterContext->GetBorderTop())); |
522 | 111 | xPropSet->setPropertyValue(u"Width"_ustr, Any(pPageMasterContext->GetWidth())); |
523 | 111 | xPropSet->setPropertyValue(u"Height"_ustr, Any(pPageMasterContext->GetHeight())); |
524 | 111 | xPropSet->setPropertyValue(u"Orientation"_ustr, Any(pPageMasterContext->GetOrientation())); |
525 | 111 | } |
526 | 111 | } |
527 | | |
528 | | namespace { |
529 | | |
530 | | class XoNavigationOrderAccess : public ::cppu::WeakImplHelper< XIndexAccess > |
531 | | { |
532 | | public: |
533 | | explicit XoNavigationOrderAccess( std::vector< Reference< XShape > >& rShapes ); |
534 | | |
535 | | // XIndexAccess |
536 | | virtual sal_Int32 SAL_CALL getCount( ) override; |
537 | | virtual Any SAL_CALL getByIndex( sal_Int32 Index ) override; |
538 | | |
539 | | // XElementAccess |
540 | | virtual Type SAL_CALL getElementType( ) override; |
541 | | virtual sal_Bool SAL_CALL hasElements( ) override; |
542 | | |
543 | | private: |
544 | | std::vector< Reference< XShape > > maShapes; |
545 | | }; |
546 | | |
547 | | } |
548 | | |
549 | | XoNavigationOrderAccess::XoNavigationOrderAccess( std::vector< Reference< XShape > >& rShapes ) |
550 | 0 | { |
551 | 0 | maShapes.swap( rShapes ); |
552 | 0 | } |
553 | | |
554 | | // XIndexAccess |
555 | | sal_Int32 SAL_CALL XoNavigationOrderAccess::getCount( ) |
556 | 0 | { |
557 | 0 | return static_cast< sal_Int32 >( maShapes.size() ); |
558 | 0 | } |
559 | | |
560 | | Any SAL_CALL XoNavigationOrderAccess::getByIndex( sal_Int32 Index ) |
561 | 0 | { |
562 | 0 | if( (Index < 0) || (Index > getCount()) ) |
563 | 0 | throw IndexOutOfBoundsException(); |
564 | | |
565 | 0 | return Any( maShapes[Index] ); |
566 | 0 | } |
567 | | |
568 | | // XElementAccess |
569 | | Type SAL_CALL XoNavigationOrderAccess::getElementType( ) |
570 | 0 | { |
571 | 0 | return cppu::UnoType<XShape>::get(); |
572 | 0 | } |
573 | | |
574 | | sal_Bool SAL_CALL XoNavigationOrderAccess::hasElements( ) |
575 | 0 | { |
576 | 0 | return !maShapes.empty(); |
577 | 0 | } |
578 | | |
579 | | void SdXMLGenericPageContext::SetNavigationOrder() |
580 | 125 | { |
581 | 125 | if( msNavOrder.isEmpty() ) |
582 | 125 | return; |
583 | | |
584 | 0 | try |
585 | 0 | { |
586 | 0 | sal_uInt32 nIndex; |
587 | 0 | const sal_uInt32 nCount = static_cast< sal_uInt32 >( mxShapes->getCount() ); |
588 | 0 | std::vector< Reference< XShape > > aShapes( nCount ); |
589 | |
|
590 | 0 | ::comphelper::UnoInterfaceToUniqueIdentifierMapper& rIdMapper = GetSdImport().getInterfaceToIdentifierMapper(); |
591 | 0 | SvXMLTokenEnumerator aEnumerator( msNavOrder ); |
592 | 0 | std::u16string_view sId; |
593 | 0 | for( nIndex = 0; nIndex < nCount; ++nIndex ) |
594 | 0 | { |
595 | 0 | if( !aEnumerator.getNextToken(sId) ) |
596 | 0 | break; |
597 | | |
598 | 0 | aShapes[nIndex].set( rIdMapper.getReference( OUString(sId) ), UNO_QUERY ); |
599 | 0 | } |
600 | |
|
601 | 0 | for( nIndex = 0; nIndex < nCount; ++nIndex ) |
602 | 0 | { |
603 | 0 | if( !aShapes[nIndex].is() ) |
604 | 0 | { |
605 | 0 | OSL_FAIL("xmloff::SdXMLGenericPageContext::SetNavigationOrder(), draw:nav-order attribute incomplete!"); |
606 | | // todo: warning? |
607 | 0 | return; |
608 | 0 | } |
609 | 0 | } |
610 | | |
611 | 0 | Reference< XPropertySet > xSet( mxShapes, UNO_QUERY_THROW ); |
612 | 0 | xSet->setPropertyValue(u"NavigationOrder"_ustr, Any( Reference< XIndexAccess >( new XoNavigationOrderAccess( aShapes ) ) ) ); |
613 | 0 | } |
614 | 0 | catch(const uno::Exception&) |
615 | 0 | { |
616 | 0 | TOOLS_WARN_EXCEPTION("xmloff.draw", |
617 | 0 | "unexpected exception caught while importing shape navigation order!"); |
618 | 0 | } |
619 | 0 | } |
620 | | |
621 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |