LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/dialogs - res_LegendPosition.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 120 0.0 %
Date: 2012-12-17 Functions: 0 15 0.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 "res_LegendPosition.hxx"
      22             : #include "ResourceIds.hrc"
      23             : #include "Strings.hrc"
      24             : #include "res_LegendPosition_IDs.hrc"
      25             : #include "ResId.hxx"
      26             : #include "ChartModelHelper.hxx"
      27             : #include "macros.hxx"
      28             : #include "LegendHelper.hxx"
      29             : 
      30             : #include <svtools/controldims.hrc>
      31             : #include <com/sun/star/chart2/LegendPosition.hpp>
      32             : #include <com/sun/star/chart/ChartLegendExpansion.hpp>
      33             : 
      34             : //itemset stuff
      35             : #include "chartview/ChartSfxItemIds.hxx"
      36             : #include <svl/intitem.hxx>
      37             : #include <svl/eitem.hxx>
      38             : 
      39             : //.............................................................................
      40             : namespace chart
      41             : {
      42             : //.............................................................................
      43             : 
      44             : using namespace ::com::sun::star;
      45             : using namespace ::com::sun::star::chart2;
      46             : 
      47           0 : LegendPositionResources::LegendPositionResources( Window* pWindow )
      48             :     : m_xCC() //unused in this scenario
      49             :     , m_aCbxShow( pWindow ) //unused in this scenario
      50             :     , m_aRbtLeft( pWindow, SchResId(RBT_LEFT) )
      51             :     , m_aRbtRight( pWindow, SchResId(RBT_RIGHT) )
      52             :     , m_aRbtTop( pWindow, SchResId(RBT_TOP) )
      53           0 :     , m_aRbtBottom( pWindow, SchResId(RBT_BOTTOM) )
      54             : {
      55           0 :     m_aCbxShow.Check();//legend is assumed to be visible in this scenario
      56           0 :     impl_setRadioButtonToggleHdl();
      57           0 : }
      58             : 
      59           0 : LegendPositionResources::LegendPositionResources( Window* pWindow, const uno::Reference< uno::XComponentContext >& xCC )
      60             :     : m_xCC( xCC )
      61             :     , m_aCbxShow( pWindow, SchResId(CBX_SHOWLEGEND) )
      62             :     , m_aRbtLeft( pWindow, SchResId(RBT_LEFT) )
      63             :     , m_aRbtRight( pWindow, SchResId(RBT_RIGHT) )
      64             :     , m_aRbtTop( pWindow, SchResId(RBT_TOP) )
      65           0 :     , m_aRbtBottom( pWindow, SchResId(RBT_BOTTOM) )
      66             : {
      67           0 :     m_aCbxShow.SetToggleHdl( LINK( this, LegendPositionResources, PositionEnableHdl ) );
      68           0 :     impl_setRadioButtonToggleHdl();
      69           0 :     m_aCbxShow.SetAccessibleRelationMemberOf(&m_aCbxShow);
      70           0 :     m_aRbtLeft.SetAccessibleRelationMemberOf(&m_aCbxShow);
      71           0 :     m_aRbtRight.SetAccessibleRelationMemberOf(&m_aCbxShow);
      72           0 :     m_aRbtTop.SetAccessibleRelationMemberOf(&m_aCbxShow);
      73           0 :     m_aRbtBottom.SetAccessibleRelationMemberOf(&m_aCbxShow);
      74           0 : }
      75             : 
      76           0 : void LegendPositionResources::impl_setRadioButtonToggleHdl()
      77             : {
      78           0 :     m_aRbtLeft.SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) );
      79           0 :     m_aRbtTop.SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) );
      80           0 :     m_aRbtRight.SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) );
      81           0 :     m_aRbtBottom.SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) );
      82           0 : }
      83             : 
      84           0 : LegendPositionResources::~LegendPositionResources()
      85             : {
      86           0 : }
      87             : 
      88           0 : void LegendPositionResources::writeToResources( const uno::Reference< frame::XModel >& xChartModel )
      89             : {
      90             :     try
      91             :     {
      92           0 :         uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram( xChartModel );
      93           0 :         uno::Reference< beans::XPropertySet > xProp( xDiagram->getLegend(), uno::UNO_QUERY );
      94           0 :         if( xProp.is() )
      95             :         {
      96             :             //show
      97           0 :             sal_Bool bShowLegend = sal_False;
      98           0 :             xProp->getPropertyValue( "Show" ) >>= bShowLegend;
      99           0 :             m_aCbxShow.Check( bShowLegend );
     100           0 :             PositionEnableHdl(0);
     101             : 
     102             :             //position
     103             :             chart2::LegendPosition ePos;
     104           0 :             xProp->getPropertyValue( "AnchorPosition" )  >>= ePos;
     105           0 :             switch( ePos )
     106             :             {
     107             :                 case chart2::LegendPosition_LINE_START:
     108           0 :                     m_aRbtLeft.Check();
     109           0 :                     break;
     110             :                 case chart2::LegendPosition_LINE_END:
     111           0 :                     m_aRbtRight.Check();
     112           0 :                     break;
     113             :                 case chart2::LegendPosition_PAGE_START:
     114           0 :                     m_aRbtTop.Check();
     115           0 :                     break;
     116             :                 case chart2::LegendPosition_PAGE_END:
     117           0 :                     m_aRbtBottom.Check();
     118           0 :                     break;
     119             : 
     120             :                 case chart2::LegendPosition_CUSTOM:
     121             :                 default:
     122           0 :                     m_aRbtRight.Check();
     123           0 :                     break;
     124             :             }
     125           0 :         }
     126             :     }
     127           0 :     catch( const uno::Exception & ex )
     128             :     {
     129             :         ASSERT_EXCEPTION( ex );
     130             :     }
     131           0 : }
     132             : 
     133           0 : void LegendPositionResources::writeToModel( const ::com::sun::star::uno::Reference< frame::XModel >& xChartModel ) const
     134             : {
     135             :     try
     136             :     {
     137           0 :         sal_Bool bShowLegend = static_cast<sal_Bool>(m_aCbxShow.IsChecked());
     138           0 :         uno::Reference< beans::XPropertySet > xProp( LegendHelper::getLegend( xChartModel,m_xCC,bShowLegend ), uno::UNO_QUERY );
     139           0 :         if( xProp.is() )
     140             :         {
     141             :             //show
     142           0 :             xProp->setPropertyValue( "Show" , uno::makeAny( bShowLegend ));
     143             : 
     144             :             //position
     145             :             chart2::LegendPosition eNewPos;
     146           0 :             ::com::sun::star::chart::ChartLegendExpansion eExp = ::com::sun::star::chart::ChartLegendExpansion_HIGH;
     147             : 
     148           0 :             if( m_aRbtLeft.IsChecked() )
     149           0 :                 eNewPos = chart2::LegendPosition_LINE_START;
     150           0 :             else if( m_aRbtRight.IsChecked() )
     151             :             {
     152           0 :                 eNewPos = chart2::LegendPosition_LINE_END;
     153             :             }
     154           0 :             else if( m_aRbtTop.IsChecked() )
     155             :             {
     156           0 :                 eNewPos = chart2::LegendPosition_PAGE_START;
     157           0 :                 eExp = ::com::sun::star::chart::ChartLegendExpansion_WIDE;
     158             :             }
     159           0 :             else if( m_aRbtBottom.IsChecked() )
     160             :             {
     161           0 :                 eNewPos = chart2::LegendPosition_PAGE_END;
     162           0 :                 eExp = ::com::sun::star::chart::ChartLegendExpansion_WIDE;
     163             :             }
     164             : 
     165           0 :             xProp->setPropertyValue( "AnchorPosition" , uno::makeAny( eNewPos ));
     166           0 :             xProp->setPropertyValue( "Expansion" , uno::makeAny( eExp ));
     167           0 :             xProp->setPropertyValue( "RelativePosition" , uno::Any());
     168           0 :         }
     169             :     }
     170           0 :     catch( const uno::Exception & ex )
     171             :     {
     172             :         ASSERT_EXCEPTION( ex );
     173             :     }
     174           0 : }
     175             : 
     176           0 : IMPL_LINK_NOARG(LegendPositionResources, PositionEnableHdl)
     177             : {
     178           0 :     sal_Bool bEnable = m_aCbxShow.IsChecked();
     179             : 
     180           0 :     m_aRbtLeft.Enable( bEnable );
     181           0 :     m_aRbtTop.Enable( bEnable );
     182           0 :     m_aRbtRight.Enable( bEnable );
     183           0 :     m_aRbtBottom.Enable( bEnable );
     184             : 
     185           0 :     m_aChangeLink.Call(NULL);
     186             : 
     187           0 :     return 0;
     188             : }
     189             : 
     190           0 : void LegendPositionResources::initFromItemSet( const SfxItemSet& rInAttrs )
     191             : {
     192           0 :     const SfxPoolItem* pPoolItem = NULL;
     193           0 :     if( rInAttrs.GetItemState( SCHATTR_LEGEND_POS, sal_True, &pPoolItem ) == SFX_ITEM_SET )
     194             :     {
     195           0 :         sal_Int32 nLegendPosition = ((const SfxInt32Item*)pPoolItem)->GetValue();
     196           0 :         switch( nLegendPosition )
     197             :         {
     198             :             case chart2::LegendPosition_LINE_START:
     199           0 :                 m_aRbtLeft.Check(sal_True);
     200           0 :                 break;
     201             :             case chart2::LegendPosition_PAGE_START:
     202           0 :                 m_aRbtTop.Check(sal_True);
     203           0 :                 break;
     204             :             case chart2::LegendPosition_LINE_END:
     205           0 :                 m_aRbtRight.Check(sal_True);
     206           0 :                 break;
     207             :             case chart2::LegendPosition_PAGE_END:
     208           0 :                 m_aRbtBottom.Check(sal_True);
     209           0 :                 break;
     210             :             default:
     211           0 :                 break;
     212             :         }
     213             :     }
     214             : 
     215           0 :     if( rInAttrs.GetItemState( SCHATTR_LEGEND_SHOW, sal_True, &pPoolItem ) == SFX_ITEM_SET )
     216             :     {
     217           0 :         bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
     218           0 :         m_aCbxShow.Check(bShow);
     219             :     }
     220           0 : }
     221             : 
     222           0 : void LegendPositionResources::writeToItemSet( SfxItemSet& rOutAttrs ) const
     223             : {
     224           0 :     sal_Int32 nLegendPosition = chart2::LegendPosition_CUSTOM;
     225           0 :     if( m_aRbtLeft.IsChecked() )
     226           0 :         nLegendPosition = chart2::LegendPosition_LINE_START;
     227           0 :     else if( m_aRbtTop.IsChecked() )
     228           0 :         nLegendPosition = chart2::LegendPosition_PAGE_START;
     229           0 :     else if( m_aRbtRight.IsChecked() )
     230           0 :         nLegendPosition = chart2::LegendPosition_LINE_END;
     231           0 :     else if( m_aRbtBottom.IsChecked() )
     232           0 :         nLegendPosition = chart2::LegendPosition_PAGE_END;
     233           0 :     rOutAttrs.Put(SfxInt32Item(SCHATTR_LEGEND_POS, nLegendPosition ));
     234             : 
     235           0 :     rOutAttrs.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, m_aCbxShow.IsChecked()) );
     236           0 : }
     237             : 
     238           0 : IMPL_LINK( LegendPositionResources, PositionChangeHdl, RadioButton*, pRadio )
     239             : {
     240             :     //for each radio click ther are coming two change events
     241             :     //first uncheck of previous button -> ignore that call
     242             :     //the second call gives the check of the new button
     243           0 :     if( pRadio && pRadio->IsChecked() )
     244           0 :         m_aChangeLink.Call(NULL);
     245           0 :     return 0;
     246             : }
     247             : 
     248           0 : void LegendPositionResources::SetChangeHdl( const Link& rLink )
     249             : {
     250           0 :     m_aChangeLink = rLink;
     251           0 : }
     252             : 
     253           0 : void LegendPositionResources::SetAccessibleRelationMemberOf(Window* pMemberOf)
     254             : {
     255           0 :     m_aRbtLeft.SetAccessibleRelationMemberOf(pMemberOf);
     256           0 :     m_aRbtRight.SetAccessibleRelationMemberOf(pMemberOf);
     257           0 :     m_aRbtTop.SetAccessibleRelationMemberOf(pMemberOf);
     258           0 :     m_aRbtBottom.SetAccessibleRelationMemberOf(pMemberOf);
     259           0 : }
     260             : 
     261             : //.............................................................................
     262             : } //namespace chart
     263             : //.............................................................................
     264             : 
     265             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10