blob: dab932121ef568476035a39ee38a4a64a12dcc77 [file] [log] [blame]
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sc.hxx"
// INCLUDE ---------------------------------------------------------------
#include "xmlcoli.hxx"
#include "xmlimprt.hxx"
#include "global.hxx"
#include "xmlstyli.hxx"
#include "document.hxx"
#include "docuno.hxx"
#include "olinetab.hxx"
#include "sheetdata.hxx"
#include "unonames.hxx"
#include <xmloff/xmltkmap.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/xmlnmspe.hxx>
#include <xmloff/families.hxx>
#include <xmloff/xmltoken.hxx>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
#include <com/sun/star/table/XColumnRowRange.hpp>
#include <com/sun/star/sheet/XPrintAreas.hpp>
using namespace com::sun::star;
using namespace xmloff::token;
//------------------------------------------------------------------
ScXMLTableColContext::ScXMLTableColContext( ScXMLImport& rImport,
sal_uInt16 nPrfx,
const ::rtl::OUString& rLName,
const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList>& xAttrList ) :
SvXMLImportContext( rImport, nPrfx, rLName ),
sVisibility(GetXMLToken(XML_VISIBLE))
{
nColCount = 1;
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableColAttrTokenMap();
for( sal_Int16 i=0; i < nAttrCount; ++i )
{
const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
rtl::OUString aLocalName;
sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
sAttrName, &aLocalName );
const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
{
case XML_TOK_TABLE_COL_ATTR_REPEATED:
{
nColCount = sValue.toInt32();
}
break;
case XML_TOK_TABLE_COL_ATTR_STYLE_NAME:
{
sStyleName = sValue;
}
break;
case XML_TOK_TABLE_COL_ATTR_VISIBILITY:
{
sVisibility = sValue;
}
break;
case XML_TOK_TABLE_COL_ATTR_DEFAULT_CELL_STYLE_NAME:
{
sCellStyleName = sValue;
}
break;
}
}
}
ScXMLTableColContext::~ScXMLTableColContext()
{
}
SvXMLImportContext *ScXMLTableColContext::CreateChildContext( sal_uInt16 nPrefix,
const ::rtl::OUString& rLName,
const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
{
SvXMLImportContext *pContext = 0;
/*
const SvXMLTokenMap& rTokenMap = GetScImport().GetTableRowElemTokenMap();
sal_Bool bHeader = sal_False;
switch( rTokenMap.Get( nPrefix, rLName ) )
{
case XML_TOK_TABLE_ROW_CELL:
// if( IsInsertCellPossible() )
pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
rLName, xAttrList//,
//this
);
break;
case XML_TOK_TABLE_ROW_COVERED_CELL:
// if( IsInsertCellPossible() )
pContext = new ScXMLTableRowCellContext( GetScImport(), nPrefix,
rLName, xAttrList//,
//this
);
break;
}*/
if( !pContext )
pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
return pContext;
}
void ScXMLTableColContext::EndElement()
{
ScXMLImport& rXMLImport = GetScImport();
sal_Int32 nSheet = rXMLImport.GetTables().GetCurrentSheet();
sal_Int32 nCurrentColumn = rXMLImport.GetTables().GetCurrentColumn();
uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
if(xSheet.is())
{
sal_Int32 nLastColumn(nCurrentColumn + nColCount - 1);
if (nLastColumn > MAXCOL)
nLastColumn = MAXCOL;
if (nCurrentColumn > MAXCOL)
nCurrentColumn = MAXCOL;
uno::Reference<table::XColumnRowRange> xColumnRowRange (xSheet->getCellRangeByPosition(nCurrentColumn, 0, nLastColumn, 0), uno::UNO_QUERY);
if (xColumnRowRange.is())
{
uno::Reference <beans::XPropertySet> xColumnProperties(xColumnRowRange->getColumns(), uno::UNO_QUERY);
if (xColumnProperties.is())
{
if (sStyleName.getLength())
{
XMLTableStylesContext *pStyles = (XMLTableStylesContext *)rXMLImport.GetAutoStyles();
if ( pStyles )
{
XMLTableStyleContext* pStyle = (XMLTableStyleContext *)pStyles->FindStyleChildContext(
XML_STYLE_FAMILY_TABLE_COLUMN, sStyleName, sal_True);
if (pStyle)
{
pStyle->FillPropertySet(xColumnProperties);
if ( nSheet != pStyle->GetLastSheet() )
{
ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
pSheetData->AddColumnStyle( sStyleName, ScAddress( (SCCOL)nCurrentColumn, 0, (SCTAB)nSheet ) );
pStyle->SetLastSheet(nSheet);
}
}
}
}
rtl::OUString sVisible(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLVIS));
sal_Bool bValue(sal_True);
if (!IsXMLToken(sVisibility, XML_VISIBLE))
bValue = sal_False;
xColumnProperties->setPropertyValue(sVisible, uno::makeAny(bValue));
}
}
}
// #i57915# ScXMLImport::SetStyleToRange can't handle empty style names.
// The default for a column if there is no attribute is the style "Default" (programmatic API name).
if ( !sCellStyleName.getLength() )
sCellStyleName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Default" ));
GetScImport().GetTables().AddColCount(nColCount);
GetScImport().GetTables().AddColStyle(nColCount, sCellStyleName);
}
ScXMLTableColsContext::ScXMLTableColsContext( ScXMLImport& rImport,
sal_uInt16 nPrfx,
const ::rtl::OUString& rLName,
const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList>& xAttrList,
const sal_Bool bTempHeader, const sal_Bool bTempGroup) :
SvXMLImportContext( rImport, nPrfx, rLName ),
nHeaderStartCol(0),
nHeaderEndCol(0),
nGroupStartCol(0),
nGroupEndCol(0),
bHeader(bTempHeader),
bGroup(bTempGroup),
bGroupDisplay(sal_True)
{
// don't have any attributes
if (bHeader)
nHeaderStartCol = rImport.GetTables().GetCurrentColumn();
else if (bGroup)
{
nGroupStartCol = rImport.GetTables().GetCurrentColumn();
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for( sal_Int16 i=0; i < nAttrCount; ++i )
{
const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
rtl::OUString aLocalName;
sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
sAttrName, &aLocalName );
const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
if (nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(aLocalName, XML_DISPLAY))
{
if (IsXMLToken(sValue, XML_FALSE))
bGroupDisplay = sal_False;
}
}
}
}
ScXMLTableColsContext::~ScXMLTableColsContext()
{
}
SvXMLImportContext *ScXMLTableColsContext::CreateChildContext( sal_uInt16 nPrefix,
const ::rtl::OUString& rLName,
const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList>& xAttrList )
{
SvXMLImportContext *pContext = 0;
const SvXMLTokenMap& rTokenMap = GetScImport().GetTableColsElemTokenMap();
switch( rTokenMap.Get( nPrefix, rLName ) )
{
case XML_TOK_TABLE_COLS_COL_GROUP:
pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
rLName, xAttrList,
sal_False, sal_True );
break;
case XML_TOK_TABLE_COLS_HEADER_COLS:
pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
rLName, xAttrList,
sal_True, sal_False );
break;
case XML_TOK_TABLE_COLS_COLS:
pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
rLName, xAttrList,
sal_False, sal_False );
break;
case XML_TOK_TABLE_COLS_COL:
pContext = new ScXMLTableColContext( GetScImport(), nPrefix,
rLName, xAttrList//,
//this
);
break;
}
if( !pContext )
pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
return pContext;
}
void ScXMLTableColsContext::EndElement()
{
ScXMLImport& rXMLImport = GetScImport();
if (bHeader)
{
nHeaderEndCol = rXMLImport.GetTables().GetCurrentColumn();
nHeaderEndCol--;
if (nHeaderStartCol <= nHeaderEndCol)
{
uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
if (xPrintAreas.is())
{
if (!xPrintAreas->getPrintTitleColumns())
{
xPrintAreas->setPrintTitleColumns(sal_True);
table::CellRangeAddress aColumnHeaderRange;
aColumnHeaderRange.StartColumn = nHeaderStartCol;
aColumnHeaderRange.EndColumn = nHeaderEndCol;
xPrintAreas->setTitleColumns(aColumnHeaderRange);
}
else
{
table::CellRangeAddress aColumnHeaderRange(xPrintAreas->getTitleColumns());
aColumnHeaderRange.EndColumn = nHeaderEndCol;
xPrintAreas->setTitleColumns(aColumnHeaderRange);
}
}
}
}
else if (bGroup)
{
sal_Int32 nSheet = rXMLImport.GetTables().GetCurrentSheet();
nGroupEndCol = rXMLImport.GetTables().GetCurrentColumn();
nGroupEndCol--;
if (nGroupStartCol <= nGroupEndCol)
{
ScDocument* pDoc = GetScImport().GetDocument();
if (pDoc)
{
rXMLImport.LockSolarMutex();
ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(static_cast<SCTAB>(nSheet), sal_True);
ScOutlineArray* pColArray = pOutlineTable ? pOutlineTable->GetColArray() : NULL;
if (pColArray)
{
sal_Bool bResized;
pColArray->Insert(static_cast<SCCOL>(nGroupStartCol), static_cast<SCCOL>(nGroupEndCol), bResized, !bGroupDisplay, sal_True);
}
rXMLImport.UnlockSolarMutex();
}
}
}
}