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