xref: /trunk/main/oox/source/drawingml/table/tablecellcontext.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
59     uno::Reference< xml::sax::XFastContextHandler > xRet;
60 
61     switch( aElementToken )
62     {
63     case A_TOKEN( txBody ):     // CT_TextBody
64         {
65             oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody );
66             mrTableCell.setTextBody( xTextBody );
67             xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody );
68         }
69         break;
70 
71     case A_TOKEN( tcPr ):       // CT_TableCellProperties
72         {
73             AttributeList aAttribs( xAttribs );
74             mrTableCell.setLeftMargin( aAttribs.getInteger( XML_marL, 91440 ) );
75             mrTableCell.setRightMargin( aAttribs.getInteger( XML_marR, 91440 ) );
76             mrTableCell.setTopMargin( aAttribs.getInteger( XML_marT, 45720 ) );
77             mrTableCell.setBottomMargin( aAttribs.getInteger( XML_marB, 45720 ) );
78             mrTableCell.setVertToken( xAttribs->getOptionalValueToken( XML_vert, XML_horz ) );                  // ST_TextVerticalType
79             mrTableCell.setAnchorToken( xAttribs->getOptionalValueToken( XML_anchor, XML_t ) );                 // ST_TextAnchoringType
80             mrTableCell.setAnchorCtr( aAttribs.getBool( XML_anchorCtr, sal_False ) );
81             mrTableCell.setHorzOverflowToken( xAttribs->getOptionalValueToken( XML_horzOverflow, XML_clip ) );  // ST_TextHorzOverflowType
82         }
83         break;
84         case A_TOKEN( lnL ):
85                 xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesLeft ) );
86             break;
87         case A_TOKEN( lnR ):
88                 xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesRight ) );
89             break;
90         case A_TOKEN( lnT ):
91                 xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesTop ) );
92             break;
93         case A_TOKEN( lnB ):
94                 xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesBottom ) );
95             break;
96         case A_TOKEN( lnTlToBr ):
97                 xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesTopLeftToBottomRight ) );
98             break;
99         case A_TOKEN( lnBlToTr ):
100                 xRet.set( new oox::drawingml::LinePropertiesContext( *this, xAttribs, mrTableCell.maLinePropertiesBottomLeftToTopRight ) );
101             break;
102         case A_TOKEN( cell3D ): // CT_Cell3D
103         break;
104 
105     case A_TOKEN( extLst ):     // CT_OfficeArtExtensionList
106     break;
107 
108     default:
109         xRet.set( FillPropertiesContext::createFillContext( *this, aElementToken, xAttribs, mrTableCell.maFillProperties ) );
110     break;
111 
112     }
113     if ( !xRet.is() )
114     {
115         uno::Reference< XFastContextHandler > xTmp( this );
116         xRet.set( xTmp );
117     }
118     return xRet;
119 }
120 
121 } } }
122