Bump for 3.6-28
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_3D_SceneAppearance.cxx
blobd46083141eaf3f6fbad5eb1396394ccddb9338c7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "tp_3D_SceneAppearance.hxx"
31 #include "tp_3D_SceneAppearance.hrc"
32 #include "ResId.hxx"
33 #include "Strings.hrc"
34 #include "NoWarningThisInCTOR.hxx"
35 #include "ChartModelHelper.hxx"
36 #include "ThreeDHelper.hxx"
37 #include "macros.hxx"
38 #include <rtl/math.hxx>
39 #include <com/sun/star/beans/XPropertySet.hpp>
41 using namespace ::com::sun::star;
43 namespace
46 struct lcl_ModelProperties
48 drawing::ShadeMode m_aShadeMode;
49 sal_Int32 m_nRoundedEdges;
50 sal_Int32 m_nObjectLines;
51 ::chart::ThreeDLookScheme m_eScheme;
53 lcl_ModelProperties() :
54 m_nRoundedEdges(-1),
55 m_nObjectLines(-1),
56 m_eScheme(::chart::ThreeDLookScheme_Unknown)
60 lcl_ModelProperties lcl_getPropertiesFromModel( uno::Reference< frame::XModel > & xModel )
62 lcl_ModelProperties aProps;
63 try
65 uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) );
66 uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY_THROW );
67 xDiaProp->getPropertyValue( C2U("D3DSceneShadeMode")) >>= aProps.m_aShadeMode;
68 ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram, aProps.m_nRoundedEdges, aProps.m_nObjectLines );
69 aProps.m_eScheme = ::chart::ThreeDHelper::detectScheme( xDiagram );
71 catch( const uno::Exception & ex )
73 ASSERT_EXCEPTION( ex );
75 return aProps;
78 void lcl_setShadeModeAtModel( uno::Reference< frame::XModel > & xModel, drawing::ShadeMode aShadeMode )
80 try
82 uno::Reference< beans::XPropertySet > xDiaProp(
83 ::chart::ChartModelHelper::findDiagram( xModel ), uno::UNO_QUERY_THROW );
84 xDiaProp->setPropertyValue( C2U("D3DSceneShadeMode"), uno::makeAny( aShadeMode ));
86 catch( const uno::Exception & ex )
88 ASSERT_EXCEPTION( ex );
92 } // anonymous namespace
94 //.............................................................................
95 namespace chart
97 //.............................................................................
99 #define POS_3DSCHEME_SIMPLE 0
100 #define POS_3DSCHEME_REALISTIC 1
101 #define POS_3DSCHEME_CUSTOM 2
103 ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage(
104 Window* pWindow
105 , const uno::Reference< frame::XModel > & xChartModel
106 , ControllerLockHelper & rControllerLockHelper )
107 : TabPage ( pWindow, SchResId( TP_3D_SCENEAPPEARANCE ) )
108 , m_xChartModel ( xChartModel )
109 , m_aFT_Scheme ( this, SchResId( FT_SCHEME ) )
110 , m_aLB_Scheme ( this, SchResId( LB_SCHEME ) )
111 , m_aFL_Seperator ( this, SchResId( FL_SEPERATOR ) )
112 , m_aCB_Shading ( this, SchResId( CB_SHADING ) )
113 , m_aCB_ObjectLines ( this, SchResId( CB_OBJECTLINES ) )
114 , m_aCB_RoundedEdge ( this, SchResId( CB_ROUNDEDEDGE ) )
115 , m_bUpdateOtherControls( true )
116 , m_bCommitToModel( true )
117 , m_rControllerLockHelper( rControllerLockHelper )
119 FreeResource();
120 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_SIMPLE)),POS_3DSCHEME_SIMPLE);
121 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_REALISTIC)),POS_3DSCHEME_REALISTIC);
122 m_aLB_Scheme.SetDropDownLineCount(2);
124 m_aLB_Scheme.SetSelectHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectSchemeHdl ) );
126 m_aCB_RoundedEdge.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
127 m_aCB_Shading.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectShading ) );
128 m_aCB_ObjectLines.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
130 m_aCB_RoundedEdge.EnableTriState( sal_True );
131 m_aCB_Shading.EnableTriState( sal_True );
132 m_aCB_ObjectLines.EnableTriState( sal_True );
134 initControlsFromModel();
137 ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
140 void ThreeD_SceneAppearance_TabPage::ActivatePage()
142 updateScheme();
145 void ThreeD_SceneAppearance_TabPage::commitPendingChanges()
149 void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
151 if(!m_bCommitToModel)
152 return;
154 sal_Int32 nObjectLines = -1;
156 switch( m_aCB_ObjectLines.GetState())
158 case STATE_NOCHECK:
159 nObjectLines = 0;
160 break;
161 case STATE_CHECK:
162 nObjectLines = 1;
163 break;
164 case STATE_DONTKNOW:
165 nObjectLines = -1;
166 break;
169 sal_Int32 nCurrentRoundedEdges = -1;
170 switch( m_aCB_RoundedEdge.GetState() )
172 case STATE_NOCHECK:
173 nCurrentRoundedEdges = 0;
174 break;
175 case STATE_CHECK:
176 nCurrentRoundedEdges = 5;
177 break;
178 case STATE_DONTKNOW:
179 nCurrentRoundedEdges = -1;
180 break;
183 // locked controllers
184 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
185 ThreeDHelper::setRoundedEdgesAndObjectLines(
186 ::chart::ChartModelHelper::findDiagram( m_xChartModel ), nCurrentRoundedEdges, nObjectLines );
189 void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
191 if(!m_bCommitToModel)
192 return;
194 drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG;
196 switch( m_aCB_Shading.GetState())
198 case STATE_NOCHECK:
199 aShadeMode = drawing::ShadeMode_FLAT;
200 break;
201 case STATE_CHECK:
202 aShadeMode = drawing::ShadeMode_SMOOTH;
203 break;
204 case STATE_DONTKNOW:
205 // nothing
206 break;
209 lcl_setShadeModeAtModel( m_xChartModel, aShadeMode );
212 void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
214 m_bCommitToModel = false;
215 m_bUpdateOtherControls = false;
217 lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
219 if(aProps.m_aShadeMode == drawing::ShadeMode_FLAT)
221 m_aCB_Shading.EnableTriState( sal_False );
222 m_aCB_Shading.Check(sal_False);
224 else if(aProps.m_aShadeMode == drawing::ShadeMode_SMOOTH)
226 m_aCB_Shading.EnableTriState( sal_False );
227 m_aCB_Shading.Check(sal_True);
229 else
231 m_aCB_Shading.EnableTriState( sal_True );
232 m_aCB_Shading.SetState( STATE_DONTKNOW );
235 if(aProps.m_nObjectLines == 0)
237 m_aCB_ObjectLines.EnableTriState( sal_False );
238 m_aCB_ObjectLines.Check(sal_False);
240 else if(aProps.m_nObjectLines==1)
242 m_aCB_ObjectLines.EnableTriState( sal_False );
243 m_aCB_ObjectLines.Check(sal_True);
245 else
247 m_aCB_ObjectLines.EnableTriState( sal_True );
248 m_aCB_ObjectLines.SetState( STATE_DONTKNOW );
251 if(aProps.m_nRoundedEdges >= 5)
253 m_aCB_RoundedEdge.EnableTriState( sal_False );
254 m_aCB_RoundedEdge.Check(sal_True);
256 else if(aProps.m_nRoundedEdges<0)
258 m_aCB_RoundedEdge.EnableTriState( sal_False );
259 m_aCB_RoundedEdge.SetState( STATE_DONTKNOW );
261 else
263 m_aCB_RoundedEdge.EnableTriState( sal_True );
264 m_aCB_RoundedEdge.Check(sal_False);
266 m_aCB_RoundedEdge.Enable( !m_aCB_ObjectLines.IsChecked() );
268 updateScheme();
270 m_bCommitToModel = true;
271 m_bUpdateOtherControls = true;
274 void ThreeD_SceneAppearance_TabPage::updateScheme()
276 lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
278 if( m_aLB_Scheme.GetEntryCount() == (POS_3DSCHEME_CUSTOM+1) )
280 m_aLB_Scheme.RemoveEntry(POS_3DSCHEME_CUSTOM);
281 m_aLB_Scheme.SetDropDownLineCount(2);
283 switch( aProps.m_eScheme )
285 case ThreeDLookScheme_Simple:
286 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_SIMPLE );
287 break;
288 case ThreeDLookScheme_Realistic:
289 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_REALISTIC );
290 break;
291 case ThreeDLookScheme_Unknown:
293 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_CUSTOM)),POS_3DSCHEME_CUSTOM);
294 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_CUSTOM );
295 m_aLB_Scheme.SetDropDownLineCount(3);
297 break;
301 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectSchemeHdl)
303 if( !m_bUpdateOtherControls )
304 return 0;
307 // locked controllers
308 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
310 uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( m_xChartModel ) );
312 if( m_aLB_Scheme.GetSelectEntryPos() == POS_3DSCHEME_REALISTIC )
313 ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Realistic );
314 else if( m_aLB_Scheme.GetSelectEntryPos() == POS_3DSCHEME_SIMPLE )
315 ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Simple );
316 else
318 OSL_FAIL( "Invalid Entry selected" );
322 // update other controls
323 initControlsFromModel();
324 return 0;
327 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectShading)
329 if( !m_bUpdateOtherControls )
330 return 0;
332 m_aCB_Shading.EnableTriState( sal_False );
333 applyShadeModeToModel();
334 updateScheme();
335 return 0;
337 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, CheckBox*, pCheckBox )
339 if( !m_bUpdateOtherControls )
340 return 0;
342 if( pCheckBox == &m_aCB_ObjectLines )
344 m_aCB_ObjectLines.EnableTriState( sal_False );
345 m_bUpdateOtherControls = false;
346 m_aCB_RoundedEdge.Enable( !m_aCB_ObjectLines.IsChecked() );
347 if(!m_aCB_RoundedEdge.IsEnabled())
348 m_aCB_RoundedEdge.Check(sal_False);
349 m_bUpdateOtherControls = true;
351 else
352 m_aCB_RoundedEdge.EnableTriState( sal_False );
353 applyRoundedEdgeAndObjectLinesToModel();
354 updateScheme();
355 return 0;
358 //.............................................................................
359 } //namespace chart
360 //.............................................................................
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */