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/xmlnamespace.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 void SAL_CALL ScXMLTableColContext::endFastElement( sal_Int32 /*nElement*/ )
83 {
84  ScXMLImport& rXMLImport = GetScImport();
85  ScDocument* pDoc = rXMLImport.GetDocument();
86  SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
87  sal_Int32 nCurrentColumn = rXMLImport.GetTables().GetCurrentColCount();
88  uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
89  if(xSheet.is())
90  {
91  sal_Int32 nLastColumn(nCurrentColumn + nColCount - 1);
92  if (nLastColumn > pDoc->MaxCol())
93  nLastColumn = pDoc->MaxCol();
94  if (nCurrentColumn > pDoc->MaxCol())
95  nCurrentColumn = pDoc->MaxCol();
96  uno::Reference<table::XColumnRowRange> xColumnRowRange (xSheet->getCellRangeByPosition(nCurrentColumn, 0, nLastColumn, 0), uno::UNO_QUERY);
97  if (xColumnRowRange.is())
98  {
99  uno::Reference <beans::XPropertySet> xColumnProperties(xColumnRowRange->getColumns(), uno::UNO_QUERY);
100  if (xColumnProperties.is())
101  {
102  if (!sStyleName.isEmpty())
103  {
104  XMLTableStylesContext *pStyles = static_cast<XMLTableStylesContext *>(rXMLImport.GetAutoStyles());
105  if ( pStyles )
106  {
107  XMLTableStyleContext* pStyle = const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
108  XmlStyleFamily::TABLE_COLUMN, sStyleName, true)));
109  if (pStyle)
110  {
111  pStyle->FillPropertySet(xColumnProperties);
112 
113  if ( nSheet != pStyle->GetLastSheet() )
114  {
115  ScSheetSaveData* pSheetData = comphelper::getUnoTunnelImplementation<ScModelObj>(rXMLImport.GetModel())->GetSheetSaveData();
116  pSheetData->AddColumnStyle( sStyleName, ScAddress( static_cast<SCCOL>(nCurrentColumn), 0, nSheet ) );
117  pStyle->SetLastSheet(nSheet);
118  }
119  }
120  }
121  }
122  bool bValue(true);
124  bValue = false;
125  xColumnProperties->setPropertyValue(SC_UNONAME_CELLVIS, uno::makeAny(bValue));
126  }
127  }
128  }
129 
130  // #i57915# ScXMLImport::SetStyleToRange can't handle empty style names.
131  // The default for a column if there is no attribute is the style "Default" (programmatic API name).
132  if ( sCellStyleName.isEmpty() )
133  sCellStyleName = "Default";
134 
136 }
137 
140  const bool bTempHeader, const bool bTempGroup) :
141  ScXMLImportContext( rImport ),
142  nHeaderStartCol(0),
143  nHeaderEndCol(0),
144  nGroupStartCol(0),
145  nGroupEndCol(0),
146  bHeader(bTempHeader),
147  bGroup(bTempGroup),
148  bGroupDisplay(true)
149 {
150  // don't have any attributes
151  if (bHeader)
153  else if (bGroup)
154  {
156  if ( rAttrList.is() )
157  {
158  auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_DISPLAY ) ) );
159  if ( aIter != rAttrList->end() && IsXMLToken(aIter, XML_FALSE) )
160  bGroupDisplay = false;
161  }
162  }
163 }
164 
166 {
167 }
168 
169 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLTableColsContext::createFastChildContext(
170  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
171 {
172  SvXMLImportContext *pContext = nullptr;
173  sax_fastparser::FastAttributeList *pAttribList =
175 
176  switch (nElement)
177  {
179  pContext = new ScXMLTableColsContext( GetScImport(), pAttribList,
180  false, true );
181  break;
183  pContext = new ScXMLTableColsContext( GetScImport(), pAttribList,
184  true, false );
185  break;
187  pContext = new ScXMLTableColsContext( GetScImport(), pAttribList,
188  false, false );
189  break;
191  pContext = new ScXMLTableColContext( GetScImport(), pAttribList );
192  break;
193  }
194 
195  return pContext;
196 }
197 
198 void SAL_CALL ScXMLTableColsContext::endFastElement( sal_Int32 /*nElement*/ )
199 {
200  ScXMLImport& rXMLImport = GetScImport();
201  if (bHeader)
202  {
203  nHeaderEndCol = rXMLImport.GetTables().GetCurrentColCount();
204  nHeaderEndCol--;
206  {
207  uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
208  if (xPrintAreas.is())
209  {
210  if (!xPrintAreas->getPrintTitleColumns())
211  {
212  xPrintAreas->setPrintTitleColumns(true);
213  table::CellRangeAddress aColumnHeaderRange;
214  aColumnHeaderRange.StartColumn = nHeaderStartCol;
215  aColumnHeaderRange.EndColumn = nHeaderEndCol;
216  xPrintAreas->setTitleColumns(aColumnHeaderRange);
217  }
218  else
219  {
220  table::CellRangeAddress aColumnHeaderRange(xPrintAreas->getTitleColumns());
221  aColumnHeaderRange.EndColumn = nHeaderEndCol;
222  xPrintAreas->setTitleColumns(aColumnHeaderRange);
223  }
224  }
225  }
226  }
227  else if (bGroup)
228  {
229  SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
230  nGroupEndCol = rXMLImport.GetTables().GetCurrentColCount();
231  nGroupEndCol--;
233  {
234  ScDocument* pDoc = GetScImport().GetDocument();
235  if (pDoc)
236  {
238  ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(nSheet, true);
239  if (pOutlineTable)
240  {
241  ScOutlineArray& rColArray = pOutlineTable->GetColArray();
242  bool bResized;
243  rColArray.Insert(static_cast<SCCOL>(nGroupStartCol), static_cast<SCCOL>(nGroupEndCol), bResized, !bGroupDisplay);
244  }
245  }
246  }
247  }
248 }
249 
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XML_TABLE_COLUMN_GROUP
sal_Int32 nHeaderStartCol
Definition: xmlcoli.hxx:44
XML_STYLE_NAME
virtual ~ScXMLTableColContext() override
Definition: xmlcoli.cxx:78
XML_DISPLAY
OUString sVisibility
Definition: xmlcoli.hxx:29
XML_DEFAULT_CELL_STYLE_NAME
SCTAB GetCurrentSheet() const
Definition: xmlsubti.hxx:84
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlcoli.cxx:82
ScMyTables & GetTables()
Definition: xmlimprt.hxx:208
void AddColumnStyle(const OUString &rName, const ScAddress &rCellPos)
Definition: sheetdata.cxx:46
SCTAB GetLastSheet() const
Definition: xmlstyli.hxx:103
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
void SetLastSheet(SCTAB nNew)
Definition: xmlstyli.hxx:104
const SCCOL MAXCOLCOUNT
Definition: address.hxx:63
OUString sStyleName
Definition: xmlcoli.hxx:28
#define SC_UNONAME_CELLVIS
Definition: unonames.hxx:165
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:511
SCCOL GetCurrentColCount() const
Definition: xmlsubti.cxx:287
sal_Int32 nHeaderEndCol
Definition: xmlcoli.hxx:45
XML_VISIBILITY
XML_FALSE
This class exists only to provide GetScImport() to its derived classes.
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:870
OUString sCellStyleName
Definition: xmlcoli.hxx:30
sal_Int32 nColCount
Definition: xmlcoli.hxx:27
const ScOutlineArray & GetColArray() const
Definition: olinetab.hxx:158
sal_Int32 nGroupStartCol
Definition: xmlcoli.hxx:46
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:293
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:169
ScXMLTableColsContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, const bool bHeader, const bool bGroup)
Definition: xmlcoli.cxx:138
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:198
TABLE
virtual ~ScXMLTableColsContext() override
Definition: xmlcoli.cxx:165
sal_Int32 nGroupEndCol
Definition: xmlcoli.hxx:47
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:735
const css::uno::Reference< css::frame::XModel > & GetModel() const
XML_TABLE_COLUMN
const css::uno::Reference< css::sheet::XSpreadsheet > & GetCurrentXSheet() const
Definition: xmlsubti.hxx:88
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:22