fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / xml / xmlcoli.cxx
blob86227a593df7a8fe0c47d506f004dc56c62797d4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "global.hxx"
23 #include "xmlstyli.hxx"
24 #include "document.hxx"
25 #include "docuno.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,
44 sal_uInt16 nPrfx,
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))
51 nColCount = 1;
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 ));
58 OUString aLocalName;
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);
70 break;
71 case XML_TOK_TABLE_COL_ATTR_STYLE_NAME:
73 sStyleName = sValue;
75 break;
76 case XML_TOK_TABLE_COL_ATTR_VISIBILITY:
78 sVisibility = sValue;
80 break;
81 case XML_TOK_TABLE_COL_ATTR_DEFAULT_CELL_STYLE_NAME:
83 sCellStyleName = sValue;
85 break;
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;
101 if( !pContext )
102 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
104 return pContext;
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());
113 if(xSheet.is())
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());
129 if ( pStyles )
131 XMLTableStyleContext* pStyle = const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
132 XML_STYLE_FAMILY_TABLE_COLUMN, sStyleName, true)));
133 if (pStyle)
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);
147 bool bValue(true);
148 if (!IsXMLToken(sVisibility, XML_VISIBLE))
149 bValue = false;
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,
164 sal_uInt16 nPrfx,
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 ),
170 nHeaderStartCol(0),
171 nHeaderEndCol(0),
172 nGroupStartCol(0),
173 nGroupEndCol(0),
174 bHeader(bTempHeader),
175 bGroup(bTempGroup),
176 bGroupDisplay(true)
178 // don't have any attributes
179 if (bHeader)
180 nHeaderStartCol = rImport.GetTables().GetCurrentColCount();
181 else if (bGroup)
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 ));
188 OUString aLocalName;
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,
218 rLName, xAttrList,
219 false, true );
220 break;
221 case XML_TOK_TABLE_COLS_HEADER_COLS:
222 pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
223 rLName, xAttrList,
224 true, false );
225 break;
226 case XML_TOK_TABLE_COLS_COLS:
227 pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
228 rLName, xAttrList,
229 false, false );
230 break;
231 case XML_TOK_TABLE_COLS_COL:
232 pContext = new ScXMLTableColContext( GetScImport(), nPrefix,
233 rLName, xAttrList//,
234 //this
236 break;
239 if( !pContext )
240 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
242 return pContext;
245 void ScXMLTableColsContext::EndElement()
247 ScXMLImport& rXMLImport = GetScImport();
248 if (bHeader)
250 nHeaderEndCol = rXMLImport.GetTables().GetCurrentColCount();
251 nHeaderEndCol--;
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);
265 else
267 table::CellRangeAddress aColumnHeaderRange(xPrintAreas->getTitleColumns());
268 aColumnHeaderRange.EndColumn = nHeaderEndCol;
269 xPrintAreas->setTitleColumns(aColumnHeaderRange);
274 else if (bGroup)
276 SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
277 nGroupEndCol = rXMLImport.GetTables().GetCurrentColCount();
278 nGroupEndCol--;
279 if (nGroupStartCol <= nGroupEndCol)
281 ScDocument* pDoc = GetScImport().GetDocument();
282 if (pDoc)
284 ScXMLImport::MutexGuard aGuard(GetScImport());
285 ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(nSheet, true);
286 if (pOutlineTable)
288 ScOutlineArray& rColArray = pOutlineTable->GetColArray();
289 bool bResized;
290 rColArray.Insert(static_cast<SCCOL>(nGroupStartCol), static_cast<SCCOL>(nGroupEndCol), bResized, !bGroupDisplay, true);
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */