1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <oox/ppt/pptshape.hxx>
21 #include <oox/ppt/pptgraphicshapecontext.hxx>
22 #include <oox/ppt/pptshapepropertiescontext.hxx>
23 #include <oox/ppt/slidepersist.hxx>
24 #include <drawingml/shapestylecontext.hxx>
25 #include <oox/drawingml/drawingmltypes.hxx>
26 #include <drawingml/textbodycontext.hxx>
27 #include <oox/helper/attributelist.hxx>
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
30 #include <oox/token/properties.hxx>
33 using namespace oox::core
;
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::text
;
41 PPTGraphicShapeContext::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
))
47 ContextHandlerRef
PPTGraphicShapeContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
49 switch( aElementToken
)
51 // nvSpPr CT_ShapeNonVisual begin
52 // case NMSP_PPT|XML_drElemPr:
54 case PPT_TOKEN(cNvPr
):
55 mpShapePtr
->setId( rAttribs
.getStringDefaulted( XML_id
) );
56 mpShapePtr
->setName( rAttribs
.getStringDefaulted( XML_name
) );
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
);
68 if ( nSubType
|| bHasIdx
)
70 PPTShape
* pPPTShapePtr
= dynamic_cast< PPTShape
* >( mpShapePtr
.get() );
73 oox::ppt::ShapeLocation eShapeLocation
= pPPTShapePtr
->getShapeLocation();
74 oox::drawingml::ShapePtr pPlaceholder
;
76 if ( bHasIdx
&& eShapeLocation
== Slide
)
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() );
83 if ( !pPlaceholder
&& ( ( eShapeLocation
== Slide
) || ( eShapeLocation
== Layout
) ) )
85 // inheriting properties from placeholder objects by cloning shape
87 sal_Int32 nFirstPlaceholder
= 0;
88 sal_Int32 nSecondPlaceholder
= 0;
91 case XML_ctrTitle
: // slide/layout
92 nFirstPlaceholder
= XML_ctrTitle
;
93 nSecondPlaceholder
= XML_title
;
95 case XML_subTitle
: // slide/layout
96 nFirstPlaceholder
= XML_subTitle
;
97 nSecondPlaceholder
= XML_title
;
99 case XML_obj
: // slide/layout
100 nFirstPlaceholder
= XML_body
;
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
;
120 if ( nFirstPlaceholder
)
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
127 SlidePersistPtr
pMasterPersist( mpSlidePersistPtr
->getMasterPersist() );
128 if ( pMasterPersist
)
129 pPlaceholder
= PPTShape::findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
,
130 pPPTShapePtr
->getSubTypeIndex(), pMasterPersist
->getShapes()->getChildren() );
136 bool bUseText
= true;
137 switch( pPlaceholder
->getSubType() )
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() );
162 pPPTShape
->setReferenced( true );
163 pPPTShapePtr
->setPlaceholder( pPlaceholder
);
169 // nvSpPr CT_ShapeNonVisual end
171 case PPT_TOKEN(spPr
):
172 return new PPTShapePropertiesContext( *this, *mpShapePtr
);
174 case PPT_TOKEN(style
):
175 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr
);
177 case PPT_TOKEN(txBody
):
179 oox::drawingml::TextBodyPtr xTextBody
= std::make_shared
<oox::drawingml::TextBody
>();
180 mpShapePtr
->setTextBody( xTextBody
);
181 return new oox::drawingml::TextBodyContext( *this, *xTextBody
);
185 return GraphicShapeContext::onCreateContext( aElementToken
, rAttribs
);
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */