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