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 "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"
29 :
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>
39 :
40 : #include <com/sun/star/table/CellAddress.hpp>
41 :
42 : #define SC_ISVISIBLE "IsVisible"
43 : #define SC_ISFILTERED "IsFiltered"
44 :
45 : using namespace com::sun::star;
46 : using namespace xmloff::token;
47 :
48 2719 : 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 2719 : sVisibility(GetXMLToken(XML_VISIBLE)),
55 : nRepeatedRows(1),
56 5438 : bHasCell(false)
57 : {
58 2719 : OUString sCellStyleName;
59 2719 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
60 2719 : const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableRowAttrTokenMap());
61 5613 : for( sal_Int16 i=0; i < nAttrCount; ++i )
62 : {
63 2894 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
64 5788 : OUString aLocalName;
65 2894 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
66 2894 : sAttrName, &aLocalName ));
67 5788 : const OUString& sValue(xAttrList->getValueByIndex( i ));
68 :
69 2894 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
70 : {
71 : case XML_TOK_TABLE_ROW_ATTR_STYLE_NAME:
72 : {
73 2719 : sStyleName = sValue;
74 : }
75 2719 : break;
76 : case XML_TOK_TABLE_ROW_ATTR_VISIBILITY:
77 : {
78 17 : sVisibility = sValue;
79 : }
80 17 : break;
81 : case XML_TOK_TABLE_ROW_ATTR_REPEATED:
82 : {
83 158 : nRepeatedRows = std::max( sValue.toInt32(), (sal_Int32) 1 );
84 158 : nRepeatedRows = std::min( nRepeatedRows, MAXROWCOUNT );
85 : }
86 158 : break;
87 : case XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME:
88 : {
89 0 : sCellStyleName = sValue;
90 : }
91 0 : break;
92 : /*case XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT:
93 : {
94 : sOptimalHeight = sValue;
95 : }
96 : break;*/
97 : }
98 2894 : }
99 2719 : GetScImport().GetTables().AddRow();
100 2719 : GetScImport().GetTables().SetRowStyle(sCellStyleName);
101 2719 : }
102 :
103 5438 : ScXMLTableRowContext::~ScXMLTableRowContext()
104 : {
105 5438 : }
106 :
107 8860 : 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 )
111 : {
112 8860 : SvXMLImportContext *pContext(0);
113 :
114 8860 : const SvXMLTokenMap& rTokenMap(GetScImport().GetTableRowElemTokenMap());
115 8860 : switch( rTokenMap.Get( nPrefix, rLName ) )
116 : {
117 : case XML_TOK_TABLE_ROW_CELL:
118 : // if( IsInsertCellPossible() )
119 : {
120 8811 : bHasCell = true;
121 : pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
122 : rLName, xAttrList, false, static_cast<SCROW>(nRepeatedRows)
123 : //this
124 8811 : );
125 : }
126 8811 : break;
127 : case XML_TOK_TABLE_ROW_COVERED_CELL:
128 : // if( IsInsertCellPossible() )
129 : {
130 49 : bHasCell = true;
131 : pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
132 : rLName, xAttrList, true, static_cast<SCROW>(nRepeatedRows)
133 : //this
134 49 : );
135 : }
136 49 : break;
137 : }
138 :
139 8860 : if( !pContext )
140 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
141 :
142 8860 : return pContext;
143 : }
144 :
145 2719 : void ScXMLTableRowContext::EndElement()
146 : {
147 2719 : ScXMLImport& rXMLImport(GetScImport());
148 2719 : if (!bHasCell && nRepeatedRows > 1)
149 : {
150 0 : for (sal_Int32 i = 0; i < nRepeatedRows - 1; ++i) //one row is always added
151 0 : GetScImport().GetTables().AddRow();
152 : OSL_FAIL("it seems here is a nonvalid file; possible missing of table:table-cell element");
153 : }
154 2719 : SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
155 2719 : sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
156 2719 : uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
157 2719 : if(xSheet.is())
158 : {
159 2719 : sal_Int32 nFirstRow(nCurrentRow - nRepeatedRows + 1);
160 2719 : if (nFirstRow > MAXROW)
161 0 : nFirstRow = MAXROW;
162 2719 : if (nCurrentRow > MAXROW)
163 0 : nCurrentRow = MAXROW;
164 2719 : uno::Reference <table::XCellRange> xCellRange(xSheet->getCellRangeByPosition(0, nFirstRow, 0, nCurrentRow));
165 2719 : if (xCellRange.is())
166 : {
167 2719 : uno::Reference<table::XColumnRowRange> xColumnRowRange (xCellRange, uno::UNO_QUERY);
168 2719 : if (xColumnRowRange.is())
169 : {
170 2719 : uno::Reference <beans::XPropertySet> xRowProperties(xColumnRowRange->getRows(), uno::UNO_QUERY);
171 2719 : if (xRowProperties.is())
172 : {
173 2719 : if (!sStyleName.isEmpty())
174 : {
175 2719 : XMLTableStylesContext *pStyles((XMLTableStylesContext *)rXMLImport.GetAutoStyles());
176 2719 : if ( pStyles )
177 : {
178 : XMLTableStyleContext* pStyle((XMLTableStyleContext *)pStyles->FindStyleChildContext(
179 2719 : XML_STYLE_FAMILY_TABLE_ROW, sStyleName, true));
180 2719 : if (pStyle)
181 : {
182 2719 : pStyle->FillPropertySet(xRowProperties);
183 :
184 2719 : if ( nSheet != pStyle->GetLastSheet() )
185 : {
186 320 : ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
187 320 : pSheetData->AddRowStyle( sStyleName, ScAddress( 0, (SCROW)nFirstRow, nSheet ) );
188 320 : pStyle->SetLastSheet(nSheet);
189 : }
190 : }
191 : }
192 : }
193 2719 : bool bVisible (true);
194 2719 : bool bFiltered (false);
195 2719 : if (IsXMLToken(sVisibility, XML_COLLAPSE))
196 : {
197 3 : bVisible = false;
198 : }
199 2716 : else if (IsXMLToken(sVisibility, XML_FILTER))
200 : {
201 14 : bVisible = false;
202 14 : bFiltered = true;
203 : }
204 2719 : if (!bVisible)
205 17 : xRowProperties->setPropertyValue(OUString(SC_ISVISIBLE), uno::makeAny(bVisible));
206 2719 : if (bFiltered)
207 14 : xRowProperties->setPropertyValue(OUString(SC_ISFILTERED), uno::makeAny(bFiltered));
208 2719 : }
209 2719 : }
210 2719 : }
211 2719 : }
212 2719 : }
213 :
214 10 : 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 10 : bGroupDisplay(true)
226 : {
227 : // don't have any attributes
228 10 : if (bHeader)
229 : {
230 2 : ScAddress aAddr = rImport.GetTables().GetCurrentCellPos();
231 2 : nHeaderStartRow = aAddr.Row();
232 2 : ++nHeaderStartRow;
233 : }
234 8 : else if (bGroup)
235 : {
236 8 : nGroupStartRow = rImport.GetTables().GetCurrentRow();
237 8 : ++nGroupStartRow;
238 8 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
239 9 : for( sal_Int16 i=0; i < nAttrCount; ++i )
240 : {
241 1 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
242 2 : OUString aLocalName;
243 1 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
244 1 : sAttrName, &aLocalName ));
245 2 : const OUString& sValue(xAttrList->getValueByIndex( i ));
246 :
247 1 : if ((nPrefix == XML_NAMESPACE_TABLE) && IsXMLToken(aLocalName, XML_DISPLAY))
248 1 : bGroupDisplay = IsXMLToken(sValue, XML_TRUE);
249 1 : }
250 : }
251 10 : }
252 :
253 20 : ScXMLTableRowsContext::~ScXMLTableRowsContext()
254 : {
255 20 : }
256 :
257 26 : 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 )
261 : {
262 26 : SvXMLImportContext *pContext(0);
263 :
264 26 : const SvXMLTokenMap& rTokenMap(GetScImport().GetTableRowsElemTokenMap());
265 26 : switch( rTokenMap.Get( nPrefix, rLName ) )
266 : {
267 : case XML_TOK_TABLE_ROWS_ROW_GROUP:
268 : pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
269 : rLName, xAttrList,
270 6 : false, true );
271 6 : break;
272 : case XML_TOK_TABLE_ROWS_HEADER_ROWS:
273 : pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
274 : rLName, xAttrList,
275 0 : true, false );
276 0 : break;
277 : case XML_TOK_TABLE_ROWS_ROWS:
278 : pContext = new ScXMLTableRowsContext( GetScImport(), nPrefix,
279 : rLName, xAttrList,
280 0 : false, false );
281 0 : break;
282 : case XML_TOK_TABLE_ROWS_ROW:
283 : pContext = new ScXMLTableRowContext( GetScImport(), nPrefix,
284 : rLName, xAttrList//,
285 : //this
286 20 : );
287 20 : break;
288 : }
289 :
290 26 : if( !pContext )
291 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
292 :
293 26 : return pContext;
294 : }
295 :
296 10 : void ScXMLTableRowsContext::EndElement()
297 : {
298 10 : ScXMLImport& rXMLImport(GetScImport());
299 10 : if (bHeader)
300 : {
301 2 : SCROW nHeaderEndRow = rXMLImport.GetTables().GetCurrentRow();
302 2 : if (nHeaderStartRow <= nHeaderEndRow)
303 : {
304 2 : uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
305 2 : if (xPrintAreas.is())
306 : {
307 2 : if (!xPrintAreas->getPrintTitleRows())
308 : {
309 2 : xPrintAreas->setPrintTitleRows(true);
310 2 : table::CellRangeAddress aRowHeaderRange;
311 2 : aRowHeaderRange.StartRow = nHeaderStartRow;
312 2 : aRowHeaderRange.EndRow = nHeaderEndRow;
313 2 : xPrintAreas->setTitleRows(aRowHeaderRange);
314 : }
315 : else
316 : {
317 0 : table::CellRangeAddress aRowHeaderRange(xPrintAreas->getTitleRows());
318 0 : aRowHeaderRange.EndRow = nHeaderEndRow;
319 0 : xPrintAreas->setTitleRows(aRowHeaderRange);
320 : }
321 2 : }
322 : }
323 : }
324 8 : else if (bGroup)
325 : {
326 8 : SCROW nGroupEndRow = rXMLImport.GetTables().GetCurrentRow();
327 8 : SCTAB nSheet(rXMLImport.GetTables().GetCurrentSheet());
328 8 : if (nGroupStartRow <= nGroupEndRow)
329 : {
330 8 : ScDocument* pDoc(GetScImport().GetDocument());
331 8 : if (pDoc)
332 : {
333 8 : ScXMLImport::MutexGuard aGuard(GetScImport());
334 8 : ScOutlineTable* pOutlineTable(pDoc->GetOutlineTable(nSheet, true));
335 8 : ScOutlineArray* pRowArray(pOutlineTable->GetRowArray());
336 : bool bResized;
337 8 : pRowArray->Insert(static_cast<SCROW>(nGroupStartRow), static_cast<SCROW>(nGroupEndRow), bResized, !bGroupDisplay, true);
338 : }
339 : }
340 : }
341 10 : }
342 :
343 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|