Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "oox/drawingml/table/tableproperties.hxx"
21 : : #include "oox/drawingml/drawingmltypes.hxx"
22 : : #include <com/sun/star/table/XTable.hpp>
23 : : #include <com/sun/star/container/XNameContainer.hpp>
24 : : #include <com/sun/star/beans/XMultiPropertySet.hpp>
25 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 : : #include <com/sun/star/table/XMergeableCellRange.hpp>
27 : : #include <com/sun/star/table/BorderLine2.hpp>
28 : : #include <rtl/instance.hxx>
29 : : #include "oox/core/xmlfilterbase.hxx"
30 : : #include "oox/helper/propertyset.hxx"
31 : :
32 : : using rtl::OUString;
33 : : using namespace ::oox::core;
34 : : using namespace ::com::sun::star;
35 : : using namespace ::com::sun::star::uno;
36 : : using namespace ::com::sun::star::beans;
37 : : using namespace ::com::sun::star::table;
38 : :
39 : :
40 : : namespace oox { namespace drawingml { namespace table {
41 : :
42 : 0 : TableProperties::TableProperties()
43 : : : mbRtl( sal_False )
44 : : , mbFirstRow( sal_False )
45 : : , mbFirstCol( sal_False )
46 : : , mbLastRow( sal_False )
47 : : , mbLastCol( sal_False )
48 : : , mbBandRow( sal_False )
49 [ # # ][ # # ]: 0 : , mbBandCol( sal_False )
[ # # ]
50 : : {
51 : 0 : }
52 [ # # ]: 0 : TableProperties::~TableProperties()
53 : : {
54 : 0 : }
55 : :
56 : 0 : void CreateTableRows( uno::Reference< XTableRows > xTableRows, const std::vector< TableRow >& rvTableRows )
57 : : {
58 [ # # ]: 0 : if ( rvTableRows.size() > 1 )
59 [ # # ][ # # ]: 0 : xTableRows->insertByIndex( 0, rvTableRows.size() - 1 );
60 : 0 : std::vector< TableRow >::const_iterator aTableRowIter( rvTableRows.begin() );
61 [ # # ]: 0 : uno::Reference< container::XIndexAccess > xIndexAccess( xTableRows, UNO_QUERY_THROW );
62 [ # # ][ # # ]: 0 : for ( sal_Int32 n = 0; n < xIndexAccess->getCount(); n++ )
[ # # ]
63 : : {
64 [ # # ][ # # ]: 0 : static const rtl::OUString sHeight( RTL_CONSTASCII_USTRINGPARAM ( "Height" ) );
[ # # ][ # # ]
65 [ # # ][ # # ]: 0 : Reference< XPropertySet > xPropSet( xIndexAccess->getByIndex( n ), UNO_QUERY_THROW );
[ # # ]
66 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( sHeight, Any( static_cast< sal_Int32 >( aTableRowIter->getHeight() / 360 ) ) );
[ # # ]
67 : 0 : ++aTableRowIter;
68 : 0 : }
69 : 0 : }
70 : :
71 : 0 : void CreateTableColumns( Reference< XTableColumns > xTableColumns, const std::vector< sal_Int32 >& rvTableGrid )
72 : : {
73 [ # # ]: 0 : if ( rvTableGrid.size() > 1 )
74 [ # # ][ # # ]: 0 : xTableColumns->insertByIndex( 0, rvTableGrid.size() - 1 );
75 : 0 : std::vector< sal_Int32 >::const_iterator aTableGridIter( rvTableGrid.begin() );
76 [ # # ]: 0 : uno::Reference< container::XIndexAccess > xIndexAccess( xTableColumns, UNO_QUERY_THROW );
77 [ # # ][ # # ]: 0 : for ( sal_Int32 n = 0; n < xIndexAccess->getCount(); n++ )
[ # # ]
78 : : {
79 [ # # ][ # # ]: 0 : static const rtl::OUString sWidth( RTL_CONSTASCII_USTRINGPARAM ( "Width" ) );
[ # # ][ # # ]
80 [ # # ][ # # ]: 0 : Reference< XPropertySet > xPropSet( xIndexAccess->getByIndex( n ), UNO_QUERY_THROW );
[ # # ]
81 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( sWidth, Any( static_cast< sal_Int32 >( *aTableGridIter++ / 360 ) ) );
[ # # ][ # # ]
[ # # ]
82 : 0 : }
83 : 0 : }
84 : :
85 : 0 : void MergeCells( const uno::Reference< XTable >& xTable, sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan )
86 : : {
87 [ # # ]: 0 : if( xTable.is() ) try
88 : : {
89 [ # # ][ # # ]: 0 : Reference< XMergeableCellRange > xRange( xTable->createCursorByRange( xTable->getCellRangeByPosition( nCol, nRow,nCol + nColSpan - 1, nRow + nRowSpan - 1 ) ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
90 [ # # ][ # # ]: 0 : if( xRange->isMergeable() )
[ # # ]
91 [ # # ][ # # ]: 0 : xRange->merge();
[ # # ]
92 : : }
93 : 0 : catch( Exception& )
94 : : {
95 : : }
96 : 0 : }
97 : :
98 : : namespace
99 : : {
100 : : struct theDefaultTableStyle : public ::rtl::Static< TableStyle, theDefaultTableStyle > {};
101 : : }
102 : :
103 : 0 : const TableStyle& TableProperties::getUsedTableStyle( const ::oox::core::XmlFilterBase& rFilterBase )
104 : : {
105 : 0 : ::oox::core::XmlFilterBase& rBase( const_cast< ::oox::core::XmlFilterBase& >( rFilterBase ) );
106 : :
107 : 0 : TableStyle* pTableStyle = NULL;
108 [ # # ]: 0 : if ( mpTableStyle )
109 : 0 : pTableStyle = &*mpTableStyle;
110 [ # # ]: 0 : else if ( rBase.getTableStyles() )
111 : : {
112 [ # # ][ # # ]: 0 : const std::vector< TableStyle >& rTableStyles( rBase.getTableStyles()->getTableStyles() );
113 [ # # ][ # # ]: 0 : const rtl::OUString aStyleId( getStyleId().isEmpty() ? rBase.getTableStyles()->getDefaultStyleId() : getStyleId() );
[ # # ][ # # ]
[ # # ]
114 : 0 : std::vector< TableStyle >::const_iterator aIter( rTableStyles.begin() );
115 [ # # ][ # # ]: 0 : while( aIter != rTableStyles.end() )
116 : : {
117 [ # # ]: 0 : if ( const_cast< TableStyle& >( *aIter ).getStyleId() == aStyleId )
118 : : {
119 : 0 : pTableStyle = &const_cast< TableStyle& >( *aIter );
120 : 0 : break; // we get the correct style
121 : : }
122 : 0 : ++aIter;
123 : 0 : }
124 : : }
125 : :
126 [ # # ]: 0 : if ( !pTableStyle )
127 : 0 : return theDefaultTableStyle::get();
128 : :
129 : 0 : return *pTableStyle;
130 : : }
131 : :
132 : 0 : void TableProperties::pushToPropSet( const ::oox::core::XmlFilterBase& rFilterBase,
133 : : const Reference < XPropertySet >& xPropSet, TextListStylePtr pMasterTextListStyle )
134 : : {
135 [ # # ][ # # ]: 0 : TableStyleListPtr( const_cast< ::oox::core::XmlFilterBase& >( rFilterBase ).getTableStyles() );
136 : :
137 : : uno::Reference< XColumnRowRange > xColumnRowRange(
138 [ # # ][ # # ]: 0 : xPropSet->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ) ), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
139 : :
140 [ # # ][ # # ]: 0 : CreateTableColumns( xColumnRowRange->getColumns(), mvTableGrid );
[ # # ]
141 [ # # ][ # # ]: 0 : CreateTableRows( xColumnRowRange->getRows(), mvTableRows );
[ # # ]
142 : :
143 [ # # ]: 0 : const TableStyle& rTableStyle( getUsedTableStyle( rFilterBase ) );
144 : 0 : sal_Int32 nRow = 0;
145 : 0 : std::vector< TableRow >::iterator aTableRowIter( mvTableRows.begin() );
146 [ # # ][ # # ]: 0 : while( aTableRowIter != mvTableRows.end() )
147 : : {
148 : 0 : sal_Int32 nColumn = 0;
149 : 0 : std::vector< TableCell >::iterator aTableCellIter( aTableRowIter->getTableCells().begin() );
150 [ # # ][ # # ]: 0 : while( aTableCellIter != aTableRowIter->getTableCells().end() )
151 : : {
152 : 0 : TableCell& rTableCell( *aTableCellIter );
153 [ # # ][ # # ]: 0 : if ( !rTableCell.getvMerge() && !rTableCell.gethMerge() )
[ # # ]
154 : : {
155 [ # # ]: 0 : uno::Reference< XTable > xTable( xColumnRowRange, uno::UNO_QUERY_THROW );
156 [ # # ][ # # ]: 0 : if ( ( rTableCell.getRowSpan() > 1 ) || ( rTableCell.getGridSpan() > 1 ) )
[ # # ]
157 [ # # ]: 0 : MergeCells( xTable, nColumn, nRow, rTableCell.getGridSpan(), rTableCell.getRowSpan() );
158 : :
159 [ # # ]: 0 : Reference< XCellRange > xCellRange( xTable, UNO_QUERY_THROW );
160 [ # # ]: 0 : rTableCell.pushToXCell( rFilterBase, pMasterTextListStyle, xCellRange->getCellByPosition( nColumn, nRow ), *this, rTableStyle,
161 [ # # ][ # # ]: 0 : nColumn, aTableRowIter->getTableCells().size(), nRow, mvTableRows.size() );
[ # # ][ # # ]
162 : : }
163 : 0 : nColumn++;
164 [ # # ]: 0 : aTableCellIter++;
165 : : }
166 : 0 : nRow++;
167 [ # # ]: 0 : aTableRowIter++;
168 : 0 : }
169 : 0 : }
170 : :
171 [ + - ][ + - ]: 285 : } } }
172 : :
173 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|