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 : #include "tp_3D_SceneIllumination.hxx"
21 : #include "ResId.hxx"
22 : #include "Bitmaps.hrc"
23 : #include "CommonConverters.hxx"
24 :
25 : #include "svx/dialogs.hrc"
26 : #include <svx/dialmgr.hxx>
27 : #include <rtl/math.hxx>
28 : #include <svtools/colrdlg.hxx>
29 : #include <vcl/msgbox.hxx>
30 : #include <svx/svx3ditems.hxx>
31 : #include <svx/svddef.hxx>
32 : #include <vcl/builderfactory.hxx>
33 :
34 : namespace chart
35 : {
36 :
37 : using namespace ::com::sun::star;
38 : using namespace ::com::sun::star::chart2;
39 :
40 0 : LightButton::LightButton( vcl::Window* pParent)
41 : : ImageButton( pParent)
42 0 : , m_bLightOn(false)
43 : {
44 0 : SetModeImage( Image( SVX_RES(RID_SVXIMAGE_LIGHT_OFF) ) );
45 0 : }
46 :
47 0 : VCL_BUILDER_FACTORY(LightButton)
48 :
49 0 : void LightButton::switchLightOn(bool bOn)
50 : {
51 0 : if( m_bLightOn==bOn )
52 0 : return;
53 0 : m_bLightOn = bOn;
54 0 : if(m_bLightOn)
55 : {
56 0 : SetModeImage( Image( SVX_RES(RID_SVXIMAGE_LIGHT_ON) ) );
57 : }
58 : else
59 : {
60 0 : SetModeImage( Image( SVX_RES(RID_SVXIMAGE_LIGHT_OFF) ) );
61 : }
62 : }
63 :
64 : struct LightSource
65 : {
66 : long nDiffuseColor;
67 : ::com::sun::star::drawing::Direction3D aDirection;
68 : bool bIsEnabled;
69 :
70 0 : LightSource() :
71 : nDiffuseColor( 0xcccccc ),
72 : aDirection( 1.0, 1.0, -1.0 ),
73 0 : bIsEnabled( false )
74 0 : {}
75 : };
76 :
77 0 : struct LightSourceInfo
78 : {
79 : VclPtr<LightButton> pButton;
80 : LightSource aLightSource;
81 :
82 : LightSourceInfo();
83 : void initButtonFromSource();
84 : };
85 :
86 0 : LightSourceInfo::LightSourceInfo()
87 : : pButton(0)
88 0 : , aLightSource()
89 : {
90 0 : aLightSource.nDiffuseColor = 0xffffff; // white
91 0 : aLightSource.aDirection = drawing::Direction3D(1,1,1);
92 0 : aLightSource.bIsEnabled = false;
93 0 : }
94 :
95 0 : void LightSourceInfo::initButtonFromSource()
96 : {
97 0 : if(!pButton)
98 0 : return;
99 0 : pButton->SetModeImage( Image( SVX_RES(
100 : aLightSource.bIsEnabled ? RID_SVXIMAGE_LIGHT_ON : RID_SVXIMAGE_LIGHT_OFF
101 0 : ) ) );
102 : }
103 :
104 : namespace
105 : {
106 0 : OUString lcl_makeColorName( Color rColor )
107 : {
108 0 : OUString aStr = SVX_RESSTR(RID_SVXFLOAT3D_FIX_R) +
109 0 : OUString::number(rColor.GetRed()) +
110 0 : " " +
111 0 : SVX_RESSTR(RID_SVXFLOAT3D_FIX_G) +
112 0 : OUString::number(rColor.GetGreen()) +
113 0 : " " +
114 0 : SVX_RESSTR(RID_SVXFLOAT3D_FIX_B) +
115 0 : OUString::number(rColor.GetBlue());
116 0 : return aStr;
117 : }
118 0 : void lcl_selectColor( ColorListBox& rListBox, const Color& rColor )
119 : {
120 0 : rListBox.SetNoSelection();
121 0 : rListBox.SelectEntry( rColor );
122 0 : if( rListBox.GetSelectEntryCount() == 0 )
123 : {
124 0 : sal_uInt16 nPos = rListBox.InsertEntry( rColor, lcl_makeColorName( rColor ) );
125 0 : rListBox.SelectEntryPos( nPos );
126 : }
127 0 : }
128 :
129 0 : ::chart::LightSource lcl_getLightSourceFromProperties(
130 : const uno::Reference< beans::XPropertySet > & xSceneProperties,
131 : sal_Int32 nIndex )
132 : {
133 0 : ::chart::LightSource aResult;
134 0 : if( 0 <= nIndex && nIndex < 8 )
135 : {
136 0 : OUString aColorPropertyPrefix("D3DSceneLightColor");
137 0 : OUString aDirectionPropertyPrefix("D3DSceneLightDirection");
138 0 : OUString aEnabledPropertyPrefix("D3DSceneLightOn");
139 0 : OUString aIndex( OUString::number( nIndex + 1 ));
140 :
141 : try
142 : {
143 0 : xSceneProperties->getPropertyValue( aColorPropertyPrefix + aIndex ) >>= aResult.nDiffuseColor;
144 0 : xSceneProperties->getPropertyValue( aDirectionPropertyPrefix + aIndex ) >>= aResult.aDirection;
145 0 : xSceneProperties->getPropertyValue( aEnabledPropertyPrefix + aIndex ) >>= aResult.bIsEnabled;
146 : }
147 0 : catch( const uno::Exception & ex )
148 : {
149 : (void)(ex); // no warning in non-debug builds
150 : OSL_FAIL( OUStringToOString("Property Exception caught. Message: " +
151 : ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
152 0 : }
153 : }
154 0 : return aResult;
155 : }
156 :
157 0 : void lcl_setLightSource(
158 : const uno::Reference< beans::XPropertySet > & xSceneProperties,
159 : const ::chart::LightSource & rLightSource,
160 : sal_Int32 nIndex )
161 : {
162 0 : if( 0 <= nIndex && nIndex < 8 )
163 : {
164 0 : OUString aColorPropertyPrefix("D3DSceneLightColor");
165 0 : OUString aDirectionPropertyPrefix("D3DSceneLightDirection");
166 0 : OUString aEnabledPropertyPrefix("D3DSceneLightOn");
167 0 : OUString aIndex( OUString::number( nIndex + 1 ));
168 :
169 : try
170 : {
171 0 : xSceneProperties->setPropertyValue( aColorPropertyPrefix + aIndex,
172 0 : uno::makeAny( rLightSource.nDiffuseColor ));
173 0 : xSceneProperties->setPropertyValue( aDirectionPropertyPrefix + aIndex,
174 0 : uno::makeAny( rLightSource.aDirection ));
175 0 : xSceneProperties->setPropertyValue( aEnabledPropertyPrefix + aIndex,
176 0 : uno::makeAny( rLightSource.bIsEnabled ));
177 : }
178 0 : catch( const uno::Exception & ex )
179 : {
180 : (void)(ex); // no warning in non-debug builds
181 : OSL_FAIL( OUStringToOString("Property Exception caught. Message: " +
182 : ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
183 0 : }
184 : }
185 0 : }
186 :
187 0 : Color lcl_getAmbientColor(
188 : const uno::Reference< beans::XPropertySet > & xSceneProperties )
189 : {
190 0 : sal_Int32 nResult = 0x000000;
191 : try
192 : {
193 0 : xSceneProperties->getPropertyValue("D3DSceneAmbientColor") >>= nResult;
194 : }
195 0 : catch( const uno::Exception & ex )
196 : {
197 : (void)(ex); // no warning in non-debug builds
198 : OSL_FAIL( OUStringToOString("Property Exception caught. Message: " +
199 : ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
200 : }
201 0 : return Color( nResult );
202 : }
203 :
204 0 : void lcl_setAmbientColor(
205 : const uno::Reference< beans::XPropertySet > & xSceneProperties,
206 : const Color & rColor )
207 : {
208 : try
209 : {
210 0 : xSceneProperties->setPropertyValue("D3DSceneAmbientColor",
211 0 : uno::makeAny( rColor.GetColor()));
212 : }
213 0 : catch( const uno::Exception & ex )
214 : {
215 : (void)(ex); // no warning in non-debug builds
216 : OSL_FAIL( OUStringToOString( "Property Exception caught. Message: " +
217 : ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
218 : }
219 0 : }
220 : }
221 :
222 0 : ThreeD_SceneIllumination_TabPage::ThreeD_SceneIllumination_TabPage( vcl::Window* pWindow
223 : , const uno::Reference< beans::XPropertySet > & xSceneProperties
224 : , const uno::Reference< frame::XModel >& xChartModel
225 : , const XColorListRef & pColorTable )
226 : : TabPage ( pWindow
227 : ,"tp_3D_SceneIllumination"
228 : ,"modules/schart/ui/tp_3D_SceneIllumination.ui")
229 : , m_pLightSourceInfoList(0)
230 : , m_xSceneProperties( xSceneProperties )
231 : , m_aTimerTriggeredControllerLock( xChartModel )
232 : , m_bInCommitToModel( false )
233 : , m_aModelChangeListener( LINK( this, ThreeD_SceneIllumination_TabPage, fillControlsFromModel ) )
234 0 : , m_xChartModel( xChartModel )
235 : {
236 0 : get(m_pBtn_Light1, "BTN_LIGHT_1");
237 0 : get(m_pBtn_Light2, "BTN_LIGHT_2");
238 0 : get(m_pBtn_Light3, "BTN_LIGHT_3");
239 0 : get(m_pBtn_Light4, "BTN_LIGHT_4");
240 0 : get(m_pBtn_Light5, "BTN_LIGHT_5");
241 0 : get(m_pBtn_Light6, "BTN_LIGHT_6");
242 0 : get(m_pBtn_Light7, "BTN_LIGHT_7");
243 0 : get(m_pBtn_Light8, "BTN_LIGHT_8");
244 :
245 0 : get(m_pLB_LightSource, "LB_LIGHTSOURCE");
246 0 : get(m_pLB_AmbientLight, "LB_AMBIENTLIGHT");
247 0 : get(m_pBtn_LightSource_Color, "BTN_LIGHTSOURCE_COLOR");
248 0 : get(m_pBtn_AmbientLight_Color, "BTN_AMBIENT_COLOR");
249 :
250 0 : get(m_pCtl_Preview, "CTL_LIGHT_PREVIEW");
251 :
252 0 : if( pColorTable.is() )
253 : {
254 0 : m_pLB_AmbientLight->Fill( pColorTable );
255 0 : m_pLB_LightSource->Fill( pColorTable );
256 : }
257 0 : m_pLB_AmbientLight->SetDropDownLineCount(10);
258 0 : m_pLB_LightSource->SetDropDownLineCount(10);
259 :
260 0 : m_pLightSourceInfoList = new LightSourceInfo[8];
261 0 : m_pLightSourceInfoList[0].pButton = m_pBtn_Light1;
262 0 : m_pLightSourceInfoList[1].pButton = m_pBtn_Light2;
263 0 : m_pLightSourceInfoList[2].pButton = m_pBtn_Light3;
264 0 : m_pLightSourceInfoList[3].pButton = m_pBtn_Light4;
265 0 : m_pLightSourceInfoList[4].pButton = m_pBtn_Light5;
266 0 : m_pLightSourceInfoList[5].pButton = m_pBtn_Light6;
267 0 : m_pLightSourceInfoList[6].pButton = m_pBtn_Light7;
268 0 : m_pLightSourceInfoList[7].pButton = m_pBtn_Light8;
269 :
270 0 : fillControlsFromModel(0);
271 :
272 0 : m_pBtn_Light1->SetClickHdl( LINK( this, ThreeD_SceneIllumination_TabPage, ClickLightSourceButtonHdl ) );
273 0 : m_pBtn_Light2->SetClickHdl( LINK( this, ThreeD_SceneIllumination_TabPage, ClickLightSourceButtonHdl ) );
274 0 : m_pBtn_Light3->SetClickHdl( LINK( this, ThreeD_SceneIllumination_TabPage, ClickLightSourceButtonHdl ) );
275 0 : m_pBtn_Light4->SetClickHdl( LINK( this, ThreeD_SceneIllumination_TabPage, ClickLightSourceButtonHdl ) );
276 0 : m_pBtn_Light5->SetClickHdl( LINK( this, ThreeD_SceneIllumination_TabPage, ClickLightSourceButtonHdl ) );
277 0 : m_pBtn_Light6->SetClickHdl( LINK( this, ThreeD_SceneIllumination_TabPage, ClickLightSourceButtonHdl ) );
278 0 : m_pBtn_Light7->SetClickHdl( LINK( this, ThreeD_SceneIllumination_TabPage, ClickLightSourceButtonHdl ) );
279 0 : m_pBtn_Light8->SetClickHdl( LINK( this, ThreeD_SceneIllumination_TabPage, ClickLightSourceButtonHdl ) );
280 :
281 0 : m_pLB_AmbientLight->SetSelectHdl( LINK( this, ThreeD_SceneIllumination_TabPage, SelectColorHdl ) );
282 0 : m_pLB_LightSource->SetSelectHdl( LINK( this, ThreeD_SceneIllumination_TabPage, SelectColorHdl ) );
283 :
284 0 : m_pBtn_AmbientLight_Color->SetClickHdl( LINK( this, ThreeD_SceneIllumination_TabPage, ColorDialogHdl ) );
285 0 : m_pBtn_LightSource_Color->SetClickHdl( LINK( this, ThreeD_SceneIllumination_TabPage, ColorDialogHdl ) );
286 :
287 0 : m_pCtl_Preview->SetUserInteractiveChangeCallback( LINK( this, ThreeD_SceneIllumination_TabPage, PreviewChangeHdl ) );
288 0 : m_pCtl_Preview->SetUserSelectionChangeCallback( LINK( this, ThreeD_SceneIllumination_TabPage, PreviewSelectHdl ) );
289 :
290 0 : ClickLightSourceButtonHdl(m_pBtn_Light2);
291 0 : }
292 :
293 0 : ThreeD_SceneIllumination_TabPage::~ThreeD_SceneIllumination_TabPage()
294 : {
295 0 : disposeOnce();
296 0 : }
297 :
298 0 : void ThreeD_SceneIllumination_TabPage::dispose()
299 : {
300 0 : delete[] m_pLightSourceInfoList;
301 0 : m_pLightSourceInfoList = NULL;
302 0 : m_pBtn_Light1.clear();
303 0 : m_pBtn_Light2.clear();
304 0 : m_pBtn_Light3.clear();
305 0 : m_pBtn_Light4.clear();
306 0 : m_pBtn_Light5.clear();
307 0 : m_pBtn_Light6.clear();
308 0 : m_pBtn_Light7.clear();
309 0 : m_pBtn_Light8.clear();
310 0 : m_pLB_LightSource.clear();
311 0 : m_pBtn_LightSource_Color.clear();
312 0 : m_pLB_AmbientLight.clear();
313 0 : m_pBtn_AmbientLight_Color.clear();
314 0 : m_pCtl_Preview.clear();
315 0 : TabPage::dispose();
316 0 : }
317 :
318 0 : IMPL_LINK_NOARG(ThreeD_SceneIllumination_TabPage, fillControlsFromModel)
319 : {
320 0 : if( m_bInCommitToModel )//don't read own changes
321 0 : return 0;
322 :
323 0 : sal_Int32 nL=0;
324 0 : for( nL=0; nL<8; nL++)
325 0 : m_pLightSourceInfoList[nL].aLightSource = lcl_getLightSourceFromProperties( m_xSceneProperties, nL );
326 0 : for( nL=0; nL<8; nL++)
327 0 : m_pLightSourceInfoList[nL].initButtonFromSource();
328 :
329 0 : lcl_selectColor( *m_pLB_AmbientLight, lcl_getAmbientColor( m_xSceneProperties ));
330 :
331 0 : this->updatePreview();
332 :
333 0 : return 0;
334 : }
335 :
336 0 : void ThreeD_SceneIllumination_TabPage::applyLightSourceToModel( sal_uInt32 nLightNumber )
337 : {
338 0 : ControllerLockGuardUNO aGuard( m_xChartModel );
339 0 : m_bInCommitToModel = true;
340 0 : sal_Int32 nIndex( nLightNumber );
341 0 : lcl_setLightSource( m_xSceneProperties, m_pLightSourceInfoList[nIndex].aLightSource, nIndex );
342 0 : m_bInCommitToModel = false;
343 0 : }
344 :
345 0 : void ThreeD_SceneIllumination_TabPage::applyLightSourcesToModel()
346 : {
347 0 : m_aTimerTriggeredControllerLock.startTimer();
348 0 : ControllerLockGuardUNO aGuard( m_xChartModel );
349 0 : for( sal_Int32 nL=0; nL<8; nL++)
350 0 : applyLightSourceToModel( nL );
351 0 : m_aTimerTriggeredControllerLock.startTimer();
352 0 : }
353 :
354 0 : IMPL_LINK_NOARG(ThreeD_SceneIllumination_TabPage, PreviewChangeHdl)
355 : {
356 0 : m_aTimerTriggeredControllerLock.startTimer();
357 :
358 : //update m_pLightSourceInfoList from preview
359 0 : const SfxItemSet a3DLightAttributes(m_pCtl_Preview->GetSvx3DLightControl().Get3DAttributes());
360 0 : LightSourceInfo* pInfo = &m_pLightSourceInfoList[0];
361 :
362 0 : pInfo->aLightSource.nDiffuseColor = static_cast<const SvxColorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTCOLOR_1)).GetValue().GetColor();
363 0 : pInfo->aLightSource.bIsEnabled = static_cast<const SfxBoolItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTON_1)).GetValue();
364 0 : pInfo->aLightSource.aDirection = B3DVectorToDirection3D(static_cast<const SvxB3DVectorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_1)).GetValue());
365 :
366 0 : pInfo = &m_pLightSourceInfoList[1];
367 0 : pInfo->aLightSource.nDiffuseColor = static_cast<const SvxColorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTCOLOR_2)).GetValue().GetColor();
368 0 : pInfo->aLightSource.bIsEnabled = static_cast<const SfxBoolItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTON_2)).GetValue();
369 0 : pInfo->aLightSource.aDirection = B3DVectorToDirection3D(static_cast<const SvxB3DVectorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_2)).GetValue());
370 :
371 0 : pInfo = &m_pLightSourceInfoList[2];
372 0 : pInfo->aLightSource.nDiffuseColor = static_cast<const SvxColorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTCOLOR_3)).GetValue().GetColor();
373 0 : pInfo->aLightSource.bIsEnabled = static_cast<const SfxBoolItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTON_3)).GetValue();
374 0 : pInfo->aLightSource.aDirection = B3DVectorToDirection3D(static_cast<const SvxB3DVectorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_3)).GetValue());
375 :
376 0 : pInfo = &m_pLightSourceInfoList[3];
377 0 : pInfo->aLightSource.nDiffuseColor = static_cast<const SvxColorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTCOLOR_4)).GetValue().GetColor();
378 0 : pInfo->aLightSource.bIsEnabled = static_cast<const SfxBoolItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTON_4)).GetValue();
379 0 : pInfo->aLightSource.aDirection = B3DVectorToDirection3D(static_cast<const SvxB3DVectorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_4)).GetValue());
380 :
381 0 : pInfo = &m_pLightSourceInfoList[4];
382 0 : pInfo->aLightSource.nDiffuseColor = static_cast<const SvxColorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTCOLOR_5)).GetValue().GetColor();
383 0 : pInfo->aLightSource.bIsEnabled = static_cast<const SfxBoolItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTON_5)).GetValue();
384 0 : pInfo->aLightSource.aDirection = B3DVectorToDirection3D(static_cast<const SvxB3DVectorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_5)).GetValue());
385 :
386 0 : pInfo = &m_pLightSourceInfoList[5];
387 0 : pInfo->aLightSource.nDiffuseColor = static_cast<const SvxColorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTCOLOR_6)).GetValue().GetColor();
388 0 : pInfo->aLightSource.bIsEnabled = static_cast<const SfxBoolItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTON_6)).GetValue();
389 0 : pInfo->aLightSource.aDirection = B3DVectorToDirection3D(static_cast<const SvxB3DVectorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_6)).GetValue());
390 :
391 0 : pInfo = &m_pLightSourceInfoList[6];
392 0 : pInfo->aLightSource.nDiffuseColor = static_cast<const SvxColorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTCOLOR_7)).GetValue().GetColor();
393 0 : pInfo->aLightSource.bIsEnabled = static_cast<const SfxBoolItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTON_7)).GetValue();
394 0 : pInfo->aLightSource.aDirection = B3DVectorToDirection3D(static_cast<const SvxB3DVectorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_7)).GetValue());
395 :
396 0 : pInfo = &m_pLightSourceInfoList[7];
397 0 : pInfo->aLightSource.nDiffuseColor = static_cast<const SvxColorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTCOLOR_8)).GetValue().GetColor();
398 0 : pInfo->aLightSource.bIsEnabled = static_cast<const SfxBoolItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTON_8)).GetValue();
399 0 : pInfo->aLightSource.aDirection = B3DVectorToDirection3D(static_cast<const SvxB3DVectorItem&>(a3DLightAttributes.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_8)).GetValue());
400 :
401 0 : applyLightSourcesToModel();
402 :
403 0 : return 0;
404 : }
405 :
406 0 : IMPL_LINK_NOARG(ThreeD_SceneIllumination_TabPage, PreviewSelectHdl)
407 : {
408 0 : sal_uInt32 nLightNumber = m_pCtl_Preview->GetSvx3DLightControl().GetSelectedLight();
409 0 : if(nLightNumber<8)
410 : {
411 0 : LightButton* pButton = m_pLightSourceInfoList[nLightNumber].pButton;
412 0 : if(!pButton->IsChecked())
413 0 : ClickLightSourceButtonHdl(pButton);
414 :
415 0 : applyLightSourcesToModel();
416 : }
417 0 : return 0;
418 : }
419 :
420 0 : IMPL_LINK( ThreeD_SceneIllumination_TabPage, ColorDialogHdl, Button*, pButton )
421 : {
422 0 : bool bIsAmbientLight = (pButton==m_pBtn_AmbientLight_Color);
423 0 : ColorLB* pListBox = ( bIsAmbientLight ? m_pLB_AmbientLight : m_pLB_LightSource);
424 :
425 0 : SvColorDialog aColorDlg( this );
426 0 : aColorDlg.SetColor( pListBox->GetSelectEntryColor() );
427 0 : if( aColorDlg.Execute() == RET_OK )
428 : {
429 0 : Color aColor( aColorDlg.GetColor());
430 0 : lcl_selectColor( *pListBox, aColor );
431 0 : if( bIsAmbientLight )
432 : {
433 0 : m_bInCommitToModel = true;
434 0 : lcl_setAmbientColor( m_xSceneProperties, aColor );
435 0 : m_bInCommitToModel = false;
436 : }
437 : else
438 : {
439 : //get active lightsource:
440 0 : LightSourceInfo* pInfo = 0;
441 0 : sal_Int32 nL=0;
442 0 : for( nL=0; nL<8; nL++)
443 : {
444 0 : pInfo = &m_pLightSourceInfoList[nL];
445 0 : if(pInfo->pButton->IsChecked())
446 0 : break;
447 0 : pInfo = 0;
448 : }
449 0 : if(pInfo)
450 0 : applyLightSourceToModel( nL );
451 : }
452 0 : SelectColorHdl( pListBox );
453 : }
454 0 : return 0;
455 : }
456 :
457 0 : IMPL_LINK( ThreeD_SceneIllumination_TabPage, SelectColorHdl, ColorLB*, pListBox )
458 : {
459 0 : if(pListBox==m_pLB_AmbientLight)
460 : {
461 0 : m_bInCommitToModel = true;
462 0 : lcl_setAmbientColor( m_xSceneProperties, pListBox->GetSelectEntryColor().GetColor());
463 0 : m_bInCommitToModel = false;
464 : }
465 0 : else if(pListBox==m_pLB_LightSource)
466 : {
467 : //get active lightsource:
468 0 : LightSourceInfo* pInfo = 0;
469 0 : sal_Int32 nL=0;
470 0 : for( nL=0; nL<8; nL++)
471 : {
472 0 : pInfo = &m_pLightSourceInfoList[nL];
473 0 : if(pInfo->pButton->IsChecked())
474 0 : break;
475 0 : pInfo = 0;
476 : }
477 0 : if(pInfo)
478 : {
479 0 : pInfo->aLightSource.nDiffuseColor = pListBox->GetSelectEntryColor().GetColor();
480 0 : applyLightSourceToModel( nL );
481 : }
482 : }
483 0 : this->updatePreview();
484 0 : return 0;
485 : }
486 :
487 0 : IMPL_LINK( ThreeD_SceneIllumination_TabPage, ClickLightSourceButtonHdl, LightButton*, pButton )
488 : {
489 0 : if( !pButton )
490 0 : return 0;
491 :
492 0 : LightSourceInfo* pInfo = 0;
493 0 : sal_Int32 nL=0;
494 0 : for( nL=0; nL<8; nL++)
495 : {
496 0 : if( m_pLightSourceInfoList[nL].pButton == pButton )
497 : {
498 0 : pInfo = &m_pLightSourceInfoList[nL];
499 0 : break;
500 : }
501 : }
502 :
503 : //update light button
504 0 : bool bIsChecked = pButton->IsChecked();
505 0 : if(bIsChecked)
506 : {
507 0 : pButton->switchLightOn(!pButton->isLightOn());
508 0 : if(pInfo)
509 : {
510 0 : pInfo->aLightSource.bIsEnabled=pButton->isLightOn();
511 0 : applyLightSourceToModel( nL );
512 : }
513 : }
514 : else
515 : {
516 0 : ControllerLockGuardUNO aGuard( m_xChartModel );
517 0 : for( nL=0; nL<8; nL++)
518 : {
519 0 : LightButton* pLightButton = m_pLightSourceInfoList[nL].pButton;
520 0 : pLightButton->Check( pLightButton == pButton );
521 0 : }
522 : }
523 :
524 : //update color list box
525 0 : if(pInfo)
526 : {
527 0 : lcl_selectColor( *m_pLB_LightSource, pInfo->aLightSource.nDiffuseColor );
528 : }
529 0 : this->updatePreview();
530 0 : return 0;
531 : }
532 :
533 0 : void ThreeD_SceneIllumination_TabPage::updatePreview()
534 : {
535 0 : SfxItemSet aItemSet(m_pCtl_Preview->GetSvx3DLightControl().Get3DAttributes());
536 0 : LightSourceInfo* pInfo = &m_pLightSourceInfoList[0];
537 :
538 : // AmbientColor
539 0 : aItemSet.Put(makeSvx3DAmbientcolorItem(m_pLB_AmbientLight->GetSelectEntryColor()));
540 :
541 0 : aItemSet.Put(makeSvx3DLightcolor1Item(pInfo->aLightSource.nDiffuseColor));
542 0 : aItemSet.Put(makeSvx3DLightOnOff1Item(pInfo->aLightSource.bIsEnabled));
543 0 : aItemSet.Put(makeSvx3DLightDirection1Item(Direction3DToB3DVector(pInfo->aLightSource.aDirection)));
544 :
545 0 : pInfo = &m_pLightSourceInfoList[1];
546 0 : aItemSet.Put(makeSvx3DLightcolor2Item(pInfo->aLightSource.nDiffuseColor));
547 0 : aItemSet.Put(makeSvx3DLightOnOff2Item(pInfo->aLightSource.bIsEnabled));
548 0 : aItemSet.Put(makeSvx3DLightDirection2Item(Direction3DToB3DVector(pInfo->aLightSource.aDirection)));
549 :
550 0 : pInfo = &m_pLightSourceInfoList[2];
551 0 : aItemSet.Put(makeSvx3DLightcolor3Item(pInfo->aLightSource.nDiffuseColor));
552 0 : aItemSet.Put(makeSvx3DLightOnOff3Item(pInfo->aLightSource.bIsEnabled));
553 0 : aItemSet.Put(makeSvx3DLightDirection3Item(Direction3DToB3DVector(pInfo->aLightSource.aDirection)));
554 :
555 0 : pInfo = &m_pLightSourceInfoList[3];
556 0 : aItemSet.Put(makeSvx3DLightcolor4Item(pInfo->aLightSource.nDiffuseColor));
557 0 : aItemSet.Put(makeSvx3DLightOnOff4Item(pInfo->aLightSource.bIsEnabled));
558 0 : aItemSet.Put(makeSvx3DLightDirection4Item(Direction3DToB3DVector(pInfo->aLightSource.aDirection)));
559 :
560 0 : pInfo = &m_pLightSourceInfoList[4];
561 0 : aItemSet.Put(makeSvx3DLightcolor5Item(pInfo->aLightSource.nDiffuseColor));
562 0 : aItemSet.Put(makeSvx3DLightOnOff5Item(pInfo->aLightSource.bIsEnabled));
563 0 : aItemSet.Put(makeSvx3DLightDirection5Item(Direction3DToB3DVector(pInfo->aLightSource.aDirection)));
564 :
565 0 : pInfo = &m_pLightSourceInfoList[5];
566 0 : aItemSet.Put(makeSvx3DLightcolor6Item(pInfo->aLightSource.nDiffuseColor));
567 0 : aItemSet.Put(makeSvx3DLightOnOff6Item(pInfo->aLightSource.bIsEnabled));
568 0 : aItemSet.Put(makeSvx3DLightDirection6Item(Direction3DToB3DVector(pInfo->aLightSource.aDirection)));
569 :
570 0 : pInfo = &m_pLightSourceInfoList[6];
571 0 : aItemSet.Put(makeSvx3DLightcolor7Item(pInfo->aLightSource.nDiffuseColor));
572 0 : aItemSet.Put(makeSvx3DLightOnOff7Item(pInfo->aLightSource.bIsEnabled));
573 0 : aItemSet.Put(makeSvx3DLightDirection7Item(Direction3DToB3DVector(pInfo->aLightSource.aDirection)));
574 :
575 0 : pInfo = &m_pLightSourceInfoList[7];
576 0 : aItemSet.Put(makeSvx3DLightcolor8Item(pInfo->aLightSource.nDiffuseColor));
577 0 : aItemSet.Put(makeSvx3DLightOnOff8Item(pInfo->aLightSource.bIsEnabled));
578 0 : aItemSet.Put(makeSvx3DLightDirection8Item(Direction3DToB3DVector(pInfo->aLightSource.aDirection)));
579 :
580 : // set lights and ambient light
581 0 : m_pCtl_Preview->GetSvx3DLightControl().Set3DAttributes(aItemSet);
582 :
583 : // select light
584 0 : for(sal_uInt32 a(0); a < 8; a++)
585 : {
586 0 : if(m_pLightSourceInfoList[a].pButton->IsChecked())
587 : {
588 0 : m_pCtl_Preview->GetSvx3DLightControl().SelectLight(a);
589 0 : m_pCtl_Preview->CheckSelection();
590 0 : break;
591 : }
592 0 : }
593 0 : }
594 :
595 57 : } //namespace chart
596 :
597 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|