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 <sal/log.hxx>
22 #include <com/sun/star/xml/sax/FastToken.hpp>
23 #include <com/sun/star/drawing/LineStyle.hpp>
24 #include <com/sun/star/beans/XMultiPropertySet.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/container/XNamed.hpp>
28 #include <oox/helper/attributelist.hxx>
29 #include <oox/ppt/pptshape.hxx>
30 #include <oox/ppt/pptshapecontext.hxx>
31 #include <oox/ppt/pptshapepropertiescontext.hxx>
32 #include <oox/ppt/slidepersist.hxx>
33 #include <drawingml/shapestylecontext.hxx>
34 #include <drawingml/misccontexts.hxx>
35 #include <drawingml/lineproperties.hxx>
36 #include <oox/drawingml/drawingmltypes.hxx>
37 #include <drawingml/customshapegeometry.hxx>
38 #include <drawingml/textbodycontext.hxx>
39 #include <drawingml/transform2dcontext.hxx>
40 #include <oox/token/namespaces.hxx>
41 #include <oox/token/properties.hxx>
42 #include <oox/token/tokens.hxx>
44 using namespace oox::core
;
45 using namespace ::com::sun::star
;
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::drawing
;
48 using namespace ::com::sun::star::beans
;
49 using namespace ::com::sun::star::text
;
50 using namespace ::com::sun::star::xml::sax
;
52 namespace oox
{ namespace ppt
{
55 PPTShapeContext::PPTShapeContext( ContextHandler2Helper
const & rParent
, const SlidePersistPtr
& rSlidePersistPtr
, const oox::drawingml::ShapePtr
& pMasterShapePtr
, const oox::drawingml::ShapePtr
& pShapePtr
)
56 : oox::drawingml::ShapeContext( rParent
, pMasterShapePtr
, pShapePtr
)
57 , mpSlidePersistPtr( rSlidePersistPtr
)
61 ContextHandlerRef
PPTShapeContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
63 if( getNamespace( aElementToken
) == NMSP_dsp
)
64 aElementToken
= NMSP_ppt
| getBaseToken( aElementToken
);
66 switch( aElementToken
)
68 // nvSpPr CT_ShapeNonVisual begin
69 // case PPT_TOKEN( drElemPr ):
71 case PPT_TOKEN( cNvPr
):
73 mpShapePtr
->setHidden( rAttribs
.getBool( XML_hidden
, false ) );
74 mpShapePtr
->setId( rAttribs
.getString( XML_id
).get() );
75 mpShapePtr
->setName( rAttribs
.getString( XML_name
).get() );
80 sal_Int32
nSubType( rAttribs
.getToken( XML_type
, XML_obj
) );
81 mpShapePtr
->setSubType( nSubType
);
82 if( rAttribs
.hasAttribute( XML_idx
) )
83 mpShapePtr
->setSubTypeIndex( rAttribs
.getString( XML_idx
).get().toInt32() );
86 PPTShape
* pPPTShapePtr
= dynamic_cast< PPTShape
* >( mpShapePtr
.get() );
89 oox::ppt::ShapeLocation eShapeLocation
= pPPTShapePtr
->getShapeLocation();
90 if ( ( eShapeLocation
== Slide
) || ( eShapeLocation
== Layout
) )
92 // inheriting properties from placeholder objects by cloning shape
93 sal_Int32 nFirstPlaceholder
= 0;
94 sal_Int32 nSecondPlaceholder
= 0;
97 case XML_ctrTitle
: // slide/layout
98 nFirstPlaceholder
= XML_ctrTitle
;
99 nSecondPlaceholder
= XML_title
;
102 case XML_subTitle
: // slide/layout
103 nFirstPlaceholder
= XML_subTitle
;
104 nSecondPlaceholder
= XML_body
;
107 case XML_obj
: // slide/layout
108 nFirstPlaceholder
= XML_obj
;
109 nSecondPlaceholder
= XML_body
;
112 case XML_dt
: // slide/layout/master/notes/notesmaster/handoutmaster
113 case XML_sldNum
: // slide/layout/master/notes/notesmaster/handoutmaster
114 case XML_ftr
: // slide/layout/master/notes/notesmaster/handoutmaster
115 case XML_hdr
: // notes/notesmaster/handoutmaster
116 case XML_body
: // slide/layout/master/notes/notesmaster
117 case XML_title
: // slide/layout/master/
118 case XML_chart
: // slide/layout
119 case XML_tbl
: // slide/layout
120 case XML_clipArt
: // slide/layout
121 case XML_dgm
: // slide/layout
122 case XML_media
: // slide/layout
123 case XML_sldImg
: // notes/notesmaster
124 case XML_pic
: // slide/layout
125 nFirstPlaceholder
= nSubType
;
130 if ( nFirstPlaceholder
)
132 oox::drawingml::ShapePtr pPlaceholder
;
133 if ( eShapeLocation
== Layout
) // for layout objects the referenced object can be found within the same shape tree
135 pPlaceholder
= PPTShape::findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
,
136 pPPTShapePtr
->getSubTypeIndex(), mpSlidePersistPtr
->getShapes()->getChildren(), true );
138 else if ( eShapeLocation
== Slide
) // normal slide shapes have to search within the corresponding master tree for referenced objects
140 SlidePersistPtr
pMasterPersist( mpSlidePersistPtr
->getMasterPersist() );
141 if ( pMasterPersist
.get() )
143 pPlaceholder
= PPTShape::findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
,
144 pPPTShapePtr
->getSubTypeIndex(), pMasterPersist
->getShapes()->getChildren() );
147 if ( pPlaceholder
.get() )
149 SAL_INFO("oox.ppt","shape " << mpShapePtr
->getId() <<
150 " will get shape reference " << pPlaceholder
->getId() << " applied");
151 mpShapePtr
->applyShapeReference( *pPlaceholder
);
152 PPTShape
* pPPTShape
= dynamic_cast< PPTShape
* >( pPlaceholder
.get() );
154 pPPTShape
->setReferenced( true );
155 pPPTShapePtr
->setPlaceholder( pPlaceholder
);
165 // nvSpPr CT_ShapeNonVisual end
167 case PPT_TOKEN( spPr
):
168 return new PPTShapePropertiesContext( *this, *mpShapePtr
);
170 case PPT_TOKEN( style
):
171 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr
);
173 case PPT_TOKEN( txBody
):
175 oox::drawingml::TextBodyPtr
xTextBody( new oox::drawingml::TextBody( mpShapePtr
->getTextBody() ) );
176 xTextBody
->getTextProperties().maPropertyMap
.setProperty( PROP_FontIndependentLineSpacing
, true );
177 mpShapePtr
->setTextBody( xTextBody
);
178 return new oox::drawingml::TextBodyContext( *this, mpShapePtr
);
180 case PPT_TOKEN( txXfrm
):
182 return new oox::drawingml::Transform2DContext( *this, rAttribs
, *mpShapePtr
, true );
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */