1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <osl/diagnose.h>
29 
30 #include "oox/drawingml/table/tablecellcontext.hxx"
31 #include "oox/drawingml/textbodycontext.hxx"
32 #include "oox/drawingml/linepropertiescontext.hxx"
33 #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
34 #include "oox/helper/attributelist.hxx"
35 
36 using namespace ::oox::core;
37 using namespace ::com::sun::star;
38 using ::rtl::OUString;
39 
40 namespace oox { namespace drawingml { namespace table {
41 
42 TableCellContext::TableCellContext( ContextHandler& rParent, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs, TableCell& rTableCell )
43 : ContextHandler( rParent )
44 , mrTableCell( rTableCell )
45 {
46 	if ( xAttribs->hasAttribute( XML_rowSpan ) )
47 		mrTableCell.setRowSpan( xAttribs->getOptionalValue( XML_rowSpan ).toInt32() );
48 	if ( xAttribs->hasAttribute( XML_gridSpan ) )
49 		mrTableCell.setGridSpan( xAttribs->getOptionalValue( XML_gridSpan ).toInt32() );
50 
51 	AttributeList aAttribs( xAttribs );
52 	mrTableCell.sethMerge( aAttribs.getBool( XML_hMerge, sal_False ) );
53 	mrTableCell.setvMerge( aAttribs.getBool( XML_vMerge, sal_False ) );
54 }
55 
56 TableCellContext::~TableCellContext()
57 {
58 }
59 
60 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
61 TableCellContext::createFastChildContext( ::sal_Int32 aElementToken, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs )
62 	throw ( xml::sax::SAXException, uno::RuntimeException)
63 {
64 	uno::Reference< xml::sax::XFastContextHandler > xRet;
65 
66 	switch( aElementToken )
67 	{
68 	case A_TOKEN( txBody ):		// CT_TextBody
69 		{
70 	        oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody );
71 		    mrTableCell.setTextBody( xTextBody );
72 			xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody );
73 		}
74 		break;
75 
76 	case A_TOKEN( tcPr ):		// CT_TableCellProperties
77 		{
78 			AttributeList aAttribs( xAttribs );
79 			mrTableCell.setLeftMargin( aAttribs.getInteger( XML_marL, 91440 ) );
80 			mrTableCell.setRightMargin( aAttribs.getInteger( XML_marR, 91440 ) );
81 			mrTableCell.setTopMargin( aAttribs.getInteger( XML_marT, 45720 ) );
82 			mrTableCell.setBottomMargin( aAttribs.getInteger( XML_marB, 45720 ) );
83 			mrTableCell.setVertToken( xAttribs->getOptionalValueToken( XML_vert, XML_horz ) );					// ST_TextVerticalType
84 			mrTableCell.setAnchorToken( xAttribs->getOptionalValueToken( XML_anchor, XML_t ) );					// ST_TextAnchoringType
85 			mrTableCell.setAnchorCtr( aAttribs.getBool( XML_anchorCtr, sal_False ) );
86 			mrTableCell.setHorzOverflowToken( xAttribs->getOptionalValueToken( XML_horzOverflow, XML_clip ) );	// ST_TextHorzOverflowType
87 		}
88 		break;
89 		case A_TOKEN( lnL ):
90 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesLeft ) );
91 			break;
92 		case A_TOKEN( lnR ):
93 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesRight ) );
94 			break;
95 		case A_TOKEN( lnT ):
96 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesTop ) );
97 			break;
98 		case A_TOKEN( lnB ):
99 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesBottom ) );
100 			break;
101 		case A_TOKEN( lnTlToBr ):
102 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesTopLeftToBottomRight ) );
103 			break;
104 		case A_TOKEN( lnBlToTr ):
105 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesBottomLeftToTopRight ) );
106 			break;
107 		case A_TOKEN( cell3D ):	// CT_Cell3D
108 		break;
109 
110 	case A_TOKEN( extLst ):		// CT_OfficeArtExtensionList
111 	break;
112 
113 	default:
114         xRet.set( FillPropertiesContext::createFillContext( *this, aElementToken, xAttribs, mrTableCell.maFillProperties ) );
115 	break;
116 
117 	}
118 	if ( !xRet.is() )
119 	{
120         uno::Reference< XFastContextHandler > xTmp( this );
121 		xRet.set( xTmp );
122 	}
123 	return xRet;
124 }
125 
126 } } }
127