1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
/* -*- 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 <ChartModelHelper.hxx>
#include <LegendHelper.hxx>
#include <CommonConverters.hxx>
#include <servicenames.hxx>
#include <ObjectIdentifier.hxx>
#include <chartview/ExplicitValueProvider.hxx>
#include <chartview/DrawModelWrapper.hxx>
#include <AxisHelper.hxx>
#include <DiagramHelper.hxx>
#include <ChartModel.hxx>
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 ),
mpModel( nullptr )
{
}
Chart2ModelContact::~Chart2ModelContact()
{
clear();
}
void Chart2ModelContact::setModel( const css::uno::Reference< css::frame::XModel >& xChartModel )
{
clear();
m_xChartModel = xChartModel;
mpModel = dynamic_cast<ChartModel*>(xChartModel.get());
uno::Reference< lang::XMultiServiceFactory > xTableFactory( xChartModel, uno::UNO_QUERY );
if( !xTableFactory.is() )
return;
uno::Reference< container::XNameContainer > xDashTable( xTableFactory->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY );
uno::Reference< container::XNameContainer > xGradientTable( xTableFactory->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
uno::Reference< container::XNameContainer > xHatchTable( xTableFactory->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY );
uno::Reference< container::XNameContainer > xBitmapTable( xTableFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
uno::Reference< container::XNameContainer > xTransparencyGradientTable( xTableFactory->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();
mpModel = nullptr;
}
Reference< frame::XModel > Chart2ModelContact::getChartModel() const
{
return Reference< frame::XModel >( m_xChartModel.get(), uno::UNO_QUERY );
}
Reference< chart2::XChartDocument > Chart2ModelContact::getChart2Document() const
{
return Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY );
}
Reference< chart2::XDiagram > Chart2ModelContact::getChart2Diagram() const
{
return ChartModelHelper::findDiagram( getChartModel() );
}
uno::Reference< lang::XUnoTunnel > const & Chart2ModelContact::getChartView() const
{
if(!m_xChartView.is())
{
// get the chart view
Reference<frame::XModel> xModel(m_xChartModel);
uno::Reference< lang::XMultiServiceFactory > xFact( xModel, uno::UNO_QUERY );
if( xFact.is() )
m_xChartView.set( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
}
return m_xChartView;
}
ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const
{
getChartView();
if(!m_xChartView.is())
return nullptr;
//obtain the ExplicitValueProvider from the chart view
ExplicitValueProvider* pProvider = reinterpret_cast<ExplicitValueProvider*>(m_xChartView->getSomething(
ExplicitValueProvider::getUnoTunnelId() ));
return pProvider;
}
uno::Reference< drawing::XDrawPage > Chart2ModelContact::getDrawPage() const
{
uno::Reference< drawing::XDrawPage > xResult;
ExplicitValueProvider* pProvider( getExplicitValueProvider() );
if( pProvider )
{
xResult.set( 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 )
{
Reference< chart2::XCoordinateSystem > xCooSys(
AxisHelper::getCoordinateSystemOfAxis(
xAxis, ChartModelHelper::findDiagram( m_xChartModel ) ) );
return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys
, getChart2Document());
}
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);
}
awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect )
{
awt::Rectangle aRect = ExplicitValueProvider::AddSubtractAxisTitleSizes(
*mpModel, getChartView(), rPositionRect, true );
return aRect;
}
awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingTitle() const
{
awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() );
//add axis title sizes to the diagram size
aRect = ExplicitValueProvider::AddSubtractAxisTitleSizes(
*mpModel, getChartView(), aRect, false );
return aRect;
}
awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const
{
awt::Rectangle aRect(0,0,0,0);
uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
if( DiagramHelper::getDiagramPositioningMode( xDiagram ) == DiagramPositioningMode_INCLUDING )
aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
else
{
ExplicitValueProvider* pProvider( getExplicitValueProvider() );
if( pProvider )
aRect = pProvider->getRectangleOfObject("PlotAreaIncludingAxes");
}
return aRect;
}
awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const
{
awt::Rectangle aRect(0,0,0,0);
uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
if( DiagramHelper::getDiagramPositioningMode( xDiagram ) == DiagramPositioningMode_EXCLUDING )
aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
else
{
ExplicitValueProvider* pProvider( getExplicitValueProvider() );
if( pProvider )
aRect = pProvider->getDiagramRectangleExcludingAxes();
}
return aRect;
}
awt::Size Chart2ModelContact::GetLegendSize() const
{
awt::Size aSize;
ExplicitValueProvider* pProvider( getExplicitValueProvider() );
if( pProvider )
{
uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *mpModel ) );
OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, *mpModel ) );
aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
}
return aSize;
}
awt::Point Chart2ModelContact::GetLegendPosition() const
{
awt::Point aPoint;
ExplicitValueProvider* pProvider( getExplicitValueProvider() );
if( pProvider )
{
uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *mpModel ) );
OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, *mpModel ) );
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 ) );
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 ) );
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 ) );
aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
}
return aPoint;
}
} // namespace chart::wrapper
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|