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