fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / writerfilter / source / dmapper / TablePropertiesHandler.cxx
blob0b5952cd5434f9864385cd539aa2adea78a17244
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "BorderHandler.hxx"
21 #include "CellColorHandler.hxx"
22 #include "CellMarginHandler.hxx"
23 #include "ConversionHelper.hxx"
24 #include "MeasureHandler.hxx"
25 #include "TablePropertiesHandler.hxx"
26 #include "TDefTableHandler.hxx"
27 #include "DomainMapperTableManager.hxx"
29 #include <ooxml/resourceids.hxx>
30 #include <doctok/sprmids.hxx>
32 #include <com/sun/star/text/SizeType.hpp>
33 #include <com/sun/star/text/VertOrientation.hpp>
34 #include <dmapperLoggers.hxx>
37 namespace writerfilter {
38 namespace dmapper {
40 TablePropertiesHandler::TablePropertiesHandler( bool bOOXML ) :
41 m_pTableManager( NULL ),
42 m_bOOXML( bOOXML )
47 TablePropertiesHandler::~TablePropertiesHandler( )
49 // Do not delete the table manager... this will be done somewhere else
50 m_pTableManager = NULL;
53 bool TablePropertiesHandler::sprm(Sprm & rSprm)
55 #ifdef DEBUG_DOMAINMAPPER
56 dmapper_logger->startElement("TablePropertiesHandler.sprm");
57 dmapper_logger->attribute("sprm", rSprm.toString());
58 #endif
60 bool bRet = true;
61 sal_uInt32 nSprmId = rSprm.getId();
62 Value::Pointer_t pValue = rSprm.getValue();
63 sal_Int32 nIntValue = ((pValue.get() != NULL) ? pValue->getInt() : 0);
64 switch( nSprmId )
66 case NS_ooxml::LN_CT_TrPrBase_jc: //90706
67 case NS_ooxml::LN_CT_TblPrBase_jc:
68 case 0x5400: // sprmTJc
70 //table justification 0: left, 1: center, 2: right
71 sal_Int16 nOrient = ConversionHelper::convertTableJustification( nIntValue );
72 TablePropertyMapPtr pTableMap( new TablePropertyMap );
73 pTableMap->setValue( TablePropertyMap::HORI_ORIENT, nOrient );
74 insertTableProps( pTableMap );
76 break;
77 case 0x9601: // sprmTDxaLeft
78 break;
79 case 0x9602: // sprmTDxaGapHalf
81 //m_nGapHalf = ConversionHelper::convertTwipToMM100( nIntValue );
82 TablePropertyMapPtr pPropMap( new TablePropertyMap );
83 pPropMap->setValue( TablePropertyMap::GAP_HALF, ConversionHelper::convertTwipToMM100( nIntValue ) );
84 insertTableProps(pPropMap);
86 break;
87 case NS_ooxml::LN_CT_TrPrBase_trHeight: //90703
89 //contains unit and value
90 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
91 if( pProperties.get())
92 { //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft)
93 MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
94 pProperties->resolve(*pMeasureHandler);
95 TablePropertyMapPtr pPropMap( new TablePropertyMap );
97 DomainMapperTableManager* pManager = dynamic_cast<DomainMapperTableManager*>(m_pTableManager);
98 // In case any of the cells has the btLr cell direction, then an explicit minimal size will just hide the whole row, don't do that.
99 if (pMeasureHandler->GetRowHeightSizeType() != text::SizeType::MIN || !pManager->HasBtlrCell())
101 // In case a cell already wanted fixed size, we should not overwrite it here.
102 if (!pManager || !pManager->IsRowSizeTypeInserted())
103 pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny( pMeasureHandler->GetRowHeightSizeType() ), false);
105 pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(pMeasureHandler->getMeasureValue() ));
107 insertRowProps(pPropMap);
110 break;
111 case 0x3403: // sprmTFCantSplit
112 case NS_sprm::LN_TCantSplit: // 0x3644
114 //row can't break across pages if nIntValue == 1
115 TablePropertyMapPtr pPropMap( new TablePropertyMap );
116 pPropMap->Insert( PROP_IS_SPLIT_ALLOWED, false, uno::makeAny(sal_Bool( nIntValue == 1 ? sal_False : sal_True ) ));
117 insertRowProps(pPropMap);
119 break;
120 case 0x9407: // sprmTDyaRowHeight
122 // table row height - negative values indicate 'exact height' - positive 'at least'
123 TablePropertyMapPtr pPropMap( new TablePropertyMap );
124 bool bMinHeight = true;
125 sal_Int16 nHeight = static_cast<sal_Int16>( nIntValue );
126 if( nHeight < 0 )
128 bMinHeight = false;
129 nHeight *= -1;
131 pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny(bMinHeight ? text::SizeType::MIN : text::SizeType::FIX ));
132 pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(ConversionHelper::convertTwipToMM100( nHeight )));
133 insertRowProps(pPropMap);
135 break;
136 case NS_ooxml::LN_CT_TcPrBase_vAlign://90694
138 sal_Int16 nVertOrient = text::VertOrientation::NONE;
139 switch( nIntValue ) //0 - top 1 - center 3 - bottom
141 case 1: nVertOrient = text::VertOrientation::CENTER; break;
142 case 3: nVertOrient = text::VertOrientation::BOTTOM; break;
143 default:;
145 TablePropertyMapPtr pCellPropMap( new TablePropertyMap() );
146 pCellPropMap->Insert( PROP_VERT_ORIENT, false, uno::makeAny( nVertOrient ) );
147 //todo: in ooxml import the value of m_ncell is wrong
148 cellProps( pCellPropMap );
150 break;
151 case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
153 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
154 if( pProperties.get())
156 BorderHandlerPtr pBorderHandler( new BorderHandler(m_bOOXML) );
157 pProperties->resolve(*pBorderHandler);
158 TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
159 pTablePropMap->InsertProps(pBorderHandler->getProperties());
161 #ifdef DEBUG_DOMAINMAPPER
162 pTablePropMap->dumpXml( dmapper_logger );
163 #endif
164 insertTableProps( pTablePropMap );
167 break;
168 case NS_ooxml::LN_CT_TblPrBase_tblLayout:
170 DomainMapperTableManager* pManager = dynamic_cast<DomainMapperTableManager*>(m_pTableManager);
171 if (pManager)
172 pManager->SetLayoutType(static_cast<sal_uInt32>(nIntValue));
174 break;
175 case NS_ooxml::LN_CT_TcPrBase_tcBorders ://cell borders
176 //contains CT_TcBorders_left, right, top, bottom
178 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
179 if( pProperties.get())
181 //in OOXML there's one set of borders at each cell (if there is any)
182 TDefTableHandlerPtr pTDefTableHandler( new TDefTableHandler( m_bOOXML ));
183 pProperties->resolve( *pTDefTableHandler );
184 TablePropertyMapPtr pCellPropMap( new TablePropertyMap );
185 pTDefTableHandler->fillCellProperties( 0, pCellPropMap );
186 cellProps( pCellPropMap );
189 break;
190 case NS_ooxml::LN_CT_TcPrBase_tcMar:
192 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
193 if (pProperties.get())
195 CellMarginHandlerPtr pCellMarginHandler(new CellMarginHandler);
196 pProperties->resolve(*pCellMarginHandler);
197 TablePropertyMapPtr pCellProperties(new TablePropertyMap);
198 if (pCellMarginHandler->m_bTopMarginValid)
199 pCellProperties->Insert(PROP_TOP_BORDER_DISTANCE, false, uno::makeAny(pCellMarginHandler->m_nTopMargin));
200 if (pCellMarginHandler->m_bLeftMarginValid)
201 pCellProperties->Insert(PROP_LEFT_BORDER_DISTANCE, false, uno::makeAny(pCellMarginHandler->m_nLeftMargin));
202 if (pCellMarginHandler->m_bBottomMarginValid)
203 pCellProperties->Insert(PROP_BOTTOM_BORDER_DISTANCE, false, uno::makeAny(pCellMarginHandler->m_nBottomMargin));
204 if (pCellMarginHandler->m_bRightMarginValid)
205 pCellProperties->Insert(PROP_RIGHT_BORDER_DISTANCE, false, uno::makeAny(pCellMarginHandler->m_nRightMargin));
206 cellProps(pCellProperties);
209 break;
210 case NS_ooxml::LN_CT_TblPrBase_shd:
212 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
213 if( pProperties.get())
215 CellColorHandlerPtr pCellColorHandler( new CellColorHandler);
216 pProperties->resolve( *pCellColorHandler );
217 TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
218 insertTableProps( pCellColorHandler->getProperties() );
221 break;
222 case 0xd61a : // sprmTCellTopColor
223 case 0xd61b : // sprmTCellLeftColor
224 case 0xd61c : // sprmTCellBottomColor
225 case 0xd61d : // sprmTCellRightColor
226 case NS_ooxml::LN_CT_TcPrBase_shd:
228 // each color sprm contains as much colors as cells are in a row
229 //LN_CT_TcPrBase_shd: cell shading contains: LN_CT_Shd_val, LN_CT_Shd_fill, LN_CT_Shd_color
230 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
231 if( pProperties.get())
233 CellColorHandlerPtr pCellColorHandler( new CellColorHandler );
234 pProperties->resolve( *pCellColorHandler );
235 cellProps( pCellColorHandler->getProperties());
238 break;
239 //OOXML table properties
240 case NS_ooxml::LN_CT_TblPrBase_tblCellMar: //cell margins
242 //contains LN_CT_TblCellMar_top, LN_CT_TblCellMar_left, LN_CT_TblCellMar_bottom, LN_CT_TblCellMar_right
243 // LN_CT_TblCellMar_start, LN_CT_TblCellMar_end
244 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
245 if( pProperties.get())
247 CellMarginHandlerPtr pCellMarginHandler( new CellMarginHandler );
248 pProperties->resolve( *pCellMarginHandler );
249 TablePropertyMapPtr pMarginProps( new TablePropertyMap );
250 if( pCellMarginHandler->m_bTopMarginValid )
251 pMarginProps->setValue( TablePropertyMap::CELL_MAR_TOP, pCellMarginHandler->m_nTopMargin );
252 if( pCellMarginHandler->m_bBottomMarginValid )
253 pMarginProps->setValue( TablePropertyMap::CELL_MAR_BOTTOM, pCellMarginHandler->m_nBottomMargin );
254 if( pCellMarginHandler->m_bLeftMarginValid )
255 pMarginProps->setValue( TablePropertyMap::CELL_MAR_LEFT, pCellMarginHandler->m_nLeftMargin );
256 if( pCellMarginHandler->m_bRightMarginValid )
257 pMarginProps->setValue( TablePropertyMap::CELL_MAR_RIGHT, pCellMarginHandler->m_nRightMargin );
258 insertTableProps(pMarginProps);
261 break;
262 case NS_ooxml::LN_CT_TblPrBase_tblInd:
264 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
265 if (pProperties.get())
267 MeasureHandlerPtr pHandler(new MeasureHandler);
268 pProperties->resolve( *pHandler );
269 TablePropertyMapPtr pTblIndMap(new TablePropertyMap);
270 sal_uInt32 nTblInd = pHandler->getMeasureValue();
271 pTblIndMap->setValue( TablePropertyMap::LEFT_MARGIN, nTblInd);
272 insertTableProps(pTblIndMap);
275 break;
276 default: bRet = false;
279 #ifdef DEBUG_DOMAINMAPPER
280 dmapper_logger->endElement();
281 #endif
283 return bRet;
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */