Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / xmloff / source / draw / ximpshow.cxx
blobcf9c540db69241c7fec1a8eb0262b21d1bad4593
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/presentation/XCustomPresentationSupplier.hpp>
23 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
24 #include <com/sun/star/container/XIndexContainer.hpp>
25 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
26 #include <sax/tools/converter.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include "ximpshow.hxx"
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::xml;
34 using namespace ::com::sun::star::xml::sax;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::drawing;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::util;
40 using namespace ::com::sun::star::container;
41 using namespace ::com::sun::star::presentation;
42 using namespace ::xmloff::token;
44 SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, const Reference< XFastAttributeList >& xAttrList )
45 : SvXMLImportContext(rImport)
48 Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY );
49 if( xShowsSupplier.is() )
51 mxShows = xShowsSupplier->getCustomPresentations();
52 mxShowFactory.set( mxShows, UNO_QUERY );
55 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY );
56 if( xDrawPagesSupplier.is() )
57 mxPages.set( xDrawPagesSupplier->getDrawPages(), UNO_QUERY );
59 Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY );
60 if( xPresentationSupplier.is() )
61 mxPresProps.set( xPresentationSupplier->getPresentation(), UNO_QUERY );
63 if( !mxPresProps.is() )
64 return;
66 bool bAll = true;
67 uno::Any aAny;
68 // Per ODF this is default, but we did it wrong before LO 6.0 (tdf#108824)
69 bool bIsMouseVisible = true;
70 if (rImport.getGeneratorVersion() < SvXMLImport::LO_6x)
71 bIsMouseVisible = false;
73 // read attributes
74 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
76 switch( aIter.getToken() )
78 case XML_ELEMENT(PRESENTATION, XML_START_PAGE):
80 mxPresProps->setPropertyValue(u"FirstPage"_ustr, Any(aIter.toString()) );
81 bAll = false;
82 break;
84 case XML_ELEMENT(PRESENTATION, XML_SHOW):
86 maCustomShowName = aIter.toString();
87 bAll = false;
88 break;
90 case XML_ELEMENT(PRESENTATION, XML_PAUSE):
92 Duration aDuration;
93 if (!::sax::Converter::convertDuration(aDuration, aIter.toView()))
94 continue;
96 const sal_Int32 nMS = (aDuration.Hours * 60 +
97 aDuration.Minutes) * 60 + aDuration.Seconds;
98 mxPresProps->setPropertyValue(u"Pause"_ustr, Any(nMS) );
99 break;
101 case XML_ELEMENT(PRESENTATION, XML_ANIMATIONS):
103 aAny <<= IsXMLToken( aIter, XML_ENABLED );
104 mxPresProps->setPropertyValue(u"AllowAnimations"_ustr, aAny );
105 break;
107 case XML_ELEMENT(PRESENTATION, XML_STAY_ON_TOP):
109 aAny <<= IsXMLToken( aIter, XML_TRUE );
110 mxPresProps->setPropertyValue(u"IsAlwaysOnTop"_ustr, aAny );
111 break;
113 case XML_ELEMENT(PRESENTATION, XML_FORCE_MANUAL):
115 aAny <<= IsXMLToken( aIter, XML_TRUE );
116 mxPresProps->setPropertyValue(u"IsAutomatic"_ustr, aAny );
117 break;
119 case XML_ELEMENT(PRESENTATION, XML_ENDLESS):
121 aAny <<= IsXMLToken( aIter, XML_TRUE );
122 mxPresProps->setPropertyValue(u"IsEndless"_ustr, aAny );
123 break;
125 case XML_ELEMENT(PRESENTATION, XML_FULL_SCREEN):
127 aAny <<= IsXMLToken( aIter, XML_TRUE );
128 mxPresProps->setPropertyValue(u"IsFullScreen"_ustr, aAny );
129 break;
131 case XML_ELEMENT(PRESENTATION, XML_MOUSE_VISIBLE):
133 bIsMouseVisible = IsXMLToken( aIter, XML_TRUE );
134 break;
136 case XML_ELEMENT(PRESENTATION, XML_START_WITH_NAVIGATOR):
138 aAny <<= IsXMLToken( aIter, XML_TRUE );
139 mxPresProps->setPropertyValue(u"StartWithNavigator"_ustr, aAny );
140 break;
142 case XML_ELEMENT(PRESENTATION, XML_MOUSE_AS_PEN):
144 aAny <<= IsXMLToken( aIter, XML_TRUE );
145 mxPresProps->setPropertyValue(u"UsePen"_ustr, aAny );
146 break;
148 case XML_ELEMENT(PRESENTATION, XML_TRANSITION_ON_CLICK):
150 aAny <<= IsXMLToken( aIter, XML_ENABLED );
151 mxPresProps->setPropertyValue(u"IsTransitionOnClick"_ustr, aAny );
152 break;
154 case XML_ELEMENT(PRESENTATION, XML_SHOW_LOGO):
156 aAny <<= IsXMLToken( aIter, XML_TRUE );
157 mxPresProps->setPropertyValue(u"IsShowLogo"_ustr, aAny );
158 break;
162 mxPresProps->setPropertyValue(u"IsShowAll"_ustr, Any(bAll) );
163 mxPresProps->setPropertyValue(u"IsMouseVisible"_ustr, Any(bIsMouseVisible) );
166 SdXMLShowsContext::~SdXMLShowsContext()
168 if( !maCustomShowName.isEmpty() )
170 uno::Any aAny;
171 aAny <<= maCustomShowName;
172 mxPresProps->setPropertyValue(u"CustomShow"_ustr, aAny );
176 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLShowsContext::createFastChildContext(
177 sal_Int32 nElement,
178 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
180 if( nElement == XML_ELEMENT(PRESENTATION, XML_SHOW) )
182 OUString aName;
183 OUString aPages;
185 // read attributes
186 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
188 OUString sValue = aIter.toString();
190 switch( aIter.getToken() )
192 case XML_ELEMENT(PRESENTATION, XML_NAME):
193 aName = sValue;
194 break;
195 case XML_ELEMENT(PRESENTATION, XML_PAGES):
196 aPages = sValue;
197 break;
201 if( !aName.isEmpty() && !aPages.isEmpty() )
203 Reference< XIndexContainer > xShow( mxShowFactory->createInstance(), UNO_QUERY );
204 if( xShow.is() )
206 SvXMLTokenEnumerator aPageNames( aPages, ',' );
207 std::u16string_view sPageNameView;
209 while( aPageNames.getNextToken( sPageNameView ) )
211 OUString sPageName(sPageNameView);
212 if( !mxPages->hasByName( sPageName ) )
213 continue;
215 Reference< XDrawPage > xPage;
216 mxPages->getByName( sPageName ) >>= xPage;
217 if( xPage.is() )
219 xShow->insertByIndex( xShow->getCount(), Any(xPage) );
223 Any aAny;
224 aAny <<= xShow;
225 if( mxShows->hasByName( aName ) )
227 mxShows->replaceByName( aName, aAny );
229 else
231 mxShows->insertByName( aName, aAny );
237 return nullptr;
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */