1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <com/sun/star/xml/sax/FastToken.hpp>
25 #include <com/sun/star/drawing/LineStyle.hpp>
26 #include <com/sun/star/beans/XMultiPropertySet.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/container/XNamed.hpp>
29 
30 #include "oox/helper/attributelist.hxx"
31 #include "oox/drawingml/shapecontext.hxx"
32 #include "oox/drawingml/shapestylecontext.hxx"
33 #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
34 #include "oox/drawingml/lineproperties.hxx"
35 #include "oox/drawingml/drawingmltypes.hxx"
36 #include "oox/drawingml/customshapegeometry.hxx"
37 #include "oox/drawingml/textbodycontext.hxx"
38 
39 using rtl::OUString;
40 using namespace oox::core;
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::drawing;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::text;
46 using namespace ::com::sun::star::xml::sax;
47 
48 namespace oox { namespace drawingml {
49 
50 // CT_Shape
ShapeContext(ContextHandler & rParent,ShapePtr pMasterShapePtr,ShapePtr pShapePtr)51 ShapeContext::ShapeContext( ContextHandler& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr )
52 : ContextHandler( rParent )
53 , mpMasterShapePtr( pMasterShapePtr )
54 , mpShapePtr( pShapePtr )
55 {
56 }
57 
~ShapeContext()58 ShapeContext::~ShapeContext()
59 {
60 	if ( mpMasterShapePtr.get() && mpShapePtr.get() )
61 		mpMasterShapePtr->addChild( mpShapePtr );
62 }
63 
getShape()64 ShapePtr ShapeContext::getShape()
65 {
66 	return mpShapePtr;
67 }
68 
endFastElement(sal_Int32)69 void ShapeContext::endFastElement( sal_Int32 /* aElementToken */ ) throw( SAXException, RuntimeException )
70 {
71 }
72 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)73 Reference< XFastContextHandler > ShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
74 {
75 	Reference< XFastContextHandler > xRet;
76 
77     switch( getBaseToken( aElementToken ) )
78 	{
79 	// nvSpPr CT_ShapeNonVisual begin
80 //	case XML_drElemPr:
81 //		break;
82 	case XML_cNvPr:
83 	{
84 		AttributeList aAttribs( xAttribs );
85 		mpShapePtr->setHidden( aAttribs.getBool( XML_hidden, false ) );
86 		mpShapePtr->setId( xAttribs->getOptionalValue( XML_id ) );
87 		mpShapePtr->setName( xAttribs->getOptionalValue( XML_name ) );
88 		break;
89 	}
90 	case XML_ph:
91 		mpShapePtr->setSubType( xAttribs->getOptionalValueToken( XML_type, XML_obj ) );
92 		mpShapePtr->setSubTypeIndex( xAttribs->getOptionalValue( XML_idx ).toInt32() );
93 		break;
94 	// nvSpPr CT_ShapeNonVisual end
95 
96 	case XML_spPr:
97         xRet = new ShapePropertiesContext( *this, *mpShapePtr );
98 		break;
99 
100 	case XML_style:
101         xRet = new ShapeStyleContext( *this, *mpShapePtr );
102 		break;
103 
104 	case XML_txBody:
105 	{
106         TextBodyPtr xTextBody( new TextBody );
107         mpShapePtr->setTextBody( xTextBody );
108         xRet = new TextBodyContext( *this, *xTextBody );
109 		break;
110 	}
111 	}
112 
113 	if( !xRet.is() )
114     {
115         uno::Reference<XFastContextHandler> xTmp(this);
116 		xRet.set( xTmp );
117     }
118 
119 	return xRet;
120 }
121 
122 
123 } }
124