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 <com/sun/star/xml/sax/FastToken.hpp>
21 #include <com/sun/star/drawing/LineStyle.hpp>
22 #include <com/sun/star/beans/XMultiPropertySet.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/container/XNamed.hpp>
26 #include "oox/ppt/pptshape.hxx"
27 #include "oox/ppt/pptgraphicshapecontext.hxx"
28 #include "oox/ppt/pptshapepropertiescontext.hxx"
29 #include "oox/ppt/slidepersist.hxx"
30 #include "drawingml/shapestylecontext.hxx"
31 #include "oox/token/namespaces.hxx"
32 #include "drawingml/fillpropertiesgroupcontext.hxx"
33 #include "oox/drawingml/lineproperties.hxx"
34 #include "oox/drawingml/drawingmltypes.hxx"
35 #include "drawingml/customshapegeometry.hxx"
36 #include "drawingml/textbodycontext.hxx"
37 #include <oox/token/tokens.hxx>
39 using namespace oox::core
;
40 using namespace ::com::sun::star
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::drawing
;
43 using namespace ::com::sun::star::beans
;
44 using namespace ::com::sun::star::text
;
45 using namespace ::com::sun::star::xml::sax
;
47 namespace oox
{ namespace ppt
{
50 PPTGraphicShapeContext::PPTGraphicShapeContext( ContextHandler2Helper
& rParent
, const SlidePersistPtr
& rSlidePersistPtr
, oox::drawingml::ShapePtr pMasterShapePtr
, oox::drawingml::ShapePtr pShapePtr
)
51 : oox::drawingml::GraphicShapeContext( rParent
, pMasterShapePtr
, pShapePtr
)
52 , mpSlidePersistPtr( rSlidePersistPtr
)
56 ContextHandlerRef
PPTGraphicShapeContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
58 switch( aElementToken
)
60 // nvSpPr CT_ShapeNonVisual begin
61 // case NMSP_PPT|XML_drElemPr:
63 case PPT_TOKEN(cNvPr
):
64 mpShapePtr
->setId( rAttribs
.getString( XML_id
).get() );
65 mpShapePtr
->setName( rAttribs
.getString( XML_name
).get() );
69 sal_Int32
nSubType( rAttribs
.getToken( XML_type
, XML_obj
) );
70 mpShapePtr
->setSubType( nSubType
);
71 OUString
sIdx( rAttribs
.getString( XML_idx
).get() );
72 bool bHasIdx
= !sIdx
.isEmpty();
73 sal_Int32 nIdx
= sIdx
.toInt32();
74 if( rAttribs
.hasAttribute( XML_idx
) )
75 mpShapePtr
->setSubTypeIndex( nIdx
);
77 if ( nSubType
|| bHasIdx
)
79 PPTShape
* pPPTShapePtr
= dynamic_cast< PPTShape
* >( mpShapePtr
.get() );
82 oox::ppt::ShapeLocation eShapeLocation
= pPPTShapePtr
->getShapeLocation();
83 oox::drawingml::ShapePtr pPlaceholder
;
85 if ( bHasIdx
&& eShapeLocation
== Slide
)
87 // TODO: use id to shape map
88 SlidePersistPtr
pMasterPersist( mpSlidePersistPtr
->getMasterPersist() );
89 if ( pMasterPersist
.get() && rAttribs
.hasAttribute( XML_idx
) )
90 pPlaceholder
= PPTShape::findPlaceholderByIndex( nIdx
, pMasterPersist
->getShapes()->getChildren() );
92 if ( !pPlaceholder
.get() && ( ( eShapeLocation
== Slide
) || ( eShapeLocation
== Layout
) ) )
94 // inheriting properties from placeholder objects by cloning shape
96 sal_Int32 nFirstPlaceholder
= 0;
97 sal_Int32 nSecondPlaceholder
= 0;
100 case XML_ctrTitle
: // slide/layout
101 nFirstPlaceholder
= XML_ctrTitle
;
102 nSecondPlaceholder
= XML_title
;
104 case XML_subTitle
: // slide/layout
105 nFirstPlaceholder
= XML_subTitle
;
106 nSecondPlaceholder
= XML_title
;
108 case XML_obj
: // slide/layout
109 nFirstPlaceholder
= XML_body
;
111 case XML_dt
: // slide/layout/master/notes/notesmaster/handoutmaster
112 case XML_sldNum
: // slide/layout/master/notes/notesmaster/handoutmaster
113 case XML_ftr
: // slide/layout/master/notes/notesmaster/handoutmaster
114 case XML_hdr
: // notes/notesmaster/handoutmaster
115 case XML_body
: // slide/layout/master/notes/notesmaster
116 case XML_title
: // slide/layout/master/
117 case XML_chart
: // slide/layout
118 case XML_tbl
: // slide/layout
119 case XML_clipArt
: // slide/layout
120 case XML_dgm
: // slide/layout
121 case XML_media
: // slide/layout
122 case XML_sldImg
: // notes/notesmaster
123 case XML_pic
: // slide/layout
124 nFirstPlaceholder
= nSubType
;
128 if ( nFirstPlaceholder
)
130 if ( eShapeLocation
== Layout
) // for layout objects the referenced object can be found within the same shape tree
131 pPlaceholder
= PPTShape::findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
,
132 pPPTShapePtr
->getSubTypeIndex(), mpSlidePersistPtr
->getShapes()->getChildren(), true );
133 else if ( eShapeLocation
== Slide
) // normal slide shapes have to search within the corresponding master tree for referenced objects
135 SlidePersistPtr
pMasterPersist( mpSlidePersistPtr
->getMasterPersist() );
136 if ( pMasterPersist
.get() )
137 pPlaceholder
= PPTShape::findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
,
138 pPPTShapePtr
->getSubTypeIndex(), pMasterPersist
->getShapes()->getChildren() );
142 if ( pPlaceholder
.get() )
144 bool bUseText
= true;
145 switch( pPlaceholder
->getSubType() )
165 mpShapePtr
->applyShapeReference( *pPlaceholder
.get(), bUseText
);
166 PPTShape
* pPPTShape
= dynamic_cast< PPTShape
* >( pPlaceholder
.get() );
168 pPPTShape
->setReferenced( true );
169 pPPTShapePtr
->setPlaceholder( pPlaceholder
);
175 // nvSpPr CT_ShapeNonVisual end
177 case PPT_TOKEN(spPr
):
178 return new PPTShapePropertiesContext( *this, *mpShapePtr
);
180 case PPT_TOKEN(style
):
181 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr
);
183 case PPT_TOKEN(txBody
):
185 oox::drawingml::TextBodyPtr
xTextBody( new oox::drawingml::TextBody
);
186 mpShapePtr
->setTextBody( xTextBody
);
187 return new oox::drawingml::TextBodyContext( *this, *xTextBody
);
191 return GraphicShapeContext::onCreateContext( aElementToken
, rAttribs
);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */