update dev300-m58
[ooovba.git] / sc / source / filter / xml / xmlrowi.cxx
blobabd59379d990286e5b77d56db83cb0c10eca93e5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlrowi.cxx,v $
10 * $Revision: 1.29 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "xmlrowi.hxx"
39 #include "xmlimprt.hxx"
40 #include "xmlcelli.hxx"
41 #include "global.hxx"
42 #include "xmlstyli.hxx"
43 #include "document.hxx"
44 #include "docuno.hxx"
45 #include "olinetab.hxx"
46 #include "sheetdata.hxx"
48 #include <xmloff/xmltkmap.hxx>
49 #include <xmloff/nmspmap.hxx>
50 #include <xmloff/xmlnmspe.hxx>
51 #include <xmloff/families.hxx>
52 #include <xmloff/xmltoken.hxx>
53 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
54 #include <com/sun/star/sheet/XSpreadsheet.hpp>
55 #include <com/sun/star/table/XColumnRowRange.hpp>
56 #include <com/sun/star/sheet/XPrintAreas.hpp>
58 #include <com/sun/star/table/CellAddress.hpp>
60 #define SC_ISVISIBLE "IsVisible"
61 #define SC_OPTIMALHEIGHT "OptimalHeight"
62 #define SC_ISFILTERED "IsFiltered"
64 using namespace com::sun::star;
65 using namespace xmloff::token;
67 //------------------------------------------------------------------
69 ScXMLTableRowContext::ScXMLTableRowContext( ScXMLImport& rImport,
70 USHORT nPrfx,
71 const ::rtl::OUString& rLName,
72 const ::com::sun::star::uno::Reference<
73 ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) :
74 SvXMLImportContext( rImport, nPrfx, rLName ),
75 sVisibility(GetXMLToken(XML_VISIBLE)),
76 nRepeatedRows(1),
77 bHasCell(sal_False)
79 rtl::OUString sCellStyleName;
80 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
81 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableRowAttrTokenMap());
82 for( sal_Int16 i=0; i < nAttrCount; ++i )
84 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
85 rtl::OUString aLocalName;
86 sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
87 sAttrName, &aLocalName ));
88 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
90 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
92 case XML_TOK_TABLE_ROW_ATTR_STYLE_NAME:
94 sStyleName = sValue;
96 break;
97 case XML_TOK_TABLE_ROW_ATTR_VISIBILITY:
99 sVisibility = sValue;
101 break;
102 case XML_TOK_TABLE_ROW_ATTR_REPEATED:
104 nRepeatedRows = std::max( sValue.toInt32(), (sal_Int32) 1 );
106 break;
107 case XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME:
109 sCellStyleName = sValue;
111 break;
112 /*case XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT:
114 sOptimalHeight = sValue;
116 break;*/
119 GetScImport().GetTables().AddRow();
120 GetScImport().GetTables().SetRowStyle(sCellStyleName);
123 ScXMLTableRowContext::~ScXMLTableRowContext()
127 SvXMLImportContext *ScXMLTableRowContext::CreateChildContext( USHORT nPrefix,
128 const ::rtl::OUString& rLName,
129 const ::com::sun::star::uno::Reference<
130 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
132 SvXMLImportContext *pContext(0);
134 const SvXMLTokenMap& rTokenMap(GetScImport().GetTableRowElemTokenMap());
135 switch( rTokenMap.Get( nPrefix, rLName ) )
137 case XML_TOK_TABLE_ROW_CELL:
138 // if( IsInsertCellPossible() )
140 bHasCell = sal_True;
141 pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
142 rLName, xAttrList, sal_False, nRepeatedRows
143 //this
146 break;
147 case XML_TOK_TABLE_ROW_COVERED_CELL:
148 // if( IsInsertCellPossible() )
150 bHasCell = sal_True;
151 pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
152 rLName, xAttrList, sal_True, nRepeatedRows
153 //this
156 break;
159 if( !pContext )
160 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
162 return pContext;
165 void ScXMLTableRowContext::EndElement()
167 ScXMLImport& rXMLImport(GetScImport());
168 if (!bHasCell && nRepeatedRows > 1)
170 for (sal_Int32 i = 0; i < nRepeatedRows - 1; ++i) //one row is always added
171 GetScImport().GetTables().AddRow();
172 DBG_ERRORFILE("it seems here is a nonvalid file; possible missing of table:table-cell element");
174 sal_Int32 nSheet = rXMLImport.GetTables().GetCurrentSheet();
175 sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
176 uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
177 if(xSheet.is())
179 sal_Int32 nFirstRow(nCurrentRow - nRepeatedRows + 1);
180 if (nFirstRow > MAXROW)
181 nFirstRow = MAXROW;
182 if (nCurrentRow > MAXROW)
183 nCurrentRow = MAXROW;
184 uno::Reference <table::XCellRange> xCellRange(xSheet->getCellRangeByPosition(0, nFirstRow, 0, nCurrentRow));
185 if (xCellRange.is())
187 uno::Reference<table::XColumnRowRange> xColumnRowRange (xCellRange, uno::UNO_QUERY);
188 if (xColumnRowRange.is())
190 uno::Reference <beans::XPropertySet> xRowProperties(xColumnRowRange->getRows(), uno::UNO_QUERY);
191 if (xRowProperties.is())
193 if (sStyleName.getLength())
195 XMLTableStylesContext *pStyles((XMLTableStylesContext *)rXMLImport.GetAutoStyles());
196 if ( pStyles )
198 XMLTableStyleContext* pStyle((XMLTableStyleContext *)pStyles->FindStyleChildContext(
199 XML_STYLE_FAMILY_TABLE_ROW, sStyleName, sal_True));
200 if (pStyle)
202 pStyle->FillPropertySet(xRowProperties);
204 if ( nSheet != pStyle->GetLastSheet() )
206 ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
207 pSheetData->AddRowStyle( sStyleName, ScAddress( 0, (SCROW)nFirstRow, (SCTAB)nSheet ) );
208 pStyle->SetLastSheet(nSheet);
213 sal_Bool bVisible (sal_True);
214 sal_Bool bFiltered (sal_False);
215 if (IsXMLToken(sVisibility, XML_COLLAPSE))
217 bVisible = sal_False;
219 else if (IsXMLToken(sVisibility, XML_FILTER))
221 bVisible = sal_False;
222 bFiltered = sal_True;
224 if (!bVisible)
225 xRowProperties->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ISVISIBLE)), uno::makeAny(bVisible));
226 if (bFiltered)
227 xRowProperties->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ISFILTERED)), uno::makeAny(bFiltered));
234 ScXMLTableRowsContext::ScXMLTableRowsContext( ScXMLImport& rImport,
235 USHORT nPrfx,
236 const ::rtl::OUString& rLName,
237 const ::com::sun::star::uno::Reference<
238 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
239 const sal_Bool bTempHeader, const sal_Bool bTempGroup ) :
240 SvXMLImportContext( rImport, nPrfx, rLName ),
241 nHeaderStartRow(0),
242 nHeaderEndRow(0),
243 nGroupStartRow(0),
244 nGroupEndRow(0),
245 bHeader(bTempHeader),
246 bGroup(bTempGroup),
247 bGroupDisplay(sal_True)
249 // don't have any attributes
250 if (bHeader)
252 nHeaderStartRow = rImport.GetTables().GetCurrentRow();
253 ++nHeaderStartRow;
255 else if (bGroup)
257 nGroupStartRow = rImport.GetTables().GetCurrentRow();
258 ++nGroupStartRow;
259 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
260 for( sal_Int16 i=0; i < nAttrCount; ++i )
262 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
263 rtl::OUString aLocalName;
264 sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
265 sAttrName, &aLocalName ));
266 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
268 if ((nPrefix == XML_NAMESPACE_TABLE) && IsXMLToken(aLocalName, XML_DISPLAY))
269 bGroupDisplay = IsXMLToken(sValue, XML_TRUE);
274 ScXMLTableRowsContext::~ScXMLTableRowsContext()
278 SvXMLImportContext *ScXMLTableRowsContext::CreateChildContext( USHORT nPrefix,
279 const ::rtl::OUString& rLName,
280 const ::com::sun::star::uno::Reference<
281 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
283 SvXMLImportContext *pContext(0);
285 const SvXMLTokenMap& rTokenMap(GetScImport().GetTableRowsElemTokenMap());
286 switch( rTokenMap.Get( nPrefix, rLName ) )
288 case XML_TOK_TABLE_ROWS_ROW_GROUP:
289 pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
290 rLName, xAttrList,
291 sal_False, sal_True );
292 break;
293 case XML_TOK_TABLE_ROWS_HEADER_ROWS:
294 pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
295 rLName, xAttrList,
296 sal_True, sal_False );
297 break;
298 case XML_TOK_TABLE_ROWS_ROWS:
299 pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
300 rLName, xAttrList,
301 sal_False, sal_False );
302 break;
303 case XML_TOK_TABLE_ROWS_ROW:
304 pContext = new ScXMLTableRowContext( GetScImport(), nPrefix,
305 rLName, xAttrList//,
306 //this
308 break;
311 if( !pContext )
312 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
314 return pContext;
317 void ScXMLTableRowsContext::EndElement()
319 ScXMLImport& rXMLImport(GetScImport());
320 if (bHeader)
322 nHeaderEndRow = rXMLImport.GetTables().GetCurrentRow();
323 if (nHeaderStartRow <= nHeaderEndRow)
325 uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
326 if (xPrintAreas.is())
328 if (!xPrintAreas->getPrintTitleRows())
330 xPrintAreas->setPrintTitleRows(sal_True);
331 table::CellRangeAddress aRowHeaderRange;
332 aRowHeaderRange.StartRow = nHeaderStartRow;
333 aRowHeaderRange.EndRow = nHeaderEndRow;
334 xPrintAreas->setTitleRows(aRowHeaderRange);
336 else
338 table::CellRangeAddress aRowHeaderRange(xPrintAreas->getTitleRows());
339 aRowHeaderRange.EndRow = nHeaderEndRow;
340 xPrintAreas->setTitleRows(aRowHeaderRange);
345 else if (bGroup)
347 nGroupEndRow = rXMLImport.GetTables().GetCurrentRow();
348 sal_Int32 nSheet(rXMLImport.GetTables().GetCurrentSheet());
349 if (nGroupStartRow <= nGroupEndRow)
351 ScDocument* pDoc(GetScImport().GetDocument());
352 if (pDoc)
354 GetScImport().LockSolarMutex();
355 ScOutlineTable* pOutlineTable(pDoc->GetOutlineTable(static_cast<SCTAB>(nSheet), sal_True));
356 ScOutlineArray* pRowArray(pOutlineTable->GetRowArray());
357 sal_Bool bResized;
358 pRowArray->Insert(static_cast<SCROW>(nGroupStartRow), static_cast<SCROW>(nGroupEndRow), bResized, !bGroupDisplay, sal_True);
359 GetScImport().UnlockSolarMutex();