LibreOffice Module sc (master) 1
xmlrowi.cxx
Go to the documentation of this file.
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 "xmlstyli.hxx"
24#include "xmlstyle.hxx"
25#include <document.hxx>
26#include <docuno.hxx>
27#include <olinetab.hxx>
28#include <sheetdata.hxx>
29#include <documentimport.hxx>
30#include <unonames.hxx>
31
35#include <xmloff/families.hxx>
36#include <xmloff/xmltoken.hxx>
37#include <sax/fastattribs.hxx>
38#include <com/sun/star/sheet/XSpreadsheet.hpp>
39#include <com/sun/star/table/XColumnRowRange.hpp>
40#include <com/sun/star/sheet/XPrintAreas.hpp>
42#include <osl/diagnose.h>
43
44constexpr OUStringLiteral SC_ISFILTERED = u"IsFiltered";
45
46using namespace com::sun::star;
47using namespace xmloff::token;
48
51 ScXMLImportContext( rImport ),
52 sVisibility(GetXMLToken(XML_VISIBLE)),
53 nRepeatedRows(1),
54 bHasCell(false)
55{
56 OUString sCellStyleName;
57 if ( rAttrList.is() )
58 {
59 for (auto &it : *rAttrList)
60 {
61 switch (it.getToken())
62 {
64 {
65 sStyleName = it.toString();
66 }
67 break;
69 {
70 sVisibility = it.toString();
71 }
72 break;
74 {
75 nRepeatedRows = std::max( it.toInt32(), sal_Int32(1) );
78 nRepeatedRows = std::min(nRepeatedRows, sal_Int32(1024));
79 }
80 break;
82 {
83 sCellStyleName = it.toString();
84 }
85 break;
86 /*case XML_ELEMENT( TABLE, XML_USE_OPTIMAL_HEIGHT ):
87 {
88 sOptimalHeight = it.toString();
89 }
90 break;*/
91 }
92 }
93 }
94
96 GetScImport().GetTables().SetRowStyle(sCellStyleName);
97}
98
100{
101}
102
103uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
105 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
106{
107 SvXMLImportContext *pContext(nullptr);
110
111 switch( nElement )
112 {
114// if( IsInsertCellPossible() )
115 {
116 bHasCell = true;
117 pContext = new ScXMLTableRowCellContext( GetScImport(),
118 pAttribList, false, static_cast<SCROW>(nRepeatedRows)
119 //this
120 );
121 }
122 break;
124// if( IsInsertCellPossible() )
125 {
126 bHasCell = true;
127 pContext = new ScXMLTableRowCellContext( GetScImport(),
128 pAttribList, true, static_cast<SCROW>(nRepeatedRows)
129 //this
130 );
131 }
132 break;
133 }
134
135 return pContext;
136}
137
138void SAL_CALL ScXMLTableRowContext::endFastElement(sal_Int32 /*nElement*/)
139{
140 ScXMLImport& rXMLImport(GetScImport());
141 ScDocument* pDoc(rXMLImport.GetDocument());
142 if (!bHasCell && nRepeatedRows > 1)
143 {
144 for (sal_Int32 i = 0; i < nRepeatedRows - 1; ++i) //one row is always added
146 OSL_FAIL("it seems here is a nonvalid file; possible missing of table:table-cell element");
147 }
148 SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
149 sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
150 uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
151 if(!xSheet.is())
152 return;
153
154 sal_Int32 nFirstRow(nCurrentRow - nRepeatedRows + 1);
155 if (nFirstRow > pDoc->MaxRow())
156 nFirstRow = pDoc->MaxRow();
157 if (nCurrentRow > pDoc->MaxRow())
158 nCurrentRow = pDoc->MaxRow();
159 uno::Reference <table::XCellRange> xCellRange(xSheet->getCellRangeByPosition(0, nFirstRow, 0, nCurrentRow));
160 if (!xCellRange.is())
161 return;
162
163 uno::Reference<table::XColumnRowRange> xColumnRowRange (xCellRange, uno::UNO_QUERY);
164 if (!xColumnRowRange.is())
165 return;
166
167 uno::Reference <beans::XPropertySet> xRowProperties(xColumnRowRange->getRows(), uno::UNO_QUERY);
168 if (!xRowProperties.is())
169 return;
170
171 XMLTableStyleContext* ptmpStyle = nullptr;
172
173 if (!sStyleName.isEmpty())
174 {
175 XMLTableStylesContext *pStyles(static_cast<XMLTableStylesContext *>(rXMLImport.GetAutoStyles()));
176 if ( pStyles )
177 {
178 XMLTableStyleContext* pStyle(const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
179 XmlStyleFamily::TABLE_ROW, sStyleName, true))));
180 if (pStyle)
181 {
182 pStyle->FillPropertySet(xRowProperties);
183
184 if ( nSheet != pStyle->GetLastSheet() )
185 {
186 ScSheetSaveData* pSheetData = comphelper::getFromUnoTunnel<ScModelObj>(rXMLImport.GetModel())->GetSheetSaveData();
187 pSheetData->AddRowStyle( sStyleName, ScAddress( 0, static_cast<SCROW>(nFirstRow), nSheet ) );
188 pStyle->SetLastSheet(nSheet);
189 }
190
191 // for later checking of optimal row height
192 ptmpStyle = pStyle;
193 }
194 }
195 }
196 bool bVisible (true);
197 bool bFiltered (false);
199 {
200 bVisible = false;
201 }
203 {
204 bVisible = false;
205 bFiltered = true;
206 }
207 if (!bVisible)
208 {
209 rXMLImport.GetDoc().setRowsVisible(nSheet, nFirstRow, nCurrentRow, false);
210 }
211 if (bFiltered)
212 xRowProperties->setPropertyValue(SC_ISFILTERED, uno::Any(bFiltered));
213
214 uno::Any any = xRowProperties->getPropertyValue(SC_UNONAME_OHEIGHT);
215 bool bOptionalHeight = false;
216 any >>= bOptionalHeight;
217 if (bOptionalHeight)
218 {
219 // Save this row for later height update, only if we have no already optimal row heights
220 // If we have already optimal row heights, recalc only the first 200 row in case of optimal document loading
221 std::vector<ScDocRowHeightUpdater::TabRanges>& rRecalcRanges = rXMLImport.GetRecalcRowRanges();
222 while (static_cast<SCTAB>(rRecalcRanges.size()) <= nSheet)
223 {
224 rRecalcRanges.emplace_back(0, pDoc->MaxRow());
225 }
226 rRecalcRanges.at(nSheet).mnTab = nSheet;
227
228 // check that, we already have valid optimal row heights
229 if (nCurrentRow > 200 && ptmpStyle && !ptmpStyle->FindProperty(CTF_SC_ROWHEIGHT))
230 {
231 XMLPropertyState* pOptimalHeight = ptmpStyle->FindProperty(CTF_SC_ROWOPTIMALHEIGHT);
232 if (pOptimalHeight && ::cppu::any2bool(pOptimalHeight->maValue))
233 {
234 rRecalcRanges.at(nSheet).maRanges.setFalse(nFirstRow, nCurrentRow);
235 }
236 else
237 {
238 rRecalcRanges.at(nSheet).maRanges.setTrue(nFirstRow, nCurrentRow);
239 }
240 }
241 else
242 {
243 rRecalcRanges.at(nSheet).maRanges.setTrue(nFirstRow, nCurrentRow);
244 }
245 }
246}
247
250 const bool bTempHeader,
251 const bool bTempGroup ) :
252 ScXMLImportContext( rImport ),
253 nHeaderStartRow(0),
254 nGroupStartRow(0),
255 bHeader(bTempHeader),
256 bGroup(bTempGroup),
257 bGroupDisplay(true)
258{
259 // don't have any attributes
260 if (bHeader)
261 {
262 ScAddress aAddr = rImport.GetTables().GetCurrentCellPos();
263 nHeaderStartRow = aAddr.Row();
265 }
266 else if (bGroup)
267 {
270 if ( rAttrList.is() )
271 {
272 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_DISPLAY ) ) );
273 if (aIter != rAttrList->end())
275 }
276 }
277}
278
280{
281}
282
283uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
285 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
286{
287 SvXMLImportContext *pContext(nullptr);
290
291 switch( nElement )
292 {
294 pContext = new ScXMLTableRowsContext( GetScImport(), pAttribList,
295 false, true );
296 break;
298 pContext = new ScXMLTableRowsContext( GetScImport(), pAttribList,
299 true, false );
300 break;
302 pContext = new ScXMLTableRowsContext( GetScImport(), pAttribList,
303 false, false );
304 break;
306 pContext = new ScXMLTableRowContext( GetScImport(), pAttribList );
307 break;
308 }
309
310 return pContext;
311}
312
313void SAL_CALL ScXMLTableRowsContext::endFastElement(sal_Int32 /*nElement*/)
314{
315 ScXMLImport& rXMLImport(GetScImport());
316 if (bHeader)
317 {
318 SCROW nHeaderEndRow = rXMLImport.GetTables().GetCurrentRow();
319 if (nHeaderStartRow <= nHeaderEndRow)
320 {
321 uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
322 if (xPrintAreas.is())
323 {
324 if (!xPrintAreas->getPrintTitleRows())
325 {
326 xPrintAreas->setPrintTitleRows(true);
327 table::CellRangeAddress aRowHeaderRange;
328 aRowHeaderRange.StartRow = nHeaderStartRow;
329 aRowHeaderRange.EndRow = nHeaderEndRow;
330 xPrintAreas->setTitleRows(aRowHeaderRange);
331 }
332 else
333 {
334 table::CellRangeAddress aRowHeaderRange(xPrintAreas->getTitleRows());
335 aRowHeaderRange.EndRow = nHeaderEndRow;
336 xPrintAreas->setTitleRows(aRowHeaderRange);
337 }
338 }
339 }
340 }
341 else if (bGroup)
342 {
343 SCROW nGroupEndRow = rXMLImport.GetTables().GetCurrentRow();
344 SCTAB nSheet(rXMLImport.GetTables().GetCurrentSheet());
345 if (nGroupStartRow <= nGroupEndRow)
346 {
347 ScDocument* pDoc(GetScImport().GetDocument());
348 if (pDoc)
349 {
351 ScOutlineTable* pOutlineTable(pDoc->GetOutlineTable(nSheet, true));
352 ScOutlineArray& rRowArray(pOutlineTable->GetRowArray());
353 bool bResized;
354 rRowArray.Insert(nGroupStartRow, nGroupEndRow, bResized, !bGroupDisplay);
355 }
356 }
357 }
358}
359
360/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Any & any
SCROW Row() const
Definition: address.hxx:274
void setRowsVisible(SCTAB nTab, SCROW nRowStart, SCROW nRowEnd, bool bVisible)
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:898
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
SC_DLLPUBLIC ScOutlineTable * GetOutlineTable(SCTAB nTab, bool bCreate=false)
Definition: documen3.cxx:737
const ScAddress & GetCurrentCellPos() const
Definition: xmlsubti.hxx:80
SCROW GetCurrentRow() const
Definition: xmlsubti.hxx:86
SCTAB GetCurrentSheet() const
Definition: xmlsubti.hxx:84
const css::uno::Reference< css::sheet::XSpreadsheet > & GetCurrentXSheet() const
Definition: xmlsubti.hxx:88
void AddRow()
Definition: xmlsubti.cxx:162
void SetRowStyle(const OUString &rCellStyleName)
Definition: xmlsubti.cxx:168
bool Insert(SCCOLROW nStartPos, SCCOLROW nEndPos, bool &rSizeChanged, bool bHidden=false)
Definition: olinetab.cxx:197
const ScOutlineArray & GetRowArray() const
Definition: olinetab.hxx:160
void AddRowStyle(const OUString &rName, const ScAddress &rCellPos)
Definition: sheetdata.cxx:51
This class exists only to provide GetScImport() to its derived classes.
ScXMLImport & GetScImport()
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:289
ScDocumentImport & GetDoc()
Definition: xmlimprt.cxx:506
std::vector< ScDocRowHeightUpdater::TabRanges > & GetRecalcRowRanges()
Definition: xmlimprt.hxx:210
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
ScMyTables & GetTables()
Definition: xmlimprt.hxx:208
ScXMLTableRowContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
Definition: xmlrowi.cxx:49
sal_Int32 nRepeatedRows
Definition: xmlrowi.hxx:31
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlrowi.cxx:138
OUString sStyleName
Definition: xmlrowi.hxx:29
virtual ~ScXMLTableRowContext() override
Definition: xmlrowi.cxx:99
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlrowi.cxx:104
OUString sVisibility
Definition: xmlrowi.hxx:30
virtual ~ScXMLTableRowsContext() override
Definition: xmlrowi.cxx:279
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlrowi.cxx:284
ScXMLTableRowsContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, const bool bHeader, const bool bGroup)
Definition: xmlrowi.cxx:248
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlrowi.cxx:313
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
SCTAB GetLastSheet() const
Definition: xmlstyli.hxx:104
XMLPropertyState * FindProperty(const sal_Int16 nContextID)
Definition: xmlstyli.cxx:569
void SetLastSheet(SCTAB nNew)
Definition: xmlstyli.hxx:105
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
Definition: xmlstyli.cxx:519
static bool IsFuzzing()
float u
TABLE
int i
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_COLLAPSE
XML_TABLE_ROW
XML_COVERED_TABLE_CELL
XML_FILTER
XML_DISPLAY
XML_TRUE
XML_VISIBILITY
XML_DEFAULT_CELL_STYLE_NAME
XML_TABLE_ROW_GROUP
XML_STYLE_NAME
XML_VISIBLE
XML_TABLE_HEADER_ROWS
XML_NUMBER_ROWS_REPEATED
XML_TABLE_ROWS
XML_TABLE_CELL
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
SCROW GetMaxRowCount() const
Definition: sheetlimits.hxx:66
css::uno::Any maValue
bool bVisible
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int32 SCROW
Definition: types.hxx:17
constexpr OUStringLiteral SC_UNONAME_OHEIGHT
Definition: unonames.hxx:178
#define XML_ELEMENT(prefix, name)
constexpr OUStringLiteral SC_ISFILTERED
Definition: xmlrowi.cxx:44
#define CTF_SC_ROWHEIGHT
Definition: xmlstyle.hxx:89
#define CTF_SC_ROWOPTIMALHEIGHT
Definition: xmlstyle.hxx:90