fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / model / main / ChartModel.cxx
blobe38dfcee6b4f9128d8e9aa7b7079dbed1e9e32b4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ChartModel.hxx"
21 #include "servicenames.hxx"
22 #include "MediaDescriptorHelper.hxx"
23 #include "macros.hxx"
24 #include "DataSourceHelper.hxx"
25 #include "ChartModelHelper.hxx"
26 #include "DiagramHelper.hxx"
27 #include "DisposeHelper.hxx"
28 #include "ControllerLockGuard.hxx"
29 #include "ObjectIdentifier.hxx"
30 #include "PageBackground.hxx"
31 #include "CloneHelper.hxx"
32 #include "NameContainer.hxx"
33 #include "UndoManager.hxx"
34 #include "ChartView.hxx"
35 #include <svx/charthelper.hxx>
37 #include <vcl/openglwin.hxx>
39 #include <com/sun/star/chart/ChartDataRowSource.hpp>
41 #include <comphelper/InlineContainer.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <cppuhelper/supportsservice.hxx>
45 #include <svl/numuno.hxx>
46 #include <com/sun/star/lang/DisposedException.hpp>
47 #include <com/sun/star/lang/XInitialization.hpp>
48 #include <com/sun/star/view/XSelectionSupplier.hpp>
49 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
50 #include <com/sun/star/embed/XEmbedPersist.hpp>
51 #include <com/sun/star/embed/EmbedStates.hpp>
52 #include <com/sun/star/embed/XComponentSupplier.hpp>
53 #include <com/sun/star/embed/XStorage.hpp>
54 #include <com/sun/star/embed/EmbedMapUnits.hpp>
55 #include <com/sun/star/embed/Aspects.hpp>
56 #include <com/sun/star/awt/Gradient.hpp>
57 #include <com/sun/star/awt/XWindow.hpp>
58 #include <com/sun/star/awt/PosSize.hpp>
59 #include <com/sun/star/datatransfer/XTransferable.hpp>
60 #include <com/sun/star/drawing/Hatch.hpp>
61 #include <com/sun/star/drawing/LineDash.hpp>
62 #include <com/sun/star/drawing/XShapes.hpp>
63 #include <com/sun/star/document/DocumentProperties.hpp>
64 #include <com/sun/star/chart2/XTimeBased.hpp>
66 #include <svl/zforlist.hxx>
68 using ::com::sun::star::uno::Sequence;
69 using ::com::sun::star::uno::Reference;
70 using ::com::sun::star::uno::RuntimeException;
71 using ::com::sun::star::uno::Any;
72 using ::osl::MutexGuard;
74 using namespace ::com::sun::star;
75 using namespace ::apphelper;
76 using namespace ::chart::CloneHelper;
78 namespace
80 const OUString lcl_aGDIMetaFileMIMEType(
81 "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"");
82 const OUString lcl_aGDIMetaFileMIMETypeHighContrast(
83 "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"");
85 } // anonymous namespace
87 // ChartModel Constructor and Destructor
89 namespace chart
92 ChartModel::ChartModel(uno::Reference<uno::XComponentContext > const & xContext)
93 : m_aLifeTimeManager( this, this )
94 , m_bReadOnly( false )
95 , m_bModified( false )
96 , m_nInLoad(0)
97 , m_bUpdateNotificationsPending(false)
98 , mbTimeBased(false)
99 , mpChartView(NULL)
100 , m_pUndoManager( NULL )
101 , m_aControllers( m_aModelMutex )
102 , m_nControllerLockCount(0)
103 , m_xContext( xContext )
104 , m_aVisualAreaSize( ChartModelHelper::getDefaultPageSize() )
105 , m_xDataProvider( 0 )
106 , m_xInternalDataProvider( 0 )
107 , m_xPageBackground( new PageBackground( m_xContext ) )
108 , m_xXMLNamespaceMap( createNameContainer( ::cppu::UnoType<OUString>::get(),
109 "com.sun.star.xml.NamespaceMap", "com.sun.star.comp.chart.XMLNameSpaceMap" ), uno::UNO_QUERY)
110 , mnStart(0)
111 , mnEnd(0)
112 ,bSet(false)
113 , mpOpenGLWindow(NULL)
115 OSL_TRACE( "ChartModel: CTOR called" );
117 osl_atomic_increment(&m_refCount);
119 m_xOldModelAgg.set(
120 m_xContext->getServiceManager()->createInstanceWithContext(
121 CHART_CHARTAPIWRAPPER_SERVICE_NAME,
122 m_xContext ), uno::UNO_QUERY_THROW );
123 m_xOldModelAgg->setDelegator( *this );
127 ModifyListenerHelper::addListener( m_xPageBackground, this );
128 m_xChartTypeManager.set( xContext->getServiceManager()->createInstanceWithContext(
129 "com.sun.star.chart2.ChartTypeManager", m_xContext ), uno::UNO_QUERY );
131 osl_atomic_decrement(&m_refCount);
134 ChartModel::ChartModel( const ChartModel & rOther )
135 : impl::ChartModel_Base()
136 , m_aLifeTimeManager( this, this )
137 , m_bReadOnly( rOther.m_bReadOnly )
138 , m_bModified( rOther.m_bModified )
139 , m_nInLoad(0)
140 , m_bUpdateNotificationsPending(false)
141 , mbTimeBased(rOther.mbTimeBased)
142 , mpChartView(NULL)
143 , m_aResource( rOther.m_aResource )
144 , m_aMediaDescriptor( rOther.m_aMediaDescriptor )
145 , m_aControllers( m_aModelMutex )
146 , m_nControllerLockCount(0)
147 , m_xContext( rOther.m_xContext )
148 // @note: the old model aggregate must not be shared with other models if it
149 // is, you get mutex deadlocks
150 , m_xOldModelAgg( 0 ) //rOther.m_xOldModelAgg )
151 , m_xStorage( 0 ) //rOther.m_xStorage )
152 , m_aVisualAreaSize( rOther.m_aVisualAreaSize )
153 , m_aGraphicObjectVector( rOther.m_aGraphicObjectVector )
154 , m_xDataProvider( rOther.m_xDataProvider )
155 , m_xInternalDataProvider( rOther.m_xInternalDataProvider )
156 , mnStart(rOther.mnStart)
157 , mnEnd(rOther.mnEnd)
158 , bSet(false)
159 , mpOpenGLWindow(NULL)
161 OSL_TRACE( "ChartModel: Copy-CTOR called" );
163 osl_atomic_increment(&m_refCount);
165 m_xOldModelAgg.set(
166 m_xContext->getServiceManager()->createInstanceWithContext(
167 CHART_CHARTAPIWRAPPER_SERVICE_NAME,
168 m_xContext ), uno::UNO_QUERY_THROW );
169 m_xOldModelAgg->setDelegator( *this );
171 Reference< util::XModifyListener > xListener;
172 Reference< chart2::XTitle > xNewTitle = CreateRefClone< Reference< chart2::XTitle > >()( rOther.m_xTitle );
173 Reference< chart2::XDiagram > xNewDiagram = CreateRefClone< Reference< chart2::XDiagram > >()( rOther.m_xDiagram );
174 Reference< beans::XPropertySet > xNewPageBackground = CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xPageBackground );
175 Reference< chart2::XChartTypeManager > xChartTypeManager = CreateRefClone< Reference< chart2::XChartTypeManager > >()( rOther.m_xChartTypeManager );
176 Reference< container::XNameAccess > xXMLNamespaceMap = CreateRefClone< Reference< container::XNameAccess > >()( rOther.m_xXMLNamespaceMap );
179 MutexGuard aGuard( m_aModelMutex );
180 xListener = this;
181 m_xTitle = xNewTitle;
182 m_xDiagram = xNewDiagram;
183 m_xPageBackground = xNewPageBackground;
184 m_xChartTypeManager = xChartTypeManager;
185 m_xXMLNamespaceMap = xXMLNamespaceMap;
188 ModifyListenerHelper::addListener( xNewTitle, xListener );
189 ModifyListenerHelper::addListener( xNewDiagram, xListener );
190 ModifyListenerHelper::addListener( xNewPageBackground, xListener );
191 xListener.clear();
193 osl_atomic_decrement(&m_refCount);
196 ChartModel::~ChartModel()
198 OSL_TRACE( "ChartModel: DTOR called" );
199 if( m_xOldModelAgg.is())
200 m_xOldModelAgg->setDelegator( NULL );
203 void SAL_CALL ChartModel::initialize( const Sequence< Any >& /*rArguments*/ )
204 throw (uno::Exception, uno::RuntimeException, std::exception)
206 //#i113722# avoid duplicate creation
208 //maybe additional todo?:
209 //support argument "EmbeddedObject"?
210 //support argument "EmbeddedScriptSupport"?
211 //support argument "DocumentRecoverySupport"?
214 // private methods
216 OUString ChartModel::impl_g_getLocation()
219 LifeTimeGuard aGuard(m_aLifeTimeManager);
220 if(!aGuard.startApiCall())
221 return OUString(); //behave passive if already disposed or closed or throw exception @todo?
222 //mutex is acquired
223 return m_aResource;
226 bool ChartModel::impl_isControllerConnected( const uno::Reference< frame::XController >& xController )
230 uno::Sequence< uno::Reference<uno::XInterface> > aSeq = m_aControllers.getElements();
231 for( sal_Int32 nN = aSeq.getLength(); nN--; )
233 if( aSeq[nN] == xController )
234 return true;
237 catch (const uno::Exception&)
240 return false;
243 uno::Reference< frame::XController > ChartModel::impl_getCurrentController() throw(uno::RuntimeException)
245 //@todo? hold only weak references to controllers
247 // get the last active controller of this model
248 if( m_xCurrentController.is() )
249 return m_xCurrentController;
251 // get the first controller of this model
252 if( m_aControllers.getLength() )
254 uno::Reference<uno::XInterface> xI = m_aControllers.getElements()[0];
255 return uno::Reference<frame::XController>( xI, uno::UNO_QUERY );
258 //return nothing if no controllers are connected at all
259 return uno::Reference< frame::XController > ();
262 void SAL_CALL ChartModel::impl_notifyCloseListeners()
263 throw( uno::RuntimeException)
265 ::cppu::OInterfaceContainerHelper* pIC = m_aLifeTimeManager.m_aListenerContainer
266 .getContainer( cppu::UnoType<util::XCloseListener>::get());
267 if( pIC )
269 lang::EventObject aEvent( static_cast< lang::XComponent*>(this) );
270 ::cppu::OInterfaceIteratorHelper aIt( *pIC );
271 while( aIt.hasMoreElements() )
273 uno::Reference< util::XCloseListener > xListener( aIt.next(), uno::UNO_QUERY );
274 if( xListener.is() )
275 xListener->notifyClosing( aEvent );
280 void ChartModel::impl_adjustAdditionalShapesPositionAndSize( const awt::Size& aVisualAreaSize )
282 uno::Reference< beans::XPropertySet > xProperties( static_cast< ::cppu::OWeakObject* >( this ), uno::UNO_QUERY );
283 if ( xProperties.is() )
285 uno::Reference< drawing::XShapes > xShapes;
286 xProperties->getPropertyValue( "AdditionalShapes" ) >>= xShapes;
287 if ( xShapes.is() )
289 sal_Int32 nCount = xShapes->getCount();
290 for ( sal_Int32 i = 0; i < nCount; ++i )
292 Reference< drawing::XShape > xShape;
293 if ( xShapes->getByIndex( i ) >>= xShape )
295 if ( xShape.is() )
297 awt::Point aPos( xShape->getPosition() );
298 awt::Size aSize( xShape->getSize() );
300 double fWidth = static_cast< double >( aVisualAreaSize.Width ) / m_aVisualAreaSize.Width;
301 double fHeight = static_cast< double >( aVisualAreaSize.Height ) / m_aVisualAreaSize.Height;
303 aPos.X = static_cast< long >( aPos.X * fWidth );
304 aPos.Y = static_cast< long >( aPos.Y * fHeight );
305 aSize.Width = static_cast< long >( aSize.Width * fWidth );
306 aSize.Height = static_cast< long >( aSize.Height * fHeight );
308 xShape->setPosition( aPos );
309 xShape->setSize( aSize );
317 // lang::XServiceInfo
319 OUString SAL_CALL ChartModel::getImplementationName()
320 throw( css::uno::RuntimeException, std::exception )
322 return getImplementationName_Static();
325 OUString ChartModel::getImplementationName_Static()
327 return OUString(CHART_MODEL_SERVICE_IMPLEMENTATION_NAME);
330 sal_Bool SAL_CALL ChartModel::supportsService( const OUString& rServiceName )
331 throw( css::uno::RuntimeException, std::exception )
333 return cppu::supportsService(this, rServiceName);
336 css::uno::Sequence< OUString > SAL_CALL ChartModel::getSupportedServiceNames()
337 throw( css::uno::RuntimeException, std::exception )
339 return getSupportedServiceNames_Static();
342 uno::Sequence< OUString > ChartModel::getSupportedServiceNames_Static()
344 uno::Sequence< OUString > aSNS( 3 );
345 aSNS[0] = CHART_MODEL_SERVICE_NAME;
346 aSNS[1] = "com.sun.star.document.OfficeDocument";
347 aSNS[2] = "com.sun.star.chart.ChartDocument";
348 //// @todo : add additional services if you support any further
349 return aSNS;
352 // frame::XModel (required interface)
354 sal_Bool SAL_CALL ChartModel::attachResource( const OUString& rURL
355 , const uno::Sequence< beans::PropertyValue >& rMediaDescriptor )
356 throw(uno::RuntimeException, std::exception)
359 The method attachResource() is used by the frame loader implementations
360 to inform the model about its URL and MediaDescriptor.
363 LifeTimeGuard aGuard(m_aLifeTimeManager);
364 if(!aGuard.startApiCall())
365 return sal_False; //behave passive if already disposed or closed or throw exception @todo?
366 //mutex is acquired
368 if(!m_aResource.isEmpty())//we have a resource already //@todo? or is setting a new resource allowed?
369 return sal_False;
370 m_aResource = rURL;
371 m_aMediaDescriptor = rMediaDescriptor;
373 //@todo ? check rURL ??
374 //@todo ? evaluate m_aMediaDescriptor;
375 //@todo ? ... ??? --> nothing, this method is only for setting information
377 return sal_True;
380 OUString SAL_CALL ChartModel::getURL() throw(uno::RuntimeException, std::exception)
382 return impl_g_getLocation();
385 uno::Sequence< beans::PropertyValue > SAL_CALL ChartModel::getArgs() throw(uno::RuntimeException, std::exception)
388 The method getArgs() returns a sequence of property values
389 that report the resource description according to com.sun.star.document.MediaDescriptor,
390 specified on loading or saving with storeAsURL.
393 LifeTimeGuard aGuard(m_aLifeTimeManager);
394 if(!aGuard.startApiCall())
395 return uno::Sequence< beans::PropertyValue >(); //behave passive if already disposed or closed or throw exception @todo?
396 //mutex is acquired
398 return m_aMediaDescriptor;
401 void SAL_CALL ChartModel::connectController( const uno::Reference< frame::XController >& xController )
402 throw(uno::RuntimeException, std::exception)
404 //@todo? this method is declared as oneway -> ...?
406 LifeTimeGuard aGuard(m_aLifeTimeManager);
407 if(!aGuard.startApiCall())
408 return ; //behave passive if already disposed or closed
409 //mutex is acquired
411 //--add controller
412 m_aControllers.addInterface(xController);
415 void SAL_CALL ChartModel::disconnectController( const uno::Reference< frame::XController >& xController )
416 throw(uno::RuntimeException, std::exception)
418 //@todo? this method is declared as oneway -> ...?
420 LifeTimeGuard aGuard(m_aLifeTimeManager);
421 if(!aGuard.startApiCall())
422 return; //behave passive if already disposed or closed
424 //--remove controller
425 m_aControllers.removeInterface(xController);
427 //case: current controller is disconnected:
428 if( m_xCurrentController == xController )
429 m_xCurrentController.clear();
431 DisposeHelper::DisposeAndClear( m_xRangeHighlighter );
434 void SAL_CALL ChartModel::lockControllers() throw(uno::RuntimeException, std::exception)
437 suspends some notifications to the controllers which are used for display updates.
439 The calls to lockControllers() and unlockControllers() may be nested
440 and even overlapping, but they must be in pairs. While there is at least one lock
441 remaining, some notifications for display updates are not broadcasted.
444 //@todo? this method is declared as oneway -> ...?
446 LifeTimeGuard aGuard(m_aLifeTimeManager);
447 if(!aGuard.startApiCall())
448 return; //behave passive if already disposed or closed or throw exception @todo?
449 ++m_nControllerLockCount;
452 void SAL_CALL ChartModel::unlockControllers() throw(uno::RuntimeException, std::exception)
455 resumes the notifications which were suspended by lockControllers() .
457 The calls to lockControllers() and unlockControllers() may be nested
458 and even overlapping, but they must be in pairs. While there is at least one lock
459 remaining, some notifications for display updates are not broadcasted.
462 //@todo? this method is declared as oneway -> ...?
464 LifeTimeGuard aGuard(m_aLifeTimeManager);
465 if(!aGuard.startApiCall())
466 return; //behave passive if already disposed or closed or throw exception @todo?
467 if( m_nControllerLockCount == 0 )
469 OSL_TRACE( "ChartModel: unlockControllers called with m_nControllerLockCount == 0" );
470 return;
472 --m_nControllerLockCount;
473 if( m_nControllerLockCount == 0 && m_bUpdateNotificationsPending )
475 aGuard.clear();
476 impl_notifyModifiedListeners();
480 sal_Bool SAL_CALL ChartModel::hasControllersLocked() throw(uno::RuntimeException, std::exception)
482 LifeTimeGuard aGuard(m_aLifeTimeManager);
483 if(!aGuard.startApiCall())
484 return sal_False; //behave passive if already disposed or closed or throw exception @todo?
485 return ( m_nControllerLockCount != 0 ) ;
488 uno::Reference< frame::XController > SAL_CALL ChartModel::getCurrentController() throw(uno::RuntimeException, std::exception)
490 LifeTimeGuard aGuard(m_aLifeTimeManager);
491 if(!aGuard.startApiCall())
492 throw lang::DisposedException(
493 "getCurrentController was called on an already disposed or closed model",
494 static_cast< ::cppu::OWeakObject* >(this) );
496 return impl_getCurrentController();
499 void SAL_CALL ChartModel::setCurrentController( const uno::Reference< frame::XController >& xController )
500 throw(container::NoSuchElementException, uno::RuntimeException, std::exception)
502 LifeTimeGuard aGuard(m_aLifeTimeManager);
503 if(!aGuard.startApiCall())
504 throw lang::DisposedException(
505 "setCurrentController was called on an already disposed or closed model",
506 static_cast< ::cppu::OWeakObject* >(this) );
508 //OSL_ENSURE( impl_isControllerConnected(xController), "setCurrentController is called with a Controller which is not connected" );
509 if(!impl_isControllerConnected(xController))
510 throw container::NoSuchElementException(
511 "setCurrentController is called with a Controller which is not connected",
512 static_cast< ::cppu::OWeakObject* >(this) );
514 m_xCurrentController = xController;
516 DisposeHelper::DisposeAndClear( m_xRangeHighlighter );
519 uno::Reference< uno::XInterface > SAL_CALL ChartModel::getCurrentSelection() throw(uno::RuntimeException, std::exception)
521 LifeTimeGuard aGuard(m_aLifeTimeManager);
522 if(!aGuard.startApiCall())
523 throw lang::DisposedException(
524 "getCurrentSelection was called on an already disposed or closed model",
525 static_cast< ::cppu::OWeakObject* >(this) );
527 uno::Reference< uno::XInterface > xReturn;
528 uno::Reference< frame::XController > xController = impl_getCurrentController();
530 aGuard.clear();
531 if( xController.is() )
533 uno::Reference< view::XSelectionSupplier > xSelectionSupl( xController, uno::UNO_QUERY );
534 if ( xSelectionSupl.is() )
536 uno::Any aSel = xSelectionSupl->getSelection();
537 OUString aObjectCID;
538 if( aSel >>= aObjectCID )
539 xReturn.set( ObjectIdentifier::getObjectPropertySet( aObjectCID, Reference< XChartDocument >(this)));
542 return xReturn;
545 // lang::XComponent (base of XModel)
546 void SAL_CALL ChartModel::dispose() throw(uno::RuntimeException, std::exception)
548 Reference< XInterface > xKeepAlive( *this );
550 //This object should release all resources and references in the
551 //easiest possible manner
552 //This object must notify all registered listeners using the method
553 //<member>XEventListener::disposing</member>
555 //hold no mutex
556 if( !m_aLifeTimeManager.dispose() )
557 return;
559 //--release all resources and references
560 //// @todo
562 if ( m_xDiagram.is() )
563 ModifyListenerHelper::removeListener( m_xDiagram, this );
565 m_xDataProvider.clear();
566 m_xInternalDataProvider.clear();
567 m_xNumberFormatsSupplier.clear();
568 DisposeHelper::DisposeAndClear( m_xOwnNumberFormatsSupplier );
569 DisposeHelper::DisposeAndClear( m_xChartTypeManager );
570 DisposeHelper::DisposeAndClear( m_xDiagram );
571 DisposeHelper::DisposeAndClear( m_xTitle );
572 DisposeHelper::DisposeAndClear( m_xPageBackground );
573 DisposeHelper::DisposeAndClear( m_xXMLNamespaceMap );
575 m_xStorage.clear();
576 // just clear, don't dispose - we're not the owner
578 if ( m_pUndoManager.is() )
579 m_pUndoManager->disposing();
580 m_pUndoManager.clear();
581 // that's important, since the UndoManager implementation delegates its ref counting to ourself.
583 if( m_xOldModelAgg.is()) // #i120828#, to release cyclic reference to ChartModel object
584 m_xOldModelAgg->setDelegator( 0 );
586 m_aControllers.disposeAndClear( lang::EventObject( static_cast< cppu::OWeakObject * >( this )));
587 m_xCurrentController.clear();
589 DisposeHelper::DisposeAndClear( m_xRangeHighlighter );
591 if( m_xOldModelAgg.is())
592 m_xOldModelAgg->setDelegator( NULL );
594 OSL_TRACE( "ChartModel: dispose() called" );
597 void SAL_CALL ChartModel::addEventListener( const uno::Reference< lang::XEventListener > & xListener )
598 throw(uno::RuntimeException, std::exception)
600 if( m_aLifeTimeManager.impl_isDisposedOrClosed() )
601 return; //behave passive if already disposed or closed
603 m_aLifeTimeManager.m_aListenerContainer.addInterface( cppu::UnoType<lang::XEventListener>::get(), xListener );
606 void SAL_CALL ChartModel::removeEventListener( const uno::Reference< lang::XEventListener > & xListener )
607 throw(uno::RuntimeException, std::exception)
609 if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
610 return; //behave passive if already disposed or closed
612 m_aLifeTimeManager.m_aListenerContainer.removeInterface( cppu::UnoType<lang::XEventListener>::get(), xListener );
613 return;
616 // util::XCloseBroadcaster (base of XCloseable)
617 void SAL_CALL ChartModel::addCloseListener( const uno::Reference< util::XCloseListener > & xListener )
618 throw(uno::RuntimeException, std::exception)
620 m_aLifeTimeManager.g_addCloseListener( xListener );
623 void SAL_CALL ChartModel::removeCloseListener( const uno::Reference< util::XCloseListener > & xListener )
624 throw(uno::RuntimeException, std::exception)
626 if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
627 return; //behave passive if already disposed or closed
629 m_aLifeTimeManager.m_aListenerContainer.removeInterface( cppu::UnoType<util::XCloseListener>::get(), xListener );
630 return;
633 // util::XCloseable
634 void SAL_CALL ChartModel::close( sal_Bool bDeliverOwnership )
635 throw( util::CloseVetoException,
636 uno::RuntimeException, std::exception )
638 //hold no mutex
640 if( !m_aLifeTimeManager.g_close_startTryClose( bDeliverOwnership ) )
641 return;
642 //no mutex is acquired
644 // At the end of this method may we must dispose ourself ...
645 // and may nobody from outside hold a reference to us ...
646 // then it's a good idea to do that by ourself.
647 uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
649 //the listeners have had no veto
650 //check whether we self can close
652 util::CloseVetoException aVetoException = util::CloseVetoException(
653 "the model itself could not be closed",
654 static_cast< ::cppu::OWeakObject* >(this) );
656 if( m_aLifeTimeManager.g_close_isNeedToCancelLongLastingCalls( bDeliverOwnership, aVetoException ) )
658 ////you can empty this block, if you never start longlasting calls or
659 ////if your longlasting calls are per default not cancelable (check how you have constructed your LifeTimeManager)
661 bool bLongLastingCallsAreCanceled = false;
664 //try to cancel running longlasting calls
665 //// @todo
667 catch (const uno::Exception&)
669 //// @todo
670 //do not throw anything here!! (without endTryClose)
672 //if not successful canceled
673 if(!bLongLastingCallsAreCanceled)
675 m_aLifeTimeManager.g_close_endTryClose( bDeliverOwnership, true );
676 throw aVetoException;
681 m_aLifeTimeManager.g_close_endTryClose_doClose();
683 // BM @todo: is it ok to call the listeners here?
684 impl_notifyCloseListeners();
687 // lang::XTypeProvider
688 uno::Sequence< uno::Type > SAL_CALL ChartModel::getTypes()
689 throw (uno::RuntimeException, std::exception)
691 uno::Reference< lang::XTypeProvider > xAggTypeProvider;
692 if( (m_xOldModelAgg->queryAggregation( cppu::UnoType<decltype(xAggTypeProvider)>::get()) >>= xAggTypeProvider)
693 && xAggTypeProvider.is())
695 uno::Sequence< uno::Type > aOwnTypes( impl::ChartModel_Base::getTypes());
696 uno::Sequence< uno::Type > aAggTypes( xAggTypeProvider->getTypes());
697 uno::Sequence< uno::Type > aResult( aOwnTypes.getLength() + aAggTypes.getLength());
698 sal_Int32 i=0;
699 for( ;i<aOwnTypes.getLength(); ++i )
700 aResult[i] = aOwnTypes[i];
701 for( sal_Int32 j=0; i<aResult.getLength(); ++j, ++i)
702 aResult[i] = aAggTypes[j];
703 return aResult;
706 return impl::ChartModel_Base::getTypes();
709 // document::XDocumentPropertiesSupplier
710 uno::Reference< document::XDocumentProperties > SAL_CALL
711 ChartModel::getDocumentProperties() throw (uno::RuntimeException, std::exception)
713 ::osl::MutexGuard aGuard( m_aModelMutex );
714 if ( !m_xDocumentProperties.is() )
716 m_xDocumentProperties.set( document::DocumentProperties::create( ::comphelper::getProcessComponentContext() ) );
718 return m_xDocumentProperties;
721 // document::XDocumentPropertiesSupplier
722 Reference< document::XUndoManager > SAL_CALL ChartModel::getUndoManager( ) throw (RuntimeException, std::exception)
724 ::osl::MutexGuard aGuard( m_aModelMutex );
725 if ( !m_pUndoManager.is() )
726 m_pUndoManager.set( new UndoManager( *this, m_aModelMutex ) );
727 return m_pUndoManager.get();
730 // chart2::XChartDocument
732 uno::Reference< chart2::XDiagram > SAL_CALL ChartModel::getFirstDiagram()
733 throw (uno::RuntimeException, std::exception)
735 MutexGuard aGuard( m_aModelMutex );
736 return m_xDiagram;
739 void SAL_CALL ChartModel::setFirstDiagram( const uno::Reference< chart2::XDiagram >& xDiagram )
740 throw (uno::RuntimeException, std::exception)
742 Reference< chart2::XDiagram > xOldDiagram;
743 Reference< util::XModifyListener > xListener;
745 MutexGuard aGuard( m_aModelMutex );
746 if( xDiagram == m_xDiagram )
747 return;
748 xOldDiagram = m_xDiagram;
749 m_xDiagram = xDiagram;
750 xListener = this;
752 //don't keep the mutex locked while calling out
753 ModifyListenerHelper::removeListener( xOldDiagram, xListener );
754 ModifyListenerHelper::addListener( xDiagram, xListener );
755 setModified( sal_True );
758 Reference< chart2::data::XDataSource > ChartModel::impl_createDefaultData()
760 Reference< chart2::data::XDataSource > xDataSource;
761 if( hasInternalDataProvider() )
763 uno::Reference< lang::XInitialization > xIni(m_xInternalDataProvider,uno::UNO_QUERY);
764 if( xIni.is() )
766 //init internal dataprovider
768 uno::Sequence< uno::Any > aArgs(1);
769 beans::NamedValue aParam( "CreateDefaultData" ,uno::makeAny(sal_True) );
770 aArgs[0] <<= aParam;
771 xIni->initialize(aArgs);
773 //create data
774 uno::Sequence< beans::PropertyValue > aArgs( 4 );
775 aArgs[0] = beans::PropertyValue(
776 OUString( "CellRangeRepresentation" ), -1,
777 uno::makeAny( OUString("all") ), beans::PropertyState_DIRECT_VALUE );
778 aArgs[1] = beans::PropertyValue(
779 "HasCategories",
781 uno::makeAny( true ),
782 beans::PropertyState_DIRECT_VALUE );
783 aArgs[2] = beans::PropertyValue(
784 "FirstCellAsLabel",
786 uno::makeAny( true ),
787 beans::PropertyState_DIRECT_VALUE );
788 aArgs[3] = beans::PropertyValue(
789 "DataRowSource",
791 uno::makeAny( ::com::sun::star::chart::ChartDataRowSource_COLUMNS ),
792 beans::PropertyState_DIRECT_VALUE );
793 xDataSource = m_xInternalDataProvider->createDataSource( aArgs );
796 return xDataSource;
799 void SAL_CALL ChartModel::createInternalDataProvider( sal_Bool bCloneExistingData )
800 throw (util::CloseVetoException, uno::RuntimeException, std::exception)
802 // don't lock the mutex, because this call calls out to code that tries to
803 // lock the solar mutex. On the other hand, a paint locks the solar mutex
804 // and calls to the model lock the model's mutex => deadlock
805 // @todo: lock a separate mutex in the InternalData class
806 if( !hasInternalDataProvider() )
808 if( bCloneExistingData )
809 m_xInternalDataProvider = ChartModelHelper::createInternalDataProvider( this, true );
810 else
811 m_xInternalDataProvider = ChartModelHelper::createInternalDataProvider( Reference<XChartDocument>(), true );
812 m_xDataProvider.set( m_xInternalDataProvider );
814 setModified( sal_True );
817 sal_Bool SAL_CALL ChartModel::hasInternalDataProvider()
818 throw (uno::RuntimeException, std::exception)
820 return m_xDataProvider.is() && m_xInternalDataProvider.is();
823 uno::Reference< chart2::data::XDataProvider > SAL_CALL ChartModel::getDataProvider()
824 throw (uno::RuntimeException, std::exception)
826 MutexGuard aGuard( m_aModelMutex );
827 return m_xDataProvider;
830 // ____ XDataReceiver ____
832 void SAL_CALL ChartModel::attachDataProvider( const uno::Reference< chart2::data::XDataProvider >& xDataProvider )
833 throw (uno::RuntimeException, std::exception)
836 MutexGuard aGuard( m_aModelMutex );
837 uno::Reference< beans::XPropertySet > xProp( xDataProvider, uno::UNO_QUERY );
838 if( xProp.is() )
842 bool bIncludeHiddenCells = ChartModelHelper::isIncludeHiddenCells( Reference< frame::XModel >(this) );
843 xProp->setPropertyValue("IncludeHiddenCells", uno::makeAny(bIncludeHiddenCells));
845 catch (const beans::UnknownPropertyException&)
850 m_xDataProvider.set( xDataProvider );
851 m_xInternalDataProvider.clear();
853 //the numberformatter is kept independent of the data provider!
855 setModified( sal_True );
858 void SAL_CALL ChartModel::attachNumberFormatsSupplier( const uno::Reference< util::XNumberFormatsSupplier >& xNewSupplier )
859 throw (uno::RuntimeException, std::exception)
862 MutexGuard aGuard( m_aModelMutex );
863 if( xNewSupplier==m_xNumberFormatsSupplier )
864 return;
865 if( xNewSupplier==m_xOwnNumberFormatsSupplier )
866 return;
867 if( m_xOwnNumberFormatsSupplier.is() && xNewSupplier.is() )
869 //@todo
870 //merge missing numberformats from own to new formatter
872 else if( !xNewSupplier.is() )
874 if( m_xNumberFormatsSupplier.is() )
876 //@todo
877 //merge missing numberformats from old numberformatter to own numberformatter
878 //create own numberformatter if necessary
882 m_xNumberFormatsSupplier.set( xNewSupplier );
883 m_xOwnNumberFormatsSupplier.clear();
885 setModified( sal_True );
888 void SAL_CALL ChartModel::setArguments( const Sequence< beans::PropertyValue >& aArguments )
889 throw (lang::IllegalArgumentException,
890 uno::RuntimeException, std::exception)
893 MutexGuard aGuard( m_aModelMutex );
894 if( !m_xDataProvider.is() )
895 return;
896 lockControllers();
900 Reference< chart2::data::XDataSource > xDataSource( m_xDataProvider->createDataSource( aArguments ) );
901 if( xDataSource.is() )
903 Reference< chart2::XDiagram > xDia( getFirstDiagram() );
904 if( !xDia.is() )
906 Reference< chart2::XChartTypeTemplate > xTemplate( impl_createDefaultChartTypeTemplate() );
907 if( xTemplate.is())
908 setFirstDiagram( xTemplate->createDiagramByDataSource( xDataSource, aArguments ) );
910 else
911 xDia->setDiagramData( xDataSource, aArguments );
914 catch (const lang::IllegalArgumentException&)
916 throw;
918 catch (const uno::Exception& ex)
920 ASSERT_EXCEPTION( ex );
922 unlockControllers();
924 setModified( sal_True );
927 Sequence< OUString > SAL_CALL ChartModel::getUsedRangeRepresentations()
928 throw (uno::RuntimeException, std::exception)
930 return DataSourceHelper::getUsedDataRanges( Reference< frame::XModel >(this));
933 Reference< chart2::data::XDataSource > SAL_CALL ChartModel::getUsedData()
934 throw (uno::RuntimeException, std::exception)
936 return DataSourceHelper::getUsedData( Reference< chart2::XChartDocument >(this));
939 Reference< chart2::data::XRangeHighlighter > SAL_CALL ChartModel::getRangeHighlighter()
940 throw (uno::RuntimeException, std::exception)
942 if( ! m_xRangeHighlighter.is())
944 uno::Reference< view::XSelectionSupplier > xSelSupp( this->getCurrentController(), uno::UNO_QUERY );
945 if( xSelSupp.is() )
946 m_xRangeHighlighter.set( ChartModelHelper::createRangeHighlighter( xSelSupp ));
948 return m_xRangeHighlighter;
951 Reference< chart2::XChartTypeTemplate > ChartModel::impl_createDefaultChartTypeTemplate()
953 Reference< chart2::XChartTypeTemplate > xTemplate;
954 Reference< lang::XMultiServiceFactory > xFact( m_xChartTypeManager, uno::UNO_QUERY );
955 if( xFact.is() )
956 xTemplate.set( xFact->createInstance( "com.sun.star.chart2.template.Column" ), uno::UNO_QUERY );
957 return xTemplate;
960 void SAL_CALL ChartModel::setChartTypeManager( const uno::Reference< chart2::XChartTypeManager >& xNewManager )
961 throw (uno::RuntimeException, std::exception)
964 MutexGuard aGuard( m_aModelMutex );
965 m_xChartTypeManager = xNewManager;
967 setModified( sal_True );
970 uno::Reference< chart2::XChartTypeManager > SAL_CALL ChartModel::getChartTypeManager()
971 throw (uno::RuntimeException, std::exception)
973 MutexGuard aGuard( m_aModelMutex );
974 return m_xChartTypeManager;
977 uno::Reference< beans::XPropertySet > SAL_CALL ChartModel::getPageBackground()
978 throw (uno::RuntimeException, std::exception)
980 MutexGuard aGuard( m_aModelMutex );
981 return m_xPageBackground;
984 void SAL_CALL ChartModel::createDefaultChart()
985 throw (css::uno::RuntimeException, std::exception)
987 insertDefaultChart();
990 sal_Bool SAL_CALL ChartModel::isOpenGLChart()
991 throw (css::uno::RuntimeException, std::exception)
993 return ChartHelper::isGL3DDiagram(m_xDiagram);
996 // ____ XTitled ____
997 uno::Reference< chart2::XTitle > SAL_CALL ChartModel::getTitleObject()
998 throw (uno::RuntimeException, std::exception)
1000 MutexGuard aGuard( m_aModelMutex );
1001 return m_xTitle;
1004 void SAL_CALL ChartModel::setTitleObject( const uno::Reference< chart2::XTitle >& xTitle )
1005 throw (uno::RuntimeException, std::exception)
1008 MutexGuard aGuard( m_aModelMutex );
1009 if( m_xTitle.is() )
1010 ModifyListenerHelper::removeListener( m_xTitle, this );
1011 m_xTitle = xTitle;
1012 ModifyListenerHelper::addListener( m_xTitle, this );
1014 setModified( sal_True );
1017 // ____ XInterface (for old API wrapper) ____
1018 uno::Any SAL_CALL ChartModel::queryInterface( const uno::Type& aType )
1019 throw (uno::RuntimeException, std::exception)
1021 uno::Any aResult( impl::ChartModel_Base::queryInterface( aType ));
1023 if( ! aResult.hasValue())
1025 // try old API wrapper
1028 if( m_xOldModelAgg.is())
1029 aResult = m_xOldModelAgg->queryAggregation( aType );
1031 catch (const uno::Exception& ex)
1033 ASSERT_EXCEPTION( ex );
1037 return aResult;
1040 // ____ XCloneable ____
1041 Reference< util::XCloneable > SAL_CALL ChartModel::createClone()
1042 throw (uno::RuntimeException, std::exception)
1044 return Reference< util::XCloneable >( new ChartModel( *this ));
1047 // ____ XVisualObject ____
1048 void SAL_CALL ChartModel::setVisualAreaSize( ::sal_Int64 nAspect, const awt::Size& aSize )
1049 throw (lang::IllegalArgumentException,
1050 embed::WrongStateException,
1051 uno::Exception,
1052 uno::RuntimeException, std::exception)
1054 if( nAspect == embed::Aspects::MSOLE_CONTENT )
1056 ControllerLockGuard aLockGuard( *this );
1057 bool bChanged =
1058 (m_aVisualAreaSize.Width != aSize.Width ||
1059 m_aVisualAreaSize.Height != aSize.Height);
1061 // #i12587# support for shapes in chart
1062 if ( bChanged )
1064 impl_adjustAdditionalShapesPositionAndSize( aSize );
1067 m_aVisualAreaSize = aSize;
1068 if( bChanged )
1069 setModified( sal_True );
1071 else
1073 OSL_FAIL( "setVisualAreaSize: Aspect not implemented yet.");
1077 awt::Size SAL_CALL ChartModel::getVisualAreaSize( ::sal_Int64 nAspect )
1078 throw (lang::IllegalArgumentException,
1079 embed::WrongStateException,
1080 uno::Exception,
1081 uno::RuntimeException, std::exception)
1083 OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT,
1084 "No aspects other than content are supported" );
1085 (void)(nAspect); // avoid warning in non-debug builds
1086 // other possible aspects are MSOLE_THUMBNAIL, MSOLE_ICON and MSOLE_DOCPRINT
1088 return m_aVisualAreaSize;
1091 embed::VisualRepresentation SAL_CALL ChartModel::getPreferredVisualRepresentation( ::sal_Int64 nAspect )
1092 throw (lang::IllegalArgumentException,
1093 embed::WrongStateException,
1094 uno::Exception,
1095 uno::RuntimeException, std::exception)
1097 OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT,
1098 "No aspects other than content are supported" );
1099 (void)(nAspect); // avoid warning in non-debug builds
1101 embed::VisualRepresentation aResult;
1105 Sequence< sal_Int8 > aMetafile;
1107 //get view from old api wrapper
1108 Reference< datatransfer::XTransferable > xTransferable(
1109 this->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
1110 if( xTransferable.is() )
1112 datatransfer::DataFlavor aDataFlavor( lcl_aGDIMetaFileMIMEType,
1113 "GDIMetaFile",
1114 cppu::UnoType<uno::Sequence< sal_Int8 >>::get() );
1116 uno::Any aData( xTransferable->getTransferData( aDataFlavor ) );
1117 aData >>= aMetafile;
1120 aResult.Flavor.MimeType = lcl_aGDIMetaFileMIMEType;
1121 aResult.Flavor.DataType = cppu::UnoType<decltype(aMetafile)>::get();
1123 aResult.Data <<= aMetafile;
1125 catch (const uno::Exception& ex)
1127 ASSERT_EXCEPTION( ex );
1130 return aResult;
1133 ::sal_Int32 SAL_CALL ChartModel::getMapUnit( ::sal_Int64 nAspect )
1134 throw (uno::Exception,
1135 uno::RuntimeException, std::exception)
1137 OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT,
1138 "No aspects other than content are supported" );
1139 (void)(nAspect); // avoid warning in non-debug builds
1140 return embed::EmbedMapUnits::ONE_100TH_MM;
1143 // ____ datatransfer::XTransferable ____
1144 uno::Any SAL_CALL ChartModel::getTransferData( const datatransfer::DataFlavor& aFlavor )
1145 throw (datatransfer::UnsupportedFlavorException,
1146 io::IOException,
1147 uno::RuntimeException, std::exception)
1149 uno::Any aResult;
1150 if( this->isDataFlavorSupported( aFlavor ))
1154 //get view from old api wrapper
1155 Reference< datatransfer::XTransferable > xTransferable(
1156 this->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
1157 if( xTransferable.is() &&
1158 xTransferable->isDataFlavorSupported( aFlavor ))
1160 aResult = xTransferable->getTransferData( aFlavor );
1163 catch (const uno::Exception& ex)
1165 ASSERT_EXCEPTION( ex );
1168 else
1170 throw datatransfer::UnsupportedFlavorException(
1171 aFlavor.MimeType, static_cast< ::cppu::OWeakObject* >( this ));
1174 return aResult;
1177 Sequence< datatransfer::DataFlavor > SAL_CALL ChartModel::getTransferDataFlavors()
1178 throw (uno::RuntimeException, std::exception)
1180 uno::Sequence< datatransfer::DataFlavor > aRet(1);
1182 aRet[0] = datatransfer::DataFlavor( lcl_aGDIMetaFileMIMETypeHighContrast,
1183 "GDIMetaFile",
1184 cppu::UnoType<uno::Sequence< sal_Int8 >>::get() );
1186 return aRet;
1189 sal_Bool SAL_CALL ChartModel::isDataFlavorSupported( const datatransfer::DataFlavor& aFlavor )
1190 throw (uno::RuntimeException, std::exception)
1192 return aFlavor.MimeType.equals(lcl_aGDIMetaFileMIMETypeHighContrast);
1195 namespace
1197 enum eServiceType
1199 SERVICE_DASH_TABLE,
1200 SERVICE_GARDIENT_TABLE,
1201 SERVICE_HATCH_TABLE,
1202 SERVICE_BITMAP_TABLE,
1203 SERVICE_TRANSP_GRADIENT_TABLE,
1204 SERVICE_MARKER_TABLE,
1205 SERVICE_NAMESPACE_MAP
1208 typedef ::std::map< OUString, enum eServiceType > tServiceNameMap;
1209 typedef ::comphelper::MakeMap< OUString, enum eServiceType > tMakeServiceNameMap;
1211 tServiceNameMap & lcl_getStaticServiceNameMap()
1213 static tServiceNameMap aServiceNameMap(
1214 tMakeServiceNameMap
1215 ( "com.sun.star.drawing.DashTable", SERVICE_DASH_TABLE )
1216 ( "com.sun.star.drawing.GradientTable", SERVICE_GARDIENT_TABLE )
1217 ( "com.sun.star.drawing.HatchTable", SERVICE_HATCH_TABLE )
1218 ( "com.sun.star.drawing.BitmapTable", SERVICE_BITMAP_TABLE )
1219 ( "com.sun.star.drawing.TransparencyGradientTable", SERVICE_TRANSP_GRADIENT_TABLE )
1220 ( "com.sun.star.drawing.MarkerTable", SERVICE_MARKER_TABLE )
1221 ( "com.sun.star.xml.NamespaceMap", SERVICE_NAMESPACE_MAP )
1223 return aServiceNameMap;
1226 // ____ XMultiServiceFactory ____
1227 Reference< uno::XInterface > SAL_CALL ChartModel::createInstance( const OUString& rServiceSpecifier )
1228 throw( uno::Exception, uno::RuntimeException, std::exception )
1230 uno::Reference< uno::XInterface > xResult;
1231 tServiceNameMap & rMap = lcl_getStaticServiceNameMap();
1233 tServiceNameMap::const_iterator aIt( rMap.find( rServiceSpecifier ));
1234 if( aIt != rMap.end())
1236 switch( (*aIt).second )
1238 case SERVICE_DASH_TABLE:
1239 case SERVICE_GARDIENT_TABLE:
1240 case SERVICE_HATCH_TABLE:
1241 case SERVICE_BITMAP_TABLE:
1242 case SERVICE_TRANSP_GRADIENT_TABLE:
1243 case SERVICE_MARKER_TABLE:
1245 if(!mpChartView)
1247 mpChartView = new ChartView( m_xContext, *this);
1248 xChartView = static_cast< ::cppu::OWeakObject* >( mpChartView );
1250 return mpChartView->createInstance( rServiceSpecifier );
1252 break;
1253 case SERVICE_NAMESPACE_MAP:
1254 return Reference< uno::XInterface >( m_xXMLNamespaceMap );
1257 else if(rServiceSpecifier == CHART_VIEW_SERVICE_NAME)
1259 if(!mpChartView)
1261 mpChartView = new ChartView( m_xContext, *this);
1262 xChartView = static_cast< ::cppu::OWeakObject* >( mpChartView );
1265 return static_cast< ::cppu::OWeakObject* >( mpChartView );
1267 else
1269 if( m_xOldModelAgg.is() )
1271 Any aAny = m_xOldModelAgg->queryAggregation( cppu::UnoType<lang::XMultiServiceFactory>::get());
1272 uno::Reference< lang::XMultiServiceFactory > xOldModelFactory;
1273 if( (aAny >>= xOldModelFactory) && xOldModelFactory.is() )
1275 return xOldModelFactory->createInstance( rServiceSpecifier );
1279 return 0;
1282 Reference< uno::XInterface > SAL_CALL ChartModel::createInstanceWithArguments(
1283 const OUString& rServiceSpecifier , const Sequence< Any >& Arguments )
1284 throw( uno::Exception, uno::RuntimeException, std::exception )
1286 OSL_ENSURE( Arguments.getLength(), "createInstanceWithArguments: Warning: Arguments are ignored" );
1287 (void)(Arguments); // avoid warning in non-debug builds
1288 return createInstance( rServiceSpecifier );
1291 Sequence< OUString > SAL_CALL ChartModel::getAvailableServiceNames()
1292 throw( uno::RuntimeException, std::exception )
1294 uno::Sequence< OUString > aResult;
1296 if( m_xOldModelAgg.is())
1298 Any aAny = m_xOldModelAgg->queryAggregation( cppu::UnoType<lang::XMultiServiceFactory>::get());
1299 uno::Reference< lang::XMultiServiceFactory > xOldModelFactory;
1300 if( (aAny >>= xOldModelFactory) && xOldModelFactory.is() )
1302 return xOldModelFactory->getAvailableServiceNames();
1305 return aResult;
1308 Reference< util::XNumberFormatsSupplier > ChartModel::getNumberFormatsSupplier()
1310 if( !m_xNumberFormatsSupplier.is() )
1312 if( !m_xOwnNumberFormatsSupplier.is() )
1314 m_apSvNumberFormatter.reset( new SvNumberFormatter( m_xContext, LANGUAGE_SYSTEM ) );
1315 m_xOwnNumberFormatsSupplier = new SvNumberFormatsSupplierObj( m_apSvNumberFormatter.get() );
1316 //pOwnNumberFormatter->ChangeStandardPrec( 15 ); todo?
1318 m_xNumberFormatsSupplier = m_xOwnNumberFormatsSupplier;
1320 return m_xNumberFormatsSupplier;
1323 // ____ XUnoTunnel ___
1324 ::sal_Int64 SAL_CALL ChartModel::getSomething( const Sequence< ::sal_Int8 >& aIdentifier )
1325 throw( uno::RuntimeException, std::exception)
1327 if( aIdentifier.getLength() == 16 && 0 == memcmp( SvNumberFormatsSupplierObj::getUnoTunnelId().getConstArray(),
1328 aIdentifier.getConstArray(), 16 ) )
1330 Reference< lang::XUnoTunnel > xTunnel( getNumberFormatsSupplier(), uno::UNO_QUERY );
1331 if( xTunnel.is() )
1332 return xTunnel->getSomething( aIdentifier );
1334 return 0;
1337 // ____ XNumberFormatsSupplier ____
1338 uno::Reference< beans::XPropertySet > SAL_CALL ChartModel::getNumberFormatSettings()
1339 throw (uno::RuntimeException, std::exception)
1341 Reference< util::XNumberFormatsSupplier > xSupplier( getNumberFormatsSupplier() );
1342 if( xSupplier.is() )
1343 return xSupplier->getNumberFormatSettings();
1344 return uno::Reference< beans::XPropertySet >();
1347 uno::Reference< util::XNumberFormats > SAL_CALL ChartModel::getNumberFormats()
1348 throw (uno::RuntimeException, std::exception)
1350 Reference< util::XNumberFormatsSupplier > xSupplier( getNumberFormatsSupplier() );
1351 if( xSupplier.is() )
1352 return xSupplier->getNumberFormats();
1353 return uno::Reference< util::XNumberFormats >();
1356 // ____ XChild ____
1357 Reference< uno::XInterface > SAL_CALL ChartModel::getParent()
1358 throw (uno::RuntimeException, std::exception)
1360 return Reference< uno::XInterface >(m_xParent,uno::UNO_QUERY);
1363 void SAL_CALL ChartModel::setParent( const Reference< uno::XInterface >& Parent )
1364 throw (lang::NoSupportException,
1365 uno::RuntimeException, std::exception)
1367 if( Parent != m_xParent )
1368 m_xParent.set( Parent, uno::UNO_QUERY );
1371 // ____ XDataSource ____
1372 uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > SAL_CALL ChartModel::getDataSequences()
1373 throw (uno::RuntimeException, std::exception)
1375 Reference< chart2::data::XDataSource > xSource(
1376 DataSourceHelper::getUsedData( uno::Reference< frame::XModel >(this) ) );
1377 if( xSource.is())
1378 return xSource->getDataSequences();
1380 return uno::Sequence< Reference< chart2::data::XLabeledDataSequence > >();
1383 //XDumper
1384 OUString SAL_CALL ChartModel::dump()
1385 throw (uno::RuntimeException, std::exception)
1387 uno::Reference< qa::XDumper > xDumper(
1388 this->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
1389 if (xDumper.is())
1390 return xDumper->dump();
1392 return OUString();
1395 void ChartModel::setTimeBased(bool bTimeBased)
1397 mbTimeBased = bTimeBased;
1398 uno::Sequence<Reference< chart2::data::XLabeledDataSequence > >
1399 xDataSequences = getDataSequences();
1400 sal_Int32 n = xDataSequences.getLength();
1401 for(sal_Int32 i = 0; i < n; ++i)
1403 uno::Reference< chart2::XTimeBased > xTimeBased(xDataSequences[i]->getValues(), uno::UNO_QUERY);
1404 SAL_WARN_IF(!xTimeBased.is(), "chart2", "does not support time based charting");
1405 if(xTimeBased.is())
1407 uno::Reference< beans::XPropertySet > xPropSet(xTimeBased, uno::UNO_QUERY_THROW);
1408 xPropSet->setPropertyValue("TimeBased", uno::makeAny(bTimeBased));
1413 void ChartModel::getNextTimePoint()
1415 uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > xDataSequences = getDataSequences();
1416 sal_Int32 n = xDataSequences.getLength();
1417 for(sal_Int32 i = 0; i < n; ++i)
1419 uno::Reference< chart2::XTimeBased > xTimeBased(xDataSequences[i]->getValues(), uno::UNO_QUERY);
1420 SAL_WARN_IF(!xTimeBased.is(), "chart2", "does not support time based charting");
1421 if(xTimeBased.is())
1423 if(!bSet)
1424 xTimeBased->setRange(mnStart, mnEnd);
1425 xTimeBased->switchToNext(sal_True);
1428 bSet = true;
1431 void ChartModel::setTimeBasedRange(sal_Int32 nStart, sal_Int32 nEnd)
1433 bSet = false;
1434 mnStart = nStart;
1435 mnEnd = nEnd;
1436 mbTimeBased = true;
1439 void ChartModel::setWindow( const sal_uInt64 nWindowPtr )
1440 throw (uno::RuntimeException, std::exception)
1442 OpenGLWindow* pWindow = reinterpret_cast<OpenGLWindow*>(nWindowPtr);
1443 mpOpenGLWindow = pWindow;
1446 void ChartModel::update()
1447 throw (uno::RuntimeException, std::exception)
1449 if(!mpChartView)
1451 mpChartView = new ChartView( m_xContext, *this);
1452 xChartView = static_cast< ::cppu::OWeakObject* >( mpChartView );
1454 if(mpChartView)
1456 mpChartView->setViewDirty();
1457 mpChartView->update();
1458 mpChartView->updateOpenGLWindow();
1462 } // namespace chart
1464 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
1465 com_sun_star_comp_chart2_ChartModel_get_implementation(css::uno::XComponentContext *context,
1466 css::uno::Sequence<css::uno::Any> const &)
1468 return cppu::acquire(new ::chart::ChartModel(context));
1471 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */