Update ooo320-m1
[ooovba.git] / sc / source / filter / xml / xmlcoli.cxx
blob260a17a19f81bbcb6cb3f6a7b1eb01939dc96fd7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlcoli.cxx,v $
10 * $Revision: 1.23 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "xmlcoli.hxx"
39 #include "xmlimprt.hxx"
40 #include "global.hxx"
41 #include "xmlstyli.hxx"
42 #include "document.hxx"
43 #include "docuno.hxx"
44 #include "olinetab.hxx"
45 #include "sheetdata.hxx"
46 #include "unonames.hxx"
48 #include <xmloff/xmltkmap.hxx>
49 #include <xmloff/nmspmap.hxx>
50 #include <xmloff/xmlnmspe.hxx>
51 #include <xmloff/families.hxx>
52 #include <xmloff/xmltoken.hxx>
53 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
54 #include <com/sun/star/sheet/XSpreadsheet.hpp>
55 #include <com/sun/star/table/XColumnRowRange.hpp>
56 #include <com/sun/star/sheet/XPrintAreas.hpp>
58 using namespace com::sun::star;
59 using namespace xmloff::token;
61 //------------------------------------------------------------------
63 ScXMLTableColContext::ScXMLTableColContext( ScXMLImport& rImport,
64 USHORT nPrfx,
65 const ::rtl::OUString& rLName,
66 const ::com::sun::star::uno::Reference<
67 ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) :
68 SvXMLImportContext( rImport, nPrfx, rLName ),
69 sVisibility(GetXMLToken(XML_VISIBLE))
71 nColCount = 1;
72 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
73 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableColAttrTokenMap();
75 for( sal_Int16 i=0; i < nAttrCount; ++i )
77 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
78 rtl::OUString aLocalName;
79 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
80 sAttrName, &aLocalName );
81 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
83 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
85 case XML_TOK_TABLE_COL_ATTR_REPEATED:
87 nColCount = sValue.toInt32();
89 break;
90 case XML_TOK_TABLE_COL_ATTR_STYLE_NAME:
92 sStyleName = sValue;
94 break;
95 case XML_TOK_TABLE_COL_ATTR_VISIBILITY:
97 sVisibility = sValue;
99 break;
100 case XML_TOK_TABLE_COL_ATTR_DEFAULT_CELL_STYLE_NAME:
102 sCellStyleName = sValue;
104 break;
109 ScXMLTableColContext::~ScXMLTableColContext()
113 SvXMLImportContext *ScXMLTableColContext::CreateChildContext( USHORT nPrefix,
114 const ::rtl::OUString& rLName,
115 const ::com::sun::star::uno::Reference<
116 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
118 SvXMLImportContext *pContext = 0;
120 const SvXMLTokenMap& rTokenMap = GetScImport().GetTableRowElemTokenMap();
121 sal_Bool bHeader = sal_False;
122 switch( rTokenMap.Get( nPrefix, rLName ) )
124 case XML_TOK_TABLE_ROW_CELL:
125 // if( IsInsertCellPossible() )
126 pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
127 rLName, xAttrList//,
128 //this
130 break;
131 case XML_TOK_TABLE_ROW_COVERED_CELL:
132 // if( IsInsertCellPossible() )
133 pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
134 rLName, xAttrList//,
135 //this
137 break;
140 if( !pContext )
141 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
143 return pContext;
146 void ScXMLTableColContext::EndElement()
148 ScXMLImport& rXMLImport = GetScImport();
149 sal_Int32 nSheet = rXMLImport.GetTables().GetCurrentSheet();
150 sal_Int32 nCurrentColumn = rXMLImport.GetTables().GetCurrentColumn();
151 uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
152 if(xSheet.is())
154 sal_Int32 nLastColumn(nCurrentColumn + nColCount - 1);
155 if (nLastColumn > MAXCOL)
156 nLastColumn = MAXCOL;
157 if (nCurrentColumn > MAXCOL)
158 nCurrentColumn = MAXCOL;
159 uno::Reference<table::XColumnRowRange> xColumnRowRange (xSheet->getCellRangeByPosition(nCurrentColumn, 0, nLastColumn, 0), uno::UNO_QUERY);
160 if (xColumnRowRange.is())
162 uno::Reference <beans::XPropertySet> xColumnProperties(xColumnRowRange->getColumns(), uno::UNO_QUERY);
163 if (xColumnProperties.is())
165 if (sStyleName.getLength())
167 XMLTableStylesContext *pStyles = (XMLTableStylesContext *)rXMLImport.GetAutoStyles();
168 if ( pStyles )
170 XMLTableStyleContext* pStyle = (XMLTableStyleContext *)pStyles->FindStyleChildContext(
171 XML_STYLE_FAMILY_TABLE_COLUMN, sStyleName, sal_True);
172 if (pStyle)
174 pStyle->FillPropertySet(xColumnProperties);
176 if ( nSheet != pStyle->GetLastSheet() )
178 ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
179 pSheetData->AddColumnStyle( sStyleName, ScAddress( (SCCOL)nCurrentColumn, 0, (SCTAB)nSheet ) );
180 pStyle->SetLastSheet(nSheet);
185 rtl::OUString sVisible(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLVIS));
186 sal_Bool bValue(sal_True);
187 if (!IsXMLToken(sVisibility, XML_VISIBLE))
188 bValue = sal_False;
189 xColumnProperties->setPropertyValue(sVisible, uno::makeAny(bValue));
194 // #i57915# ScXMLImport::SetStyleToRange can't handle empty style names.
195 // The default for a column if there is no attribute is the style "Default" (programmatic API name).
196 if ( !sCellStyleName.getLength() )
197 sCellStyleName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Default" ));
199 GetScImport().GetTables().AddColCount(nColCount);
200 GetScImport().GetTables().AddColStyle(nColCount, sCellStyleName);
203 ScXMLTableColsContext::ScXMLTableColsContext( ScXMLImport& rImport,
204 USHORT nPrfx,
205 const ::rtl::OUString& rLName,
206 const ::com::sun::star::uno::Reference<
207 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
208 const sal_Bool bTempHeader, const sal_Bool bTempGroup) :
209 SvXMLImportContext( rImport, nPrfx, rLName ),
210 nHeaderStartCol(0),
211 nHeaderEndCol(0),
212 nGroupStartCol(0),
213 nGroupEndCol(0),
214 bHeader(bTempHeader),
215 bGroup(bTempGroup),
216 bGroupDisplay(sal_True)
218 // don't have any attributes
219 if (bHeader)
220 nHeaderStartCol = rImport.GetTables().GetCurrentColumn();
221 else if (bGroup)
223 nGroupStartCol = rImport.GetTables().GetCurrentColumn();
224 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
225 for( sal_Int16 i=0; i < nAttrCount; ++i )
227 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
228 rtl::OUString aLocalName;
229 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
230 sAttrName, &aLocalName );
231 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
233 if (nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(aLocalName, XML_DISPLAY))
235 if (IsXMLToken(sValue, XML_FALSE))
236 bGroupDisplay = sal_False;
242 ScXMLTableColsContext::~ScXMLTableColsContext()
246 SvXMLImportContext *ScXMLTableColsContext::CreateChildContext( USHORT nPrefix,
247 const ::rtl::OUString& rLName,
248 const ::com::sun::star::uno::Reference<
249 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
251 SvXMLImportContext *pContext = 0;
253 const SvXMLTokenMap& rTokenMap = GetScImport().GetTableColsElemTokenMap();
254 switch( rTokenMap.Get( nPrefix, rLName ) )
256 case XML_TOK_TABLE_COLS_COL_GROUP:
257 pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
258 rLName, xAttrList,
259 sal_False, sal_True );
260 break;
261 case XML_TOK_TABLE_COLS_HEADER_COLS:
262 pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
263 rLName, xAttrList,
264 sal_True, sal_False );
265 break;
266 case XML_TOK_TABLE_COLS_COLS:
267 pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
268 rLName, xAttrList,
269 sal_False, sal_False );
270 break;
271 case XML_TOK_TABLE_COLS_COL:
272 pContext = new ScXMLTableColContext( GetScImport(), nPrefix,
273 rLName, xAttrList//,
274 //this
276 break;
279 if( !pContext )
280 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
282 return pContext;
285 void ScXMLTableColsContext::EndElement()
287 ScXMLImport& rXMLImport = GetScImport();
288 if (bHeader)
290 nHeaderEndCol = rXMLImport.GetTables().GetCurrentColumn();
291 nHeaderEndCol--;
292 if (nHeaderStartCol <= nHeaderEndCol)
294 uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
295 if (xPrintAreas.is())
297 if (!xPrintAreas->getPrintTitleColumns())
299 xPrintAreas->setPrintTitleColumns(sal_True);
300 table::CellRangeAddress aColumnHeaderRange;
301 aColumnHeaderRange.StartColumn = nHeaderStartCol;
302 aColumnHeaderRange.EndColumn = nHeaderEndCol;
303 xPrintAreas->setTitleColumns(aColumnHeaderRange);
305 else
307 table::CellRangeAddress aColumnHeaderRange(xPrintAreas->getTitleColumns());
308 aColumnHeaderRange.EndColumn = nHeaderEndCol;
309 xPrintAreas->setTitleColumns(aColumnHeaderRange);
314 else if (bGroup)
316 sal_Int32 nSheet = rXMLImport.GetTables().GetCurrentSheet();
317 nGroupEndCol = rXMLImport.GetTables().GetCurrentColumn();
318 nGroupEndCol--;
319 if (nGroupStartCol <= nGroupEndCol)
321 ScDocument* pDoc = GetScImport().GetDocument();
322 if (pDoc)
324 rXMLImport.LockSolarMutex();
325 ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(static_cast<SCTAB>(nSheet), sal_True);
326 ScOutlineArray* pColArray = pOutlineTable ? pOutlineTable->GetColArray() : NULL;
327 if (pColArray)
329 sal_Bool bResized;
330 pColArray->Insert(static_cast<SCCOL>(nGroupStartCol), static_cast<SCCOL>(nGroupEndCol), bResized, !bGroupDisplay, sal_True);
332 rXMLImport.UnlockSolarMutex();