1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "xmlcoli.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlstyli.hxx"
23 #include <document.hxx>
25 #include <olinetab.hxx>
26 #include <sheetdata.hxx>
27 #include <unonames.hxx>
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>
35 #include <comphelper/servicehelper.hxx>
37 using namespace com::sun::star
;
38 using namespace xmloff::token
;
40 ScXMLTableColContext::ScXMLTableColContext( ScXMLImport
& rImport
,
41 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
42 ScXMLImportContext( rImport
),
43 sVisibility(GetXMLToken(XML_VISIBLE
))
48 for (auto &aIter
: *rAttrList
)
50 switch (aIter
.getToken())
52 case XML_ELEMENT( TABLE
, XML_NUMBER_COLUMNS_REPEATED
):
54 nColCount
= std::max
<sal_Int32
>(aIter
.toInt32(), 1);
55 nColCount
= std::min
<sal_Int32
>(nColCount
, MAXCOLCOUNT
);
58 case XML_ELEMENT( TABLE
, XML_STYLE_NAME
):
60 sStyleName
= aIter
.toString();
63 case XML_ELEMENT( TABLE
, XML_VISIBILITY
):
65 sVisibility
= aIter
.toString();
68 case XML_ELEMENT( TABLE
, XML_DEFAULT_CELL_STYLE_NAME
):
70 sCellStyleName
= aIter
.toString();
78 ScXMLTableColContext::~ScXMLTableColContext()
82 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLTableColContext::createFastChildContext(
83 sal_Int32
/*nElement*/, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
85 return new SvXMLImportContext( GetImport() );
88 void SAL_CALL
ScXMLTableColContext::endFastElement( sal_Int32
/*nElement*/ )
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());
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())
105 uno::Reference
<beans::XPropertySet
> xColumnProperties(xColumnRowRange
->getColumns(), uno::UNO_QUERY
);
106 if (xColumnProperties
.is())
108 if (!sStyleName
.isEmpty())
110 XMLTableStylesContext
*pStyles
= static_cast<XMLTableStylesContext
*>(rXMLImport
.GetAutoStyles());
113 XMLTableStyleContext
* pStyle
= const_cast<XMLTableStyleContext
*>(static_cast<const XMLTableStyleContext
*>(pStyles
->FindStyleChildContext(
114 XML_STYLE_FAMILY_TABLE_COLUMN
, sStyleName
, true)));
117 pStyle
->FillPropertySet(xColumnProperties
);
119 if ( nSheet
!= pStyle
->GetLastSheet() )
121 ScSheetSaveData
* pSheetData
= comphelper::getUnoTunnelImplementation
<ScModelObj
>(rXMLImport
.GetModel())->GetSheetSaveData();
122 pSheetData
->AddColumnStyle( sStyleName
, ScAddress( static_cast<SCCOL
>(nCurrentColumn
), 0, nSheet
) );
123 pStyle
->SetLastSheet(nSheet
);
129 if (!IsXMLToken(sVisibility
, XML_VISIBLE
))
131 xColumnProperties
->setPropertyValue(SC_UNONAME_CELLVIS
, uno::makeAny(bValue
));
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";
141 GetScImport().GetTables().AddColStyle(nColCount
, sCellStyleName
);
144 ScXMLTableColsContext::ScXMLTableColsContext( ScXMLImport
& rImport
,
145 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
146 const bool bTempHeader
, const bool bTempGroup
) :
147 ScXMLImportContext( rImport
),
152 bHeader(bTempHeader
),
156 // don't have any attributes
158 nHeaderStartCol
= rImport
.GetTables().GetCurrentColCount();
161 nGroupStartCol
= rImport
.GetTables().GetCurrentColCount();
162 if ( rAttrList
.is() )
164 auto aIter( rAttrList
->find( XML_ELEMENT( TABLE
, XML_DISPLAY
) ) );
165 if ( aIter
!= rAttrList
->end() && IsXMLToken(aIter
, XML_FALSE
) )
166 bGroupDisplay
= false;
171 ScXMLTableColsContext::~ScXMLTableColsContext()
175 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLTableColsContext::createFastChildContext(
176 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
178 SvXMLImportContext
*pContext
= nullptr;
179 sax_fastparser::FastAttributeList
*pAttribList
=
180 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
184 case XML_ELEMENT( TABLE
, XML_TABLE_COLUMN_GROUP
):
185 pContext
= new ScXMLTableColsContext( GetScImport(), pAttribList
,
188 case XML_ELEMENT( TABLE
, XML_TABLE_HEADER_COLUMNS
):
189 pContext
= new ScXMLTableColsContext( GetScImport(), pAttribList
,
192 case XML_ELEMENT( TABLE
, XML_TABLE_COLUMNS
):
193 pContext
= new ScXMLTableColsContext( GetScImport(), pAttribList
,
196 case XML_ELEMENT( TABLE
, XML_TABLE_COLUMN
):
197 pContext
= new ScXMLTableColContext( GetScImport(), pAttribList
);
202 pContext
= new SvXMLImportContext( GetImport() );
207 void SAL_CALL
ScXMLTableColsContext::endFastElement( sal_Int32
/*nElement*/ )
209 ScXMLImport
& rXMLImport
= GetScImport();
212 nHeaderEndCol
= rXMLImport
.GetTables().GetCurrentColCount();
214 if (nHeaderStartCol
<= nHeaderEndCol
)
216 uno::Reference
<sheet::XPrintAreas
> xPrintAreas (rXMLImport
.GetTables().GetCurrentXSheet(), uno::UNO_QUERY
);
217 if (xPrintAreas
.is())
219 if (!xPrintAreas
->getPrintTitleColumns())
221 xPrintAreas
->setPrintTitleColumns(true);
222 table::CellRangeAddress aColumnHeaderRange
;
223 aColumnHeaderRange
.StartColumn
= nHeaderStartCol
;
224 aColumnHeaderRange
.EndColumn
= nHeaderEndCol
;
225 xPrintAreas
->setTitleColumns(aColumnHeaderRange
);
229 table::CellRangeAddress
aColumnHeaderRange(xPrintAreas
->getTitleColumns());
230 aColumnHeaderRange
.EndColumn
= nHeaderEndCol
;
231 xPrintAreas
->setTitleColumns(aColumnHeaderRange
);
238 SCTAB nSheet
= rXMLImport
.GetTables().GetCurrentSheet();
239 nGroupEndCol
= rXMLImport
.GetTables().GetCurrentColCount();
241 if (nGroupStartCol
<= nGroupEndCol
)
243 ScDocument
* pDoc
= GetScImport().GetDocument();
246 ScXMLImport::MutexGuard
aGuard(GetScImport());
247 ScOutlineTable
* pOutlineTable
= pDoc
->GetOutlineTable(nSheet
, true);
250 ScOutlineArray
& rColArray
= pOutlineTable
->GetColArray();
252 rColArray
.Insert(static_cast<SCCOL
>(nGroupStartCol
), static_cast<SCCOL
>(nGroupEndCol
), bResized
, !bGroupDisplay
);
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */