LibreOffice Module xmloff (master) 1
ximpshow.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
20#include <com/sun/star/frame/XModel.hpp>
21#include <com/sun/star/util/Duration.hpp>
22#include <com/sun/star/xml/sax/XAttributeList.hpp>
23#include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
24#include <com/sun/star/presentation/XPresentationSupplier.hpp>
25#include <com/sun/star/container/XIndexContainer.hpp>
26#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
28#include <xmloff/xmltoken.hxx>
31#include <xmloff/xmluconv.hxx>
32#include "ximpshow.hxx"
33
34using namespace ::cppu;
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::xml;
37using namespace ::com::sun::star::xml::sax;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::drawing;
40using namespace ::com::sun::star::beans;
41using namespace ::com::sun::star::lang;
42using namespace ::com::sun::star::util;
43using namespace ::com::sun::star::container;
44using namespace ::com::sun::star::presentation;
45using namespace ::xmloff::token;
46
47SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, const Reference< XFastAttributeList >& xAttrList )
48: SvXMLImportContext(rImport)
49{
50
51 Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY );
52 if( xShowsSupplier.is() )
53 {
54 mxShows = xShowsSupplier->getCustomPresentations();
55 mxShowFactory.set( mxShows, UNO_QUERY );
56 }
57
58 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY );
59 if( xDrawPagesSupplier.is() )
60 mxPages.set( xDrawPagesSupplier->getDrawPages(), UNO_QUERY );
61
62 Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY );
63 if( xPresentationSupplier.is() )
64 mxPresProps.set( xPresentationSupplier->getPresentation(), UNO_QUERY );
65
66 if( !mxPresProps.is() )
67 return;
68
69 bool bAll = true;
70 uno::Any aAny;
71 // Per ODF this is default, but we did it wrong before LO 6.0 (tdf#108824)
72 bool bIsMouseVisible = true;
73 if (rImport.getGeneratorVersion() < SvXMLImport::LO_6x)
74 bIsMouseVisible = false;
75
76 // read attributes
77 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
78 {
79 switch( aIter.getToken() )
80 {
81 case XML_ELEMENT(PRESENTATION, XML_START_PAGE):
82 {
83 mxPresProps->setPropertyValue("FirstPage", Any(aIter.toString()) );
84 bAll = false;
85 break;
86 }
87 case XML_ELEMENT(PRESENTATION, XML_SHOW):
88 {
89 maCustomShowName = aIter.toString();
90 bAll = false;
91 break;
92 }
93 case XML_ELEMENT(PRESENTATION, XML_PAUSE):
94 {
95 Duration aDuration;
96 if (!::sax::Converter::convertDuration(aDuration, aIter.toView()))
97 continue;
98
99 const sal_Int32 nMS = (aDuration.Hours * 60 +
100 aDuration.Minutes) * 60 + aDuration.Seconds;
101 mxPresProps->setPropertyValue("Pause", Any(nMS) );
102 break;
103 }
104 case XML_ELEMENT(PRESENTATION, XML_ANIMATIONS):
105 {
106 aAny <<= IsXMLToken( aIter, XML_ENABLED );
107 mxPresProps->setPropertyValue("AllowAnimations", aAny );
108 break;
109 }
110 case XML_ELEMENT(PRESENTATION, XML_STAY_ON_TOP):
111 {
112 aAny <<= IsXMLToken( aIter, XML_TRUE );
113 mxPresProps->setPropertyValue("IsAlwaysOnTop", aAny );
114 break;
115 }
116 case XML_ELEMENT(PRESENTATION, XML_FORCE_MANUAL):
117 {
118 aAny <<= IsXMLToken( aIter, XML_TRUE );
119 mxPresProps->setPropertyValue("IsAutomatic", aAny );
120 break;
121 }
122 case XML_ELEMENT(PRESENTATION, XML_ENDLESS):
123 {
124 aAny <<= IsXMLToken( aIter, XML_TRUE );
125 mxPresProps->setPropertyValue("IsEndless", aAny );
126 break;
127 }
128 case XML_ELEMENT(PRESENTATION, XML_FULL_SCREEN):
129 {
130 aAny <<= IsXMLToken( aIter, XML_TRUE );
131 mxPresProps->setPropertyValue("IsFullScreen", aAny );
132 break;
133 }
134 case XML_ELEMENT(PRESENTATION, XML_MOUSE_VISIBLE):
135 {
136 bIsMouseVisible = IsXMLToken( aIter, XML_TRUE );
137 break;
138 }
139 case XML_ELEMENT(PRESENTATION, XML_START_WITH_NAVIGATOR):
140 {
141 aAny <<= IsXMLToken( aIter, XML_TRUE );
142 mxPresProps->setPropertyValue("StartWithNavigator", aAny );
143 break;
144 }
145 case XML_ELEMENT(PRESENTATION, XML_MOUSE_AS_PEN):
146 {
147 aAny <<= IsXMLToken( aIter, XML_TRUE );
148 mxPresProps->setPropertyValue("UsePen", aAny );
149 break;
150 }
151 case XML_ELEMENT(PRESENTATION, XML_TRANSITION_ON_CLICK):
152 {
153 aAny <<= IsXMLToken( aIter, XML_ENABLED );
154 mxPresProps->setPropertyValue("IsTransitionOnClick", aAny );
155 break;
156 }
157 case XML_ELEMENT(PRESENTATION, XML_SHOW_LOGO):
158 {
159 aAny <<= IsXMLToken( aIter, XML_TRUE );
160 mxPresProps->setPropertyValue("IsShowLogo", aAny );
161 break;
162 }
163 }
164 }
165 mxPresProps->setPropertyValue("IsShowAll", Any(bAll) );
166 mxPresProps->setPropertyValue("IsMouseVisible", Any(bIsMouseVisible) );
167}
168
170{
171 if( !maCustomShowName.isEmpty() )
172 {
173 uno::Any aAny;
174 aAny <<= maCustomShowName;
175 mxPresProps->setPropertyValue("CustomShow", aAny );
176 }
177}
178
179css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLShowsContext::createFastChildContext(
180 sal_Int32 nElement,
181 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
182{
183 if( nElement == XML_ELEMENT(PRESENTATION, XML_SHOW) )
184 {
185 OUString aName;
186 OUString aPages;
187
188 // read attributes
189 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
190 {
191 OUString sValue = aIter.toString();
192
193 switch( aIter.getToken() )
194 {
195 case XML_ELEMENT(PRESENTATION, XML_NAME):
196 aName = sValue;
197 break;
198 case XML_ELEMENT(PRESENTATION, XML_PAGES):
199 aPages = sValue;
200 break;
201 }
202 }
203
204 if( !aName.isEmpty() && !aPages.isEmpty() )
205 {
206 Reference< XIndexContainer > xShow( mxShowFactory->createInstance(), UNO_QUERY );
207 if( xShow.is() )
208 {
209 SvXMLTokenEnumerator aPageNames( aPages, ',' );
210 std::u16string_view sPageNameView;
211
212 while( aPageNames.getNextToken( sPageNameView ) )
213 {
214 OUString sPageName(sPageNameView);
215 if( !mxPages->hasByName( sPageName ) )
216 continue;
217
218 Reference< XDrawPage > xPage;
219 mxPages->getByName( sPageName ) >>= xPage;
220 if( xPage.is() )
221 {
222 xShow->insertByIndex( xShow->getCount(), Any(xPage) );
223 }
224 }
225
226 Any aAny;
227 aAny <<= xShow;
228 if( mxShows->hasByName( aName ) )
229 {
230 mxShows->replaceByName( aName, aAny );
231 }
232 else
233 {
234 mxShows->insertByName( aName, aAny );
235 }
236 }
237 }
238 }
239
240 return nullptr;
241}
242
243/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::container::XNameAccess > mxPages
Definition: ximpshow.hxx:45
css::uno::Reference< css::lang::XSingleServiceFactory > mxShowFactory
Definition: ximpshow.hxx:42
css::uno::Reference< css::beans::XPropertySet > mxPresProps
Definition: ximpshow.hxx:44
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: ximpshow.cxx:179
SdXMLShowsContext(SdXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Definition: ximpshow.cxx:47
OUString maCustomShowName
Definition: ximpshow.hxx:46
css::uno::Reference< css::container::XNameContainer > mxShows
Definition: ximpshow.hxx:43
virtual ~SdXMLShowsContext() override
Definition: ximpshow.cxx:169
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
bool getNextToken(std::u16string_view &rToken)
Definition: xmluconv.cxx:529
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
OUString aName
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_START_WITH_NAVIGATOR
Definition: xmltoken.hxx:1850
@ XML_TRANSITION_ON_CLICK
Definition: xmltoken.hxx:2032
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97