xref: /trunk/main/oox/source/drawingml/table/tablecontext.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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 #include "oox/helper/attributelist.hxx"
26 #include "oox/drawingml/guidcontext.hxx"
27 #include "oox/drawingml/table/tablecontext.hxx"
28 #include "oox/drawingml/table/tableproperties.hxx"
29 #include "oox/drawingml/table/tablestylecontext.hxx"
30 #include "oox/drawingml/table/tablerowcontext.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 
38 TableContext::TableContext( ContextHandler& rParent, ShapePtr pShapePtr )
39 : ShapeContext( rParent, ShapePtr(), pShapePtr )
40 , mrTableProperties( *pShapePtr->getTableProperties().get() )
41 {
42     pShapePtr->setTableType();
43 }
44 
45 TableContext::~TableContext()
46 {
47 }
48 
49 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
50 TableContext::createFastChildContext( ::sal_Int32 aElementToken, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs )
51 {
52     uno::Reference< xml::sax::XFastContextHandler > xRet;
53 
54     switch( aElementToken )
55     {
56     case A_TOKEN( tblPr ):              // CT_TableProperties
57         {
58             AttributeList aAttribs( xAttribs );
59             mrTableProperties.isRtl() = aAttribs.getBool( XML_rtl, sal_False );
60             mrTableProperties.isFirstRow() = aAttribs.getBool( XML_firstRow, sal_False );
61             mrTableProperties.isFirstCol() = aAttribs.getBool( XML_firstCol, sal_False );
62             mrTableProperties.isLastRow() = aAttribs.getBool( XML_lastRow, sal_False );
63             mrTableProperties.isLastCol() = aAttribs.getBool( XML_lastCol, sal_False );
64             mrTableProperties.isBandRow() = aAttribs.getBool( XML_bandRow, sal_False );
65             mrTableProperties.isBandCol() = aAttribs.getBool( XML_bandCol, sal_False );
66         }
67         break;
68     case A_TOKEN( tableStyle ):         // CT_TableStyle
69         {
70             boost::shared_ptr< TableStyle >& rTableStyle = mrTableProperties.getTableStyle();
71             rTableStyle.reset( new TableStyle() );
72             xRet = new TableStyleContext( *this, xAttribs, *rTableStyle );
73         }
74         break;
75     case A_TOKEN( tableStyleId ):       // ST_Guid
76         xRet.set( new oox::drawingml::GuidContext( *this, mrTableProperties.getStyleId() ) );
77         break;
78 
79     case A_TOKEN( tblGrid ):            // CT_TableGrid
80         break;
81     case A_TOKEN( gridCol ):            // CT_TableCol
82         {
83             std::vector< sal_Int32 >& rvTableGrid( mrTableProperties.getTableGrid() );
84             rvTableGrid.push_back( xAttribs->getOptionalValue( XML_w ).toInt32() );
85         }
86         break;
87     case A_TOKEN( tr ):                 // CT_TableRow
88         {
89             std::vector< TableRow >& rvTableRows( mrTableProperties.getTableRows() );
90             rvTableRows.resize( rvTableRows.size() + 1 );
91             xRet.set( new TableRowContext( *this, xAttribs, rvTableRows.back() ) );
92         }
93         break;
94     }
95 
96     if( !xRet.is() )
97         xRet.set( this );
98 
99     return xRet;
100 }
101 
102 } } }
103