LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/chartapiwrapper - Chart2ModelContact.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 61 134 45.5 %
Date: 2012-12-27 Functions: 13 25 52.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10