1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_chart2.hxx" 30 31 #include "tp_3D_SceneAppearance.hxx" 32 #include "tp_3D_SceneAppearance.hrc" 33 #include "ResId.hxx" 34 #include "Strings.hrc" 35 #include "NoWarningThisInCTOR.hxx" 36 #include "ChartModelHelper.hxx" 37 #include "ThreeDHelper.hxx" 38 #include "macros.hxx" 39 #include <rtl/math.hxx> 40 #include <com/sun/star/beans/XPropertySet.hpp> 41 42 using namespace ::com::sun::star; 43 44 namespace 45 { 46 47 struct lcl_ModelProperties 48 { 49 drawing::ShadeMode m_aShadeMode; 50 sal_Int32 m_nRoundedEdges; 51 sal_Int32 m_nObjectLines; 52 ::chart::ThreeDLookScheme m_eScheme; 53 54 lcl_ModelProperties() : 55 m_nRoundedEdges(-1), 56 m_nObjectLines(-1), 57 m_eScheme(::chart::ThreeDLookScheme_Unknown) 58 {} 59 }; 60 61 lcl_ModelProperties lcl_getPropertiesFromModel( uno::Reference< frame::XModel > & xModel ) 62 { 63 lcl_ModelProperties aProps; 64 try 65 { 66 uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) ); 67 uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY_THROW ); 68 xDiaProp->getPropertyValue( C2U("D3DSceneShadeMode")) >>= aProps.m_aShadeMode; 69 ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram, aProps.m_nRoundedEdges, aProps.m_nObjectLines ); 70 aProps.m_eScheme = ::chart::ThreeDHelper::detectScheme( xDiagram ); 71 } 72 catch( const uno::Exception & ex ) 73 { 74 ASSERT_EXCEPTION( ex ); 75 } 76 return aProps; 77 } 78 79 void lcl_setShadeModeAtModel( uno::Reference< frame::XModel > & xModel, drawing::ShadeMode aShadeMode ) 80 { 81 try 82 { 83 uno::Reference< beans::XPropertySet > xDiaProp( 84 ::chart::ChartModelHelper::findDiagram( xModel ), uno::UNO_QUERY_THROW ); 85 xDiaProp->setPropertyValue( C2U("D3DSceneShadeMode"), uno::makeAny( aShadeMode )); 86 } 87 catch( const uno::Exception & ex ) 88 { 89 ASSERT_EXCEPTION( ex ); 90 } 91 } 92 93 } // anonymous namespace 94 95 //............................................................................. 96 namespace chart 97 { 98 //............................................................................. 99 100 #define POS_3DSCHEME_SIMPLE 0 101 #define POS_3DSCHEME_REALISTIC 1 102 #define POS_3DSCHEME_CUSTOM 2 103 104 ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage( 105 Window* pWindow 106 , const uno::Reference< frame::XModel > & xChartModel 107 , ControllerLockHelper & rControllerLockHelper ) 108 : TabPage ( pWindow, SchResId( TP_3D_SCENEAPPEARANCE ) ) 109 , m_xChartModel ( xChartModel ) 110 , m_aFT_Scheme ( this, SchResId( FT_SCHEME ) ) 111 , m_aLB_Scheme ( this, SchResId( LB_SCHEME ) ) 112 , m_aFL_Seperator ( this, SchResId( FL_SEPERATOR ) ) 113 , m_aCB_Shading ( this, SchResId( CB_SHADING ) ) 114 , m_aCB_ObjectLines ( this, SchResId( CB_OBJECTLINES ) ) 115 , m_aCB_RoundedEdge ( this, SchResId( CB_ROUNDEDEDGE ) ) 116 , m_bUpdateOtherControls( true ) 117 , m_bCommitToModel( true ) 118 , m_rControllerLockHelper( rControllerLockHelper ) 119 { 120 FreeResource(); 121 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_SIMPLE)),POS_3DSCHEME_SIMPLE); 122 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_REALISTIC)),POS_3DSCHEME_REALISTIC); 123 m_aLB_Scheme.SetDropDownLineCount(2); 124 125 m_aLB_Scheme.SetSelectHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectSchemeHdl ) ); 126 127 m_aCB_RoundedEdge.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) ); 128 m_aCB_Shading.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectShading ) ); 129 m_aCB_ObjectLines.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) ); 130 131 m_aCB_RoundedEdge.EnableTriState( sal_True ); 132 m_aCB_Shading.EnableTriState( sal_True ); 133 m_aCB_ObjectLines.EnableTriState( sal_True ); 134 135 initControlsFromModel(); 136 } 137 138 ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage() 139 {} 140 141 void ThreeD_SceneAppearance_TabPage::ActivatePage() 142 { 143 updateScheme(); 144 } 145 146 void ThreeD_SceneAppearance_TabPage::commitPendingChanges() 147 { 148 } 149 150 void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel() 151 { 152 if(!m_bCommitToModel) 153 return; 154 155 sal_Int32 nObjectLines = -1; 156 157 switch( m_aCB_ObjectLines.GetState()) 158 { 159 case STATE_NOCHECK: 160 nObjectLines = 0; 161 break; 162 case STATE_CHECK: 163 nObjectLines = 1; 164 break; 165 case STATE_DONTKNOW: 166 nObjectLines = -1; 167 break; 168 } 169 170 sal_Int32 nCurrentRoundedEdges = -1; 171 switch( m_aCB_RoundedEdge.GetState() ) 172 { 173 case STATE_NOCHECK: 174 nCurrentRoundedEdges = 0; 175 break; 176 case STATE_CHECK: 177 nCurrentRoundedEdges = 5; 178 break; 179 case STATE_DONTKNOW: 180 nCurrentRoundedEdges = -1; 181 break; 182 } 183 184 // /-- locked controllers 185 ControllerLockHelperGuard aGuard( m_rControllerLockHelper ); 186 ThreeDHelper::setRoundedEdgesAndObjectLines( 187 ::chart::ChartModelHelper::findDiagram( m_xChartModel ), nCurrentRoundedEdges, nObjectLines ); 188 // \-- locked controllers 189 } 190 191 void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel() 192 { 193 if(!m_bCommitToModel) 194 return; 195 196 drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG; 197 198 switch( m_aCB_Shading.GetState()) 199 { 200 case STATE_NOCHECK: 201 aShadeMode = drawing::ShadeMode_FLAT; 202 break; 203 case STATE_CHECK: 204 aShadeMode = drawing::ShadeMode_SMOOTH; 205 break; 206 case STATE_DONTKNOW: 207 // nothing 208 break; 209 } 210 211 lcl_setShadeModeAtModel( m_xChartModel, aShadeMode ); 212 } 213 214 void ThreeD_SceneAppearance_TabPage::initControlsFromModel() 215 { 216 m_bCommitToModel = false; 217 m_bUpdateOtherControls = false; 218 219 lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel )); 220 221 if(aProps.m_aShadeMode == drawing::ShadeMode_FLAT) 222 { 223 m_aCB_Shading.EnableTriState( sal_False ); 224 m_aCB_Shading.Check(sal_False); 225 } 226 else if(aProps.m_aShadeMode == drawing::ShadeMode_SMOOTH) 227 { 228 m_aCB_Shading.EnableTriState( sal_False ); 229 m_aCB_Shading.Check(sal_True); 230 } 231 else 232 { 233 m_aCB_Shading.EnableTriState( sal_True ); 234 m_aCB_Shading.SetState( STATE_DONTKNOW ); 235 } 236 237 if(aProps.m_nObjectLines == 0) 238 { 239 m_aCB_ObjectLines.EnableTriState( sal_False ); 240 m_aCB_ObjectLines.Check(sal_False); 241 } 242 else if(aProps.m_nObjectLines==1) 243 { 244 m_aCB_ObjectLines.EnableTriState( sal_False ); 245 m_aCB_ObjectLines.Check(sal_True); 246 } 247 else 248 { 249 m_aCB_ObjectLines.EnableTriState( sal_True ); 250 m_aCB_ObjectLines.SetState( STATE_DONTKNOW ); 251 } 252 253 if(aProps.m_nRoundedEdges >= 5) 254 { 255 m_aCB_RoundedEdge.EnableTriState( sal_False ); 256 m_aCB_RoundedEdge.Check(sal_True); 257 } 258 else if(aProps.m_nRoundedEdges<0) 259 { 260 m_aCB_RoundedEdge.EnableTriState( sal_False ); 261 m_aCB_RoundedEdge.SetState( STATE_DONTKNOW ); 262 } 263 else 264 { 265 m_aCB_RoundedEdge.EnableTriState( sal_True ); 266 m_aCB_RoundedEdge.Check(sal_False); 267 } 268 m_aCB_RoundedEdge.Enable( !m_aCB_ObjectLines.IsChecked() ); 269 270 updateScheme(); 271 272 m_bCommitToModel = true; 273 m_bUpdateOtherControls = true; 274 } 275 276 void ThreeD_SceneAppearance_TabPage::updateScheme() 277 { 278 lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel )); 279 280 if( m_aLB_Scheme.GetEntryCount() == (POS_3DSCHEME_CUSTOM+1) ) 281 { 282 m_aLB_Scheme.RemoveEntry(POS_3DSCHEME_CUSTOM); 283 m_aLB_Scheme.SetDropDownLineCount(2); 284 } 285 switch( aProps.m_eScheme ) 286 { 287 case ThreeDLookScheme_Simple: 288 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_SIMPLE ); 289 break; 290 case ThreeDLookScheme_Realistic: 291 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_REALISTIC ); 292 break; 293 case ThreeDLookScheme_Unknown: 294 { 295 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_CUSTOM)),POS_3DSCHEME_CUSTOM); 296 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_CUSTOM ); 297 m_aLB_Scheme.SetDropDownLineCount(3); 298 } 299 break; 300 } 301 } 302 303 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectSchemeHdl, void*, EMPTYARG ) 304 { 305 if( !m_bUpdateOtherControls ) 306 return 0; 307 308 { 309 // /-- locked controllers 310 ControllerLockHelperGuard aGuard( m_rControllerLockHelper ); 311 312 uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( m_xChartModel ) ); 313 314 if( m_aLB_Scheme.GetSelectEntryPos() == POS_3DSCHEME_REALISTIC ) 315 ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Realistic ); 316 else if( m_aLB_Scheme.GetSelectEntryPos() == POS_3DSCHEME_SIMPLE ) 317 ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Simple ); 318 else 319 { 320 OSL_ENSURE( false, "Invalid Entry selected" ); 321 } 322 // \-- locked controllers 323 } 324 325 // update other controls 326 initControlsFromModel(); 327 return 0; 328 } 329 330 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectShading, void*, EMPTYARG ) 331 { 332 if( !m_bUpdateOtherControls ) 333 return 0; 334 335 m_aCB_Shading.EnableTriState( sal_False ); 336 applyShadeModeToModel(); 337 updateScheme(); 338 return 0; 339 } 340 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, CheckBox*, pCheckBox ) 341 { 342 if( !m_bUpdateOtherControls ) 343 return 0; 344 345 if( pCheckBox == &m_aCB_ObjectLines ) 346 { 347 m_aCB_ObjectLines.EnableTriState( sal_False ); 348 m_bUpdateOtherControls = false; 349 m_aCB_RoundedEdge.Enable( !m_aCB_ObjectLines.IsChecked() ); 350 if(!m_aCB_RoundedEdge.IsEnabled()) 351 m_aCB_RoundedEdge.Check(sal_False); 352 m_bUpdateOtherControls = true; 353 } 354 else 355 m_aCB_RoundedEdge.EnableTriState( sal_False ); 356 applyRoundedEdgeAndObjectLinesToModel(); 357 updateScheme(); 358 return 0; 359 } 360 361 //............................................................................. 362 } //namespace chart 363 //............................................................................. 364