From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../chartapiwrapper/Chart2ModelContact.cxx | 302 +++++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 chart2/source/controller/chartapiwrapper/Chart2ModelContact.cxx (limited to 'chart2/source/controller/chartapiwrapper/Chart2ModelContact.cxx') diff --git a/chart2/source/controller/chartapiwrapper/Chart2ModelContact.cxx b/chart2/source/controller/chartapiwrapper/Chart2ModelContact.cxx new file mode 100644 index 000000000..e65d78915 --- /dev/null +++ b/chart2/source/controller/chartapiwrapper/Chart2ModelContact.cxx @@ -0,0 +1,302 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "Chart2ModelContact.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; + +using ::com::sun::star::uno::Reference; + +namespace chart::wrapper +{ + +Chart2ModelContact::Chart2ModelContact( + const Reference< uno::XComponentContext > & xContext ) : + m_xContext( xContext ), + m_xChartModel( nullptr ) +{ +} + +Chart2ModelContact::~Chart2ModelContact() +{ + clear(); +} + +void Chart2ModelContact::setDocumentModel( ChartModel* pChartModel ) +{ + clear(); + m_xChartModel = pChartModel; + if( !pChartModel ) + return; + + uno::Reference< container::XNameContainer > xDashTable( pChartModel->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY ); + uno::Reference< container::XNameContainer > xGradientTable( pChartModel->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY ); + uno::Reference< container::XNameContainer > xHatchTable( pChartModel->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY ); + uno::Reference< container::XNameContainer > xBitmapTable( pChartModel->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY ); + uno::Reference< container::XNameContainer > xTransparencyGradientTable( pChartModel->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY ); + m_aTableMap["LineDashName"] = xDashTable; + m_aTableMap["FillGradientName"] = xGradientTable; + m_aTableMap["FillHatchName"] = xHatchTable; + m_aTableMap["FillBitmapName"] = xBitmapTable; + m_aTableMap["FillTransparenceGradientName"] = xTransparencyGradientTable; +} + +void Chart2ModelContact::clear() +{ + m_xChartModel.clear(); + m_xChartView.clear(); +} + +rtl::Reference< ChartModel > Chart2ModelContact::getDocumentModel() const +{ + return m_xChartModel; +} + +rtl::Reference< ::chart::Diagram > Chart2ModelContact::getDiagram() const +{ + try + { + rtl::Reference xChartModel = getDocumentModel(); + if( xChartModel) + return xChartModel->getFirstChartDiagram(); + } + catch( const uno::Exception & ) + { + DBG_UNHANDLED_EXCEPTION("chart2"); + } + return nullptr; +} + +rtl::Reference< ::chart::ChartView > const & Chart2ModelContact::getChartView() const +{ + if(!m_xChartView.is()) + { + // get the chart view + rtl::Reference xChartModel( m_xChartModel ); + if( xChartModel ) + { + auto xInstance = xChartModel->createInstance( CHART_VIEW_SERVICE_NAME ); + auto pChartView = dynamic_cast(xInstance.get()); + assert(!xInstance || pChartView); + m_xChartView = pChartView; + } + } + return m_xChartView; +} + +ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const +{ + getChartView(); + + //obtain the ExplicitValueProvider from the chart view + return m_xChartView.get(); +} + +rtl::Reference Chart2ModelContact::getDrawPage() const +{ + rtl::Reference xResult; + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider ) + { + xResult = pProvider->getDrawModelWrapper()->getMainDrawPage(); + } + return xResult; +} + +void Chart2ModelContact::getExplicitValuesForAxis( + const Reference< XAxis > & xAxis, + ExplicitScaleData & rOutExplicitScale, + ExplicitIncrementData & rOutExplicitIncrement ) +{ + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider ) + { + pProvider->getExplicitValuesForAxis( + xAxis, rOutExplicitScale, rOutExplicitIncrement ); + } +} + +sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForAxis( + const Reference< chart2::XAxis >& xAxis ) +{ + rtl::Reference< BaseCoordinateSystem > xCooSys( + AxisHelper::getCoordinateSystemOfAxis( + xAxis, ChartModelHelper::findDiagram( m_xChartModel ) ) ); + + return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys + , m_xChartModel.get() ); +} + +sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForSeries( + const Reference< chart2::XDataSeries >& xSeries ) +{ + return ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( + uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY )); +} + +awt::Size Chart2ModelContact::GetPageSize() const +{ + return ChartModelHelper::getPageSize(m_xChartModel.get()); +} + +awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect ) +{ + awt::Rectangle aRect = ExplicitValueProvider::AddSubtractAxisTitleSizes( + *m_xChartModel.get(), getChartView().get(), rPositionRect, true ); + return aRect; +} + +awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingTitle() const +{ + awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() ); + + //add axis title sizes to the diagram size + aRect = ExplicitValueProvider::AddSubtractAxisTitleSizes( + *m_xChartModel.get(), getChartView().get(), aRect, false ); + + return aRect; +} + +awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const +{ + awt::Rectangle aRect(0,0,0,0); + rtl::Reference< Diagram > xDiagram = ChartModelHelper::findDiagram( m_xChartModel ); + + if( DiagramHelper::getDiagramPositioningMode( xDiagram ) == DiagramPositioningMode_INCLUDING ) + aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel.get()); + else + { + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider ) + aRect = pProvider->getRectangleOfObject("PlotAreaIncludingAxes"); + } + return aRect; +} + +awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const +{ + awt::Rectangle aRect(0,0,0,0); + rtl::Reference< Diagram > xDiagram = ChartModelHelper::findDiagram( m_xChartModel ); + + if( DiagramHelper::getDiagramPositioningMode( xDiagram ) == DiagramPositioningMode_EXCLUDING ) + aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel.get()); + else + { + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider ) + aRect = pProvider->getDiagramRectangleExcludingAxes(); + } + return aRect; +} + +awt::Size Chart2ModelContact::GetLegendSize() const +{ + awt::Size aSize; + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider ) + { + rtl::Reference< Legend > xLegend = LegendHelper::getLegend( *m_xChartModel.get() ); + OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, m_xChartModel ) ); + aSize = ToSize( pProvider->getRectangleOfObject( aCID ) ); + } + return aSize; +} + +awt::Point Chart2ModelContact::GetLegendPosition() const +{ + awt::Point aPoint; + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider ) + { + rtl::Reference< Legend > xLegend = LegendHelper::getLegend( *m_xChartModel.get() ); + OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, m_xChartModel ) ); + aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) ); + } + return aPoint; +} + +awt::Size Chart2ModelContact::GetTitleSize( const uno::Reference< css::chart2::XTitle > & xTitle ) const +{ + awt::Size aSize; + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider && xTitle.is() ) + { + OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) ); + aSize = ToSize( pProvider->getRectangleOfObject( aCID ) ); + } + return aSize; +} + +awt::Point Chart2ModelContact::GetTitlePosition( const uno::Reference< css::chart2::XTitle > & xTitle ) const +{ + awt::Point aPoint; + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider && xTitle.is() ) + { + OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel.get() ) ); + aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) ); + } + return aPoint; +} + +awt::Size Chart2ModelContact::GetAxisSize( const uno::Reference< css::chart2::XAxis > & xAxis ) const +{ + awt::Size aSize; + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider && xAxis.is() ) + { + OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel.get() ) ); + aSize = ToSize( pProvider->getRectangleOfObject( aCID ) ); + } + return aSize; +} + +awt::Point Chart2ModelContact::GetAxisPosition( const uno::Reference< css::chart2::XAxis > & xAxis ) const +{ + awt::Point aPoint; + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider && xAxis.is() ) + { + OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel.get() ) ); + aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) ); + } + return aPoint; +} + +} // namespace chart::wrapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3