fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_3D_SceneAppearance.cxx
blob7c866eed86b5cc7509b226489d040837f1bc21cc
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 "macros.hxx"
24 #include <rtl/math.hxx>
25 #include <com/sun/star/beans/XPropertySet.hpp>
27 using namespace ::com::sun::star;
29 namespace
32 struct lcl_ModelProperties
34 drawing::ShadeMode m_aShadeMode;
35 sal_Int32 m_nRoundedEdges;
36 sal_Int32 m_nObjectLines;
37 ::chart::ThreeDLookScheme m_eScheme;
39 lcl_ModelProperties()
40 : m_aShadeMode(drawing::ShadeMode_FLAT)
41 , m_nRoundedEdges(-1)
42 , m_nObjectLines(-1)
43 , m_eScheme(::chart::ThreeDLookScheme_Unknown)
47 lcl_ModelProperties lcl_getPropertiesFromModel( uno::Reference< frame::XModel > & xModel )
49 lcl_ModelProperties aProps;
50 try
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 );
62 return aProps;
65 void lcl_setShadeModeAtModel( uno::Reference< frame::XModel > & xModel, drawing::ShadeMode aShadeMode )
67 try
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
81 namespace chart
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(
89 vcl::Window* pWindow
90 , const uno::Reference< frame::XModel > & xChartModel
91 , ControllerLockHelper & rControllerLockHelper )
92 : TabPage ( pWindow
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()
125 disposeOnce();
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();
134 TabPage::dispose();
137 void ThreeD_SceneAppearance_TabPage::ActivatePage()
139 updateScheme();
142 void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
144 if(!m_bCommitToModel)
145 return;
147 sal_Int32 nObjectLines = -1;
149 switch( m_pCB_ObjectLines->GetState())
151 case TRISTATE_FALSE:
152 nObjectLines = 0;
153 break;
154 case TRISTATE_TRUE:
155 nObjectLines = 1;
156 break;
157 case TRISTATE_INDET:
158 nObjectLines = -1;
159 break;
162 sal_Int32 nCurrentRoundedEdges = -1;
163 switch( m_pCB_RoundedEdge->GetState() )
165 case TRISTATE_FALSE:
166 nCurrentRoundedEdges = 0;
167 break;
168 case TRISTATE_TRUE:
169 nCurrentRoundedEdges = 5;
170 break;
171 case TRISTATE_INDET:
172 nCurrentRoundedEdges = -1;
173 break;
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)
185 return;
187 drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG;
189 switch( m_pCB_Shading->GetState())
191 case TRISTATE_FALSE:
192 aShadeMode = drawing::ShadeMode_FLAT;
193 break;
194 case TRISTATE_TRUE:
195 aShadeMode = drawing::ShadeMode_SMOOTH;
196 break;
197 case TRISTATE_INDET:
198 // nothing
199 break;
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);
222 else
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);
238 else
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 );
254 else
256 m_pCB_RoundedEdge->EnableTriState( true );
257 m_pCB_RoundedEdge->Check(false);
259 m_pCB_RoundedEdge->Enable( !m_pCB_ObjectLines->IsChecked() );
261 updateScheme();
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 );
280 break;
281 case ThreeDLookScheme_Realistic:
282 m_pLB_Scheme->SelectEntryPos( POS_3DSCHEME_REALISTIC );
283 break;
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);
290 break;
294 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectSchemeHdl)
296 if( !m_bUpdateOtherControls )
297 return 0;
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 );
309 else
311 OSL_FAIL( "Invalid Entry selected" );
315 // update other controls
316 initControlsFromModel();
317 return 0;
320 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectShading)
322 if( !m_bUpdateOtherControls )
323 return 0;
325 m_pCB_Shading->EnableTriState( false );
326 applyShadeModeToModel();
327 updateScheme();
328 return 0;
330 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, CheckBox*, pCheckBox )
332 if( !m_bUpdateOtherControls )
333 return 0;
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;
344 else
345 m_pCB_RoundedEdge->EnableTriState( false );
346 applyRoundedEdgeAndObjectLinesToModel();
347 updateScheme();
348 return 0;
351 } //namespace chart
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */