/src/libreoffice/xmloff/source/draw/ximpshow.cxx
Line | Count | Source |
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/frame/XModel.hpp> |
21 | | #include <com/sun/star/util/Duration.hpp> |
22 | | #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp> |
23 | | #include <com/sun/star/presentation/XPresentationSupplier.hpp> |
24 | | #include <com/sun/star/container/XIndexContainer.hpp> |
25 | | #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> |
26 | | #include <sax/tools/converter.hxx> |
27 | | #include <xmloff/xmltoken.hxx> |
28 | | #include <xmloff/xmlnamespace.hxx> |
29 | | #include <xmloff/xmluconv.hxx> |
30 | | #include "ximpshow.hxx" |
31 | | |
32 | | using namespace ::com::sun::star; |
33 | | using namespace ::com::sun::star::xml; |
34 | | using namespace ::com::sun::star::xml::sax; |
35 | | using namespace ::com::sun::star::uno; |
36 | | using namespace ::com::sun::star::drawing; |
37 | | using namespace ::com::sun::star::beans; |
38 | | using namespace ::com::sun::star::lang; |
39 | | using namespace ::com::sun::star::util; |
40 | | using namespace ::com::sun::star::container; |
41 | | using namespace ::com::sun::star::presentation; |
42 | | using namespace ::xmloff::token; |
43 | | |
44 | | SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, const Reference< XFastAttributeList >& xAttrList ) |
45 | 2 | : SvXMLImportContext(rImport) |
46 | 2 | { |
47 | | |
48 | 2 | Reference< XCustomPresentationSupplier > xShowsSupplier( rImport.GetModel(), UNO_QUERY ); |
49 | 2 | if( xShowsSupplier.is() ) |
50 | 2 | { |
51 | 2 | mxShows = xShowsSupplier->getCustomPresentations(); |
52 | 2 | mxShowFactory.set( mxShows, UNO_QUERY ); |
53 | 2 | } |
54 | | |
55 | 2 | Reference< XDrawPagesSupplier > xDrawPagesSupplier( rImport.GetModel(), UNO_QUERY ); |
56 | 2 | if( xDrawPagesSupplier.is() ) |
57 | 2 | mxPages.set( xDrawPagesSupplier->getDrawPages(), UNO_QUERY ); |
58 | | |
59 | 2 | Reference< XPresentationSupplier > xPresentationSupplier( rImport.GetModel(), UNO_QUERY ); |
60 | 2 | if( xPresentationSupplier.is() ) |
61 | 2 | mxPresProps.set( xPresentationSupplier->getPresentation(), UNO_QUERY ); |
62 | | |
63 | 2 | if( !mxPresProps.is() ) |
64 | 0 | return; |
65 | | |
66 | 2 | bool bAll = true; |
67 | 2 | uno::Any aAny; |
68 | | // Per ODF this is default, but we did it wrong before LO 6.0 (tdf#108824) |
69 | 2 | bool bIsMouseVisible = true; |
70 | 2 | if (rImport.getGeneratorVersion() < SvXMLImport::LO_6x) |
71 | 2 | bIsMouseVisible = false; |
72 | | |
73 | | // read attributes |
74 | 2 | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
75 | 2 | { |
76 | 2 | switch( aIter.getToken() ) |
77 | 2 | { |
78 | 0 | case XML_ELEMENT(PRESENTATION, XML_START_PAGE): |
79 | 0 | { |
80 | 0 | mxPresProps->setPropertyValue(u"FirstPage"_ustr, Any(aIter.toString()) ); |
81 | 0 | bAll = false; |
82 | 0 | break; |
83 | 0 | } |
84 | 0 | case XML_ELEMENT(PRESENTATION, XML_SHOW): |
85 | 0 | { |
86 | 0 | maCustomShowName = aIter.toString(); |
87 | 0 | bAll = false; |
88 | 0 | break; |
89 | 0 | } |
90 | 0 | case XML_ELEMENT(PRESENTATION, XML_PAUSE): |
91 | 0 | { |
92 | 0 | Duration aDuration; |
93 | 0 | if (!::sax::Converter::convertDuration(aDuration, aIter.toView())) |
94 | 0 | continue; |
95 | | |
96 | 0 | const sal_Int32 nMS = (aDuration.Hours * 60 + |
97 | 0 | aDuration.Minutes) * 60 + aDuration.Seconds; |
98 | 0 | mxPresProps->setPropertyValue(u"Pause"_ustr, Any(nMS) ); |
99 | 0 | break; |
100 | 0 | } |
101 | 0 | case XML_ELEMENT(PRESENTATION, XML_ANIMATIONS): |
102 | 0 | { |
103 | 0 | aAny <<= IsXMLToken( aIter, XML_ENABLED ); |
104 | 0 | mxPresProps->setPropertyValue(u"AllowAnimations"_ustr, aAny ); |
105 | 0 | break; |
106 | 0 | } |
107 | 0 | case XML_ELEMENT(PRESENTATION, XML_STAY_ON_TOP): |
108 | 0 | { |
109 | 0 | aAny <<= IsXMLToken( aIter, XML_TRUE ); |
110 | 0 | mxPresProps->setPropertyValue(u"IsAlwaysOnTop"_ustr, aAny ); |
111 | 0 | break; |
112 | 0 | } |
113 | 0 | case XML_ELEMENT(PRESENTATION, XML_FORCE_MANUAL): |
114 | 0 | { |
115 | 0 | aAny <<= IsXMLToken( aIter, XML_TRUE ); |
116 | 0 | mxPresProps->setPropertyValue(u"IsAutomatic"_ustr, aAny ); |
117 | 0 | break; |
118 | 0 | } |
119 | 0 | case XML_ELEMENT(PRESENTATION, XML_ENDLESS): |
120 | 0 | { |
121 | 0 | aAny <<= IsXMLToken( aIter, XML_TRUE ); |
122 | 0 | mxPresProps->setPropertyValue(u"IsEndless"_ustr, aAny ); |
123 | 0 | break; |
124 | 0 | } |
125 | 0 | case XML_ELEMENT(PRESENTATION, XML_FULL_SCREEN): |
126 | 0 | { |
127 | 0 | aAny <<= IsXMLToken( aIter, XML_TRUE ); |
128 | 0 | mxPresProps->setPropertyValue(u"IsFullScreen"_ustr, aAny ); |
129 | 0 | break; |
130 | 0 | } |
131 | 2 | case XML_ELEMENT(PRESENTATION, XML_MOUSE_VISIBLE): |
132 | 2 | { |
133 | 2 | bIsMouseVisible = IsXMLToken( aIter, XML_TRUE ); |
134 | 2 | break; |
135 | 0 | } |
136 | 0 | case XML_ELEMENT(PRESENTATION, XML_START_WITH_NAVIGATOR): |
137 | 0 | { |
138 | 0 | aAny <<= IsXMLToken( aIter, XML_TRUE ); |
139 | 0 | mxPresProps->setPropertyValue(u"StartWithNavigator"_ustr, aAny ); |
140 | 0 | break; |
141 | 0 | } |
142 | 0 | case XML_ELEMENT(PRESENTATION, XML_MOUSE_AS_PEN): |
143 | 0 | { |
144 | 0 | aAny <<= IsXMLToken( aIter, XML_TRUE ); |
145 | 0 | mxPresProps->setPropertyValue(u"UsePen"_ustr, aAny ); |
146 | 0 | break; |
147 | 0 | } |
148 | 0 | case XML_ELEMENT(PRESENTATION, XML_TRANSITION_ON_CLICK): |
149 | 0 | { |
150 | 0 | aAny <<= IsXMLToken( aIter, XML_ENABLED ); |
151 | 0 | mxPresProps->setPropertyValue(u"IsTransitionOnClick"_ustr, aAny ); |
152 | 0 | break; |
153 | 0 | } |
154 | 0 | case XML_ELEMENT(PRESENTATION, XML_SHOW_LOGO): |
155 | 0 | { |
156 | 0 | aAny <<= IsXMLToken( aIter, XML_TRUE ); |
157 | 0 | mxPresProps->setPropertyValue(u"IsShowLogo"_ustr, aAny ); |
158 | 0 | break; |
159 | 0 | } |
160 | 2 | } |
161 | 2 | } |
162 | 2 | mxPresProps->setPropertyValue(u"IsShowAll"_ustr, Any(bAll) ); |
163 | 2 | mxPresProps->setPropertyValue(u"IsMouseVisible"_ustr, Any(bIsMouseVisible) ); |
164 | 2 | } |
165 | | |
166 | | SdXMLShowsContext::~SdXMLShowsContext() |
167 | 2 | { |
168 | 2 | if( !maCustomShowName.isEmpty() ) |
169 | 0 | { |
170 | 0 | uno::Any aAny; |
171 | 0 | aAny <<= maCustomShowName; |
172 | 0 | mxPresProps->setPropertyValue(u"CustomShow"_ustr, aAny ); |
173 | 0 | } |
174 | 2 | } |
175 | | |
176 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLShowsContext::createFastChildContext( |
177 | | sal_Int32 nElement, |
178 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
179 | 0 | { |
180 | 0 | if( nElement == XML_ELEMENT(PRESENTATION, XML_SHOW) ) |
181 | 0 | { |
182 | 0 | OUString aName; |
183 | 0 | OUString aPages; |
184 | | |
185 | | // read attributes |
186 | 0 | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
187 | 0 | { |
188 | 0 | OUString sValue = aIter.toString(); |
189 | |
|
190 | 0 | switch( aIter.getToken() ) |
191 | 0 | { |
192 | 0 | case XML_ELEMENT(PRESENTATION, XML_NAME): |
193 | 0 | aName = sValue; |
194 | 0 | break; |
195 | 0 | case XML_ELEMENT(PRESENTATION, XML_PAGES): |
196 | 0 | aPages = sValue; |
197 | 0 | break; |
198 | 0 | } |
199 | 0 | } |
200 | | |
201 | 0 | if( !aName.isEmpty() && !aPages.isEmpty() ) |
202 | 0 | { |
203 | 0 | Reference< XIndexContainer > xShow( mxShowFactory->createInstance(), UNO_QUERY ); |
204 | 0 | if( xShow.is() ) |
205 | 0 | { |
206 | 0 | SvXMLTokenEnumerator aPageNames( aPages, ',' ); |
207 | 0 | std::u16string_view sPageNameView; |
208 | |
|
209 | 0 | while( aPageNames.getNextToken( sPageNameView ) ) |
210 | 0 | { |
211 | 0 | OUString sPageName(sPageNameView); |
212 | 0 | if( !mxPages->hasByName( sPageName ) ) |
213 | 0 | continue; |
214 | | |
215 | 0 | Reference< XDrawPage > xPage; |
216 | 0 | mxPages->getByName( sPageName ) >>= xPage; |
217 | 0 | if( xPage.is() ) |
218 | 0 | { |
219 | 0 | xShow->insertByIndex( xShow->getCount(), Any(xPage) ); |
220 | 0 | } |
221 | 0 | } |
222 | |
|
223 | 0 | Any aAny; |
224 | 0 | aAny <<= xShow; |
225 | 0 | if( mxShows->hasByName( aName ) ) |
226 | 0 | { |
227 | 0 | mxShows->replaceByName( aName, aAny ); |
228 | 0 | } |
229 | 0 | else |
230 | 0 | { |
231 | 0 | mxShows->insertByName( aName, aAny ); |
232 | 0 | } |
233 | 0 | } |
234 | 0 | } |
235 | 0 | } |
236 | | |
237 | 0 | return nullptr; |
238 | 0 | } |
239 | | |
240 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |