LibreOffice Module oox (master)  1
pptgraphicshapecontext.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 <oox/ppt/pptshape.hxx>
23 #include <oox/ppt/slidepersist.hxx>
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
30 #include <oox/token/properties.hxx>
31 
32 using namespace oox::core;
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::text;
36 
37 namespace oox::ppt {
38 
39 // CT_Shape
40 PPTGraphicShapeContext::PPTGraphicShapeContext( ContextHandler2Helper const & rParent, const SlidePersistPtr& rSlidePersistPtr, const oox::drawingml::ShapePtr& pMasterShapePtr, const oox::drawingml::ShapePtr& pShapePtr )
41 : oox::drawingml::GraphicShapeContext( rParent, pMasterShapePtr, pShapePtr )
42 , mpSlidePersistPtr( rSlidePersistPtr )
43 {
44 }
45 
46 ContextHandlerRef PPTGraphicShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
47 {
48  switch( aElementToken )
49  {
50  // nvSpPr CT_ShapeNonVisual begin
51 // case NMSP_PPT|XML_drElemPr:
52 // break;
53  case PPT_TOKEN(cNvPr):
54  mpShapePtr->setId( rAttribs.getString( XML_id ).get() );
55  mpShapePtr->setName( rAttribs.getString( XML_name ).get() );
56  break;
57  case PPT_TOKEN(ph):
58  {
59  sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
60  mpShapePtr->setSubType( nSubType );
61  OUString sIdx( rAttribs.getString( XML_idx ).get() );
62  bool bHasIdx = !sIdx.isEmpty();
63  sal_Int32 nIdx = sIdx.toInt32();
64  if( rAttribs.hasAttribute( XML_idx ) )
65  mpShapePtr->setSubTypeIndex( nIdx );
66 
67  if ( nSubType || bHasIdx )
68  {
69  PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
70  if ( pPPTShapePtr )
71  {
72  oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
73  oox::drawingml::ShapePtr pPlaceholder;
74 
75  if ( bHasIdx && eShapeLocation == Slide )
76  {
77  // TODO: use id to shape map
78  SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
79  if ( pMasterPersist && rAttribs.hasAttribute( XML_idx ) )
80  pPlaceholder = PPTShape::findPlaceholderByIndex( nIdx, pMasterPersist->getShapes()->getChildren() );
81  }
82  if ( !pPlaceholder && ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) )
83  {
84  // inheriting properties from placeholder objects by cloning shape
85 
86  sal_Int32 nFirstPlaceholder = 0;
87  sal_Int32 nSecondPlaceholder = 0;
88  switch( nSubType )
89  {
90  case XML_ctrTitle : // slide/layout
91  nFirstPlaceholder = XML_ctrTitle;
92  nSecondPlaceholder = XML_title;
93  break;
94  case XML_subTitle : // slide/layout
95  nFirstPlaceholder = XML_subTitle;
96  nSecondPlaceholder = XML_title;
97  break;
98  case XML_obj : // slide/layout
99  nFirstPlaceholder = XML_body;
100  break;
101  case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster
102  case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster
103  case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster
104  case XML_hdr : // notes/notesmaster/handoutmaster
105  case XML_body : // slide/layout/master/notes/notesmaster
106  case XML_title : // slide/layout/master/
107  case XML_chart : // slide/layout
108  case XML_tbl : // slide/layout
109  case XML_clipArt : // slide/layout
110  case XML_dgm : // slide/layout
111  case XML_media : // slide/layout
112  case XML_sldImg : // notes/notesmaster
113  case XML_pic : // slide/layout
114  nFirstPlaceholder = nSubType;
115  break;
116  default:
117  break;
118  }
119  if ( nFirstPlaceholder )
120  {
121  if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
122  pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
123  pPPTShapePtr->getSubTypeIndex(), mpSlidePersistPtr->getShapes()->getChildren(), true );
124  else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
125  {
126  SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
127  if ( pMasterPersist )
128  pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
129  pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
130  }
131  }
132  }
133  if ( pPlaceholder )
134  {
135  bool bUseText = true;
136  switch( pPlaceholder->getSubType() )
137  {
138  case XML_title :
139  case XML_body :
140  case XML_ctrTitle :
141  case XML_subTitle :
142  case XML_dt :
143  case XML_sldNum :
144  case XML_ftr :
145  case XML_hdr :
146  case XML_obj :
147  case XML_chart :
148  case XML_tbl :
149  case XML_clipArt :
150  case XML_dgm :
151  case XML_media :
152  case XML_sldImg :
153  case XML_pic :
154  bUseText = false;
155  }
156  pPlaceholder->getShapeProperties().setAnyProperty(
157  PROP_URL, mpShapePtr->getShapeProperties().getProperty(PROP_URL));
158  mpShapePtr->applyShapeReference( *pPlaceholder, bUseText );
159  PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
160  if ( pPPTShape )
161  pPPTShape->setReferenced( true );
162  pPPTShapePtr->setPlaceholder( pPlaceholder );
163  }
164  }
165  }
166  break;
167  }
168  // nvSpPr CT_ShapeNonVisual end
169 
170  case PPT_TOKEN(spPr):
171  return new PPTShapePropertiesContext( *this, *mpShapePtr );
172 
173  case PPT_TOKEN(style):
174  return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
175 
176  case PPT_TOKEN(txBody):
177  {
178  oox::drawingml::TextBodyPtr xTextBody = std::make_shared<oox::drawingml::TextBody>();
179  mpShapePtr->setTextBody( xTextBody );
180  return new oox::drawingml::TextBodyContext( *this, *xTextBody );
181  }
182  }
183 
184  return GraphicShapeContext::onCreateContext( aElementToken, rAttribs );
185 }
186 
187 }
188 
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setReferenced(bool bReferenced)
Definition: pptshape.hxx:76
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
const Type & get() const
Definition: helper.hxx:185
ShapeLocation getShapeLocation() const
Definition: pptshape.hxx:75
static oox::drawingml::ShapePtr findPlaceholder(const sal_Int32 nFirstSubType, const sal_Int32 nSecondSubType, const OptValue< sal_Int32 > &oSubTypeIndex, std::vector< oox::drawingml::ShapePtr > &rShapes, bool bMasterOnly=false)
Definition: pptshape.cxx:655
void setPlaceholder(oox::drawingml::ShapePtr pPlaceholder)
Definition: pptshape.hxx:77
const OptValue< sal_Int32 > & getSubTypeIndex() const
Definition: shape.hxx:164
std::shared_ptr< TextBody > TextBodyPtr
Provides access to attribute values of an element.
exports com.sun.star. style
static oox::drawingml::ShapePtr findPlaceholderByIndex(const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr > &rShapes, bool bMasterOnly=false)
Definition: pptshape.cxx:755
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
std::shared_ptr< SlidePersist > SlidePersistPtr
std::shared_ptr< Shape > ShapePtr
Helper class that provides a context stack.
OptValue< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.