LibreOffice Module oox (master)  1
slidefragmenthandler.cxx
Go to the documentation of this file.
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/beans/XPropertySet.hpp>
21 #include <com/sun/star/container/XNamed.hpp>
22 #include <com/sun/star/drawing/XDrawPage.hpp>
23 #include <tools/diagnose_ex.h>
24 
28 #include "headerfootercontext.hxx"
35 #include <oox/ppt/pptshape.hxx>
36 #include <oox/vml/vmldrawing.hxx>
40 #include <oox/ppt/pptimport.hxx>
41 #include <oox/token/namespaces.hxx>
42 #include <oox/token/properties.hxx>
43 #include <oox/token/tokens.hxx>
44 
45 using namespace ::com::sun::star;
46 using namespace ::oox::core;
47 using namespace ::oox::drawingml;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::drawing;
50 using namespace ::com::sun::star::xml::sax;
51 using namespace ::com::sun::star::container;
52 
53 namespace oox::ppt {
54 
55 SlideFragmentHandler::SlideFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath, const SlidePersistPtr& pPersistPtr, const ShapeLocation eShapeLocation )
56 : FragmentHandler2( rFilter, rFragmentPath )
57 , mpSlidePersistPtr( pPersistPtr )
58 , meShapeLocation( eShapeLocation )
59 {
60  OUString aVMLDrawingFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( u"vmlDrawing" );
61  if( !aVMLDrawingFragmentPath.isEmpty() )
62  getFilter().importFragment( new oox::vml::DrawingFragment(
63  getFilter(), aVMLDrawingFragmentPath, *pPersistPtr->getDrawing() ) );
64 }
65 
67 {
68  // convert and insert all VML shapes (mostly form controls)
69  mpSlidePersistPtr->getDrawing()->convertAndInsert();
70 }
71 
73 {
74  switch( aElementToken )
75  {
76  case PPT_TOKEN( sldMaster ): // CT_SlideMaster
77  case PPT_TOKEN( handoutMaster ): // CT_HandoutMaster
78  case PPT_TOKEN( sld ): // CT_CommonSlideData
79  {
80  Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
81  PropertyMap aPropMap;
82  PropertySet aSlideProp( xSlide );
83 
84  aPropMap.setProperty( PROP_Visible, rAttribs.getBool( XML_show, true ));
85  aSlideProp.setProperties( aPropMap );
86 
87  return this;
88  }
89  case PPT_TOKEN( notes ): // CT_NotesSlide
90  {
91  // Import notesMaster
92  PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
93  OUString aNotesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( u"notesMaster" );
94 
95  std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
96  bool bNotesFragmentPathFound = false;
97  for (auto const& masterPage : rMasterPages)
98  {
99  if( masterPage->getPath() == aNotesFragmentPath )
100  {
101  if( !mpSlidePersistPtr->getMasterPersist() )
102  mpSlidePersistPtr->setMasterPersist(masterPage);
103  bNotesFragmentPathFound=true;
104  break;
105  }
106  }
107  if( !bNotesFragmentPathFound && !mpSlidePersistPtr->getMasterPersist() )
108  {
109  SlidePersistPtr pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter, true, true, mpSlidePersistPtr->getPage(),
110  std::make_shared<PPTShape>( Master, "com.sun.star.drawing.GroupShape" ), mpSlidePersistPtr->getNotesTextStyle() );
111  pMasterPersistPtr->setPath( aNotesFragmentPath );
112  rFilter.getMasterPages().push_back( pMasterPersistPtr );
113  FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aNotesFragmentPath, pMasterPersistPtr, Master ) );
114  rFilter.importFragment( xMasterFragmentHandler );
115  mpSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
116  }
117  return this;
118  }
119  case PPT_TOKEN( notesMaster ): // CT_NotesMaster
120  return this;
121  case PPT_TOKEN( cSld ): // CT_CommonSlideData
122  maSlideName = rAttribs.getString(XML_name, OUString());
123  return this;
124 
125  case PPT_TOKEN( spTree ): // CT_GroupShape
126  {
127  return new PPTShapeGroupContext(
129  std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GroupShape" ) );
130  }
131  break;
132 
133  case PPT_TOKEN( controls ):
134  return this;
135  case PPT_TOKEN( control ):
136  {
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 );
142  }
143  return this;
144 
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() );
151 
152  // BackgroundGroup
153  case PPT_TOKEN( bg ):
154  return this;
155  case PPT_TOKEN( bgPr ): // CT_BackgroundProperties
156  {
157  FillPropertiesPtr pFillPropertiesPtr =std::make_shared<FillProperties>();
158  mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
159  return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr );
160  }
161  break;
162 
163  case PPT_TOKEN( bgRef ): // a:CT_StyleMatrixReference
164  {
165  const FillProperties *pFillProperties = nullptr;
166  if( mpSlidePersistPtr->getTheme() )
167  pFillProperties = mpSlidePersistPtr->getTheme()->getFillStyle( rAttribs.getInteger( XML_idx, -1 ) );
168  FillPropertiesPtr pFillPropertiesPtr =
169  pFillProperties
170  ? std::make_shared<FillProperties>( *pFillProperties )
171  : std::make_shared<FillProperties>();
172  mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
173  ContextHandlerRef ret = new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() );
174  return ret;
175  }
176  break;
177 
178  case A_TOKEN( overrideClrMapping ):
179  case PPT_TOKEN( clrMap ): // CT_ColorMapping
180  {
181  oox::drawingml::ClrMapPtr pClrMapPtr =
182  ( aElementToken == PPT_TOKEN( clrMap ) || !mpSlidePersistPtr || !mpSlidePersistPtr->getClrMap() )
183  ? std::make_shared<oox::drawingml::ClrMap>()
184  : std::make_shared<oox::drawingml::ClrMap>( *mpSlidePersistPtr->getClrMap() );
185  ContextHandlerRef ret = new oox::drawingml::clrMapContext( *this, rAttribs, *pClrMapPtr );
186  mpSlidePersistPtr->setClrMap( pClrMapPtr );
187  return ret;
188  }
189  break;
190  case PPT_TOKEN( clrMapOvr ): // CT_ColorMappingOverride
191  case PPT_TOKEN( sldLayoutIdLst ): // CT_SlideLayoutIdList
192  return this;
193  case PPT_TOKEN( txStyles ): // CT_SlideMasterTextStyles
194  return new SlideMasterTextStylesContext( *this, mpSlidePersistPtr );
195  case PPT_TOKEN( custDataLst ): // CT_CustomerDataList
196  case PPT_TOKEN( tagLst ): // CT_TagList
197  return this;
198 
199  //for Comments
200  case PPT_TOKEN( cmLst ):
201  break;
202  case PPT_TOKEN( cm ):
203  if (!mpSlidePersistPtr->getCommentsList().cmLst.empty() && !getCharVector().empty())
204  {
205  // set comment text for earlier comment
206  mpSlidePersistPtr->getCommentsList().cmLst.back().setText( getCharVector().back() );
207  }
208  // insert a new comment in vector commentsList
209  mpSlidePersistPtr->getCommentsList().cmLst.emplace_back();
210  mpSlidePersistPtr->getCommentsList().cmLst.back().setAuthorId(rAttribs.getString(XML_authorId, OUString()));
211  mpSlidePersistPtr->getCommentsList().cmLst.back().setdt(rAttribs.getString(XML_dt, OUString()));
212  mpSlidePersistPtr->getCommentsList().cmLst.back().setidx(rAttribs.getString(XML_idx, OUString()));
213  break;
214 
215  case PPT_TOKEN( pos ):
216  mpSlidePersistPtr->getCommentsList().cmLst.back().setPoint(
217  rAttribs.getString(XML_x, OUString()),
218  rAttribs.getString(XML_y, OUString()));
219  break;
220 
221  case PPT_TOKEN( cmAuthor ):
222  CommentAuthor _author;
223  _author.clrIdx = rAttribs.getString(XML_clrIdx, OUString());
224  _author.id = rAttribs.getString(XML_id, OUString());
225  _author.initials = rAttribs.getString(XML_initials, OUString());
226  _author.lastIdx = rAttribs.getString(XML_lastIdx, OUString());
227  _author.name = rAttribs.getString(XML_name, OUString());
228  mpSlidePersistPtr->getCommentAuthors().addAuthor(_author);
229  break;
230  }
231 
232  return this;
233 }
234 void SlideFragmentHandler::onCharacters( const OUString& rChars)
235 {
236  maCharVector.push_back(rChars);
237 }
239 {
240  try
241  {
242  Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
243  PropertySet aSlideProp( xSlide );
244  aSlideProp.setProperties( maSlideProperties );
245  if ( !maSlideName.isEmpty() )
246  {
247  Reference< XNamed > xNamed( xSlide, UNO_QUERY );
248  if( xNamed.is() )
249  xNamed->setName( maSlideName );
250  }
251  }
252  catch( uno::Exception& )
253  {
254  TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::SlideFragmentHandler::EndElement()" );
255  }
256 }
257 
258 }
259 
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< FillProperties > FillPropertiesPtr
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
OptValue< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
std::vector< SlidePersistPtr > & getMasterPages()
Definition: pptimport.hxx:73
exports com.sun.star.form. control
OptValue< OUString > getXString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
OptValue< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
void setProperties(const css::uno::Sequence< OUString > &rPropNames, const css::uno::Sequence< css::uno::Any > &rValues)
Puts the passed properties into the property set.
virtual void finalizeImport() override
size_t pos
Contains information about a form control embedded in a draw page.
Definition: vmldrawing.hxx:78
#define TOOLS_WARN_EXCEPTION(area, stream)
const ::std::vector< OUString > & getCharVector() const
SlideFragmentHandler(::oox::core::XmlFilterBase &rFilter, const OUString &rFragmentPath, const SlidePersistPtr &pPersistPtr, const ShapeLocation eShapeLocation)
const snewfoil_value_info notes[]
float u
OUString maName
Programmatical name of the form control.
Definition: vmldrawing.hxx:82
A wrapper for a UNO property set.
Definition: propertyset.hxx:57
OUString maFragmentPath
Path to the fragment describing the form control properties.
Definition: vmldrawing.hxx:81
Provides access to attribute values of an element.
::std::vector< OUString > maCharVector
virtual void onCharacters(const OUString &rChars) override
Will be called before a new child element starts, or if the current element is about to be left...
::rtl::Reference< ContextHandler > ContextHandlerRef
std::shared_ptr< ClrMap > ClrMapPtr
Definition: clrscheme.hxx:78
::rtl::Reference< FragmentHandler > FragmentHandlerRef
std::shared_ptr< SlidePersist > SlidePersistPtr
void setShapeId(sal_Int32 nShapeId)
Sets the string representation of the passed numeric shape identifier.
Definition: vmldrawing.cxx:89