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 3887 : 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 3887 : sVisibility(GetXMLToken(XML_VISIBLE)),
55 : nRepeatedRows(1),
56 7774 : bHasCell(false)
57 : {
58 3887 : OUString sCellStyleName;
59 3887 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
60 3887 : const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableRowAttrTokenMap());
61 8009 : for( sal_Int16 i=0; i < nAttrCount; ++i )
62 : {
63 4122 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
64 8244 : OUString aLocalName;
65 4122 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
66 4122 : sAttrName, &aLocalName ));
67 8244 : const OUString& sValue(xAttrList->getValueByIndex( i ));
68 :
69 4122 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
70 : {
71 : case XML_TOK_TABLE_ROW_ATTR_STYLE_NAME:
72 : {
73 3887 : sStyleName = sValue;
74 : }
75 3887 : 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 218 : nRepeatedRows = std::max( sValue.toInt32(), (sal_Int32) 1 );
84 218 : nRepeatedRows = std::min( nRepeatedRows, MAXROWCOUNT );
85 : }
86 218 : 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 4122 : }
99 3887 : GetScImport().GetTables().AddRow();
100 3887 : GetScImport().GetTables().SetRowStyle(sCellStyleName);
101 3887 : }
102 :
103 7774 : ScXMLTableRowContext::~ScXMLTableRowContext()
104 : {
105 7774 : }
106 :
107 14558 : 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 14558 : SvXMLImportContext *pContext(0);
113 :
114 14558 : const SvXMLTokenMap& rTokenMap(GetScImport().GetTableRowElemTokenMap());
115 14558 : switch( rTokenMap.Get( nPrefix, rLName ) )
116 : {
117 : case XML_TOK_TABLE_ROW_CELL:
118 : // if( IsInsertCellPossible() )
119 : {
120 14507 : bHasCell = true;
121 : pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
122 : rLName, xAttrList, false, static_cast<SCROW>(nRepeatedRows)
123 : //this
124 14507 : );
125 : }
126 14507 : break;
127 : case XML_TOK_TABLE_ROW_COVERED_CELL:
128 : // if( IsInsertCellPossible() )
129 : {
130 51 : bHasCell = true;
131 : pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
132 : rLName, xAttrList, true, static_cast<SCROW>(nRepeatedRows)
133 : //this
134 51 : );
135 : }
136 51 : break;
137 : }
138 :
139 14558 : if( !pContext )
140 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
141 :
142 14558 : return pContext;
143 : }
144 :
145 3887 : void ScXMLTableRowContext::EndElement()
146 : {
147 3887 : ScXMLImport& rXMLImport(GetScImport());
148 3887 : 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 3887 : SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
155 3887 : sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
156 3887 : uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
157 3887 : if(xSheet.is())
158 : {
159 3887 : sal_Int32 nFirstRow(nCurrentRow - nRepeatedRows + 1);
160 3887 : if (nFirstRow > MAXROW)
161 0 : nFirstRow = MAXROW;
162 3887 : if (nCurrentRow > MAXROW)
163 0 : nCurrentRow = MAXROW;
164 3887 : uno::Reference <table::XCellRange> xCellRange(xSheet->getCellRangeByPosition(0, nFirstRow, 0, nCurrentRow));
165 3887 : if (xCellRange.is())
166 : {
167 3887 : uno::Reference<table::XColumnRowRange> xColumnRowRange (xCellRange, uno::UNO_QUERY);
168 3887 : if (xColumnRowRange.is())
169 : {
170 3887 : uno::Reference <beans::XPropertySet> xRowProperties(xColumnRowRange->getRows(), uno::UNO_QUERY);
171 3887 : if (xRowProperties.is())
172 : {
173 3887 : if (!sStyleName.isEmpty())
174 : {
175 3887 : XMLTableStylesContext *pStyles(static_cast<XMLTableStylesContext *>(rXMLImport.GetAutoStyles()));
176 3887 : if ( pStyles )
177 : {
178 : XMLTableStyleContext* pStyle(const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
179 3887 : XML_STYLE_FAMILY_TABLE_ROW, sStyleName, true))));
180 3887 : if (pStyle)
181 : {
182 3887 : pStyle->FillPropertySet(xRowProperties);
183 :
184 3887 : if ( nSheet != pStyle->GetLastSheet() )
185 : {
186 451 : ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
187 451 : pSheetData->AddRowStyle( sStyleName, ScAddress( 0, (SCROW)nFirstRow, nSheet ) );
188 451 : pStyle->SetLastSheet(nSheet);
189 : }
190 : }
191 : }
192 : }
193 3887 : bool bVisible (true);
194 3887 : bool bFiltered (false);
195 3887 : if (IsXMLToken(sVisibility, XML_COLLAPSE))
196 : {
197 3 : bVisible = false;
198 : }
199 3884 : else if (IsXMLToken(sVisibility, XML_FILTER))
200 : {
201 14 : bVisible = false;
202 14 : bFiltered = true;
203 : }
204 3887 : if (!bVisible)
205 17 : xRowProperties->setPropertyValue(OUString(SC_ISVISIBLE), uno::makeAny(bVisible));
206 3887 : if (bFiltered)
207 14 : xRowProperties->setPropertyValue(OUString(SC_ISFILTERED), uno::makeAny(bFiltered));
208 3887 : }
209 3887 : }
210 3887 : }
211 3887 : }
212 3887 : }
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& rRowArray(pOutlineTable->GetRowArray());
336 : bool bResized;
337 8 : rRowArray.Insert(static_cast<SCROW>(nGroupStartRow), static_cast<SCROW>(nGroupEndRow), bResized, !bGroupDisplay, true);
338 : }
339 : }
340 : }
341 166 : }
342 :
343 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|