1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "tp_3D_SceneAppearance.hxx"
21 #include "ChartModelHelper.hxx"
22 #include "ThreeDHelper.hxx"
24 #include <rtl/math.hxx>
25 #include <com/sun/star/beans/XPropertySet.hpp>
27 using namespace ::com::sun::star
;
32 struct lcl_ModelProperties
34 drawing::ShadeMode m_aShadeMode
;
35 sal_Int32 m_nRoundedEdges
;
36 sal_Int32 m_nObjectLines
;
37 ::chart::ThreeDLookScheme m_eScheme
;
40 : m_aShadeMode(drawing::ShadeMode_FLAT
)
43 , m_eScheme(::chart::ThreeDLookScheme_Unknown
)
47 lcl_ModelProperties
lcl_getPropertiesFromModel( uno::Reference
< frame::XModel
> & xModel
)
49 lcl_ModelProperties aProps
;
52 uno::Reference
< chart2::XDiagram
> xDiagram( ::chart::ChartModelHelper::findDiagram( xModel
) );
53 uno::Reference
< beans::XPropertySet
> xDiaProp( xDiagram
, uno::UNO_QUERY_THROW
);
54 xDiaProp
->getPropertyValue( "D3DSceneShadeMode" ) >>= aProps
.m_aShadeMode
;
55 ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram
, aProps
.m_nRoundedEdges
, aProps
.m_nObjectLines
);
56 aProps
.m_eScheme
= ::chart::ThreeDHelper::detectScheme( xDiagram
);
58 catch( const uno::Exception
& ex
)
60 ASSERT_EXCEPTION( ex
);
65 void lcl_setShadeModeAtModel( uno::Reference
< frame::XModel
> & xModel
, drawing::ShadeMode aShadeMode
)
69 uno::Reference
< beans::XPropertySet
> xDiaProp(
70 ::chart::ChartModelHelper::findDiagram( xModel
), uno::UNO_QUERY_THROW
);
71 xDiaProp
->setPropertyValue( "D3DSceneShadeMode" , uno::makeAny( aShadeMode
));
73 catch( const uno::Exception
& ex
)
75 ASSERT_EXCEPTION( ex
);
79 } // anonymous namespace
84 #define POS_3DSCHEME_SIMPLE 0
85 #define POS_3DSCHEME_REALISTIC 1
86 #define POS_3DSCHEME_CUSTOM 2
88 ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage(
90 , const uno::Reference
< frame::XModel
> & xChartModel
91 , ControllerLockHelper
& rControllerLockHelper
)
93 , "tp_3D_SceneAppearance"
94 , "modules/schart/ui/tp_3D_SceneAppearance.ui")
95 , m_xChartModel ( xChartModel
)
96 , m_bUpdateOtherControls( true )
97 , m_bCommitToModel( true )
98 , m_rControllerLockHelper( rControllerLockHelper
)
101 get(m_pLB_Scheme
, "LB_SCHEME");
102 get(m_pCB_Shading
, "CB_SHADING");
103 get(m_pCB_ObjectLines
, "CB_OBJECTLINES");
104 get(m_pCB_RoundedEdge
, "CB_ROUNDEDEDGE");
106 m_aCustom
= m_pLB_Scheme
->GetEntry(POS_3DSCHEME_CUSTOM
);
107 m_pLB_Scheme
->RemoveEntry(POS_3DSCHEME_CUSTOM
);
108 m_pLB_Scheme
->SetDropDownLineCount(2);
110 m_pLB_Scheme
->SetSelectHdl( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectSchemeHdl
) );
112 m_pCB_RoundedEdge
->SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectRoundedEdgeOrObjectLines
) );
113 m_pCB_Shading
->SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectShading
) );
114 m_pCB_ObjectLines
->SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectRoundedEdgeOrObjectLines
) );
116 m_pCB_RoundedEdge
->EnableTriState( true );
117 m_pCB_Shading
->EnableTriState( true );
118 m_pCB_ObjectLines
->EnableTriState( true );
120 initControlsFromModel();
123 ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
128 void ThreeD_SceneAppearance_TabPage::dispose()
130 m_pLB_Scheme
.clear();
131 m_pCB_Shading
.clear();
132 m_pCB_ObjectLines
.clear();
133 m_pCB_RoundedEdge
.clear();
137 void ThreeD_SceneAppearance_TabPage::ActivatePage()
142 void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
144 if(!m_bCommitToModel
)
147 sal_Int32 nObjectLines
= -1;
149 switch( m_pCB_ObjectLines
->GetState())
162 sal_Int32 nCurrentRoundedEdges
= -1;
163 switch( m_pCB_RoundedEdge
->GetState() )
166 nCurrentRoundedEdges
= 0;
169 nCurrentRoundedEdges
= 5;
172 nCurrentRoundedEdges
= -1;
176 // locked controllers
177 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
178 ThreeDHelper::setRoundedEdgesAndObjectLines(
179 ::chart::ChartModelHelper::findDiagram( m_xChartModel
), nCurrentRoundedEdges
, nObjectLines
);
182 void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
184 if(!m_bCommitToModel
)
187 drawing::ShadeMode aShadeMode
= drawing::ShadeMode_PHONG
;
189 switch( m_pCB_Shading
->GetState())
192 aShadeMode
= drawing::ShadeMode_FLAT
;
195 aShadeMode
= drawing::ShadeMode_SMOOTH
;
202 lcl_setShadeModeAtModel( m_xChartModel
, aShadeMode
);
205 void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
207 m_bCommitToModel
= false;
208 m_bUpdateOtherControls
= false;
210 lcl_ModelProperties
aProps( lcl_getPropertiesFromModel( m_xChartModel
));
212 if(aProps
.m_aShadeMode
== drawing::ShadeMode_FLAT
)
214 m_pCB_Shading
->EnableTriState( false );
215 m_pCB_Shading
->Check(false);
217 else if(aProps
.m_aShadeMode
== drawing::ShadeMode_SMOOTH
)
219 m_pCB_Shading
->EnableTriState( false );
220 m_pCB_Shading
->Check(true);
224 m_pCB_Shading
->EnableTriState( true );
225 m_pCB_Shading
->SetState( TRISTATE_INDET
);
228 if(aProps
.m_nObjectLines
== 0)
230 m_pCB_ObjectLines
->EnableTriState( false );
231 m_pCB_ObjectLines
->Check(false);
233 else if(aProps
.m_nObjectLines
==1)
235 m_pCB_ObjectLines
->EnableTriState( false );
236 m_pCB_ObjectLines
->Check(true);
240 m_pCB_ObjectLines
->EnableTriState( true );
241 m_pCB_ObjectLines
->SetState( TRISTATE_INDET
);
244 if(aProps
.m_nRoundedEdges
>= 5)
246 m_pCB_RoundedEdge
->EnableTriState( false );
247 m_pCB_RoundedEdge
->Check(true);
249 else if(aProps
.m_nRoundedEdges
<0)
251 m_pCB_RoundedEdge
->EnableTriState( false );
252 m_pCB_RoundedEdge
->SetState( TRISTATE_INDET
);
256 m_pCB_RoundedEdge
->EnableTriState( true );
257 m_pCB_RoundedEdge
->Check(false);
259 m_pCB_RoundedEdge
->Enable( !m_pCB_ObjectLines
->IsChecked() );
263 m_bCommitToModel
= true;
264 m_bUpdateOtherControls
= true;
267 void ThreeD_SceneAppearance_TabPage::updateScheme()
269 lcl_ModelProperties
aProps( lcl_getPropertiesFromModel( m_xChartModel
));
271 if( m_pLB_Scheme
->GetEntryCount() == (POS_3DSCHEME_CUSTOM
+1) )
273 m_pLB_Scheme
->RemoveEntry(POS_3DSCHEME_CUSTOM
);
274 m_pLB_Scheme
->SetDropDownLineCount(2);
276 switch( aProps
.m_eScheme
)
278 case ThreeDLookScheme_Simple
:
279 m_pLB_Scheme
->SelectEntryPos( POS_3DSCHEME_SIMPLE
);
281 case ThreeDLookScheme_Realistic
:
282 m_pLB_Scheme
->SelectEntryPos( POS_3DSCHEME_REALISTIC
);
284 case ThreeDLookScheme_Unknown
:
286 m_pLB_Scheme
->InsertEntry(m_aCustom
,POS_3DSCHEME_CUSTOM
);
287 m_pLB_Scheme
->SelectEntryPos( POS_3DSCHEME_CUSTOM
);
288 m_pLB_Scheme
->SetDropDownLineCount(3);
294 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage
, SelectSchemeHdl
)
296 if( !m_bUpdateOtherControls
)
300 // locked controllers
301 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
303 uno::Reference
< chart2::XDiagram
> xDiagram( ::chart::ChartModelHelper::findDiagram( m_xChartModel
) );
305 if( m_pLB_Scheme
->GetSelectEntryPos() == POS_3DSCHEME_REALISTIC
)
306 ThreeDHelper::setScheme( xDiagram
, ThreeDLookScheme_Realistic
);
307 else if( m_pLB_Scheme
->GetSelectEntryPos() == POS_3DSCHEME_SIMPLE
)
308 ThreeDHelper::setScheme( xDiagram
, ThreeDLookScheme_Simple
);
311 OSL_FAIL( "Invalid Entry selected" );
315 // update other controls
316 initControlsFromModel();
320 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage
, SelectShading
)
322 if( !m_bUpdateOtherControls
)
325 m_pCB_Shading
->EnableTriState( false );
326 applyShadeModeToModel();
330 IMPL_LINK( ThreeD_SceneAppearance_TabPage
, SelectRoundedEdgeOrObjectLines
, CheckBox
*, pCheckBox
)
332 if( !m_bUpdateOtherControls
)
335 if( pCheckBox
== m_pCB_ObjectLines
)
337 m_pCB_ObjectLines
->EnableTriState( false );
338 m_bUpdateOtherControls
= false;
339 m_pCB_RoundedEdge
->Enable( !m_pCB_ObjectLines
->IsChecked() );
340 if(!m_pCB_RoundedEdge
->IsEnabled())
341 m_pCB_RoundedEdge
->Check(false);
342 m_bUpdateOtherControls
= true;
345 m_pCB_RoundedEdge
->EnableTriState( false );
346 applyRoundedEdgeAndObjectLinesToModel();
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */