bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / draw / ximpshow.cxx
blob2cc993478da0614bcb51b74185206879b87f973d
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/util/Duration.hpp>
21 #include <com/sun/star/xml/sax/XAttributeList.hpp>
22 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
23 #include <com/sun/star/container/XNameContainer.hpp>
24 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
25 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
26 #include <com/sun/star/container/XIndexContainer.hpp>
27 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
28 #include <sax/tools/converter.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include "ximpshow.hxx"
35 using namespace ::std;
36 using namespace ::cppu;
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::xml;
39 using namespace ::com::sun::star::xml::sax;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::drawing;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::util;
45 using namespace ::com::sun::star::container;
46 using namespace ::com::sun::star::presentation;
47 using namespace ::xmloff::token;
49 class ShowsImpImpl
51 public:
52 Reference< XSingleServiceFactory > mxShowFactory;
53 Reference< XNameContainer > mxShows;
54 Reference< XPropertySet > mxPresProps;
55 Reference< XNameAccess > mxPages;
56 OUString maCustomShowName;
57 SdXMLImport& mrImport;
59 ShowsImpImpl( SdXMLImport& rImport )
60 : mrImport( rImport )
64 TYPEINIT1( SdXMLShowsContext, SvXMLImportContext );
66 SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
67 : SvXMLImportContext(rImport, nPrfx, rLocalName)
69 mpImpl = new ShowsImpImpl( rImport );
71 Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY );
72 if( xShowsSupplier.is() )
74 mpImpl->mxShows = xShowsSupplier->getCustomPresentations();
75 mpImpl->mxShowFactory = Reference< XSingleServiceFactory >::query( mpImpl->mxShows );
78 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY );
79 if( xDrawPagesSupplier.is() )
80 mpImpl->mxPages = Reference< XNameAccess >::query( xDrawPagesSupplier->getDrawPages() );
82 Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY );
83 if( xPresentationSupplier.is() )
84 mpImpl->mxPresProps = Reference< XPropertySet >::query( xPresentationSupplier->getPresentation() );
86 if( mpImpl->mxPresProps.is() )
88 bool bAll = true;
89 uno::Any aAny;
91 // read attributes
92 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
93 for(sal_Int16 i=0; i < nAttrCount; i++)
95 OUString sAttrName = xAttrList->getNameByIndex( i );
96 OUString aLocalName;
97 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
98 OUString sValue = xAttrList->getValueByIndex( i );
100 switch( nPrefix )
102 case XML_NAMESPACE_PRESENTATION:
103 if( IsXMLToken( aLocalName, XML_START_PAGE ) )
105 aAny <<= sValue;
106 mpImpl->mxPresProps->setPropertyValue("FirstPage", aAny );
107 bAll = false;
109 else if( IsXMLToken( aLocalName, XML_SHOW ) )
111 mpImpl->maCustomShowName = sValue;
112 bAll = false;
114 else if( IsXMLToken( aLocalName, XML_PAUSE ) )
116 Duration aDuration;
117 if (!::sax::Converter::convertDuration(aDuration, sValue))
118 continue;
120 const sal_Int32 nMS = (aDuration.Hours * 60 +
121 aDuration.Minutes) * 60 + aDuration.Seconds;
122 aAny <<= nMS;
123 mpImpl->mxPresProps->setPropertyValue("Pause", aAny );
125 else if( IsXMLToken( aLocalName, XML_ANIMATIONS ) )
127 aAny <<= IsXMLToken( sValue, XML_ENABLED );
128 mpImpl->mxPresProps->setPropertyValue("AllowAnimations", aAny );
130 else if( IsXMLToken( aLocalName, XML_STAY_ON_TOP ) )
132 aAny <<= IsXMLToken( sValue, XML_TRUE );
133 mpImpl->mxPresProps->setPropertyValue("IsAlwaysOnTop", aAny );
135 else if( IsXMLToken( aLocalName, XML_FORCE_MANUAL ) )
137 aAny <<= IsXMLToken( sValue, XML_TRUE );
138 mpImpl->mxPresProps->setPropertyValue("IsAutomatic", aAny );
140 else if( IsXMLToken( aLocalName, XML_ENDLESS ) )
142 aAny <<= IsXMLToken( sValue, XML_TRUE );
143 mpImpl->mxPresProps->setPropertyValue("IsEndless", aAny );
145 else if( IsXMLToken( aLocalName, XML_FULL_SCREEN ) )
147 aAny <<= IsXMLToken( sValue, XML_TRUE );
148 mpImpl->mxPresProps->setPropertyValue("IsFullScreen", aAny );
150 else if( IsXMLToken( aLocalName, XML_MOUSE_VISIBLE ) )
152 aAny <<= IsXMLToken( sValue, XML_TRUE );
153 mpImpl->mxPresProps->setPropertyValue("IsMouseVisible", aAny );
155 else if( IsXMLToken( aLocalName, XML_START_WITH_NAVIGATOR ) )
157 aAny <<= IsXMLToken( sValue, XML_TRUE );
158 mpImpl->mxPresProps->setPropertyValue("StartWithNavigator", aAny );
160 else if( IsXMLToken( aLocalName, XML_MOUSE_AS_PEN ) )
162 aAny <<= IsXMLToken( sValue, XML_TRUE );
163 mpImpl->mxPresProps->setPropertyValue("UsePen", aAny );
165 else if( IsXMLToken( aLocalName, XML_TRANSITION_ON_CLICK ) )
167 aAny <<= IsXMLToken( sValue, XML_ENABLED );
168 mpImpl->mxPresProps->setPropertyValue("IsTransitionOnClick", aAny );
170 else if( IsXMLToken( aLocalName, XML_SHOW_LOGO ) )
172 aAny <<= IsXMLToken( sValue, XML_TRUE );
173 mpImpl->mxPresProps->setPropertyValue("IsShowLogo", aAny );
177 aAny <<= bAll;
178 mpImpl->mxPresProps->setPropertyValue("IsShowAll", aAny );
182 SdXMLShowsContext::~SdXMLShowsContext()
184 if( mpImpl && !mpImpl->maCustomShowName.isEmpty() )
186 uno::Any aAny;
187 aAny <<= mpImpl->maCustomShowName;
188 mpImpl->mxPresProps->setPropertyValue("CustomShow", aAny );
191 delete mpImpl;
194 SvXMLImportContext * SdXMLShowsContext::CreateChildContext( sal_uInt16 p_nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList )
196 if( mpImpl && p_nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SHOW ) )
198 OUString aName;
199 OUString aPages;
201 // read attributes
202 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
203 for(sal_Int16 i=0; i < nAttrCount; i++)
205 OUString sAttrName = xAttrList->getNameByIndex( i );
206 OUString aLocalName;
207 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
208 OUString sValue = xAttrList->getValueByIndex( i );
210 switch( nPrefix )
212 case XML_NAMESPACE_PRESENTATION:
213 if( IsXMLToken( aLocalName, XML_NAME ) )
215 aName = sValue;
217 else if( IsXMLToken( aLocalName, XML_PAGES ) )
219 aPages = sValue;
224 if( !aName.isEmpty() && !aPages.isEmpty() )
226 Reference< XIndexContainer > xShow( mpImpl->mxShowFactory->createInstance(), UNO_QUERY );
227 if( xShow.is() )
229 SvXMLTokenEnumerator aPageNames( aPages, ',' );
230 OUString sPageName;
231 Any aAny;
233 while( aPageNames.getNextToken( sPageName ) )
235 if( !mpImpl->mxPages->hasByName( sPageName ) )
236 continue;
238 Reference< XDrawPage > xPage;
239 mpImpl->mxPages->getByName( sPageName ) >>= xPage;
240 if( xPage.is() )
242 aAny <<= xPage;
243 xShow->insertByIndex( xShow->getCount(), aAny );
247 aAny <<= xShow;
249 if( mpImpl->mxShows->hasByName( aName ) )
251 mpImpl->mxShows->replaceByName( aName, aAny );
253 else
255 mpImpl->mxShows->insertByName( aName, aAny );
261 return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */