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