LibreOffice Module sc (master)  1
xmlcoli.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 "xmlcoli.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlstyli.hxx"
23 #include <document.hxx>
24 #include <docuno.hxx>
25 #include <olinetab.hxx>
26 #include <sheetdata.hxx>
27 #include <unonames.hxx>
28 
29 #include <xmloff/xmlnmspe.hxx>
30 #include <xmloff/families.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <com/sun/star/sheet/XSpreadsheet.hpp>
33 #include <com/sun/star/table/XColumnRowRange.hpp>
34 #include <com/sun/star/sheet/XPrintAreas.hpp>
36 
37 using namespace com::sun::star;
38 using namespace xmloff::token;
39 
42  ScXMLImportContext( rImport ),
43  nColCount(1),
44  sVisibility(GetXMLToken(XML_VISIBLE))
45 {
46  if ( !rAttrList.is() )
47  return;
48 
49  for (auto &aIter : *rAttrList)
50  {
51  switch (aIter.getToken())
52  {
54  {
55  nColCount = std::max<sal_Int32>(aIter.toInt32(), 1);
56  nColCount = std::min<sal_Int32>(nColCount, MAXCOLCOUNT);
57  }
58  break;
60  {
61  sStyleName = aIter.toString();
62  }
63  break;
65  {
66  sVisibility = aIter.toString();
67  }
68  break;
70  {
71  sCellStyleName = aIter.toString();
72  }
73  break;
74  }
75  }
76 }
77 
79 {
80 }
81 
82 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLTableColContext::createFastChildContext(
83  sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
84 {
85  return nullptr;
86 }
87 
88 void SAL_CALL ScXMLTableColContext::endFastElement( sal_Int32 /*nElement*/ )
89 {
90  ScXMLImport& rXMLImport = GetScImport();
91  ScDocument* pDoc = rXMLImport.GetDocument();
92  SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
93  sal_Int32 nCurrentColumn = rXMLImport.GetTables().GetCurrentColCount();
94  uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
95  if(xSheet.is())
96  {
97  sal_Int32 nLastColumn(nCurrentColumn + nColCount - 1);
98  if (nLastColumn > pDoc->MaxCol())
99  nLastColumn = pDoc->MaxCol();
100  if (nCurrentColumn > pDoc->MaxCol())
101  nCurrentColumn = pDoc->MaxCol();
102  uno::Reference<table::XColumnRowRange> xColumnRowRange (xSheet->getCellRangeByPosition(nCurrentColumn, 0, nLastColumn, 0), uno::UNO_QUERY);
103  if (xColumnRowRange.is())
104  {
105  uno::Reference <beans::XPropertySet> xColumnProperties(xColumnRowRange->getColumns(), uno::UNO_QUERY);
106  if (xColumnProperties.is())
107  {
108  if (!sStyleName.isEmpty())
109  {
110  XMLTableStylesContext *pStyles = static_cast<XMLTableStylesContext *>(rXMLImport.GetAutoStyles());
111  if ( pStyles )
112  {
113  XMLTableStyleContext* pStyle = const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
114  XmlStyleFamily::TABLE_COLUMN, sStyleName, true)));
115  if (pStyle)
116  {
117  pStyle->FillPropertySet(xColumnProperties);
118 
119  if ( nSheet != pStyle->GetLastSheet() )
120  {
121  ScSheetSaveData* pSheetData = comphelper::getUnoTunnelImplementation<ScModelObj>(rXMLImport.GetModel())->GetSheetSaveData();
122  pSheetData->AddColumnStyle( sStyleName, ScAddress( static_cast<SCCOL>(nCurrentColumn), 0, nSheet ) );
123  pStyle->SetLastSheet(nSheet);
124  }
125  }
126  }
127  }
128  bool bValue(true);
130  bValue = false;
131  xColumnProperties->setPropertyValue(SC_UNONAME_CELLVIS, uno::makeAny(bValue));
132  }
133  }
134  }
135 
136  // #i57915# ScXMLImport::SetStyleToRange can't handle empty style names.
137  // The default for a column if there is no attribute is the style "Default" (programmatic API name).
138  if ( sCellStyleName.isEmpty() )
139  sCellStyleName = "Default";
140 
142 }
143 
146  const bool bTempHeader, const bool bTempGroup) :
147  ScXMLImportContext( rImport ),
148  nHeaderStartCol(0),
149  nHeaderEndCol(0),
150  nGroupStartCol(0),
151  nGroupEndCol(0),
152  bHeader(bTempHeader),
153  bGroup(bTempGroup),
154  bGroupDisplay(true)
155 {
156  // don't have any attributes
157  if (bHeader)
159  else if (bGroup)
160  {
162  if ( rAttrList.is() )
163  {
164  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_DISPLAY ) ) );
165  if ( aIter != rAttrList->end() && IsXMLToken(aIter, XML_FALSE) )
166  bGroupDisplay = false;
167  }
168  }
169 }
170 
172 {
173 }
174 
175 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLTableColsContext::createFastChildContext(
176  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
177 {
178  SvXMLImportContext *pContext = nullptr;
179  sax_fastparser::FastAttributeList *pAttribList =
181 
182  switch (nElement)
183  {
185  pContext = new ScXMLTableColsContext( GetScImport(), pAttribList,
186  false, true );
187  break;
189  pContext = new ScXMLTableColsContext( GetScImport(), pAttribList,
190  true, false );
191  break;
193  pContext = new ScXMLTableColsContext( GetScImport(), pAttribList,
194  false, false );
195  break;
197  pContext = new ScXMLTableColContext( GetScImport(), pAttribList );
198  break;
199  }
200 
201  return pContext;
202 }
203 
204 void SAL_CALL ScXMLTableColsContext::endFastElement( sal_Int32 /*nElement*/ )
205 {
206  ScXMLImport& rXMLImport = GetScImport();
207  if (bHeader)
208  {
209  nHeaderEndCol = rXMLImport.GetTables().GetCurrentColCount();
210  nHeaderEndCol--;
212  {
213  uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
214  if (xPrintAreas.is())
215  {
216  if (!xPrintAreas->getPrintTitleColumns())
217  {
218  xPrintAreas->setPrintTitleColumns(true);
219  table::CellRangeAddress aColumnHeaderRange;
220  aColumnHeaderRange.StartColumn = nHeaderStartCol;
221  aColumnHeaderRange.EndColumn = nHeaderEndCol;
222  xPrintAreas->setTitleColumns(aColumnHeaderRange);
223  }
224  else
225  {
226  table::CellRangeAddress aColumnHeaderRange(xPrintAreas->getTitleColumns());
227  aColumnHeaderRange.EndColumn = nHeaderEndCol;
228  xPrintAreas->setTitleColumns(aColumnHeaderRange);
229  }
230  }
231  }
232  }
233  else if (bGroup)
234  {
235  SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
236  nGroupEndCol = rXMLImport.GetTables().GetCurrentColCount();
237  nGroupEndCol--;
239  {
240  ScDocument* pDoc = GetScImport().GetDocument();
241  if (pDoc)
242  {
244  ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(nSheet, true);
245  if (pOutlineTable)
246  {
247  ScOutlineArray& rColArray = pOutlineTable->GetColArray();
248  bool bResized;
249  rColArray.Insert(static_cast<SCCOL>(nGroupStartCol), static_cast<SCCOL>(nGroupEndCol), bResized, !bGroupDisplay);
250  }
251  }
252  }
253  }
254 }
255 
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const int nColCount
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
XML_TABLE_COLUMN_GROUP
sal_Int32 nHeaderStartCol
Definition: xmlcoli.hxx:48
XML_STYLE_NAME
virtual ~ScXMLTableColContext() override
Definition: xmlcoli.cxx:78
XML_DISPLAY
OUString sVisibility
Definition: xmlcoli.hxx:30
XML_DEFAULT_CELL_STYLE_NAME
SCTAB GetCurrentSheet() const
Definition: xmlsubti.hxx:85
ScDocument * GetDocument()
Definition: xmlimprt.hxx:296
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlcoli.cxx:88
ScMyTables & GetTables()
Definition: xmlimprt.hxx:299
void AddColumnStyle(const OUString &rName, const ScAddress &rCellPos)
Definition: sheetdata.cxx:46
SCTAB GetLastSheet() const
Definition: xmlstyli.hxx:110
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
void SetLastSheet(SCTAB nNew)
Definition: xmlstyli.hxx:111
const SCCOL MAXCOLCOUNT
Definition: address.hxx:64
OUString sStyleName
Definition: xmlcoli.hxx:29
#define SC_UNONAME_CELLVIS
Definition: unonames.hxx:166
ScXMLTableColContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
Definition: xmlcoli.cxx:40
XML_TABLE_HEADER_COLUMNS
XML_NUMBER_COLUMNS_REPEATED
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
Definition: xmlstyli.cxx:527
SCCOL GetCurrentColCount() const
Definition: xmlsubti.cxx:287
sal_Int32 nHeaderEndCol
Definition: xmlcoli.hxx:49
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: xmlcoli.cxx:82
XML_VISIBILITY
XML_FALSE
This class exists only to provide GetScImport() to its derived classes.
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:872
OUString sCellStyleName
Definition: xmlcoli.hxx:31
sal_Int32 nColCount
Definition: xmlcoli.hxx:28
const ScOutlineArray & GetColArray() const
Definition: olinetab.hxx:159
sal_Int32 nGroupStartCol
Definition: xmlcoli.hxx:50
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: xmlcoli.cxx:175
ScXMLTableColsContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, const bool bHeader, const bool bGroup)
Definition: xmlcoli.cxx:144
void AddColStyle(const sal_Int32 nRepeat, const OUString &rCellStyleName)
Definition: xmlsubti.cxx:211
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlcoli.cxx:204
TABLE
virtual ~ScXMLTableColsContext() override
Definition: xmlcoli.cxx:171
sal_Int32 nGroupEndCol
Definition: xmlcoli.hxx:51
XML_TABLE_COLUMNS
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
#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
XML_TABLE_COLUMN
const css::uno::Reference< css::sheet::XSpreadsheet > & GetCurrentXSheet() const
Definition: xmlsubti.hxx:89
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
SvXMLStylesContext * GetAutoStyles()
bool Insert(SCCOLROW nStartPos, SCCOLROW nEndPos, bool &rSizeChanged, bool bHidden=false)
Definition: olinetab.cxx:197
sal_Int16 SCTAB
Definition: types.hxx:23