1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include "sampleaddin.hxx" 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 30*cdf0e10cSrcweir #include <osl/diagnose.h> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPageSupplier.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPage.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/chart/XChartDataArray.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/text/XTextRange.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/chart/X3DDisplay.hpp> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir using namespace com::sun::star; 39*cdf0e10cSrcweir using namespace rtl; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // code for creating instances of SampleAddIn 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir extern "C" { 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment( 46*cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir sal_Bool SAL_CALL component_writeInfo( 52*cdf0e10cSrcweir void * /*pServiceManager*/, registry::XRegistryKey * pRegistryKey ) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir if( pRegistryKey ) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir try 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir OUString aImpl = OUString::createFromAscii( "/" ); 59*cdf0e10cSrcweir aImpl += SampleAddIn::getImplementationName_Static(); 60*cdf0e10cSrcweir aImpl += OUString::createFromAscii( "/UNO/SERVICES" ); 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir uno::Reference< registry::XRegistryKey> xNewKey( 63*cdf0e10cSrcweir reinterpret_cast<registry::XRegistryKey*>( pRegistryKey )->createKey( aImpl ) ); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir uno::Sequence< OUString > aSequ = SampleAddIn::getSupportedServiceNames_Static(); 66*cdf0e10cSrcweir const OUString * pArray = aSequ.getConstArray(); 67*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSequ.getLength(); i++ ) 68*cdf0e10cSrcweir xNewKey->createKey( pArray[i] ); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir return sal_True; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir catch( registry::InvalidRegistryException& ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir return sal_False; 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir void * SAL_CALL component_getFactory( 81*cdf0e10cSrcweir const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir void* pRet = 0; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir if ( pServiceManager && 86*cdf0e10cSrcweir OUString::createFromAscii( pImplName ) == SampleAddIn::getImplementationName_Static() ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory> xFactory( cppu::createSingleFactory( 89*cdf0e10cSrcweir reinterpret_cast<lang::XMultiServiceFactory*>( pServiceManager ), 90*cdf0e10cSrcweir SampleAddIn::getImplementationName_Static(), 91*cdf0e10cSrcweir SampleAddIn_CreateInstance, 92*cdf0e10cSrcweir SampleAddIn::getSupportedServiceNames_Static() ) ); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir if( xFactory.is()) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir xFactory->acquire(); 97*cdf0e10cSrcweir pRet = xFactory.get(); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir return pRet; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir } // extern C 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // -------------------- 108*cdf0e10cSrcweir // class SampleAddIn 109*cdf0e10cSrcweir // -------------------- 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir SampleAddIn::SampleAddIn() 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir SampleAddIn::~SampleAddIn() 117*cdf0e10cSrcweir {} 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // this functionality should be provided by the chart API some day 121*cdf0e10cSrcweir sal_Bool SampleAddIn::getLogicalPosition( uno::Reference< drawing::XShape >& xAxis, 122*cdf0e10cSrcweir double fValue, 123*cdf0e10cSrcweir sal_Bool bVertical, 124*cdf0e10cSrcweir awt::Point& aOutPosition ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir sal_Bool bRet = sal_False; 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir if( xAxis.is()) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir awt::Size aSize = xAxis->getSize(); 131*cdf0e10cSrcweir sal_Int32 nLength = bVertical? aSize.Height: aSize.Width; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY ); 134*cdf0e10cSrcweir if( xProp.is()) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir try 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir double fMin(0.0), fMax(0.0); 139*cdf0e10cSrcweir uno::Any aAny = xProp->getPropertyValue( OUString::createFromAscii( "Min" )); 140*cdf0e10cSrcweir aAny >>= fMin; 141*cdf0e10cSrcweir aAny = xProp->getPropertyValue( OUString::createFromAscii( "Max" )); 142*cdf0e10cSrcweir aAny >>= fMax; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir double fRange = fMax - fMin; 145*cdf0e10cSrcweir if( fMin <= fValue && fValue <= fMax && 146*cdf0e10cSrcweir fRange != 0.0 ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir double fPercentage = (fValue - fMin) / fRange; 149*cdf0e10cSrcweir awt::Point aPos = xAxis->getPosition(); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir if( bVertical ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir aOutPosition.X = aPos.X; 154*cdf0e10cSrcweir aOutPosition.Y = static_cast<sal_Int32>(aPos.Y + nLength * (1.0 - fPercentage)); // y scale goes from top to bottom 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir else 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir aOutPosition.X = static_cast<sal_Int32>(aPos.X + nLength * fPercentage); 159*cdf0e10cSrcweir aOutPosition.Y = aPos.Y; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir bRet = sal_True; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir catch( beans::UnknownPropertyException ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir // the shape xAxis was no chart axis 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir return bRet; 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir OUString SampleAddIn::getImplementationName_Static() 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir return OUString::createFromAscii( "SampleAddIn" ); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SampleAddIn::getSupportedServiceNames_Static() 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir uno::Sequence< OUString > aSeq( 4 ); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir aSeq[ 0 ] = OUString::createFromAscii( "com.sun.star.chart.ChartAxisXSupplier" ); 184*cdf0e10cSrcweir aSeq[ 1 ] = OUString::createFromAscii( "com.sun.star.chart.ChartAxisYSupplier" ); 185*cdf0e10cSrcweir aSeq[ 2 ] = OUString::createFromAscii( "com.sun.star.chart.Diagram" ); 186*cdf0e10cSrcweir aSeq[ 3 ] = OUString::createFromAscii( "com.sun.star.chart.SampleAddIn" ); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir return aSeq; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL SampleAddIn_CreateInstance( 192*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir uno::Reference< uno::XInterface > xInst = (cppu::OWeakObject*)new SampleAddIn(); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir return xInst; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir // implementation of interface methods 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir // XInitialization 202*cdf0e10cSrcweir void SAL_CALL SampleAddIn::initialize( const uno::Sequence< uno::Any >& aArguments ) 203*cdf0e10cSrcweir throw( uno::Exception, uno::RuntimeException ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir // first argument should be the XChartDocument 206*cdf0e10cSrcweir OSL_ENSURE( aArguments.getLength() > 0, "Please initialize Chart AddIn with ChartDocument!" ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir if( aArguments.getLength()) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir aArguments[ 0 ] >>= mxChartDoc; 211*cdf0e10cSrcweir OSL_ENSURE( mxChartDoc.is(), "First argument in initialization is not an XChartDocument!" ); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir // set XY chart as base type to be drawn 214*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xDocProp( mxChartDoc, uno::UNO_QUERY ); 215*cdf0e10cSrcweir if( xDocProp.is()) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir uno::Any aBaseType; 218*cdf0e10cSrcweir aBaseType <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart.XYDiagram" )); 219*cdf0e10cSrcweir try 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir xDocProp->setPropertyValue( rtl::OUString::createFromAscii( "BaseDiagram" ), aBaseType ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir catch( ... ) 224*cdf0e10cSrcweir {} 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir // change background of plot area to light blue 228*cdf0e10cSrcweir uno::Reference< chart::X3DDisplay > xWallSupplier( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 229*cdf0e10cSrcweir if( xWallSupplier.is()) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xDiaProp( xWallSupplier->getWall(), uno::UNO_QUERY ); 232*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xLegendProp( mxChartDoc->getLegend(), uno::UNO_QUERY ); 233*cdf0e10cSrcweir if( xDiaProp.is() && 234*cdf0e10cSrcweir xLegendProp.is()) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir uno::Any aAny; 237*cdf0e10cSrcweir aAny <<= (sal_Int32)( 0xe0e0f0 ); 238*cdf0e10cSrcweir xDiaProp->setPropertyValue( OUString::createFromAscii( "FillColor" ), aAny ); 239*cdf0e10cSrcweir xLegendProp->setPropertyValue( OUString::createFromAscii( "FillColor" ), aAny ); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir // XRefreshable 246*cdf0e10cSrcweir /******************************************************************************** 247*cdf0e10cSrcweir * 248*cdf0e10cSrcweir * The method refresh is the most important method - here all objects that 249*cdf0e10cSrcweir * are necessary for the chart are created 250*cdf0e10cSrcweir * 251*cdf0e10cSrcweir * in the first implementation you will have to insert everything in this 252*cdf0e10cSrcweir * routine - all old objects are deleted beforehand 253*cdf0e10cSrcweir * 254*cdf0e10cSrcweir ********************************************************************************/ 255*cdf0e10cSrcweir void SAL_CALL SampleAddIn::refresh() throw( uno::RuntimeException ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir if( ! mxChartDoc.is()) 258*cdf0e10cSrcweir return; 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir // first of all get the draw page 261*cdf0e10cSrcweir uno::Reference< drawing::XDrawPageSupplier > xPageSupp( mxChartDoc, uno::UNO_QUERY ); 262*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory( mxChartDoc, uno::UNO_QUERY ); 263*cdf0e10cSrcweir if( xPageSupp.is() && 264*cdf0e10cSrcweir xFactory.is() ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir uno::Reference< drawing::XDrawPage > xPage = xPageSupp->getDrawPage(); 267*cdf0e10cSrcweir if( xPage.is()) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir // now we have the page to insert objects 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir // add a horizontal line at the middle value of the first series 272*cdf0e10cSrcweir // ------------------------------------------------------------- 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir // get the logical position from the coordinate 276*cdf0e10cSrcweir // get x- and y-axis 277*cdf0e10cSrcweir uno::Reference< drawing::XShape > xYAxisShape( getYAxis(), uno::UNO_QUERY ); 278*cdf0e10cSrcweir uno::Reference< drawing::XShape > xXAxisShape( getXAxis(), uno::UNO_QUERY ); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir if( xXAxisShape.is() && 281*cdf0e10cSrcweir xYAxisShape.is() ) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir // create line first time 284*cdf0e10cSrcweir if( ! mxMyRedLine.is()) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir mxMyRedLine = uno::Reference< drawing::XShape >( 287*cdf0e10cSrcweir xFactory->createInstance( OUString::createFromAscii( "com.sun.star.drawing.LineShape" )), 288*cdf0e10cSrcweir uno::UNO_QUERY ); 289*cdf0e10cSrcweir xPage->add( mxMyRedLine ); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir // make line red and thick 292*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xShapeProp( mxMyRedLine, uno::UNO_QUERY ); 293*cdf0e10cSrcweir if( xShapeProp.is()) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir uno::Any aColor, aWidth; 296*cdf0e10cSrcweir aColor <<= (sal_Int32)(0xe01010); 297*cdf0e10cSrcweir aWidth <<= (sal_Int32)(50); // 0.5 mm 298*cdf0e10cSrcweir try 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir xShapeProp->setPropertyValue( OUString::createFromAscii( "LineColor" ), aColor ); 301*cdf0e10cSrcweir xShapeProp->setPropertyValue( OUString::createFromAscii( "LineWidth" ), aWidth ); 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir catch( ... ) 304*cdf0e10cSrcweir {} 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir // create text object first time 308*cdf0e10cSrcweir if( ! mxMyText.is()) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir mxMyText = uno::Reference< drawing::XShape >( 311*cdf0e10cSrcweir xFactory->createInstance( OUString::createFromAscii( "com.sun.star.drawing.TextShape" )), 312*cdf0e10cSrcweir uno::UNO_QUERY ); 313*cdf0e10cSrcweir xPage->add( mxMyText ); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir // change text 316*cdf0e10cSrcweir OUString aText; 317*cdf0e10cSrcweir // if( maLocale.Language.equalsIgnoreCase( OUString::createFromAscii("DE"))) 318*cdf0e10cSrcweir // aText = OUString::createFromAscii( "Kleines Beispiel" ); 319*cdf0e10cSrcweir // else 320*cdf0e10cSrcweir aText = OUString::createFromAscii( "Little Example" ); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xTextProp( mxMyText, uno::UNO_QUERY ); 323*cdf0e10cSrcweir if( xTextProp.is()) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir uno::Any aTrueAny; 326*cdf0e10cSrcweir aTrueAny <<= (sal_Bool)(sal_True); 327*cdf0e10cSrcweir try 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir xTextProp->setPropertyValue( rtl::OUString::createFromAscii( "TextAutoGrowWidth" ), aTrueAny ); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir catch( ... ) 332*cdf0e10cSrcweir {} 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir uno::Reference< text::XTextRange > xTextRange( mxMyText, uno::UNO_QUERY ); 336*cdf0e10cSrcweir if( xTextRange.is()) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir xTextRange->setString( aText ); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir // position line and text 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir // get the array. Note: the first dimension is the length 346*cdf0e10cSrcweir // of each series and the second one is the number of series 347*cdf0e10cSrcweir // this should be changed in the future 348*cdf0e10cSrcweir uno::Sequence< uno::Sequence< double > > aData; 349*cdf0e10cSrcweir uno::Reference< chart::XChartData > xData = mxChartDoc->getData(); 350*cdf0e10cSrcweir uno::Reference< chart::XChartDataArray > xDataArray( xData, uno::UNO_QUERY ); 351*cdf0e10cSrcweir if( xDataArray.is()) 352*cdf0e10cSrcweir aData = xDataArray->getData(); 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir // get row count == length of each series 355*cdf0e10cSrcweir sal_Int32 nSize = aData.getLength(); 356*cdf0e10cSrcweir sal_Int32 nMiddle = nSize / 2; 357*cdf0e10cSrcweir // get value for first series 358*cdf0e10cSrcweir double fMiddleVal = xData->getNotANumber(); // set to NaN 359*cdf0e10cSrcweir if( aData[ nMiddle ].getLength()) // we have at least one series 360*cdf0e10cSrcweir fMiddleVal = aData[ nMiddle ][ 0 ]; 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir awt::Point aPos; 363*cdf0e10cSrcweir getLogicalPosition( xYAxisShape, fMiddleVal, sal_True, aPos ); 364*cdf0e10cSrcweir awt::Size aSize = xXAxisShape->getSize(); 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir if( mxMyRedLine.is()) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir awt::Point aEnd = aPos; 369*cdf0e10cSrcweir aEnd.X += aSize.Width; 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir uno::Sequence< uno::Sequence< awt::Point > > aPtSeq( 1 ); 372*cdf0e10cSrcweir aPtSeq[ 0 ].realloc( 2 ); 373*cdf0e10cSrcweir aPtSeq[ 0 ][ 0 ] = aPos; 374*cdf0e10cSrcweir aPtSeq[ 0 ][ 1 ] = aEnd; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xShapeProp( mxMyRedLine, uno::UNO_QUERY ); 377*cdf0e10cSrcweir if( xShapeProp.is()) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir uno::Any aAny; 380*cdf0e10cSrcweir aAny <<= aPtSeq; 381*cdf0e10cSrcweir xShapeProp->setPropertyValue( rtl::OUString::createFromAscii( "PolyPolygon" ), aAny ); 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir if( mxMyText.is()) 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir // put the text centered below the red line 387*cdf0e10cSrcweir aPos.X += ( aSize.Width - mxMyRedLine->getPosition().X ) / 2; 388*cdf0e10cSrcweir aPos.Y += 1000; 389*cdf0e10cSrcweir aPos.Y += static_cast<sal_Int32>(0.1 * xYAxisShape->getSize().Height); 390*cdf0e10cSrcweir mxMyText->setPosition( aPos ); 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir // set axis scale to 200 397*cdf0e10cSrcweir // uno::Reference< beans::XPropertySet > xXAxis( getXAxis(), uno::UNO_QUERY ); 398*cdf0e10cSrcweir // if( xXAxis.is()) 399*cdf0e10cSrcweir // { 400*cdf0e10cSrcweir // uno::Any aAny; 401*cdf0e10cSrcweir // aAny <<= (sal_Bool)(sal_False); 402*cdf0e10cSrcweir // xXAxis->setPropertyValue( rtl::OUString::createFromAscii( "AutoStepMain" ), 403*cdf0e10cSrcweir // aAny ); 404*cdf0e10cSrcweir // aAny <<= (double)(200.0); 405*cdf0e10cSrcweir // xXAxis->setPropertyValue( rtl::OUString::createFromAscii( "StepMain" ), 406*cdf0e10cSrcweir // aAny ); 407*cdf0e10cSrcweir // } 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir // try setting symbols 410*cdf0e10cSrcweir // uno::Reference< beans::XPropertySet > xProp = getDataRowProperties( 0 ); 411*cdf0e10cSrcweir // if( xProp.is()) 412*cdf0e10cSrcweir // { 413*cdf0e10cSrcweir // uno::Any aAny; 414*cdf0e10cSrcweir // aAny <<= (sal_Int32)(-1); 415*cdf0e10cSrcweir // xProp->setPropertyValue( OUString::createFromAscii( "SymbolType" ), aAny ); 416*cdf0e10cSrcweir // aAny <<= rtl::OUString::createFromAscii( "http://mib-1168/www/images/go.gif" ); 417*cdf0e10cSrcweir // xProp->setPropertyValue( OUString::createFromAscii( "SymbolBitmapURL" ), aAny ); 418*cdf0e10cSrcweir // } 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir void SAL_CALL SampleAddIn::addRefreshListener( const uno::Reference< util::XRefreshListener >& ) 422*cdf0e10cSrcweir throw( uno::RuntimeException ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir // not implemented - this is not necessary 425*cdf0e10cSrcweir // (this method exists just because the interface requires it) 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir void SAL_CALL SampleAddIn::removeRefreshListener( const uno::Reference< util::XRefreshListener >& ) 429*cdf0e10cSrcweir throw( uno::RuntimeException ) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir // not implemented - this is not necessary 432*cdf0e10cSrcweir // (this method exists just because the interface requires it) 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir // XDiagram 436*cdf0e10cSrcweir OUString SAL_CALL SampleAddIn::getDiagramType() throw( uno::RuntimeException ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir return OUString::createFromAscii( "com.sun.star.chart.SampleDiagram" ); 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir // the following methods just delegate to the "parent diagram" (which in the future might no longer exist) 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getDataRowProperties( sal_Int32 nRow ) 444*cdf0e10cSrcweir throw( lang::IndexOutOfBoundsException, 445*cdf0e10cSrcweir uno::RuntimeException ) 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir if( mxChartDoc.is()) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir uno::Reference< chart::XDiagram > xDia = mxChartDoc->getDiagram(); 450*cdf0e10cSrcweir if( xDia.is()) 451*cdf0e10cSrcweir return xDia->getDataRowProperties( nRow ); 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getDataPointProperties( sal_Int32 nCol, sal_Int32 nRow ) 458*cdf0e10cSrcweir throw( lang::IndexOutOfBoundsException, 459*cdf0e10cSrcweir uno::RuntimeException ) 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir if( mxChartDoc.is()) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir uno::Reference< chart::XDiagram > xDia = mxChartDoc->getDiagram(); 464*cdf0e10cSrcweir if( xDia.is()) 465*cdf0e10cSrcweir return xDia->getDataPointProperties( nCol, nRow ); 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir // XShape ( ::XDiagram ) 472*cdf0e10cSrcweir awt::Size SAL_CALL SampleAddIn::getSize() 473*cdf0e10cSrcweir throw( uno::RuntimeException ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir if( mxChartDoc.is()) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 478*cdf0e10cSrcweir if( xShape.is()) 479*cdf0e10cSrcweir return xShape->getSize(); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir return awt::Size(); 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir void SAL_CALL SampleAddIn::setSize( const awt::Size& aSize ) 486*cdf0e10cSrcweir throw( beans::PropertyVetoException, uno::RuntimeException ) 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir if( mxChartDoc.is()) 489*cdf0e10cSrcweir { 490*cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 491*cdf0e10cSrcweir if( xShape.is()) 492*cdf0e10cSrcweir xShape->setSize( aSize ); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir awt::Point SAL_CALL SampleAddIn::getPosition() 497*cdf0e10cSrcweir throw( uno::RuntimeException ) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir if( mxChartDoc.is()) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 502*cdf0e10cSrcweir if( xShape.is()) 503*cdf0e10cSrcweir return xShape->getPosition(); 504*cdf0e10cSrcweir } 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir return awt::Point(); 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir void SAL_CALL SampleAddIn::setPosition( const awt::Point& aPos ) 510*cdf0e10cSrcweir throw( uno::RuntimeException ) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir if( mxChartDoc.is()) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 515*cdf0e10cSrcweir if( xShape.is()) 516*cdf0e10cSrcweir xShape->setPosition( aPos ); 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir // XShapeDescriptor ( ::XShape ::XDiagram ) 521*cdf0e10cSrcweir rtl::OUString SAL_CALL SampleAddIn::getShapeType() throw( com::sun::star::uno::RuntimeException ) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir return OUString::createFromAscii( "com.sun.star.chart.SampleAddinShape" ); 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir // XAxisXSupplier 527*cdf0e10cSrcweir uno::Reference< drawing::XShape > SAL_CALL SampleAddIn::getXAxisTitle() 528*cdf0e10cSrcweir throw( uno::RuntimeException ) 529*cdf0e10cSrcweir { 530*cdf0e10cSrcweir if( mxChartDoc.is()) 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir uno::Reference< chart::XAxisXSupplier > xAxisSupp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 533*cdf0e10cSrcweir if( xAxisSupp.is()) 534*cdf0e10cSrcweir return xAxisSupp->getXAxisTitle(); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir return uno::Reference< drawing::XShape >(); 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getXAxis() 541*cdf0e10cSrcweir throw( uno::RuntimeException ) 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir if( mxChartDoc.is()) 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir uno::Reference< chart::XAxisXSupplier > xAxisSupp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 546*cdf0e10cSrcweir if( xAxisSupp.is()) 547*cdf0e10cSrcweir return xAxisSupp->getXAxis(); 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getXMainGrid() 554*cdf0e10cSrcweir throw( uno::RuntimeException ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir if( mxChartDoc.is()) 557*cdf0e10cSrcweir { 558*cdf0e10cSrcweir uno::Reference< chart::XAxisXSupplier > xAxisSupp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 559*cdf0e10cSrcweir if( xAxisSupp.is()) 560*cdf0e10cSrcweir return xAxisSupp->getXMainGrid(); 561*cdf0e10cSrcweir } 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getXHelpGrid() 567*cdf0e10cSrcweir throw( uno::RuntimeException ) 568*cdf0e10cSrcweir { 569*cdf0e10cSrcweir if( mxChartDoc.is()) 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir uno::Reference< chart::XAxisXSupplier > xAxisSupp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 572*cdf0e10cSrcweir if( xAxisSupp.is()) 573*cdf0e10cSrcweir return xAxisSupp->getXHelpGrid(); 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir // XAxisYSupplier 580*cdf0e10cSrcweir uno::Reference< drawing::XShape > SAL_CALL SampleAddIn::getYAxisTitle() 581*cdf0e10cSrcweir throw( uno::RuntimeException ) 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir if( mxChartDoc.is()) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir uno::Reference< chart::XAxisYSupplier > xAxisSupp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 586*cdf0e10cSrcweir if( xAxisSupp.is()) 587*cdf0e10cSrcweir return xAxisSupp->getYAxisTitle(); 588*cdf0e10cSrcweir } 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir return uno::Reference< drawing::XShape >(); 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getYAxis() 594*cdf0e10cSrcweir throw( uno::RuntimeException ) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir if( mxChartDoc.is()) 597*cdf0e10cSrcweir { 598*cdf0e10cSrcweir uno::Reference< chart::XAxisYSupplier > xAxisSupp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 599*cdf0e10cSrcweir if( xAxisSupp.is()) 600*cdf0e10cSrcweir return xAxisSupp->getYAxis(); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getYMainGrid() 607*cdf0e10cSrcweir throw( uno::RuntimeException ) 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir if( mxChartDoc.is()) 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir uno::Reference< chart::XAxisYSupplier > xAxisSupp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 612*cdf0e10cSrcweir if( xAxisSupp.is()) 613*cdf0e10cSrcweir return xAxisSupp->getYMainGrid(); 614*cdf0e10cSrcweir } 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getYHelpGrid() 620*cdf0e10cSrcweir throw( uno::RuntimeException ) 621*cdf0e10cSrcweir { 622*cdf0e10cSrcweir if( mxChartDoc.is()) 623*cdf0e10cSrcweir { 624*cdf0e10cSrcweir uno::Reference< chart::XAxisYSupplier > xAxisSupp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 625*cdf0e10cSrcweir if( xAxisSupp.is()) 626*cdf0e10cSrcweir return xAxisSupp->getYHelpGrid(); 627*cdf0e10cSrcweir } 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 630*cdf0e10cSrcweir } 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir // XStatisticDisplay 633*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getUpBar() 634*cdf0e10cSrcweir throw( uno::RuntimeException ) 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir if( mxChartDoc.is()) 637*cdf0e10cSrcweir { 638*cdf0e10cSrcweir uno::Reference< chart::XStatisticDisplay > xStatDisp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 639*cdf0e10cSrcweir if( xStatDisp.is()) 640*cdf0e10cSrcweir return xStatDisp->getUpBar(); 641*cdf0e10cSrcweir } 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 644*cdf0e10cSrcweir } 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getDownBar() 647*cdf0e10cSrcweir throw( uno::RuntimeException ) 648*cdf0e10cSrcweir { 649*cdf0e10cSrcweir if( mxChartDoc.is()) 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir uno::Reference< chart::XStatisticDisplay > xStatDisp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 652*cdf0e10cSrcweir if( xStatDisp.is()) 653*cdf0e10cSrcweir return xStatDisp->getDownBar(); 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL SampleAddIn::getMinMaxLine() 660*cdf0e10cSrcweir throw( uno::RuntimeException ) 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir if( mxChartDoc.is()) 663*cdf0e10cSrcweir { 664*cdf0e10cSrcweir uno::Reference< chart::XStatisticDisplay > xStatDisp( mxChartDoc->getDiagram(), uno::UNO_QUERY ); 665*cdf0e10cSrcweir if( xStatDisp.is()) 666*cdf0e10cSrcweir return xStatDisp->getMinMaxLine(); 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >(); 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir // XServiceName 673*cdf0e10cSrcweir OUString SAL_CALL SampleAddIn::getServiceName() throw( uno::RuntimeException ) 674*cdf0e10cSrcweir { 675*cdf0e10cSrcweir return OUString::createFromAscii( "com.sun.star.chart.SampleAddIn" ); 676*cdf0e10cSrcweir } 677*cdf0e10cSrcweir 678*cdf0e10cSrcweir // XServiceInfo 679*cdf0e10cSrcweir OUString SAL_CALL SampleAddIn::getImplementationName() throw( uno::RuntimeException ) 680*cdf0e10cSrcweir { 681*cdf0e10cSrcweir return getImplementationName_Static(); 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir sal_Bool SAL_CALL SampleAddIn::supportsService( const OUString& ServiceName ) 685*cdf0e10cSrcweir throw( uno::RuntimeException ) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir uno::Sequence< OUString > aServiceSeq = getSupportedServiceNames_Static(); 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir sal_Int32 nLength = aServiceSeq.getLength(); 690*cdf0e10cSrcweir for( sal_Int32 i=0; i < nLength; i++ ) 691*cdf0e10cSrcweir { 692*cdf0e10cSrcweir if( ServiceName.equals( aServiceSeq[ i ] )) 693*cdf0e10cSrcweir return sal_True; 694*cdf0e10cSrcweir } 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir return sal_False; 697*cdf0e10cSrcweir } 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL SampleAddIn::getSupportedServiceNames() 700*cdf0e10cSrcweir throw( uno::RuntimeException ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir return getSupportedServiceNames_Static(); 703*cdf0e10cSrcweir } 704*cdf0e10cSrcweir 705*cdf0e10cSrcweir // XLocalizable 706*cdf0e10cSrcweir void SAL_CALL SampleAddIn::setLocale( const lang::Locale& eLocale ) 707*cdf0e10cSrcweir throw( uno::RuntimeException ) 708*cdf0e10cSrcweir { 709*cdf0e10cSrcweir maLocale = eLocale; 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir lang::Locale SAL_CALL SampleAddIn::getLocale() 713*cdf0e10cSrcweir throw( uno::RuntimeException ) 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir return maLocale; 716*cdf0e10cSrcweir } 717