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