fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / oox / source / drawingml / table / tablecell.cxx
blobc3c4f49ec718f456751c0a0edf94b0df468df97a
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 "oox/drawingml/table/tablecell.hxx"
21 #include "oox/drawingml/table/tableproperties.hxx"
22 #include "oox/drawingml/shapepropertymap.hxx"
23 #include "oox/drawingml/textbody.hxx"
24 #include "oox/core/xmlfilterbase.hxx"
25 #include "oox/helper/propertyset.hxx"
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/beans/XMultiPropertySet.hpp>
28 #include <com/sun/star/table/XTable.hpp>
29 #include <com/sun/star/table/XMergeableCellRange.hpp>
30 #include <com/sun/star/table/BorderLine2.hpp>
31 #include <com/sun/star/drawing/LineStyle.hpp>
32 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
33 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
34 #include <com/sun/star/text/XText.hpp>
35 #include <com/sun/star/text/WritingMode.hpp>
37 using namespace ::oox::core;
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using ::com::sun::star::table::BorderLine2;
43 namespace oox { namespace drawingml { namespace table {
45 TableCell::TableCell()
46 : mpTextBody( new TextBody() )
47 , mnRowSpan ( 1 )
48 , mnGridSpan( 1 )
49 , mbhMerge( sal_False )
50 , mbvMerge( sal_False )
51 , mnMarL( 91440 )
52 , mnMarR( 91440 )
53 , mnMarT( 45720 )
54 , mnMarB( 45720 )
55 , mnVertToken( XML_horz )
56 , mnAnchorToken( XML_t )
57 , mbAnchorCtr( sal_False )
58 , mnHorzOverflowToken( XML_clip )
61 TableCell::~TableCell()
65 void applyLineAttributes( const ::oox::core::XmlFilterBase& rFilterBase,
66 Reference< XPropertySet >& rxPropSet, oox::drawingml::LineProperties& rLineProperties,
67 sal_Int32 nPropId )
69 BorderLine2 aBorderLine;
70 if( rLineProperties.maLineFill.moFillType.differsFrom( XML_noFill ) )
72 Color aColor = rLineProperties.maLineFill.getBestSolidColor();
73 aBorderLine.Color = aColor.getColor( rFilterBase.getGraphicHelper() );
74 aBorderLine.OuterLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.get( 0 ) ) / 4 );
75 aBorderLine.InnerLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.get( 0 ) ) / 4 );
76 aBorderLine.LineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.get( 0 ) ) / 2 );
77 aBorderLine.LineDistance = 0;
80 PropertySet aPropSet( rxPropSet );
81 aPropSet.setProperty( nPropId, aBorderLine );
84 void applyBorder( TableStylePart& rTableStylePart, sal_Int32 nLineType, oox::drawingml::LineProperties& rLineProperties )
86 std::map < sal_Int32, ::oox::drawingml::LinePropertiesPtr >& rPartLineBorders( rTableStylePart.getLineBorders() );
87 std::map < sal_Int32, ::oox::drawingml::LinePropertiesPtr >::const_iterator aIter( rPartLineBorders.find( nLineType ) );
88 if ( ( aIter != rPartLineBorders.end() ) && aIter->second.get() )
89 rLineProperties.assignUsed( *aIter->second );
92 void applyTableStylePart( oox::drawingml::FillProperties& rFillProperties,
93 TextCharacterProperties& aTextCharProps,
94 oox::drawingml::LineProperties& rLeftBorder,
95 oox::drawingml::LineProperties& rRightBorder,
96 oox::drawingml::LineProperties& rTopBorder,
97 oox::drawingml::LineProperties& rBottomBorder,
98 oox::drawingml::LineProperties& rTopLeftToBottomRightBorder,
99 oox::drawingml::LineProperties& rBottomLeftToTopRightBorder,
100 TableStylePart& rTableStylePart )
102 boost::shared_ptr< ::oox::drawingml::FillProperties >& rPartFillPropertiesPtr( rTableStylePart.getFillProperties() );
103 if ( rPartFillPropertiesPtr.get() )
104 rFillProperties.assignUsed( *rPartFillPropertiesPtr );
106 applyBorder( rTableStylePart, XML_left, rLeftBorder );
107 applyBorder( rTableStylePart, XML_right, rRightBorder );
108 applyBorder( rTableStylePart, XML_top, rTopBorder );
109 applyBorder( rTableStylePart, XML_bottom, rBottomBorder );
110 applyBorder( rTableStylePart, XML_tl2br, rTopLeftToBottomRightBorder );
111 applyBorder( rTableStylePart, XML_tr2bl, rBottomLeftToTopRightBorder );
113 aTextCharProps.maLatinFont = rTableStylePart.getLatinFont();
114 aTextCharProps.maAsianFont = rTableStylePart.getAsianFont();
115 aTextCharProps.maComplexFont = rTableStylePart.getComplexFont();
116 aTextCharProps.maSymbolFont = rTableStylePart.getSymbolFont();
117 if (rTableStylePart.getTextColor().isUsed())
118 aTextCharProps.maCharColor = rTableStylePart.getTextColor();
119 if( rTableStylePart.getTextBoldStyle().is_initialized() )
120 aTextCharProps.moBold = rTableStylePart.getTextBoldStyle();
121 if( rTableStylePart.getTextItalicStyle().is_initialized() )
122 aTextCharProps.moItalic = rTableStylePart.getTextItalicStyle();
125 void applyTableCellProperties( const Reference < ::com::sun::star::table::XCell >& rxCell, const TableCell& rTableCell )
127 Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
128 xPropSet->setPropertyValue( "TextUpperDistance", Any( static_cast< sal_Int32 >( rTableCell.getTopMargin() / 360 ) ) );
129 xPropSet->setPropertyValue( "TextRightDistance", Any( static_cast< sal_Int32 >( rTableCell.getRightMargin() / 360 ) ) );
130 xPropSet->setPropertyValue( "TextLeftDistance", Any( static_cast< sal_Int32 >( rTableCell.getLeftMargin() / 360 ) ) );
131 xPropSet->setPropertyValue( "TextLowerDistance", Any( static_cast< sal_Int32 >( rTableCell.getBottomMargin() / 360 ) ) );
133 drawing::TextVerticalAdjust eVA;
134 switch( rTableCell.getAnchorToken() )
136 case XML_ctr: eVA = drawing::TextVerticalAdjust_CENTER; break;
137 case XML_b: eVA = drawing::TextVerticalAdjust_BOTTOM; break;
138 case XML_just:
139 case XML_dist:
140 default:
141 case XML_t: eVA = drawing::TextVerticalAdjust_TOP; break;
143 xPropSet->setPropertyValue( "TextVerticalAdjust", Any( eVA ) );
146 void TableCell::pushToXCell( const ::oox::core::XmlFilterBase& rFilterBase, ::oox::drawingml::TextListStylePtr pMasterTextListStyle,
147 const ::com::sun::star::uno::Reference < ::com::sun::star::table::XCell >& rxCell, const TableProperties& rTableProperties,
148 const TableStyle& rTableStyle, sal_Int32 nColumn, sal_Int32 nMaxColumn, sal_Int32 nRow, sal_Int32 nMaxRow )
150 TableStyle& rTable( const_cast< TableStyle& >( rTableStyle ) );
151 TableProperties& rProperties( const_cast< TableProperties& >( rTableProperties ) );
153 Reference< text::XText > xText( rxCell, UNO_QUERY_THROW );
154 Reference< text::XTextCursor > xAt = xText->createTextCursor();
156 applyTableCellProperties( rxCell, *this );
157 TextCharacterProperties aTextStyleProps;
158 xAt->gotoStart( sal_True );
159 Reference< text::XTextRange > xStart( xAt, UNO_QUERY );
160 xAt->gotoEnd( sal_True );
162 Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
163 oox::drawingml::FillProperties aFillProperties;
164 oox::drawingml::LineProperties aLinePropertiesLeft;
165 oox::drawingml::LineProperties aLinePropertiesRight;
166 oox::drawingml::LineProperties aLinePropertiesTop;
167 oox::drawingml::LineProperties aLinePropertiesBottom;
168 oox::drawingml::LineProperties aLinePropertiesTopLeftToBottomRight;
169 oox::drawingml::LineProperties aLinePropertiesBottomLeftToTopRight;
171 boost::shared_ptr< ::oox::drawingml::FillProperties >& rBackgroundFillPropertiesPtr( rTable.getBackgroundFillProperties() );
172 if ( rBackgroundFillPropertiesPtr.get() )
173 aFillProperties.assignUsed( *rBackgroundFillPropertiesPtr );
175 applyTableStylePart( aFillProperties, aTextStyleProps,
176 aLinePropertiesLeft,
177 aLinePropertiesRight,
178 aLinePropertiesTop,
179 aLinePropertiesBottom,
180 aLinePropertiesTopLeftToBottomRight,
181 aLinePropertiesBottomLeftToTopRight,
182 rTable.getWholeTbl() );
184 if ( rProperties.isFirstRow() && ( nRow == 0 ) )
186 applyTableStylePart( aFillProperties, aTextStyleProps,
187 aLinePropertiesLeft,
188 aLinePropertiesRight,
189 aLinePropertiesTop,
190 aLinePropertiesBottom,
191 aLinePropertiesTopLeftToBottomRight,
192 aLinePropertiesBottomLeftToTopRight,
193 rTable.getFirstRow() );
195 if ( rProperties.isLastRow() && ( nRow == nMaxRow ) )
197 applyTableStylePart( aFillProperties, aTextStyleProps,
198 aLinePropertiesLeft,
199 aLinePropertiesRight,
200 aLinePropertiesTop,
201 aLinePropertiesBottom,
202 aLinePropertiesTopLeftToBottomRight,
203 aLinePropertiesBottomLeftToTopRight,
204 rTable.getLastRow() );
206 if ( rProperties.isFirstCol() && ( nColumn == 0 ) )
208 applyTableStylePart( aFillProperties, aTextStyleProps,
209 aLinePropertiesLeft,
210 aLinePropertiesRight,
211 aLinePropertiesTop,
212 aLinePropertiesBottom,
213 aLinePropertiesTopLeftToBottomRight,
214 aLinePropertiesBottomLeftToTopRight,
215 rTable.getFirstCol() );
217 if ( rProperties.isLastCol() && ( nColumn == nMaxColumn ) )
219 applyTableStylePart( aFillProperties, aTextStyleProps,
220 aLinePropertiesLeft,
221 aLinePropertiesRight,
222 aLinePropertiesTop,
223 aLinePropertiesBottom,
224 aLinePropertiesTopLeftToBottomRight,
225 aLinePropertiesBottomLeftToTopRight,
226 rTable.getLastCol() );
228 if ( rProperties.isBandRow() )
230 if ( ( !rProperties.isFirstRow() || ( nRow != 0 ) ) &&
231 ( !rProperties.isLastRow() || ( nRow != nMaxRow ) ) )
233 sal_Int32 nBand = nRow;
234 if ( rProperties.isFirstRow() )
235 nBand++;
236 if ( nBand & 1 )
238 applyTableStylePart( aFillProperties, aTextStyleProps,
239 aLinePropertiesLeft,
240 aLinePropertiesRight,
241 aLinePropertiesTop,
242 aLinePropertiesBottom,
243 aLinePropertiesTopLeftToBottomRight,
244 aLinePropertiesBottomLeftToTopRight,
245 rTable.getBand2H() );
247 else
249 applyTableStylePart( aFillProperties, aTextStyleProps,
250 aLinePropertiesLeft,
251 aLinePropertiesRight,
252 aLinePropertiesTop,
253 aLinePropertiesBottom,
254 aLinePropertiesTopLeftToBottomRight,
255 aLinePropertiesBottomLeftToTopRight,
256 rTable.getBand1H() );
260 if ( ( nRow == 0 ) && ( nColumn == 0 ) )
262 applyTableStylePart( aFillProperties, aTextStyleProps,
263 aLinePropertiesLeft,
264 aLinePropertiesRight,
265 aLinePropertiesTop,
266 aLinePropertiesBottom,
267 aLinePropertiesTopLeftToBottomRight,
268 aLinePropertiesBottomLeftToTopRight,
269 rTable.getNwCell() );
271 if ( ( nRow == nMaxRow ) && ( nColumn == 0 ) )
273 applyTableStylePart( aFillProperties, aTextStyleProps,
274 aLinePropertiesLeft,
275 aLinePropertiesRight,
276 aLinePropertiesTop,
277 aLinePropertiesBottom,
278 aLinePropertiesTopLeftToBottomRight,
279 aLinePropertiesBottomLeftToTopRight,
280 rTable.getSwCell() );
282 if ( ( nRow == 0 ) && ( nColumn == nMaxColumn ) )
284 applyTableStylePart( aFillProperties, aTextStyleProps,
285 aLinePropertiesLeft,
286 aLinePropertiesRight,
287 aLinePropertiesTop,
288 aLinePropertiesBottom,
289 aLinePropertiesTopLeftToBottomRight,
290 aLinePropertiesBottomLeftToTopRight,
291 rTable.getNeCell() );
293 if ( ( nRow == nMaxColumn ) && ( nColumn == nMaxColumn ) )
295 applyTableStylePart( aFillProperties, aTextStyleProps,
296 aLinePropertiesLeft,
297 aLinePropertiesRight,
298 aLinePropertiesTop,
299 aLinePropertiesBottom,
300 aLinePropertiesTopLeftToBottomRight,
301 aLinePropertiesBottomLeftToTopRight,
302 rTable.getSeCell() );
304 if ( rProperties.isBandCol() )
306 if ( ( !rProperties.isFirstCol() || ( nColumn != 0 ) ) &&
307 ( !rProperties.isLastCol() || ( nColumn != nMaxColumn ) ) )
309 sal_Int32 nBand = nColumn;
310 if ( rProperties.isFirstCol() )
311 nBand++;
312 if ( nBand & 1 )
314 applyTableStylePart( aFillProperties, aTextStyleProps,
315 aLinePropertiesLeft,
316 aLinePropertiesRight,
317 aLinePropertiesTop,
318 aLinePropertiesBottom,
319 aLinePropertiesTopLeftToBottomRight,
320 aLinePropertiesBottomLeftToTopRight,
321 rTable.getBand2V() );
323 else
325 applyTableStylePart( aFillProperties, aTextStyleProps,
326 aLinePropertiesLeft,
327 aLinePropertiesRight,
328 aLinePropertiesTop,
329 aLinePropertiesBottom,
330 aLinePropertiesTopLeftToBottomRight,
331 aLinePropertiesBottomLeftToTopRight,
332 rTable.getBand1V() );
336 aLinePropertiesLeft.assignUsed( maLinePropertiesLeft );
337 aLinePropertiesRight.assignUsed( maLinePropertiesRight );
338 aLinePropertiesTop.assignUsed( maLinePropertiesTop );
339 aLinePropertiesBottom.assignUsed( maLinePropertiesBottom );
340 aLinePropertiesTopLeftToBottomRight.assignUsed( maLinePropertiesTopLeftToBottomRight );
341 aLinePropertiesBottomLeftToTopRight.assignUsed( maLinePropertiesBottomLeftToTopRight );
342 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesLeft, PROP_LeftBorder );
343 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesRight, PROP_RightBorder );
344 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesTop, PROP_TopBorder );
345 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesBottom, PROP_BottomBorder );
346 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesTopLeftToBottomRight, PROP_DiagonalTLBR );
347 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesBottomLeftToTopRight, PROP_DiagonalBLTR );
349 aFillProperties.assignUsed( maFillProperties );
350 ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
351 // TODO: phClr?
352 aFillProperties.pushToPropMap( aPropMap, rFilterBase.getGraphicHelper() );
353 PropertySet( xPropSet ).setProperties( aPropMap );
355 if ( getVertToken() == XML_eaVert )
357 xPropSet->setPropertyValue("TextWritingMode", Any(com::sun::star::text::WritingMode_TB_RL));
360 getTextBody()->insertAt( rFilterBase, xText, xAt, aTextStyleProps, pMasterTextListStyle );
363 } } }
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */