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 "oox/drawingml/shapestylecontext.hxx"
31 #include "oox/token/namespaces.hxx"
32 #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
33 #include "oox/drawingml/lineproperties.hxx"
34 #include "oox/drawingml/drawingmltypes.hxx"
35 #include "oox/drawingml/customshapegeometry.hxx"
36 #include "oox/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( ContextHandler
& rParent
, const SlidePersistPtr pSlidePersistPtr
, oox::drawingml::ShapePtr pMasterShapePtr
, oox::drawingml::ShapePtr pShapePtr
)
51 : oox::drawingml::GraphicShapeContext( rParent
, pMasterShapePtr
, pShapePtr
)
52 , mpSlidePersistPtr( pSlidePersistPtr
)
56 // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
57 static oox::drawingml::ShapePtr
findPlaceholder( sal_Int32 nFirstPlaceholder
, sal_Int32 nSecondPlaceholder
, std::vector
< oox::drawingml::ShapePtr
>& rShapes
)
59 oox::drawingml::ShapePtr pPlaceholder
= PPTShape::findPlaceholder( nFirstPlaceholder
, rShapes
);
60 return !nSecondPlaceholder
|| pPlaceholder
.get() ? pPlaceholder
: PPTShape::findPlaceholder( nSecondPlaceholder
, rShapes
);
63 Reference
< XFastContextHandler
> PPTGraphicShapeContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
65 Reference
< XFastContextHandler
> xRet
;
67 switch( aElementToken
)
69 // nvSpPr CT_ShapeNonVisual begin
70 // case NMSP_PPT|XML_drElemPr:
72 case PPT_TOKEN(cNvPr
):
73 mpShapePtr
->setId( xAttribs
->getOptionalValue( XML_id
) );
74 mpShapePtr
->setName( xAttribs
->getOptionalValue( XML_name
) );
78 sal_Int32
nSubType( xAttribs
->getOptionalValueToken( XML_type
, XML_obj
) );
79 mpShapePtr
->setSubType( nSubType
);
80 OUString
sIdx( xAttribs
->getOptionalValue( XML_idx
) );
81 sal_Bool bHasIdx
= !sIdx
.isEmpty();
82 sal_Int32 nIdx
= sIdx
.toInt32();
83 if( xAttribs
->hasAttribute( XML_idx
) )
84 mpShapePtr
->setSubTypeIndex( nIdx
);
86 if ( nSubType
|| bHasIdx
)
88 PPTShape
* pPPTShapePtr
= dynamic_cast< PPTShape
* >( mpShapePtr
.get() );
91 oox::ppt::ShapeLocation eShapeLocation
= pPPTShapePtr
->getShapeLocation();
92 oox::drawingml::ShapePtr pPlaceholder
;
94 if ( bHasIdx
&& eShapeLocation
== Slide
)
96 // TODO: use id to shape map
97 SlidePersistPtr
pMasterPersist( mpSlidePersistPtr
->getMasterPersist() );
98 if ( pMasterPersist
.get() && xAttribs
->hasAttribute( XML_idx
) )
99 pPlaceholder
= PPTShape::findPlaceholderByIndex( nIdx
, pMasterPersist
->getShapes()->getChildren() );
101 if ( !pPlaceholder
.get() && ( ( eShapeLocation
== Slide
) || ( eShapeLocation
== Layout
) ) )
103 // inheriting properties from placeholder objects by cloning shape
105 sal_Int32 nFirstPlaceholder
= 0;
106 sal_Int32 nSecondPlaceholder
= 0;
109 case XML_ctrTitle
: // slide/layout
110 nFirstPlaceholder
= XML_ctrTitle
;
111 nSecondPlaceholder
= XML_title
;
113 case XML_subTitle
: // slide/layout
114 nFirstPlaceholder
= XML_subTitle
;
115 nSecondPlaceholder
= XML_title
;
117 case XML_obj
: // slide/layout
118 nFirstPlaceholder
= XML_body
;
120 case XML_dt
: // slide/layout/master/notes/notesmaster/handoutmaster
121 case XML_sldNum
: // slide/layout/master/notes/notesmaster/handoutmaster
122 case XML_ftr
: // slide/layout/master/notes/notesmaster/handoutmaster
123 case XML_hdr
: // notes/notesmaster/handoutmaster
124 case XML_body
: // slide/layout/master/notes/notesmaster
125 case XML_title
: // slide/layout/master/
126 case XML_chart
: // slide/layout
127 case XML_tbl
: // slide/layout
128 case XML_clipArt
: // slide/layout
129 case XML_dgm
: // slide/layout
130 case XML_media
: // slide/layout
131 case XML_sldImg
: // notes/notesmaster
132 case XML_pic
: // slide/layout
133 nFirstPlaceholder
= nSubType
;
137 if ( nFirstPlaceholder
)
139 if ( eShapeLocation
== Layout
) // for layout objects the referenced object can be found within the same shape tree
140 pPlaceholder
= findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
, mpSlidePersistPtr
->getShapes()->getChildren() );
141 else if ( eShapeLocation
== Slide
) // normal slide shapes have to search within the corresponding master tree for referenced objects
143 SlidePersistPtr
pMasterPersist( mpSlidePersistPtr
->getMasterPersist() );
144 if ( pMasterPersist
.get() )
145 pPlaceholder
= findPlaceholder( nFirstPlaceholder
, nSecondPlaceholder
, pMasterPersist
->getShapes()->getChildren() );
149 if ( pPlaceholder
.get() )
151 bool bUseText
= true;
152 switch( pPlaceholder
->getSubType() )
172 mpShapePtr
->applyShapeReference( *pPlaceholder
.get(), bUseText
);
173 PPTShape
* pPPTShape
= dynamic_cast< PPTShape
* >( pPlaceholder
.get() );
175 pPPTShape
->setReferenced( sal_True
);
176 pPPTShapePtr
->setPlaceholder( pPlaceholder
);
182 // nvSpPr CT_ShapeNonVisual end
184 case PPT_TOKEN(spPr
):
185 xRet
= new PPTShapePropertiesContext( *this, *mpShapePtr
);
188 case PPT_TOKEN(style
):
189 xRet
= new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr
);
192 case PPT_TOKEN(txBody
):
194 oox::drawingml::TextBodyPtr
xTextBody( new oox::drawingml::TextBody
);
195 mpShapePtr
->setTextBody( xTextBody
);
196 xRet
= new oox::drawingml::TextBodyContext( *this, *xTextBody
);
202 xRet
.set( GraphicShapeContext::createFastChildContext( aElementToken
, xAttribs
) );
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */