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