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 
31 #include <xmloff/xmlnmspe.hxx>
32 #include <xmloff/families.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <sax/fastattribs.hxx>
35 #include <com/sun/star/sheet/XSpreadsheet.hpp>
36 #include <com/sun/star/table/XColumnRowRange.hpp>
37 #include <com/sun/star/sheet/XPrintAreas.hpp>
39 #include <osl/diagnose.h>
40 
41 #define SC_ISFILTERED "IsFiltered"
42 
43 using namespace com::sun::star;
44 using namespace xmloff::token;
45 
48  ScXMLImportContext( rImport ),
49  sVisibility(GetXMLToken(XML_VISIBLE)),
50  nRepeatedRows(1),
51  bHasCell(false)
52 {
53  OUString sCellStyleName;
54  if ( rAttrList.is() )
55  {
56  for (auto &it : *rAttrList)
57  {
58  switch (it.getToken())
59  {
61  {
62  sStyleName = it.toString();
63  }
64  break;
66  {
67  sVisibility = it.toString();
68  }
69  break;
71  {
72  nRepeatedRows = std::max( it.toInt32(), sal_Int32(1) );
73  nRepeatedRows = std::min( nRepeatedRows, MAXROWCOUNT );
74  }
75  break;
77  {
78  sCellStyleName = it.toString();
79  }
80  break;
81  /*case XML_ELEMENT( TABLE, XML_USE_OPTIMAL_HEIGHT ):
82  {
83  sOptimalHeight = it.toString();
84  }
85  break;*/
86  }
87  }
88  }
89 
91  GetScImport().GetTables().SetRowStyle(sCellStyleName);
92 }
93 
95 {
96 }
97 
98 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
100  const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
101 {
102  SvXMLImportContext *pContext(nullptr);
103  sax_fastparser::FastAttributeList *pAttribList =
105 
106  switch( nElement )
107  {
109 // if( IsInsertCellPossible() )
110  {
111  bHasCell = true;
112  pContext = new ScXMLTableRowCellContext( GetScImport(),
113  pAttribList, false, static_cast<SCROW>(nRepeatedRows)
114  //this
115  );
116  }
117  break;
119 // if( IsInsertCellPossible() )
120  {
121  bHasCell = true;
122  pContext = new ScXMLTableRowCellContext( GetScImport(),
123  pAttribList, true, static_cast<SCROW>(nRepeatedRows)
124  //this
125  );
126  }
127  break;
128  }
129 
130  return pContext;
131 }
132 
133 void SAL_CALL ScXMLTableRowContext::endFastElement(sal_Int32 /*nElement*/)
134 {
135  ScXMLImport& rXMLImport(GetScImport());
136  ScDocument* pDoc(rXMLImport.GetDocument());
137  if (!bHasCell && nRepeatedRows > 1)
138  {
139  for (sal_Int32 i = 0; i < nRepeatedRows - 1; ++i) //one row is always added
141  OSL_FAIL("it seems here is a nonvalid file; possible missing of table:table-cell element");
142  }
143  SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
144  sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
145  uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
146  if(!xSheet.is())
147  return;
148 
149  sal_Int32 nFirstRow(nCurrentRow - nRepeatedRows + 1);
150  if (nFirstRow > pDoc->MaxRow())
151  nFirstRow = pDoc->MaxRow();
152  if (nCurrentRow > pDoc->MaxRow())
153  nCurrentRow = pDoc->MaxRow();
154  uno::Reference <table::XCellRange> xCellRange(xSheet->getCellRangeByPosition(0, nFirstRow, 0, nCurrentRow));
155  if (!xCellRange.is())
156  return;
157 
158  uno::Reference<table::XColumnRowRange> xColumnRowRange (xCellRange, uno::UNO_QUERY);
159  if (!xColumnRowRange.is())
160  return;
161 
162  uno::Reference <beans::XPropertySet> xRowProperties(xColumnRowRange->getRows(), uno::UNO_QUERY);
163  if (!xRowProperties.is())
164  return;
165 
166  if (!sStyleName.isEmpty())
167  {
168  XMLTableStylesContext *pStyles(static_cast<XMLTableStylesContext *>(rXMLImport.GetAutoStyles()));
169  if ( pStyles )
170  {
171  XMLTableStyleContext* pStyle(const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
172  XmlStyleFamily::TABLE_ROW, sStyleName, true))));
173  if (pStyle)
174  {
175  pStyle->FillPropertySet(xRowProperties);
176 
177  if ( nSheet != pStyle->GetLastSheet() )
178  {
179  ScSheetSaveData* pSheetData = comphelper::getUnoTunnelImplementation<ScModelObj>(rXMLImport.GetModel())->GetSheetSaveData();
180  pSheetData->AddRowStyle( sStyleName, ScAddress( 0, static_cast<SCROW>(nFirstRow), nSheet ) );
181  pStyle->SetLastSheet(nSheet);
182  }
183  }
184  }
185  }
186  bool bVisible (true);
187  bool bFiltered (false);
189  {
190  bVisible = false;
191  }
192  else if (IsXMLToken(sVisibility, XML_FILTER))
193  {
194  bVisible = false;
195  bFiltered = true;
196  }
197  if (!bVisible)
198  {
199  rXMLImport.GetDoc().setRowsVisible(nSheet, nFirstRow, nCurrentRow, false);
200  }
201  if (bFiltered)
202  xRowProperties->setPropertyValue(SC_ISFILTERED, uno::makeAny(bFiltered));
203 
204  uno::Any any = xRowProperties->getPropertyValue(SC_UNONAME_OHEIGHT);
205  bool bOptionalHeight = false;
206  any >>= bOptionalHeight;
207  if (bOptionalHeight)
208  {
209  // Save this row for later height update
210  std::vector<ScDocRowHeightUpdater::TabRanges>& rRecalcRanges = rXMLImport.GetRecalcRowRanges();
211  while (static_cast<SCTAB>(rRecalcRanges.size()) <= nSheet)
212  {
213  rRecalcRanges.emplace_back(0, pDoc->MaxRow());
214  }
215  rRecalcRanges.at(nSheet).mnTab = nSheet;
216  rRecalcRanges.at(nSheet).maRanges.setTrue(nFirstRow, nCurrentRow);
217  }
218 }
219 
222  const bool bTempHeader,
223  const bool bTempGroup ) :
224  ScXMLImportContext( rImport ),
225  nHeaderStartRow(0),
226  nGroupStartRow(0),
227  bHeader(bTempHeader),
228  bGroup(bTempGroup),
229  bGroupDisplay(true)
230 {
231  // don't have any attributes
232  if (bHeader)
233  {
234  ScAddress aAddr = rImport.GetTables().GetCurrentCellPos();
235  nHeaderStartRow = aAddr.Row();
236  ++nHeaderStartRow;
237  }
238  else if (bGroup)
239  {
240  nGroupStartRow = rImport.GetTables().GetCurrentRow();
241  ++nGroupStartRow;
242  if ( rAttrList.is() )
243  {
244  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_DISPLAY ) ) );
245  if (aIter != rAttrList->end())
246  bGroupDisplay = IsXMLToken( aIter, XML_TRUE );
247  }
248  }
249 }
250 
252 {
253 }
254 
255 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
257  const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
258 {
259  SvXMLImportContext *pContext(nullptr);
260  sax_fastparser::FastAttributeList *pAttribList =
262 
263  switch( nElement )
264  {
266  pContext = new ScXMLTableRowsContext( GetScImport(), pAttribList,
267  false, true );
268  break;
270  pContext = new ScXMLTableRowsContext( GetScImport(), pAttribList,
271  true, false );
272  break;
274  pContext = new ScXMLTableRowsContext( GetScImport(), pAttribList,
275  false, false );
276  break;
278  pContext = new ScXMLTableRowContext( GetScImport(), pAttribList );
279  break;
280  }
281 
282  return pContext;
283 }
284 
285 void SAL_CALL ScXMLTableRowsContext::endFastElement(sal_Int32 /*nElement*/)
286 {
287  ScXMLImport& rXMLImport(GetScImport());
288  if (bHeader)
289  {
290  SCROW nHeaderEndRow = rXMLImport.GetTables().GetCurrentRow();
291  if (nHeaderStartRow <= nHeaderEndRow)
292  {
293  uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
294  if (xPrintAreas.is())
295  {
296  if (!xPrintAreas->getPrintTitleRows())
297  {
298  xPrintAreas->setPrintTitleRows(true);
299  table::CellRangeAddress aRowHeaderRange;
300  aRowHeaderRange.StartRow = nHeaderStartRow;
301  aRowHeaderRange.EndRow = nHeaderEndRow;
302  xPrintAreas->setTitleRows(aRowHeaderRange);
303  }
304  else
305  {
306  table::CellRangeAddress aRowHeaderRange(xPrintAreas->getTitleRows());
307  aRowHeaderRange.EndRow = nHeaderEndRow;
308  xPrintAreas->setTitleRows(aRowHeaderRange);
309  }
310  }
311  }
312  }
313  else if (bGroup)
314  {
315  SCROW nGroupEndRow = rXMLImport.GetTables().GetCurrentRow();
316  SCTAB nSheet(rXMLImport.GetTables().GetCurrentSheet());
317  if (nGroupStartRow <= nGroupEndRow)
318  {
319  ScDocument* pDoc(GetScImport().GetDocument());
320  if (pDoc)
321  {
323  ScOutlineTable* pOutlineTable(pDoc->GetOutlineTable(nSheet, true));
324  ScOutlineArray& rRowArray(pOutlineTable->GetRowArray());
325  bool bResized;
326  rRowArray.Insert(nGroupStartRow, nGroupEndRow, bResized, !bGroupDisplay);
327  }
328  }
329  }
330 }
331 
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~ScXMLTableRowContext() override
Definition: xmlrowi.cxx:94
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
XML_NUMBER_ROWS_REPEATED
bool bVisible
XML_STYLE_NAME
XML_COLLAPSE
XML_DISPLAY
SCROW Row() const
Definition: address.hxx:262
void SetRowStyle(const OUString &rCellStyleName)
Definition: xmlsubti.cxx:170
std::vector< ScDocRowHeightUpdater::TabRanges > & GetRecalcRowRanges()
Definition: xmlimprt.hxx:301
XML_DEFAULT_CELL_STYLE_NAME
SCTAB GetCurrentSheet() const
Definition: xmlsubti.hxx:85
ScDocument * GetDocument()
Definition: xmlimprt.hxx:296
ScMyTables & GetTables()
Definition: xmlimprt.hxx:299
XML_TABLE_ROW_GROUP
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString sVisibility
Definition: xmlrowi.hxx:31
XML_TABLE_CELL
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
Definition: xmlstyli.cxx:527
XML_VISIBILITY
ScXMLTableRowsContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, const bool bHeader, const bool bGroup)
Definition: xmlrowi.cxx:220
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:256
const SCROW MAXROWCOUNT
Definition: address.hxx:63
virtual ~ScXMLTableRowsContext() override
Definition: xmlrowi.cxx:251
This class exists only to provide GetScImport() to its derived classes.
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlrowi.cxx:133
#define SC_UNONAME_OHEIGHT
Definition: unonames.hxx:170
XML_TABLE_ROW
int i
#define SC_ISFILTERED
Definition: xmlrowi.cxx:41
const Any & any
OUString sStyleName
Definition: xmlrowi.hxx:30
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:392
XML_VISIBLE
ScXMLImport & GetScImport()
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:99
XML_COVERED_TABLE_CELL
SCROW GetCurrentRow() const
Definition: xmlsubti.hxx:87
const ScAddress & GetCurrentCellPos() const
Definition: xmlsubti.hxx:81
TABLE
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlrowi.cxx:285
sal_Int32 SCROW
Definition: types.hxx:18
void setRowsVisible(SCTAB nTab, SCROW nRowStart, SCROW nRowEnd, bool bVisible)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
XML_FILTER
ScXMLTableRowContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
Definition: xmlrowi.cxx:46
#define XML_ELEMENT(prefix, name)
SC_DLLPUBLIC ScOutlineTable * GetOutlineTable(SCTAB nTab, bool bCreate=false)
Definition: documen3.cxx:717
const css::uno::Reference< css::frame::XModel > & GetModel() const
const css::uno::Reference< css::sheet::XSpreadsheet > & GetCurrentXSheet() const
Definition: xmlsubti.hxx:89
XML_TRUE
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
sal_Int32 nRepeatedRows
Definition: xmlrowi.hxx:32
void AddRowStyle(const OUString &rName, const ScAddress &rCellPos)
Definition: sheetdata.cxx:49
XML_TABLE_HEADER_ROWS
SvXMLStylesContext * GetAutoStyles()
bool Insert(SCCOLROW nStartPos, SCCOLROW nEndPos, bool &rSizeChanged, bool bHidden=false)
Definition: olinetab.cxx:197
XML_TABLE_ROWS
void AddRow()
Definition: xmlsubti.cxx:164
ScDocumentImport & GetDoc()
Definition: xmlimprt.cxx:722
sal_Int16 SCTAB
Definition: types.hxx:23