LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/dialogs - tp_3D_SceneAppearance.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 152 0.0 %
Date: 2012-12-27 Functions: 0 18 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 "tp_3D_SceneAppearance.hxx"
      22             : #include "tp_3D_SceneAppearance.hrc"
      23             : #include "ResId.hxx"
      24             : #include "Strings.hrc"
      25             : #include "NoWarningThisInCTOR.hxx"
      26             : #include "ChartModelHelper.hxx"
      27             : #include "ThreeDHelper.hxx"
      28             : #include "macros.hxx"
      29             : #include <rtl/math.hxx>
      30             : #include <com/sun/star/beans/XPropertySet.hpp>
      31             : 
      32             : using namespace ::com::sun::star;
      33             : 
      34             : namespace
      35             : {
      36             : 
      37             : struct lcl_ModelProperties
      38             : {
      39             :     drawing::ShadeMode        m_aShadeMode;
      40             :     sal_Int32                 m_nRoundedEdges;
      41             :     sal_Int32                 m_nObjectLines;
      42             :     ::chart::ThreeDLookScheme m_eScheme;
      43             : 
      44           0 :     lcl_ModelProperties() :
      45             :             m_nRoundedEdges(-1),
      46             :             m_nObjectLines(-1),
      47           0 :             m_eScheme(::chart::ThreeDLookScheme_Unknown)
      48           0 :     {}
      49             : };
      50             : 
      51           0 : lcl_ModelProperties lcl_getPropertiesFromModel( uno::Reference< frame::XModel > & xModel )
      52             : {
      53           0 :     lcl_ModelProperties aProps;
      54             :     try
      55             :     {
      56           0 :         uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) );
      57           0 :         uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY_THROW );
      58           0 :         xDiaProp->getPropertyValue( "D3DSceneShadeMode" ) >>= aProps.m_aShadeMode;
      59           0 :         ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram, aProps.m_nRoundedEdges, aProps.m_nObjectLines );
      60           0 :         aProps.m_eScheme = ::chart::ThreeDHelper::detectScheme( xDiagram );
      61             :     }
      62           0 :     catch( const uno::Exception & ex )
      63             :     {
      64             :         ASSERT_EXCEPTION( ex );
      65             :     }
      66           0 :     return aProps;
      67             : }
      68             : 
      69           0 : void lcl_setShadeModeAtModel( uno::Reference< frame::XModel > & xModel, drawing::ShadeMode aShadeMode )
      70             : {
      71             :     try
      72             :     {
      73             :         uno::Reference< beans::XPropertySet > xDiaProp(
      74           0 :             ::chart::ChartModelHelper::findDiagram( xModel ), uno::UNO_QUERY_THROW );
      75           0 :         xDiaProp->setPropertyValue( "D3DSceneShadeMode" , uno::makeAny( aShadeMode ));
      76             :     }
      77           0 :     catch( const uno::Exception & ex )
      78             :     {
      79             :         ASSERT_EXCEPTION( ex );
      80             :     }
      81           0 : }
      82             : 
      83             : } // anonymous namespace
      84             : 
      85             : //.............................................................................
      86             : namespace chart
      87             : {
      88             : //.............................................................................
      89             : 
      90             : #define POS_3DSCHEME_SIMPLE    0
      91             : #define POS_3DSCHEME_REALISTIC 1
      92             : #define POS_3DSCHEME_CUSTOM 2
      93             : 
      94           0 : ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage(
      95             :       Window* pWindow
      96             :     , const uno::Reference< frame::XModel > & xChartModel
      97             :     , ControllerLockHelper & rControllerLockHelper )
      98             :                 : TabPage           ( pWindow, SchResId( TP_3D_SCENEAPPEARANCE ) )
      99             :                 , m_xChartModel     ( xChartModel )
     100             :                 , m_aFT_Scheme      ( this, SchResId( FT_SCHEME ) )
     101             :                 , m_aLB_Scheme      ( this, SchResId( LB_SCHEME ) )
     102             :                 , m_aFL_Seperator   ( this, SchResId( FL_SEPERATOR ) )
     103             :                 , m_aCB_Shading     ( this, SchResId( CB_SHADING ) )
     104             :                 , m_aCB_ObjectLines ( this, SchResId( CB_OBJECTLINES ) )
     105             :                 , m_aCB_RoundedEdge ( this, SchResId( CB_ROUNDEDEDGE ) )
     106             :                 , m_bUpdateOtherControls( true )
     107             :                 , m_bCommitToModel( true )
     108           0 :                 , m_rControllerLockHelper( rControllerLockHelper )
     109             : {
     110           0 :     FreeResource();
     111           0 :     m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_SIMPLE)),POS_3DSCHEME_SIMPLE);
     112           0 :     m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_REALISTIC)),POS_3DSCHEME_REALISTIC);
     113           0 :     m_aLB_Scheme.SetDropDownLineCount(2);
     114             : 
     115           0 :     m_aLB_Scheme.SetSelectHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectSchemeHdl ) );
     116             : 
     117           0 :     m_aCB_RoundedEdge.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
     118           0 :     m_aCB_Shading.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectShading ) );
     119           0 :     m_aCB_ObjectLines.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
     120             : 
     121           0 :     m_aCB_RoundedEdge.EnableTriState( sal_True );
     122           0 :     m_aCB_Shading.EnableTriState( sal_True );
     123           0 :     m_aCB_ObjectLines.EnableTriState( sal_True );
     124             : 
     125           0 :     initControlsFromModel();
     126           0 : }
     127             : 
     128           0 : ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
     129           0 : {}
     130             : 
     131           0 : void ThreeD_SceneAppearance_TabPage::ActivatePage()
     132             : {
     133           0 :     updateScheme();
     134           0 : }
     135             : 
     136           0 : void ThreeD_SceneAppearance_TabPage::commitPendingChanges()
     137             : {
     138           0 : }
     139             : 
     140           0 : void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
     141             : {
     142           0 :     if(!m_bCommitToModel)
     143           0 :         return;
     144             : 
     145           0 :     sal_Int32 nObjectLines = -1;
     146             : 
     147           0 :     switch( m_aCB_ObjectLines.GetState())
     148             :     {
     149             :         case STATE_NOCHECK:
     150           0 :             nObjectLines = 0;
     151           0 :             break;
     152             :         case STATE_CHECK:
     153           0 :             nObjectLines = 1;
     154           0 :             break;
     155             :         case STATE_DONTKNOW:
     156           0 :             nObjectLines = -1;
     157           0 :             break;
     158             :     }
     159             : 
     160           0 :     sal_Int32 nCurrentRoundedEdges = -1;
     161           0 :     switch( m_aCB_RoundedEdge.GetState() )
     162             :     {
     163             :         case STATE_NOCHECK:
     164           0 :             nCurrentRoundedEdges = 0;
     165           0 :             break;
     166             :         case STATE_CHECK:
     167           0 :             nCurrentRoundedEdges = 5;
     168           0 :             break;
     169             :         case STATE_DONTKNOW:
     170           0 :             nCurrentRoundedEdges = -1;
     171           0 :             break;
     172             :     }
     173             : 
     174             :     // locked controllers
     175           0 :     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     176             :     ThreeDHelper::setRoundedEdgesAndObjectLines(
     177           0 :         ::chart::ChartModelHelper::findDiagram( m_xChartModel ), nCurrentRoundedEdges, nObjectLines );
     178             : }
     179             : 
     180           0 : void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
     181             : {
     182           0 :     if(!m_bCommitToModel)
     183           0 :         return;
     184             : 
     185           0 :     drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG;
     186             : 
     187           0 :     switch( m_aCB_Shading.GetState())
     188             :     {
     189             :         case STATE_NOCHECK:
     190           0 :             aShadeMode = drawing::ShadeMode_FLAT;
     191           0 :             break;
     192             :         case STATE_CHECK:
     193           0 :             aShadeMode = drawing::ShadeMode_SMOOTH;
     194           0 :             break;
     195             :         case STATE_DONTKNOW:
     196             :             // nothing
     197           0 :             break;
     198             :     }
     199             : 
     200           0 :     lcl_setShadeModeAtModel( m_xChartModel, aShadeMode );
     201             : }
     202             : 
     203           0 : void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
     204             : {
     205           0 :     m_bCommitToModel = false;
     206           0 :     m_bUpdateOtherControls = false;
     207             : 
     208           0 :     lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
     209             : 
     210           0 :     if(aProps.m_aShadeMode == drawing::ShadeMode_FLAT)
     211             :     {
     212           0 :         m_aCB_Shading.EnableTriState( sal_False );
     213           0 :         m_aCB_Shading.Check(sal_False);
     214             :     }
     215           0 :     else if(aProps.m_aShadeMode == drawing::ShadeMode_SMOOTH)
     216             :     {
     217           0 :         m_aCB_Shading.EnableTriState( sal_False );
     218           0 :         m_aCB_Shading.Check(sal_True);
     219             :     }
     220             :     else
     221             :     {
     222           0 :         m_aCB_Shading.EnableTriState( sal_True );
     223           0 :         m_aCB_Shading.SetState( STATE_DONTKNOW );
     224             :     }
     225             : 
     226           0 :     if(aProps.m_nObjectLines == 0)
     227             :     {
     228           0 :         m_aCB_ObjectLines.EnableTriState( sal_False );
     229           0 :         m_aCB_ObjectLines.Check(sal_False);
     230             :     }
     231           0 :     else if(aProps.m_nObjectLines==1)
     232             :     {
     233           0 :         m_aCB_ObjectLines.EnableTriState( sal_False );
     234           0 :         m_aCB_ObjectLines.Check(sal_True);
     235             :     }
     236             :     else
     237             :     {
     238           0 :         m_aCB_ObjectLines.EnableTriState( sal_True );
     239           0 :         m_aCB_ObjectLines.SetState( STATE_DONTKNOW );
     240             :     }
     241             : 
     242           0 :     if(aProps.m_nRoundedEdges >= 5)
     243             :     {
     244           0 :         m_aCB_RoundedEdge.EnableTriState( sal_False );
     245           0 :         m_aCB_RoundedEdge.Check(sal_True);
     246             :     }
     247           0 :     else if(aProps.m_nRoundedEdges<0)
     248             :     {
     249           0 :         m_aCB_RoundedEdge.EnableTriState( sal_False );
     250           0 :         m_aCB_RoundedEdge.SetState( STATE_DONTKNOW );
     251             :     }
     252             :     else
     253             :     {
     254           0 :         m_aCB_RoundedEdge.EnableTriState( sal_True );
     255           0 :         m_aCB_RoundedEdge.Check(sal_False);
     256             :     }
     257           0 :     m_aCB_RoundedEdge.Enable( !m_aCB_ObjectLines.IsChecked() );
     258             : 
     259           0 :     updateScheme();
     260             : 
     261           0 :     m_bCommitToModel = true;
     262           0 :     m_bUpdateOtherControls = true;
     263           0 : }
     264             : 
     265           0 : void ThreeD_SceneAppearance_TabPage::updateScheme()
     266             : {
     267           0 :     lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
     268             : 
     269           0 :     if( m_aLB_Scheme.GetEntryCount() == (POS_3DSCHEME_CUSTOM+1) )
     270             :     {
     271           0 :         m_aLB_Scheme.RemoveEntry(POS_3DSCHEME_CUSTOM);
     272           0 :         m_aLB_Scheme.SetDropDownLineCount(2);
     273             :     }
     274           0 :     switch( aProps.m_eScheme )
     275             :     {
     276             :         case ThreeDLookScheme_Simple:
     277           0 :             m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_SIMPLE );
     278           0 :             break;
     279             :         case ThreeDLookScheme_Realistic:
     280           0 :             m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_REALISTIC );
     281           0 :             break;
     282             :         case ThreeDLookScheme_Unknown:
     283             :             {
     284           0 :                 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_CUSTOM)),POS_3DSCHEME_CUSTOM);
     285           0 :                 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_CUSTOM );
     286           0 :                 m_aLB_Scheme.SetDropDownLineCount(3);
     287             :             }
     288           0 :             break;
     289             :     }
     290           0 : }
     291             : 
     292           0 : IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectSchemeHdl)
     293             : {
     294           0 :     if( !m_bUpdateOtherControls )
     295           0 :         return 0;
     296             : 
     297             :     {
     298             :         // locked controllers
     299           0 :         ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     300             : 
     301           0 :         uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( m_xChartModel ) );
     302             : 
     303           0 :         if( m_aLB_Scheme.GetSelectEntryPos() == POS_3DSCHEME_REALISTIC )
     304           0 :             ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Realistic );
     305           0 :         else if( m_aLB_Scheme.GetSelectEntryPos() == POS_3DSCHEME_SIMPLE )
     306           0 :             ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Simple );
     307             :         else
     308             :         {
     309             :             OSL_FAIL( "Invalid Entry selected" );
     310           0 :         }
     311             :     }
     312             : 
     313             :     // update other controls
     314           0 :     initControlsFromModel();
     315           0 :     return 0;
     316             : }
     317             : 
     318           0 : IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectShading)
     319             : {
     320           0 :     if( !m_bUpdateOtherControls )
     321           0 :         return 0;
     322             : 
     323           0 :     m_aCB_Shading.EnableTriState( sal_False );
     324           0 :     applyShadeModeToModel();
     325           0 :     updateScheme();
     326           0 :     return 0;
     327             : }
     328           0 : IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, CheckBox*, pCheckBox )
     329             : {
     330           0 :     if( !m_bUpdateOtherControls )
     331           0 :         return 0;
     332             : 
     333           0 :     if( pCheckBox == &m_aCB_ObjectLines )
     334             :     {
     335           0 :         m_aCB_ObjectLines.EnableTriState( sal_False );
     336           0 :         m_bUpdateOtherControls = false;
     337           0 :         m_aCB_RoundedEdge.Enable( !m_aCB_ObjectLines.IsChecked() );
     338           0 :         if(!m_aCB_RoundedEdge.IsEnabled())
     339           0 :             m_aCB_RoundedEdge.Check(sal_False);
     340           0 :         m_bUpdateOtherControls = true;
     341             :     }
     342             :     else
     343           0 :         m_aCB_RoundedEdge.EnableTriState( sal_False );
     344           0 :     applyRoundedEdgeAndObjectLinesToModel();
     345           0 :     updateScheme();
     346           0 :     return 0;
     347             : }
     348             : 
     349             : //.............................................................................
     350             : } //namespace chart
     351             : //.............................................................................
     352             : 
     353             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10