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/helper/attributelist.hxx"
27 #include "oox/ppt/pptshape.hxx"
28 #include "oox/ppt/pptshapecontext.hxx"
29 #include "oox/ppt/pptshapepropertiescontext.hxx"
30 #include "oox/ppt/slidepersist.hxx"
31 #include "drawingml/shapestylecontext.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 "drawingml/transform2dcontext.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 PPTShapeContext::PPTShapeContext( ContextHandler2Helper
& rParent
, const SlidePersistPtr
& rSlidePersistPtr
, oox::drawingml::ShapePtr pMasterShapePtr
, oox::drawingml::ShapePtr pShapePtr
)
51 : oox::drawingml::ShapeContext( rParent
, pMasterShapePtr
, pShapePtr
)
52 , mpSlidePersistPtr( rSlidePersistPtr
)
56 ContextHandlerRef
PPTShapeContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
58 if( getNamespace( aElementToken
) == NMSP_dsp
)
59 aElementToken
= NMSP_ppt
| getBaseToken( aElementToken
);
61 switch( aElementToken
)
63 // nvSpPr CT_ShapeNonVisual begin
64 // case PPT_TOKEN( drElemPr ):
66 case PPT_TOKEN( cNvPr
):
68 mpShapePtr
->setHidden( rAttribs
.getBool( XML_hidden
, false ) );
69 mpShapePtr
->setId( rAttribs
.getString( XML_id
).get() );
70 mpShapePtr
->setName( rAttribs
.getString( XML_name
).get() );
75 sal_Int32
nSubType( rAttribs
.getToken( XML_type
, XML_obj
) );
76 mpShapePtr
->setSubType( nSubType
);
77 if( rAttribs
.hasAttribute( XML_idx
) )
78 mpShapePtr
->setSubTypeIndex( rAttribs
.getString( XML_idx
).get().toInt32() );
81 PPTShape
* pPPTShapePtr
= dynamic_cast< PPTShape
* >( mpShapePtr
.get() );
84 oox::ppt::ShapeLocation eShapeLocation
= pPPTShapePtr
->getShapeLocation();
85 if ( ( eShapeLocation
== Slide
) || ( eShapeLocation
== Layout
) )
87 // inheriting properties from placeholder objects by cloning shape
88 sal_Int32 nFirstPlaceholder
= 0;
89 sal_Int32 nSecondPlaceholder
= 0;
92 case XML_ctrTitle
: // slide/layout
93 nFirstPlaceholder
= XML_ctrTitle
;
94 nSecondPlaceholder
= XML_title
;
97 case XML_subTitle
: // slide/layout
98 nFirstPlaceholder
= XML_subTitle
;
99 nSecondPlaceholder
= XML_body
;
102 case XML_obj
: // slide/layout
103 nFirstPlaceholder
= XML_obj
;
104 nSecondPlaceholder
= XML_body
;
107 case XML_dt
: // slide/layout/master/notes/notesmaster/handoutmaster
108 case XML_sldNum
: // slide/layout/master/notes/notesmaster/handoutmaster
109 case XML_ftr
: // slide/layout/master/notes/notesmaster/handoutmaster
110 case XML_hdr
: // notes/notesmaster/handoutmaster
111 case XML_body
: // slide/layout/master/notes/notesmaster
112 case XML_title
: // slide/layout/master/
113 case XML_chart
: // slide/layout
114 case XML_tbl
: // slide/layout
115 case XML_clipArt
: // slide/layout
116 case XML_dgm
: // slide/layout
117 case XML_media
: // slide/layout
118 case XML_sldImg
: // notes/notesmaster
119 case XML_pic
: // slide/layout
120 nFirstPlaceholder
= nSubType
;
124 if ( nFirstPlaceholder
)
126 oox::drawingml::ShapePtr pPlaceholder
;
127 if ( eShapeLocation
== Layout
) // for layout objects the referenced object can be found within the same shape tree
129 pPlaceholder
= PPTShape::findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
,
130 pPPTShapePtr
->getSubTypeIndex(), mpSlidePersistPtr
->getShapes()->getChildren(), true );
132 else if ( eShapeLocation
== Slide
) // normal slide shapes have to search within the corresponding master tree for referenced objects
134 SlidePersistPtr
pMasterPersist( mpSlidePersistPtr
->getMasterPersist() );
135 if ( pMasterPersist
.get() )
137 pPlaceholder
= PPTShape::findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
,
138 pPPTShapePtr
->getSubTypeIndex(), pMasterPersist
->getShapes()->getChildren() );
141 if ( pPlaceholder
.get() )
143 SAL_INFO("oox.ppt","shape " << mpShapePtr
->getId() <<
144 " will get shape reference " << pPlaceholder
->getId() << " applied");
145 mpShapePtr
->applyShapeReference( *pPlaceholder
.get() );
146 PPTShape
* pPPTShape
= dynamic_cast< PPTShape
* >( pPlaceholder
.get() );
148 pPPTShape
->setReferenced( true );
149 pPPTShapePtr
->setPlaceholder( pPlaceholder
);
159 // nvSpPr CT_ShapeNonVisual end
161 case PPT_TOKEN( spPr
):
162 return new PPTShapePropertiesContext( *this, *mpShapePtr
);
164 case PPT_TOKEN( style
):
165 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr
);
167 case PPT_TOKEN( txBody
):
169 oox::drawingml::TextBodyPtr
xTextBody( new oox::drawingml::TextBody( mpShapePtr
->getTextBody() ) );
170 xTextBody
->getTextProperties().maPropertyMap
.setProperty( PROP_FontIndependentLineSpacing
, true );
171 mpShapePtr
->setTextBody( xTextBody
);
172 return new oox::drawingml::TextBodyContext( *this, *xTextBody
);
174 case PPT_TOKEN( txXfrm
):
176 return new oox::drawingml::Transform2DContext( *this, rAttribs
, *mpShapePtr
, true );
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */