merge the formfield patch from ooo-build
[ooovba.git] / writerfilter / source / dmapper / TablePropertiesHandler.cxx
blobe7bc423708d55ee7d34edd0a71068352c71d4b47
1 #include "BorderHandler.hxx"
2 #include "CellColorHandler.hxx"
3 #include "CellMarginHandler.hxx"
4 #include "ConversionHelper.hxx"
5 #include "MeasureHandler.hxx"
6 #include "TablePropertiesHandler.hxx"
7 #include "TDefTableHandler.hxx"
9 #include <ooxml/resourceids.hxx>
10 #include <doctok/sprmids.hxx>
12 #include <com/sun/star/text/SizeType.hpp>
13 #include <com/sun/star/text/VertOrientation.hpp>
16 namespace writerfilter {
17 namespace dmapper {
19 TablePropertiesHandler::TablePropertiesHandler( bool bOOXML ) :
20 m_pTableManager( NULL ),
21 m_bOOXML( bOOXML )
26 TablePropertiesHandler::~TablePropertiesHandler( )
28 // Do not delete the table manager... this will be done somewhere else
29 m_pTableManager = NULL;
32 bool TablePropertiesHandler::sprm(Sprm & rSprm)
34 bool bRet = true;
35 sal_uInt32 nSprmId = rSprm.getId();
36 Value::Pointer_t pValue = rSprm.getValue();
37 sal_Int32 nIntValue = ((pValue.get() != NULL) ? pValue->getInt() : 0);
38 /* WRITERFILTERSTATUS: table: table_sprmdata */
39 switch( nSprmId )
41 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 2 */
42 case NS_ooxml::LN_CT_TrPrBase_jc: //90706
43 /* WRITERFILTERSTATUS: done: 1, planned: 0.5, spent: 0.5 */
44 case NS_ooxml::LN_CT_TblPrBase_jc:
45 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 2 */
46 case 0x5400: // sprmTJc
48 //table justification 0: left, 1: center, 2: right
49 sal_Int16 nOrient = ConversionHelper::convertTableJustification( nIntValue );
50 TablePropertyMapPtr pTableMap( new TablePropertyMap );
51 pTableMap->setValue( TablePropertyMap::HORI_ORIENT, nOrient );
52 insertTableProps( pTableMap );
54 break;
55 /* WRITERFILTERSTATUS: done: 0, planned: 2, spent: 0 */
56 case 0x9601: // sprmTDxaLeft
57 break;
58 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
59 case 0x9602: // sprmTDxaGapHalf
61 //m_nGapHalf = ConversionHelper::convertTwipToMM100( nIntValue );
62 TablePropertyMapPtr pPropMap( new TablePropertyMap );
63 pPropMap->setValue( TablePropertyMap::GAP_HALF, ConversionHelper::convertTwipToMM100( nIntValue ) );
64 insertTableProps(pPropMap);
66 break;
67 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 2 */
68 case NS_ooxml::LN_CT_TrPrBase_trHeight: //90703
70 //contains unit and value
71 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
72 if( pProperties.get())
73 { //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft)
74 MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
75 pProperties->resolve(*pMeasureHandler);
76 TablePropertyMapPtr pPropMap( new TablePropertyMap );
77 pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny( pMeasureHandler->GetRowHeightSizeType() ));
78 pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(pMeasureHandler->getMeasureValue() ));
79 insertRowProps(pPropMap);
82 break;
83 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
84 case 0x3403: // sprmTFCantSplit
85 case NS_sprm::LN_TCantSplit: // 0x3644
87 //row can't break across pages if nIntValue == 1
88 TablePropertyMapPtr pPropMap( new TablePropertyMap );
89 pPropMap->Insert( PROP_IS_SPLIT_ALLOWED, false, uno::makeAny(sal_Bool( nIntValue == 1 ? sal_False : sal_True ) ));
90 insertRowProps(pPropMap);
92 break;
93 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
94 case 0x9407: // sprmTDyaRowHeight
96 // table row height - negative values indicate 'exact height' - positive 'at least'
97 TablePropertyMapPtr pPropMap( new TablePropertyMap );
98 bool bMinHeight = true;
99 sal_Int16 nHeight = static_cast<sal_Int16>( nIntValue );
100 if( nHeight < 0 )
102 bMinHeight = false;
103 nHeight *= -1;
105 pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny(bMinHeight ? text::SizeType::MIN : text::SizeType::FIX ));
106 pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(ConversionHelper::convertTwipToMM100( nHeight )));
107 insertRowProps(pPropMap);
109 break;
110 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
111 case NS_ooxml::LN_CT_TcPrBase_vAlign://90694
113 sal_Int16 nVertOrient = text::VertOrientation::NONE;
114 switch( nIntValue ) //0 - top 1 - center 3 - bottom
116 case 1: nVertOrient = text::VertOrientation::CENTER; break;
117 case 3: nVertOrient = text::VertOrientation::BOTTOM; break;
118 default:;
120 TablePropertyMapPtr pCellPropMap( new TablePropertyMap() );
121 pCellPropMap->Insert( PROP_VERT_ORIENT, false, uno::makeAny( nVertOrient ) );
122 //todo: in ooxml import the value of m_ncell is wrong
123 cellProps( pCellPropMap );
125 break;
126 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
127 case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
129 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
130 if( pProperties.get())
132 BorderHandlerPtr pBorderHandler( new BorderHandler(m_bOOXML) );
133 pProperties->resolve(*pBorderHandler);
134 TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
135 pTablePropMap->insert( pBorderHandler->getProperties() );
136 insertTableProps( pTablePropMap );
139 break;
140 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
141 case NS_ooxml::LN_CT_TcPrBase_tcBorders ://cell borders
142 //contains CT_TcBorders_left, right, top, bottom
144 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
145 if( pProperties.get())
147 //in OOXML there's one set of borders at each cell (if there is any)
148 TDefTableHandlerPtr pTDefTableHandler( new TDefTableHandler( m_bOOXML ));
149 pProperties->resolve( *pTDefTableHandler );
150 TablePropertyMapPtr pCellPropMap( new TablePropertyMap );
151 pTDefTableHandler->fillCellProperties( 0, pCellPropMap );
152 cellProps( pCellPropMap );
155 break;
156 case NS_ooxml::LN_CT_TblPrBase_shd:
158 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
159 if( pProperties.get())
161 CellColorHandlerPtr pCellColorHandler( new CellColorHandler);
162 pProperties->resolve( *pCellColorHandler );
163 TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
164 insertTableProps( pCellColorHandler->getProperties() );
167 break;
168 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
169 case 0xd61a : // sprmTCellTopColor
170 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
171 case 0xd61b : // sprmTCellLeftColor
172 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
173 case 0xd61c : // sprmTCellBottomColor
174 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
175 case 0xd61d : // sprmTCellRightColor
176 /* WRITERFILTERSTATUS: done: 1, planned: 2, spent: 0 */
177 case NS_ooxml::LN_CT_TcPrBase_shd:
179 // each color sprm contains as much colors as cells are in a row
180 //LN_CT_TcPrBase_shd: cell shading contains: LN_CT_Shd_val, LN_CT_Shd_fill, LN_CT_Shd_color
181 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
182 if( pProperties.get())
184 CellColorHandlerPtr pCellColorHandler( new CellColorHandler );
185 pProperties->resolve( *pCellColorHandler );
186 cellProps( pCellColorHandler->getProperties());
189 break;
190 //OOXML table properties
191 /* WRITERFILTERSTATUS: done: 0, planned: 2, spent: 0 */
192 case NS_ooxml::LN_CT_TblPrBase_tblCellMar: //cell margins
194 //contains LN_CT_TblCellMar_top, LN_CT_TblCellMar_left, LN_CT_TblCellMar_bottom, LN_CT_TblCellMar_right
195 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
196 if( pProperties.get())
198 CellMarginHandlerPtr pCellMarginHandler( new CellMarginHandler );
199 pProperties->resolve( *pCellMarginHandler );
200 TablePropertyMapPtr pMarginProps( new TablePropertyMap );
201 if( pCellMarginHandler->m_bTopMarginValid )
202 pMarginProps->setValue( TablePropertyMap::CELL_MAR_TOP, pCellMarginHandler->m_nTopMargin );
203 if( pCellMarginHandler->m_bBottomMarginValid )
204 pMarginProps->setValue( TablePropertyMap::CELL_MAR_BOTTOM, pCellMarginHandler->m_nBottomMargin );
205 if( pCellMarginHandler->m_bLeftMarginValid )
206 pMarginProps->setValue( TablePropertyMap::CELL_MAR_LEFT, pCellMarginHandler->m_nLeftMargin );
207 if( pCellMarginHandler->m_bRightMarginValid )
208 pMarginProps->setValue( TablePropertyMap::CELL_MAR_RIGHT, pCellMarginHandler->m_nRightMargin );
209 insertTableProps(pMarginProps);
212 break;
213 default: bRet = false;
215 return bRet;