23#include <servicenames.hxx>
33#include <NameContainer.hxx>
42#include <com/sun/star/chart/ChartDataRowSource.hpp>
43#include <com/sun/star/chart2/data/XPivotTableDataProvider.hpp>
51#include <com/sun/star/lang/DisposedException.hpp>
52#include <com/sun/star/view/XSelectionSupplier.hpp>
53#include <com/sun/star/embed/EmbedMapUnits.hpp>
54#include <com/sun/star/embed/Aspects.hpp>
55#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
56#include <com/sun/star/datatransfer/XTransferable.hpp>
57#include <com/sun/star/drawing/XShapes.hpp>
58#include <com/sun/star/document/DocumentProperties.hpp>
59#include <com/sun/star/util/CloseVetoException.hpp>
60#include <com/sun/star/util/XModifyBroadcaster.hpp>
65#include <libxml/xmlwriter.h>
67using ::com::sun::star::uno::Sequence;
68using ::com::sun::star::uno::Reference;
69using ::com::sun::star::uno::Any;
70using ::osl::MutexGuard;
78constexpr OUStringLiteral lcl_aGDIMetaFileMIMEType(
79 u
"application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"");
80constexpr OUStringLiteral lcl_aGDIMetaFileMIMETypeHighContrast(
81 u
"application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"");
90ChartModel::ChartModel(uno::Reference<uno::XComponentContext > xContext)
91 : m_aLifeTimeManager( this, this )
93 , m_bModified( false )
95 , m_bUpdateNotificationsPending(false)
97 , m_aControllers( m_aModelMutex )
98 , m_nControllerLockCount(0)
100 , m_aVisualAreaSize( ChartModelHelper::getDefaultPageSize() )
101 , m_xPageBackground( new PageBackground )
106 osl_atomic_increment(&m_refCount);
109 m_xContext->getServiceManager()->createInstanceWithContext(
112 m_xOldModelAgg->setDelegator( *
this );
116 m_xPageBackground->addModifyListener(
this );
117 m_xChartTypeManager = new ::chart::ChartTypeManager(
m_xContext );
119 osl_atomic_decrement(&m_refCount);
122ChartModel::ChartModel(
const ChartModel & rOther )
124 , m_aLifeTimeManager( this, this )
126 , m_bModified( rOther.m_bModified )
128 , m_bUpdateNotificationsPending(false)
129 , mbTimeBased(rOther.mbTimeBased)
130 , m_aResource( rOther.m_aResource )
131 , m_aMediaDescriptor( rOther.m_aMediaDescriptor )
132 , m_aControllers( m_aModelMutex )
133 , m_nControllerLockCount(0)
139 , m_aVisualAreaSize( rOther.m_aVisualAreaSize )
140 , m_aGraphicObjectVector( rOther.m_aGraphicObjectVector )
141 , m_xDataProvider( rOther.m_xDataProvider )
142 , m_xInternalDataProvider( rOther.m_xInternalDataProvider )
146 osl_atomic_increment(&m_refCount);
149 m_xContext->getServiceManager()->createInstanceWithContext(
152 m_xOldModelAgg->setDelegator( *
this );
154 Reference< util::XModifyListener > xListener;
156 if ( rOther.m_xTitle )
157 xNewTitle =
new Title(*rOther.m_xTitle);
159 if (rOther.m_xDiagram.is())
160 xNewDiagram = new ::chart::Diagram( *rOther.m_xDiagram );
166 MutexGuard aGuard( m_aModelMutex );
168 m_xTitle = xNewTitle;
169 m_xDiagram = xNewDiagram;
170 m_xPageBackground = xNewPageBackground;
171 m_xChartTypeManager = xChartTypeManager;
172 m_xXMLNamespaceMap = xXMLNamespaceMap;
176 if( xNewDiagram && xListener)
177 xNewDiagram->addModifyListener( xListener );
178 if( xNewPageBackground && xListener)
179 xNewPageBackground->addModifyListener( xListener );
182 osl_atomic_decrement(&m_refCount);
185ChartModel::~ChartModel()
187 if( m_xOldModelAgg.is())
188 m_xOldModelAgg->setDelegator(
nullptr );
191void SAL_CALL ChartModel::initialize(
const Sequence< Any >& )
201ChartView* ChartModel::getChartView()
const
203 return mxChartView.get();
208OUString ChartModel::impl_g_getLocation()
211 LifeTimeGuard aGuard(m_aLifeTimeManager);
212 if(!aGuard.startApiCall())
218bool ChartModel::impl_isControllerConnected(
const uno::Reference< frame::XController >& xController )
222 std::vector< uno::Reference<uno::XInterface> >
aSeq = m_aControllers.getElements();
223 for(
const auto & r : aSeq )
225 if( r == xController )
229 catch (
const uno::Exception&)
235uno::Reference< frame::XController > ChartModel::impl_getCurrentController()
240 if( m_xCurrentController.is() )
241 return m_xCurrentController;
244 if( m_aControllers.getLength() )
246 uno::Reference<uno::XInterface> xI = m_aControllers.getInterface(0);
247 return uno::Reference<frame::XController>( xI, uno::UNO_QUERY );
251 return uno::Reference< frame::XController > ();
254void ChartModel::impl_notifyCloseListeners()
256 std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
257 if( m_aLifeTimeManager.m_aCloseListeners.getLength(aGuard) )
259 lang::EventObject
aEvent(
static_cast< lang::XComponent*
>(
this) );
260 m_aLifeTimeManager.m_aCloseListeners.notifyEach(aGuard, &util::XCloseListener::notifyClosing, aEvent);
264void ChartModel::impl_adjustAdditionalShapesPositionAndSize(
const awt::Size& aVisualAreaSize )
266 uno::Reference< beans::XPropertySet > xProperties(
static_cast< ::
cppu::OWeakObject*
>(
this ), uno::UNO_QUERY );
267 if ( !xProperties.is() )
270 uno::Reference< drawing::XShapes > xShapes;
271 xProperties->getPropertyValue(
"AdditionalShapes" ) >>= xShapes;
275 sal_Int32
nCount = xShapes->getCount();
276 for ( sal_Int32 i = 0;
i <
nCount; ++
i )
278 Reference< drawing::XShape > xShape;
279 if ( xShapes->getByIndex( i ) >>= xShape )
283 awt::Point aPos( xShape->getPosition() );
284 awt::Size aSize( xShape->getSize() );
286 double fWidth =
static_cast< double >( aVisualAreaSize.Width ) / m_aVisualAreaSize.Width;
287 double fHeight =
static_cast< double >( aVisualAreaSize.Height ) / m_aVisualAreaSize.Height;
289 aPos.X =
static_cast< tools::Long >( aPos.X * fWidth );
290 aPos.Y =
static_cast< tools::Long >( aPos.Y * fHeight );
291 aSize.Width =
static_cast< tools::Long >( aSize.Width * fWidth );
292 aSize.Height =
static_cast< tools::Long >( aSize.Height * fHeight );
294 xShape->setPosition( aPos );
295 xShape->setSize( aSize );
303OUString SAL_CALL ChartModel::getImplementationName()
308sal_Bool SAL_CALL ChartModel::supportsService(
const OUString& rServiceName )
313css::uno::Sequence< OUString > SAL_CALL ChartModel::getSupportedServiceNames()
317 "com.sun.star.document.OfficeDocument",
318 "com.sun.star.chart.ChartDocument"
324sal_Bool SAL_CALL ChartModel::attachResource(
const OUString& rURL
325 ,
const uno::Sequence< beans::PropertyValue >& rMediaDescriptor )
332 LifeTimeGuard aGuard(m_aLifeTimeManager);
333 if(!aGuard.startApiCall())
337 if(!m_aResource.isEmpty())
340 m_aMediaDescriptor = rMediaDescriptor;
349OUString SAL_CALL ChartModel::getURL()
351 return impl_g_getLocation();
354uno::Sequence< beans::PropertyValue > SAL_CALL ChartModel::getArgs()
362 LifeTimeGuard aGuard(m_aLifeTimeManager);
363 if(!aGuard.startApiCall())
364 return uno::Sequence< beans::PropertyValue >();
367 return m_aMediaDescriptor;
370void SAL_CALL ChartModel::connectController(
const uno::Reference< frame::XController >& xController )
374 LifeTimeGuard aGuard(m_aLifeTimeManager);
375 if(!aGuard.startApiCall())
380 m_aControllers.addInterface(xController);
383void SAL_CALL ChartModel::disconnectController(
const uno::Reference< frame::XController >& xController )
387 LifeTimeGuard aGuard(m_aLifeTimeManager);
388 if(!aGuard.startApiCall())
392 m_aControllers.removeInterface(xController);
395 if( m_xCurrentController == xController )
396 m_xCurrentController.clear();
398 if (m_xRangeHighlighter)
400 m_xRangeHighlighter->dispose();
401 m_xRangeHighlighter.clear();
406void SAL_CALL ChartModel::lockControllers()
418 LifeTimeGuard aGuard(m_aLifeTimeManager);
419 if(!aGuard.startApiCall())
421 ++m_nControllerLockCount;
424void SAL_CALL ChartModel::unlockControllers()
436 LifeTimeGuard aGuard(m_aLifeTimeManager);
437 if(!aGuard.startApiCall())
439 if( m_nControllerLockCount == 0 )
441 SAL_WARN(
"chart2",
"ChartModel: unlockControllers called with m_nControllerLockCount == 0" );
444 --m_nControllerLockCount;
445 if( m_nControllerLockCount == 0 && m_bUpdateNotificationsPending )
448 impl_notifyModifiedListeners();
452sal_Bool SAL_CALL ChartModel::hasControllersLocked()
454 LifeTimeGuard aGuard(m_aLifeTimeManager);
455 if(!aGuard.startApiCall())
457 return ( m_nControllerLockCount != 0 ) ;
460uno::Reference< frame::XController > SAL_CALL ChartModel::getCurrentController()
462 LifeTimeGuard aGuard(m_aLifeTimeManager);
463 if(!aGuard.startApiCall())
464 throw lang::DisposedException(
465 "getCurrentController was called on an already disposed or closed model",
468 return impl_getCurrentController();
471void SAL_CALL ChartModel::setCurrentController(
const uno::Reference< frame::XController >& xController )
473 LifeTimeGuard aGuard(m_aLifeTimeManager);
474 if(!aGuard.startApiCall())
475 throw lang::DisposedException(
476 "setCurrentController was called on an already disposed or closed model",
480 if(!impl_isControllerConnected(xController))
481 throw container::NoSuchElementException(
482 "setCurrentController is called with a Controller which is not connected",
487 if (m_xRangeHighlighter)
489 m_xRangeHighlighter->dispose();
490 m_xRangeHighlighter.clear();
495uno::Reference< uno::XInterface > SAL_CALL ChartModel::getCurrentSelection()
497 LifeTimeGuard aGuard(m_aLifeTimeManager);
498 if(!aGuard.startApiCall())
499 throw lang::DisposedException(
500 "getCurrentSelection was called on an already disposed or closed model",
503 uno::Reference< uno::XInterface > xReturn;
504 uno::Reference< frame::XController >
xController = impl_getCurrentController();
509 uno::Reference< view::XSelectionSupplier > xSelectionSupl( xController, uno::UNO_QUERY );
510 if ( xSelectionSupl.is() )
512 uno::Any aSel = xSelectionSupl->getSelection();
514 if( aSel >>= aObjectCID )
515 xReturn.set( ObjectIdentifier::getObjectPropertySet( aObjectCID,
this));
522void SAL_CALL ChartModel::dispose()
524 Reference< XInterface > xKeepAlive( *
this );
532 if( !m_aLifeTimeManager.dispose() )
538 if ( m_xDiagram.is() )
539 m_xDiagram->removeModifyListener(
this );
541 if ( m_xDataProvider.is() )
543 Reference<util::XModifyBroadcaster> xModifyBroadcaster( m_xDataProvider, uno::UNO_QUERY );
544 if ( xModifyBroadcaster.is() )
545 xModifyBroadcaster->removeModifyListener(
this );
548 m_xDataProvider.clear();
549 m_xInternalDataProvider.clear();
550 m_xNumberFormatsSupplier.clear();
551 m_xOwnNumberFormatsSupplier.clear();
552 m_xChartTypeManager.clear();
555 m_xPageBackground.clear();
556 m_xXMLNamespaceMap.clear();
561 if ( m_pUndoManager.is() )
562 m_pUndoManager->disposing();
563 m_pUndoManager.clear();
566 if( m_xOldModelAgg.is())
567 m_xOldModelAgg->setDelegator(
nullptr );
569 m_aControllers.disposeAndClear( lang::EventObject(
static_cast< cppu::OWeakObject *
>(
this )));
570 m_xCurrentController.clear();
572 if (m_xRangeHighlighter)
574 m_xRangeHighlighter->dispose();
575 m_xRangeHighlighter.clear();
579 if( m_xOldModelAgg.is())
580 m_xOldModelAgg->setDelegator(
nullptr );
583void SAL_CALL ChartModel::addEventListener(
const uno::Reference< lang::XEventListener > & xListener )
585 if( m_aLifeTimeManager.impl_isDisposedOrClosed() )
588 std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
589 m_aLifeTimeManager.m_aEventListeners.addInterface( aGuard, xListener );
592void SAL_CALL ChartModel::removeEventListener(
const uno::Reference< lang::XEventListener > & xListener )
594 if( m_aLifeTimeManager.impl_isDisposedOrClosed(
false) )
597 std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
598 m_aLifeTimeManager.m_aEventListeners.removeInterface( aGuard, xListener );
602void SAL_CALL ChartModel::addCloseListener(
const uno::Reference< util::XCloseListener > & xListener )
604 m_aLifeTimeManager.g_addCloseListener( xListener );
607void SAL_CALL ChartModel::removeCloseListener(
const uno::Reference< util::XCloseListener > & xListener )
609 if( m_aLifeTimeManager.impl_isDisposedOrClosed(
false) )
612 std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex);
613 m_aLifeTimeManager.m_aCloseListeners.removeInterface( aGuard, xListener );
617void SAL_CALL ChartModel::close(
sal_Bool bDeliverOwnership )
621 if( !m_aLifeTimeManager.g_close_startTryClose( bDeliverOwnership ) )
628 uno::Reference< uno::XInterface > xSelfHold(
static_cast< ::
cppu::OWeakObject*
>(
this) );
633 util::CloseVetoException aVetoException(
634 "the model itself could not be closed",
637 m_aLifeTimeManager.g_close_isNeedToCancelLongLastingCalls( bDeliverOwnership, aVetoException );
639 m_aLifeTimeManager.g_close_endTryClose_doClose();
642 impl_notifyCloseListeners();
646uno::Sequence< uno::Type > SAL_CALL ChartModel::getTypes()
648 uno::Reference< lang::XTypeProvider > xAggTypeProvider;
649 if( (m_xOldModelAgg->queryAggregation(
cppu::UnoType<
decltype(xAggTypeProvider)>::get()) >>= xAggTypeProvider)
650 && xAggTypeProvider.is())
653 impl::ChartModel_Base::getTypes(),
654 xAggTypeProvider->getTypes());
657 return impl::ChartModel_Base::getTypes();
661uno::Reference< document::XDocumentProperties > SAL_CALL
662 ChartModel::getDocumentProperties()
664 ::osl::MutexGuard aGuard( m_aModelMutex );
665 if ( !m_xDocumentProperties.is() )
667 m_xDocumentProperties.set( document::DocumentProperties::create( ::comphelper::getProcessComponentContext() ) );
669 return m_xDocumentProperties;
673Reference< document::XUndoManager > SAL_CALL ChartModel::getUndoManager( )
675 ::osl::MutexGuard aGuard( m_aModelMutex );
676 if ( !m_pUndoManager.is() )
677 m_pUndoManager.set(
new UndoManager( *
this, m_aModelMutex ) );
678 return m_pUndoManager;
683uno::Reference< chart2::XDiagram > SAL_CALL ChartModel::getFirstDiagram()
685 MutexGuard aGuard( m_aModelMutex );
689void SAL_CALL ChartModel::setFirstDiagram(
const uno::Reference< chart2::XDiagram >& xDiagram )
692 Reference< util::XModifyListener > xListener;
694 MutexGuard aGuard( m_aModelMutex );
695 if( xDiagram.get() == m_xDiagram.get() )
697 xOldDiagram = m_xDiagram;
698 assert(!xDiagram ||
dynamic_cast<::
chart::Diagram*
>(xDiagram.get()));
703 if( xOldDiagram && xListener )
704 xOldDiagram->removeModifyListener( xListener );
709Reference< chart2::data::XDataSource > ChartModel::impl_createDefaultData()
711 Reference< chart2::data::XDataSource > xDataSource;
712 if( hasInternalDataProvider() )
716 beans::NamedValue aParam(
"CreateDefaultData" ,
uno::Any(
true) );
717 uno::Sequence< uno::Any > aArgs{
uno::Any(aParam) };
718 m_xInternalDataProvider->initialize(aArgs);
722 {
"CellRangeRepresentation",
uno::Any( OUString(
"all") ) },
723 {
"HasCategories",
uno::Any(
true ) },
724 {
"FirstCellAsLabel",
uno::Any(
true ) },
725 {
"DataRowSource",
uno::Any( css::chart::ChartDataRowSource_COLUMNS ) }
727 xDataSource = m_xInternalDataProvider->createDataSource( aArgs );
732void SAL_CALL ChartModel::createInternalDataProvider(
sal_Bool bCloneExistingData )
738 if( !hasInternalDataProvider() )
740 if( bCloneExistingData )
741 m_xInternalDataProvider = ChartModelHelper::createInternalDataProvider(
this,
true );
743 m_xInternalDataProvider = ChartModelHelper::createInternalDataProvider(
nullptr,
true );
744 m_xDataProvider.set( m_xInternalDataProvider );
749void ChartModel::removeDataProviders()
751 if (m_xInternalDataProvider.is())
752 m_xInternalDataProvider.clear();
753 if (m_xDataProvider.is())
754 m_xDataProvider.clear();
759 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"ChartModel"));
760 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
762 if (mxChartView.is())
764 mxChartView->dumpAsXml(pWriter);
767 (void)xmlTextWriterEndElement(pWriter);
770sal_Bool SAL_CALL ChartModel::hasInternalDataProvider()
772 return m_xDataProvider.is() && m_xInternalDataProvider.is();
775uno::Reference< chart2::data::XDataProvider > SAL_CALL ChartModel::getDataProvider()
777 MutexGuard aGuard( m_aModelMutex );
778 return m_xDataProvider;
783void SAL_CALL ChartModel::attachDataProvider(
const uno::Reference< chart2::data::XDataProvider >& xDataProvider )
786 MutexGuard aGuard( m_aModelMutex );
787 uno::Reference< beans::XPropertySet > xProp( xDataProvider, uno::UNO_QUERY );
792 bool bIncludeHiddenCells = ChartModelHelper::isIncludeHiddenCells(
this );
793 xProp->setPropertyValue(
"IncludeHiddenCells",
uno::Any(bIncludeHiddenCells));
795 catch (
const beans::UnknownPropertyException&)
800 uno::Reference<util::XModifyBroadcaster> xModifyBroadcaster(xDataProvider, uno::UNO_QUERY);
801 if (xModifyBroadcaster.is())
803 xModifyBroadcaster->addModifyListener(
this);
806 m_xDataProvider.set( xDataProvider );
807 m_xInternalDataProvider.clear();
814void SAL_CALL ChartModel::attachNumberFormatsSupplier(
const uno::Reference< util::XNumberFormatsSupplier >& xNewSupplier )
817 MutexGuard aGuard( m_aModelMutex );
818 if( xNewSupplier == m_xNumberFormatsSupplier )
820 if( xNewSupplier == uno::Reference<XNumberFormatsSupplier>(m_xOwnNumberFormatsSupplier) )
822 if( m_xOwnNumberFormatsSupplier.is() && xNewSupplier.is() )
827 else if( !xNewSupplier.is() )
829 if( m_xNumberFormatsSupplier.is() )
837 m_xNumberFormatsSupplier.set( xNewSupplier );
838 m_xOwnNumberFormatsSupplier.clear();
843void SAL_CALL ChartModel::setArguments(
const Sequence< beans::PropertyValue >& aArguments )
846 MutexGuard aGuard( m_aModelMutex );
847 if( !m_xDataProvider.is() )
853 Reference< chart2::data::XDataSource > xDataSource( m_xDataProvider->createDataSource( aArguments ) );
854 if( xDataSource.is() )
861 setFirstDiagram( xTemplate->createDiagramByDataSource( xDataSource, aArguments ) );
864 xDia->setDiagramData( xDataSource, aArguments );
867 catch (
const lang::IllegalArgumentException&)
871 catch (
const uno::Exception&)
880Sequence< OUString > SAL_CALL ChartModel::getUsedRangeRepresentations()
882 return DataSourceHelper::getUsedDataRanges(
this );
885Reference< chart2::data::XDataSource > SAL_CALL ChartModel::getUsedData()
887 return DataSourceHelper::getUsedData( *
this );
890Reference< chart2::data::XRangeHighlighter > SAL_CALL ChartModel::getRangeHighlighter()
892 if( ! m_xRangeHighlighter.is())
893 m_xRangeHighlighter =
new RangeHighlighter(
this );
894 return m_xRangeHighlighter;
897Reference<awt::XRequestCallback> SAL_CALL ChartModel::getPopupRequest()
899 if (!m_xPopupRequest.is())
900 m_xPopupRequest.set(
new PopupRequest);
901 return m_xPopupRequest;
907 if( m_xChartTypeManager.is() )
908 xTemplate = m_xChartTypeManager->createTemplate(
"com.sun.star.chart2.template.Column" );
912void SAL_CALL ChartModel::setChartTypeManager(
const uno::Reference< chart2::XChartTypeManager >& xNewManager )
915 MutexGuard aGuard( m_aModelMutex );
917 assert(!xNewManager || m_xChartTypeManager);
922uno::Reference< chart2::XChartTypeManager > SAL_CALL ChartModel::getChartTypeManager()
924 MutexGuard aGuard( m_aModelMutex );
925 return m_xChartTypeManager;
928uno::Reference< beans::XPropertySet > SAL_CALL ChartModel::getPageBackground()
930 MutexGuard aGuard( m_aModelMutex );
931 return m_xPageBackground;
934void SAL_CALL ChartModel::createDefaultChart()
936 insertDefaultChart();
940uno::Reference< chart2::XTitle > SAL_CALL ChartModel::getTitleObject()
942 MutexGuard aGuard( m_aModelMutex );
948 MutexGuard aGuard( m_aModelMutex );
952void SAL_CALL ChartModel::setTitleObject(
const uno::Reference< chart2::XTitle >& xNewTitle )
955 assert(!xNewTitle || xTitle);
956 setTitleObject(xTitle);
962 MutexGuard aGuard( m_aModelMutex );
974 uno::Any aResult( impl::ChartModel_Base::queryInterface( aType ));
976 if( ! aResult.hasValue())
981 if( m_xOldModelAgg.is())
982 aResult = m_xOldModelAgg->queryAggregation( aType );
984 catch (
const uno::Exception&)
994Reference< util::XCloneable > SAL_CALL ChartModel::createClone()
996 return Reference< util::XCloneable >(
new ChartModel( *
this ));
1000void SAL_CALL ChartModel::setVisualAreaSize( ::sal_Int64 nAspect,
const awt::Size& aSize )
1002 if( nAspect == embed::Aspects::MSOLE_CONTENT )
1004 ControllerLockGuard aLockGuard( *
this );
1006 (m_aVisualAreaSize.Width != aSize.Width ||
1007 m_aVisualAreaSize.Height != aSize.Height);
1012 impl_adjustAdditionalShapesPositionAndSize( aSize );
1015 m_aVisualAreaSize = aSize;
1017 setModified(
true );
1021 OSL_FAIL(
"setVisualAreaSize: Aspect not implemented yet.");
1025awt::Size SAL_CALL ChartModel::getVisualAreaSize( ::sal_Int64 nAspect )
1027 OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT,
1028 "No aspects other than content are supported" );
1031 return m_aVisualAreaSize;
1034embed::VisualRepresentation SAL_CALL ChartModel::getPreferredVisualRepresentation( ::sal_Int64 nAspect )
1036 OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT,
1037 "No aspects other than content are supported" );
1039 embed::VisualRepresentation aResult;
1046 Reference< datatransfer::XTransferable > xTransferable(
1048 if( xTransferable.is() )
1050 datatransfer::DataFlavor aDataFlavor( lcl_aGDIMetaFileMIMEType,
1054 uno::Any aData( xTransferable->getTransferData( aDataFlavor ) );
1055 aData >>= aMetafile;
1058 aResult.Flavor.MimeType = lcl_aGDIMetaFileMIMEType;
1059 aResult.Flavor.DataType =
cppu::UnoType<
decltype(aMetafile)>::get();
1061 aResult.Data <<= aMetafile;
1063 catch (
const uno::Exception&)
1071::sal_Int32 SAL_CALL ChartModel::getMapUnit( ::sal_Int64 nAspect )
1073 OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT,
1074 "No aspects other than content are supported" );
1075 return embed::EmbedMapUnits::ONE_100TH_MM;
1079uno::Any SAL_CALL ChartModel::getTransferData(
const datatransfer::DataFlavor& aFlavor )
1082 if( !isDataFlavorSupported( aFlavor ) )
1083 throw datatransfer::UnsupportedFlavorException(
1089 Reference< datatransfer::XTransferable > xTransferable(
1091 if( xTransferable.is() &&
1092 xTransferable->isDataFlavorSupported( aFlavor ))
1094 aResult = xTransferable->getTransferData( aFlavor );
1097 catch (
const uno::Exception&)
1105Sequence< datatransfer::DataFlavor > SAL_CALL ChartModel::getTransferDataFlavors()
1107 return { datatransfer::DataFlavor( lcl_aGDIMetaFileMIMETypeHighContrast,
1112sal_Bool SAL_CALL ChartModel::isDataFlavorSupported(
const datatransfer::DataFlavor& aFlavor )
1114 return aFlavor.MimeType == lcl_aGDIMetaFileMIMETypeHighContrast;
1122 SERVICE_GRADIENT_TABLE,
1123 SERVICE_HATCH_TABLE,
1124 SERVICE_BITMAP_TABLE,
1125 SERVICE_TRANSP_GRADIENT_TABLE,
1126 SERVICE_MARKER_TABLE,
1127 SERVICE_NAMESPACE_MAP
1130typedef std::map< OUString, enum eServiceType > tServiceNameMap;
1132tServiceNameMap & lcl_getStaticServiceNameMap()
1134 static tServiceNameMap aServiceNameMap{
1135 {
"com.sun.star.drawing.DashTable", SERVICE_DASH_TABLE},
1136 {
"com.sun.star.drawing.GradientTable", SERVICE_GRADIENT_TABLE},
1137 {
"com.sun.star.drawing.HatchTable", SERVICE_HATCH_TABLE},
1138 {
"com.sun.star.drawing.BitmapTable", SERVICE_BITMAP_TABLE},
1139 {
"com.sun.star.drawing.TransparencyGradientTable", SERVICE_TRANSP_GRADIENT_TABLE},
1140 {
"com.sun.star.drawing.MarkerTable", SERVICE_MARKER_TABLE},
1141 {
"com.sun.star.xml.NamespaceMap", SERVICE_NAMESPACE_MAP}};
1142 return aServiceNameMap;
1146Reference< uno::XInterface > SAL_CALL ChartModel::createInstance(
const OUString& rServiceSpecifier )
1148 tServiceNameMap & rMap = lcl_getStaticServiceNameMap();
1150 tServiceNameMap::const_iterator aIt( rMap.find( rServiceSpecifier ));
1151 if( aIt != rMap.end())
1153 switch( (*aIt).second )
1155 case SERVICE_DASH_TABLE:
1156 case SERVICE_GRADIENT_TABLE:
1157 case SERVICE_HATCH_TABLE:
1158 case SERVICE_BITMAP_TABLE:
1159 case SERVICE_TRANSP_GRADIENT_TABLE:
1160 case SERVICE_MARKER_TABLE:
1162 if(!mxChartView.is())
1164 mxChartView =
new ChartView(
m_xContext, *
this);
1166 return mxChartView->createInstance( rServiceSpecifier );
1169 case SERVICE_NAMESPACE_MAP:
1175 if(!mxChartView.is())
1177 mxChartView =
new ChartView(
m_xContext, *
this);
1184 if( m_xOldModelAgg.is() )
1187 uno::Reference< lang::XMultiServiceFactory > xOldModelFactory;
1188 if( (aAny >>= xOldModelFactory) && xOldModelFactory.is() )
1190 return xOldModelFactory->createInstance( rServiceSpecifier );
1197Reference< uno::XInterface > SAL_CALL ChartModel::createInstanceWithArguments(
1198 const OUString& rServiceSpecifier ,
const Sequence< Any >& Arguments )
1200 OSL_ENSURE( Arguments.hasElements(),
"createInstanceWithArguments: Warning: Arguments are ignored" );
1204Sequence< OUString > SAL_CALL ChartModel::getAvailableServiceNames()
1206 uno::Sequence< OUString > aResult;
1208 if( m_xOldModelAgg.is())
1211 uno::Reference< lang::XMultiServiceFactory > xOldModelFactory;
1212 if( (aAny >>= xOldModelFactory) && xOldModelFactory.is() )
1214 return xOldModelFactory->getAvailableServiceNames();
1220Reference< util::XNumberFormatsSupplier >
const & ChartModel::getNumberFormatsSupplier()
1222 if( !m_xNumberFormatsSupplier.is() )
1224 if( !m_xOwnNumberFormatsSupplier.is() )
1230 m_xNumberFormatsSupplier = m_xOwnNumberFormatsSupplier;
1232 return m_xNumberFormatsSupplier;
1236::sal_Int64 SAL_CALL ChartModel::getSomething(
const Sequence< ::sal_Int8 >& aIdentifier )
1238 if( comphelper::isUnoTunnelId<SvNumberFormatsSupplierObj>(aIdentifier) )
1240 Reference< lang::XUnoTunnel > xTunnel( getNumberFormatsSupplier(), uno::UNO_QUERY );
1242 return xTunnel->getSomething( aIdentifier );
1248uno::Reference< beans::XPropertySet > SAL_CALL ChartModel::getNumberFormatSettings()
1250 Reference< util::XNumberFormatsSupplier > xSupplier( getNumberFormatsSupplier() );
1251 if( xSupplier.is() )
1252 return xSupplier->getNumberFormatSettings();
1253 return uno::Reference< beans::XPropertySet >();
1256uno::Reference< util::XNumberFormats > SAL_CALL ChartModel::getNumberFormats()
1258 Reference< util::XNumberFormatsSupplier > xSupplier( getNumberFormatsSupplier() );
1259 if( xSupplier.is() )
1260 return xSupplier->getNumberFormats();
1261 return uno::Reference< util::XNumberFormats >();
1265Reference< uno::XInterface > SAL_CALL ChartModel::getParent()
1267 return Reference< uno::XInterface >(m_xParent,uno::UNO_QUERY);
1270void SAL_CALL ChartModel::setParent(
const Reference< uno::XInterface >& Parent )
1272 if( Parent != m_xParent )
1273 m_xParent.set( Parent, uno::UNO_QUERY );
1277uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > SAL_CALL ChartModel::getDataSequences()
1281 return xSource->getDataSequences();
1283 return uno::Sequence< Reference< chart2::data::XLabeledDataSequence > >();
1287OUString SAL_CALL ChartModel::dump(OUString
const & kind)
1289 if (kind.isEmpty()) {
1290 return dumpXmlToString([
this](
auto writer) {
return dumpAsXml(writer); });
1294 uno::Reference< qa::XDumper > xDumper(
1297 return xDumper->dump(kind);
1302void ChartModel::setTimeBasedRange(sal_Int32 nStart, sal_Int32 nEnd)
1309void ChartModel::update()
1311 if(!mxChartView.is())
1313 mxChartView =
new ChartView(
m_xContext, *
this);
1315 mxChartView->setViewDirty();
1316 mxChartView->update();
1319bool ChartModel::isDataFromSpreadsheet()
1321 return !isDataFromPivotTable() && !hasInternalDataProvider();
1324bool ChartModel::isDataFromPivotTable()
const
1326 uno::Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider(m_xDataProvider, uno::UNO_QUERY);
1327 return xPivotTableDataProvider.is();
1332extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1334 css::uno::Sequence<css::uno::Any>
const &)
1336 return cppu::acquire(new ::chart::ChartModel(context));
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_ChartModel_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< uno::XComponentContext > m_xContext
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
#define DBG_UNHANDLED_EXCEPTION(...)
struct _xmlTextWriter * xmlTextWriterPtr
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
constexpr OUStringLiteral aData
void DisposeAndClear(css::uno::Reference< T > &rInterface)
void addListener(const InterfaceRef &xObject, const css::uno::Reference< css::lang::XEventListener > &xListener)
void removeListener(const InterfaceRef &xObject, const css::uno::Reference< css::lang::XEventListener > &xListener)
cppu::WeakImplHelper< css::util::XCloseable,css::frame::XStorable2,css::util::XModifiable,css::lang::XServiceInfo,css::lang::XInitialization,css::chart2::XChartDocument,css::chart2::data::XDataReceiver,css::chart2::XTitled,css::frame::XLoadable,css::util::XCloneable,css::embed::XVisualObject,css::lang::XMultiServiceFactory,css::document::XStorageBasedDocument,css::lang::XUnoTunnel,css::util::XNumberFormatsSupplier,css::container::XChild,css::util::XModifyListener,css::datatransfer::XTransferable,css::document::XDocumentPropertiesSupplier,css::chart2::data::XDataSource,css::document::XUndoManagerSupplier,css::util::XUpdatable,css::qa::XDumper > ChartModel_Base
OUString dumpXmlToString(F f)
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral CHART_VIEW_SERVICE_NAME
constexpr OUStringLiteral CHART_MODEL_SERVICE_NAME
constexpr OUStringLiteral CHART_MODEL_SERVICE_IMPLEMENTATION_NAME
constexpr OUStringLiteral CHART_CHARTAPIWRAPPER_SERVICE_NAME
Reference< XController > xController