1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/frame/XModel.hpp>
21 #include <com/sun/star/util/Duration.hpp>
22 #include <com/sun/star/xml/sax/XAttributeList.hpp>
23 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
24 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
25 #include <com/sun/star/container/XIndexContainer.hpp>
26 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
27 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmlnamespace.hxx>
30 #include <xmloff/namespacemap.hxx>
31 #include <xmloff/xmluconv.hxx>
32 #include "ximpshow.hxx"
34 using namespace ::cppu
;
35 using namespace ::com::sun::star
;
36 using namespace ::com::sun::star::xml
;
37 using namespace ::com::sun::star::xml::sax
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::drawing
;
40 using namespace ::com::sun::star::beans
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::util
;
43 using namespace ::com::sun::star::container
;
44 using namespace ::com::sun::star::presentation
;
45 using namespace ::xmloff::token
;
47 SdXMLShowsContext::SdXMLShowsContext( SdXMLImport
& rImport
, const Reference
< XFastAttributeList
>& xAttrList
)
48 : SvXMLImportContext(rImport
)
51 Reference
< XCustomPresentationSupplier
> xShowsSupplier( rImport
.GetModel(), UNO_QUERY
);
52 if( xShowsSupplier
.is() )
54 mxShows
= xShowsSupplier
->getCustomPresentations();
55 mxShowFactory
.set( mxShows
, UNO_QUERY
);
58 Reference
< XDrawPagesSupplier
> xDrawPagesSupplier( rImport
.GetModel(), UNO_QUERY
);
59 if( xDrawPagesSupplier
.is() )
60 mxPages
.set( xDrawPagesSupplier
->getDrawPages(), UNO_QUERY
);
62 Reference
< XPresentationSupplier
> xPresentationSupplier( rImport
.GetModel(), UNO_QUERY
);
63 if( xPresentationSupplier
.is() )
64 mxPresProps
.set( xPresentationSupplier
->getPresentation(), UNO_QUERY
);
66 if( !mxPresProps
.is() )
71 // Per ODF this is default, but we did it wrong before LO 6.0 (tdf#108824)
72 bool bIsMouseVisible
= true;
73 if (rImport
.getGeneratorVersion() < SvXMLImport::LO_6x
)
74 bIsMouseVisible
= false;
77 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
79 switch( aIter
.getToken() )
81 case XML_ELEMENT(PRESENTATION
, XML_START_PAGE
):
83 mxPresProps
->setPropertyValue("FirstPage", Any(aIter
.toString()) );
87 case XML_ELEMENT(PRESENTATION
, XML_SHOW
):
89 maCustomShowName
= aIter
.toString();
93 case XML_ELEMENT(PRESENTATION
, XML_PAUSE
):
96 if (!::sax::Converter::convertDuration(aDuration
, aIter
.toView()))
99 const sal_Int32 nMS
= (aDuration
.Hours
* 60 +
100 aDuration
.Minutes
) * 60 + aDuration
.Seconds
;
101 mxPresProps
->setPropertyValue("Pause", Any(nMS
) );
104 case XML_ELEMENT(PRESENTATION
, XML_ANIMATIONS
):
106 aAny
<<= IsXMLToken( aIter
, XML_ENABLED
);
107 mxPresProps
->setPropertyValue("AllowAnimations", aAny
);
110 case XML_ELEMENT(PRESENTATION
, XML_STAY_ON_TOP
):
112 aAny
<<= IsXMLToken( aIter
, XML_TRUE
);
113 mxPresProps
->setPropertyValue("IsAlwaysOnTop", aAny
);
116 case XML_ELEMENT(PRESENTATION
, XML_FORCE_MANUAL
):
118 aAny
<<= IsXMLToken( aIter
, XML_TRUE
);
119 mxPresProps
->setPropertyValue("IsAutomatic", aAny
);
122 case XML_ELEMENT(PRESENTATION
, XML_ENDLESS
):
124 aAny
<<= IsXMLToken( aIter
, XML_TRUE
);
125 mxPresProps
->setPropertyValue("IsEndless", aAny
);
128 case XML_ELEMENT(PRESENTATION
, XML_FULL_SCREEN
):
130 aAny
<<= IsXMLToken( aIter
, XML_TRUE
);
131 mxPresProps
->setPropertyValue("IsFullScreen", aAny
);
134 case XML_ELEMENT(PRESENTATION
, XML_MOUSE_VISIBLE
):
136 bIsMouseVisible
= IsXMLToken( aIter
, XML_TRUE
);
139 case XML_ELEMENT(PRESENTATION
, XML_START_WITH_NAVIGATOR
):
141 aAny
<<= IsXMLToken( aIter
, XML_TRUE
);
142 mxPresProps
->setPropertyValue("StartWithNavigator", aAny
);
145 case XML_ELEMENT(PRESENTATION
, XML_MOUSE_AS_PEN
):
147 aAny
<<= IsXMLToken( aIter
, XML_TRUE
);
148 mxPresProps
->setPropertyValue("UsePen", aAny
);
151 case XML_ELEMENT(PRESENTATION
, XML_TRANSITION_ON_CLICK
):
153 aAny
<<= IsXMLToken( aIter
, XML_ENABLED
);
154 mxPresProps
->setPropertyValue("IsTransitionOnClick", aAny
);
157 case XML_ELEMENT(PRESENTATION
, XML_SHOW_LOGO
):
159 aAny
<<= IsXMLToken( aIter
, XML_TRUE
);
160 mxPresProps
->setPropertyValue("IsShowLogo", aAny
);
165 mxPresProps
->setPropertyValue("IsShowAll", Any(bAll
) );
166 mxPresProps
->setPropertyValue("IsMouseVisible", Any(bIsMouseVisible
) );
169 SdXMLShowsContext::~SdXMLShowsContext()
171 if( !maCustomShowName
.isEmpty() )
174 aAny
<<= maCustomShowName
;
175 mxPresProps
->setPropertyValue("CustomShow", aAny
);
179 css::uno::Reference
< css::xml::sax::XFastContextHandler
> SdXMLShowsContext::createFastChildContext(
181 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
183 if( nElement
== XML_ELEMENT(PRESENTATION
, XML_SHOW
) )
189 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
191 OUString sValue
= aIter
.toString();
193 switch( aIter
.getToken() )
195 case XML_ELEMENT(PRESENTATION
, XML_NAME
):
198 case XML_ELEMENT(PRESENTATION
, XML_PAGES
):
204 if( !aName
.isEmpty() && !aPages
.isEmpty() )
206 Reference
< XIndexContainer
> xShow( mxShowFactory
->createInstance(), UNO_QUERY
);
209 SvXMLTokenEnumerator
aPageNames( aPages
, ',' );
210 std::u16string_view sPageNameView
;
212 while( aPageNames
.getNextToken( sPageNameView
) )
214 OUString
sPageName(sPageNameView
);
215 if( !mxPages
->hasByName( sPageName
) )
218 Reference
< XDrawPage
> xPage
;
219 mxPages
->getByName( sPageName
) >>= xPage
;
222 xShow
->insertByIndex( xShow
->getCount(), Any(xPage
) );
228 if( mxShows
->hasByName( aName
) )
230 mxShows
->replaceByName( aName
, aAny
);
234 mxShows
->insertByName( aName
, aAny
);
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */