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 3020 : 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 3020 : sVisibility(GetXMLToken(XML_VISIBLE)),
57 : nRepeatedRows(1),
58 6040 : bHasCell(false)
59 : {
60 3020 : rtl::OUString sCellStyleName;
61 3020 : sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
62 3020 : const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetTableRowAttrTokenMap());
63 6130 : for( sal_Int16 i=0; i < nAttrCount; ++i )
64 : {
65 3110 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
66 3110 : rtl::OUString aLocalName;
67 3110 : sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
68 3110 : sAttrName, &aLocalName ));
69 3110 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
70 :
71 3110 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
72 : {
73 : case XML_TOK_TABLE_ROW_ATTR_STYLE_NAME:
74 : {
75 3020 : sStyleName = sValue;
76 : }
77 3020 : break;
78 : case XML_TOK_TABLE_ROW_ATTR_VISIBILITY:
79 : {
80 28 : sVisibility = sValue;
81 : }
82 28 : break;
83 : case XML_TOK_TABLE_ROW_ATTR_REPEATED:
84 : {
85 62 : nRepeatedRows = std::max( sValue.toInt32(), (sal_Int32) 1 );
86 : }
87 62 : 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 3110 : }
100 3020 : GetScImport().GetTables().AddRow();
101 3020 : GetScImport().GetTables().SetRowStyle(sCellStyleName);
102 3020 : }
103 :
104 6040 : ScXMLTableRowContext::~ScXMLTableRowContext()
105 : {
106 6040 : }
107 :
108 7508 : 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 7508 : SvXMLImportContext *pContext(0);
114 :
115 7508 : const SvXMLTokenMap& rTokenMap(GetScImport().GetTableRowElemTokenMap());
116 7508 : switch( rTokenMap.Get( nPrefix, rLName ) )
117 : {
118 : case XML_TOK_TABLE_ROW_CELL:
119 : // if( IsInsertCellPossible() )
120 : {
121 7414 : bHasCell = true;
122 : pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
123 : rLName, xAttrList, false, static_cast<SCROW>(nRepeatedRows)
124 : //this
125 7414 : );
126 : }
127 7414 : break;
128 : case XML_TOK_TABLE_ROW_COVERED_CELL:
129 : // if( IsInsertCellPossible() )
130 : {
131 94 : bHasCell = true;
132 : pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
133 : rLName, xAttrList, true, static_cast<SCROW>(nRepeatedRows)
134 : //this
135 94 : );
136 : }
137 94 : break;
138 : }
139 :
140 7508 : if( !pContext )
141 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
142 :
143 7508 : return pContext;
144 : }
145 :
146 3020 : void ScXMLTableRowContext::EndElement()
147 : {
148 3020 : ScXMLImport& rXMLImport(GetScImport());
149 3020 : 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 3020 : SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
156 3020 : sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
157 3020 : uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
158 3020 : if(xSheet.is())
159 : {
160 3020 : sal_Int32 nFirstRow(nCurrentRow - nRepeatedRows + 1);
161 3020 : if (nFirstRow > MAXROW)
162 0 : nFirstRow = MAXROW;
163 3020 : if (nCurrentRow > MAXROW)
164 0 : nCurrentRow = MAXROW;
165 3020 : uno::Reference <table::XCellRange> xCellRange(xSheet->getCellRangeByPosition(0, nFirstRow, 0, nCurrentRow));
166 3020 : if (xCellRange.is())
167 : {
168 3020 : uno::Reference<table::XColumnRowRange> xColumnRowRange (xCellRange, uno::UNO_QUERY);
169 3020 : if (xColumnRowRange.is())
170 : {
171 3020 : uno::Reference <beans::XPropertySet> xRowProperties(xColumnRowRange->getRows(), uno::UNO_QUERY);
172 3020 : if (xRowProperties.is())
173 : {
174 3020 : if (!sStyleName.isEmpty())
175 : {
176 3020 : XMLTableStylesContext *pStyles((XMLTableStylesContext *)rXMLImport.GetAutoStyles());
177 3020 : if ( pStyles )
178 : {
179 : XMLTableStyleContext* pStyle((XMLTableStyleContext *)pStyles->FindStyleChildContext(
180 3020 : XML_STYLE_FAMILY_TABLE_ROW, sStyleName, true));
181 3020 : if (pStyle)
182 : {
183 3020 : pStyle->FillPropertySet(xRowProperties);
184 :
185 3020 : if ( nSheet != pStyle->GetLastSheet() )
186 : {
187 192 : ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
188 192 : pSheetData->AddRowStyle( sStyleName, ScAddress( 0, (SCROW)nFirstRow, nSheet ) );
189 192 : pStyle->SetLastSheet(nSheet);
190 : }
191 : }
192 : }
193 : }
194 3020 : bool bVisible (true);
195 3020 : bool bFiltered (false);
196 3020 : if (IsXMLToken(sVisibility, XML_COLLAPSE))
197 : {
198 0 : bVisible = false;
199 : }
200 3020 : else if (IsXMLToken(sVisibility, XML_FILTER))
201 : {
202 28 : bVisible = false;
203 28 : bFiltered = true;
204 : }
205 3020 : if (!bVisible)
206 28 : xRowProperties->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ISVISIBLE)), uno::makeAny(bVisible));
207 3020 : if (bFiltered)
208 28 : xRowProperties->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ISFILTERED)), uno::makeAny(bFiltered));
209 3020 : }
210 3020 : }
211 3020 : }
212 3020 : }
213 3020 : }
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: */
|