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