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/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"
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
;
52 Reference
< XSingleServiceFactory
> mxShowFactory
;
53 Reference
< XNameContainer
> mxShows
;
54 Reference
< XPropertySet
> mxPresProps
;
55 Reference
< XNameAccess
> mxPages
;
56 OUString maCustomShowName
;
57 SdXMLImport
& mrImport
;
59 ShowsImpImpl( SdXMLImport
& rImport
)
64 TYPEINIT1( SdXMLShowsContext
, SvXMLImportContext
);
66 SdXMLShowsContext::SdXMLShowsContext( SdXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
)
67 : SvXMLImportContext(rImport
, nPrfx
, rLocalName
)
69 mpImpl
= new ShowsImpImpl( rImport
);
71 Reference
< XCustomPresentationSupplier
> xShowsSupplier( rImport
.GetModel(), UNO_QUERY
);
72 if( xShowsSupplier
.is() )
74 mpImpl
->mxShows
= xShowsSupplier
->getCustomPresentations();
75 mpImpl
->mxShowFactory
= Reference
< XSingleServiceFactory
>::query( mpImpl
->mxShows
);
78 Reference
< XDrawPagesSupplier
> xDrawPagesSupplier( rImport
.GetModel(), UNO_QUERY
);
79 if( xDrawPagesSupplier
.is() )
80 mpImpl
->mxPages
= Reference
< XNameAccess
>::query( xDrawPagesSupplier
->getDrawPages() );
82 Reference
< XPresentationSupplier
> xPresentationSupplier( rImport
.GetModel(), UNO_QUERY
);
83 if( xPresentationSupplier
.is() )
84 mpImpl
->mxPresProps
= Reference
< XPropertySet
>::query( xPresentationSupplier
->getPresentation() );
86 if( mpImpl
->mxPresProps
.is() )
92 const sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
93 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
95 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
97 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
98 OUString sValue
= xAttrList
->getValueByIndex( i
);
102 case XML_NAMESPACE_PRESENTATION
:
103 if( IsXMLToken( aLocalName
, XML_START_PAGE
) )
106 mpImpl
->mxPresProps
->setPropertyValue("FirstPage", aAny
);
109 else if( IsXMLToken( aLocalName
, XML_SHOW
) )
111 mpImpl
->maCustomShowName
= sValue
;
114 else if( IsXMLToken( aLocalName
, XML_PAUSE
) )
117 if (!::sax::Converter::convertDuration(aDuration
, sValue
))
120 const sal_Int32 nMS
= (aDuration
.Hours
* 60 +
121 aDuration
.Minutes
) * 60 + aDuration
.Seconds
;
123 mpImpl
->mxPresProps
->setPropertyValue("Pause", aAny
);
125 else if( IsXMLToken( aLocalName
, XML_ANIMATIONS
) )
127 aAny
<<= IsXMLToken( sValue
, XML_ENABLED
);
128 mpImpl
->mxPresProps
->setPropertyValue("AllowAnimations", aAny
);
130 else if( IsXMLToken( aLocalName
, XML_STAY_ON_TOP
) )
132 aAny
<<= IsXMLToken( sValue
, XML_TRUE
);
133 mpImpl
->mxPresProps
->setPropertyValue("IsAlwaysOnTop", aAny
);
135 else if( IsXMLToken( aLocalName
, XML_FORCE_MANUAL
) )
137 aAny
<<= IsXMLToken( sValue
, XML_TRUE
);
138 mpImpl
->mxPresProps
->setPropertyValue("IsAutomatic", aAny
);
140 else if( IsXMLToken( aLocalName
, XML_ENDLESS
) )
142 aAny
<<= IsXMLToken( sValue
, XML_TRUE
);
143 mpImpl
->mxPresProps
->setPropertyValue("IsEndless", aAny
);
145 else if( IsXMLToken( aLocalName
, XML_FULL_SCREEN
) )
147 aAny
<<= IsXMLToken( sValue
, XML_TRUE
);
148 mpImpl
->mxPresProps
->setPropertyValue("IsFullScreen", aAny
);
150 else if( IsXMLToken( aLocalName
, XML_MOUSE_VISIBLE
) )
152 aAny
<<= IsXMLToken( sValue
, XML_TRUE
);
153 mpImpl
->mxPresProps
->setPropertyValue("IsMouseVisible", aAny
);
155 else if( IsXMLToken( aLocalName
, XML_START_WITH_NAVIGATOR
) )
157 aAny
<<= IsXMLToken( sValue
, XML_TRUE
);
158 mpImpl
->mxPresProps
->setPropertyValue("StartWithNavigator", aAny
);
160 else if( IsXMLToken( aLocalName
, XML_MOUSE_AS_PEN
) )
162 aAny
<<= IsXMLToken( sValue
, XML_TRUE
);
163 mpImpl
->mxPresProps
->setPropertyValue("UsePen", aAny
);
165 else if( IsXMLToken( aLocalName
, XML_TRANSITION_ON_CLICK
) )
167 aAny
<<= IsXMLToken( sValue
, XML_ENABLED
);
168 mpImpl
->mxPresProps
->setPropertyValue("IsTransitionOnClick", aAny
);
170 else if( IsXMLToken( aLocalName
, XML_SHOW_LOGO
) )
172 aAny
<<= IsXMLToken( sValue
, XML_TRUE
);
173 mpImpl
->mxPresProps
->setPropertyValue("IsShowLogo", aAny
);
178 mpImpl
->mxPresProps
->setPropertyValue("IsShowAll", aAny
);
182 SdXMLShowsContext::~SdXMLShowsContext()
184 if( mpImpl
&& !mpImpl
->maCustomShowName
.isEmpty() )
187 aAny
<<= mpImpl
->maCustomShowName
;
188 mpImpl
->mxPresProps
->setPropertyValue("CustomShow", aAny
);
194 SvXMLImportContext
* SdXMLShowsContext::CreateChildContext( sal_uInt16 p_nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
)
196 if( mpImpl
&& p_nPrefix
== XML_NAMESPACE_PRESENTATION
&& IsXMLToken( rLocalName
, XML_SHOW
) )
202 const sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
203 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
205 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
207 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
208 OUString sValue
= xAttrList
->getValueByIndex( i
);
212 case XML_NAMESPACE_PRESENTATION
:
213 if( IsXMLToken( aLocalName
, XML_NAME
) )
217 else if( IsXMLToken( aLocalName
, XML_PAGES
) )
224 if( !aName
.isEmpty() && !aPages
.isEmpty() )
226 Reference
< XIndexContainer
> xShow( mpImpl
->mxShowFactory
->createInstance(), UNO_QUERY
);
229 SvXMLTokenEnumerator
aPageNames( aPages
, ',' );
233 while( aPageNames
.getNextToken( sPageName
) )
235 if( !mpImpl
->mxPages
->hasByName( sPageName
) )
238 Reference
< XDrawPage
> xPage
;
239 mpImpl
->mxPages
->getByName( sPageName
) >>= xPage
;
243 xShow
->insertByIndex( xShow
->getCount(), aAny
);
249 if( mpImpl
->mxShows
->hasByName( aName
) )
251 mpImpl
->mxShows
->replaceByName( aName
, aAny
);
255 mpImpl
->mxShows
->insertByName( aName
, aAny
);
261 return new SvXMLImportContext( GetImport(), p_nPrefix
, rLocalName
);
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */