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