2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: SchXMLChartContext.cxx,v $
|
|
|
|
*
|
2002-11-11 14:53:31 +00:00
|
|
|
* $Revision: 1.28 $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2002-11-11 14:53:31 +00:00
|
|
|
* last change: $Author: bm $ $Date: 2002-11-11 15:53:31 $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (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.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include "SchXMLChartContext.hxx"
|
|
|
|
#include "SchXMLImport.hxx"
|
|
|
|
#include "SchXMLPlotAreaContext.hxx"
|
|
|
|
#include "SchXMLParagraphContext.hxx"
|
|
|
|
#include "SchXMLTableContext.hxx"
|
|
|
|
|
|
|
|
#ifndef _TOOLS_DEBUG_HXX
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _XMLOFF_XMLNMSPE_HXX
|
|
|
|
#include "xmlnmspe.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _XMLOFF_XMLEMENT_HXX
|
|
|
|
#include "xmlement.hxx"
|
|
|
|
#endif
|
2001-06-29 20:07:26 +00:00
|
|
|
#ifndef _XMLOFF_XMLTOKEN_HXX
|
|
|
|
#include "xmltoken.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
#endif
|
|
|
|
#ifndef _XMLOFF_NMSPMAP_HXX
|
|
|
|
#include "nmspmap.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _XMLOFF_XMLUCONV_HXX
|
|
|
|
#include "xmluconv.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _XMLOFF_XMLSTYLE_HXX
|
|
|
|
#include "xmlstyle.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _XMLOFF_PRSTYLEI_HXX_
|
|
|
|
#include "prstylei.hxx"
|
|
|
|
#endif
|
|
|
|
|
2001-10-23 09:02:41 +00:00
|
|
|
#include "vector"
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#ifndef _COM_SUN_STAR_CHART_XCHARTDOCUMENT_HPP_
|
|
|
|
#include <com/sun/star/chart/XChartDocument.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_CHART_XDIAGRAM_HPP_
|
|
|
|
#include <com/sun/star/chart/XDiagram.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_XML_SAX_XATTRIBUTELIST_HPP_
|
|
|
|
#include <com/sun/star/xml/sax/XAttributeList.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_CHART_CHARTLEGENDPOSITION_HPP_
|
|
|
|
#include <com/sun/star/chart/ChartLegendPosition.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_UTIL_XSTRINGMAPPING_HPP_
|
|
|
|
#include <com/sun/star/util/XStringMapping.hpp>
|
|
|
|
#endif
|
2000-11-27 08:09:12 +00:00
|
|
|
#ifndef _COM_SUN_STAR_DRAWING_XDRAWPAGESUPPLIER_HPP_
|
|
|
|
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_DRAWING_XDRAWPAGE_HPP_
|
|
|
|
#include <com/sun/star/drawing/XDrawPage.hpp>
|
|
|
|
#endif
|
2001-03-26 14:37:47 +00:00
|
|
|
#ifndef _COM_SUN_STAR_CHART_CHARTDATAROWSOURCE_HPP_
|
|
|
|
#include <com/sun/star/chart/ChartDataRowSource.hpp>
|
|
|
|
#endif
|
2001-03-29 15:21:08 +00:00
|
|
|
#ifndef _COM_SUN_STAR_CHART_XCHARTDATAARRAY_HPP_
|
|
|
|
#include <com/sun/star/chart/XChartDataArray.hpp>
|
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
using namespace com::sun::star;
|
2001-06-15 09:37:08 +00:00
|
|
|
using namespace ::xmloff::token;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-03-27 12:24:46 +00:00
|
|
|
#define SCH_BUILDCHART(xDoc) if( xDoc->hasControllersLocked() ) {\
|
|
|
|
xDoc->unlockControllers();\
|
|
|
|
xDoc->lockControllers(); }
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
enum SchXMLChartType
|
|
|
|
{
|
|
|
|
XML_CHART_CLASS_LINE,
|
|
|
|
XML_CHART_CLASS_AREA,
|
|
|
|
XML_CHART_CLASS_CIRCLE,
|
|
|
|
XML_CHART_CLASS_RING,
|
|
|
|
XML_CHART_CLASS_SCATTER,
|
|
|
|
XML_CHART_CLASS_RADAR,
|
|
|
|
XML_CHART_CLASS_BAR,
|
|
|
|
XML_CHART_CLASS_STOCK,
|
2000-11-24 14:08:19 +00:00
|
|
|
XML_CHART_CLASS_BUBBLE, // not yet implemented
|
|
|
|
XML_CHART_CLASS_ADDIN
|
2000-09-18 16:07:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
static __FAR_DATA SvXMLEnumMapEntry aXMLChartClassMap[] =
|
|
|
|
{
|
2001-06-15 09:37:08 +00:00
|
|
|
{ XML_LINE, XML_CHART_CLASS_LINE },
|
|
|
|
{ XML_AREA, XML_CHART_CLASS_AREA },
|
|
|
|
{ XML_CIRCLE, XML_CHART_CLASS_CIRCLE },
|
|
|
|
{ XML_RING, XML_CHART_CLASS_RING },
|
|
|
|
{ XML_SCATTER, XML_CHART_CLASS_SCATTER },
|
|
|
|
{ XML_RADAR, XML_CHART_CLASS_RADAR },
|
|
|
|
{ XML_BAR, XML_CHART_CLASS_BAR },
|
|
|
|
{ XML_STOCK, XML_CHART_CLASS_STOCK },
|
|
|
|
{ XML_BUBBLE, XML_CHART_CLASS_BUBBLE },
|
2001-06-26 12:08:17 +00:00
|
|
|
{ XML_ADD_IN, XML_CHART_CLASS_ADDIN },
|
2001-06-15 09:37:08 +00:00
|
|
|
{ XML_TOKEN_INVALID, 0 }
|
2000-09-18 16:07:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static __FAR_DATA SvXMLEnumMapEntry aXMLLegendAlignmentMap[] =
|
|
|
|
{
|
2001-06-15 09:37:08 +00:00
|
|
|
{ XML_LEFT, chart::ChartLegendPosition_LEFT },
|
|
|
|
{ XML_TOP, chart::ChartLegendPosition_TOP },
|
|
|
|
{ XML_RIGHT, chart::ChartLegendPosition_RIGHT },
|
|
|
|
{ XML_BOTTOM, chart::ChartLegendPosition_BOTTOM },
|
|
|
|
{ XML_TOKEN_INVALID, 0 }
|
2000-09-18 16:07:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
SchXMLChartContext::SchXMLChartContext( SchXMLImportHelper& rImpHelper,
|
|
|
|
SvXMLImport& rImport, const rtl::OUString& rLocalName ) :
|
|
|
|
SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
|
|
|
|
mrImportHelper( rImpHelper ),
|
2001-03-29 10:08:57 +00:00
|
|
|
mbHasOwnTable( sal_False ),
|
|
|
|
mbHasLegend( sal_False )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SchXMLChartContext::~SchXMLChartContext()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void SchXMLChartContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
|
|
|
|
{
|
|
|
|
// parse attributes
|
|
|
|
sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
|
|
|
|
rtl::OUString aValue;
|
|
|
|
const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetChartAttrTokenMap();
|
2000-11-27 08:09:12 +00:00
|
|
|
awt::Size aChartSize;
|
2001-03-26 14:37:47 +00:00
|
|
|
// this flag is necessarry for pie charts in the core
|
|
|
|
sal_Bool bSetSwitchData = sal_False;
|
2001-05-04 16:18:36 +00:00
|
|
|
sal_Bool bDomainForDefaultDataNeeded = sal_False;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2000-11-24 14:08:19 +00:00
|
|
|
rtl::OUString aServiceName;
|
2000-11-29 11:33:52 +00:00
|
|
|
rtl::OUString sAutoStyleName;
|
2000-11-24 14:08:19 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
for( sal_Int16 i = 0; i < nAttrCount; i++ )
|
|
|
|
{
|
|
|
|
rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
|
|
|
|
rtl::OUString aLocalName;
|
|
|
|
rtl::OUString aValue = xAttrList->getValueByIndex( i );
|
|
|
|
USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
|
|
|
|
|
|
|
|
switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
|
|
|
|
{
|
|
|
|
case XML_TOK_CHART_CLASS:
|
|
|
|
{
|
|
|
|
USHORT nEnumVal;
|
|
|
|
if( GetImport().GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLChartClassMap ))
|
|
|
|
{
|
|
|
|
switch( nEnumVal )
|
|
|
|
{
|
|
|
|
case XML_CHART_CLASS_LINE:
|
|
|
|
aServiceName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.chart.LineDiagram" ));
|
|
|
|
break;
|
|
|
|
case XML_CHART_CLASS_AREA:
|
|
|
|
aServiceName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.chart.AreaDiagram" ));
|
|
|
|
break;
|
|
|
|
case XML_CHART_CLASS_CIRCLE:
|
|
|
|
aServiceName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.chart.PieDiagram" ));
|
2001-03-26 14:37:47 +00:00
|
|
|
bSetSwitchData = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
case XML_CHART_CLASS_RING:
|
|
|
|
aServiceName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.chart.DonutDiagram" ));
|
|
|
|
break;
|
|
|
|
case XML_CHART_CLASS_SCATTER:
|
|
|
|
aServiceName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.chart.XYDiagram" ));
|
2001-05-04 16:18:36 +00:00
|
|
|
bDomainForDefaultDataNeeded = sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
case XML_CHART_CLASS_RADAR:
|
|
|
|
aServiceName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.chart.NetDiagram" ));
|
|
|
|
break;
|
|
|
|
case XML_CHART_CLASS_BAR:
|
|
|
|
aServiceName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.chart.BarDiagram" ));
|
|
|
|
break;
|
|
|
|
case XML_CHART_CLASS_STOCK:
|
|
|
|
aServiceName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"com.sun.star.chart.StockDiagram" ));
|
|
|
|
break;
|
|
|
|
case XML_CHART_CLASS_BUBBLE:
|
|
|
|
DBG_ERROR( "Bubble chart not supported yet" );
|
|
|
|
break;
|
2000-11-24 14:08:19 +00:00
|
|
|
case XML_CHART_CLASS_ADDIN:
|
|
|
|
// service is taken from add-in-name attribute
|
2001-06-26 12:08:17 +00:00
|
|
|
|
|
|
|
// for service charts assume domain in base type
|
|
|
|
// if base type doesn't use a domain this is ok,
|
|
|
|
// the data just grows bigger
|
|
|
|
bDomainForDefaultDataNeeded = sal_True;
|
2000-11-24 14:08:19 +00:00
|
|
|
break;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XML_TOK_CHART_WIDTH:
|
2000-11-27 08:09:12 +00:00
|
|
|
GetImport().GetMM100UnitConverter().convertMeasure( aChartSize.Width, aValue );
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XML_TOK_CHART_HEIGHT:
|
2000-11-27 08:09:12 +00:00
|
|
|
GetImport().GetMM100UnitConverter().convertMeasure( aChartSize.Height, aValue );
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XML_TOK_CHART_STYLE_NAME:
|
2000-11-29 11:33:52 +00:00
|
|
|
sAutoStyleName = aValue;
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
2000-11-24 14:08:19 +00:00
|
|
|
|
|
|
|
case XML_TOK_CHART_ADDIN_NAME:
|
|
|
|
aServiceName = aValue;
|
2000-11-29 11:33:52 +00:00
|
|
|
break;
|
2001-10-23 09:02:41 +00:00
|
|
|
|
|
|
|
case XML_TOK_CHART_COL_MAPPING:
|
|
|
|
msColTrans = aValue;
|
|
|
|
break;
|
|
|
|
case XML_TOK_CHART_ROW_MAPPING:
|
|
|
|
msRowTrans = aValue;
|
|
|
|
break;
|
2000-11-24 14:08:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-08 13:57:28 +00:00
|
|
|
InitChart (aChartSize, bDomainForDefaultDataNeeded, aServiceName, bSetSwitchData);
|
2000-11-27 08:09:12 +00:00
|
|
|
|
2000-12-06 16:05:00 +00:00
|
|
|
// set auto-styles for Area
|
|
|
|
uno::Reference< beans::XPropertySet > xProp( mrImportHelper.GetChartDocument()->getArea(), uno::UNO_QUERY );
|
2000-11-29 11:33:52 +00:00
|
|
|
if( xProp.is())
|
|
|
|
{
|
|
|
|
const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
|
|
|
|
if( pStylesCtxt )
|
|
|
|
{
|
|
|
|
const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
|
|
|
|
mrImportHelper.GetChartFamilyID(), sAutoStyleName );
|
|
|
|
|
|
|
|
if( pStyle && pStyle->ISA( XMLPropStyleContext ))
|
|
|
|
(( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-27 08:09:12 +00:00
|
|
|
// prevent BuildChart from now on
|
|
|
|
uno::Reference< frame::XModel > xModel( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
|
|
|
|
if( xModel.is())
|
|
|
|
xModel->lockControllers();
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchXMLChartContext::EndElement()
|
|
|
|
{
|
|
|
|
uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument();
|
|
|
|
uno::Reference< beans::XPropertySet > xProp( xDoc, uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if( xProp.is())
|
|
|
|
{
|
|
|
|
if( maMainTitle.getLength())
|
|
|
|
{
|
2000-11-24 14:08:19 +00:00
|
|
|
uno::Reference< beans::XPropertySet > xTitleProp( xDoc->getTitle(), uno::UNO_QUERY );
|
|
|
|
if( xTitleProp.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
uno::Any aAny;
|
|
|
|
aAny <<= maMainTitle;
|
|
|
|
xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
|
|
|
|
}
|
|
|
|
catch( beans::UnknownPropertyException )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "Property String for Title not available" );
|
|
|
|
}
|
2001-06-25 11:21:40 +00:00
|
|
|
/* uno::Reference< drawing::XShape > xShape( xTitleProp, uno::UNO_QUERY );
|
2001-03-27 12:24:46 +00:00
|
|
|
if( xShape.is())
|
|
|
|
{
|
|
|
|
// perform build chart with new title string
|
|
|
|
// so that setting the position works correctly
|
|
|
|
if( xDoc.is())
|
|
|
|
{
|
|
|
|
xDoc->unlockControllers();
|
|
|
|
xDoc->lockControllers();
|
|
|
|
}
|
|
|
|
xShape->setPosition( maMainTitlePos );
|
|
|
|
}
|
2001-06-25 11:21:40 +00:00
|
|
|
*/ }
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
if( maSubTitle.getLength())
|
|
|
|
{
|
2000-11-24 14:08:19 +00:00
|
|
|
uno::Reference< beans::XPropertySet > xTitleProp( xDoc->getSubTitle(), uno::UNO_QUERY );
|
|
|
|
if( xTitleProp.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
uno::Any aAny;
|
|
|
|
aAny <<= maSubTitle;
|
|
|
|
xTitleProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "String" )), aAny );
|
|
|
|
}
|
|
|
|
catch( beans::UnknownPropertyException )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "Property String for Title not available" );
|
|
|
|
}
|
2001-06-25 11:21:40 +00:00
|
|
|
/* uno::Reference< drawing::XShape > xShape( xTitleProp, uno::UNO_QUERY );
|
2001-03-27 12:24:46 +00:00
|
|
|
if( xShape.is())
|
|
|
|
{
|
|
|
|
// perform build chart with new title string
|
|
|
|
// so that setting the position works correctly
|
|
|
|
if( xDoc.is())
|
|
|
|
{
|
|
|
|
xDoc->unlockControllers();
|
|
|
|
xDoc->lockControllers();
|
|
|
|
}
|
|
|
|
xShape->setPosition( maSubTitlePos );
|
|
|
|
}
|
2001-06-25 11:21:40 +00:00
|
|
|
*/ }
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-25 11:21:40 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
if( mbHasOwnTable )
|
|
|
|
{
|
|
|
|
// apply data read in table sub-element to chart
|
2001-04-10 09:25:34 +00:00
|
|
|
// SchXMLTableHelper::applyTable( maTable, maSeriesAddresses, msCategoriesAddress, xDoc );
|
|
|
|
SchXMLTableHelper::applyTableSimple( maTable, xDoc );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-15 11:27:08 +00:00
|
|
|
// deprecated method
|
2000-09-18 16:07:07 +00:00
|
|
|
// translate cell-address strings
|
2001-05-15 11:27:08 +00:00
|
|
|
if( maSeriesAddresses.getLength() ||
|
|
|
|
msCategoriesAddress.getLength())
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-05-15 11:27:08 +00:00
|
|
|
uno::Reference< util::XStringMapping > xTableAddressMapper = mrImportHelper.GetTableAddressMapper();
|
|
|
|
if( xTableAddressMapper.is())
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-05-15 11:27:08 +00:00
|
|
|
// series
|
|
|
|
sal_Int32 nLength = maSeriesAddresses.getLength();
|
|
|
|
sal_Int32 nIdx;
|
|
|
|
uno::Sequence< rtl::OUString > aStrSeq( nLength * 2 + 1 );
|
|
|
|
sal_Bool bHasDomain = sal_False;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-05-15 11:27:08 +00:00
|
|
|
for( nIdx = 0; nIdx < nLength; nIdx++ )
|
2000-12-07 17:18:37 +00:00
|
|
|
{
|
2001-05-15 11:27:08 +00:00
|
|
|
aStrSeq[ nIdx * 2 ] = maSeriesAddresses[ nIdx ].DataRangeAddress;
|
|
|
|
aStrSeq[ nIdx * 2 + 1 ] = maSeriesAddresses[ nIdx ].LabelAddress;
|
|
|
|
|
|
|
|
// domains
|
|
|
|
if( maSeriesAddresses[ nIdx ].DomainRangeAddresses.getLength())
|
|
|
|
{
|
|
|
|
xTableAddressMapper->mapStrings( maSeriesAddresses[ nIdx ].DomainRangeAddresses );
|
|
|
|
bHasDomain = sal_True;
|
|
|
|
}
|
2000-12-07 17:18:37 +00:00
|
|
|
}
|
2001-05-15 11:27:08 +00:00
|
|
|
// categories
|
|
|
|
aStrSeq[ nLength * 2 ] = msCategoriesAddress;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-05-15 11:27:08 +00:00
|
|
|
// translate
|
|
|
|
xTableAddressMapper->mapStrings( aStrSeq );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-05-15 11:27:08 +00:00
|
|
|
// write back
|
|
|
|
sal_Int32 nOffset = 0;
|
|
|
|
for( nIdx = 0; nIdx < nLength; nIdx++ )
|
2000-12-07 17:18:37 +00:00
|
|
|
{
|
2001-05-15 11:27:08 +00:00
|
|
|
// #81525# convert addresses for xy charts
|
|
|
|
// this should be done by calc in the future
|
|
|
|
if( nIdx == 0 &&
|
|
|
|
bHasDomain )
|
|
|
|
{
|
|
|
|
// enlarge the sequence
|
|
|
|
maSeriesAddresses.realloc( maSeriesAddresses.getLength() + 1 );
|
|
|
|
|
|
|
|
// copy the domain as first series
|
|
|
|
if( maSeriesAddresses[ nIdx + nOffset ].DomainRangeAddresses.getLength() > 0 )
|
|
|
|
maSeriesAddresses[ nIdx + nOffset ].DataRangeAddress =
|
|
|
|
maSeriesAddresses[ nIdx + nOffset ].DomainRangeAddresses[ 0 ];
|
|
|
|
// the current data range becomes the second series
|
|
|
|
nOffset++;
|
|
|
|
}
|
2000-12-07 17:18:37 +00:00
|
|
|
|
2001-05-15 11:27:08 +00:00
|
|
|
maSeriesAddresses[ nIdx + nOffset ].DataRangeAddress = aStrSeq[ nIdx * 2 ];
|
|
|
|
maSeriesAddresses[ nIdx + nOffset ].LabelAddress = aStrSeq[ nIdx * 2 + 1 ];
|
|
|
|
}
|
|
|
|
msCategoriesAddress = aStrSeq[ nLength * 2 ];
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-25 11:01:07 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-05-25 11:01:07 +00:00
|
|
|
// set table references at document
|
|
|
|
// even when having own table (Writer)
|
|
|
|
if( xProp.is())
|
|
|
|
{
|
|
|
|
try
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-05-25 11:01:07 +00:00
|
|
|
uno::Any aAny;
|
|
|
|
if( msChartAddress.getLength())
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-05-25 11:01:07 +00:00
|
|
|
aAny <<= msChartAddress;
|
|
|
|
xProp->setPropertyValue( ::rtl::OUString::createFromAscii( "ChartRangeAddress" ), aAny );
|
2001-05-17 14:48:47 +00:00
|
|
|
|
2001-05-25 11:01:07 +00:00
|
|
|
if( msTableNumberList.getLength())
|
2001-05-15 11:27:08 +00:00
|
|
|
{
|
2001-05-25 11:01:07 +00:00
|
|
|
aAny <<= msTableNumberList;
|
|
|
|
xProp->setPropertyValue( ::rtl::OUString::createFromAscii( "TableNumberList" ), aAny );
|
2001-05-15 11:27:08 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2001-05-25 11:01:07 +00:00
|
|
|
else
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-05-25 11:01:07 +00:00
|
|
|
// deprecated
|
|
|
|
if( msCategoriesAddress.getLength())
|
|
|
|
{
|
|
|
|
aAny <<= msCategoriesAddress;
|
|
|
|
xProp->setPropertyValue( rtl::OUString::createFromAscii( "CategoriesRangeAddress" ), aAny );
|
|
|
|
}
|
|
|
|
|
|
|
|
// deprecated
|
|
|
|
if( maSeriesAddresses.getLength())
|
|
|
|
{
|
|
|
|
aAny <<= maSeriesAddresses;
|
|
|
|
xProp->setPropertyValue( rtl::OUString::createFromAscii( "SeriesAddresses" ), aAny );
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2001-10-23 09:02:41 +00:00
|
|
|
|
|
|
|
// row / col translations
|
|
|
|
bool bHasColTrans = (msColTrans.getLength() > 0);
|
|
|
|
bool bHasRowTrans = (msRowTrans.getLength() > 0);
|
|
|
|
if( bHasColTrans )
|
|
|
|
{
|
|
|
|
uno::Sequence< sal_Int32 > aSeq = GetNumberSequenceFromString( msColTrans );
|
|
|
|
aAny <<= aSeq;
|
|
|
|
xProp->setPropertyValue( ::rtl::OUString::createFromAscii( "TranslatedColumns" ), aAny );
|
|
|
|
}
|
|
|
|
else if( bHasRowTrans )
|
|
|
|
{
|
|
|
|
uno::Sequence< sal_Int32 > aSeq = GetNumberSequenceFromString( msRowTrans );
|
|
|
|
aAny <<= aSeq;
|
|
|
|
xProp->setPropertyValue( ::rtl::OUString::createFromAscii( "TranslatedRows" ), aAny );
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2001-05-25 11:01:07 +00:00
|
|
|
catch( beans::UnknownPropertyException )
|
|
|
|
{
|
|
|
|
DBG_WARNING( "Required property not found in ChartDocument" );
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2000-11-27 08:09:12 +00:00
|
|
|
|
|
|
|
// allow BuildChart again
|
2001-06-25 11:21:40 +00:00
|
|
|
/* uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY );
|
2000-11-27 08:09:12 +00:00
|
|
|
if( xModel.is())
|
|
|
|
xModel->unlockControllers();
|
2001-06-25 11:21:40 +00:00
|
|
|
*/
|
|
|
|
// Set the main title's and subtitle's positions.
|
|
|
|
if( maMainTitle.getLength() > 0)
|
|
|
|
{
|
|
|
|
uno::Reference<drawing::XShape> xMainTitleShape(xDoc->getTitle(), uno::UNO_QUERY);
|
|
|
|
if( xMainTitleShape.is())
|
|
|
|
xMainTitleShape->setPosition( maMainTitlePos );
|
|
|
|
}
|
|
|
|
if( maSubTitle.getLength() > 0)
|
|
|
|
{
|
|
|
|
uno::Reference<drawing::XShape> xSubTitleShape(xDoc->getSubTitle(), uno::UNO_QUERY);
|
|
|
|
if( xSubTitleShape.is())
|
|
|
|
xSubTitleShape->setPosition( maSubTitlePos );
|
|
|
|
}
|
2001-03-27 12:24:46 +00:00
|
|
|
|
|
|
|
// set absolute legend position after (BuildChart!)
|
2001-03-29 10:08:57 +00:00
|
|
|
if( mbHasLegend )
|
2001-03-27 12:24:46 +00:00
|
|
|
{
|
|
|
|
uno::Reference< drawing::XShape > xLegendShape( xDoc->getLegend(), uno::UNO_QUERY );
|
|
|
|
if( xLegendShape.is())
|
|
|
|
xLegendShape->setPosition( maLegendPos );
|
|
|
|
}
|
2001-06-18 14:01:39 +00:00
|
|
|
|
2002-08-29 08:07:55 +00:00
|
|
|
// #102413# BuildChart to manifest legend position
|
2002-11-11 14:53:31 +00:00
|
|
|
if( xDoc->hasControllersLocked())
|
|
|
|
xDoc->unlockControllers();
|
2002-08-29 08:07:55 +00:00
|
|
|
|
2002-11-11 14:53:31 +00:00
|
|
|
// AF: No more BuildCharts until Initialize is called (by Draw or SaveAs).
|
|
|
|
|
|
|
|
// BM: There should be no further BuildCharts, and it is very dangerous to
|
|
|
|
// leave the lock status on hoping that it is changed in Draw or SaveAs
|
|
|
|
// (OLE-Clone?). At least it isn't for the writer flat XML filter. So,
|
|
|
|
// leave Controllers unlocked from now on, as this is the last line of code
|
|
|
|
// that the Chart XML import routine will call
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLImportContext* SchXMLChartContext::CreateChildContext(
|
|
|
|
USHORT nPrefix,
|
|
|
|
const rtl::OUString& rLocalName,
|
|
|
|
const uno::Reference< xml::sax::XAttributeList >& xAttrList )
|
|
|
|
{
|
2001-05-25 11:01:07 +00:00
|
|
|
static const sal_Bool bTrue = sal_True;
|
|
|
|
static const uno::Any aTrueBool( &bTrue, ::getBooleanCppuType());
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
SvXMLImportContext* pContext = 0;
|
|
|
|
const SvXMLTokenMap& rTokenMap = mrImportHelper.GetChartElemTokenMap();
|
2000-11-27 16:37:52 +00:00
|
|
|
uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument();
|
2001-05-25 11:01:07 +00:00
|
|
|
uno::Reference< beans::XPropertySet > xProp( xDoc, uno::UNO_QUERY );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
switch( rTokenMap.Get( nPrefix, rLocalName ))
|
|
|
|
{
|
|
|
|
case XML_TOK_CHART_PLOT_AREA:
|
|
|
|
pContext = new SchXMLPlotAreaContext( mrImportHelper, GetImport(), rLocalName,
|
2001-05-15 11:27:08 +00:00
|
|
|
maSeriesAddresses, msCategoriesAddress,
|
2001-05-17 14:48:47 +00:00
|
|
|
msChartAddress, msTableNumberList );
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XML_TOK_CHART_TITLE:
|
2000-11-27 16:37:52 +00:00
|
|
|
if( xDoc.is())
|
|
|
|
{
|
|
|
|
if( xProp.is())
|
|
|
|
{
|
|
|
|
uno::Any aTrueBool;
|
|
|
|
aTrueBool <<= (sal_Bool)(sal_True);
|
|
|
|
xProp->setPropertyValue( rtl::OUString::createFromAscii( "HasMainTitle" ), aTrueBool );
|
|
|
|
|
2001-03-27 12:24:46 +00:00
|
|
|
SCH_BUILDCHART( xDoc );
|
2000-11-27 16:37:52 +00:00
|
|
|
}
|
|
|
|
uno::Reference< drawing::XShape > xTitleShape( xDoc->getTitle(), uno::UNO_QUERY );
|
|
|
|
pContext = new SchXMLTitleContext( mrImportHelper, GetImport(),
|
2001-03-27 12:24:46 +00:00
|
|
|
rLocalName, maMainTitle, xTitleShape, maMainTitlePos );
|
2000-11-27 16:37:52 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XML_TOK_CHART_SUBTITLE:
|
2000-11-27 16:37:52 +00:00
|
|
|
if( xDoc.is())
|
|
|
|
{
|
|
|
|
if( xProp.is())
|
|
|
|
{
|
|
|
|
xProp->setPropertyValue( rtl::OUString::createFromAscii( "HasSubTitle" ), aTrueBool );
|
2001-03-27 12:24:46 +00:00
|
|
|
SCH_BUILDCHART( xDoc );
|
2000-11-27 16:37:52 +00:00
|
|
|
}
|
|
|
|
uno::Reference< drawing::XShape > xTitleShape( xDoc->getSubTitle(), uno::UNO_QUERY );
|
|
|
|
pContext = new SchXMLTitleContext( mrImportHelper, GetImport(),
|
2001-03-27 12:24:46 +00:00
|
|
|
rLocalName, maSubTitle, xTitleShape, maSubTitlePos );
|
2000-11-27 16:37:52 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XML_TOK_CHART_LEGEND:
|
2001-03-27 12:24:46 +00:00
|
|
|
pContext = new SchXMLLegendContext( mrImportHelper, GetImport(), rLocalName, maLegendPos );
|
2001-03-29 10:08:57 +00:00
|
|
|
mbHasLegend =sal_True;
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XML_TOK_CHART_TABLE:
|
|
|
|
pContext = new SchXMLTableContext( mrImportHelper, GetImport(), rLocalName, maTable );
|
|
|
|
if( pContext )
|
2001-05-25 11:01:07 +00:00
|
|
|
{
|
2000-09-18 16:07:07 +00:00
|
|
|
mbHasOwnTable = sal_True;
|
2001-05-25 11:01:07 +00:00
|
|
|
if( xProp.is())
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xProp->setPropertyValue( ::rtl::OUString::createFromAscii( "ExportData" ), aTrueBool );
|
|
|
|
}
|
|
|
|
catch( uno::Exception )
|
|
|
|
{
|
|
|
|
DBG_ERRORFILE( "Property missing" );
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
2001-09-28 13:56:18 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// try importing as an additional shape
|
|
|
|
if( ! mxDrawPage.is())
|
|
|
|
{
|
|
|
|
uno::Reference< drawing::XDrawPageSupplier > xSupp( xDoc, uno::UNO_QUERY );
|
|
|
|
if( xSupp.is())
|
|
|
|
mxDrawPage = uno::Reference< drawing::XShapes >( xSupp->getDrawPage(), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
DBG_ASSERT( mxDrawPage.is(), "Invalid Chart Page" );
|
|
|
|
}
|
|
|
|
if( mxDrawPage.is())
|
|
|
|
pContext = GetImport().GetShapeImport()->CreateGroupChildContext(
|
|
|
|
GetImport(), nPrefix, rLocalName, xAttrList, mxDrawPage );
|
|
|
|
break;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ! pContext )
|
|
|
|
pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
|
|
|
|
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
|
2001-06-08 13:57:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
With a locked controller the following is done here:
|
|
|
|
1. Hide title, subtitle, and legend.
|
|
|
|
2. Set the size of the draw page.
|
|
|
|
3. Set a (logically) empty data set.
|
|
|
|
4. Set the chart type.
|
|
|
|
*/
|
|
|
|
void SchXMLChartContext::InitChart (awt::Size aChartSize,
|
|
|
|
sal_Bool bDomainForDefaultDataNeeded,
|
|
|
|
rtl::OUString aServiceName,
|
|
|
|
sal_Bool bSetSwitchData)
|
|
|
|
{
|
|
|
|
uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument();
|
|
|
|
DBG_ASSERT( xDoc.is(), "No valid document!" );
|
|
|
|
uno::Reference< frame::XModel > xModel (xDoc, uno::UNO_QUERY );
|
|
|
|
if( xModel.is())
|
|
|
|
xModel->lockControllers();
|
|
|
|
|
|
|
|
// Hide title, subtitle, and legend
|
|
|
|
uno::Reference< beans::XPropertySet > xProp( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
|
|
|
|
if( xProp.is())
|
|
|
|
{
|
|
|
|
uno::Any aFalseBool;
|
|
|
|
aFalseBool <<= (sal_Bool)(sal_False);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xProp->setPropertyValue( rtl::OUString::createFromAscii( "HasMainTitle" ), aFalseBool );
|
|
|
|
xProp->setPropertyValue( rtl::OUString::createFromAscii( "HasSubTitle" ), aFalseBool );
|
|
|
|
xProp->setPropertyValue( rtl::OUString::createFromAscii( "HasLegend" ), aFalseBool );
|
|
|
|
}
|
|
|
|
catch( beans::UnknownPropertyException )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "XML-Chart Import: Property not found" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the size of the draw page.
|
|
|
|
uno::Reference< drawing::XDrawPageSupplier > xPageSupp( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
|
|
|
|
if( xPageSupp.is())
|
|
|
|
{
|
|
|
|
uno::Reference< beans::XPropertySet > xPageProp( xPageSupp->getDrawPage(), uno::UNO_QUERY );
|
|
|
|
if( xPageProp.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
uno::Any aAny;
|
|
|
|
aAny <<= (sal_Int32)( aChartSize.Width );
|
|
|
|
xPageProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" )), aAny );
|
|
|
|
|
|
|
|
aAny <<= (sal_Int32)( aChartSize.Height );
|
|
|
|
xPageProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" )), aAny );
|
|
|
|
}
|
|
|
|
catch( beans::UnknownPropertyException )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "Cannot set page size" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have to unlock the controllers and execute an implicit BuildChart because
|
2001-06-25 11:21:40 +00:00
|
|
|
// the following call to setData needs data structures created in a BuildChart.
|
2001-06-08 13:57:28 +00:00
|
|
|
if( xModel.is())
|
|
|
|
xModel->unlockControllers();
|
|
|
|
|
|
|
|
// Set a (logically) empty data set. It will later be filled with the
|
|
|
|
// actual data.
|
|
|
|
// Because the chart does not work with a really empty data set a dummy data point
|
|
|
|
// and, if necessary, a dummy domain value (Not a number) are set.
|
|
|
|
uno::Reference< chart::XChartDataArray > xArray( xDoc->getData(), uno::UNO_QUERY );
|
|
|
|
if( xArray.is())
|
|
|
|
{
|
|
|
|
double fNan = 0.0;
|
|
|
|
|
|
|
|
uno::Reference< chart::XChartData > xData( xDoc->getData(), uno::UNO_QUERY );
|
|
|
|
if( xData.is())
|
|
|
|
fNan = xData->getNotANumber();
|
|
|
|
|
|
|
|
// attention: the data must at least be 1 x 1,
|
2001-10-22 09:38:33 +00:00
|
|
|
// (or 2 x 2 for scatter charts)
|
2001-06-08 13:57:28 +00:00
|
|
|
// otherwise BuildChart doesn't perform much.
|
|
|
|
if( bDomainForDefaultDataNeeded )
|
|
|
|
{
|
2001-10-22 09:38:33 +00:00
|
|
|
uno::Sequence< uno::Sequence< double > > aAlmostEmptySeq( 2 );
|
2001-06-08 13:57:28 +00:00
|
|
|
aAlmostEmptySeq[ 0 ].realloc( 2 );
|
|
|
|
aAlmostEmptySeq[ 0 ][ 0 ] = 0.0;
|
|
|
|
aAlmostEmptySeq[ 0 ][ 1 ] = fNan;
|
2001-10-22 09:38:33 +00:00
|
|
|
|
|
|
|
aAlmostEmptySeq[ 1 ].realloc( 2 );
|
|
|
|
aAlmostEmptySeq[ 1 ][ 0 ] = 0.0;
|
|
|
|
aAlmostEmptySeq[ 1 ][ 1 ] = fNan;
|
|
|
|
|
|
|
|
xArray->setData( aAlmostEmptySeq );
|
2001-06-08 13:57:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-10-22 09:38:33 +00:00
|
|
|
uno::Sequence< uno::Sequence< double > > aAlmostEmptySeq( 1 );
|
2001-06-08 13:57:28 +00:00
|
|
|
aAlmostEmptySeq[ 0 ].realloc( 1 );
|
2001-10-22 09:38:33 +00:00
|
|
|
aAlmostEmptySeq[ 0 ][ 0 ] = 0.0;
|
|
|
|
|
|
|
|
xArray->setData( aAlmostEmptySeq );
|
2001-06-08 13:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( xModel.is())
|
|
|
|
xModel->lockControllers();
|
|
|
|
|
|
|
|
// Set the chart type via setting the diagram.
|
|
|
|
if( aServiceName.getLength() &&
|
|
|
|
xDoc.is())
|
|
|
|
{
|
|
|
|
uno::Reference< lang::XMultiServiceFactory > xFact( xDoc, uno::UNO_QUERY );
|
|
|
|
if( xFact.is())
|
|
|
|
{
|
|
|
|
uno::Reference< chart::XDiagram > xDia( xFact->createInstance( aServiceName ), uno::UNO_QUERY );
|
|
|
|
if( xDia.is())
|
|
|
|
{
|
|
|
|
xDoc->setDiagram( xDia );
|
|
|
|
|
|
|
|
// set data row source for pie charts to ROWS
|
|
|
|
if( bSetSwitchData )
|
|
|
|
{
|
|
|
|
uno::Reference< beans::XPropertySet > xDiaProp( xDia, uno::UNO_QUERY );
|
|
|
|
if( xDiaProp.is())
|
|
|
|
{
|
|
|
|
uno::Any aAny;
|
|
|
|
aAny <<= chart::ChartDataRowSource( chart::ChartDataRowSource_ROWS );
|
|
|
|
xDiaProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DataRowSource" )), aAny );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( xModel.is())
|
|
|
|
xModel->unlockControllers();
|
|
|
|
}
|
|
|
|
|
2001-10-23 09:02:41 +00:00
|
|
|
uno::Sequence< sal_Int32 > SchXMLChartContext::GetNumberSequenceFromString( const ::rtl::OUString& rStr )
|
|
|
|
{
|
|
|
|
const sal_Unicode aSpace( ' ' );
|
|
|
|
|
|
|
|
// count number of entries
|
|
|
|
::std::vector< sal_Int32 > aVec;
|
|
|
|
sal_Int32 nLastPos = 0;
|
|
|
|
sal_Int32 nPos = 0;
|
|
|
|
const sal_Int32 nSize = rStr.getLength();
|
|
|
|
while( nPos != -1 )
|
|
|
|
{
|
|
|
|
nPos = rStr.indexOf( aSpace, nLastPos );
|
|
|
|
if( nPos > nLastPos )
|
|
|
|
{
|
|
|
|
aVec.push_back( rStr.copy( nLastPos, (nPos - nLastPos) ).toInt32() );
|
|
|
|
}
|
|
|
|
if( nPos != -1 )
|
|
|
|
nLastPos = nPos + 1;
|
|
|
|
}
|
|
|
|
// last entry
|
|
|
|
if( nLastPos != 0 &&
|
|
|
|
rStr.getLength() > nLastPos )
|
|
|
|
{
|
|
|
|
aVec.push_back( rStr.copy( nLastPos, (rStr.getLength() - nLastPos) ).toInt32() );
|
|
|
|
}
|
|
|
|
|
|
|
|
const sal_Int32 nVecSize = aVec.size();
|
|
|
|
uno::Sequence< sal_Int32 > aSeq( nVecSize );
|
|
|
|
sal_Int32* pSeqArr = aSeq.getArray();
|
|
|
|
for( nPos = 0; nPos < nVecSize; ++nPos )
|
|
|
|
{
|
|
|
|
pSeqArr[ nPos ] = aVec[ nPos ];
|
|
|
|
}
|
|
|
|
return aSeq;
|
|
|
|
}
|
2001-06-08 13:57:28 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
// ----------------------------------------
|
|
|
|
|
2000-11-27 16:37:52 +00:00
|
|
|
SchXMLTitleContext::SchXMLTitleContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport,
|
|
|
|
const rtl::OUString& rLocalName,
|
2001-03-27 12:24:46 +00:00
|
|
|
rtl::OUString& rTitle,
|
|
|
|
uno::Reference< drawing::XShape >& xTitleShape,
|
|
|
|
awt::Point& rPosition ) :
|
2000-09-18 16:07:07 +00:00
|
|
|
SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
|
2000-11-27 16:37:52 +00:00
|
|
|
mrImportHelper( rImpHelper ),
|
2001-03-27 12:24:46 +00:00
|
|
|
mrTitle( rTitle ),
|
|
|
|
mxTitleShape( xTitleShape ),
|
|
|
|
mrPosition( rPosition )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SchXMLTitleContext::~SchXMLTitleContext()
|
|
|
|
{}
|
|
|
|
|
2000-11-27 16:37:52 +00:00
|
|
|
void SchXMLTitleContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
|
|
|
|
{
|
|
|
|
sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
|
|
|
|
rtl::OUString aValue;
|
|
|
|
|
|
|
|
if( mxTitleShape.is())
|
2001-03-27 12:24:46 +00:00
|
|
|
mrPosition = mxTitleShape->getPosition();
|
2000-11-27 16:37:52 +00:00
|
|
|
|
|
|
|
for( sal_Int16 i = 0; i < nAttrCount; i++ )
|
|
|
|
{
|
|
|
|
rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
|
|
|
|
rtl::OUString aLocalName;
|
|
|
|
rtl::OUString aValue = xAttrList->getValueByIndex( i );
|
|
|
|
USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
|
|
|
|
|
|
|
|
if( nPrefix == XML_NAMESPACE_SVG )
|
|
|
|
{
|
2001-06-29 20:07:26 +00:00
|
|
|
if( IsXMLToken( aLocalName, XML_X ) )
|
2001-03-27 12:24:46 +00:00
|
|
|
GetImport().GetMM100UnitConverter().convertMeasure( mrPosition.X, aValue );
|
2001-06-29 20:07:26 +00:00
|
|
|
else if( IsXMLToken( aLocalName, XML_Y ) )
|
2001-03-27 12:24:46 +00:00
|
|
|
GetImport().GetMM100UnitConverter().convertMeasure( mrPosition.Y, aValue );
|
2000-11-27 16:37:52 +00:00
|
|
|
}
|
|
|
|
else if( nPrefix == XML_NAMESPACE_CHART )
|
|
|
|
{
|
2001-06-29 20:07:26 +00:00
|
|
|
if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
|
2001-03-27 12:24:46 +00:00
|
|
|
msAutoStyleName = aValue;
|
2000-11-27 16:37:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( mxTitleShape.is())
|
|
|
|
{
|
|
|
|
uno::Reference< beans::XPropertySet > xProp( mxTitleShape, uno::UNO_QUERY );
|
|
|
|
if( xProp.is())
|
|
|
|
{
|
|
|
|
const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
|
|
|
|
if( pStylesCtxt )
|
|
|
|
{
|
|
|
|
const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
|
2001-03-27 12:24:46 +00:00
|
|
|
mrImportHelper.GetChartFamilyID(), msAutoStyleName );
|
2000-11-27 16:37:52 +00:00
|
|
|
|
|
|
|
if( pStyle && pStyle->ISA( XMLPropStyleContext ))
|
|
|
|
(( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
SvXMLImportContext* SchXMLTitleContext::CreateChildContext(
|
|
|
|
USHORT nPrefix,
|
|
|
|
const rtl::OUString& rLocalName,
|
|
|
|
const uno::Reference< xml::sax::XAttributeList >& xAttrList )
|
|
|
|
{
|
|
|
|
SvXMLImportContext* pContext = 0;
|
|
|
|
|
|
|
|
if( nPrefix == XML_NAMESPACE_TEXT &&
|
2001-06-29 20:07:26 +00:00
|
|
|
IsXMLToken( rLocalName, XML_P ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-03-27 12:24:46 +00:00
|
|
|
pContext = new SchXMLParagraphContext( GetImport(), rLocalName, mrTitle );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
|
|
|
|
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
SchXMLLegendContext::SchXMLLegendContext( SchXMLImportHelper& rImpHelper,
|
2001-03-27 12:24:46 +00:00
|
|
|
SvXMLImport& rImport, const rtl::OUString& rLocalName,
|
|
|
|
com::sun::star::awt::Point& rPosition ) :
|
2000-09-18 16:07:07 +00:00
|
|
|
SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
|
2001-03-27 12:24:46 +00:00
|
|
|
mrImportHelper( rImpHelper ),
|
|
|
|
mrPosition( rPosition )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchXMLLegendContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
|
|
|
|
{
|
|
|
|
uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument();
|
|
|
|
if( ! xDoc.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// turn on legend
|
|
|
|
uno::Reference< beans::XPropertySet > xDocProp( xDoc, uno::UNO_QUERY );
|
|
|
|
if( xDocProp.is())
|
|
|
|
{
|
|
|
|
uno::Any aTrueBool;
|
|
|
|
aTrueBool <<= (sal_Bool)(sal_True);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xDocProp->setPropertyValue( rtl::OUString::createFromAscii( "HasLegend" ), aTrueBool );
|
2001-03-27 12:24:46 +00:00
|
|
|
SCH_BUILDCHART( xDoc );
|
2001-03-29 10:08:57 +00:00
|
|
|
|
|
|
|
// initialize position
|
|
|
|
uno::Reference< drawing::XShape > xLegendShape( xDoc->getLegend(), uno::UNO_QUERY );
|
|
|
|
if( xLegendShape.is())
|
|
|
|
mrPosition = xLegendShape->getPosition();
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
catch( beans::UnknownPropertyException )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "Property HasLegend not found" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse attributes
|
|
|
|
sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
|
|
|
|
rtl::OUString aValue;
|
|
|
|
const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetLegendAttrTokenMap();
|
|
|
|
|
2000-11-27 16:37:52 +00:00
|
|
|
awt::Point aPosition;
|
|
|
|
uno::Reference< drawing::XShape > xLegendShape( xDoc->getLegend(), uno::UNO_QUERY );
|
|
|
|
if( xLegendShape.is())
|
|
|
|
aPosition = xLegendShape->getPosition();
|
|
|
|
|
2000-12-09 14:54:51 +00:00
|
|
|
rtl::OUString sAutoStyleName;
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
for( sal_Int16 i = 0; i < nAttrCount; i++ )
|
|
|
|
{
|
|
|
|
rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
|
|
|
|
rtl::OUString aLocalName;
|
|
|
|
rtl::OUString aValue = xAttrList->getValueByIndex( i );
|
|
|
|
USHORT nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
|
|
|
|
|
|
|
|
switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
|
|
|
|
{
|
|
|
|
case XML_TOK_LEGEND_POSITION:
|
|
|
|
{
|
2000-12-09 14:54:51 +00:00
|
|
|
// set anchor position
|
2000-09-18 16:07:07 +00:00
|
|
|
uno::Reference< beans::XPropertySet > xProp( xDoc->getLegend(), uno::UNO_QUERY );
|
|
|
|
if( xProp.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
USHORT nEnumVal;
|
|
|
|
if( GetImport().GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLLegendAlignmentMap ))
|
|
|
|
{
|
|
|
|
uno::Any aAny;
|
|
|
|
aAny <<= (chart::ChartLegendPosition)(nEnumVal);
|
|
|
|
xProp->setPropertyValue( rtl::OUString::createFromAscii( "Alignment" ), aAny );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( beans::UnknownPropertyException )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "Property Alignment (legend) not found" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XML_TOK_LEGEND_X:
|
2001-03-27 12:24:46 +00:00
|
|
|
GetImport().GetMM100UnitConverter().convertMeasure( mrPosition.X, aValue );
|
2000-11-27 16:37:52 +00:00
|
|
|
break;
|
2000-09-18 16:07:07 +00:00
|
|
|
case XML_TOK_LEGEND_Y:
|
2001-03-27 12:24:46 +00:00
|
|
|
GetImport().GetMM100UnitConverter().convertMeasure( mrPosition.Y, aValue );
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
2000-12-09 14:54:51 +00:00
|
|
|
case XML_TOK_LEGEND_STYLE_NAME:
|
|
|
|
sAutoStyleName = aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set auto-styles for Area
|
|
|
|
uno::Reference< beans::XPropertySet > xProp( xDoc->getLegend(), uno::UNO_QUERY );
|
|
|
|
if( xProp.is())
|
|
|
|
{
|
|
|
|
const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
|
|
|
|
if( pStylesCtxt )
|
|
|
|
{
|
|
|
|
const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
|
|
|
|
mrImportHelper.GetChartFamilyID(), sAutoStyleName );
|
|
|
|
|
|
|
|
if( pStyle && pStyle->ISA( XMLPropStyleContext ))
|
|
|
|
(( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SchXMLLegendContext::~SchXMLLegendContext()
|
|
|
|
{
|
|
|
|
}
|