1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
29cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
32cdf0e10cSrcweir #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
33cdf0e10cSrcweir #include <com/sun/star/presentation/XPresentationSupplier.hpp>
34cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
35cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
36cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
37cdf0e10cSrcweir #include <comphelper/extract.hxx>
38cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
39cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
40cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
41cdf0e10cSrcweir #include "ximpshow.hxx"
42cdf0e10cSrcweir
43cdf0e10cSrcweir using ::rtl::OUString;
44cdf0e10cSrcweir using ::rtl::OUStringBuffer;
45cdf0e10cSrcweir
46cdf0e10cSrcweir using namespace ::std;
47cdf0e10cSrcweir using namespace ::cppu;
48cdf0e10cSrcweir using namespace ::com::sun::star;
49cdf0e10cSrcweir using namespace ::com::sun::star::xml;
50cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
51cdf0e10cSrcweir using namespace ::com::sun::star::uno;
52cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
53cdf0e10cSrcweir using namespace ::com::sun::star::beans;
54cdf0e10cSrcweir using namespace ::com::sun::star::lang;
55cdf0e10cSrcweir using namespace ::com::sun::star::util;
56cdf0e10cSrcweir using namespace ::com::sun::star::container;
57cdf0e10cSrcweir using namespace ::com::sun::star::presentation;
58cdf0e10cSrcweir using namespace ::xmloff::token;
59cdf0e10cSrcweir
60cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
61cdf0e10cSrcweir
62cdf0e10cSrcweir class ShowsImpImpl
63cdf0e10cSrcweir {
64cdf0e10cSrcweir public:
65cdf0e10cSrcweir Reference< XSingleServiceFactory > mxShowFactory;
66cdf0e10cSrcweir Reference< XNameContainer > mxShows;
67cdf0e10cSrcweir Reference< XPropertySet > mxPresProps;
68cdf0e10cSrcweir Reference< XNameAccess > mxPages;
69cdf0e10cSrcweir OUString maCustomShowName;
70cdf0e10cSrcweir SdXMLImport& mrImport;
71cdf0e10cSrcweir
ShowsImpImpl(SdXMLImport & rImport)72cdf0e10cSrcweir ShowsImpImpl( SdXMLImport& rImport )
73cdf0e10cSrcweir : mrImport( rImport )
74cdf0e10cSrcweir {}
75cdf0e10cSrcweir };
76cdf0e10cSrcweir
77cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
78cdf0e10cSrcweir
79cdf0e10cSrcweir TYPEINIT1( SdXMLShowsContext, SvXMLImportContext );
80cdf0e10cSrcweir
SdXMLShowsContext(SdXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)81cdf0e10cSrcweir SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
82cdf0e10cSrcweir : SvXMLImportContext(rImport, nPrfx, rLocalName)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir mpImpl = new ShowsImpImpl( rImport );
85cdf0e10cSrcweir
86cdf0e10cSrcweir Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY );
87cdf0e10cSrcweir if( xShowsSupplier.is() )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir mpImpl->mxShows = xShowsSupplier->getCustomPresentations();
90cdf0e10cSrcweir mpImpl->mxShowFactory = Reference< XSingleServiceFactory >::query( mpImpl->mxShows );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
93cdf0e10cSrcweir Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY );
94cdf0e10cSrcweir if( xDrawPagesSupplier.is() )
95cdf0e10cSrcweir mpImpl->mxPages = Reference< XNameAccess >::query( xDrawPagesSupplier->getDrawPages() );
96cdf0e10cSrcweir
97cdf0e10cSrcweir Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY );
98cdf0e10cSrcweir if( xPresentationSupplier.is() )
99cdf0e10cSrcweir mpImpl->mxPresProps = Reference< XPropertySet >::query( xPresentationSupplier->getPresentation() );
100cdf0e10cSrcweir
101cdf0e10cSrcweir
102cdf0e10cSrcweir if( mpImpl->mxPresProps.is() )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir sal_Bool bAll = sal_True;
105cdf0e10cSrcweir uno::Any aAny;
106cdf0e10cSrcweir
107cdf0e10cSrcweir // read attributes
108cdf0e10cSrcweir const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
109cdf0e10cSrcweir for(sal_Int16 i=0; i < nAttrCount; i++)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir OUString sAttrName = xAttrList->getNameByIndex( i );
112cdf0e10cSrcweir OUString aLocalName;
113cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
114cdf0e10cSrcweir OUString sValue = xAttrList->getValueByIndex( i );
115cdf0e10cSrcweir
116cdf0e10cSrcweir switch( nPrefix )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir case XML_NAMESPACE_PRESENTATION:
119cdf0e10cSrcweir if( IsXMLToken( aLocalName, XML_START_PAGE ) )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir aAny <<= sValue;
122cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FirstPage" ) ), aAny );
123cdf0e10cSrcweir bAll = sal_False;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_SHOW ) )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir mpImpl->maCustomShowName = sValue;
128cdf0e10cSrcweir bAll = sal_False;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_PAUSE ) )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir DateTime aTime;
133cdf0e10cSrcweir if( !SvXMLUnitConverter::convertTime( aTime, sValue ) )
134cdf0e10cSrcweir continue;
135cdf0e10cSrcweir
136cdf0e10cSrcweir const sal_Int32 nMS = ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds;
137cdf0e10cSrcweir aAny <<= nMS;
138cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Pause" ) ), aAny );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_ANIMATIONS ) )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
143cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowAnimations" ) ), aAny );
144cdf0e10cSrcweir }
145cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_STAY_ON_TOP ) )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
148cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAlwaysOnTop" ) ), aAny );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_FORCE_MANUAL ) )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
153cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) ), aAny );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_ENDLESS ) )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
158cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsEndless" ) ), aAny );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_FULL_SCREEN ) )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
163cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFullScreen" ) ), aAny );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_MOUSE_VISIBLE ) )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
168cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsMouseVisible" ) ), aAny );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_START_WITH_NAVIGATOR ) )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
173cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "StartWithNavigator" ) ), aAny );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_MOUSE_AS_PEN ) )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
178cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "UsePen" ) ), aAny );
179cdf0e10cSrcweir }
180cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_TRANSITION_ON_CLICK ) )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
183cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTransitionOnClick" ) ), aAny );
184cdf0e10cSrcweir }
185cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_SHOW_LOGO ) )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
188cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsShowLogo" ) ), aAny );
189cdf0e10cSrcweir }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir }
192cdf0e10cSrcweir aAny = bool2any( bAll );
193cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsShowAll" ) ), aAny );
194cdf0e10cSrcweir }
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
~SdXMLShowsContext()197cdf0e10cSrcweir SdXMLShowsContext::~SdXMLShowsContext()
198cdf0e10cSrcweir {
199cdf0e10cSrcweir if( mpImpl && mpImpl->maCustomShowName.getLength() )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir uno::Any aAny;
202cdf0e10cSrcweir aAny <<= mpImpl->maCustomShowName;
203cdf0e10cSrcweir mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "CustomShow" ) ), aAny );
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
206cdf0e10cSrcweir delete mpImpl;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
CreateChildContext(sal_uInt16 p_nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)209cdf0e10cSrcweir SvXMLImportContext * SdXMLShowsContext::CreateChildContext( sal_uInt16 p_nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir if( mpImpl && p_nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SHOW ) )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir OUString aName;
214cdf0e10cSrcweir OUString aPages;
215cdf0e10cSrcweir
216cdf0e10cSrcweir // read attributes
217cdf0e10cSrcweir const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
218cdf0e10cSrcweir for(sal_Int16 i=0; i < nAttrCount; i++)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir OUString sAttrName = xAttrList->getNameByIndex( i );
221cdf0e10cSrcweir OUString aLocalName;
222cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
223cdf0e10cSrcweir OUString sValue = xAttrList->getValueByIndex( i );
224cdf0e10cSrcweir
225cdf0e10cSrcweir switch( nPrefix )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir case XML_NAMESPACE_PRESENTATION:
228cdf0e10cSrcweir if( IsXMLToken( aLocalName, XML_NAME ) )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir aName = sValue;
231cdf0e10cSrcweir }
232cdf0e10cSrcweir else if( IsXMLToken( aLocalName, XML_PAGES ) )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir aPages = sValue;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir }
237cdf0e10cSrcweir }
238cdf0e10cSrcweir
239cdf0e10cSrcweir if( aName.getLength() != 0 && aPages.getLength() != 0 )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir Reference< XIndexContainer > xShow( mpImpl->mxShowFactory->createInstance(), UNO_QUERY );
242cdf0e10cSrcweir if( xShow.is() )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir SvXMLTokenEnumerator aPageNames( aPages, sal_Unicode(',') );
245cdf0e10cSrcweir OUString sPageName;
246cdf0e10cSrcweir Any aAny;
247cdf0e10cSrcweir
248cdf0e10cSrcweir while( aPageNames.getNextToken( sPageName ) )
249cdf0e10cSrcweir {
250cdf0e10cSrcweir if( !mpImpl->mxPages->hasByName( sPageName ) )
251cdf0e10cSrcweir continue;
252cdf0e10cSrcweir
253cdf0e10cSrcweir Reference< XDrawPage > xPage;
254cdf0e10cSrcweir mpImpl->mxPages->getByName( sPageName ) >>= xPage;
255cdf0e10cSrcweir if( xPage.is() )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir aAny <<= xPage;
258cdf0e10cSrcweir xShow->insertByIndex( xShow->getCount(), aAny );
259cdf0e10cSrcweir }
260cdf0e10cSrcweir }
261cdf0e10cSrcweir
262cdf0e10cSrcweir aAny <<= xShow;
263cdf0e10cSrcweir
264cdf0e10cSrcweir if( mpImpl->mxShows->hasByName( aName ) )
265cdf0e10cSrcweir {
266cdf0e10cSrcweir mpImpl->mxShows->replaceByName( aName, aAny );
267cdf0e10cSrcweir }
268cdf0e10cSrcweir else
269cdf0e10cSrcweir {
270cdf0e10cSrcweir mpImpl->mxShows->insertByName( aName, aAny );
271cdf0e10cSrcweir }
272cdf0e10cSrcweir }
273cdf0e10cSrcweir }
274cdf0e10cSrcweir }
275cdf0e10cSrcweir
276cdf0e10cSrcweir return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
277cdf0e10cSrcweir }
278cdf0e10cSrcweir
279