1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
24 #include "xmlstyli.hxx"
25 #include "document.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
,
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
)),
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
));
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
:
76 case XML_TOK_TABLE_ROW_ATTR_VISIBILITY
:
81 case XML_TOK_TABLE_ROW_ATTR_REPEATED
:
83 nRepeatedRows
= std::max( sValue
.toInt32(), (sal_Int32
) 1 );
84 nRepeatedRows
= std::min( nRepeatedRows
, MAXROWCOUNT
);
87 case XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME
:
89 sCellStyleName
= sValue
;
92 /*case XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT:
94 sOptimalHeight = sValue;
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() )
121 pContext
= new ScXMLTableRowCellContext( GetScImport(), nPrefix
,
122 rLName
, xAttrList
, false, static_cast<SCROW
>(nRepeatedRows
)
127 case XML_TOK_TABLE_ROW_COVERED_CELL
:
128 // if( IsInsertCellPossible() )
131 pContext
= new ScXMLTableRowCellContext( GetScImport(), nPrefix
,
132 rLName
, xAttrList
, true, static_cast<SCROW
>(nRepeatedRows
)
140 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
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());
159 sal_Int32
nFirstRow(nCurrentRow
- nRepeatedRows
+ 1);
160 if (nFirstRow
> MAXROW
)
162 if (nCurrentRow
> MAXROW
)
163 nCurrentRow
= MAXROW
;
164 uno::Reference
<table::XCellRange
> xCellRange(xSheet
->getCellRangeByPosition(0, nFirstRow
, 0, nCurrentRow
));
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()));
178 XMLTableStyleContext
* pStyle(const_cast<XMLTableStyleContext
*>(static_cast<const XMLTableStyleContext
*>(pStyles
->FindStyleChildContext(
179 XML_STYLE_FAMILY_TABLE_ROW
, sStyleName
, true))));
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
))
199 else if (IsXMLToken(sVisibility
, XML_FILTER
))
205 xRowProperties
->setPropertyValue(OUString(SC_ISVISIBLE
), uno::makeAny(bVisible
));
207 xRowProperties
->setPropertyValue(OUString(SC_ISFILTERED
), uno::makeAny(bFiltered
));
214 ScXMLTableRowsContext::ScXMLTableRowsContext( ScXMLImport
& rImport
,
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
),
223 bHeader(bTempHeader
),
227 // don't have any attributes
230 ScAddress aAddr
= rImport
.GetTables().GetCurrentCellPos();
231 nHeaderStartRow
= aAddr
.Row();
236 nGroupStartRow
= rImport
.GetTables().GetCurrentRow();
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
));
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
,
272 case XML_TOK_TABLE_ROWS_HEADER_ROWS
:
273 pContext
= new ScXMLTableRowsContext( GetScImport(), nPrefix
,
277 case XML_TOK_TABLE_ROWS_ROWS
:
278 pContext
= new ScXMLTableRowsContext( GetScImport(), nPrefix
,
282 case XML_TOK_TABLE_ROWS_ROW
:
283 pContext
= new ScXMLTableRowContext( GetScImport(), nPrefix
,
291 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
296 void ScXMLTableRowsContext::EndElement()
298 ScXMLImport
& rXMLImport(GetScImport());
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
);
317 table::CellRangeAddress
aRowHeaderRange(xPrintAreas
->getTitleRows());
318 aRowHeaderRange
.EndRow
= nHeaderEndRow
;
319 xPrintAreas
->setTitleRows(aRowHeaderRange
);
326 SCROW nGroupEndRow
= rXMLImport
.GetTables().GetCurrentRow();
327 SCTAB
nSheet(rXMLImport
.GetTables().GetCurrentSheet());
328 if (nGroupStartRow
<= nGroupEndRow
)
330 ScDocument
* pDoc(GetScImport().GetDocument());
333 ScXMLImport::MutexGuard
aGuard(GetScImport());
334 ScOutlineTable
* pOutlineTable(pDoc
->GetOutlineTable(nSheet
, true));
335 ScOutlineArray
& rRowArray(pOutlineTable
->GetRowArray());
337 rRowArray
.Insert(static_cast<SCROW
>(nGroupStartRow
), static_cast<SCROW
>(nGroupEndRow
), bResized
, !bGroupDisplay
, true);
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */