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