1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/drawingml/diagram/datamodelcontext.hxx"
25cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
26cdf0e10cSrcweir #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
27cdf0e10cSrcweir #include "oox/drawingml/shapepropertiescontext.hxx"
28cdf0e10cSrcweir #include "oox/drawingml/textbodycontext.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace ::oox::core;
31cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
32cdf0e10cSrcweir using namespace ::com::sun::star::uno;
33cdf0e10cSrcweir using ::rtl::OUString;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace oox { namespace drawingml {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // CL_Cxn
38cdf0e10cSrcweir class CxnContext
39cdf0e10cSrcweir     : public ContextHandler
40cdf0e10cSrcweir {
41cdf0e10cSrcweir public:
CxnContext(ContextHandler & rParent,const Reference<XFastAttributeList> & xAttribs,const dgm::ConnectionPtr & pConnection)42cdf0e10cSrcweir     CxnContext( ContextHandler& rParent,
43cdf0e10cSrcweir 				const Reference< XFastAttributeList >& xAttribs,
44cdf0e10cSrcweir 				const dgm::ConnectionPtr & pConnection )
45cdf0e10cSrcweir         : ContextHandler( rParent )
46cdf0e10cSrcweir 		, mpConnection( pConnection )
47cdf0e10cSrcweir 		{
48cdf0e10cSrcweir 			sal_Int32 nType = xAttribs->getOptionalValueToken( XML_type, XML_parOf );
49cdf0e10cSrcweir 			pConnection->mnType = nType;
50cdf0e10cSrcweir 			pConnection->msModelId = xAttribs->getOptionalValue( XML_modelId );
51cdf0e10cSrcweir 			pConnection->msSourceId = xAttribs->getOptionalValue( XML_srcId );
52cdf0e10cSrcweir 			pConnection->msDestId  = xAttribs->getOptionalValue( XML_destId );
53cdf0e10cSrcweir 			pConnection->msPresId  = xAttribs->getOptionalValue( XML_presId );
54cdf0e10cSrcweir 			pConnection->msSibTransId  = xAttribs->getOptionalValue( XML_sibTransId );
55cdf0e10cSrcweir 			AttributeList attribs( xAttribs );
56cdf0e10cSrcweir 			pConnection->mnSourceOrder = attribs.getInteger( XML_srcOrd, 0 );
57cdf0e10cSrcweir 			pConnection->mnDestOrder = attribs.getInteger( XML_destOrd, 0 );
58cdf0e10cSrcweir 		}
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     virtual Reference< XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> &)61cdf0e10cSrcweir 	createFastChildContext( sal_Int32 aElementToken,
62cdf0e10cSrcweir 							const Reference< XFastAttributeList >& /*xAttribs*/ )
63cdf0e10cSrcweir 		throw (SAXException, RuntimeException)
64cdf0e10cSrcweir 		{
65cdf0e10cSrcweir 			Reference< XFastContextHandler > xRet;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 			switch( aElementToken )
68cdf0e10cSrcweir 			{
69cdf0e10cSrcweir 			case DGM_TOKEN( extLst ):
70cdf0e10cSrcweir                 return xRet;
71cdf0e10cSrcweir 			default:
72cdf0e10cSrcweir 				break;
73cdf0e10cSrcweir 			}
74cdf0e10cSrcweir 			if( !xRet.is() )
75cdf0e10cSrcweir 				xRet.set( this );
76cdf0e10cSrcweir 			return xRet;
77cdf0e10cSrcweir 		}
78cdf0e10cSrcweir private:
79cdf0e10cSrcweir 	dgm::ConnectionPtr mpConnection;
80cdf0e10cSrcweir };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
83cdf0e10cSrcweir // CT_CxnList
84cdf0e10cSrcweir class CxnListContext
85cdf0e10cSrcweir     : public ContextHandler
86cdf0e10cSrcweir {
87cdf0e10cSrcweir public:
CxnListContext(ContextHandler & rParent,dgm::Connections & aConnections)88cdf0e10cSrcweir     CxnListContext( ContextHandler& rParent,  dgm::Connections & aConnections )
89cdf0e10cSrcweir         : ContextHandler( rParent )
90cdf0e10cSrcweir 		, maConnections( aConnections )
91cdf0e10cSrcweir 		{
92cdf0e10cSrcweir 		}
93cdf0e10cSrcweir     virtual Reference< XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)94cdf0e10cSrcweir 	createFastChildContext( sal_Int32 aElementToken,
95cdf0e10cSrcweir 							const Reference< XFastAttributeList >& xAttribs )
96cdf0e10cSrcweir 		throw (SAXException, RuntimeException)
97cdf0e10cSrcweir 		{
98cdf0e10cSrcweir 			Reference< XFastContextHandler > xRet;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 			switch( aElementToken )
101cdf0e10cSrcweir 			{
102cdf0e10cSrcweir 			case DGM_TOKEN( cxn ):
103cdf0e10cSrcweir 			{
104cdf0e10cSrcweir 				dgm::ConnectionPtr pConnection( new dgm::Connection() );
105cdf0e10cSrcweir 				maConnections.push_back( pConnection );
106cdf0e10cSrcweir                 xRet.set( new CxnContext( *this, xAttribs, pConnection ) );
107cdf0e10cSrcweir 				break;
108cdf0e10cSrcweir 			}
109cdf0e10cSrcweir 			default:
110cdf0e10cSrcweir 				break;
111cdf0e10cSrcweir 			}
112cdf0e10cSrcweir 			if( !xRet.is() )
113cdf0e10cSrcweir 				xRet.set( this );
114cdf0e10cSrcweir 			return xRet;
115cdf0e10cSrcweir 		}
116cdf0e10cSrcweir 
117cdf0e10cSrcweir private:
118cdf0e10cSrcweir 	dgm::Connections  & maConnections;
119cdf0e10cSrcweir };
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir // CL_Pt
124cdf0e10cSrcweir class PtContext
125cdf0e10cSrcweir     : public ContextHandler
126cdf0e10cSrcweir {
127cdf0e10cSrcweir public:
PtContext(ContextHandler & rParent,const Reference<XFastAttributeList> & xAttribs,const dgm::PointPtr & pPoint)128cdf0e10cSrcweir     PtContext( ContextHandler& rParent,
129cdf0e10cSrcweir 			   const Reference< XFastAttributeList >& xAttribs,
130cdf0e10cSrcweir 			   const dgm::PointPtr & pPoint)
131cdf0e10cSrcweir         : ContextHandler( rParent )
132cdf0e10cSrcweir 		, mpPoint( pPoint )
133cdf0e10cSrcweir 		{
134cdf0e10cSrcweir 			mpPoint->setModelId( xAttribs->getOptionalValue( XML_modelId ) );
135cdf0e10cSrcweir 			//
136cdf0e10cSrcweir 			// the default type is XML_node
137cdf0e10cSrcweir 			sal_Int32 nType  = xAttribs->getOptionalValueToken( XML_type, XML_node );
138cdf0e10cSrcweir 			mpPoint->setType( nType );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 			// ignore the cxnId unless it is this type. See 5.15.3.1.3 in Primer
141cdf0e10cSrcweir 			if( ( nType == XML_parTrans ) || ( nType == XML_sibTrans ) )
142cdf0e10cSrcweir 			{
143cdf0e10cSrcweir 				mpPoint->setCnxId( xAttribs->getOptionalValue( XML_cxnId ) );
144cdf0e10cSrcweir 			}
145cdf0e10cSrcweir 		}
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     virtual Reference< XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> &)149cdf0e10cSrcweir 	createFastChildContext( sal_Int32 aElementToken,
150cdf0e10cSrcweir 							const Reference< XFastAttributeList >& /*xAttribs*/ )
151cdf0e10cSrcweir 		throw (SAXException, RuntimeException)
152cdf0e10cSrcweir 		{
153cdf0e10cSrcweir 			Reference< XFastContextHandler > xRet;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 			switch( aElementToken )
156cdf0e10cSrcweir 			{
157cdf0e10cSrcweir 			case DGM_TOKEN( extLst ):
158cdf0e10cSrcweir                 return xRet;
159cdf0e10cSrcweir 			case DGM_TOKEN( prSet ):
160cdf0e10cSrcweir 				// TODO
161cdf0e10cSrcweir 				// CT_ElemPropSet
162cdf0e10cSrcweir 				break;
163cdf0e10cSrcweir 			case DGM_TOKEN( spPr ):
164cdf0e10cSrcweir 				OSL_TRACE( "shape props for point");
165cdf0e10cSrcweir                 xRet = new ShapePropertiesContext( *this, *mpPoint->getShape() );
166cdf0e10cSrcweir 				break;
167cdf0e10cSrcweir 			case DGM_TOKEN( t ):
168cdf0e10cSrcweir 			{
169cdf0e10cSrcweir 				OSL_TRACE( "shape text body for point");
170cdf0e10cSrcweir                 TextBodyPtr xTextBody( new TextBody );
171cdf0e10cSrcweir                 mpPoint->getShape()->setTextBody( xTextBody );
172cdf0e10cSrcweir                 xRet = new TextBodyContext( *this, *xTextBody );
173cdf0e10cSrcweir 				break;
174cdf0e10cSrcweir 			}
175cdf0e10cSrcweir 			default:
176cdf0e10cSrcweir 				break;
177cdf0e10cSrcweir 			}
178cdf0e10cSrcweir 			if( !xRet.is() )
179cdf0e10cSrcweir 				xRet.set( this );
180cdf0e10cSrcweir 			return xRet;
181cdf0e10cSrcweir 		}
182cdf0e10cSrcweir 
183cdf0e10cSrcweir private:
184cdf0e10cSrcweir 	dgm::PointPtr mpPoint;
185cdf0e10cSrcweir };
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 
189cdf0e10cSrcweir // CT_PtList
190cdf0e10cSrcweir class PtListContext
191cdf0e10cSrcweir     : public ContextHandler
192cdf0e10cSrcweir {
193cdf0e10cSrcweir public:
PtListContext(ContextHandler & rParent,dgm::Points & aPoints)194cdf0e10cSrcweir     PtListContext( ContextHandler& rParent,  dgm::Points & aPoints)
195cdf0e10cSrcweir         : ContextHandler( rParent )
196cdf0e10cSrcweir 		, maPoints( aPoints )
197cdf0e10cSrcweir 		{
198cdf0e10cSrcweir 		}
199cdf0e10cSrcweir     virtual Reference< XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)200cdf0e10cSrcweir 	createFastChildContext( sal_Int32 aElementToken,
201cdf0e10cSrcweir 							const Reference< XFastAttributeList >& xAttribs )
202cdf0e10cSrcweir 		throw (SAXException, RuntimeException)
203cdf0e10cSrcweir 		{
204cdf0e10cSrcweir 			Reference< XFastContextHandler > xRet;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 			switch( aElementToken )
207cdf0e10cSrcweir 			{
208cdf0e10cSrcweir 			case DGM_TOKEN( pt ):
209cdf0e10cSrcweir 			{
210cdf0e10cSrcweir 				// CT_Pt
211cdf0e10cSrcweir 				dgm::PointPtr pPoint( new dgm::Point() );
212cdf0e10cSrcweir 				maPoints.push_back( pPoint );
213cdf0e10cSrcweir                 xRet.set( new PtContext( *this, xAttribs, pPoint ) );
214cdf0e10cSrcweir 				break;
215cdf0e10cSrcweir 			}
216cdf0e10cSrcweir 			default:
217cdf0e10cSrcweir 				break;
218cdf0e10cSrcweir 			}
219cdf0e10cSrcweir 			if( !xRet.is() )
220cdf0e10cSrcweir 				xRet.set( this );
221cdf0e10cSrcweir 			return xRet;
222cdf0e10cSrcweir 		}
223cdf0e10cSrcweir 
224cdf0e10cSrcweir private:
225cdf0e10cSrcweir 	dgm::Points  & maPoints;
226cdf0e10cSrcweir };
227cdf0e10cSrcweir 
228cdf0e10cSrcweir // CT_BackgroundFormatting
229cdf0e10cSrcweir class BackgroundFormattingContext
230cdf0e10cSrcweir     : public ContextHandler
231cdf0e10cSrcweir {
232cdf0e10cSrcweir public:
BackgroundFormattingContext(ContextHandler & rParent,DiagramDataPtr & pModel)233cdf0e10cSrcweir     BackgroundFormattingContext( ContextHandler& rParent, DiagramDataPtr & pModel )
234cdf0e10cSrcweir         : ContextHandler( rParent )
235cdf0e10cSrcweir 		, mpDataModel( pModel )
236cdf0e10cSrcweir 		{
237cdf0e10cSrcweir 			OSL_ENSURE( pModel, "the data model MUST NOT be NULL" );
238cdf0e10cSrcweir 		}
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     virtual Reference< XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)241cdf0e10cSrcweir 	createFastChildContext( sal_Int32 aElementToken,
242cdf0e10cSrcweir 							const Reference< XFastAttributeList >& xAttribs )
243cdf0e10cSrcweir 		throw (SAXException, RuntimeException)
244cdf0e10cSrcweir 		{
245cdf0e10cSrcweir 			Reference< XFastContextHandler > xRet;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 			switch( aElementToken )
248cdf0e10cSrcweir 			{
249cdf0e10cSrcweir 			case A_TOKEN( blipFill ):
250cdf0e10cSrcweir 			case A_TOKEN( gradFill ):
251cdf0e10cSrcweir 			case A_TOKEN( grpFill ):
252cdf0e10cSrcweir 			case A_TOKEN( noFill ):
253cdf0e10cSrcweir 			case A_TOKEN( pattFill ):
254cdf0e10cSrcweir 			case A_TOKEN( solidFill ):
255cdf0e10cSrcweir 				// EG_FillProperties
256cdf0e10cSrcweir                 xRet.set( FillPropertiesContext::createFillContext(
257cdf0e10cSrcweir                     *this, aElementToken, xAttribs, *mpDataModel->getFillProperties() ) );
258cdf0e10cSrcweir 				break;
259cdf0e10cSrcweir 			case A_TOKEN( effectDag ):
260cdf0e10cSrcweir 			case A_TOKEN( effectLst ):
261cdf0e10cSrcweir 				// TODO
262cdf0e10cSrcweir 				// EG_EffectProperties
263cdf0e10cSrcweir 				break;
264cdf0e10cSrcweir 			default:
265cdf0e10cSrcweir 				break;
266cdf0e10cSrcweir 			}
267cdf0e10cSrcweir 			if( !xRet.is() )
268cdf0e10cSrcweir 				xRet.set( this );
269cdf0e10cSrcweir 			return xRet;
270cdf0e10cSrcweir 		}
271cdf0e10cSrcweir private:
272cdf0e10cSrcweir 	DiagramDataPtr mpDataModel;
273cdf0e10cSrcweir };
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 
DataModelContext(ContextHandler & rParent,const DiagramDataPtr & pDataModel)277cdf0e10cSrcweir DataModelContext::DataModelContext( ContextHandler& rParent,
278cdf0e10cSrcweir 									const DiagramDataPtr & pDataModel )
279cdf0e10cSrcweir     : ContextHandler( rParent )
280cdf0e10cSrcweir 	, mpDataModel( pDataModel )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir 	OSL_ENSURE( pDataModel, "Data Model must not be NULL" );
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 
~DataModelContext()286cdf0e10cSrcweir DataModelContext::~DataModelContext()
287cdf0e10cSrcweir {
288cdf0e10cSrcweir 	// some debug
289cdf0e10cSrcweir 	mpDataModel->dump();
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 
293cdf0e10cSrcweir Reference< XFastContextHandler > SAL_CALL
createFastChildContext(::sal_Int32 aElement,const Reference<XFastAttributeList> &)294cdf0e10cSrcweir DataModelContext::createFastChildContext( ::sal_Int32 aElement,
295cdf0e10cSrcweir 										  const Reference< XFastAttributeList >& /*xAttribs*/ )
296cdf0e10cSrcweir 	throw ( SAXException, RuntimeException)
297cdf0e10cSrcweir {
298cdf0e10cSrcweir 	Reference< XFastContextHandler > xRet;
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 	switch( aElement )
301cdf0e10cSrcweir 	{
302cdf0e10cSrcweir 	case DGM_TOKEN( cxnLst ):
303cdf0e10cSrcweir 		// CT_CxnList
304cdf0e10cSrcweir         xRet.set( new CxnListContext( *this, mpDataModel->getConnections() ) );
305cdf0e10cSrcweir 		break;
306cdf0e10cSrcweir 	case DGM_TOKEN( ptLst ):
307cdf0e10cSrcweir 		// CT_PtList
308cdf0e10cSrcweir         xRet.set( new PtListContext( *this, mpDataModel->getPoints() ) );
309cdf0e10cSrcweir 		break;
310cdf0e10cSrcweir 	case DGM_TOKEN( bg ):
311cdf0e10cSrcweir 		// CT_BackgroundFormatting
312cdf0e10cSrcweir         xRet.set( new BackgroundFormattingContext( *this, mpDataModel ) );
313cdf0e10cSrcweir 		break;
314cdf0e10cSrcweir 	case DGM_TOKEN( whole ):
315cdf0e10cSrcweir 		// CT_WholeE2oFormatting
316cdf0e10cSrcweir 		// TODO
317cdf0e10cSrcweir         return xRet;
318cdf0e10cSrcweir 	case DGM_TOKEN( extLst ):
319cdf0e10cSrcweir         return xRet;
320cdf0e10cSrcweir 	default:
321cdf0e10cSrcweir 		break;
322cdf0e10cSrcweir 	}
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 	if( !xRet.is() )
325cdf0e10cSrcweir 		xRet.set( this );
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 	return xRet;
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir } }
331