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