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 "comphelper/anytostring.hxx"
21 #include "cppuhelper/exc_hlp.hxx"
23 #include <com/sun/star/beans/XMultiPropertySet.hpp>
24 #include <com/sun/star/container/XNamed.hpp>
25 #include <osl/diagnose.h>
27 #include "oox/helper/propertyset.hxx"
28 #include "oox/core/xmlfilterbase.hxx"
29 #include "headerfootercontext.hxx"
30 #include "oox/ppt/backgroundproperties.hxx"
31 #include "oox/ppt/slidefragmenthandler.hxx"
32 #include "oox/ppt/slidetimingcontext.hxx"
33 #include "oox/ppt/slidetransitioncontext.hxx"
34 #include "oox/ppt/slidemastertextstylescontext.hxx"
35 #include "oox/ppt/pptshapegroupcontext.hxx"
36 #include "oox/ppt/pptshape.hxx"
37 #include "oox/vml/vmldrawing.hxx"
38 #include "oox/vml/vmldrawingfragment.hxx"
39 #include "drawingml/clrschemecontext.hxx"
40 #include "drawingml/textliststyle.hxx"
41 #include "oox/ppt/pptimport.hxx"
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
;
51 namespace oox
{ namespace ppt
{
53 SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase
& rFilter
, const OUString
& rFragmentPath
, SlidePersistPtr pPersistPtr
, const ShapeLocation eShapeLocation
)
54 : FragmentHandler2( rFilter
, rFragmentPath
)
55 , mpSlidePersistPtr( pPersistPtr
)
56 , meShapeLocation( eShapeLocation
)
58 OUString aVMLDrawingFragmentPath
= getFragmentPathFromFirstTypeFromOfficeDoc( "vmlDrawing" );
59 if( !aVMLDrawingFragmentPath
.isEmpty() )
60 getFilter().importFragment( new oox::vml::DrawingFragment(
61 getFilter(), aVMLDrawingFragmentPath
, *pPersistPtr
->getDrawing() ) );
64 SlideFragmentHandler::~SlideFragmentHandler()
66 // convert and insert all VML shapes (mostly form controls)
67 mpSlidePersistPtr
->getDrawing()->convertAndInsert();
70 ::oox::core::ContextHandlerRef
SlideFragmentHandler::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
72 switch( aElementToken
)
74 case PPT_TOKEN( sldMaster
): // CT_SlideMaster
75 case PPT_TOKEN( handoutMaster
): // CT_HandoutMaster
76 case PPT_TOKEN( sld
): // CT_CommonSlideData
78 Reference
< XDrawPage
> xSlide( mpSlidePersistPtr
->getPage() );
80 PropertySet
aSlideProp( xSlide
);
82 aPropMap
.setProperty( PROP_Visible
, rAttribs
.getBool( XML_show
, true ));
83 aSlideProp
.setProperties( aPropMap
);
87 case PPT_TOKEN( notes
): // CT_NotesSlide
90 PowerPointImport
& rFilter
= dynamic_cast< PowerPointImport
& >( getFilter() );
91 OUString aNotesFragmentPath
= getFragmentPathFromFirstTypeFromOfficeDoc( "notesMaster" );
93 std::vector
< SlidePersistPtr
>& rMasterPages( rFilter
.getMasterPages() );
94 std::vector
< SlidePersistPtr
>::iterator
aIter( rMasterPages
.begin() );
95 while( aIter
!= rMasterPages
.end() )
97 if( (*aIter
)->getPath() == aNotesFragmentPath
)
99 if( !mpSlidePersistPtr
->getMasterPersist() )
100 mpSlidePersistPtr
->setMasterPersist( *aIter
);
105 if( aIter
== rMasterPages
.end() && !mpSlidePersistPtr
->getMasterPersist() )
107 TextListStylePtr
pTextListStyle(new TextListStyle
);
108 SlidePersistPtr pMasterPersistPtr
= SlidePersistPtr( new SlidePersist( rFilter
, true, true, mpSlidePersistPtr
->getPage(),
109 ShapePtr( new PPTShape( Master
, "com.sun.star.drawing.GroupShape" ) ), mpSlidePersistPtr
->getNotesTextStyle() ) );
110 pMasterPersistPtr
->setPath( aNotesFragmentPath
);
111 rFilter
.getMasterPages().push_back( pMasterPersistPtr
);
112 FragmentHandlerRef
xMasterFragmentHandler( new SlideFragmentHandler( rFilter
, aNotesFragmentPath
, pMasterPersistPtr
, Master
) );
113 rFilter
.importFragment( xMasterFragmentHandler
);
114 mpSlidePersistPtr
->setMasterPersist( pMasterPersistPtr
);
118 case PPT_TOKEN( notesMaster
): // CT_NotesMaster
120 case PPT_TOKEN( cSld
): // CT_CommonSlideData
121 maSlideName
= rAttribs
.getString(XML_name
, OUString());
124 case PPT_TOKEN( spTree
): // CT_GroupShape
126 // TODO Convert this to FragmentHandler2
127 return new PPTShapeGroupContext(
128 *this, mpSlidePersistPtr
, meShapeLocation
, mpSlidePersistPtr
->getShapes(),
129 oox::drawingml::ShapePtr( new PPTShape( meShapeLocation
, "com.sun.star.drawing.GroupShape" ) ) );
133 case PPT_TOKEN( controls
):
135 case PPT_TOKEN( control
):
137 ::oox::vml::ControlInfo aInfo
;
138 aInfo
.setShapeId( rAttribs
.getInteger( XML_spid
, 0 ) );
139 aInfo
.maFragmentPath
= getFragmentPathFromRelId( rAttribs
.getString( R_TOKEN( id
), OUString() ) );
140 aInfo
.maName
= rAttribs
.getXString( XML_name
, OUString() );
141 mpSlidePersistPtr
->getDrawing()->registerControl( aInfo
);
145 case PPT_TOKEN( timing
): // CT_SlideTiming
146 return new SlideTimingContext( *this, mpSlidePersistPtr
->getTimeNodeList() );
147 case PPT_TOKEN( transition
): // CT_SlideTransition
148 return new SlideTransitionContext( *this, rAttribs
, maSlideProperties
);
149 case PPT_TOKEN( hf
):
150 return new HeaderFooterContext( *this, rAttribs
, mpSlidePersistPtr
->getHeaderFooter() );
153 case PPT_TOKEN( bg
):
155 case PPT_TOKEN( bgPr
): // CT_BackgroundProperties
157 FillPropertiesPtr
pFillPropertiesPtr( new FillProperties
);
158 mpSlidePersistPtr
->setBackgroundProperties( pFillPropertiesPtr
);
159 return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr
);
163 case PPT_TOKEN( bgRef
): // a:CT_StyleMatrixReference
165 const FillProperties
*pFillProperties
= NULL
;
166 if( mpSlidePersistPtr
->getTheme() )
167 pFillProperties
= mpSlidePersistPtr
->getTheme()->getFillStyle( rAttribs
.getInteger( XML_idx
, -1 ) );
168 FillPropertiesPtr
pFillPropertiesPtr( pFillProperties
? new FillProperties( *pFillProperties
) : new FillProperties() );
169 ContextHandlerRef ret
= new ColorContext( *this, mpSlidePersistPtr
->getBackgroundColor() );
170 mpSlidePersistPtr
->setBackgroundProperties( pFillPropertiesPtr
);
175 case A_TOKEN( overrideClrMapping
):
176 case PPT_TOKEN( clrMap
): // CT_ColorMapping
178 oox::drawingml::ClrMapPtr
pClrMapPtr( ( aElementToken
== PPT_TOKEN( clrMap
) || !mpSlidePersistPtr
.get() || !mpSlidePersistPtr
->getClrMap().get() ) ? new oox::drawingml::ClrMap() : new oox::drawingml::ClrMap( *mpSlidePersistPtr
->getClrMap() ) );
179 ContextHandlerRef ret
= new oox::drawingml::clrMapContext( *this, rAttribs
, *pClrMapPtr
);
180 mpSlidePersistPtr
->setClrMap( pClrMapPtr
);
184 case PPT_TOKEN( clrMapOvr
): // CT_ColorMappingOverride
185 case PPT_TOKEN( sldLayoutIdLst
): // CT_SlideLayoutIdList
187 case PPT_TOKEN( txStyles
): // CT_SlideMasterTextStyles
188 return new SlideMasterTextStylesContext( *this, mpSlidePersistPtr
);
189 case PPT_TOKEN( custDataLst
): // CT_CustomerDataList
190 case PPT_TOKEN( tagLst
): // CT_TagList
194 case PPT_TOKEN( cmLst
):
196 case PPT_TOKEN( cm
):
197 if (!mpSlidePersistPtr
->getCommentsList().cmLst
.empty() && !getCharVector().empty())
199 // set comment text for earlier comment
200 mpSlidePersistPtr
->getCommentsList().cmLst
.back().setText( getCharVector().back() );
202 // insert a new comment in vector commentsList
203 mpSlidePersistPtr
->getCommentsList().cmLst
.push_back(Comment());
204 mpSlidePersistPtr
->getCommentsList().cmLst
.back().setAuthorId(rAttribs
.getString(XML_authorId
, OUString()));
205 mpSlidePersistPtr
->getCommentsList().cmLst
.back().setdt(rAttribs
.getString(XML_dt
, OUString()));
206 mpSlidePersistPtr
->getCommentsList().cmLst
.back().setidx(rAttribs
.getString(XML_idx
, OUString()));
209 case PPT_TOKEN( pos
):
210 mpSlidePersistPtr
->getCommentsList().cmLst
.back().setPoint(
211 rAttribs
.getString(XML_x
, OUString()),
212 rAttribs
.getString(XML_y
, OUString()));
215 case PPT_TOKEN( cmAuthor
):
216 CommentAuthor _author
;
217 _author
.clrIdx
= rAttribs
.getString(XML_clrIdx
, OUString());
218 _author
.id
= rAttribs
.getString(XML_id
, OUString());
219 _author
.initials
= rAttribs
.getString(XML_initials
, OUString());
220 _author
.lastIdx
= rAttribs
.getString(XML_lastIdx
, OUString());
221 _author
.name
= rAttribs
.getString(XML_name
, OUString());
222 mpSlidePersistPtr
->getCommentAuthors().addAuthor(_author
);
228 void SlideFragmentHandler::onCharacters( const OUString
& rChars
)
230 maCharVector
.push_back(rChars
);
232 void SlideFragmentHandler::finalizeImport()
236 Reference
< XDrawPage
> xSlide( mpSlidePersistPtr
->getPage() );
237 PropertySet
aSlideProp( xSlide
);
238 aSlideProp
.setProperties( maSlideProperties
);
239 if ( !maSlideName
.isEmpty() )
241 Reference
< XNamed
> xNamed( xSlide
, UNO_QUERY
);
243 xNamed
->setName( maSlideName
);
246 catch( uno::Exception
& )
248 OSL_FAIL( OString("oox::ppt::SlideFragmentHandler::EndElement(), "
249 "exception caught: " +
251 comphelper::anyToString( cppu::getCaughtException() ),
252 RTL_TEXTENCODING_UTF8
)).getStr());
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */