Update ooo320-m1
[ooovba.git] / xmloff / source / draw / ximpshow.cxx
blob3bea281dcf0514147a2e974a94ad8ad10095e6eb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ximpshow.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include <tools/debug.hxx>
35 #include <com/sun/star/util/DateTime.hpp>
36 #include <com/sun/star/xml/sax/XAttributeList.hpp>
37 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 #include <com/sun/star/container/XNameContainer.hpp>
39 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
40 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
41 #include <com/sun/star/container/XIndexContainer.hpp>
42 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
43 #include <xmloff/xmltoken.hxx>
44 #include <comphelper/extract.hxx>
45 #include "xmlnmspe.hxx"
46 #include <xmloff/nmspmap.hxx>
47 #include <xmloff/xmluconv.hxx>
48 #include "ximpshow.hxx"
50 using ::rtl::OUString;
51 using ::rtl::OUStringBuffer;
53 using namespace ::std;
54 using namespace ::cppu;
55 using namespace ::com::sun::star;
56 using namespace ::com::sun::star::xml;
57 using namespace ::com::sun::star::xml::sax;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::drawing;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::util;
63 using namespace ::com::sun::star::container;
64 using namespace ::com::sun::star::presentation;
65 using namespace ::xmloff::token;
67 ///////////////////////////////////////////////////////////////////////
69 class ShowsImpImpl
71 public:
72 Reference< XSingleServiceFactory > mxShowFactory;
73 Reference< XNameContainer > mxShows;
74 Reference< XPropertySet > mxPresProps;
75 Reference< XNameAccess > mxPages;
76 OUString maCustomShowName;
77 SdXMLImport& mrImport;
79 ShowsImpImpl( SdXMLImport& rImport )
80 : mrImport( rImport )
84 ///////////////////////////////////////////////////////////////////////
86 TYPEINIT1( SdXMLShowsContext, SvXMLImportContext );
88 SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
89 : SvXMLImportContext(rImport, nPrfx, rLocalName)
91 mpImpl = new ShowsImpImpl( rImport );
93 Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY );
94 if( xShowsSupplier.is() )
96 mpImpl->mxShows = xShowsSupplier->getCustomPresentations();
97 mpImpl->mxShowFactory = Reference< XSingleServiceFactory >::query( mpImpl->mxShows );
100 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY );
101 if( xDrawPagesSupplier.is() )
102 mpImpl->mxPages = Reference< XNameAccess >::query( xDrawPagesSupplier->getDrawPages() );
104 Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY );
105 if( xPresentationSupplier.is() )
106 mpImpl->mxPresProps = Reference< XPropertySet >::query( xPresentationSupplier->getPresentation() );
109 if( mpImpl->mxPresProps.is() )
111 sal_Bool bAll = sal_True;
112 uno::Any aAny;
114 // read attributes
115 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
116 for(sal_Int16 i=0; i < nAttrCount; i++)
118 OUString sAttrName = xAttrList->getNameByIndex( i );
119 OUString aLocalName;
120 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
121 OUString sValue = xAttrList->getValueByIndex( i );
123 switch( nPrefix )
125 case XML_NAMESPACE_PRESENTATION:
126 if( IsXMLToken( aLocalName, XML_START_PAGE ) )
128 aAny <<= sValue;
129 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FirstPage" ) ), aAny );
130 bAll = sal_False;
132 else if( IsXMLToken( aLocalName, XML_SHOW ) )
134 mpImpl->maCustomShowName = sValue;
135 bAll = sal_False;
137 else if( IsXMLToken( aLocalName, XML_PAUSE ) )
139 DateTime aTime;
140 if( !SvXMLUnitConverter::convertTime( aTime, sValue ) )
141 continue;
143 const sal_Int32 nMS = ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds;
144 aAny <<= nMS;
145 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Pause" ) ), aAny );
147 else if( IsXMLToken( aLocalName, XML_ANIMATIONS ) )
149 aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
150 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowAnimations" ) ), aAny );
152 else if( IsXMLToken( aLocalName, XML_STAY_ON_TOP ) )
154 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
155 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAlwaysOnTop" ) ), aAny );
157 else if( IsXMLToken( aLocalName, XML_FORCE_MANUAL ) )
159 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
160 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) ), aAny );
162 else if( IsXMLToken( aLocalName, XML_ENDLESS ) )
164 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
165 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsEndless" ) ), aAny );
167 else if( IsXMLToken( aLocalName, XML_FULL_SCREEN ) )
169 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
170 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFullScreen" ) ), aAny );
172 else if( IsXMLToken( aLocalName, XML_MOUSE_VISIBLE ) )
174 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
175 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsMouseVisible" ) ), aAny );
177 else if( IsXMLToken( aLocalName, XML_START_WITH_NAVIGATOR ) )
179 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
180 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "StartWithNavigator" ) ), aAny );
182 else if( IsXMLToken( aLocalName, XML_MOUSE_AS_PEN ) )
184 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
185 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "UsePen" ) ), aAny );
187 else if( IsXMLToken( aLocalName, XML_TRANSITION_ON_CLICK ) )
189 aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
190 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTransitionOnClick" ) ), aAny );
192 else if( IsXMLToken( aLocalName, XML_SHOW_LOGO ) )
194 aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
195 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsShowLogo" ) ), aAny );
199 aAny = bool2any( bAll );
200 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsShowAll" ) ), aAny );
204 SdXMLShowsContext::~SdXMLShowsContext()
206 if( mpImpl && mpImpl->maCustomShowName.getLength() )
208 uno::Any aAny;
209 aAny <<= mpImpl->maCustomShowName;
210 mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "CustomShow" ) ), aAny );
213 delete mpImpl;
216 SvXMLImportContext * SdXMLShowsContext::CreateChildContext( USHORT p_nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList )
218 if( mpImpl && p_nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SHOW ) )
220 OUString aName;
221 OUString aPages;
223 // read attributes
224 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
225 for(sal_Int16 i=0; i < nAttrCount; i++)
227 OUString sAttrName = xAttrList->getNameByIndex( i );
228 OUString aLocalName;
229 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
230 OUString sValue = xAttrList->getValueByIndex( i );
232 switch( nPrefix )
234 case XML_NAMESPACE_PRESENTATION:
235 if( IsXMLToken( aLocalName, XML_NAME ) )
237 aName = sValue;
239 else if( IsXMLToken( aLocalName, XML_PAGES ) )
241 aPages = sValue;
246 if( aName.getLength() != 0 && aPages.getLength() != 0 )
248 Reference< XIndexContainer > xShow( mpImpl->mxShowFactory->createInstance(), UNO_QUERY );
249 if( xShow.is() )
251 SvXMLTokenEnumerator aPageNames( aPages, sal_Unicode(',') );
252 OUString sPageName;
253 Any aAny;
255 while( aPageNames.getNextToken( sPageName ) )
257 if( !mpImpl->mxPages->hasByName( sPageName ) )
258 continue;
260 Reference< XDrawPage > xPage;
261 mpImpl->mxPages->getByName( sPageName ) >>= xPage;
262 if( xPage.is() )
264 aAny <<= xPage;
265 xShow->insertByIndex( xShow->getCount(), aAny );
269 aAny <<= xShow;
271 if( mpImpl->mxShows->hasByName( aName ) )
273 mpImpl->mxShows->replaceByName( aName, aAny );
275 else
277 mpImpl->mxShows->insertByName( aName, aAny );
283 return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );