1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlrowi.cxx,v $
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"
42 #include "xmlstyli.hxx"
43 #include "document.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
,
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
)),
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
:
97 case XML_TOK_TABLE_ROW_ATTR_VISIBILITY
:
102 case XML_TOK_TABLE_ROW_ATTR_REPEATED
:
104 nRepeatedRows
= std::max( sValue
.toInt32(), (sal_Int32
) 1 );
107 case XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME
:
109 sCellStyleName
= sValue
;
112 /*case XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT:
114 sOptimalHeight = sValue;
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() )
141 pContext
= new ScXMLTableRowCellContext( GetScImport(), nPrefix
,
142 rLName
, xAttrList
, sal_False
, nRepeatedRows
147 case XML_TOK_TABLE_ROW_COVERED_CELL
:
148 // if( IsInsertCellPossible() )
151 pContext
= new ScXMLTableRowCellContext( GetScImport(), nPrefix
,
152 rLName
, xAttrList
, sal_True
, nRepeatedRows
160 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
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());
179 sal_Int32
nFirstRow(nCurrentRow
- nRepeatedRows
+ 1);
180 if (nFirstRow
> MAXROW
)
182 if (nCurrentRow
> MAXROW
)
183 nCurrentRow
= MAXROW
;
184 uno::Reference
<table::XCellRange
> xCellRange(xSheet
->getCellRangeByPosition(0, nFirstRow
, 0, nCurrentRow
));
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());
198 XMLTableStyleContext
* pStyle((XMLTableStyleContext
*)pStyles
->FindStyleChildContext(
199 XML_STYLE_FAMILY_TABLE_ROW
, sStyleName
, sal_True
));
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
;
225 xRowProperties
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ISVISIBLE
)), uno::makeAny(bVisible
));
227 xRowProperties
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ISFILTERED
)), uno::makeAny(bFiltered
));
234 ScXMLTableRowsContext::ScXMLTableRowsContext( ScXMLImport
& rImport
,
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
),
245 bHeader(bTempHeader
),
247 bGroupDisplay(sal_True
)
249 // don't have any attributes
252 nHeaderStartRow
= rImport
.GetTables().GetCurrentRow();
257 nGroupStartRow
= rImport
.GetTables().GetCurrentRow();
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
,
291 sal_False
, sal_True
);
293 case XML_TOK_TABLE_ROWS_HEADER_ROWS
:
294 pContext
= new ScXMLTableRowsContext( GetScImport(), nPrefix
,
296 sal_True
, sal_False
);
298 case XML_TOK_TABLE_ROWS_ROWS
:
299 pContext
= new ScXMLTableRowsContext( GetScImport(), nPrefix
,
301 sal_False
, sal_False
);
303 case XML_TOK_TABLE_ROWS_ROW
:
304 pContext
= new ScXMLTableRowContext( GetScImport(), nPrefix
,
312 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
317 void ScXMLTableRowsContext::EndElement()
319 ScXMLImport
& rXMLImport(GetScImport());
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
);
338 table::CellRangeAddress
aRowHeaderRange(xPrintAreas
->getTitleRows());
339 aRowHeaderRange
.EndRow
= nHeaderEndRow
;
340 xPrintAreas
->setTitleRows(aRowHeaderRange
);
347 nGroupEndRow
= rXMLImport
.GetTables().GetCurrentRow();
348 sal_Int32
nSheet(rXMLImport
.GetTables().GetCurrentSheet());
349 if (nGroupStartRow
<= nGroupEndRow
)
351 ScDocument
* pDoc(GetScImport().GetDocument());
354 GetScImport().LockSolarMutex();
355 ScOutlineTable
* pOutlineTable(pDoc
->GetOutlineTable(static_cast<SCTAB
>(nSheet
), sal_True
));
356 ScOutlineArray
* pRowArray(pOutlineTable
->GetRowArray());
358 pRowArray
->Insert(static_cast<SCROW
>(nGroupStartRow
), static_cast<SCROW
>(nGroupEndRow
), bResized
, !bGroupDisplay
, sal_True
);
359 GetScImport().UnlockSolarMutex();