fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / xml / xmlrowi.cxx
blob7af34aa1dd16d3b5f11b987e430b9e5441c1b660
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 "xmlrowi.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlcelli.hxx"
23 #include "global.hxx"
24 #include "xmlstyli.hxx"
25 #include "document.hxx"
26 #include "docuno.hxx"
27 #include "olinetab.hxx"
28 #include "sheetdata.hxx"
30 #include <xmloff/xmltkmap.hxx>
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmlnmspe.hxx>
33 #include <xmloff/families.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
36 #include <com/sun/star/sheet/XSpreadsheet.hpp>
37 #include <com/sun/star/table/XColumnRowRange.hpp>
38 #include <com/sun/star/sheet/XPrintAreas.hpp>
40 #include <com/sun/star/table/CellAddress.hpp>
42 #define SC_ISVISIBLE "IsVisible"
43 #define SC_ISFILTERED "IsFiltered"
45 using namespace com::sun::star;
46 using namespace xmloff::token;
48 ScXMLTableRowContext::ScXMLTableRowContext( ScXMLImport& rImport,
49 sal_uInt16 nPrfx,
50 const OUString& rLName,
51 const ::com::sun::star::uno::Reference<
52 ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) :
53 SvXMLImportContext( rImport, nPrfx, rLName ),
54 sVisibility(GetXMLToken(XML_VISIBLE)),
55 nRepeatedRows(1),
56 bHasCell(false)
58 OUString sCellStyleName;
59 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
60 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableRowAttrTokenMap());
61 for( sal_Int16 i=0; i < nAttrCount; ++i )
63 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
64 OUString aLocalName;
65 sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
66 sAttrName, &aLocalName ));
67 const OUString& sValue(xAttrList->getValueByIndex( i ));
69 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
71 case XML_TOK_TABLE_ROW_ATTR_STYLE_NAME:
73 sStyleName = sValue;
75 break;
76 case XML_TOK_TABLE_ROW_ATTR_VISIBILITY:
78 sVisibility = sValue;
80 break;
81 case XML_TOK_TABLE_ROW_ATTR_REPEATED:
83 nRepeatedRows = std::max( sValue.toInt32(), (sal_Int32) 1 );
84 nRepeatedRows = std::min( nRepeatedRows, MAXROWCOUNT );
86 break;
87 case XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME:
89 sCellStyleName = sValue;
91 break;
92 /*case XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT:
94 sOptimalHeight = sValue;
96 break;*/
99 GetScImport().GetTables().AddRow();
100 GetScImport().GetTables().SetRowStyle(sCellStyleName);
103 ScXMLTableRowContext::~ScXMLTableRowContext()
107 SvXMLImportContext *ScXMLTableRowContext::CreateChildContext( sal_uInt16 nPrefix,
108 const OUString& rLName,
109 const ::com::sun::star::uno::Reference<
110 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
112 SvXMLImportContext *pContext(0);
114 const SvXMLTokenMap& rTokenMap(GetScImport().GetTableRowElemTokenMap());
115 switch( rTokenMap.Get( nPrefix, rLName ) )
117 case XML_TOK_TABLE_ROW_CELL:
118 // if( IsInsertCellPossible() )
120 bHasCell = true;
121 pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
122 rLName, xAttrList, false, static_cast<SCROW>(nRepeatedRows)
123 //this
126 break;
127 case XML_TOK_TABLE_ROW_COVERED_CELL:
128 // if( IsInsertCellPossible() )
130 bHasCell = true;
131 pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
132 rLName, xAttrList, true, static_cast<SCROW>(nRepeatedRows)
133 //this
136 break;
139 if( !pContext )
140 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
142 return pContext;
145 void ScXMLTableRowContext::EndElement()
147 ScXMLImport& rXMLImport(GetScImport());
148 if (!bHasCell && nRepeatedRows > 1)
150 for (sal_Int32 i = 0; i < nRepeatedRows - 1; ++i) //one row is always added
151 GetScImport().GetTables().AddRow();
152 OSL_FAIL("it seems here is a nonvalid file; possible missing of table:table-cell element");
154 SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
155 sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
156 uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
157 if(xSheet.is())
159 sal_Int32 nFirstRow(nCurrentRow - nRepeatedRows + 1);
160 if (nFirstRow > MAXROW)
161 nFirstRow = MAXROW;
162 if (nCurrentRow > MAXROW)
163 nCurrentRow = MAXROW;
164 uno::Reference <table::XCellRange> xCellRange(xSheet->getCellRangeByPosition(0, nFirstRow, 0, nCurrentRow));
165 if (xCellRange.is())
167 uno::Reference<table::XColumnRowRange> xColumnRowRange (xCellRange, uno::UNO_QUERY);
168 if (xColumnRowRange.is())
170 uno::Reference <beans::XPropertySet> xRowProperties(xColumnRowRange->getRows(), uno::UNO_QUERY);
171 if (xRowProperties.is())
173 if (!sStyleName.isEmpty())
175 XMLTableStylesContext *pStyles(static_cast<XMLTableStylesContext *>(rXMLImport.GetAutoStyles()));
176 if ( pStyles )
178 XMLTableStyleContext* pStyle(const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
179 XML_STYLE_FAMILY_TABLE_ROW, sStyleName, true))));
180 if (pStyle)
182 pStyle->FillPropertySet(xRowProperties);
184 if ( nSheet != pStyle->GetLastSheet() )
186 ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
187 pSheetData->AddRowStyle( sStyleName, ScAddress( 0, (SCROW)nFirstRow, nSheet ) );
188 pStyle->SetLastSheet(nSheet);
193 bool bVisible (true);
194 bool bFiltered (false);
195 if (IsXMLToken(sVisibility, XML_COLLAPSE))
197 bVisible = false;
199 else if (IsXMLToken(sVisibility, XML_FILTER))
201 bVisible = false;
202 bFiltered = true;
204 if (!bVisible)
205 xRowProperties->setPropertyValue(OUString(SC_ISVISIBLE), uno::makeAny(bVisible));
206 if (bFiltered)
207 xRowProperties->setPropertyValue(OUString(SC_ISFILTERED), uno::makeAny(bFiltered));
214 ScXMLTableRowsContext::ScXMLTableRowsContext( ScXMLImport& rImport,
215 sal_uInt16 nPrfx,
216 const OUString& rLName,
217 const ::com::sun::star::uno::Reference<
218 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
219 const bool bTempHeader, const bool bTempGroup ) :
220 SvXMLImportContext( rImport, nPrfx, rLName ),
221 nHeaderStartRow(0),
222 nGroupStartRow(0),
223 bHeader(bTempHeader),
224 bGroup(bTempGroup),
225 bGroupDisplay(true)
227 // don't have any attributes
228 if (bHeader)
230 ScAddress aAddr = rImport.GetTables().GetCurrentCellPos();
231 nHeaderStartRow = aAddr.Row();
232 ++nHeaderStartRow;
234 else if (bGroup)
236 nGroupStartRow = rImport.GetTables().GetCurrentRow();
237 ++nGroupStartRow;
238 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
239 for( sal_Int16 i=0; i < nAttrCount; ++i )
241 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
242 OUString aLocalName;
243 sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
244 sAttrName, &aLocalName ));
245 const OUString& sValue(xAttrList->getValueByIndex( i ));
247 if ((nPrefix == XML_NAMESPACE_TABLE) && IsXMLToken(aLocalName, XML_DISPLAY))
248 bGroupDisplay = IsXMLToken(sValue, XML_TRUE);
253 ScXMLTableRowsContext::~ScXMLTableRowsContext()
257 SvXMLImportContext *ScXMLTableRowsContext::CreateChildContext( sal_uInt16 nPrefix,
258 const OUString& rLName,
259 const ::com::sun::star::uno::Reference<
260 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
262 SvXMLImportContext *pContext(0);
264 const SvXMLTokenMap& rTokenMap(GetScImport().GetTableRowsElemTokenMap());
265 switch( rTokenMap.Get( nPrefix, rLName ) )
267 case XML_TOK_TABLE_ROWS_ROW_GROUP:
268 pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
269 rLName, xAttrList,
270 false, true );
271 break;
272 case XML_TOK_TABLE_ROWS_HEADER_ROWS:
273 pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
274 rLName, xAttrList,
275 true, false );
276 break;
277 case XML_TOK_TABLE_ROWS_ROWS:
278 pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
279 rLName, xAttrList,
280 false, false );
281 break;
282 case XML_TOK_TABLE_ROWS_ROW:
283 pContext = new ScXMLTableRowContext( GetScImport(), nPrefix,
284 rLName, xAttrList//,
285 //this
287 break;
290 if( !pContext )
291 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
293 return pContext;
296 void ScXMLTableRowsContext::EndElement()
298 ScXMLImport& rXMLImport(GetScImport());
299 if (bHeader)
301 SCROW nHeaderEndRow = rXMLImport.GetTables().GetCurrentRow();
302 if (nHeaderStartRow <= nHeaderEndRow)
304 uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
305 if (xPrintAreas.is())
307 if (!xPrintAreas->getPrintTitleRows())
309 xPrintAreas->setPrintTitleRows(true);
310 table::CellRangeAddress aRowHeaderRange;
311 aRowHeaderRange.StartRow = nHeaderStartRow;
312 aRowHeaderRange.EndRow = nHeaderEndRow;
313 xPrintAreas->setTitleRows(aRowHeaderRange);
315 else
317 table::CellRangeAddress aRowHeaderRange(xPrintAreas->getTitleRows());
318 aRowHeaderRange.EndRow = nHeaderEndRow;
319 xPrintAreas->setTitleRows(aRowHeaderRange);
324 else if (bGroup)
326 SCROW nGroupEndRow = rXMLImport.GetTables().GetCurrentRow();
327 SCTAB nSheet(rXMLImport.GetTables().GetCurrentSheet());
328 if (nGroupStartRow <= nGroupEndRow)
330 ScDocument* pDoc(GetScImport().GetDocument());
331 if (pDoc)
333 ScXMLImport::MutexGuard aGuard(GetScImport());
334 ScOutlineTable* pOutlineTable(pDoc->GetOutlineTable(nSheet, true));
335 ScOutlineArray& rRowArray(pOutlineTable->GetRowArray());
336 bool bResized;
337 rRowArray.Insert(static_cast<SCROW>(nGroupStartRow), static_cast<SCROW>(nGroupEndRow), bResized, !bGroupDisplay, true);
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */