update credits
[LibreOffice.git] / xmloff / source / draw / ximpshow.cxx
blobd80c71d43ecb71e89e09a92f149e7121faa8773b
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 .
21 #include <com/sun/star/util/Duration.hpp>
22 #include <com/sun/star/xml/sax/XAttributeList.hpp>
23 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
24 #include <com/sun/star/container/XNameContainer.hpp>
25 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
26 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
27 #include <com/sun/star/container/XIndexContainer.hpp>
28 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
29 #include <sax/tools/converter.hxx>
30 #include <xmloff/xmltoken.hxx>
31 #include <comphelper/extract.hxx>
32 #include "xmloff/xmlnmspe.hxx"
33 #include <xmloff/nmspmap.hxx>
34 #include <xmloff/xmluconv.hxx>
35 #include "ximpshow.hxx"
38 using namespace ::std;
39 using namespace ::cppu;
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::xml;
42 using namespace ::com::sun::star::xml::sax;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::drawing;
45 using namespace ::com::sun::star::beans;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::util;
48 using namespace ::com::sun::star::container;
49 using namespace ::com::sun::star::presentation;
50 using namespace ::xmloff::token;
52 ///////////////////////////////////////////////////////////////////////
54 class ShowsImpImpl
56 public:
57 Reference< XSingleServiceFactory > mxShowFactory;
58 Reference< XNameContainer > mxShows;
59 Reference< XPropertySet > mxPresProps;
60 Reference< XNameAccess > mxPages;
61 OUString maCustomShowName;
62 SdXMLImport& mrImport;
64 ShowsImpImpl( SdXMLImport& rImport )
65 : mrImport( rImport )
69 ///////////////////////////////////////////////////////////////////////
71 TYPEINIT1( SdXMLShowsContext, SvXMLImportContext );
73 SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
74 : SvXMLImportContext(rImport, nPrfx, rLocalName)
76 mpImpl = new ShowsImpImpl( rImport );
78 Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY );
79 if( xShowsSupplier.is() )
81 mpImpl->mxShows = xShowsSupplier->getCustomPresentations();
82 mpImpl->mxShowFactory = Reference< XSingleServiceFactory >::query( mpImpl->mxShows );
85 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY );
86 if( xDrawPagesSupplier.is() )
87 mpImpl->mxPages = Reference< XNameAccess >::query( xDrawPagesSupplier->getDrawPages() );
89 Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY );
90 if( xPresentationSupplier.is() )
91 mpImpl->mxPresProps = Reference< XPropertySet >::query( xPresentationSupplier->getPresentation() );
94 if( mpImpl->mxPresProps.is() )
96 sal_Bool bAll = sal_True;
97 uno::Any aAny;
99 // read attributes
100 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
101 for(sal_Int16 i=0; i < nAttrCount; i++)
103 OUString sAttrName = xAttrList->getNameByIndex( i );
104 OUString aLocalName;
105 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
106 OUString sValue = xAttrList->getValueByIndex( i );
108 switch( nPrefix )
110 case XML_NAMESPACE_PRESENTATION:
111 if( IsXMLToken( aLocalName, XML_START_PAGE ) )
113 aAny <<= sValue;
114 mpImpl->mxPresProps->setPropertyValue( OUString( "FirstPage" ), aAny );
115 bAll = sal_False;
117 else if( IsXMLToken( aLocalName, XML_SHOW ) )
119 mpImpl->maCustomShowName = sValue;
120 bAll = sal_False;
122 else if( IsXMLToken( aLocalName, XML_PAUSE ) )
124 Duration aDuration;
125 if (!::sax::Converter::convertDuration(aDuration, sValue))
126 continue;
128 const sal_Int32 nMS = (aDuration.Hours * 60 +
129 aDuration.Minutes) * 60 + aDuration.Seconds;
130 aAny <<= nMS;
131 mpImpl->mxPresProps->setPropertyValue( OUString( "Pause" ), aAny );
133 else if( IsXMLToken( aLocalName, XML_ANIMATIONS ) )
135 aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
136 mpImpl->mxPresProps->setPropertyValue( OUString( "AllowAnimations" ), aAny );
138 else if( IsXMLToken( aLocalName, XML_STAY_ON_TOP ) )
140 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
141 mpImpl->mxPresProps->setPropertyValue( OUString( "IsAlwaysOnTop" ), aAny );
143 else if( IsXMLToken( aLocalName, XML_FORCE_MANUAL ) )
145 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
146 mpImpl->mxPresProps->setPropertyValue( OUString( "IsAutomatic" ), aAny );
148 else if( IsXMLToken( aLocalName, XML_ENDLESS ) )
150 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
151 mpImpl->mxPresProps->setPropertyValue( OUString( "IsEndless" ), aAny );
153 else if( IsXMLToken( aLocalName, XML_FULL_SCREEN ) )
155 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
156 mpImpl->mxPresProps->setPropertyValue( OUString( "IsFullScreen" ), aAny );
158 else if( IsXMLToken( aLocalName, XML_MOUSE_VISIBLE ) )
160 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
161 mpImpl->mxPresProps->setPropertyValue( OUString( "IsMouseVisible" ), aAny );
163 else if( IsXMLToken( aLocalName, XML_START_WITH_NAVIGATOR ) )
165 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
166 mpImpl->mxPresProps->setPropertyValue( OUString( "StartWithNavigator" ), aAny );
168 else if( IsXMLToken( aLocalName, XML_MOUSE_AS_PEN ) )
170 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
171 mpImpl->mxPresProps->setPropertyValue( OUString( "UsePen" ), aAny );
173 else if( IsXMLToken( aLocalName, XML_TRANSITION_ON_CLICK ) )
175 aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
176 mpImpl->mxPresProps->setPropertyValue( OUString( "IsTransitionOnClick" ), aAny );
178 else if( IsXMLToken( aLocalName, XML_SHOW_LOGO ) )
180 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
181 mpImpl->mxPresProps->setPropertyValue( OUString( "IsShowLogo" ), aAny );
185 aAny = bool2any( bAll );
186 mpImpl->mxPresProps->setPropertyValue( OUString( "IsShowAll" ), aAny );
190 SdXMLShowsContext::~SdXMLShowsContext()
192 if( mpImpl && !mpImpl->maCustomShowName.isEmpty() )
194 uno::Any aAny;
195 aAny <<= mpImpl->maCustomShowName;
196 mpImpl->mxPresProps->setPropertyValue( OUString( "CustomShow" ), aAny );
199 delete mpImpl;
202 SvXMLImportContext * SdXMLShowsContext::CreateChildContext( sal_uInt16 p_nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList )
204 if( mpImpl && p_nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SHOW ) )
206 OUString aName;
207 OUString aPages;
209 // read attributes
210 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
211 for(sal_Int16 i=0; i < nAttrCount; i++)
213 OUString sAttrName = xAttrList->getNameByIndex( i );
214 OUString aLocalName;
215 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
216 OUString sValue = xAttrList->getValueByIndex( i );
218 switch( nPrefix )
220 case XML_NAMESPACE_PRESENTATION:
221 if( IsXMLToken( aLocalName, XML_NAME ) )
223 aName = sValue;
225 else if( IsXMLToken( aLocalName, XML_PAGES ) )
227 aPages = sValue;
232 if( !aName.isEmpty() && !aPages.isEmpty() )
234 Reference< XIndexContainer > xShow( mpImpl->mxShowFactory->createInstance(), UNO_QUERY );
235 if( xShow.is() )
237 SvXMLTokenEnumerator aPageNames( aPages, sal_Unicode(',') );
238 OUString sPageName;
239 Any aAny;
241 while( aPageNames.getNextToken( sPageName ) )
243 if( !mpImpl->mxPages->hasByName( sPageName ) )
244 continue;
246 Reference< XDrawPage > xPage;
247 mpImpl->mxPages->getByName( sPageName ) >>= xPage;
248 if( xPage.is() )
250 aAny <<= xPage;
251 xShow->insertByIndex( xShow->getCount(), aAny );
255 aAny <<= xShow;
257 if( mpImpl->mxShows->hasByName( aName ) )
259 mpImpl->mxShows->replaceByName( aName, aAny );
261 else
263 mpImpl->mxShows->insertByName( aName, aAny );
269 return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */