1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
28
29 using namespace ::com::sun::star;
30
31 namespace
32 {
33
34 struct lcl_ModelProperties
35 {
36 drawing::ShadeMode m_aShadeMode;
37 sal_Int32 m_nRoundedEdges;
38 sal_Int32 m_nObjectLines;
39 ::chart::ThreeDLookScheme m_eScheme;
40
lcl_ModelProperties__anon5247a7b50111::lcl_ModelProperties41 lcl_ModelProperties()
42 : m_aShadeMode(drawing::ShadeMode_FLAT)
43 , m_nRoundedEdges(-1)
44 , m_nObjectLines(-1)
45 , m_eScheme(::chart::ThreeDLookScheme_Unknown)
46 {}
47 };
48
lcl_getPropertiesFromModel(uno::Reference<frame::XModel> const & xModel)49 lcl_ModelProperties lcl_getPropertiesFromModel( uno::Reference< frame::XModel > const & xModel )
50 {
51 lcl_ModelProperties aProps;
52 try
53 {
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 );
59 }
60 catch( const uno::Exception & )
61 {
62 DBG_UNHANDLED_EXCEPTION("chart2");
63 }
64 return aProps;
65 }
66
lcl_setShadeModeAtModel(uno::Reference<frame::XModel> const & xModel,drawing::ShadeMode aShadeMode)67 void lcl_setShadeModeAtModel( uno::Reference< frame::XModel > const & xModel, drawing::ShadeMode aShadeMode )
68 {
69 try
70 {
71 uno::Reference< beans::XPropertySet > xDiaProp(
72 ::chart::ChartModelHelper::findDiagram( xModel ), uno::UNO_QUERY_THROW );
73 xDiaProp->setPropertyValue( "D3DSceneShadeMode" , uno::Any( aShadeMode ));
74 }
75 catch( const uno::Exception & )
76 {
77 DBG_UNHANDLED_EXCEPTION("chart2");
78 }
79 }
80
81 } // anonymous namespace
82
83 namespace chart
84 {
85
86 #define POS_3DSCHEME_SIMPLE 0
87 #define POS_3DSCHEME_REALISTIC 1
88 #define POS_3DSCHEME_CUSTOM 2
89
ThreeD_SceneAppearance_TabPage(weld::Container * pParent,const uno::Reference<frame::XModel> & xChartModel,ControllerLockHelper & rControllerLockHelper)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"))
103 {
104 m_aCustom = m_xLB_Scheme->get_text(POS_3DSCHEME_CUSTOM);
105 m_xLB_Scheme->remove(POS_3DSCHEME_CUSTOM);
106
107 m_xLB_Scheme->connect_changed( LINK( this, ThreeD_SceneAppearance_TabPage, SelectSchemeHdl ) );
108
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 ) );
112
113 initControlsFromModel();
114 }
115
~ThreeD_SceneAppearance_TabPage()116 ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
117 {
118 }
119
ActivatePage()120 void ThreeD_SceneAppearance_TabPage::ActivatePage()
121 {
122 updateScheme();
123 }
124
applyRoundedEdgeAndObjectLinesToModel()125 void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
126 {
127 if(!m_bCommitToModel)
128 return;
129
130 sal_Int32 nObjectLines = -1;
131
132 switch( m_xCB_ObjectLines->get_state())
133 {
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;
143 }
144
145 sal_Int32 nCurrentRoundedEdges = -1;
146 switch( m_xCB_RoundedEdge->get_state() )
147 {
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;
157 }
158
159 // locked controllers
160 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
161 ThreeDHelper::setRoundedEdgesAndObjectLines(
162 ::chart::ChartModelHelper::findDiagram( m_xChartModel ), nCurrentRoundedEdges, nObjectLines );
163 }
164
applyShadeModeToModel()165 void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
166 {
167 if(!m_bCommitToModel)
168 return;
169
170 drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG;
171
172 switch( m_xCB_Shading->get_state())
173 {
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;
183 }
184
185 lcl_setShadeModeAtModel( m_xChartModel, aShadeMode );
186 }
187
initControlsFromModel()188 void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
189 {
190 m_bCommitToModel = false;
191 m_bUpdateOtherControls = false;
192
193 lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
194
195 if(aProps.m_aShadeMode == drawing::ShadeMode_FLAT)
196 {
197 m_xCB_Shading->set_active(false);
198 }
199 else if(aProps.m_aShadeMode == drawing::ShadeMode_SMOOTH)
200 {
201 m_xCB_Shading->set_active(true);
202 }
203 else
204 {
205 m_xCB_Shading->set_state(TRISTATE_INDET);
206 }
207
208 if(aProps.m_nObjectLines == 0)
209 {
210 m_xCB_ObjectLines->set_active(false);
211 }
212 else if(aProps.m_nObjectLines==1)
213 {
214 m_xCB_ObjectLines->set_active(true);
215 }
216 else
217 {
218 m_xCB_ObjectLines->set_state(TRISTATE_INDET);
219 }
220
221 if(aProps.m_nRoundedEdges >= 5)
222 {
223 m_xCB_RoundedEdge->set_active(true);
224 }
225 else if(aProps.m_nRoundedEdges<0)
226 {
227 m_xCB_RoundedEdge->set_state(TRISTATE_INDET);
228 }
229 else
230 {
231 m_xCB_RoundedEdge->set_active(false);
232 }
233 m_xCB_RoundedEdge->set_sensitive( !m_xCB_ObjectLines->get_active() );
234
235 updateScheme();
236
237 m_bCommitToModel = true;
238 m_bUpdateOtherControls = true;
239 }
240
updateScheme()241 void ThreeD_SceneAppearance_TabPage::updateScheme()
242 {
243 lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
244
245 if (m_xLB_Scheme->get_count() == (POS_3DSCHEME_CUSTOM+1))
246 m_xLB_Scheme->remove(POS_3DSCHEME_CUSTOM);
247 switch( aProps.m_eScheme )
248 {
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:
256 {
257 m_xLB_Scheme->insert_text(POS_3DSCHEME_CUSTOM, m_aCustom);
258 m_xLB_Scheme->set_active(POS_3DSCHEME_CUSTOM);
259 }
260 break;
261 }
262 }
263
IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage,SelectSchemeHdl,weld::ComboBox &,void)264 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectSchemeHdl, weld::ComboBox&, void)
265 {
266 if( !m_bUpdateOtherControls )
267 return;
268
269 {
270 // locked controllers
271 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
272
273 uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( m_xChartModel ) );
274
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
280 {
281 OSL_FAIL( "Invalid Entry selected" );
282 }
283 }
284
285 // update other controls
286 initControlsFromModel();
287 }
288
IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage,SelectShading,weld::ToggleButton &,void)289 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectShading, weld::ToggleButton&, void)
290 {
291 if( !m_bUpdateOtherControls )
292 return;
293
294 applyShadeModeToModel();
295 updateScheme();
296 }
297
IMPL_LINK(ThreeD_SceneAppearance_TabPage,SelectRoundedEdgeOrObjectLines,weld::ToggleButton &,rCheckBox,void)298 IMPL_LINK(ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, weld::ToggleButton&, rCheckBox, void)
299 {
300 if( !m_bUpdateOtherControls )
301 return;
302
303 if (&rCheckBox == m_xCB_ObjectLines.get())
304 {
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;
310 }
311
312 applyRoundedEdgeAndObjectLinesToModel();
313 updateScheme();
314 }
315
316 } //namespace chart
317
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
319