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