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 <osl/diagnose.h>
25 
26 #include "oox/drawingml/table/tablecellcontext.hxx"
27 #include "oox/drawingml/textbodycontext.hxx"
28 #include "oox/drawingml/linepropertiescontext.hxx"
29 #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
30 #include "oox/helper/attributelist.hxx"
31 
32 using namespace ::oox::core;
33 using namespace ::com::sun::star;
34 using ::rtl::OUString;
35 
36 namespace oox { namespace drawingml { namespace table {
37 
TableCellContext(ContextHandler & rParent,const uno::Reference<xml::sax::XFastAttributeList> & xAttribs,TableCell & rTableCell)38 TableCellContext::TableCellContext( ContextHandler& rParent, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs, TableCell& rTableCell )
39 : ContextHandler( rParent )
40 , mrTableCell( rTableCell )
41 {
42 	if ( xAttribs->hasAttribute( XML_rowSpan ) )
43 		mrTableCell.setRowSpan( xAttribs->getOptionalValue( XML_rowSpan ).toInt32() );
44 	if ( xAttribs->hasAttribute( XML_gridSpan ) )
45 		mrTableCell.setGridSpan( xAttribs->getOptionalValue( XML_gridSpan ).toInt32() );
46 
47 	AttributeList aAttribs( xAttribs );
48 	mrTableCell.sethMerge( aAttribs.getBool( XML_hMerge, sal_False ) );
49 	mrTableCell.setvMerge( aAttribs.getBool( XML_vMerge, sal_False ) );
50 }
51 
~TableCellContext()52 TableCellContext::~TableCellContext()
53 {
54 }
55 
56 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createFastChildContext(::sal_Int32 aElementToken,const uno::Reference<xml::sax::XFastAttributeList> & xAttribs)57 TableCellContext::createFastChildContext( ::sal_Int32 aElementToken, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs )
58 	throw ( xml::sax::SAXException, uno::RuntimeException)
59 {
60 	uno::Reference< xml::sax::XFastContextHandler > xRet;
61 
62 	switch( aElementToken )
63 	{
64 	case A_TOKEN( txBody ):		// CT_TextBody
65 		{
66 	        oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody );
67 		    mrTableCell.setTextBody( xTextBody );
68 			xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody );
69 		}
70 		break;
71 
72 	case A_TOKEN( tcPr ):		// CT_TableCellProperties
73 		{
74 			AttributeList aAttribs( xAttribs );
75 			mrTableCell.setLeftMargin( aAttribs.getInteger( XML_marL, 91440 ) );
76 			mrTableCell.setRightMargin( aAttribs.getInteger( XML_marR, 91440 ) );
77 			mrTableCell.setTopMargin( aAttribs.getInteger( XML_marT, 45720 ) );
78 			mrTableCell.setBottomMargin( aAttribs.getInteger( XML_marB, 45720 ) );
79 			mrTableCell.setVertToken( xAttribs->getOptionalValueToken( XML_vert, XML_horz ) );					// ST_TextVerticalType
80 			mrTableCell.setAnchorToken( xAttribs->getOptionalValueToken( XML_anchor, XML_t ) );					// ST_TextAnchoringType
81 			mrTableCell.setAnchorCtr( aAttribs.getBool( XML_anchorCtr, sal_False ) );
82 			mrTableCell.setHorzOverflowToken( xAttribs->getOptionalValueToken( XML_horzOverflow, XML_clip ) );	// ST_TextHorzOverflowType
83 		}
84 		break;
85 		case A_TOKEN( lnL ):
86 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesLeft ) );
87 			break;
88 		case A_TOKEN( lnR ):
89 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesRight ) );
90 			break;
91 		case A_TOKEN( lnT ):
92 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesTop ) );
93 			break;
94 		case A_TOKEN( lnB ):
95 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesBottom ) );
96 			break;
97 		case A_TOKEN( lnTlToBr ):
98 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesTopLeftToBottomRight ) );
99 			break;
100 		case A_TOKEN( lnBlToTr ):
101 				xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesBottomLeftToTopRight ) );
102 			break;
103 		case A_TOKEN( cell3D ):	// CT_Cell3D
104 		break;
105 
106 	case A_TOKEN( extLst ):		// CT_OfficeArtExtensionList
107 	break;
108 
109 	default:
110         xRet.set( FillPropertiesContext::createFillContext( *this, aElementToken, xAttribs, mrTableCell.maFillProperties ) );
111 	break;
112 
113 	}
114 	if ( !xRet.is() )
115 	{
116         uno::Reference< XFastContextHandler > xTmp( this );
117 		xRet.set( xTmp );
118 	}
119 	return xRet;
120 }
121 
122 } } }
123