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 "comphelper/anytostring.hxx"
21 : #include "cppuhelper/exc_hlp.hxx"
22 :
23 : #include <com/sun/star/beans/XMultiPropertySet.hpp>
24 : #include <com/sun/star/container/XNamed.hpp>
25 :
26 : #include "oox/helper/propertyset.hxx"
27 : #include "oox/core/xmlfilterbase.hxx"
28 : #include "headerfootercontext.hxx"
29 : #include "oox/ppt/backgroundproperties.hxx"
30 : #include "oox/ppt/slidefragmenthandler.hxx"
31 : #include "oox/ppt/slidetimingcontext.hxx"
32 : #include "oox/ppt/slidetransitioncontext.hxx"
33 : #include "oox/ppt/slidemastertextstylescontext.hxx"
34 : #include "oox/ppt/pptshapegroupcontext.hxx"
35 : #include "oox/ppt/pptshape.hxx"
36 : #include "oox/vml/vmldrawing.hxx"
37 : #include "oox/vml/vmldrawingfragment.hxx"
38 : #include "oox/drawingml/clrschemecontext.hxx"
39 : #include "oox/ppt/pptimport.hxx"
40 :
41 :
42 : using rtl::OUString;
43 : using namespace ::com::sun::star;
44 : using namespace ::oox::core;
45 : using namespace ::oox::drawingml;
46 : using namespace ::com::sun::star::uno;
47 : using namespace ::com::sun::star::drawing;
48 : using namespace ::com::sun::star::xml::sax;
49 : using namespace ::com::sun::star::container;
50 :
51 : namespace oox { namespace ppt {
52 :
53 14 : SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, SlidePersistPtr pPersistPtr, const ShapeLocation eShapeLocation ) throw()
54 : : FragmentHandler2( rFilter, rFragmentPath )
55 : , mpSlidePersistPtr( pPersistPtr )
56 14 : , meShapeLocation( eShapeLocation )
57 : {
58 14 : OUString aVMLDrawingFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "vmlDrawing" ) );
59 14 : if( !aVMLDrawingFragmentPath.isEmpty() )
60 0 : getFilter().importFragment( new oox::vml::DrawingFragment(
61 0 : getFilter(), aVMLDrawingFragmentPath, *pPersistPtr->getDrawing() ) );
62 14 : }
63 :
64 38 : SlideFragmentHandler::~SlideFragmentHandler() throw()
65 : {
66 : // convert and insert all VML shapes (mostly form controls)
67 14 : mpSlidePersistPtr->getDrawing()->convertAndInsert();
68 24 : }
69 :
70 187 : ::oox::core::ContextHandlerRef SlideFragmentHandler::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
71 : {
72 187 : switch( aElementToken )
73 : {
74 : case PPT_TOKEN( sldMaster ): // CT_SlideMaster
75 : case PPT_TOKEN( handoutMaster ): // CT_HandoutMaster
76 : case PPT_TOKEN( sld ): // CT_CommonSlideData
77 : {
78 8 : Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
79 8 : PropertyMap aPropMap;
80 8 : PropertySet aSlideProp( xSlide );
81 :
82 8 : aPropMap[ PROP_Visible ] = Any( rAttribs.getBool( XML_show, sal_True ) );
83 8 : aSlideProp.setProperties( aPropMap );
84 :
85 8 : return this;
86 : }
87 : case PPT_TOKEN( notes ): // CT_NotesSlide
88 : {
89 : // Import notesMaster
90 1 : PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
91 2 : OUString aNotesFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "notesMaster" ) );
92 :
93 1 : std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
94 1 : std::vector< SlidePersistPtr >::iterator aIter( rMasterPages.begin() );
95 3 : while( aIter != rMasterPages.end() )
96 : {
97 1 : if( (*aIter)->getPath() == aNotesFragmentPath )
98 : {
99 0 : if( !mpSlidePersistPtr->getMasterPersist() )
100 0 : mpSlidePersistPtr->setMasterPersist( *aIter );
101 0 : break;
102 : }
103 1 : ++aIter;
104 : }
105 1 : if( aIter == rMasterPages.end() && !mpSlidePersistPtr->getMasterPersist() )
106 : {
107 1 : TextListStylePtr pTextListStyle(new TextListStyle);
108 : SlidePersistPtr pMasterPersistPtr = SlidePersistPtr( new SlidePersist( rFilter, sal_True, sal_True, mpSlidePersistPtr->getPage(),
109 1 : ShapePtr( new PPTShape( Master, "com.sun.star.drawing.GroupShape" ) ), mpSlidePersistPtr->getNotesTextStyle() ) );
110 : //pMasterPersistPtr->setLayoutPath( aLayoutFragmentPath );
111 1 : pMasterPersistPtr->setPath( aNotesFragmentPath );
112 1 : rFilter.getMasterPages().push_back( pMasterPersistPtr );
113 1 : FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aNotesFragmentPath, pMasterPersistPtr, Master ) );
114 1 : rFilter.importFragment( xMasterFragmentHandler );
115 : //pMasterPersistPtr->createBackground( rFilter );
116 : //pMasterPersistPtr->createXShapes( rFilter );
117 1 : mpSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
118 : }
119 1 : return this;
120 : }
121 : case PPT_TOKEN( notesMaster ): // CT_NotesMaster
122 1 : return this;
123 : case PPT_TOKEN( cSld ): // CT_CommonSlideData
124 14 : maSlideName = rAttribs.getString(XML_name, OUString());
125 14 : return this;
126 :
127 : case PPT_TOKEN( spTree ): // CT_GroupShape
128 : {
129 : // TODO Convert this to FragmentHandler2
130 : return new PPTShapeGroupContext(
131 : *this, mpSlidePersistPtr, meShapeLocation, mpSlidePersistPtr->getShapes(),
132 14 : oox::drawingml::ShapePtr( new PPTShape( meShapeLocation, "com.sun.star.drawing.GroupShape" ) ) );
133 : }
134 : break;
135 :
136 : case PPT_TOKEN( controls ):
137 0 : return this;
138 : case PPT_TOKEN( control ):
139 : {
140 0 : ::oox::vml::ControlInfo aInfo;
141 0 : aInfo.setShapeId( rAttribs.getInteger( XML_spid, 0 ) );
142 0 : aInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
143 0 : aInfo.maName = rAttribs.getXString( XML_name, OUString() );
144 0 : mpSlidePersistPtr->getDrawing()->registerControl( aInfo );
145 : }
146 0 : return this;
147 :
148 : case PPT_TOKEN( timing ): // CT_SlideTiming
149 4 : return new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() );
150 : case PPT_TOKEN( transition ): // CT_SlideTransition
151 0 : return new SlideTransitionContext( *this, rAttribs, maSlideProperties );
152 : case PPT_TOKEN( hf ):
153 1 : return new HeaderFooterContext( *this, rAttribs, mpSlidePersistPtr->getHeaderFooter() );
154 :
155 : // BackgroundGroup
156 : case PPT_TOKEN( bg ):
157 5 : return this;
158 : case PPT_TOKEN( bgPr ): // CT_BackgroundProperties
159 : {
160 2 : FillPropertiesPtr pFillPropertiesPtr( new FillProperties );
161 2 : mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
162 2 : return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr );
163 : }
164 : break;
165 :
166 : case PPT_TOKEN( bgRef ): // a:CT_StyleMatrixReference
167 : {
168 3 : const FillProperties *pFillProperties = NULL;
169 3 : if( mpSlidePersistPtr->getTheme() )
170 2 : pFillProperties = mpSlidePersistPtr->getTheme()->getFillStyle( rAttribs.getInteger( XML_idx, -1 ) );
171 3 : FillPropertiesPtr pFillPropertiesPtr( pFillProperties ? new FillProperties( *pFillProperties ) : new FillProperties() );
172 3 : ContextHandlerRef ret = new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() );
173 3 : mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
174 3 : return ret;
175 : }
176 : break;
177 :
178 : case A_TOKEN( overrideClrMapping ):
179 : case PPT_TOKEN( clrMap ): // CT_ColorMapping
180 : {
181 5 : oox::drawingml::ClrMapPtr pClrMapPtr( ( aElementToken == PPT_TOKEN( clrMap ) || !mpSlidePersistPtr.get() || !mpSlidePersistPtr->getClrMap().get() ) ? new oox::drawingml::ClrMap() : new oox::drawingml::ClrMap( *mpSlidePersistPtr->getClrMap() ) );
182 5 : ContextHandlerRef ret = new oox::drawingml::clrMapContext( *this, rAttribs.getFastAttributeList(), *pClrMapPtr );
183 5 : mpSlidePersistPtr->setClrMap( pClrMapPtr );
184 5 : return ret;
185 : }
186 : break;
187 : case PPT_TOKEN( clrMapOvr ): // CT_ColorMappingOverride
188 : case PPT_TOKEN( sldLayoutIdLst ): // CT_SlideLayoutIdList
189 11 : return this;
190 : case PPT_TOKEN( txStyles ): // CT_SlideMasterTextStyles
191 3 : return new SlideMasterTextStylesContext( *this, mpSlidePersistPtr );
192 : break;
193 : case PPT_TOKEN( custDataLst ): // CT_CustomerDataList
194 : case PPT_TOKEN( tagLst ): // CT_TagList
195 0 : return this;
196 : }
197 :
198 115 : return this;
199 : }
200 :
201 14 : void SlideFragmentHandler::finalizeImport()
202 : {
203 : try
204 : {
205 14 : Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
206 14 : PropertySet aSlideProp( xSlide );
207 14 : aSlideProp.setProperties( maSlideProperties );
208 14 : if ( !maSlideName.isEmpty() )
209 : {
210 4 : Reference< XNamed > xNamed( xSlide, UNO_QUERY );
211 4 : if( xNamed.is() )
212 4 : xNamed->setName( maSlideName );
213 14 : }
214 : }
215 0 : catch( uno::Exception& )
216 : {
217 : OSL_FAIL( OString(rtl::OString("oox::ppt::SlideFragmentHandler::EndElement(), "
218 : "exception caught: ") +
219 : rtl::OUStringToOString(
220 : comphelper::anyToString( cppu::getCaughtException() ),
221 : RTL_TEXTENCODING_UTF8 )).getStr() );
222 : }
223 14 : }
224 :
225 51 : } }
226 :
227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|