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