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