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>
23 #include <ControllerLockGuard.hxx>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/drawing/ShadeMode.hpp>
26 #include <tools/diagnose_ex.h>
27 #include <vcl/svapp.hxx>
29 using namespace ::com::sun::star
;
34 struct lcl_ModelProperties
36 drawing::ShadeMode m_aShadeMode
;
37 sal_Int32 m_nRoundedEdges
;
38 sal_Int32 m_nObjectLines
;
39 ::chart::ThreeDLookScheme m_eScheme
;
42 : m_aShadeMode(drawing::ShadeMode_FLAT
)
45 , m_eScheme(::chart::ThreeDLookScheme_Unknown
)
49 lcl_ModelProperties
lcl_getPropertiesFromModel( uno::Reference
< frame::XModel
> const & xModel
)
51 lcl_ModelProperties aProps
;
54 uno::Reference
< chart2::XDiagram
> xDiagram( ::chart::ChartModelHelper::findDiagram( xModel
) );
55 uno::Reference
< beans::XPropertySet
> xDiaProp( xDiagram
, uno::UNO_QUERY_THROW
);
56 xDiaProp
->getPropertyValue( "D3DSceneShadeMode" ) >>= aProps
.m_aShadeMode
;
57 ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram
, aProps
.m_nRoundedEdges
, aProps
.m_nObjectLines
);
58 aProps
.m_eScheme
= ::chart::ThreeDHelper::detectScheme( xDiagram
);
60 catch( const uno::Exception
& )
62 DBG_UNHANDLED_EXCEPTION("chart2");
67 void lcl_setShadeModeAtModel( uno::Reference
< frame::XModel
> const & xModel
, drawing::ShadeMode aShadeMode
)
71 uno::Reference
< beans::XPropertySet
> xDiaProp(
72 ::chart::ChartModelHelper::findDiagram( xModel
), uno::UNO_QUERY_THROW
);
73 xDiaProp
->setPropertyValue( "D3DSceneShadeMode" , uno::Any( aShadeMode
));
75 catch( const uno::Exception
& )
77 DBG_UNHANDLED_EXCEPTION("chart2");
81 } // anonymous namespace
86 #define POS_3DSCHEME_SIMPLE 0
87 #define POS_3DSCHEME_REALISTIC 1
88 #define POS_3DSCHEME_CUSTOM 2
90 ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage(weld::Container
* pParent
,
91 const uno::Reference
<frame::XModel
>& xChartModel
,
92 ControllerLockHelper
& rControllerLockHelper
)
93 : m_xChartModel(xChartModel
)
94 , m_bUpdateOtherControls(true)
95 , m_bCommitToModel(true)
96 , m_rControllerLockHelper(rControllerLockHelper
)
97 , m_xBuilder(Application::CreateBuilder(pParent
, "modules/schart/ui/tp_3D_SceneAppearance.ui"))
98 , m_xContainer(m_xBuilder
->weld_container("tp_3D_SceneAppearance"))
99 , m_xLB_Scheme(m_xBuilder
->weld_combo_box("LB_SCHEME"))
100 , m_xCB_Shading(m_xBuilder
->weld_check_button("CB_SHADING"))
101 , m_xCB_ObjectLines(m_xBuilder
->weld_check_button("CB_OBJECTLINES"))
102 , m_xCB_RoundedEdge(m_xBuilder
->weld_check_button("CB_ROUNDEDEDGE"))
104 m_aCustom
= m_xLB_Scheme
->get_text(POS_3DSCHEME_CUSTOM
);
105 m_xLB_Scheme
->remove(POS_3DSCHEME_CUSTOM
);
107 m_xLB_Scheme
->connect_changed( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectSchemeHdl
) );
109 m_xCB_RoundedEdge
->connect_toggled( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectRoundedEdgeOrObjectLines
) );
110 m_xCB_Shading
->connect_toggled( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectShading
) );
111 m_xCB_ObjectLines
->connect_toggled( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectRoundedEdgeOrObjectLines
) );
113 initControlsFromModel();
116 ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
120 void ThreeD_SceneAppearance_TabPage::ActivatePage()
125 void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
127 if(!m_bCommitToModel
)
130 sal_Int32 nObjectLines
= -1;
132 switch( m_xCB_ObjectLines
->get_state())
145 sal_Int32 nCurrentRoundedEdges
= -1;
146 switch( m_xCB_RoundedEdge
->get_state() )
149 nCurrentRoundedEdges
= 0;
152 nCurrentRoundedEdges
= 5;
155 nCurrentRoundedEdges
= -1;
159 // locked controllers
160 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
161 ThreeDHelper::setRoundedEdgesAndObjectLines(
162 ::chart::ChartModelHelper::findDiagram( m_xChartModel
), nCurrentRoundedEdges
, nObjectLines
);
165 void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
167 if(!m_bCommitToModel
)
170 drawing::ShadeMode aShadeMode
= drawing::ShadeMode_PHONG
;
172 switch( m_xCB_Shading
->get_state())
175 aShadeMode
= drawing::ShadeMode_FLAT
;
178 aShadeMode
= drawing::ShadeMode_SMOOTH
;
185 lcl_setShadeModeAtModel( m_xChartModel
, aShadeMode
);
188 void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
190 m_bCommitToModel
= false;
191 m_bUpdateOtherControls
= false;
193 lcl_ModelProperties
aProps( lcl_getPropertiesFromModel( m_xChartModel
));
195 if(aProps
.m_aShadeMode
== drawing::ShadeMode_FLAT
)
197 m_xCB_Shading
->set_active(false);
199 else if(aProps
.m_aShadeMode
== drawing::ShadeMode_SMOOTH
)
201 m_xCB_Shading
->set_active(true);
205 m_xCB_Shading
->set_state(TRISTATE_INDET
);
208 if(aProps
.m_nObjectLines
== 0)
210 m_xCB_ObjectLines
->set_active(false);
212 else if(aProps
.m_nObjectLines
==1)
214 m_xCB_ObjectLines
->set_active(true);
218 m_xCB_ObjectLines
->set_state(TRISTATE_INDET
);
221 if(aProps
.m_nRoundedEdges
>= 5)
223 m_xCB_RoundedEdge
->set_active(true);
225 else if(aProps
.m_nRoundedEdges
<0)
227 m_xCB_RoundedEdge
->set_state(TRISTATE_INDET
);
231 m_xCB_RoundedEdge
->set_active(false);
233 m_xCB_RoundedEdge
->set_sensitive( !m_xCB_ObjectLines
->get_active() );
237 m_bCommitToModel
= true;
238 m_bUpdateOtherControls
= true;
241 void ThreeD_SceneAppearance_TabPage::updateScheme()
243 lcl_ModelProperties
aProps( lcl_getPropertiesFromModel( m_xChartModel
));
245 if (m_xLB_Scheme
->get_count() == (POS_3DSCHEME_CUSTOM
+1))
246 m_xLB_Scheme
->remove(POS_3DSCHEME_CUSTOM
);
247 switch( aProps
.m_eScheme
)
249 case ThreeDLookScheme_Simple
:
250 m_xLB_Scheme
->set_active( POS_3DSCHEME_SIMPLE
);
252 case ThreeDLookScheme_Realistic
:
253 m_xLB_Scheme
->set_active( POS_3DSCHEME_REALISTIC
);
255 case ThreeDLookScheme_Unknown
:
257 m_xLB_Scheme
->insert_text(POS_3DSCHEME_CUSTOM
, m_aCustom
);
258 m_xLB_Scheme
->set_active(POS_3DSCHEME_CUSTOM
);
264 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage
, SelectSchemeHdl
, weld::ComboBox
&, void)
266 if( !m_bUpdateOtherControls
)
270 // locked controllers
271 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
273 uno::Reference
< chart2::XDiagram
> xDiagram( ::chart::ChartModelHelper::findDiagram( m_xChartModel
) );
275 if( m_xLB_Scheme
->get_active() == POS_3DSCHEME_REALISTIC
)
276 ThreeDHelper::setScheme( xDiagram
, ThreeDLookScheme_Realistic
);
277 else if( m_xLB_Scheme
->get_active() == POS_3DSCHEME_SIMPLE
)
278 ThreeDHelper::setScheme( xDiagram
, ThreeDLookScheme_Simple
);
281 OSL_FAIL( "Invalid Entry selected" );
285 // update other controls
286 initControlsFromModel();
289 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage
, SelectShading
, weld::ToggleButton
&, void)
291 if( !m_bUpdateOtherControls
)
294 applyShadeModeToModel();
298 IMPL_LINK(ThreeD_SceneAppearance_TabPage
, SelectRoundedEdgeOrObjectLines
, weld::ToggleButton
&, rCheckBox
, void)
300 if( !m_bUpdateOtherControls
)
303 if (&rCheckBox
== m_xCB_ObjectLines
.get())
305 m_bUpdateOtherControls
= false;
306 m_xCB_RoundedEdge
->set_sensitive( !m_xCB_ObjectLines
->get_active() );
307 if(!m_xCB_RoundedEdge
->get_sensitive())
308 m_xCB_RoundedEdge
->set_active(false);
309 m_bUpdateOtherControls
= true;
312 applyRoundedEdgeAndObjectLinesToModel();
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */