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/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>
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
),
44 sVisibility(GetXMLToken(XML_VISIBLE
))
46 if ( !rAttrList
.is() )
49 for (auto &aIter
: *rAttrList
)
51 switch (aIter
.getToken())
53 case XML_ELEMENT( TABLE
, XML_NUMBER_COLUMNS_REPEATED
):
55 nColCount
= std::max
<sal_Int32
>(aIter
.toInt32(), 1);
56 nColCount
= std::min
<sal_Int32
>(nColCount
, rImport
.GetDocument()->GetSheetLimits().GetMaxColCount() );
59 case XML_ELEMENT( TABLE
, XML_STYLE_NAME
):
61 sStyleName
= aIter
.toString();
64 case XML_ELEMENT( TABLE
, XML_VISIBILITY
):
66 sVisibility
= aIter
.toString();
69 case XML_ELEMENT( TABLE
, XML_DEFAULT_CELL_STYLE_NAME
):
71 sCellStyleName
= aIter
.toString();
78 ScXMLTableColContext::~ScXMLTableColContext()
82 void SAL_CALL
ScXMLTableColContext::endFastElement( sal_Int32
/*nElement*/ )
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());
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())
99 uno::Reference
<beans::XPropertySet
> xColumnProperties(xColumnRowRange
->getColumns(), uno::UNO_QUERY
);
100 if (xColumnProperties
.is())
102 if (!sStyleName
.isEmpty())
104 XMLTableStylesContext
*pStyles
= static_cast<XMLTableStylesContext
*>(rXMLImport
.GetAutoStyles());
107 XMLTableStyleContext
* pStyle
= const_cast<XMLTableStyleContext
*>(static_cast<const XMLTableStyleContext
*>(pStyles
->FindStyleChildContext(
108 XmlStyleFamily::TABLE_COLUMN
, sStyleName
, true)));
111 pStyle
->FillPropertySet(xColumnProperties
);
113 if ( nSheet
!= pStyle
->GetLastSheet() )
115 ScSheetSaveData
* pSheetData
= comphelper::getFromUnoTunnel
<ScModelObj
>(rXMLImport
.GetModel())->GetSheetSaveData();
116 pSheetData
->AddColumnStyle( sStyleName
, ScAddress( static_cast<SCCOL
>(nCurrentColumn
), 0, nSheet
) );
117 pStyle
->SetLastSheet(nSheet
);
123 if (!IsXMLToken(sVisibility
, XML_VISIBLE
))
125 xColumnProperties
->setPropertyValue(SC_UNONAME_CELLVIS
, uno::Any(bValue
));
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";
135 GetScImport().GetTables().AddColStyle(nColCount
, sCellStyleName
);
138 ScXMLTableColsContext::ScXMLTableColsContext( ScXMLImport
& rImport
,
139 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
140 const bool bTempHeader
, const bool bTempGroup
) :
141 ScXMLImportContext( rImport
),
146 bHeader(bTempHeader
),
150 // don't have any attributes
152 nHeaderStartCol
= rImport
.GetTables().GetCurrentColCount();
155 nGroupStartCol
= rImport
.GetTables().GetCurrentColCount();
156 if ( rAttrList
.is() )
158 auto aIter( rAttrList
->find( XML_ELEMENT( TABLE
, XML_DISPLAY
) ) );
159 if ( aIter
!= rAttrList
->end() && IsXMLToken(aIter
, XML_FALSE
) )
160 bGroupDisplay
= false;
165 ScXMLTableColsContext::~ScXMLTableColsContext()
169 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLTableColsContext::createFastChildContext(
170 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
172 SvXMLImportContext
*pContext
= nullptr;
173 sax_fastparser::FastAttributeList
*pAttribList
=
174 &sax_fastparser::castToFastAttributeList( xAttrList
);
178 case XML_ELEMENT( TABLE
, XML_TABLE_COLUMN_GROUP
):
179 pContext
= new ScXMLTableColsContext( GetScImport(), pAttribList
,
182 case XML_ELEMENT( TABLE
, XML_TABLE_HEADER_COLUMNS
):
183 pContext
= new ScXMLTableColsContext( GetScImport(), pAttribList
,
186 case XML_ELEMENT( TABLE
, XML_TABLE_COLUMNS
):
187 pContext
= new ScXMLTableColsContext( GetScImport(), pAttribList
,
190 case XML_ELEMENT( TABLE
, XML_TABLE_COLUMN
):
191 pContext
= new ScXMLTableColContext( GetScImport(), pAttribList
);
198 void SAL_CALL
ScXMLTableColsContext::endFastElement( sal_Int32
/*nElement*/ )
200 ScXMLImport
& rXMLImport
= GetScImport();
203 nHeaderEndCol
= rXMLImport
.GetTables().GetCurrentColCount();
205 if (nHeaderStartCol
<= nHeaderEndCol
)
207 uno::Reference
<sheet::XPrintAreas
> xPrintAreas (rXMLImport
.GetTables().GetCurrentXSheet(), uno::UNO_QUERY
);
208 if (xPrintAreas
.is())
210 if (!xPrintAreas
->getPrintTitleColumns())
212 xPrintAreas
->setPrintTitleColumns(true);
213 table::CellRangeAddress aColumnHeaderRange
;
214 aColumnHeaderRange
.StartColumn
= nHeaderStartCol
;
215 aColumnHeaderRange
.EndColumn
= nHeaderEndCol
;
216 xPrintAreas
->setTitleColumns(aColumnHeaderRange
);
220 table::CellRangeAddress
aColumnHeaderRange(xPrintAreas
->getTitleColumns());
221 aColumnHeaderRange
.EndColumn
= nHeaderEndCol
;
222 xPrintAreas
->setTitleColumns(aColumnHeaderRange
);
229 SCTAB nSheet
= rXMLImport
.GetTables().GetCurrentSheet();
230 nGroupEndCol
= rXMLImport
.GetTables().GetCurrentColCount();
232 if (nGroupStartCol
<= nGroupEndCol
)
234 ScDocument
* pDoc
= GetScImport().GetDocument();
237 ScXMLImport::MutexGuard
aGuard(GetScImport());
238 ScOutlineTable
* pOutlineTable
= pDoc
->GetOutlineTable(nSheet
, true);
241 ScOutlineArray
& rColArray
= pOutlineTable
->GetColArray();
243 rColArray
.Insert(static_cast<SCCOL
>(nGroupStartCol
), static_cast<SCCOL
>(nGroupEndCol
), bResized
, !bGroupDisplay
);
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */