update dev300-m58
[ooovba.git] / chart2 / source / controller / dialogs / tp_3D_SceneAppearance.cxx
blob2575c6df7523dea38b5c77d4719de6d2b000b335
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tp_3D_SceneAppearance.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "tp_3D_SceneAppearance.hxx"
35 #include "tp_3D_SceneAppearance.hrc"
36 #include "ResId.hxx"
37 #include "Strings.hrc"
38 #include "NoWarningThisInCTOR.hxx"
39 #include "ChartModelHelper.hxx"
40 #include "ThreeDHelper.hxx"
41 #include "macros.hxx"
42 #include <rtl/math.hxx>
43 #include <com/sun/star/beans/XPropertySet.hpp>
45 using namespace ::com::sun::star;
47 namespace
50 struct lcl_ModelProperties
52 drawing::ShadeMode m_aShadeMode;
53 sal_Int32 m_nRoundedEdges;
54 sal_Int32 m_nObjectLines;
55 ::chart::ThreeDLookScheme m_eScheme;
57 lcl_ModelProperties() :
58 m_nRoundedEdges(-1),
59 m_nObjectLines(-1),
60 m_eScheme(::chart::ThreeDLookScheme_Unknown)
64 lcl_ModelProperties lcl_getPropertiesFromModel( uno::Reference< frame::XModel > & xModel )
66 lcl_ModelProperties aProps;
67 try
69 uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) );
70 uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY_THROW );
71 xDiaProp->getPropertyValue( C2U("D3DSceneShadeMode")) >>= aProps.m_aShadeMode;
72 ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram, aProps.m_nRoundedEdges, aProps.m_nObjectLines );
73 aProps.m_eScheme = ::chart::ThreeDHelper::detectScheme( xDiagram );
75 catch( const uno::Exception & ex )
77 ASSERT_EXCEPTION( ex );
79 return aProps;
82 void lcl_setShadeModeAtModel( uno::Reference< frame::XModel > & xModel, drawing::ShadeMode aShadeMode )
84 try
86 uno::Reference< beans::XPropertySet > xDiaProp(
87 ::chart::ChartModelHelper::findDiagram( xModel ), uno::UNO_QUERY_THROW );
88 xDiaProp->setPropertyValue( C2U("D3DSceneShadeMode"), uno::makeAny( aShadeMode ));
90 catch( const uno::Exception & ex )
92 ASSERT_EXCEPTION( ex );
96 } // anonymous namespace
98 //.............................................................................
99 namespace chart
101 //.............................................................................
103 #define POS_3DSCHEME_SIMPLE 0
104 #define POS_3DSCHEME_REALISTIC 1
105 #define POS_3DSCHEME_CUSTOM 2
107 ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage(
108 Window* pWindow
109 , const uno::Reference< frame::XModel > & xChartModel
110 , ControllerLockHelper & rControllerLockHelper )
111 : TabPage ( pWindow, SchResId( TP_3D_SCENEAPPEARANCE ) )
112 , m_xChartModel ( xChartModel )
113 , m_aFT_Scheme ( this, SchResId( FT_SCHEME ) )
114 , m_aLB_Scheme ( this, SchResId( LB_SCHEME ) )
115 , m_aFL_Seperator ( this, SchResId( FL_SEPERATOR ) )
116 , m_aCB_RoundedEdge ( this, SchResId( CB_ROUNDEDEDGE ) )
117 , m_aCB_Shading ( this, SchResId( CB_SHADING ) )
118 , m_aCB_ObjectLines ( this, SchResId( CB_OBJECTLINES ) )
119 , m_bUpdateOtherControls( true )
120 , m_bCommitToModel( true )
121 , m_rControllerLockHelper( rControllerLockHelper )
123 FreeResource();
124 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_SIMPLE)),POS_3DSCHEME_SIMPLE);
125 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_REALISTIC)),POS_3DSCHEME_REALISTIC);
126 m_aLB_Scheme.SetDropDownLineCount(2);
128 m_aLB_Scheme.SetSelectHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectSchemeHdl ) );
130 m_aCB_RoundedEdge.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
131 m_aCB_Shading.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectShading ) );
132 m_aCB_ObjectLines.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
134 m_aCB_RoundedEdge.EnableTriState( TRUE );
135 m_aCB_Shading.EnableTriState( TRUE );
136 m_aCB_ObjectLines.EnableTriState( TRUE );
138 initControlsFromModel();
141 ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
144 void ThreeD_SceneAppearance_TabPage::ActivatePage()
146 updateScheme();
149 void ThreeD_SceneAppearance_TabPage::commitPendingChanges()
153 void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
155 if(!m_bCommitToModel)
156 return;
158 sal_Int32 nObjectLines = -1;
160 switch( m_aCB_ObjectLines.GetState())
162 case STATE_NOCHECK:
163 nObjectLines = 0;
164 break;
165 case STATE_CHECK:
166 nObjectLines = 1;
167 break;
168 case STATE_DONTKNOW:
169 nObjectLines = -1;
170 break;
173 sal_Int32 nCurrentRoundedEdges = -1;
174 switch( m_aCB_RoundedEdge.GetState() )
176 case STATE_NOCHECK:
177 nCurrentRoundedEdges = 0;
178 break;
179 case STATE_CHECK:
180 nCurrentRoundedEdges = 5;
181 break;
182 case STATE_DONTKNOW:
183 nCurrentRoundedEdges = -1;
184 break;
187 // /-- locked controllers
188 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
189 ThreeDHelper::setRoundedEdgesAndObjectLines(
190 ::chart::ChartModelHelper::findDiagram( m_xChartModel ), nCurrentRoundedEdges, nObjectLines );
191 // \-- locked controllers
194 void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
196 if(!m_bCommitToModel)
197 return;
199 drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG;
201 switch( m_aCB_Shading.GetState())
203 case STATE_NOCHECK:
204 aShadeMode = drawing::ShadeMode_FLAT;
205 break;
206 case STATE_CHECK:
207 aShadeMode = drawing::ShadeMode_SMOOTH;
208 break;
209 case STATE_DONTKNOW:
210 // nothing
211 break;
214 lcl_setShadeModeAtModel( m_xChartModel, aShadeMode );
217 void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
219 m_bCommitToModel = false;
220 m_bUpdateOtherControls = false;
222 lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
224 if(aProps.m_aShadeMode == drawing::ShadeMode_FLAT)
226 m_aCB_Shading.EnableTriState( FALSE );
227 m_aCB_Shading.Check(FALSE);
229 else if(aProps.m_aShadeMode == drawing::ShadeMode_SMOOTH)
231 m_aCB_Shading.EnableTriState( FALSE );
232 m_aCB_Shading.Check(TRUE);
234 else
236 m_aCB_Shading.EnableTriState( TRUE );
237 m_aCB_Shading.SetState( STATE_DONTKNOW );
240 if(aProps.m_nObjectLines == 0)
242 m_aCB_ObjectLines.EnableTriState( FALSE );
243 m_aCB_ObjectLines.Check(FALSE);
245 else if(aProps.m_nObjectLines==1)
247 m_aCB_ObjectLines.EnableTriState( FALSE );
248 m_aCB_ObjectLines.Check(TRUE);
250 else
252 m_aCB_ObjectLines.EnableTriState( TRUE );
253 m_aCB_ObjectLines.SetState( STATE_DONTKNOW );
256 if(aProps.m_nRoundedEdges >= 5)
258 m_aCB_RoundedEdge.EnableTriState( FALSE );
259 m_aCB_RoundedEdge.Check(TRUE);
261 else if(aProps.m_nRoundedEdges<0)
263 m_aCB_RoundedEdge.EnableTriState( FALSE );
264 m_aCB_RoundedEdge.SetState( STATE_DONTKNOW );
266 else
268 m_aCB_RoundedEdge.EnableTriState( TRUE );
269 m_aCB_RoundedEdge.Check(FALSE);
271 m_aCB_RoundedEdge.Enable( !m_aCB_ObjectLines.IsChecked() );
273 updateScheme();
275 m_bCommitToModel = true;
276 m_bUpdateOtherControls = true;
279 void ThreeD_SceneAppearance_TabPage::updateScheme()
281 lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
283 if( m_aLB_Scheme.GetEntryCount() == (POS_3DSCHEME_CUSTOM+1) )
285 m_aLB_Scheme.RemoveEntry(POS_3DSCHEME_CUSTOM);
286 m_aLB_Scheme.SetDropDownLineCount(2);
288 switch( aProps.m_eScheme )
290 case ThreeDLookScheme_Simple:
291 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_SIMPLE );
292 break;
293 case ThreeDLookScheme_Realistic:
294 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_REALISTIC );
295 break;
296 case ThreeDLookScheme_Unknown:
298 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_CUSTOM)),POS_3DSCHEME_CUSTOM);
299 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_CUSTOM );
300 m_aLB_Scheme.SetDropDownLineCount(3);
302 break;
306 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectSchemeHdl, void*, EMPTYARG )
308 if( !m_bUpdateOtherControls )
309 return 0;
312 // /-- locked controllers
313 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
315 uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( m_xChartModel ) );
317 if( m_aLB_Scheme.GetSelectEntryPos() == POS_3DSCHEME_REALISTIC )
318 ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Realistic );
319 else if( m_aLB_Scheme.GetSelectEntryPos() == POS_3DSCHEME_SIMPLE )
320 ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Simple );
321 else
323 OSL_ENSURE( false, "Invalid Entry selected" );
325 // \-- locked controllers
328 // update other controls
329 initControlsFromModel();
330 return 0;
333 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectShading, void*, EMPTYARG )
335 if( !m_bUpdateOtherControls )
336 return 0;
338 m_aCB_Shading.EnableTriState( FALSE );
339 applyShadeModeToModel();
340 updateScheme();
341 return 0;
343 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, CheckBox*, pCheckBox )
345 if( !m_bUpdateOtherControls )
346 return 0;
348 if( pCheckBox == &m_aCB_ObjectLines )
350 m_aCB_ObjectLines.EnableTriState( FALSE );
351 m_bUpdateOtherControls = false;
352 m_aCB_RoundedEdge.Enable( !m_aCB_ObjectLines.IsChecked() );
353 if(!m_aCB_RoundedEdge.IsEnabled())
354 m_aCB_RoundedEdge.Check(FALSE);
355 m_bUpdateOtherControls = true;
357 else
358 m_aCB_RoundedEdge.EnableTriState( FALSE );
359 applyRoundedEdgeAndObjectLinesToModel();
360 updateScheme();
361 return 0;
364 //.............................................................................
365 } //namespace chart
366 //.............................................................................