/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * 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 .
*/ #include"sampleaddin.hxx"
if( xFactory.is())
{
xFactory->acquire();
pRet = xFactory.get();
}
}
return pRet;
}
} // extern C
SampleAddIn::SampleAddIn()
{
}
SampleAddIn::~SampleAddIn()
{}
// this functionality should be provided by the chart API some day
sal_Bool SampleAddIn::getLogicalPosition( uno::Reference< drawing::XShape >& xAxis, double fValue,
sal_Bool bVertical,
awt::Point& aOutPosition )
{
sal_Bool bRet = sal_False;
// XInitialization void SAL_CALL SampleAddIn::initialize( const uno::Sequence< uno::Any >& aArguments ) throw( uno::Exception, uno::RuntimeException )
{ // first argument should be the XChartDocument
OSL_ENSURE( aArguments.getLength() > 0, "Please initialize Chart AddIn with ChartDocument!" );
if( aArguments.getLength())
{
aArguments[ 0 ] >>= mxChartDoc;
OSL_ENSURE( mxChartDoc.is(), "First argument in initialization is not an XChartDocument!" );
// set XY chart as base type to be drawn
uno::Reference< beans::XPropertySet > xDocProp( mxChartDoc, uno::UNO_QUERY ); if( xDocProp.is())
{
uno::Any aBaseType;
aBaseType <<= "com.sun.star.chart.XYDiagram"; try
{
xDocProp->setPropertyValue( "BaseDiagram" , aBaseType );
} catch( ... )
{}
}
// XRefreshable /******************************************************************************** * * The method refresh is the most important method - here all objects that * are necessary for the chart are created * * in the first implementation you will have to insert everything in this * routine - all old objects are deleted beforehand *
********************************************************************************/ void SAL_CALL SampleAddIn::refresh() throw( uno::RuntimeException )
{ if( ! mxChartDoc.is()) return;
// first of all get the draw page
uno::Reference< drawing::XDrawPageSupplier > xPageSupp( mxChartDoc, uno::UNO_QUERY );
uno::Reference< lang::XMultiServiceFactory > xFactory( mxChartDoc, uno::UNO_QUERY ); if( xPageSupp.is() &&
xFactory.is() )
{
uno::Reference< drawing::XDrawPage > xPage = xPageSupp->getDrawPage(); if( xPage.is())
{ // now we have the page to insert objects
// add a horizontal line at the middle value of the first series
// get the logical position from the coordinate // get x- and y-axis
uno::Reference< drawing::XShape > xYAxisShape( getYAxis(), uno::UNO_QUERY );
uno::Reference< drawing::XShape > xXAxisShape( getXAxis(), uno::UNO_QUERY );
if( xXAxisShape.is() &&
xYAxisShape.is() )
{ // create line first time if( ! mxMyRedLine.is())
{
mxMyRedLine.set(
xFactory->createInstance( "com.sun.star.drawing.LineShape" ),
uno::UNO_QUERY );
xPage->add( mxMyRedLine );
// make line red and thick
uno::Reference< beans::XPropertySet > xShapeProp( mxMyRedLine, uno::UNO_QUERY ); if( xShapeProp.is())
{
uno::Any aColor, aWidth;
aColor <<= (sal_Int32)(0xe01010);
aWidth <<= (sal_Int32)(50); // 0.5 mm try
{
xShapeProp->setPropertyValue( "LineColor" , aColor );
xShapeProp->setPropertyValue( "LineWidth" , aWidth );
} catch( ... )
{}
}
} // create text object first time if( ! mxMyText.is())
{
mxMyText.set(
xFactory->createInstance( "com.sun.star.drawing.TextShape" ),
uno::UNO_QUERY );
xPage->add( mxMyText );
// get the array. Note: the first dimension is the length // of each series and the second one is the number of series // this should be changed in the future
uno::Sequence< uno::Sequence< double > > aData;
uno::Reference< chart::XChartData > xData = mxChartDoc->getData();
uno::Reference< chart::XChartDataArray > xDataArray( xData, uno::UNO_QUERY ); if( xDataArray.is())
aData = xDataArray->getData();
// get row count == length of each series
sal_Int32 nSize = aData.getLength();
sal_Int32 nMiddle = nSize / 2; // get value for first series double fMiddleVal = xData->getNotANumber(); // set to NaN if( aData[ nMiddle ].getLength()) // we have at least one series
fMiddleVal = aData[ nMiddle ][ 0 ];
uno::Reference< beans::XPropertySet > xShapeProp( mxMyRedLine, uno::UNO_QUERY ); if( xShapeProp.is())
{
xShapeProp->setPropertyValue( "PolyPolygon" , Any(aPtSeq) );
}
} if( mxMyText.is())
{ // put the text centered below the red line
aPos.X += ( aSize.Width - mxMyRedLine->getPosition().X ) / 2;
aPos.Y += 1000;
aPos.Y += static_cast<sal_Int32>(0.1 * xYAxisShape->getSize().Height);
mxMyText->setPosition( aPos );
}
}
}
}
}
void SAL_CALL SampleAddIn::addRefreshListener( const uno::Reference< util::XRefreshListener >& ) throw( uno::RuntimeException )
{ // not implemented - this is not necessary // (this method exists just because the interface requires it)
}
void SAL_CALL SampleAddIn::removeRefreshListener( const uno::Reference< util::XRefreshListener >& ) throw( uno::RuntimeException )
{ // not implemented - this is not necessary // (this method exists just because the interface requires it)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.