Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_3D_SceneAppearance.cxx
blob1168fe0f18c79e355990771a808a71f86b26b01b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
31 namespace
34 struct lcl_ModelProperties
36 drawing::ShadeMode m_aShadeMode;
37 sal_Int32 m_nRoundedEdges;
38 sal_Int32 m_nObjectLines;
39 ::chart::ThreeDLookScheme m_eScheme;
41 lcl_ModelProperties()
42 : m_aShadeMode(drawing::ShadeMode_FLAT)
43 , m_nRoundedEdges(-1)
44 , m_nObjectLines(-1)
45 , m_eScheme(::chart::ThreeDLookScheme_Unknown)
49 lcl_ModelProperties lcl_getPropertiesFromModel( uno::Reference< frame::XModel > const & xModel )
51 lcl_ModelProperties aProps;
52 try
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");
64 return aProps;
67 void lcl_setShadeModeAtModel( uno::Reference< frame::XModel > const & xModel, drawing::ShadeMode aShadeMode )
69 try
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
83 namespace chart
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()
122 updateScheme();
125 void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
127 if(!m_bCommitToModel)
128 return;
130 sal_Int32 nObjectLines = -1;
132 switch( m_xCB_ObjectLines->get_state())
134 case TRISTATE_FALSE:
135 nObjectLines = 0;
136 break;
137 case TRISTATE_TRUE:
138 nObjectLines = 1;
139 break;
140 case TRISTATE_INDET:
141 nObjectLines = -1;
142 break;
145 sal_Int32 nCurrentRoundedEdges = -1;
146 switch( m_xCB_RoundedEdge->get_state() )
148 case TRISTATE_FALSE:
149 nCurrentRoundedEdges = 0;
150 break;
151 case TRISTATE_TRUE:
152 nCurrentRoundedEdges = 5;
153 break;
154 case TRISTATE_INDET:
155 nCurrentRoundedEdges = -1;
156 break;
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)
168 return;
170 drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG;
172 switch( m_xCB_Shading->get_state())
174 case TRISTATE_FALSE:
175 aShadeMode = drawing::ShadeMode_FLAT;
176 break;
177 case TRISTATE_TRUE:
178 aShadeMode = drawing::ShadeMode_SMOOTH;
179 break;
180 case TRISTATE_INDET:
181 // nothing
182 break;
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);
203 else
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);
216 else
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);
229 else
231 m_xCB_RoundedEdge->set_active(false);
233 m_xCB_RoundedEdge->set_sensitive( !m_xCB_ObjectLines->get_active() );
235 updateScheme();
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 );
251 break;
252 case ThreeDLookScheme_Realistic:
253 m_xLB_Scheme->set_active( POS_3DSCHEME_REALISTIC );
254 break;
255 case ThreeDLookScheme_Unknown:
257 m_xLB_Scheme->insert_text(POS_3DSCHEME_CUSTOM, m_aCustom);
258 m_xLB_Scheme->set_active(POS_3DSCHEME_CUSTOM);
260 break;
264 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectSchemeHdl, weld::ComboBox&, void)
266 if( !m_bUpdateOtherControls )
267 return;
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 );
279 else
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 )
292 return;
294 applyShadeModeToModel();
295 updateScheme();
298 IMPL_LINK(ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, weld::ToggleButton&, rCheckBox, void)
300 if( !m_bUpdateOtherControls )
301 return;
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();
313 updateScheme();
316 } //namespace chart
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */