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  Reference< css::beans::XPropertySet > xSet(xSlide, UNO_QUERY);
82  PropertyMap aPropMap;
83  PropertySet aSlideProp( xSlide );
84 
85  OptValue<bool> aShowMasterShapes = rAttribs.getBool(XML_showMasterSp);
86  if (aShowMasterShapes.has() && !aShowMasterShapes.get())
87  xSet->setPropertyValue("IsBackgroundObjectsVisible", Any(false));
88 
89  aPropMap.setProperty( PROP_Visible, rAttribs.getBool( XML_show, true ));
90  aSlideProp.setProperties( aPropMap );
91 
92  return this;
93  }
94  case PPT_TOKEN( notes ): // CT_NotesSlide
95  {
96  // Import notesMaster
97  PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
98  OUString aNotesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( u"notesMaster" );
99 
100  std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
101  bool bNotesFragmentPathFound = false;
102  for (auto const& masterPage : rMasterPages)
103  {
104  if( masterPage->getPath() == aNotesFragmentPath )
105  {
106  if( !mpSlidePersistPtr->getMasterPersist() )
107  mpSlidePersistPtr->setMasterPersist(masterPage);
108  bNotesFragmentPathFound=true;
109  break;
110  }
111  }
112  if( !bNotesFragmentPathFound && !mpSlidePersistPtr->getMasterPersist() )
113  {
114  SlidePersistPtr pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter, true, true, mpSlidePersistPtr->getPage(),
115  std::make_shared<PPTShape>( Master, "com.sun.star.drawing.GroupShape" ), mpSlidePersistPtr->getNotesTextStyle() );
116  pMasterPersistPtr->setPath( aNotesFragmentPath );
117  rFilter.getMasterPages().push_back( pMasterPersistPtr );
118  FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aNotesFragmentPath, pMasterPersistPtr, Master ) );
119  rFilter.importFragment( xMasterFragmentHandler );
120  mpSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
121  }
122  return this;
123  }
124  case PPT_TOKEN( notesMaster ): // CT_NotesMaster
125  return this;
126  case PPT_TOKEN( cSld ): // CT_CommonSlideData
127  maSlideName = rAttribs.getString(XML_name, OUString());
128  return this;
129 
130  case PPT_TOKEN( spTree ): // CT_GroupShape
131  {
132  return new PPTShapeGroupContext(
134  std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GroupShape" ) );
135  }
136  break;
137 
138  case PPT_TOKEN( controls ):
139  return this;
140  case PPT_TOKEN( control ):
141  {
143  aInfo.setShapeId( rAttribs.getInteger( XML_spid, 0 ) );
144  aInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
145  aInfo.maName = rAttribs.getXString( XML_name, OUString() );
146  mpSlidePersistPtr->getDrawing()->registerControl( aInfo );
147  }
148  return this;
149 
150  case PPT_TOKEN( timing ): // CT_SlideTiming
151  return new SlideTimingContext( *this, mpSlidePersistPtr->getTimeNodeList() );
152  case PPT_TOKEN( transition ): // CT_SlideTransition
153  return new SlideTransitionContext( *this, rAttribs, maSlideProperties );
154  case PPT_TOKEN( hf ):
155  return new HeaderFooterContext( *this, rAttribs, mpSlidePersistPtr->getHeaderFooter() );
156 
157  // BackgroundGroup
158  case PPT_TOKEN( bg ):
159  return this;
160  case PPT_TOKEN( bgPr ): // CT_BackgroundProperties
161  {
162  FillPropertiesPtr pFillPropertiesPtr =std::make_shared<FillProperties>();
163  mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
164  return new BackgroundPropertiesContext( *this, *pFillPropertiesPtr );
165  }
166  break;
167 
168  case PPT_TOKEN( bgRef ): // a:CT_StyleMatrixReference
169  {
170  const FillProperties *pFillProperties = nullptr;
171  if( mpSlidePersistPtr->getTheme() )
172  pFillProperties = mpSlidePersistPtr->getTheme()->getFillStyle( rAttribs.getInteger( XML_idx, -1 ) );
173  FillPropertiesPtr pFillPropertiesPtr =
174  pFillProperties
175  ? std::make_shared<FillProperties>( *pFillProperties )
176  : std::make_shared<FillProperties>();
177  mpSlidePersistPtr->setBackgroundProperties( pFillPropertiesPtr );
178  ContextHandlerRef ret = new ColorContext( *this, mpSlidePersistPtr->getBackgroundColor() );
179  return ret;
180  }
181  break;
182 
183  case A_TOKEN( overrideClrMapping ):
184  case PPT_TOKEN( clrMap ): // CT_ColorMapping
185  {
186  oox::drawingml::ClrMapPtr pClrMapPtr =
187  ( aElementToken == PPT_TOKEN( clrMap ) || !mpSlidePersistPtr || !mpSlidePersistPtr->getClrMap() )
188  ? std::make_shared<oox::drawingml::ClrMap>()
189  : std::make_shared<oox::drawingml::ClrMap>( *mpSlidePersistPtr->getClrMap() );
190  ContextHandlerRef ret = new oox::drawingml::clrMapContext( *this, rAttribs, *pClrMapPtr );
191  mpSlidePersistPtr->setClrMap( pClrMapPtr );
192  return ret;
193  }
194  break;
195  case PPT_TOKEN( clrMapOvr ): // CT_ColorMappingOverride
196  case PPT_TOKEN( sldLayoutIdLst ): // CT_SlideLayoutIdList
197  return this;
198  case PPT_TOKEN( txStyles ): // CT_SlideMasterTextStyles
199  return new SlideMasterTextStylesContext( *this, mpSlidePersistPtr );
200  case PPT_TOKEN( custDataLst ): // CT_CustomerDataList
201  case PPT_TOKEN( tagLst ): // CT_TagList
202  return this;
203 
204  //for Comments
205  case PPT_TOKEN( cmLst ):
206  break;
207  case PPT_TOKEN( cm ):
208  if (!mpSlidePersistPtr->getCommentsList().cmLst.empty() && !getCharVector().empty())
209  {
210  // set comment text for earlier comment
211  mpSlidePersistPtr->getCommentsList().cmLst.back().setText( getCharVector().back() );
212  }
213  // insert a new comment in vector commentsList
214  mpSlidePersistPtr->getCommentsList().cmLst.emplace_back();
215  mpSlidePersistPtr->getCommentsList().cmLst.back().setAuthorId(rAttribs.getString(XML_authorId, OUString()));
216  mpSlidePersistPtr->getCommentsList().cmLst.back().setdt(rAttribs.getString(XML_dt, OUString()));
217  mpSlidePersistPtr->getCommentsList().cmLst.back().setidx(rAttribs.getString(XML_idx, OUString()));
218  break;
219 
220  case PPT_TOKEN( pos ):
221  mpSlidePersistPtr->getCommentsList().cmLst.back().setPoint(
222  rAttribs.getString(XML_x, OUString()),
223  rAttribs.getString(XML_y, OUString()));
224  break;
225 
226  case PPT_TOKEN( cmAuthor ):
227  CommentAuthor _author;
228  _author.clrIdx = rAttribs.getString(XML_clrIdx, OUString());
229  _author.id = rAttribs.getString(XML_id, OUString());
230  _author.initials = rAttribs.getString(XML_initials, OUString());
231  _author.lastIdx = rAttribs.getString(XML_lastIdx, OUString());
232  _author.name = rAttribs.getString(XML_name, OUString());
233  mpSlidePersistPtr->getCommentAuthors().addAuthor(_author);
234  break;
235  }
236 
237  return this;
238 }
239 void SlideFragmentHandler::onCharacters( const OUString& rChars)
240 {
241  maCharVector.push_back(rChars);
242 }
244 {
245  try
246  {
247  Reference< XDrawPage > xSlide( mpSlidePersistPtr->getPage() );
248  PropertySet aSlideProp( xSlide );
249  aSlideProp.setProperties( maSlideProperties );
250  if ( !maSlideName.isEmpty() )
251  {
252  Reference< XNamed > xNamed( xSlide, UNO_QUERY );
253  if( xNamed.is() )
254  xNamed->setName( maSlideName );
255  }
256  }
257  catch( uno::Exception& )
258  {
259  TOOLS_WARN_EXCEPTION( "oox", "oox::ppt::SlideFragmentHandler::EndElement()" );
260  }
261 }
262 
263 }
264 
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< FillProperties > FillPropertiesPtr
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:51
OptValue< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
std::vector< SlidePersistPtr > & getMasterPages()
Definition: pptimport.hxx:72
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.
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:72
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
const Type & get() const
Definition: helper.hxx:185
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)
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
const snew_slide_value_info notes[]
bool has() const
Definition: helper.hxx:181
void setShapeId(sal_Int32 nShapeId)
Sets the string representation of the passed numeric shape identifier.
Definition: vmldrawing.cxx:90