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 <ChartModel.hxx>
22 #include <ThreeDHelper.hxx>
23 #include <ControllerLockGuard.hxx>
24 #include <Diagram.hxx>
25 #include <com/sun/star/drawing/ShadeMode.hpp>
26 #include <comphelper/diagnose_ex.hxx>
28 #include <vcl/svapp.hxx>
30 using namespace ::com::sun::star
;
35 struct lcl_ModelProperties
37 drawing::ShadeMode m_aShadeMode
;
38 sal_Int32 m_nRoundedEdges
;
39 sal_Int32 m_nObjectLines
;
40 ::chart::ThreeDLookScheme m_eScheme
;
43 : m_aShadeMode(drawing::ShadeMode_FLAT
)
46 , m_eScheme(::chart::ThreeDLookScheme::ThreeDLookScheme_Unknown
)
50 lcl_ModelProperties
lcl_getPropertiesFromModel( rtl::Reference
<::chart::ChartModel
> const & xModel
)
52 lcl_ModelProperties aProps
;
55 rtl::Reference
< ::chart::Diagram
> xDiagram( xModel
->getFirstChartDiagram() );
56 xDiagram
->getPropertyValue( u
"D3DSceneShadeMode"_ustr
) >>= aProps
.m_aShadeMode
;
57 ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram
, aProps
.m_nRoundedEdges
, aProps
.m_nObjectLines
);
58 aProps
.m_eScheme
= xDiagram
->detectScheme();
60 catch( const uno::Exception
& )
62 DBG_UNHANDLED_EXCEPTION("chart2");
67 void lcl_setShadeModeAtModel( rtl::Reference
<::chart::ChartModel
> const & xModel
, drawing::ShadeMode aShadeMode
)
71 rtl::Reference
< ::chart::Diagram
> xDiaProp
= xModel
->getFirstChartDiagram();
72 xDiaProp
->setPropertyValue( u
"D3DSceneShadeMode"_ustr
, uno::Any( aShadeMode
));
74 catch( const uno::Exception
& )
76 DBG_UNHANDLED_EXCEPTION("chart2");
80 } // anonymous namespace
85 #define POS_3DSCHEME_SIMPLE 0
86 #define POS_3DSCHEME_REALISTIC 1
87 #define POS_3DSCHEME_CUSTOM 2
89 ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage(weld::Container
* pParent
,
90 rtl::Reference
<::chart::ChartModel
> xChartModel
,
91 ControllerLockHelper
& rControllerLockHelper
)
92 : m_xChartModel(std::move(xChartModel
))
93 , m_bUpdateOtherControls(true)
94 , m_bCommitToModel(true)
95 , m_rControllerLockHelper(rControllerLockHelper
)
96 , m_xBuilder(Application::CreateBuilder(pParent
, u
"modules/schart/ui/tp_3D_SceneAppearance.ui"_ustr
))
97 , m_xContainer(m_xBuilder
->weld_container(u
"tp_3D_SceneAppearance"_ustr
))
98 , m_xLB_Scheme(m_xBuilder
->weld_combo_box(u
"LB_SCHEME"_ustr
))
99 , m_xCB_Shading(m_xBuilder
->weld_check_button(u
"CB_SHADING"_ustr
))
100 , m_xCB_ObjectLines(m_xBuilder
->weld_check_button(u
"CB_OBJECTLINES"_ustr
))
101 , m_xCB_RoundedEdge(m_xBuilder
->weld_check_button(u
"CB_ROUNDEDEDGE"_ustr
))
103 m_aCustom
= m_xLB_Scheme
->get_text(POS_3DSCHEME_CUSTOM
);
104 m_xLB_Scheme
->remove(POS_3DSCHEME_CUSTOM
);
106 m_xLB_Scheme
->connect_changed( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectSchemeHdl
) );
108 m_xCB_RoundedEdge
->connect_toggled( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectRoundedEdgeOrObjectLines
) );
109 m_xCB_Shading
->connect_toggled( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectShading
) );
110 m_xCB_ObjectLines
->connect_toggled( LINK( this, ThreeD_SceneAppearance_TabPage
, SelectRoundedEdgeOrObjectLines
) );
112 initControlsFromModel();
115 ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
119 void ThreeD_SceneAppearance_TabPage::ActivatePage()
124 void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
126 if(!m_bCommitToModel
)
129 sal_Int32 nObjectLines
= -1;
131 switch( m_xCB_ObjectLines
->get_state())
144 sal_Int32 nCurrentRoundedEdges
= -1;
145 switch( m_xCB_RoundedEdge
->get_state() )
148 nCurrentRoundedEdges
= 0;
151 nCurrentRoundedEdges
= 5;
154 nCurrentRoundedEdges
= -1;
158 // locked controllers
159 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
160 ThreeDHelper::setRoundedEdgesAndObjectLines(
161 m_xChartModel
->getFirstChartDiagram(), nCurrentRoundedEdges
, nObjectLines
);
164 void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
166 if(!m_bCommitToModel
)
169 drawing::ShadeMode aShadeMode
= drawing::ShadeMode_PHONG
;
171 switch( m_xCB_Shading
->get_state())
174 aShadeMode
= drawing::ShadeMode_FLAT
;
177 aShadeMode
= drawing::ShadeMode_SMOOTH
;
184 lcl_setShadeModeAtModel( m_xChartModel
, aShadeMode
);
187 void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
189 m_bCommitToModel
= false;
190 m_bUpdateOtherControls
= false;
192 lcl_ModelProperties
aProps( lcl_getPropertiesFromModel( m_xChartModel
));
194 if(aProps
.m_aShadeMode
== drawing::ShadeMode_FLAT
)
196 m_xCB_Shading
->set_active(false);
198 else if(aProps
.m_aShadeMode
== drawing::ShadeMode_SMOOTH
)
200 m_xCB_Shading
->set_active(true);
204 m_xCB_Shading
->set_state(TRISTATE_INDET
);
207 if(aProps
.m_nObjectLines
== 0)
209 m_xCB_ObjectLines
->set_active(false);
211 else if(aProps
.m_nObjectLines
==1)
213 m_xCB_ObjectLines
->set_active(true);
217 m_xCB_ObjectLines
->set_state(TRISTATE_INDET
);
220 if(aProps
.m_nRoundedEdges
>= 5)
222 m_xCB_RoundedEdge
->set_active(true);
224 else if(aProps
.m_nRoundedEdges
<0)
226 m_xCB_RoundedEdge
->set_state(TRISTATE_INDET
);
230 m_xCB_RoundedEdge
->set_active(false);
232 m_xCB_RoundedEdge
->set_sensitive( !m_xCB_ObjectLines
->get_active() );
236 m_bCommitToModel
= true;
237 m_bUpdateOtherControls
= true;
240 void ThreeD_SceneAppearance_TabPage::updateScheme()
242 lcl_ModelProperties
aProps( lcl_getPropertiesFromModel( m_xChartModel
));
244 if (m_xLB_Scheme
->get_count() == (POS_3DSCHEME_CUSTOM
+1))
245 m_xLB_Scheme
->remove(POS_3DSCHEME_CUSTOM
);
246 switch( aProps
.m_eScheme
)
248 case ThreeDLookScheme::ThreeDLookScheme_Simple
:
249 m_xLB_Scheme
->set_active( POS_3DSCHEME_SIMPLE
);
251 case ThreeDLookScheme::ThreeDLookScheme_Realistic
:
252 m_xLB_Scheme
->set_active( POS_3DSCHEME_REALISTIC
);
254 case ThreeDLookScheme::ThreeDLookScheme_Unknown
:
256 m_xLB_Scheme
->insert_text(POS_3DSCHEME_CUSTOM
, m_aCustom
);
257 m_xLB_Scheme
->set_active(POS_3DSCHEME_CUSTOM
);
263 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage
, SelectSchemeHdl
, weld::ComboBox
&, void)
265 if( !m_bUpdateOtherControls
)
269 // locked controllers
270 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
272 rtl::Reference
< Diagram
> xDiagram
= m_xChartModel
->getFirstChartDiagram();
274 if( m_xLB_Scheme
->get_active() == POS_3DSCHEME_REALISTIC
)
275 xDiagram
->setScheme( ThreeDLookScheme::ThreeDLookScheme_Realistic
);
276 else if( m_xLB_Scheme
->get_active() == POS_3DSCHEME_SIMPLE
)
277 xDiagram
->setScheme( ThreeDLookScheme::ThreeDLookScheme_Simple
);
280 OSL_FAIL( "Invalid Entry selected" );
284 // update other controls
285 initControlsFromModel();
288 IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage
, SelectShading
, weld::Toggleable
&, void)
290 if( !m_bUpdateOtherControls
)
293 applyShadeModeToModel();
297 IMPL_LINK(ThreeD_SceneAppearance_TabPage
, SelectRoundedEdgeOrObjectLines
, weld::Toggleable
&, rCheckBox
, void)
299 if( !m_bUpdateOtherControls
)
302 if (&rCheckBox
== m_xCB_ObjectLines
.get())
304 m_bUpdateOtherControls
= false;
305 m_xCB_RoundedEdge
->set_sensitive( !m_xCB_ObjectLines
->get_active() );
306 if(!m_xCB_RoundedEdge
->get_sensitive())
307 m_xCB_RoundedEdge
->set_active(false);
308 m_bUpdateOtherControls
= true;
311 applyRoundedEdgeAndObjectLinesToModel();
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */