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>
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"
33 
34 using namespace ::std;
35 using namespace ::cppu;
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::xml;
38 using namespace ::com::sun::star::xml::sax;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::drawing;
41 using namespace ::com::sun::star::beans;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::util;
44 using namespace ::com::sun::star::container;
45 using namespace ::com::sun::star::presentation;
46 using namespace ::xmloff::token;
47 
SdXMLShowsContext(SdXMLImport & rImport,const Reference<XFastAttributeList> & xAttrList)48 SdXMLShowsContext::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;
74     if (rImport.getGeneratorVersion() < SvXMLImport::LO_6x)
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.toString()))
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 
~SdXMLShowsContext()170 SdXMLShowsContext::~SdXMLShowsContext()
171 {
172     if( !maCustomShowName.isEmpty() )
173     {
174         uno::Any aAny;
175         aAny <<= maCustomShowName;
176         mxPresProps->setPropertyValue("CustomShow", aAny );
177     }
178 }
179 
createFastChildContext(sal_Int32 nElement,const css::uno::Reference<css::xml::sax::XFastAttributeList> & xAttrList)180 css::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: */
245