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 <document.hxx>
25#include <docuno.hxx>
26#include <olinetab.hxx>
27#include <sheetdata.hxx>
28#include <documentimport.hxx>
29#include <unonames.hxx>
30
33#include <xmloff/families.hxx>
34#include <xmloff/xmltoken.hxx>
35#include <sax/fastattribs.hxx>
36#include <com/sun/star/sheet/XSpreadsheet.hpp>
37#include <com/sun/star/table/XColumnRowRange.hpp>
38#include <com/sun/star/sheet/XPrintAreas.hpp>
40#include <osl/diagnose.h>
41
42constexpr OUStringLiteral SC_ISFILTERED = u"IsFiltered";
43
44using namespace com::sun::star;
45using namespace xmloff::token;
46
49 ScXMLImportContext( rImport ),
50 sVisibility(GetXMLToken(XML_VISIBLE)),
51 nRepeatedRows(1),
52 bHasCell(false)
53{
54 OUString sCellStyleName;
55 if ( rAttrList.is() )
56 {
57 for (auto &it : *rAttrList)
58 {
59 switch (it.getToken())
60 {
62 {
63 sStyleName = it.toString();
64 }
65 break;
67 {
68 sVisibility = it.toString();
69 }
70 break;
72 {
73 nRepeatedRows = std::max( it.toInt32(), sal_Int32(1) );
76 nRepeatedRows = std::min(nRepeatedRows, sal_Int32(1024));
77 }
78 break;
80 {
81 sCellStyleName = it.toString();
82 }
83 break;
84 /*case XML_ELEMENT( TABLE, XML_USE_OPTIMAL_HEIGHT ):
85 {
86 sOptimalHeight = it.toString();
87 }
88 break;*/
89 }
90 }
91 }
92
94 GetScImport().GetTables().SetRowStyle(sCellStyleName);
95}
96
98{
99}
100
101uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
103 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
104{
105 SvXMLImportContext *pContext(nullptr);
108
109 switch( nElement )
110 {
112// if( IsInsertCellPossible() )
113 {
114 bHasCell = true;
115 pContext = new ScXMLTableRowCellContext( GetScImport(),
116 pAttribList, false, static_cast<SCROW>(nRepeatedRows)
117 //this
118 );
119 }
120 break;
122// if( IsInsertCellPossible() )
123 {
124 bHasCell = true;
125 pContext = new ScXMLTableRowCellContext( GetScImport(),
126 pAttribList, true, static_cast<SCROW>(nRepeatedRows)
127 //this
128 );
129 }
130 break;
131 }
132
133 return pContext;
134}
135
136void SAL_CALL ScXMLTableRowContext::endFastElement(sal_Int32 /*nElement*/)
137{
138 ScXMLImport& rXMLImport(GetScImport());
139 ScDocument* pDoc(rXMLImport.GetDocument());
140 if (!bHasCell && nRepeatedRows > 1)
141 {
142 for (sal_Int32 i = 0; i < nRepeatedRows - 1; ++i) //one row is always added
144 OSL_FAIL("it seems here is a nonvalid file; possible missing of table:table-cell element");
145 }
146 SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
147 sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
148 uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
149 if(!xSheet.is())
150 return;
151
152 sal_Int32 nFirstRow(nCurrentRow - nRepeatedRows + 1);
153 if (nFirstRow > pDoc->MaxRow())
154 nFirstRow = pDoc->MaxRow();
155 if (nCurrentRow > pDoc->MaxRow())
156 nCurrentRow = pDoc->MaxRow();
157 uno::Reference <table::XCellRange> xCellRange(xSheet->getCellRangeByPosition(0, nFirstRow, 0, nCurrentRow));
158 if (!xCellRange.is())
159 return;
160
161 uno::Reference<table::XColumnRowRange> xColumnRowRange (xCellRange, uno::UNO_QUERY);
162 if (!xColumnRowRange.is())
163 return;
164
165 uno::Reference <beans::XPropertySet> xRowProperties(xColumnRowRange->getRows(), uno::UNO_QUERY);
166 if (!xRowProperties.is())
167 return;
168
169 if (!sStyleName.isEmpty())
170 {
171 XMLTableStylesContext *pStyles(static_cast<XMLTableStylesContext *>(rXMLImport.GetAutoStyles()));
172 if ( pStyles )
173 {
174 XMLTableStyleContext* pStyle(const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
175 XmlStyleFamily::TABLE_ROW, sStyleName, true))));
176 if (pStyle)
177 {
178 pStyle->FillPropertySet(xRowProperties);
179
180 if ( nSheet != pStyle->GetLastSheet() )
181 {
182 ScSheetSaveData* pSheetData = comphelper::getFromUnoTunnel<ScModelObj>(rXMLImport.GetModel())->GetSheetSaveData();
183 pSheetData->AddRowStyle( sStyleName, ScAddress( 0, static_cast<SCROW>(nFirstRow), nSheet ) );
184 pStyle->SetLastSheet(nSheet);
185 }
186 }
187 }
188 }
189 bool bVisible (true);
190 bool bFiltered (false);
192 {
193 bVisible = false;
194 }
196 {
197 bVisible = false;
198 bFiltered = true;
199 }
200 if (!bVisible)
201 {
202 rXMLImport.GetDoc().setRowsVisible(nSheet, nFirstRow, nCurrentRow, false);
203 }
204 if (bFiltered)
205 xRowProperties->setPropertyValue(SC_ISFILTERED, uno::Any(bFiltered));
206
207 uno::Any any = xRowProperties->getPropertyValue(SC_UNONAME_OHEIGHT);
208 bool bOptionalHeight = false;
209 any >>= bOptionalHeight;
210 if (bOptionalHeight)
211 {
212 // Save this row for later height update
213 std::vector<ScDocRowHeightUpdater::TabRanges>& rRecalcRanges = rXMLImport.GetRecalcRowRanges();
214 while (static_cast<SCTAB>(rRecalcRanges.size()) <= nSheet)
215 {
216 rRecalcRanges.emplace_back(0, pDoc->MaxRow());
217 }
218 rRecalcRanges.at(nSheet).mnTab = nSheet;
219 rRecalcRanges.at(nSheet).maRanges.setTrue(nFirstRow, nCurrentRow);
220 }
221}
222
225 const bool bTempHeader,
226 const bool bTempGroup ) :
227 ScXMLImportContext( rImport ),
228 nHeaderStartRow(0),
229 nGroupStartRow(0),
230 bHeader(bTempHeader),
231 bGroup(bTempGroup),
232 bGroupDisplay(true)
233{
234 // don't have any attributes
235 if (bHeader)
236 {
237 ScAddress aAddr = rImport.GetTables().GetCurrentCellPos();
238 nHeaderStartRow = aAddr.Row();
240 }
241 else if (bGroup)
242 {
245 if ( rAttrList.is() )
246 {
247 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_DISPLAY ) ) );
248 if (aIter != rAttrList->end())
250 }
251 }
252}
253
255{
256}
257
258uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
260 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
261{
262 SvXMLImportContext *pContext(nullptr);
265
266 switch( nElement )
267 {
269 pContext = new ScXMLTableRowsContext( GetScImport(), pAttribList,
270 false, true );
271 break;
273 pContext = new ScXMLTableRowsContext( GetScImport(), pAttribList,
274 true, false );
275 break;
277 pContext = new ScXMLTableRowsContext( GetScImport(), pAttribList,
278 false, false );
279 break;
281 pContext = new ScXMLTableRowContext( GetScImport(), pAttribList );
282 break;
283 }
284
285 return pContext;
286}
287
288void SAL_CALL ScXMLTableRowsContext::endFastElement(sal_Int32 /*nElement*/)
289{
290 ScXMLImport& rXMLImport(GetScImport());
291 if (bHeader)
292 {
293 SCROW nHeaderEndRow = rXMLImport.GetTables().GetCurrentRow();
294 if (nHeaderStartRow <= nHeaderEndRow)
295 {
296 uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
297 if (xPrintAreas.is())
298 {
299 if (!xPrintAreas->getPrintTitleRows())
300 {
301 xPrintAreas->setPrintTitleRows(true);
302 table::CellRangeAddress aRowHeaderRange;
303 aRowHeaderRange.StartRow = nHeaderStartRow;
304 aRowHeaderRange.EndRow = nHeaderEndRow;
305 xPrintAreas->setTitleRows(aRowHeaderRange);
306 }
307 else
308 {
309 table::CellRangeAddress aRowHeaderRange(xPrintAreas->getTitleRows());
310 aRowHeaderRange.EndRow = nHeaderEndRow;
311 xPrintAreas->setTitleRows(aRowHeaderRange);
312 }
313 }
314 }
315 }
316 else if (bGroup)
317 {
318 SCROW nGroupEndRow = rXMLImport.GetTables().GetCurrentRow();
319 SCTAB nSheet(rXMLImport.GetTables().GetCurrentSheet());
320 if (nGroupStartRow <= nGroupEndRow)
321 {
322 ScDocument* pDoc(GetScImport().GetDocument());
323 if (pDoc)
324 {
326 ScOutlineTable* pOutlineTable(pDoc->GetOutlineTable(nSheet, true));
327 ScOutlineArray& rRowArray(pOutlineTable->GetRowArray());
328 bool bResized;
329 rRowArray.Insert(nGroupStartRow, nGroupEndRow, bResized, !bGroupDisplay);
330 }
331 }
332 }
333}
334
335/* 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:897
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:892
SC_DLLPUBLIC ScOutlineTable * GetOutlineTable(SCTAB nTab, bool bCreate=false)
Definition: documen3.cxx:745
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:47
sal_Int32 nRepeatedRows
Definition: xmlrowi.hxx:31
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlrowi.cxx:136
OUString sStyleName
Definition: xmlrowi.hxx:29
virtual ~ScXMLTableRowContext() override
Definition: xmlrowi.cxx:97
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:102
OUString sVisibility
Definition: xmlrowi.hxx:30
virtual ~ScXMLTableRowsContext() override
Definition: xmlrowi.cxx:254
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:259
ScXMLTableRowsContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, const bool bHeader, const bool bGroup)
Definition: xmlrowi.cxx:223
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlrowi.cxx:288
const css::uno::Reference< css::frame::XModel > & GetModel() const
SvXMLStylesContext * GetAutoStyles()
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
SCTAB GetLastSheet() const
Definition: xmlstyli.hxx:103
void SetLastSheet(SCTAB nNew)
Definition: xmlstyli.hxx:104
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
Definition: xmlstyli.cxx:510
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
bool bVisible
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int32 SCROW
Definition: types.hxx:17
#define SC_UNONAME_OHEIGHT
Definition: unonames.hxx:171
#define XML_ELEMENT(prefix, name)
constexpr OUStringLiteral SC_ISFILTERED
Definition: xmlrowi.cxx:42