xref: /trunk/main/xmloff/source/draw/ximpshow.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/presentation/XPresentationSupplier.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
40*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
41*cdf0e10cSrcweir #include <comphelper/extract.hxx>
42*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
43*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
44*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
45*cdf0e10cSrcweir #include "ximpshow.hxx"
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir using ::rtl::OUString;
48*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir using namespace ::std;
51*cdf0e10cSrcweir using namespace ::cppu;
52*cdf0e10cSrcweir using namespace ::com::sun::star;
53*cdf0e10cSrcweir using namespace ::com::sun::star::xml;
54*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
55*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
56*cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
57*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
58*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
59*cdf0e10cSrcweir using namespace ::com::sun::star::util;
60*cdf0e10cSrcweir using namespace ::com::sun::star::container;
61*cdf0e10cSrcweir using namespace ::com::sun::star::presentation;
62*cdf0e10cSrcweir using namespace ::xmloff::token;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir class ShowsImpImpl
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir public:
69*cdf0e10cSrcweir 	Reference< XSingleServiceFactory > mxShowFactory;
70*cdf0e10cSrcweir 	Reference< XNameContainer > mxShows;
71*cdf0e10cSrcweir 	Reference< XPropertySet > mxPresProps;
72*cdf0e10cSrcweir 	Reference< XNameAccess > mxPages;
73*cdf0e10cSrcweir 	OUString maCustomShowName;
74*cdf0e10cSrcweir 	SdXMLImport& mrImport;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	ShowsImpImpl( SdXMLImport& rImport )
77*cdf0e10cSrcweir 	:	mrImport( rImport )
78*cdf0e10cSrcweir 	{}
79*cdf0e10cSrcweir };
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir TYPEINIT1( SdXMLShowsContext, SvXMLImportContext );
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport,  sal_uInt16 nPrfx, const OUString& rLocalName,  const Reference< XAttributeList >& xAttrList )
86*cdf0e10cSrcweir :	SvXMLImportContext(rImport, nPrfx, rLocalName)
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir 	mpImpl = new ShowsImpImpl( rImport );
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY );
91*cdf0e10cSrcweir 	if( xShowsSupplier.is() )
92*cdf0e10cSrcweir 	{
93*cdf0e10cSrcweir 		mpImpl->mxShows = xShowsSupplier->getCustomPresentations();
94*cdf0e10cSrcweir 		mpImpl->mxShowFactory = Reference< XSingleServiceFactory >::query( mpImpl->mxShows );
95*cdf0e10cSrcweir 	}
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY );
98*cdf0e10cSrcweir 	if( xDrawPagesSupplier.is() )
99*cdf0e10cSrcweir 		mpImpl->mxPages = Reference< XNameAccess >::query( xDrawPagesSupplier->getDrawPages() );
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY );
102*cdf0e10cSrcweir 	if( xPresentationSupplier.is() )
103*cdf0e10cSrcweir 		mpImpl->mxPresProps = Reference< XPropertySet >::query( xPresentationSupplier->getPresentation() );
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 	if( mpImpl->mxPresProps.is() )
107*cdf0e10cSrcweir 	{
108*cdf0e10cSrcweir 		sal_Bool bAll = sal_True;
109*cdf0e10cSrcweir 		uno::Any aAny;
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 		// read attributes
112*cdf0e10cSrcweir 		const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
113*cdf0e10cSrcweir 		for(sal_Int16 i=0; i < nAttrCount; i++)
114*cdf0e10cSrcweir 		{
115*cdf0e10cSrcweir 			OUString sAttrName = xAttrList->getNameByIndex( i );
116*cdf0e10cSrcweir 			OUString aLocalName;
117*cdf0e10cSrcweir 			sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
118*cdf0e10cSrcweir 			OUString sValue = xAttrList->getValueByIndex( i );
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 			switch( nPrefix )
121*cdf0e10cSrcweir 			{
122*cdf0e10cSrcweir 			case XML_NAMESPACE_PRESENTATION:
123*cdf0e10cSrcweir 				if( IsXMLToken( aLocalName, XML_START_PAGE ) )
124*cdf0e10cSrcweir 				{
125*cdf0e10cSrcweir 					aAny <<= sValue;
126*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FirstPage" ) ), aAny );
127*cdf0e10cSrcweir 					bAll = sal_False;
128*cdf0e10cSrcweir 				}
129*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_SHOW ) )
130*cdf0e10cSrcweir 				{
131*cdf0e10cSrcweir 					mpImpl->maCustomShowName = sValue;
132*cdf0e10cSrcweir 					bAll = sal_False;
133*cdf0e10cSrcweir 				}
134*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_PAUSE ) )
135*cdf0e10cSrcweir 				{
136*cdf0e10cSrcweir 					DateTime aTime;
137*cdf0e10cSrcweir 					if( !SvXMLUnitConverter::convertTime( aTime,  sValue ) )
138*cdf0e10cSrcweir 						continue;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 					const sal_Int32 nMS = ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds;
141*cdf0e10cSrcweir 					aAny <<= nMS;
142*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Pause" ) ), aAny );
143*cdf0e10cSrcweir 				}
144*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_ANIMATIONS ) )
145*cdf0e10cSrcweir 				{
146*cdf0e10cSrcweir 					aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
147*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowAnimations" ) ), aAny );
148*cdf0e10cSrcweir 				}
149*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_STAY_ON_TOP ) )
150*cdf0e10cSrcweir 				{
151*cdf0e10cSrcweir 					aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
152*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAlwaysOnTop" ) ), aAny );
153*cdf0e10cSrcweir 				}
154*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_FORCE_MANUAL ) )
155*cdf0e10cSrcweir 				{
156*cdf0e10cSrcweir 					aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
157*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) ), aAny );
158*cdf0e10cSrcweir 				}
159*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_ENDLESS ) )
160*cdf0e10cSrcweir 				{
161*cdf0e10cSrcweir 					aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
162*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsEndless" ) ), aAny );
163*cdf0e10cSrcweir 				}
164*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_FULL_SCREEN ) )
165*cdf0e10cSrcweir 				{
166*cdf0e10cSrcweir 					aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
167*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFullScreen" ) ), aAny );
168*cdf0e10cSrcweir 				}
169*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_MOUSE_VISIBLE ) )
170*cdf0e10cSrcweir 				{
171*cdf0e10cSrcweir 					aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
172*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsMouseVisible" ) ), aAny );
173*cdf0e10cSrcweir 				}
174*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_START_WITH_NAVIGATOR ) )
175*cdf0e10cSrcweir 				{
176*cdf0e10cSrcweir 					aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
177*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "StartWithNavigator" ) ), aAny );
178*cdf0e10cSrcweir 				}
179*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_MOUSE_AS_PEN ) )
180*cdf0e10cSrcweir 				{
181*cdf0e10cSrcweir 					aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
182*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "UsePen" ) ), aAny );
183*cdf0e10cSrcweir 				}
184*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_TRANSITION_ON_CLICK ) )
185*cdf0e10cSrcweir 				{
186*cdf0e10cSrcweir 					aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
187*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTransitionOnClick" ) ), aAny );
188*cdf0e10cSrcweir 				}
189*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_SHOW_LOGO ) )
190*cdf0e10cSrcweir 				{
191*cdf0e10cSrcweir 					aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
192*cdf0e10cSrcweir 					mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsShowLogo" ) ), aAny );
193*cdf0e10cSrcweir 				}
194*cdf0e10cSrcweir 			}
195*cdf0e10cSrcweir 		}
196*cdf0e10cSrcweir 		aAny = bool2any( bAll );
197*cdf0e10cSrcweir 		mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsShowAll" ) ), aAny );
198*cdf0e10cSrcweir 	}
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir SdXMLShowsContext::~SdXMLShowsContext()
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir 	if( mpImpl && mpImpl->maCustomShowName.getLength() )
204*cdf0e10cSrcweir 	{
205*cdf0e10cSrcweir 		uno::Any aAny;
206*cdf0e10cSrcweir 		aAny <<= mpImpl->maCustomShowName;
207*cdf0e10cSrcweir 		mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "CustomShow" ) ), aAny );
208*cdf0e10cSrcweir 	}
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 	delete mpImpl;
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir SvXMLImportContext * SdXMLShowsContext::CreateChildContext( sal_uInt16 p_nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList )
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir 	if( mpImpl && p_nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SHOW ) )
216*cdf0e10cSrcweir 	{
217*cdf0e10cSrcweir 		OUString aName;
218*cdf0e10cSrcweir 		OUString aPages;
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 		// read attributes
221*cdf0e10cSrcweir 		const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
222*cdf0e10cSrcweir 		for(sal_Int16 i=0; i < nAttrCount; i++)
223*cdf0e10cSrcweir 		{
224*cdf0e10cSrcweir 			OUString sAttrName = xAttrList->getNameByIndex( i );
225*cdf0e10cSrcweir 			OUString aLocalName;
226*cdf0e10cSrcweir 			sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
227*cdf0e10cSrcweir 			OUString sValue = xAttrList->getValueByIndex( i );
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 			switch( nPrefix )
230*cdf0e10cSrcweir 			{
231*cdf0e10cSrcweir 			case XML_NAMESPACE_PRESENTATION:
232*cdf0e10cSrcweir 				if( IsXMLToken( aLocalName, XML_NAME ) )
233*cdf0e10cSrcweir 				{
234*cdf0e10cSrcweir 					aName = sValue;
235*cdf0e10cSrcweir 				}
236*cdf0e10cSrcweir 				else if( IsXMLToken( aLocalName, XML_PAGES ) )
237*cdf0e10cSrcweir 				{
238*cdf0e10cSrcweir 					aPages = sValue;
239*cdf0e10cSrcweir 				}
240*cdf0e10cSrcweir 			}
241*cdf0e10cSrcweir 		}
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 		if( aName.getLength() != 0 && aPages.getLength() != 0 )
244*cdf0e10cSrcweir 		{
245*cdf0e10cSrcweir 			Reference< XIndexContainer > xShow( mpImpl->mxShowFactory->createInstance(), UNO_QUERY );
246*cdf0e10cSrcweir 			if( xShow.is() )
247*cdf0e10cSrcweir 			{
248*cdf0e10cSrcweir 				SvXMLTokenEnumerator aPageNames( aPages, sal_Unicode(',') );
249*cdf0e10cSrcweir 				OUString sPageName;
250*cdf0e10cSrcweir 				Any aAny;
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 				while( aPageNames.getNextToken( sPageName ) )
253*cdf0e10cSrcweir 				{
254*cdf0e10cSrcweir 					if( !mpImpl->mxPages->hasByName( sPageName ) )
255*cdf0e10cSrcweir 						continue;
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 					Reference< XDrawPage > xPage;
258*cdf0e10cSrcweir 					mpImpl->mxPages->getByName( sPageName ) >>= xPage;
259*cdf0e10cSrcweir 					if( xPage.is() )
260*cdf0e10cSrcweir 					{
261*cdf0e10cSrcweir 						aAny <<= xPage;
262*cdf0e10cSrcweir 						xShow->insertByIndex( xShow->getCount(), aAny );
263*cdf0e10cSrcweir 					}
264*cdf0e10cSrcweir 				}
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 				aAny <<= xShow;
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 				if( mpImpl->mxShows->hasByName( aName ) )
269*cdf0e10cSrcweir 				{
270*cdf0e10cSrcweir 					mpImpl->mxShows->replaceByName( aName, aAny );
271*cdf0e10cSrcweir 				}
272*cdf0e10cSrcweir 				else
273*cdf0e10cSrcweir 				{
274*cdf0e10cSrcweir 					mpImpl->mxShows->insertByName( aName, aAny );
275*cdf0e10cSrcweir 				}
276*cdf0e10cSrcweir 			}
277*cdf0e10cSrcweir 		}
278*cdf0e10cSrcweir 	}
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
281*cdf0e10cSrcweir }
282*cdf0e10cSrcweir 
283