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"
23 #include "xmlstyli.hxx"
24 #include "document.hxx"
26 #include "olinetab.hxx"
27 #include "sheetdata.hxx"
28 #include "unonames.hxx"
30 #include <xmloff/xmltkmap.hxx>
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmlnmspe.hxx>
33 #include <xmloff/families.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
36 #include <com/sun/star/sheet/XSpreadsheet.hpp>
37 #include <com/sun/star/table/XColumnRowRange.hpp>
38 #include <com/sun/star/sheet/XPrintAreas.hpp>
40 using namespace com::sun::star
;
41 using namespace xmloff::token
;
43 ScXMLTableColContext::ScXMLTableColContext( ScXMLImport
& rImport
,
45 const OUString
& rLName
,
46 const ::com::sun::star::uno::Reference
<
47 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
) :
48 SvXMLImportContext( rImport
, nPrfx
, rLName
),
49 sVisibility(GetXMLToken(XML_VISIBLE
))
52 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
53 const SvXMLTokenMap
& rAttrTokenMap
= GetScImport().GetTableColAttrTokenMap();
55 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
57 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
59 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName(
60 sAttrName
, &aLocalName
);
61 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
63 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
) )
65 case XML_TOK_TABLE_COL_ATTR_REPEATED
:
67 nColCount
= std::max
<sal_Int32
>(sValue
.toInt32(), 1);
68 nColCount
= std::min
<sal_Int32
>(nColCount
, MAXCOLCOUNT
);
71 case XML_TOK_TABLE_COL_ATTR_STYLE_NAME
:
76 case XML_TOK_TABLE_COL_ATTR_VISIBILITY
:
81 case XML_TOK_TABLE_COL_ATTR_DEFAULT_CELL_STYLE_NAME
:
83 sCellStyleName
= sValue
;
90 ScXMLTableColContext::~ScXMLTableColContext()
94 SvXMLImportContext
*ScXMLTableColContext::CreateChildContext( sal_uInt16 nPrefix
,
95 const OUString
& rLName
,
96 const ::com::sun::star::uno::Reference
<
97 ::com::sun::star::xml::sax::XAttributeList
>& /* xAttrList */ )
99 SvXMLImportContext
*pContext
= 0;
102 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
107 void ScXMLTableColContext::EndElement()
109 ScXMLImport
& rXMLImport
= GetScImport();
110 SCTAB nSheet
= rXMLImport
.GetTables().GetCurrentSheet();
111 sal_Int32 nCurrentColumn
= rXMLImport
.GetTables().GetCurrentColCount();
112 uno::Reference
<sheet::XSpreadsheet
> xSheet(rXMLImport
.GetTables().GetCurrentXSheet());
115 sal_Int32
nLastColumn(nCurrentColumn
+ nColCount
- 1);
116 if (nLastColumn
> MAXCOL
)
117 nLastColumn
= MAXCOL
;
118 if (nCurrentColumn
> MAXCOL
)
119 nCurrentColumn
= MAXCOL
;
120 uno::Reference
<table::XColumnRowRange
> xColumnRowRange (xSheet
->getCellRangeByPosition(nCurrentColumn
, 0, nLastColumn
, 0), uno::UNO_QUERY
);
121 if (xColumnRowRange
.is())
123 uno::Reference
<beans::XPropertySet
> xColumnProperties(xColumnRowRange
->getColumns(), uno::UNO_QUERY
);
124 if (xColumnProperties
.is())
126 if (!sStyleName
.isEmpty())
128 XMLTableStylesContext
*pStyles
= static_cast<XMLTableStylesContext
*>(rXMLImport
.GetAutoStyles());
131 XMLTableStyleContext
* pStyle
= const_cast<XMLTableStyleContext
*>(static_cast<const XMLTableStyleContext
*>(pStyles
->FindStyleChildContext(
132 XML_STYLE_FAMILY_TABLE_COLUMN
, sStyleName
, true)));
135 pStyle
->FillPropertySet(xColumnProperties
);
137 if ( nSheet
!= pStyle
->GetLastSheet() )
139 ScSheetSaveData
* pSheetData
= ScModelObj::getImplementation(rXMLImport
.GetModel())->GetSheetSaveData();
140 pSheetData
->AddColumnStyle( sStyleName
, ScAddress( (SCCOL
)nCurrentColumn
, 0, nSheet
) );
141 pStyle
->SetLastSheet(nSheet
);
146 OUString
sVisible(SC_UNONAME_CELLVIS
);
148 if (!IsXMLToken(sVisibility
, XML_VISIBLE
))
150 xColumnProperties
->setPropertyValue(sVisible
, uno::makeAny(bValue
));
155 // #i57915# ScXMLImport::SetStyleToRange can't handle empty style names.
156 // The default for a column if there is no attribute is the style "Default" (programmatic API name).
157 if ( sCellStyleName
.isEmpty() )
158 sCellStyleName
= "Default";
160 GetScImport().GetTables().AddColStyle(nColCount
, sCellStyleName
);
163 ScXMLTableColsContext::ScXMLTableColsContext( ScXMLImport
& rImport
,
165 const OUString
& rLName
,
166 const ::com::sun::star::uno::Reference
<
167 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
168 const bool bTempHeader
, const bool bTempGroup
) :
169 SvXMLImportContext( rImport
, nPrfx
, rLName
),
174 bHeader(bTempHeader
),
178 // don't have any attributes
180 nHeaderStartCol
= rImport
.GetTables().GetCurrentColCount();
183 nGroupStartCol
= rImport
.GetTables().GetCurrentColCount();
184 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
185 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
187 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
189 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName(
190 sAttrName
, &aLocalName
);
191 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
193 if (nPrefix
== XML_NAMESPACE_TABLE
&& IsXMLToken(aLocalName
, XML_DISPLAY
))
195 if (IsXMLToken(sValue
, XML_FALSE
))
196 bGroupDisplay
= false;
202 ScXMLTableColsContext::~ScXMLTableColsContext()
206 SvXMLImportContext
*ScXMLTableColsContext::CreateChildContext( sal_uInt16 nPrefix
,
207 const OUString
& rLName
,
208 const ::com::sun::star::uno::Reference
<
209 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
)
211 SvXMLImportContext
*pContext
= 0;
213 const SvXMLTokenMap
& rTokenMap
= GetScImport().GetTableColsElemTokenMap();
214 switch( rTokenMap
.Get( nPrefix
, rLName
) )
216 case XML_TOK_TABLE_COLS_COL_GROUP
:
217 pContext
= new ScXMLTableColsContext( GetScImport(), nPrefix
,
221 case XML_TOK_TABLE_COLS_HEADER_COLS
:
222 pContext
= new ScXMLTableColsContext( GetScImport(), nPrefix
,
226 case XML_TOK_TABLE_COLS_COLS
:
227 pContext
= new ScXMLTableColsContext( GetScImport(), nPrefix
,
231 case XML_TOK_TABLE_COLS_COL
:
232 pContext
= new ScXMLTableColContext( GetScImport(), nPrefix
,
240 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
245 void ScXMLTableColsContext::EndElement()
247 ScXMLImport
& rXMLImport
= GetScImport();
250 nHeaderEndCol
= rXMLImport
.GetTables().GetCurrentColCount();
252 if (nHeaderStartCol
<= nHeaderEndCol
)
254 uno::Reference
<sheet::XPrintAreas
> xPrintAreas (rXMLImport
.GetTables().GetCurrentXSheet(), uno::UNO_QUERY
);
255 if (xPrintAreas
.is())
257 if (!xPrintAreas
->getPrintTitleColumns())
259 xPrintAreas
->setPrintTitleColumns(true);
260 table::CellRangeAddress aColumnHeaderRange
;
261 aColumnHeaderRange
.StartColumn
= nHeaderStartCol
;
262 aColumnHeaderRange
.EndColumn
= nHeaderEndCol
;
263 xPrintAreas
->setTitleColumns(aColumnHeaderRange
);
267 table::CellRangeAddress
aColumnHeaderRange(xPrintAreas
->getTitleColumns());
268 aColumnHeaderRange
.EndColumn
= nHeaderEndCol
;
269 xPrintAreas
->setTitleColumns(aColumnHeaderRange
);
276 SCTAB nSheet
= rXMLImport
.GetTables().GetCurrentSheet();
277 nGroupEndCol
= rXMLImport
.GetTables().GetCurrentColCount();
279 if (nGroupStartCol
<= nGroupEndCol
)
281 ScDocument
* pDoc
= GetScImport().GetDocument();
284 ScXMLImport::MutexGuard
aGuard(GetScImport());
285 ScOutlineTable
* pOutlineTable
= pDoc
->GetOutlineTable(nSheet
, true);
288 ScOutlineArray
& rColArray
= pOutlineTable
->GetColArray();
290 rColArray
.Insert(static_cast<SCCOL
>(nGroupStartCol
), static_cast<SCCOL
>(nGroupEndCol
), bResized
, !bGroupDisplay
, true);
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */