Bump version to 24.04.3.4
[LibreOffice.git] / xmloff / source / draw / ximpshow.cxx
blob117511f77c640da886e475eb257a70229a71c54e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmlnamespace.hxx>
30 #include <xmloff/namespacemap.hxx>
31 #include <xmloff/xmluconv.hxx>
32 #include "ximpshow.hxx"
34 using namespace ::cppu;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::xml;
37 using namespace ::com::sun::star::xml::sax;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::drawing;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::util;
43 using namespace ::com::sun::star::container;
44 using namespace ::com::sun::star::presentation;
45 using namespace ::xmloff::token;
47 SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, const Reference< XFastAttributeList >& xAttrList )
48 : SvXMLImportContext(rImport)
51 Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY );
52 if( xShowsSupplier.is() )
54 mxShows = xShowsSupplier->getCustomPresentations();
55 mxShowFactory.set( mxShows, UNO_QUERY );
58 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY );
59 if( xDrawPagesSupplier.is() )
60 mxPages.set( xDrawPagesSupplier->getDrawPages(), UNO_QUERY );
62 Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY );
63 if( xPresentationSupplier.is() )
64 mxPresProps.set( xPresentationSupplier->getPresentation(), UNO_QUERY );
66 if( !mxPresProps.is() )
67 return;
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;
76 // read attributes
77 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
79 switch( aIter.getToken() )
81 case XML_ELEMENT(PRESENTATION, XML_START_PAGE):
83 mxPresProps->setPropertyValue("FirstPage", Any(aIter.toString()) );
84 bAll = false;
85 break;
87 case XML_ELEMENT(PRESENTATION, XML_SHOW):
89 maCustomShowName = aIter.toString();
90 bAll = false;
91 break;
93 case XML_ELEMENT(PRESENTATION, XML_PAUSE):
95 Duration aDuration;
96 if (!::sax::Converter::convertDuration(aDuration, aIter.toView()))
97 continue;
99 const sal_Int32 nMS = (aDuration.Hours * 60 +
100 aDuration.Minutes) * 60 + aDuration.Seconds;
101 mxPresProps->setPropertyValue("Pause", Any(nMS) );
102 break;
104 case XML_ELEMENT(PRESENTATION, XML_ANIMATIONS):
106 aAny <<= IsXMLToken( aIter, XML_ENABLED );
107 mxPresProps->setPropertyValue("AllowAnimations", aAny );
108 break;
110 case XML_ELEMENT(PRESENTATION, XML_STAY_ON_TOP):
112 aAny <<= IsXMLToken( aIter, XML_TRUE );
113 mxPresProps->setPropertyValue("IsAlwaysOnTop", aAny );
114 break;
116 case XML_ELEMENT(PRESENTATION, XML_FORCE_MANUAL):
118 aAny <<= IsXMLToken( aIter, XML_TRUE );
119 mxPresProps->setPropertyValue("IsAutomatic", aAny );
120 break;
122 case XML_ELEMENT(PRESENTATION, XML_ENDLESS):
124 aAny <<= IsXMLToken( aIter, XML_TRUE );
125 mxPresProps->setPropertyValue("IsEndless", aAny );
126 break;
128 case XML_ELEMENT(PRESENTATION, XML_FULL_SCREEN):
130 aAny <<= IsXMLToken( aIter, XML_TRUE );
131 mxPresProps->setPropertyValue("IsFullScreen", aAny );
132 break;
134 case XML_ELEMENT(PRESENTATION, XML_MOUSE_VISIBLE):
136 bIsMouseVisible = IsXMLToken( aIter, XML_TRUE );
137 break;
139 case XML_ELEMENT(PRESENTATION, XML_START_WITH_NAVIGATOR):
141 aAny <<= IsXMLToken( aIter, XML_TRUE );
142 mxPresProps->setPropertyValue("StartWithNavigator", aAny );
143 break;
145 case XML_ELEMENT(PRESENTATION, XML_MOUSE_AS_PEN):
147 aAny <<= IsXMLToken( aIter, XML_TRUE );
148 mxPresProps->setPropertyValue("UsePen", aAny );
149 break;
151 case XML_ELEMENT(PRESENTATION, XML_TRANSITION_ON_CLICK):
153 aAny <<= IsXMLToken( aIter, XML_ENABLED );
154 mxPresProps->setPropertyValue("IsTransitionOnClick", aAny );
155 break;
157 case XML_ELEMENT(PRESENTATION, XML_SHOW_LOGO):
159 aAny <<= IsXMLToken( aIter, XML_TRUE );
160 mxPresProps->setPropertyValue("IsShowLogo", aAny );
161 break;
165 mxPresProps->setPropertyValue("IsShowAll", Any(bAll) );
166 mxPresProps->setPropertyValue("IsMouseVisible", Any(bIsMouseVisible) );
169 SdXMLShowsContext::~SdXMLShowsContext()
171 if( !maCustomShowName.isEmpty() )
173 uno::Any aAny;
174 aAny <<= maCustomShowName;
175 mxPresProps->setPropertyValue("CustomShow", aAny );
179 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLShowsContext::createFastChildContext(
180 sal_Int32 nElement,
181 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
183 if( nElement == XML_ELEMENT(PRESENTATION, XML_SHOW) )
185 OUString aName;
186 OUString aPages;
188 // read attributes
189 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
191 OUString sValue = aIter.toString();
193 switch( aIter.getToken() )
195 case XML_ELEMENT(PRESENTATION, XML_NAME):
196 aName = sValue;
197 break;
198 case XML_ELEMENT(PRESENTATION, XML_PAGES):
199 aPages = sValue;
200 break;
204 if( !aName.isEmpty() && !aPages.isEmpty() )
206 Reference< XIndexContainer > xShow( mxShowFactory->createInstance(), UNO_QUERY );
207 if( xShow.is() )
209 SvXMLTokenEnumerator aPageNames( aPages, ',' );
210 std::u16string_view sPageNameView;
212 while( aPageNames.getNextToken( sPageNameView ) )
214 OUString sPageName(sPageNameView);
215 if( !mxPages->hasByName( sPageName ) )
216 continue;
218 Reference< XDrawPage > xPage;
219 mxPages->getByName( sPageName ) >>= xPage;
220 if( xPage.is() )
222 xShow->insertByIndex( xShow->getCount(), Any(xPage) );
226 Any aAny;
227 aAny <<= xShow;
228 if( mxShows->hasByName( aName ) )
230 mxShows->replaceByName( aName, aAny );
232 else
234 mxShows->insertByName( aName, aAny );
240 return nullptr;
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */