Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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 :
36 : #include <com/sun/star/chart/ChartDataRowSource.hpp>
37 :
38 : #include <comphelper/InlineContainer.hxx>
39 : #include <comphelper/processfactory.hxx>
40 :
41 : // header for class SvNumberFormatsSupplierObj
42 : #include <svl/numuno.hxx>
43 : #include <com/sun/star/lang/DisposedException.hpp>
44 : #include <com/sun/star/lang/XInitialization.hpp>
45 : #include <com/sun/star/view/XSelectionSupplier.hpp>
46 : #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
47 : #include <com/sun/star/embed/XEmbedPersist.hpp>
48 : #include <com/sun/star/embed/EmbedStates.hpp>
49 : #include <com/sun/star/embed/XComponentSupplier.hpp>
50 : #include <com/sun/star/embed/XStorage.hpp>
51 : #include <com/sun/star/embed/EmbedMapUnits.hpp>
52 : #include <com/sun/star/embed/Aspects.hpp>
53 : #include <com/sun/star/awt/Gradient.hpp>
54 : #include <com/sun/star/awt/XWindow.hpp>
55 : #include <com/sun/star/awt/PosSize.hpp>
56 : #include <com/sun/star/datatransfer/XTransferable.hpp>
57 : #include <com/sun/star/drawing/Hatch.hpp>
58 : #include <com/sun/star/drawing/LineDash.hpp>
59 : #include <com/sun/star/drawing/XShapes.hpp>
60 : #include <com/sun/star/document/DocumentProperties.hpp>
61 : #include <com/sun/star/chart2/XTimeBased.hpp>
62 :
63 : // header for class SvNumberFormatter
64 : #include <svl/zforlist.hxx>
65 :
66 : using ::com::sun::star::uno::Sequence;
67 : using ::com::sun::star::uno::Reference;
68 : using ::com::sun::star::uno::RuntimeException;
69 : using ::com::sun::star::uno::Any;
70 : using ::osl::MutexGuard;
71 :
72 : using namespace ::com::sun::star;
73 : using namespace ::apphelper;
74 : using namespace ::chart::CloneHelper;
75 :
76 : namespace
77 : {
78 0 : const OUString lcl_aGDIMetaFileMIMEType(
79 0 : "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"");
80 0 : const OUString lcl_aGDIMetaFileMIMETypeHighContrast(
81 0 : "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"");
82 :
83 : } // anonymous namespace
84 :
85 : // ChartModel Constructor and Destructor
86 :
87 : namespace chart
88 : {
89 :
90 0 : ChartModel::ChartModel(uno::Reference<uno::XComponentContext > const & xContext)
91 : : m_aLifeTimeManager( this, this )
92 : , m_bReadOnly( sal_False )
93 : , m_bModified( sal_False )
94 : , m_nInLoad(0)
95 : , m_bUpdateNotificationsPending(false)
96 : , mbTimeBased(false)
97 : , mpChartView(NULL)
98 : , m_pUndoManager( NULL )
99 : , m_aControllers( m_aModelMutex )
100 : , m_nControllerLockCount(0)
101 : , m_xContext( xContext )
102 : , m_aVisualAreaSize( ChartModelHelper::getDefaultPageSize() )
103 : , m_xDataProvider( 0 )
104 : , m_xInternalDataProvider( 0 )
105 0 : , m_xPageBackground( new PageBackground( m_xContext ) )
106 0 : , m_xXMLNamespaceMap( createNameContainer( ::getCppuType( (const OUString*) 0 ),
107 : "com.sun.star.xml.NamespaceMap", "com.sun.star.comp.chart.XMLNameSpaceMap" ), uno::UNO_QUERY)
108 : , mnStart(0)
109 : , mnEnd(0)
110 0 : ,bSet(false)
111 : {
112 : OSL_TRACE( "ChartModel: CTOR called" );
113 :
114 0 : osl_atomic_increment(&m_refCount);
115 : {
116 : m_xOldModelAgg.set(
117 0 : m_xContext->getServiceManager()->createInstanceWithContext(
118 : CHART_CHARTAPIWRAPPER_SERVICE_NAME,
119 0 : m_xContext ), uno::UNO_QUERY_THROW );
120 0 : m_xOldModelAgg->setDelegator( *this );
121 : }
122 :
123 : {
124 0 : ModifyListenerHelper::addListener( m_xPageBackground, this );
125 0 : m_xChartTypeManager.set( xContext->getServiceManager()->createInstanceWithContext(
126 0 : "com.sun.star.chart2.ChartTypeManager", m_xContext ), uno::UNO_QUERY );
127 : }
128 0 : osl_atomic_decrement(&m_refCount);
129 0 : }
130 :
131 0 : ChartModel::ChartModel( const ChartModel & rOther )
132 : : impl::ChartModel_Base()
133 : , m_aLifeTimeManager( this, this )
134 : , m_bReadOnly( rOther.m_bReadOnly )
135 : , m_bModified( rOther.m_bModified )
136 : , m_nInLoad(0)
137 : , m_bUpdateNotificationsPending(false)
138 : , mbTimeBased(rOther.mbTimeBased)
139 : , mpChartView(NULL)
140 : , m_aResource( rOther.m_aResource )
141 : , m_aMediaDescriptor( rOther.m_aMediaDescriptor )
142 : , m_aControllers( m_aModelMutex )
143 : , m_nControllerLockCount(0)
144 : , m_xContext( rOther.m_xContext )
145 : // @note: the old model aggregate must not be shared with other models if it
146 : // is, you get mutex deadlocks
147 : , m_xOldModelAgg( 0 ) //rOther.m_xOldModelAgg )
148 : , m_xStorage( 0 ) //rOther.m_xStorage )
149 : , m_aVisualAreaSize( rOther.m_aVisualAreaSize )
150 : , m_aGraphicObjectVector( rOther.m_aGraphicObjectVector )
151 : , m_xDataProvider( rOther.m_xDataProvider )
152 : , m_xInternalDataProvider( rOther.m_xInternalDataProvider )
153 : , mnStart(rOther.mnStart)
154 : , mnEnd(rOther.mnEnd)
155 0 : , bSet(false)
156 : {
157 : OSL_TRACE( "ChartModel: Copy-CTOR called" );
158 :
159 0 : osl_atomic_increment(&m_refCount);
160 : {
161 : m_xOldModelAgg.set(
162 0 : m_xContext->getServiceManager()->createInstanceWithContext(
163 : CHART_CHARTAPIWRAPPER_SERVICE_NAME,
164 0 : m_xContext ), uno::UNO_QUERY_THROW );
165 0 : m_xOldModelAgg->setDelegator( *this );
166 :
167 0 : Reference< util::XModifyListener > xListener;
168 0 : Reference< chart2::XTitle > xNewTitle = CreateRefClone< Reference< chart2::XTitle > >()( rOther.m_xTitle );
169 0 : Reference< chart2::XDiagram > xNewDiagram = CreateRefClone< Reference< chart2::XDiagram > >()( rOther.m_xDiagram );
170 0 : Reference< beans::XPropertySet > xNewPageBackground = CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xPageBackground );
171 0 : Reference< chart2::XChartTypeManager > xChartTypeManager = CreateRefClone< Reference< chart2::XChartTypeManager > >()( rOther.m_xChartTypeManager );
172 0 : Reference< container::XNameAccess > xXMLNamespaceMap = CreateRefClone< Reference< container::XNameAccess > >()( rOther.m_xXMLNamespaceMap );
173 :
174 : {
175 0 : MutexGuard aGuard( m_aModelMutex );
176 0 : xListener = this;
177 0 : m_xTitle = xNewTitle;
178 0 : m_xDiagram = xNewDiagram;
179 0 : m_xPageBackground = xNewPageBackground;
180 0 : m_xChartTypeManager = xChartTypeManager;
181 0 : m_xXMLNamespaceMap = xXMLNamespaceMap;
182 : }
183 :
184 0 : ModifyListenerHelper::addListener( xNewTitle, xListener );
185 0 : ModifyListenerHelper::addListener( xNewDiagram, xListener );
186 0 : ModifyListenerHelper::addListener( xNewPageBackground, xListener );
187 0 : xListener.clear();
188 : }
189 0 : osl_atomic_decrement(&m_refCount);
190 0 : }
191 :
192 0 : ChartModel::~ChartModel()
193 : {
194 : OSL_TRACE( "ChartModel: DTOR called" );
195 0 : if( m_xOldModelAgg.is())
196 0 : m_xOldModelAgg->setDelegator( NULL );
197 0 : }
198 :
199 0 : void SAL_CALL ChartModel::initialize( const Sequence< Any >& /*rArguments*/ )
200 : throw (uno::Exception, uno::RuntimeException, std::exception)
201 : {
202 : //#i113722# avoid duplicate creation
203 :
204 : //maybe additional todo?:
205 : //support argument "EmbeddedObject"?
206 : //support argument "EmbeddedScriptSupport"?
207 : //support argument "DocumentRecoverySupport"?
208 0 : }
209 :
210 : // private methods
211 :
212 0 : OUString ChartModel::impl_g_getLocation()
213 : {
214 :
215 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
216 0 : if(!aGuard.startApiCall())
217 0 : return OUString(); //behave passive if already disposed or closed or throw exception @todo?
218 : //mutex is acquired
219 0 : return m_aResource;
220 : }
221 :
222 0 : sal_Bool ChartModel::impl_isControllerConnected( const uno::Reference< frame::XController >& xController )
223 : {
224 : try
225 : {
226 0 : uno::Sequence< uno::Reference<uno::XInterface> > aSeq = m_aControllers.getElements();
227 0 : for( sal_Int32 nN = aSeq.getLength(); nN--; )
228 : {
229 0 : if( aSeq[nN] == xController )
230 0 : return sal_True;
231 0 : }
232 : }
233 0 : catch (const uno::Exception&)
234 : {
235 : }
236 0 : return sal_False;
237 : }
238 :
239 0 : uno::Reference< frame::XController > ChartModel::impl_getCurrentController() throw(uno::RuntimeException)
240 : {
241 : //@todo? hold only weak references to controllers
242 :
243 : // get the last active controller of this model
244 0 : if( m_xCurrentController.is() )
245 0 : return m_xCurrentController;
246 :
247 : // get the first controller of this model
248 0 : if( m_aControllers.getLength() )
249 : {
250 0 : uno::Reference<uno::XInterface> xI = m_aControllers.getElements()[0];
251 0 : return uno::Reference<frame::XController>( xI, uno::UNO_QUERY );
252 : }
253 :
254 : //return nothing if no controllers are connected at all
255 0 : return uno::Reference< frame::XController > ();
256 : }
257 :
258 0 : void SAL_CALL ChartModel::impl_notifyCloseListeners()
259 : throw( uno::RuntimeException)
260 : {
261 : ::cppu::OInterfaceContainerHelper* pIC = m_aLifeTimeManager.m_aListenerContainer
262 0 : .getContainer( ::getCppuType((const uno::Reference< util::XCloseListener >*)0) );
263 0 : if( pIC )
264 : {
265 0 : lang::EventObject aEvent( static_cast< lang::XComponent*>(this) );
266 0 : ::cppu::OInterfaceIteratorHelper aIt( *pIC );
267 0 : while( aIt.hasMoreElements() )
268 : {
269 0 : uno::Reference< util::XCloseListener > xListener( aIt.next(), uno::UNO_QUERY );
270 0 : if( xListener.is() )
271 0 : xListener->notifyClosing( aEvent );
272 0 : }
273 : }
274 0 : }
275 :
276 0 : void ChartModel::impl_adjustAdditionalShapesPositionAndSize( const awt::Size& aVisualAreaSize )
277 : {
278 0 : uno::Reference< beans::XPropertySet > xProperties( static_cast< ::cppu::OWeakObject* >( this ), uno::UNO_QUERY );
279 0 : if ( xProperties.is() )
280 : {
281 0 : uno::Reference< drawing::XShapes > xShapes;
282 0 : xProperties->getPropertyValue( "AdditionalShapes" ) >>= xShapes;
283 0 : if ( xShapes.is() )
284 : {
285 0 : sal_Int32 nCount = xShapes->getCount();
286 0 : for ( sal_Int32 i = 0; i < nCount; ++i )
287 : {
288 0 : Reference< drawing::XShape > xShape;
289 0 : if ( xShapes->getByIndex( i ) >>= xShape )
290 : {
291 0 : if ( xShape.is() )
292 : {
293 0 : awt::Point aPos( xShape->getPosition() );
294 0 : awt::Size aSize( xShape->getSize() );
295 :
296 0 : double fWidth = static_cast< double >( aVisualAreaSize.Width ) / m_aVisualAreaSize.Width;
297 0 : double fHeight = static_cast< double >( aVisualAreaSize.Height ) / m_aVisualAreaSize.Height;
298 :
299 0 : aPos.X = static_cast< long >( aPos.X * fWidth );
300 0 : aPos.Y = static_cast< long >( aPos.Y * fHeight );
301 0 : aSize.Width = static_cast< long >( aSize.Width * fWidth );
302 0 : aSize.Height = static_cast< long >( aSize.Height * fHeight );
303 :
304 0 : xShape->setPosition( aPos );
305 0 : xShape->setSize( aSize );
306 : }
307 : }
308 0 : }
309 0 : }
310 0 : }
311 0 : }
312 :
313 : // lang::XServiceInfo
314 :
315 0 : APPHELPER_XSERVICEINFO_IMPL(ChartModel,CHART_MODEL_SERVICE_IMPLEMENTATION_NAME)
316 :
317 0 : uno::Sequence< OUString > ChartModel::getSupportedServiceNames_Static()
318 : {
319 0 : uno::Sequence< OUString > aSNS( 3 );
320 0 : aSNS[0] = CHART_MODEL_SERVICE_NAME;
321 0 : aSNS[1] = "com.sun.star.document.OfficeDocument";
322 0 : aSNS[2] = "com.sun.star.chart.ChartDocument";
323 : //// @todo : add additional services if you support any further
324 0 : return aSNS;
325 : }
326 :
327 : // frame::XModel (required interface)
328 :
329 0 : sal_Bool SAL_CALL ChartModel::attachResource( const OUString& rURL
330 : , const uno::Sequence< beans::PropertyValue >& rMediaDescriptor )
331 : throw(uno::RuntimeException, std::exception)
332 : {
333 : /*
334 : The method attachResource() is used by the frame loader implementations
335 : to inform the model about its URL and MediaDescriptor.
336 : */
337 :
338 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
339 0 : if(!aGuard.startApiCall())
340 0 : return sal_False; //behave passive if already disposed or closed or throw exception @todo?
341 : //mutex is acquired
342 :
343 0 : if(!m_aResource.isEmpty())//we have a resource already //@todo? or is setting a new resource allowed?
344 0 : return sal_False;
345 0 : m_aResource = rURL;
346 0 : m_aMediaDescriptor = rMediaDescriptor;
347 :
348 : //@todo ? check rURL ??
349 : //@todo ? evaluate m_aMediaDescriptor;
350 : //@todo ? ... ??? --> nothing, this method is only for setting information
351 :
352 0 : return sal_True;
353 : }
354 :
355 0 : OUString SAL_CALL ChartModel::getURL() throw(uno::RuntimeException, std::exception)
356 : {
357 0 : return impl_g_getLocation();
358 : }
359 :
360 0 : uno::Sequence< beans::PropertyValue > SAL_CALL ChartModel::getArgs() throw(uno::RuntimeException, std::exception)
361 : {
362 : /*
363 : The method getArgs() returns a sequence of property values
364 : that report the resource description according to com.sun.star.document.MediaDescriptor,
365 : specified on loading or saving with storeAsURL.
366 : */
367 :
368 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
369 0 : if(!aGuard.startApiCall())
370 0 : return uno::Sequence< beans::PropertyValue >(); //behave passive if already disposed or closed or throw exception @todo?
371 : //mutex is acquired
372 :
373 0 : return m_aMediaDescriptor;
374 : }
375 :
376 0 : void SAL_CALL ChartModel::connectController( const uno::Reference< frame::XController >& xController )
377 : throw(uno::RuntimeException, std::exception)
378 : {
379 : //@todo? this method is declared as oneway -> ...?
380 :
381 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
382 0 : if(!aGuard.startApiCall())
383 0 : return ; //behave passive if already disposed or closed
384 : //mutex is acquired
385 :
386 : //--add controller
387 0 : m_aControllers.addInterface(xController);
388 : }
389 :
390 0 : void SAL_CALL ChartModel::disconnectController( const uno::Reference< frame::XController >& xController )
391 : throw(uno::RuntimeException, std::exception)
392 : {
393 : //@todo? this method is declared as oneway -> ...?
394 :
395 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
396 0 : if(!aGuard.startApiCall())
397 0 : return; //behave passive if already disposed or closed
398 :
399 : //--remove controller
400 0 : m_aControllers.removeInterface(xController);
401 :
402 : //case: current controller is disconnected:
403 0 : if( m_xCurrentController == xController )
404 0 : m_xCurrentController.clear();
405 :
406 0 : DisposeHelper::DisposeAndClear( m_xRangeHighlighter );
407 : }
408 :
409 0 : void SAL_CALL ChartModel::lockControllers() throw(uno::RuntimeException, std::exception)
410 : {
411 : /*
412 : suspends some notifications to the controllers which are used for display updates.
413 :
414 : The calls to lockControllers() and unlockControllers() may be nested
415 : and even overlapping, but they must be in pairs. While there is at least one lock
416 : remaining, some notifications for display updates are not broadcasted.
417 : */
418 :
419 : //@todo? this method is declared as oneway -> ...?
420 :
421 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
422 0 : if(!aGuard.startApiCall())
423 0 : return; //behave passive if already disposed or closed or throw exception @todo?
424 0 : ++m_nControllerLockCount;
425 : }
426 :
427 0 : void SAL_CALL ChartModel::unlockControllers() throw(uno::RuntimeException, std::exception)
428 : {
429 : /*
430 : resumes the notifications which were suspended by lockControllers() .
431 :
432 : The calls to lockControllers() and unlockControllers() may be nested
433 : and even overlapping, but they must be in pairs. While there is at least one lock
434 : remaining, some notifications for display updates are not broadcasted.
435 : */
436 :
437 : //@todo? this method is declared as oneway -> ...?
438 :
439 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
440 0 : if(!aGuard.startApiCall())
441 0 : return; //behave passive if already disposed or closed or throw exception @todo?
442 0 : if( m_nControllerLockCount == 0 )
443 : {
444 : OSL_TRACE( "ChartModel: unlockControllers called with m_nControllerLockCount == 0" );
445 0 : return;
446 : }
447 0 : --m_nControllerLockCount;
448 0 : if( m_nControllerLockCount == 0 && m_bUpdateNotificationsPending )
449 : {
450 0 : aGuard.clear();
451 0 : impl_notifyModifiedListeners();
452 0 : }
453 : }
454 :
455 0 : sal_Bool SAL_CALL ChartModel::hasControllersLocked() throw(uno::RuntimeException, std::exception)
456 : {
457 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
458 0 : if(!aGuard.startApiCall())
459 0 : return sal_False; //behave passive if already disposed or closed or throw exception @todo?
460 0 : return ( m_nControllerLockCount != 0 ) ;
461 : }
462 :
463 0 : uno::Reference< frame::XController > SAL_CALL ChartModel::getCurrentController() throw(uno::RuntimeException, std::exception)
464 : {
465 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
466 0 : if(!aGuard.startApiCall())
467 : throw lang::DisposedException(
468 : "getCurrentController was called on an already disposed or closed model",
469 0 : static_cast< ::cppu::OWeakObject* >(this) );
470 :
471 0 : return impl_getCurrentController();
472 : }
473 :
474 0 : void SAL_CALL ChartModel::setCurrentController( const uno::Reference< frame::XController >& xController )
475 : throw(container::NoSuchElementException, uno::RuntimeException, std::exception)
476 : {
477 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
478 0 : if(!aGuard.startApiCall())
479 : throw lang::DisposedException(
480 : "setCurrentController was called on an already disposed or closed model",
481 0 : static_cast< ::cppu::OWeakObject* >(this) );
482 :
483 : //OSL_ENSURE( impl_isControllerConnected(xController), "setCurrentController is called with a Controller which is not connected" );
484 0 : if(!impl_isControllerConnected(xController))
485 : throw container::NoSuchElementException(
486 : "setCurrentController is called with a Controller which is not connected",
487 0 : static_cast< ::cppu::OWeakObject* >(this) );
488 :
489 0 : m_xCurrentController = xController;
490 :
491 0 : DisposeHelper::DisposeAndClear( m_xRangeHighlighter );
492 0 : }
493 :
494 0 : uno::Reference< uno::XInterface > SAL_CALL ChartModel::getCurrentSelection() throw(uno::RuntimeException, std::exception)
495 : {
496 0 : LifeTimeGuard aGuard(m_aLifeTimeManager);
497 0 : if(!aGuard.startApiCall())
498 : throw lang::DisposedException(
499 : "getCurrentSelection was called on an already disposed or closed model",
500 0 : static_cast< ::cppu::OWeakObject* >(this) );
501 :
502 0 : uno::Reference< uno::XInterface > xReturn;
503 0 : uno::Reference< frame::XController > xController = impl_getCurrentController();
504 :
505 0 : aGuard.clear();
506 0 : if( xController.is() )
507 : {
508 0 : uno::Reference< view::XSelectionSupplier > xSelectionSupl( xController, uno::UNO_QUERY );
509 0 : if ( xSelectionSupl.is() )
510 : {
511 0 : uno::Any aSel = xSelectionSupl->getSelection();
512 0 : OUString aObjectCID;
513 0 : if( aSel >>= aObjectCID )
514 0 : xReturn.set( ObjectIdentifier::getObjectPropertySet( aObjectCID, Reference< XChartDocument >(this)));
515 0 : }
516 : }
517 0 : return xReturn;
518 : }
519 :
520 : // lang::XComponent (base of XModel)
521 0 : void SAL_CALL ChartModel::dispose() throw(uno::RuntimeException, std::exception)
522 : {
523 0 : Reference< XInterface > xKeepAlive( *this );
524 :
525 : //This object should release all resources and references in the
526 : //easiest possible manner
527 : //This object must notify all registered listeners using the method
528 : //<member>XEventListener::disposing</member>
529 :
530 : //hold no mutex
531 0 : if( !m_aLifeTimeManager.dispose() )
532 0 : return;
533 :
534 : //--release all resources and references
535 : //// @todo
536 :
537 0 : if ( m_xDiagram.is() )
538 0 : ModifyListenerHelper::removeListener( m_xDiagram, this );
539 :
540 0 : m_xDataProvider.clear();
541 0 : m_xInternalDataProvider.clear();
542 0 : m_xNumberFormatsSupplier.clear();
543 0 : DisposeHelper::DisposeAndClear( m_xOwnNumberFormatsSupplier );
544 0 : DisposeHelper::DisposeAndClear( m_xChartTypeManager );
545 0 : DisposeHelper::DisposeAndClear( m_xDiagram );
546 0 : DisposeHelper::DisposeAndClear( m_xTitle );
547 0 : DisposeHelper::DisposeAndClear( m_xPageBackground );
548 0 : DisposeHelper::DisposeAndClear( m_xXMLNamespaceMap );
549 :
550 0 : m_xStorage.clear();
551 : // just clear, don't dispose - we're not the owner
552 :
553 0 : if ( m_pUndoManager.is() )
554 0 : m_pUndoManager->disposing();
555 0 : m_pUndoManager.clear();
556 : // that's important, since the UndoManager implementation delegates its ref counting to ourself.
557 :
558 0 : if( m_xOldModelAgg.is()) // #i120828#, to release cyclic reference to ChartModel object
559 0 : m_xOldModelAgg->setDelegator( 0 );
560 :
561 0 : m_aControllers.disposeAndClear( lang::EventObject( static_cast< cppu::OWeakObject * >( this )));
562 0 : m_xCurrentController.clear();
563 :
564 0 : DisposeHelper::DisposeAndClear( m_xRangeHighlighter );
565 :
566 0 : if( m_xOldModelAgg.is())
567 0 : m_xOldModelAgg->setDelegator( NULL );
568 :
569 0 : OSL_TRACE( "ChartModel: dispose() called" );
570 : }
571 :
572 0 : void SAL_CALL ChartModel::addEventListener( const uno::Reference< lang::XEventListener > & xListener )
573 : throw(uno::RuntimeException, std::exception)
574 : {
575 0 : if( m_aLifeTimeManager.impl_isDisposedOrClosed() )
576 0 : return; //behave passive if already disposed or closed
577 :
578 0 : m_aLifeTimeManager.m_aListenerContainer.addInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), xListener );
579 : }
580 :
581 0 : void SAL_CALL ChartModel::removeEventListener( const uno::Reference< lang::XEventListener > & xListener )
582 : throw(uno::RuntimeException, std::exception)
583 : {
584 0 : if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
585 0 : return; //behave passive if already disposed or closed
586 :
587 0 : m_aLifeTimeManager.m_aListenerContainer.removeInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), xListener );
588 0 : return;
589 : }
590 :
591 : // util::XCloseBroadcaster (base of XCloseable)
592 0 : void SAL_CALL ChartModel::addCloseListener( const uno::Reference< util::XCloseListener > & xListener )
593 : throw(uno::RuntimeException, std::exception)
594 : {
595 0 : m_aLifeTimeManager.g_addCloseListener( xListener );
596 0 : }
597 :
598 0 : void SAL_CALL ChartModel::removeCloseListener( const uno::Reference< util::XCloseListener > & xListener )
599 : throw(uno::RuntimeException, std::exception)
600 : {
601 0 : if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
602 0 : return; //behave passive if already disposed or closed
603 :
604 0 : m_aLifeTimeManager.m_aListenerContainer.removeInterface( ::getCppuType((const uno::Reference< util::XCloseListener >*)0), xListener );
605 0 : return;
606 : }
607 :
608 : // util::XCloseable
609 0 : void SAL_CALL ChartModel::close( sal_Bool bDeliverOwnership )
610 : throw( util::CloseVetoException,
611 : uno::RuntimeException, std::exception )
612 : {
613 : //hold no mutex
614 :
615 0 : if( !m_aLifeTimeManager.g_close_startTryClose( bDeliverOwnership ) )
616 0 : return;
617 : //no mutex is acquired
618 :
619 : // At the end of this method may we must dispose ourself ...
620 : // and may nobody from outside hold a reference to us ...
621 : // then it's a good idea to do that by ourself.
622 0 : uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );
623 :
624 : //the listeners have had no veto
625 : //check whether we self can close
626 : {
627 : util::CloseVetoException aVetoException = util::CloseVetoException(
628 : "the model itself could not be closed",
629 0 : static_cast< ::cppu::OWeakObject* >(this) );
630 :
631 0 : if( m_aLifeTimeManager.g_close_isNeedToCancelLongLastingCalls( bDeliverOwnership, aVetoException ) )
632 : {
633 : ////you can empty this block, if you never start longlasting calls or
634 : ////if your longlasting calls are per default not cancelable (check how you have constructed your LifeTimeManager)
635 :
636 0 : sal_Bool bLongLastingCallsAreCanceled = sal_False;
637 : try
638 : {
639 : //try to cancel running longlasting calls
640 : //// @todo
641 : }
642 : catch (const uno::Exception&)
643 : {
644 : //// @todo
645 : //do not throw anything here!! (without endTryClose)
646 : }
647 : //if not successful canceled
648 0 : if(!bLongLastingCallsAreCanceled)
649 : {
650 0 : m_aLifeTimeManager.g_close_endTryClose( bDeliverOwnership, sal_True );
651 0 : throw aVetoException;
652 : }
653 0 : }
654 :
655 : }
656 0 : m_aLifeTimeManager.g_close_endTryClose_doClose();
657 :
658 : // BM @todo: is it ok to call the listeners here?
659 0 : impl_notifyCloseListeners();
660 : }
661 :
662 : // lang::XTypeProvider
663 0 : uno::Sequence< uno::Type > SAL_CALL ChartModel::getTypes()
664 : throw (uno::RuntimeException, std::exception)
665 : {
666 0 : uno::Reference< lang::XTypeProvider > xAggTypeProvider;
667 0 : if( (m_xOldModelAgg->queryAggregation( ::getCppuType( & xAggTypeProvider )) >>= xAggTypeProvider)
668 0 : && xAggTypeProvider.is())
669 : {
670 0 : uno::Sequence< uno::Type > aOwnTypes( impl::ChartModel_Base::getTypes());
671 0 : uno::Sequence< uno::Type > aAggTypes( xAggTypeProvider->getTypes());
672 0 : uno::Sequence< uno::Type > aResult( aOwnTypes.getLength() + aAggTypes.getLength());
673 0 : sal_Int32 i=0;
674 0 : for( ;i<aOwnTypes.getLength(); ++i )
675 0 : aResult[i] = aOwnTypes[i];
676 0 : for( sal_Int32 j=0; i<aResult.getLength(); ++j, ++i)
677 0 : aResult[i] = aAggTypes[j];
678 0 : return aResult;
679 : }
680 :
681 0 : return impl::ChartModel_Base::getTypes();
682 : }
683 :
684 : // document::XDocumentPropertiesSupplier
685 : uno::Reference< document::XDocumentProperties > SAL_CALL
686 0 : ChartModel::getDocumentProperties() throw (uno::RuntimeException, std::exception)
687 : {
688 0 : ::osl::MutexGuard aGuard( m_aModelMutex );
689 0 : if ( !m_xDocumentProperties.is() )
690 : {
691 0 : m_xDocumentProperties.set( document::DocumentProperties::create( ::comphelper::getProcessComponentContext() ) );
692 : }
693 0 : return m_xDocumentProperties;
694 : }
695 :
696 : // document::XDocumentPropertiesSupplier
697 0 : Reference< document::XUndoManager > SAL_CALL ChartModel::getUndoManager( ) throw (RuntimeException, std::exception)
698 : {
699 0 : ::osl::MutexGuard aGuard( m_aModelMutex );
700 0 : if ( !m_pUndoManager.is() )
701 0 : m_pUndoManager.set( new UndoManager( *this, m_aModelMutex ) );
702 0 : return m_pUndoManager.get();
703 : }
704 :
705 : // chart2::XChartDocument
706 :
707 0 : uno::Reference< chart2::XDiagram > SAL_CALL ChartModel::getFirstDiagram()
708 : throw (uno::RuntimeException, std::exception)
709 : {
710 0 : MutexGuard aGuard( m_aModelMutex );
711 0 : return m_xDiagram;
712 : }
713 :
714 0 : void SAL_CALL ChartModel::setFirstDiagram( const uno::Reference< chart2::XDiagram >& xDiagram )
715 : throw (uno::RuntimeException, std::exception)
716 : {
717 0 : Reference< chart2::XDiagram > xOldDiagram;
718 0 : Reference< util::XModifyListener > xListener;
719 : {
720 0 : MutexGuard aGuard( m_aModelMutex );
721 0 : if( xDiagram == m_xDiagram )
722 0 : return;
723 0 : xOldDiagram = m_xDiagram;
724 0 : m_xDiagram = xDiagram;
725 0 : xListener = this;
726 : }
727 : //don't keep the mutex locked while calling out
728 0 : ModifyListenerHelper::removeListener( xOldDiagram, xListener );
729 0 : ModifyListenerHelper::addListener( xDiagram, xListener );
730 0 : setModified( sal_True );
731 : }
732 :
733 0 : Reference< chart2::data::XDataSource > ChartModel::impl_createDefaultData()
734 : {
735 0 : Reference< chart2::data::XDataSource > xDataSource;
736 0 : if( hasInternalDataProvider() )
737 : {
738 0 : uno::Reference< lang::XInitialization > xIni(m_xInternalDataProvider,uno::UNO_QUERY);
739 0 : if( xIni.is() )
740 : {
741 : //init internal dataprovider
742 : {
743 0 : uno::Sequence< uno::Any > aArgs(1);
744 0 : beans::NamedValue aParam( "CreateDefaultData" ,uno::makeAny(sal_True) );
745 0 : aArgs[0] <<= aParam;
746 0 : xIni->initialize(aArgs);
747 : }
748 : //create data
749 0 : uno::Sequence< beans::PropertyValue > aArgs( 4 );
750 0 : aArgs[0] = beans::PropertyValue(
751 : OUString( "CellRangeRepresentation" ), -1,
752 0 : uno::makeAny( OUString("all") ), beans::PropertyState_DIRECT_VALUE );
753 0 : aArgs[1] = beans::PropertyValue(
754 : "HasCategories",
755 : -1,
756 : uno::makeAny( true ),
757 0 : beans::PropertyState_DIRECT_VALUE );
758 0 : aArgs[2] = beans::PropertyValue(
759 : "FirstCellAsLabel",
760 : -1,
761 : uno::makeAny( true ),
762 0 : beans::PropertyState_DIRECT_VALUE );
763 0 : aArgs[3] = beans::PropertyValue(
764 : "DataRowSource",
765 : -1,
766 : uno::makeAny( ::com::sun::star::chart::ChartDataRowSource_COLUMNS ),
767 0 : beans::PropertyState_DIRECT_VALUE );
768 0 : xDataSource = m_xInternalDataProvider->createDataSource( aArgs );
769 0 : }
770 : }
771 0 : return xDataSource;
772 : }
773 :
774 0 : void SAL_CALL ChartModel::createInternalDataProvider( sal_Bool bCloneExistingData )
775 : throw (util::CloseVetoException, uno::RuntimeException, std::exception)
776 : {
777 : // don't lock the mutex, because this call calls out to code that tries to
778 : // lock the solar mutex. On the other hand, a paint locks the solar mutex
779 : // and calls to the model lock the model's mutex => deadlock
780 : // @todo: lock a separate mutex in the InternalData class
781 0 : if( !hasInternalDataProvider() )
782 : {
783 0 : if( bCloneExistingData )
784 0 : m_xInternalDataProvider = ChartModelHelper::createInternalDataProvider( this, true );
785 : else
786 0 : m_xInternalDataProvider = ChartModelHelper::createInternalDataProvider( Reference<XChartDocument>(), true );
787 0 : m_xDataProvider.set( m_xInternalDataProvider );
788 : }
789 0 : setModified( sal_True );
790 0 : }
791 :
792 0 : sal_Bool SAL_CALL ChartModel::hasInternalDataProvider()
793 : throw (uno::RuntimeException, std::exception)
794 : {
795 0 : return m_xDataProvider.is() && m_xInternalDataProvider.is();
796 : }
797 :
798 0 : uno::Reference< chart2::data::XDataProvider > SAL_CALL ChartModel::getDataProvider()
799 : throw (uno::RuntimeException, std::exception)
800 : {
801 0 : MutexGuard aGuard( m_aModelMutex );
802 0 : return m_xDataProvider;
803 : }
804 :
805 : // ____ XDataReceiver ____
806 :
807 0 : void SAL_CALL ChartModel::attachDataProvider( const uno::Reference< chart2::data::XDataProvider >& xDataProvider )
808 : throw (uno::RuntimeException, std::exception)
809 : {
810 : {
811 0 : MutexGuard aGuard( m_aModelMutex );
812 0 : uno::Reference< beans::XPropertySet > xProp( xDataProvider, uno::UNO_QUERY );
813 0 : if( xProp.is() )
814 : {
815 : try
816 : {
817 0 : sal_Bool bIncludeHiddenCells = ChartModelHelper::isIncludeHiddenCells( Reference< frame::XModel >(this) );
818 0 : xProp->setPropertyValue("IncludeHiddenCells", uno::makeAny(bIncludeHiddenCells));
819 : }
820 0 : catch (const beans::UnknownPropertyException&)
821 : {
822 : }
823 : }
824 :
825 0 : m_xDataProvider.set( xDataProvider );
826 0 : m_xInternalDataProvider.clear();
827 :
828 : //the numberformatter is kept independent of the data provider!
829 : }
830 0 : setModified( sal_True );
831 0 : }
832 :
833 0 : void SAL_CALL ChartModel::attachNumberFormatsSupplier( const uno::Reference< util::XNumberFormatsSupplier >& xNewSupplier )
834 : throw (uno::RuntimeException, std::exception)
835 : {
836 : {
837 0 : MutexGuard aGuard( m_aModelMutex );
838 0 : if( xNewSupplier==m_xNumberFormatsSupplier )
839 0 : return;
840 0 : if( xNewSupplier==m_xOwnNumberFormatsSupplier )
841 0 : return;
842 0 : if( m_xOwnNumberFormatsSupplier.is() && xNewSupplier.is() )
843 : {
844 : //@todo
845 : //merge missing numberformats from own to new formatter
846 : }
847 0 : else if( !xNewSupplier.is() )
848 : {
849 0 : if( m_xNumberFormatsSupplier.is() )
850 : {
851 : //@todo
852 : //merge missing numberformats from old numberformatter to own numberformatter
853 : //create own numberformatter if necessary
854 : }
855 : }
856 :
857 0 : m_xNumberFormatsSupplier.set( xNewSupplier );
858 0 : m_xOwnNumberFormatsSupplier.clear();
859 : }
860 0 : setModified( sal_True );
861 : }
862 :
863 0 : void SAL_CALL ChartModel::setArguments( const Sequence< beans::PropertyValue >& aArguments )
864 : throw (lang::IllegalArgumentException,
865 : uno::RuntimeException, std::exception)
866 : {
867 : {
868 0 : MutexGuard aGuard( m_aModelMutex );
869 0 : if( !m_xDataProvider.is() )
870 0 : return;
871 0 : lockControllers();
872 :
873 : try
874 : {
875 0 : Reference< chart2::data::XDataSource > xDataSource( m_xDataProvider->createDataSource( aArguments ) );
876 0 : if( xDataSource.is() )
877 : {
878 0 : Reference< chart2::XDiagram > xDia( getFirstDiagram() );
879 0 : if( !xDia.is() )
880 : {
881 0 : Reference< chart2::XChartTypeTemplate > xTemplate( impl_createDefaultChartTypeTemplate() );
882 0 : if( xTemplate.is())
883 0 : setFirstDiagram( xTemplate->createDiagramByDataSource( xDataSource, aArguments ) );
884 : }
885 : else
886 0 : xDia->setDiagramData( xDataSource, aArguments );
887 0 : }
888 : }
889 0 : catch (const lang::IllegalArgumentException&)
890 : {
891 0 : throw;
892 : }
893 0 : catch (const uno::Exception& ex)
894 : {
895 : ASSERT_EXCEPTION( ex );
896 : }
897 0 : unlockControllers();
898 : }
899 0 : setModified( sal_True );
900 : }
901 :
902 0 : Sequence< OUString > SAL_CALL ChartModel::getUsedRangeRepresentations()
903 : throw (uno::RuntimeException, std::exception)
904 : {
905 0 : return DataSourceHelper::getUsedDataRanges( Reference< frame::XModel >(this));
906 : }
907 :
908 0 : Reference< chart2::data::XDataSource > SAL_CALL ChartModel::getUsedData()
909 : throw (uno::RuntimeException, std::exception)
910 : {
911 0 : return DataSourceHelper::getUsedData( Reference< chart2::XChartDocument >(this));
912 : }
913 :
914 0 : Reference< chart2::data::XRangeHighlighter > SAL_CALL ChartModel::getRangeHighlighter()
915 : throw (uno::RuntimeException, std::exception)
916 : {
917 0 : if( ! m_xRangeHighlighter.is())
918 : {
919 0 : uno::Reference< view::XSelectionSupplier > xSelSupp( this->getCurrentController(), uno::UNO_QUERY );
920 0 : if( xSelSupp.is() )
921 0 : m_xRangeHighlighter.set( ChartModelHelper::createRangeHighlighter( xSelSupp ));
922 : }
923 0 : return m_xRangeHighlighter;
924 : }
925 :
926 0 : Reference< chart2::XChartTypeTemplate > ChartModel::impl_createDefaultChartTypeTemplate()
927 : {
928 0 : Reference< chart2::XChartTypeTemplate > xTemplate;
929 0 : Reference< lang::XMultiServiceFactory > xFact( m_xChartTypeManager, uno::UNO_QUERY );
930 0 : if( xFact.is() )
931 0 : xTemplate.set( xFact->createInstance( "com.sun.star.chart2.template.Column" ), uno::UNO_QUERY );
932 0 : return xTemplate;
933 : }
934 :
935 0 : void SAL_CALL ChartModel::setChartTypeManager( const uno::Reference< chart2::XChartTypeManager >& xNewManager )
936 : throw (uno::RuntimeException, std::exception)
937 : {
938 : {
939 0 : MutexGuard aGuard( m_aModelMutex );
940 0 : m_xChartTypeManager = xNewManager;
941 : }
942 0 : setModified( sal_True );
943 0 : }
944 :
945 0 : uno::Reference< chart2::XChartTypeManager > SAL_CALL ChartModel::getChartTypeManager()
946 : throw (uno::RuntimeException, std::exception)
947 : {
948 0 : MutexGuard aGuard( m_aModelMutex );
949 0 : return m_xChartTypeManager;
950 : }
951 :
952 0 : uno::Reference< beans::XPropertySet > SAL_CALL ChartModel::getPageBackground()
953 : throw (uno::RuntimeException, std::exception)
954 : {
955 0 : MutexGuard aGuard( m_aModelMutex );
956 0 : return m_xPageBackground;
957 : }
958 :
959 : // ____ XTitled ____
960 0 : uno::Reference< chart2::XTitle > SAL_CALL ChartModel::getTitleObject()
961 : throw (uno::RuntimeException, std::exception)
962 : {
963 0 : MutexGuard aGuard( m_aModelMutex );
964 0 : return m_xTitle;
965 : }
966 :
967 0 : void SAL_CALL ChartModel::setTitleObject( const uno::Reference< chart2::XTitle >& xTitle )
968 : throw (uno::RuntimeException, std::exception)
969 : {
970 : {
971 0 : MutexGuard aGuard( m_aModelMutex );
972 0 : if( m_xTitle.is() )
973 0 : ModifyListenerHelper::removeListener( m_xTitle, this );
974 0 : m_xTitle = xTitle;
975 0 : ModifyListenerHelper::addListener( m_xTitle, this );
976 : }
977 0 : setModified( sal_True );
978 0 : }
979 :
980 : // ____ XInterface (for old API wrapper) ____
981 0 : uno::Any SAL_CALL ChartModel::queryInterface( const uno::Type& aType )
982 : throw (uno::RuntimeException, std::exception)
983 : {
984 0 : uno::Any aResult( impl::ChartModel_Base::queryInterface( aType ));
985 :
986 0 : if( ! aResult.hasValue())
987 : {
988 : // try old API wrapper
989 : try
990 : {
991 0 : if( m_xOldModelAgg.is())
992 0 : aResult = m_xOldModelAgg->queryAggregation( aType );
993 : }
994 0 : catch (const uno::Exception& ex)
995 : {
996 : ASSERT_EXCEPTION( ex );
997 : }
998 : }
999 :
1000 0 : return aResult;
1001 : }
1002 :
1003 : // ____ XCloneable ____
1004 0 : Reference< util::XCloneable > SAL_CALL ChartModel::createClone()
1005 : throw (uno::RuntimeException, std::exception)
1006 : {
1007 0 : return Reference< util::XCloneable >( new ChartModel( *this ));
1008 : }
1009 :
1010 : // ____ XVisualObject ____
1011 0 : void SAL_CALL ChartModel::setVisualAreaSize( ::sal_Int64 nAspect, const awt::Size& aSize )
1012 : throw (lang::IllegalArgumentException,
1013 : embed::WrongStateException,
1014 : uno::Exception,
1015 : uno::RuntimeException, std::exception)
1016 : {
1017 0 : if( nAspect == embed::Aspects::MSOLE_CONTENT )
1018 : {
1019 0 : ControllerLockGuard aLockGuard( *this );
1020 : bool bChanged =
1021 0 : (m_aVisualAreaSize.Width != aSize.Width ||
1022 0 : m_aVisualAreaSize.Height != aSize.Height);
1023 :
1024 : // #i12587# support for shapes in chart
1025 0 : if ( bChanged )
1026 : {
1027 0 : impl_adjustAdditionalShapesPositionAndSize( aSize );
1028 : }
1029 :
1030 0 : m_aVisualAreaSize = aSize;
1031 0 : if( bChanged )
1032 0 : setModified( sal_True );
1033 : }
1034 : else
1035 : {
1036 : OSL_FAIL( "setVisualAreaSize: Aspect not implemented yet.");
1037 : }
1038 0 : }
1039 :
1040 0 : awt::Size SAL_CALL ChartModel::getVisualAreaSize( ::sal_Int64 nAspect )
1041 : throw (lang::IllegalArgumentException,
1042 : embed::WrongStateException,
1043 : uno::Exception,
1044 : uno::RuntimeException, std::exception)
1045 : {
1046 : OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT,
1047 : "No aspects other than content are supported" );
1048 : (void)(nAspect); // avoid warning in non-debug builds
1049 : // other possible aspects are MSOLE_THUMBNAIL, MSOLE_ICON and MSOLE_DOCPRINT
1050 :
1051 0 : return m_aVisualAreaSize;
1052 : }
1053 :
1054 0 : embed::VisualRepresentation SAL_CALL ChartModel::getPreferredVisualRepresentation( ::sal_Int64 nAspect )
1055 : throw (lang::IllegalArgumentException,
1056 : embed::WrongStateException,
1057 : uno::Exception,
1058 : uno::RuntimeException, std::exception)
1059 : {
1060 : OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT,
1061 : "No aspects other than content are supported" );
1062 : (void)(nAspect); // avoid warning in non-debug builds
1063 :
1064 0 : embed::VisualRepresentation aResult;
1065 :
1066 : try
1067 : {
1068 0 : Sequence< sal_Int8 > aMetafile;
1069 :
1070 : //get view from old api wrapper
1071 : Reference< datatransfer::XTransferable > xTransferable(
1072 0 : this->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
1073 0 : if( xTransferable.is() )
1074 : {
1075 : datatransfer::DataFlavor aDataFlavor( lcl_aGDIMetaFileMIMEType,
1076 : "GDIMetaFile",
1077 0 : ::getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) );
1078 :
1079 0 : uno::Any aData( xTransferable->getTransferData( aDataFlavor ) );
1080 0 : aData >>= aMetafile;
1081 : }
1082 :
1083 0 : aResult.Flavor.MimeType = lcl_aGDIMetaFileMIMEType;
1084 0 : aResult.Flavor.DataType = getCppuType( &aMetafile );
1085 :
1086 0 : aResult.Data <<= aMetafile;
1087 : }
1088 0 : catch (const uno::Exception& ex)
1089 : {
1090 : ASSERT_EXCEPTION( ex );
1091 : }
1092 :
1093 0 : return aResult;
1094 : }
1095 :
1096 0 : ::sal_Int32 SAL_CALL ChartModel::getMapUnit( ::sal_Int64 nAspect )
1097 : throw (uno::Exception,
1098 : uno::RuntimeException, std::exception)
1099 : {
1100 : OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT,
1101 : "No aspects other than content are supported" );
1102 : (void)(nAspect); // avoid warning in non-debug builds
1103 0 : return embed::EmbedMapUnits::ONE_100TH_MM;
1104 : }
1105 :
1106 : // ____ datatransfer::XTransferable ____
1107 0 : uno::Any SAL_CALL ChartModel::getTransferData( const datatransfer::DataFlavor& aFlavor )
1108 : throw (datatransfer::UnsupportedFlavorException,
1109 : io::IOException,
1110 : uno::RuntimeException, std::exception)
1111 : {
1112 0 : uno::Any aResult;
1113 0 : if( this->isDataFlavorSupported( aFlavor ))
1114 : {
1115 : try
1116 : {
1117 : //get view from old api wrapper
1118 : Reference< datatransfer::XTransferable > xTransferable(
1119 0 : this->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
1120 0 : if( xTransferable.is() &&
1121 0 : xTransferable->isDataFlavorSupported( aFlavor ))
1122 : {
1123 0 : aResult = xTransferable->getTransferData( aFlavor );
1124 0 : }
1125 : }
1126 0 : catch (const uno::Exception& ex)
1127 : {
1128 : ASSERT_EXCEPTION( ex );
1129 : }
1130 : }
1131 : else
1132 : {
1133 : throw datatransfer::UnsupportedFlavorException(
1134 0 : aFlavor.MimeType, static_cast< ::cppu::OWeakObject* >( this ));
1135 : }
1136 :
1137 0 : return aResult;
1138 : }
1139 :
1140 0 : Sequence< datatransfer::DataFlavor > SAL_CALL ChartModel::getTransferDataFlavors()
1141 : throw (uno::RuntimeException, std::exception)
1142 : {
1143 0 : uno::Sequence< datatransfer::DataFlavor > aRet(1);
1144 :
1145 0 : aRet[0] = datatransfer::DataFlavor( lcl_aGDIMetaFileMIMETypeHighContrast,
1146 : "GDIMetaFile",
1147 0 : ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
1148 :
1149 0 : return aRet;
1150 : }
1151 :
1152 0 : sal_Bool SAL_CALL ChartModel::isDataFlavorSupported( const datatransfer::DataFlavor& aFlavor )
1153 : throw (uno::RuntimeException, std::exception)
1154 : {
1155 0 : return aFlavor.MimeType.equals(lcl_aGDIMetaFileMIMETypeHighContrast);
1156 : }
1157 :
1158 : namespace
1159 : {
1160 : enum eServiceType
1161 : {
1162 : SERVICE_DASH_TABLE,
1163 : SERVICE_GARDIENT_TABLE,
1164 : SERVICE_HATCH_TABLE,
1165 : SERVICE_BITMAP_TABLE,
1166 : SERVICE_TRANSP_GRADIENT_TABLE,
1167 : SERVICE_MARKER_TABLE,
1168 : SERVICE_NAMESPACE_MAP
1169 : };
1170 :
1171 : typedef ::std::map< OUString, enum eServiceType > tServiceNameMap;
1172 : typedef ::comphelper::MakeMap< OUString, enum eServiceType > tMakeServiceNameMap;
1173 :
1174 0 : tServiceNameMap & lcl_getStaticServiceNameMap()
1175 : {
1176 : static tServiceNameMap aServiceNameMap(
1177 : tMakeServiceNameMap
1178 : ( "com.sun.star.drawing.DashTable", SERVICE_DASH_TABLE )
1179 0 : ( "com.sun.star.drawing.GradientTable", SERVICE_GARDIENT_TABLE )
1180 0 : ( "com.sun.star.drawing.HatchTable", SERVICE_HATCH_TABLE )
1181 0 : ( "com.sun.star.drawing.BitmapTable", SERVICE_BITMAP_TABLE )
1182 0 : ( "com.sun.star.drawing.TransparencyGradientTable", SERVICE_TRANSP_GRADIENT_TABLE )
1183 0 : ( "com.sun.star.drawing.MarkerTable", SERVICE_MARKER_TABLE )
1184 0 : ( "com.sun.star.xml.NamespaceMap", SERVICE_NAMESPACE_MAP )
1185 0 : );
1186 0 : return aServiceNameMap;
1187 : }
1188 : }
1189 : // ____ XMultiServiceFactory ____
1190 0 : Reference< uno::XInterface > SAL_CALL ChartModel::createInstance( const OUString& rServiceSpecifier )
1191 : throw( uno::Exception, uno::RuntimeException, std::exception )
1192 : {
1193 0 : uno::Reference< uno::XInterface > xResult;
1194 0 : tServiceNameMap & rMap = lcl_getStaticServiceNameMap();
1195 :
1196 0 : tServiceNameMap::const_iterator aIt( rMap.find( rServiceSpecifier ));
1197 0 : if( aIt != rMap.end())
1198 : {
1199 0 : switch( (*aIt).second )
1200 : {
1201 : case SERVICE_DASH_TABLE:
1202 : case SERVICE_GARDIENT_TABLE:
1203 : case SERVICE_HATCH_TABLE:
1204 : case SERVICE_BITMAP_TABLE:
1205 : case SERVICE_TRANSP_GRADIENT_TABLE:
1206 : case SERVICE_MARKER_TABLE:
1207 : {
1208 0 : if(!mpChartView)
1209 : {
1210 0 : mpChartView = new ChartView( m_xContext, *this);
1211 0 : xChartView = static_cast< ::cppu::OWeakObject* >( mpChartView );
1212 : }
1213 0 : return mpChartView->createInstance( rServiceSpecifier );
1214 : }
1215 : break;
1216 : case SERVICE_NAMESPACE_MAP:
1217 0 : return Reference< uno::XInterface >( m_xXMLNamespaceMap );
1218 : }
1219 : }
1220 0 : else if(rServiceSpecifier == CHART_VIEW_SERVICE_NAME)
1221 : {
1222 0 : if(!mpChartView)
1223 : {
1224 0 : mpChartView = new ChartView( m_xContext, *this);
1225 0 : xChartView = static_cast< ::cppu::OWeakObject* >( mpChartView );
1226 : }
1227 :
1228 0 : return static_cast< ::cppu::OWeakObject* >( mpChartView );
1229 : }
1230 : else
1231 : {
1232 0 : if( m_xOldModelAgg.is() )
1233 : {
1234 0 : Any aAny = m_xOldModelAgg->queryAggregation( ::getCppuType((const uno::Reference< lang::XMultiServiceFactory >*)0) );
1235 0 : uno::Reference< lang::XMultiServiceFactory > xOldModelFactory;
1236 0 : if( (aAny >>= xOldModelFactory) && xOldModelFactory.is() )
1237 : {
1238 0 : return xOldModelFactory->createInstance( rServiceSpecifier );
1239 0 : }
1240 : }
1241 : }
1242 0 : return 0;
1243 : }
1244 :
1245 0 : Reference< uno::XInterface > SAL_CALL ChartModel::createInstanceWithArguments(
1246 : const OUString& rServiceSpecifier , const Sequence< Any >& Arguments )
1247 : throw( uno::Exception, uno::RuntimeException, std::exception )
1248 : {
1249 : OSL_ENSURE( Arguments.getLength(), "createInstanceWithArguments: Warning: Arguments are ignored" );
1250 : (void)(Arguments); // avoid warning in non-debug builds
1251 0 : return createInstance( rServiceSpecifier );
1252 : }
1253 :
1254 0 : Sequence< OUString > SAL_CALL ChartModel::getAvailableServiceNames()
1255 : throw( uno::RuntimeException, std::exception )
1256 : {
1257 0 : uno::Sequence< OUString > aResult;
1258 :
1259 0 : if( m_xOldModelAgg.is())
1260 : {
1261 0 : Any aAny = m_xOldModelAgg->queryAggregation( ::getCppuType((const uno::Reference< lang::XMultiServiceFactory >*)0) );
1262 0 : uno::Reference< lang::XMultiServiceFactory > xOldModelFactory;
1263 0 : if( (aAny >>= xOldModelFactory) && xOldModelFactory.is() )
1264 : {
1265 0 : return xOldModelFactory->getAvailableServiceNames();
1266 0 : }
1267 : }
1268 0 : return aResult;
1269 : }
1270 :
1271 0 : Reference< util::XNumberFormatsSupplier > ChartModel::getNumberFormatsSupplier()
1272 : {
1273 0 : if( !m_xNumberFormatsSupplier.is() )
1274 : {
1275 0 : if( !m_xOwnNumberFormatsSupplier.is() )
1276 : {
1277 0 : m_apSvNumberFormatter.reset( new SvNumberFormatter( m_xContext, LANGUAGE_SYSTEM ) );
1278 0 : m_xOwnNumberFormatsSupplier = new SvNumberFormatsSupplierObj( m_apSvNumberFormatter.get() );
1279 : //pOwnNumberFormatter->ChangeStandardPrec( 15 ); todo?
1280 : }
1281 0 : m_xNumberFormatsSupplier = m_xOwnNumberFormatsSupplier;
1282 : }
1283 0 : return m_xNumberFormatsSupplier;
1284 : }
1285 :
1286 : // ____ XUnoTunnel ___
1287 0 : ::sal_Int64 SAL_CALL ChartModel::getSomething( const Sequence< ::sal_Int8 >& aIdentifier )
1288 : throw( uno::RuntimeException, std::exception)
1289 : {
1290 0 : if( aIdentifier.getLength() == 16 && 0 == memcmp( SvNumberFormatsSupplierObj::getUnoTunnelId().getConstArray(),
1291 0 : aIdentifier.getConstArray(), 16 ) )
1292 : {
1293 0 : Reference< lang::XUnoTunnel > xTunnel( getNumberFormatsSupplier(), uno::UNO_QUERY );
1294 0 : if( xTunnel.is() )
1295 0 : return xTunnel->getSomething( aIdentifier );
1296 : }
1297 0 : return 0;
1298 : }
1299 :
1300 : // ____ XNumberFormatsSupplier ____
1301 0 : uno::Reference< beans::XPropertySet > SAL_CALL ChartModel::getNumberFormatSettings()
1302 : throw (uno::RuntimeException, std::exception)
1303 : {
1304 0 : Reference< util::XNumberFormatsSupplier > xSupplier( getNumberFormatsSupplier() );
1305 0 : if( xSupplier.is() )
1306 0 : return xSupplier->getNumberFormatSettings();
1307 0 : return uno::Reference< beans::XPropertySet >();
1308 : }
1309 :
1310 0 : uno::Reference< util::XNumberFormats > SAL_CALL ChartModel::getNumberFormats()
1311 : throw (uno::RuntimeException, std::exception)
1312 : {
1313 0 : Reference< util::XNumberFormatsSupplier > xSupplier( getNumberFormatsSupplier() );
1314 0 : if( xSupplier.is() )
1315 0 : return xSupplier->getNumberFormats();
1316 0 : return uno::Reference< util::XNumberFormats >();
1317 : }
1318 :
1319 : // ____ XChild ____
1320 0 : Reference< uno::XInterface > SAL_CALL ChartModel::getParent()
1321 : throw (uno::RuntimeException, std::exception)
1322 : {
1323 0 : return Reference< uno::XInterface >(m_xParent,uno::UNO_QUERY);
1324 : }
1325 :
1326 0 : void SAL_CALL ChartModel::setParent( const Reference< uno::XInterface >& Parent )
1327 : throw (lang::NoSupportException,
1328 : uno::RuntimeException, std::exception)
1329 : {
1330 0 : if( Parent != m_xParent )
1331 0 : m_xParent.set( Parent, uno::UNO_QUERY );
1332 0 : }
1333 :
1334 : // ____ XDataSource ____
1335 0 : uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > SAL_CALL ChartModel::getDataSequences()
1336 : throw (uno::RuntimeException, std::exception)
1337 : {
1338 : Reference< chart2::data::XDataSource > xSource(
1339 0 : DataSourceHelper::getUsedData( uno::Reference< frame::XModel >(this) ) );
1340 0 : if( xSource.is())
1341 0 : return xSource->getDataSequences();
1342 :
1343 0 : return uno::Sequence< Reference< chart2::data::XLabeledDataSequence > >();
1344 : }
1345 :
1346 : //XDumper
1347 0 : OUString SAL_CALL ChartModel::dump()
1348 : throw (uno::RuntimeException, std::exception)
1349 : {
1350 : uno::Reference< qa::XDumper > xDumper(
1351 0 : this->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
1352 0 : if (xDumper.is())
1353 0 : return xDumper->dump();
1354 :
1355 0 : return OUString();
1356 : }
1357 :
1358 0 : bool ChartModel::isTimeBased() const
1359 : {
1360 0 : return mbTimeBased;
1361 : }
1362 :
1363 0 : void ChartModel::setTimeBased(bool bTimeBased)
1364 : {
1365 0 : mbTimeBased = bTimeBased;
1366 : uno::Sequence<Reference< chart2::data::XLabeledDataSequence > >
1367 0 : xDataSequences = getDataSequences();
1368 0 : sal_Int32 n = xDataSequences.getLength();
1369 0 : for(sal_Int32 i = 0; i < n; ++i)
1370 : {
1371 0 : uno::Reference< chart2::XTimeBased > xTimeBased(xDataSequences[i]->getValues(), uno::UNO_QUERY);
1372 : SAL_WARN_IF(!xTimeBased.is(), "chart2", "does not support time based charting");
1373 0 : if(xTimeBased.is())
1374 : {
1375 0 : uno::Reference< beans::XPropertySet > xPropSet(xTimeBased, uno::UNO_QUERY_THROW);
1376 0 : xPropSet->setPropertyValue("TimeBased", uno::makeAny(bTimeBased));
1377 : }
1378 0 : }
1379 0 : }
1380 :
1381 0 : void ChartModel::getNextTimePoint()
1382 : {
1383 0 : uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > xDataSequences = getDataSequences();
1384 0 : sal_Int32 n = xDataSequences.getLength();
1385 0 : for(sal_Int32 i = 0; i < n; ++i)
1386 : {
1387 0 : uno::Reference< chart2::XTimeBased > xTimeBased(xDataSequences[i]->getValues(), uno::UNO_QUERY);
1388 : SAL_WARN_IF(!xTimeBased.is(), "chart2", "does not support time based charting");
1389 0 : if(xTimeBased.is())
1390 : {
1391 0 : if(!bSet)
1392 0 : xTimeBased->setRange(mnStart, mnEnd);
1393 0 : xTimeBased->switchToNext(sal_True);
1394 : }
1395 0 : }
1396 0 : bSet = true;
1397 0 : }
1398 :
1399 0 : void ChartModel::setTimeBasedRange(sal_Int32 nStart, sal_Int32 nEnd)
1400 : {
1401 0 : bSet = false;
1402 0 : mnStart = nStart;
1403 0 : mnEnd = nEnd;
1404 0 : mbTimeBased = true;
1405 0 : }
1406 :
1407 0 : } // namespace chart
1408 :
1409 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|