Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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"
36 :
37 : using ::rtl::OUString;
38 : using ::rtl::OUStringBuffer;
39 :
40 : using namespace ::std;
41 : using namespace ::cppu;
42 : using namespace ::com::sun::star;
43 : using namespace ::com::sun::star::xml;
44 : using namespace ::com::sun::star::xml::sax;
45 : using namespace ::com::sun::star::uno;
46 : using namespace ::com::sun::star::drawing;
47 : using namespace ::com::sun::star::beans;
48 : using namespace ::com::sun::star::lang;
49 : using namespace ::com::sun::star::util;
50 : using namespace ::com::sun::star::container;
51 : using namespace ::com::sun::star::presentation;
52 : using namespace ::xmloff::token;
53 :
54 : ///////////////////////////////////////////////////////////////////////
55 :
56 1 : class ShowsImpImpl
57 : {
58 : public:
59 : Reference< XSingleServiceFactory > mxShowFactory;
60 : Reference< XNameContainer > mxShows;
61 : Reference< XPropertySet > mxPresProps;
62 : Reference< XNameAccess > mxPages;
63 : OUString maCustomShowName;
64 : SdXMLImport& mrImport;
65 :
66 1 : ShowsImpImpl( SdXMLImport& rImport )
67 1 : : mrImport( rImport )
68 1 : {}
69 : };
70 :
71 : ///////////////////////////////////////////////////////////////////////
72 :
73 0 : TYPEINIT1( SdXMLShowsContext, SvXMLImportContext );
74 :
75 1 : SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
76 1 : : SvXMLImportContext(rImport, nPrfx, rLocalName)
77 : {
78 1 : mpImpl = new ShowsImpImpl( rImport );
79 :
80 1 : Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY );
81 1 : if( xShowsSupplier.is() )
82 : {
83 1 : mpImpl->mxShows = xShowsSupplier->getCustomPresentations();
84 1 : mpImpl->mxShowFactory = Reference< XSingleServiceFactory >::query( mpImpl->mxShows );
85 : }
86 :
87 1 : Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY );
88 1 : if( xDrawPagesSupplier.is() )
89 1 : mpImpl->mxPages = Reference< XNameAccess >::query( xDrawPagesSupplier->getDrawPages() );
90 :
91 1 : Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY );
92 1 : if( xPresentationSupplier.is() )
93 1 : mpImpl->mxPresProps = Reference< XPropertySet >::query( xPresentationSupplier->getPresentation() );
94 :
95 :
96 1 : if( mpImpl->mxPresProps.is() )
97 : {
98 1 : sal_Bool bAll = sal_True;
99 1 : uno::Any aAny;
100 :
101 : // read attributes
102 1 : const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
103 2 : for(sal_Int16 i=0; i < nAttrCount; i++)
104 : {
105 1 : OUString sAttrName = xAttrList->getNameByIndex( i );
106 1 : OUString aLocalName;
107 1 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
108 1 : OUString sValue = xAttrList->getValueByIndex( i );
109 :
110 1 : switch( nPrefix )
111 : {
112 : case XML_NAMESPACE_PRESENTATION:
113 1 : if( IsXMLToken( aLocalName, XML_START_PAGE ) )
114 : {
115 0 : aAny <<= sValue;
116 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FirstPage" ) ), aAny );
117 0 : bAll = sal_False;
118 : }
119 1 : else if( IsXMLToken( aLocalName, XML_SHOW ) )
120 : {
121 0 : mpImpl->maCustomShowName = sValue;
122 0 : bAll = sal_False;
123 : }
124 1 : else if( IsXMLToken( aLocalName, XML_PAUSE ) )
125 : {
126 0 : Duration aDuration;
127 0 : if (!::sax::Converter::convertDuration(aDuration, sValue))
128 0 : continue;
129 :
130 : const sal_Int32 nMS = (aDuration.Hours * 60 +
131 0 : aDuration.Minutes) * 60 + aDuration.Seconds;
132 0 : aAny <<= nMS;
133 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Pause" ) ), aAny );
134 : }
135 1 : else if( IsXMLToken( aLocalName, XML_ANIMATIONS ) )
136 : {
137 0 : aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
138 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowAnimations" ) ), aAny );
139 : }
140 1 : else if( IsXMLToken( aLocalName, XML_STAY_ON_TOP ) )
141 : {
142 0 : aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
143 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAlwaysOnTop" ) ), aAny );
144 : }
145 1 : else if( IsXMLToken( aLocalName, XML_FORCE_MANUAL ) )
146 : {
147 0 : aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
148 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAutomatic" ) ), aAny );
149 : }
150 1 : else if( IsXMLToken( aLocalName, XML_ENDLESS ) )
151 : {
152 0 : aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
153 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsEndless" ) ), aAny );
154 : }
155 1 : else if( IsXMLToken( aLocalName, XML_FULL_SCREEN ) )
156 : {
157 0 : aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
158 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFullScreen" ) ), aAny );
159 : }
160 1 : else if( IsXMLToken( aLocalName, XML_MOUSE_VISIBLE ) )
161 : {
162 1 : aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
163 1 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsMouseVisible" ) ), aAny );
164 : }
165 0 : else if( IsXMLToken( aLocalName, XML_START_WITH_NAVIGATOR ) )
166 : {
167 0 : aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
168 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "StartWithNavigator" ) ), aAny );
169 : }
170 0 : else if( IsXMLToken( aLocalName, XML_MOUSE_AS_PEN ) )
171 : {
172 0 : aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
173 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "UsePen" ) ), aAny );
174 : }
175 0 : else if( IsXMLToken( aLocalName, XML_TRANSITION_ON_CLICK ) )
176 : {
177 0 : aAny = bool2any( IsXMLToken( sValue, XML_ENABLED ) );
178 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTransitionOnClick" ) ), aAny );
179 : }
180 0 : else if( IsXMLToken( aLocalName, XML_SHOW_LOGO ) )
181 : {
182 0 : aAny = bool2any( IsXMLToken( sValue, XML_TRUE ) );
183 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsShowLogo" ) ), aAny );
184 : }
185 : }
186 1 : }
187 1 : aAny = bool2any( bAll );
188 1 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsShowAll" ) ), aAny );
189 1 : }
190 1 : }
191 :
192 3 : SdXMLShowsContext::~SdXMLShowsContext()
193 : {
194 1 : if( mpImpl && !mpImpl->maCustomShowName.isEmpty() )
195 : {
196 0 : uno::Any aAny;
197 0 : aAny <<= mpImpl->maCustomShowName;
198 0 : mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "CustomShow" ) ), aAny );
199 : }
200 :
201 1 : delete mpImpl;
202 2 : }
203 :
204 0 : SvXMLImportContext * SdXMLShowsContext::CreateChildContext( sal_uInt16 p_nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList )
205 : {
206 0 : if( mpImpl && p_nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SHOW ) )
207 : {
208 0 : OUString aName;
209 0 : OUString aPages;
210 :
211 : // read attributes
212 0 : const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
213 0 : for(sal_Int16 i=0; i < nAttrCount; i++)
214 : {
215 0 : OUString sAttrName = xAttrList->getNameByIndex( i );
216 0 : OUString aLocalName;
217 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
218 0 : OUString sValue = xAttrList->getValueByIndex( i );
219 :
220 0 : switch( nPrefix )
221 : {
222 : case XML_NAMESPACE_PRESENTATION:
223 0 : if( IsXMLToken( aLocalName, XML_NAME ) )
224 : {
225 0 : aName = sValue;
226 : }
227 0 : else if( IsXMLToken( aLocalName, XML_PAGES ) )
228 : {
229 0 : aPages = sValue;
230 : }
231 : }
232 0 : }
233 :
234 0 : if( !aName.isEmpty() && !aPages.isEmpty() )
235 : {
236 0 : Reference< XIndexContainer > xShow( mpImpl->mxShowFactory->createInstance(), UNO_QUERY );
237 0 : if( xShow.is() )
238 : {
239 0 : SvXMLTokenEnumerator aPageNames( aPages, sal_Unicode(',') );
240 0 : OUString sPageName;
241 0 : Any aAny;
242 :
243 0 : while( aPageNames.getNextToken( sPageName ) )
244 : {
245 0 : if( !mpImpl->mxPages->hasByName( sPageName ) )
246 0 : continue;
247 :
248 0 : Reference< XDrawPage > xPage;
249 0 : mpImpl->mxPages->getByName( sPageName ) >>= xPage;
250 0 : if( xPage.is() )
251 : {
252 0 : aAny <<= xPage;
253 0 : xShow->insertByIndex( xShow->getCount(), aAny );
254 : }
255 0 : }
256 :
257 0 : aAny <<= xShow;
258 :
259 0 : if( mpImpl->mxShows->hasByName( aName ) )
260 : {
261 0 : mpImpl->mxShows->replaceByName( aName, aAny );
262 : }
263 : else
264 : {
265 0 : mpImpl->mxShows->insertByName( aName, aAny );
266 0 : }
267 0 : }
268 0 : }
269 : }
270 :
271 0 : return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
272 : }
273 :
274 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|