| 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_ChartType.hxx" |
| 21 |
#include <ChartResourceGroups.hxx> |
| 22 |
#include <ChartTypeManager.hxx> |
| 23 |
#include <strings.hrc> |
| 24 |
#include <ResId.hxx> |
| 25 |
#include <ChartModel.hxx> |
| 26 |
#include <ChartTypeTemplate.hxx> |
| 27 |
#include <Diagram.hxx> |
| 28 |
#include <unonames.hxx> |
| 29 |
|
| 30 |
#include <svtools/valueset.hxx> |
| 31 |
|
| 32 |
#include <utility> |
| 33 |
#include <vcl/weld.hxx> |
| 34 |
#include <vcl/outdev.hxx> |
| 35 |
#include <comphelper/diagnose_ex.hxx> |
| 36 |
|
| 37 |
namespace chart |
| 38 |
{ |
| 39 |
using namespace ::com::sun::star; |
| 40 |
|
| 41 |
ChartTypeTabPage::ChartTypeTabPage(weld::Container* pPage, weld::DialogController* pController, rtl::Reference<::chart::ChartModel> xChartModel, |
| 42 |
bool bShowDescription) |
| 43 |
: OWizardPage(pPage, pController, u"modules/schart/ui/tp_ChartType.ui"_ustr, u"tp_ChartType"_ustr) |
| 44 |
, m_pDim3DLookResourceGroup( new Dim3DLookResourceGroup(m_xBuilder.get()) ) |
| 45 |
, m_pStackingResourceGroup( new StackingResourceGroup(m_xBuilder.get()) ) |
| 46 |
, m_pSplineResourceGroup( new SplineResourceGroup(m_xBuilder.get(), pController->getDialog()) ) |
| 47 |
, m_pGeometryResourceGroup( new GeometryResourceGroup(m_xBuilder.get()) ) |
| 48 |
, m_pSortByXValuesResourceGroup( new SortByXValuesResourceGroup(m_xBuilder.get()) ) |
| 49 |
, m_xChartModel(std::move( xChartModel )) |
| 50 |
, m_aChartTypeDialogControllerList(0) |
| 51 |
, m_pCurrentMainType(nullptr) |
| 52 |
, m_nChangingCalls(0) |
| 53 |
, m_aTimerTriggeredControllerLock( m_xChartModel ) |
| 54 |
, m_xFT_ChooseType(m_xBuilder->weld_label(u"FT_CAPTION_FOR_WIZARD"_ustr)) |
| 55 |
, m_xMainTypeList(m_xBuilder->weld_tree_view(u"charttype"_ustr)) |
| 56 |
, m_xSubTypeList(new ValueSet(m_xBuilder->weld_scrolled_window(u"subtypewin"_ustr, true))) |
| 57 |
, m_xSubTypeListWin(new weld::CustomWeld(*m_xBuilder, u"subtype"_ustr, *m_xSubTypeList)) |
| 58 |
{ |
| 59 |
Size aSize(m_xSubTypeList->GetDrawingArea()->get_ref_device().LogicToPixel(Size(150, 50), MapMode(MapUnit::MapAppFont))); |
| 60 |
m_xSubTypeListWin->set_size_request(aSize.Width(), aSize.Height()); |
| 61 |
|
| 62 |
if (bShowDescription) |
| 63 |
{ |
| 64 |
m_xFT_ChooseType->show(); |
| 65 |
} |
| 66 |
else |
| 67 |
{ |
| 68 |
m_xFT_ChooseType->hide(); |
| 69 |
} |
| 70 |
|
| 71 |
SetPageTitle(SchResId(STR_PAGE_CHARTTYPE)); |
| 72 |
|
| 73 |
m_xMainTypeList->connect_selection_changed(LINK(this, ChartTypeTabPage, SelectMainTypeHdl)); |
| 74 |
m_xSubTypeList->SetSelectHdl( LINK( this, ChartTypeTabPage, SelectSubTypeHdl ) ); |
| 75 |
|
| 76 |
m_xSubTypeList->SetStyle(m_xSubTypeList->GetStyle() | |
| 77 |
WB_ITEMBORDER | WB_DOUBLEBORDER | WB_NAMEFIELD | WB_FLATVALUESET | WB_3DLOOK ); |
| 78 |
// Set number of columns in chart type selector. |
| 79 |
// TODO: Ideally this would not be hard-coded, but determined |
| 80 |
// programmatically based on the maximum number of chart types across all |
| 81 |
// controllers. |
| 82 |
m_xSubTypeList->SetColCount(4); |
| 83 |
m_xSubTypeList->SetLineCount(1); |
| 84 |
|
| 85 |
bool bEnableComplexChartTypes = true; |
| 86 |
uno::Reference< beans::XPropertySet > xProps( static_cast<cppu::OWeakObject*>(m_xChartModel.get()), uno::UNO_QUERY ); |
| 87 |
if ( xProps.is() ) |
| 88 |
{ |
| 89 |
try |
| 90 |
{ |
| 91 |
xProps->getPropertyValue(u"EnableComplexChartTypes"_ustr) >>= bEnableComplexChartTypes; |
| 92 |
} |
| 93 |
catch( const uno::Exception& ) |
| 94 |
{ |
| 95 |
TOOLS_WARN_EXCEPTION("chart2", "" ); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
m_aChartTypeDialogControllerList.push_back(std::make_unique<ColumnChartDialogController>()); |
| 100 |
m_aChartTypeDialogControllerList.push_back(std::make_unique<BarChartDialogController>()); |
| 101 |
m_aChartTypeDialogControllerList.push_back(std::make_unique<PieChartDialogController>()); |
| 102 |
m_aChartTypeDialogControllerList.push_back(std::make_unique<OfPieChartDialogController>()); |
| 103 |
m_aChartTypeDialogControllerList.push_back(std::make_unique<AreaChartDialogController>()); |
| 104 |
m_aChartTypeDialogControllerList.push_back(std::make_unique<LineChartDialogController>()); |
| 105 |
if (bEnableComplexChartTypes) |
| 106 |
{ |
| 107 |
m_aChartTypeDialogControllerList.push_back(std::make_unique<XYChartDialogController>()); |
| 108 |
m_aChartTypeDialogControllerList.push_back( |
| 109 |
std::make_unique<BubbleChartDialogController>()); |
| 110 |
} |
| 111 |
m_aChartTypeDialogControllerList.push_back(std::make_unique<NetChartDialogController>()); |
| 112 |
if (bEnableComplexChartTypes) |
| 113 |
{ |
| 114 |
m_aChartTypeDialogControllerList.push_back(std::make_unique<StockChartDialogController>()); |
| 115 |
} |
| 116 |
m_aChartTypeDialogControllerList.push_back( |
| 117 |
std::make_unique<CombiColumnLineChartDialogController>()); |
| 118 |
|
| 119 |
for (auto const& elem : m_aChartTypeDialogControllerList) |
| 120 |
{ |
| 121 |
m_xMainTypeList->append(u""_ustr, elem->getName(), elem->getImage()); |
| 122 |
elem->setChangeListener( this ); |
| 123 |
} |
| 124 |
|
| 125 |
m_xMainTypeList->set_size_request(m_xMainTypeList->get_preferred_size().Width(), -1); |
| 126 |
|
| 127 |
m_pDim3DLookResourceGroup->setChangeListener( this ); |
| 128 |
m_pStackingResourceGroup->setChangeListener( this ); |
| 129 |
m_pSplineResourceGroup->setChangeListener( this ); |
| 130 |
m_pGeometryResourceGroup->setChangeListener( this ); |
| 131 |
m_pSortByXValuesResourceGroup->setChangeListener( this ); |
| 132 |
} |
| 133 |
|
| 134 |
ChartTypeTabPage::~ChartTypeTabPage() |
| 135 |
{ |
| 136 |
//delete all dialog controller |
| 137 |
m_aChartTypeDialogControllerList.clear(); |
| 138 |
|
| 139 |
//delete all resource helper |
| 140 |
m_pDim3DLookResourceGroup.reset(); |
| 141 |
m_pStackingResourceGroup.reset(); |
| 142 |
m_pSplineResourceGroup.reset(); |
| 143 |
m_pGeometryResourceGroup.reset(); |
| 144 |
m_pSortByXValuesResourceGroup.reset(); |
| 145 |
m_xSubTypeListWin.reset(); |
| 146 |
m_xSubTypeList.reset(); |
| 147 |
} |
| 148 |
|
| 149 |
ChartTypeParameter ChartTypeTabPage::getCurrentParamter() const |
| 150 |
{ |
| 151 |
ChartTypeParameter aParameter; |
| 152 |
aParameter.nSubTypeIndex = static_cast<sal_Int32>(m_xSubTypeList->GetSelectedItemId()); |
| 153 |
m_pDim3DLookResourceGroup->fillParameter( aParameter ); |
| 154 |
m_pStackingResourceGroup->fillParameter( aParameter ); |
| 155 |
m_pSplineResourceGroup->fillParameter( aParameter ); |
| 156 |
m_pGeometryResourceGroup->fillParameter( aParameter ); |
| 157 |
m_pSortByXValuesResourceGroup->fillParameter( aParameter ); |
| 158 |
return aParameter; |
| 159 |
} |
| 160 |
|
| 161 |
void ChartTypeTabPage::commitToModel( const ChartTypeParameter& rParameter ) |
| 162 |
{ |
| 163 |
if( !m_pCurrentMainType ) |
| 164 |
return; |
| 165 |
|
| 166 |
m_aTimerTriggeredControllerLock.startTimer(); |
| 167 |
uno::Reference< beans::XPropertySet > xTemplateProps( static_cast<cppu::OWeakObject*>(getCurrentTemplate().get()), uno::UNO_QUERY ); |
| 168 |
m_pCurrentMainType->commitToModel( rParameter, m_xChartModel, xTemplateProps ); |
| 169 |
} |
| 170 |
|
| 171 |
void ChartTypeTabPage::stateChanged() |
| 172 |
{ |
| 173 |
if(m_nChangingCalls) |
| 174 |
return; |
| 175 |
m_nChangingCalls++; |
| 176 |
|
| 177 |
ChartTypeParameter aParameter( getCurrentParamter() ); |
| 178 |
if( m_pCurrentMainType ) |
| 179 |
{ |
| 180 |
m_pCurrentMainType->adjustParameterToSubType( aParameter ); |
| 181 |
m_pCurrentMainType->adjustSubTypeAndEnableControls( aParameter ); |
| 182 |
} |
| 183 |
commitToModel( aParameter ); |
| 184 |
|
| 185 |
//detect the new ThreeDLookScheme |
| 186 |
rtl::Reference< Diagram > xDiagram = m_xChartModel->getFirstChartDiagram(); |
| 187 |
// tdf#124295 - select always a 3D scheme |
| 188 |
if (xDiagram) |
| 189 |
{ |
| 190 |
if (ThreeDLookScheme aThreeDLookScheme = xDiagram->detectScheme(); |
| 191 |
aThreeDLookScheme != ThreeDLookScheme::ThreeDLookScheme_Unknown) |
| 192 |
aParameter.eThreeDLookScheme = aThreeDLookScheme; |
| 193 |
} |
| 194 |
|
| 195 |
try |
| 196 |
{ |
| 197 |
if (xDiagram) |
| 198 |
xDiagram->getPropertyValue(CHART_UNONAME_SORT_BY_XVALUES) >>= aParameter.bSortByXValues; |
| 199 |
} |
| 200 |
catch ( const uno::Exception& ) |
| 201 |
{ |
| 202 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 203 |
} |
| 204 |
//the controls have to be enabled/disabled accordingly |
| 205 |
fillAllControls( aParameter ); |
| 206 |
|
| 207 |
m_nChangingCalls--; |
| 208 |
} |
| 209 |
|
| 210 |
ChartTypeDialogController* ChartTypeTabPage::getSelectedMainType() |
| 211 |
{ |
| 212 |
ChartTypeDialogController* pTypeController = nullptr; |
| 213 |
auto nM = static_cast< std::vector< ChartTypeDialogController* >::size_type >( |
| 214 |
m_xMainTypeList->get_selected_index() ); |
| 215 |
if( nM<m_aChartTypeDialogControllerList.size() ) |
| 216 |
pTypeController = m_aChartTypeDialogControllerList[nM].get(); |
| 217 |
return pTypeController; |
| 218 |
} |
| 219 |
|
| 220 |
IMPL_LINK_NOARG(ChartTypeTabPage, SelectSubTypeHdl, ValueSet*, void) |
| 221 |
{ |
| 222 |
if( m_pCurrentMainType ) |
| 223 |
{ |
| 224 |
ChartTypeParameter aParameter( getCurrentParamter() ); |
| 225 |
m_pCurrentMainType->adjustParameterToSubType( aParameter ); |
| 226 |
fillAllControls( aParameter, false ); |
| 227 |
commitToModel( aParameter ); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
IMPL_LINK_NOARG(ChartTypeTabPage, SelectMainTypeHdl, weld::TreeView&, void) |
| 232 |
{ |
| 233 |
selectMainType(); |
| 234 |
} |
| 235 |
|
| 236 |
void ChartTypeTabPage::selectMainType() |
| 237 |
{ |
| 238 |
ChartTypeParameter aParameter( getCurrentParamter() ); |
| 239 |
|
| 240 |
if( m_pCurrentMainType ) |
| 241 |
{ |
| 242 |
m_pCurrentMainType->adjustParameterToSubType( aParameter ); |
| 243 |
m_pCurrentMainType->hideExtraControls(); |
| 244 |
} |
| 245 |
|
| 246 |
m_pCurrentMainType = getSelectedMainType(); |
| 247 |
if( !m_pCurrentMainType ) |
| 248 |
return; |
| 249 |
|
| 250 |
showAllControls(*m_pCurrentMainType); |
| 251 |
|
| 252 |
m_pCurrentMainType->adjustParameterToMainType( aParameter ); |
| 253 |
commitToModel( aParameter ); |
| 254 |
//detect the new ThreeDLookScheme |
| 255 |
aParameter.eThreeDLookScheme = ThreeDLookScheme::ThreeDLookScheme_Unknown; |
| 256 |
rtl::Reference< Diagram > xDiagram = m_xChartModel->getFirstChartDiagram(); |
| 257 |
if (xDiagram) |
| 258 |
aParameter.eThreeDLookScheme = m_xChartModel->getFirstChartDiagram()->detectScheme(); |
| 259 |
if (!aParameter.b3DLook |
| 260 |
&& aParameter.eThreeDLookScheme != ThreeDLookScheme::ThreeDLookScheme_Realistic) |
| 261 |
aParameter.eThreeDLookScheme = ThreeDLookScheme::ThreeDLookScheme_Realistic; |
| 262 |
|
| 263 |
try |
| 264 |
{ |
| 265 |
if (xDiagram) |
| 266 |
xDiagram->getPropertyValue(CHART_UNONAME_SORT_BY_XVALUES) >>= aParameter.bSortByXValues; |
| 267 |
} |
| 268 |
catch ( const uno::Exception& ) |
| 269 |
{ |
| 270 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 271 |
} |
| 272 |
|
| 273 |
fillAllControls( aParameter ); |
| 274 |
uno::Reference< beans::XPropertySet > xTemplateProps( static_cast<cppu::OWeakObject*>(getCurrentTemplate().get()), uno::UNO_QUERY ); |
| 275 |
m_pCurrentMainType->fillExtraControls(m_xChartModel,xTemplateProps); |
| 276 |
} |
| 277 |
|
| 278 |
void ChartTypeTabPage::showAllControls( ChartTypeDialogController& rTypeController ) |
| 279 |
{ |
| 280 |
m_xMainTypeList->show(); |
| 281 |
m_xSubTypeList->Show(); |
| 282 |
|
| 283 |
bool bShow = rTypeController.shouldShow_3DLookControl(); |
| 284 |
m_pDim3DLookResourceGroup->showControls( bShow ); |
| 285 |
bShow = rTypeController.shouldShow_StackingControl(); |
| 286 |
m_pStackingResourceGroup->showControls( bShow ); |
| 287 |
bShow = rTypeController.shouldShow_SplineControl(); |
| 288 |
m_pSplineResourceGroup->showControls( bShow ); |
| 289 |
bShow = rTypeController.shouldShow_GeometryControl(); |
| 290 |
m_pGeometryResourceGroup->showControls( bShow ); |
| 291 |
bShow = rTypeController.shouldShow_SortByXValuesResourceGroup(); |
| 292 |
m_pSortByXValuesResourceGroup->showControls( bShow ); |
| 293 |
rTypeController.showExtraControls(m_xBuilder.get()); |
| 294 |
} |
| 295 |
|
| 296 |
void ChartTypeTabPage::fillAllControls( const ChartTypeParameter& rParameter, bool bAlsoResetSubTypeList ) |
| 297 |
{ |
| 298 |
m_nChangingCalls++; |
| 299 |
if( m_pCurrentMainType && bAlsoResetSubTypeList ) |
| 300 |
{ |
| 301 |
m_pCurrentMainType->fillSubTypeList(*m_xSubTypeList, rParameter); |
| 302 |
} |
| 303 |
m_xSubTypeList->SelectItem( static_cast<sal_uInt16>( rParameter.nSubTypeIndex) ); |
| 304 |
m_pDim3DLookResourceGroup->fillControls( rParameter ); |
| 305 |
m_pStackingResourceGroup->fillControls( rParameter ); |
| 306 |
m_pSplineResourceGroup->fillControls( rParameter ); |
| 307 |
m_pGeometryResourceGroup->fillControls( rParameter ); |
| 308 |
m_pSortByXValuesResourceGroup->fillControls( rParameter ); |
| 309 |
m_nChangingCalls--; |
| 310 |
} |
| 311 |
|
| 312 |
void ChartTypeTabPage::initializePage() |
| 313 |
{ |
| 314 |
if( !m_xChartModel.is() ) |
| 315 |
return; |
| 316 |
rtl::Reference< ::chart::ChartTypeManager > xChartTypeManager = m_xChartModel->getTypeManager(); |
| 317 |
rtl::Reference< Diagram > xDiagram = m_xChartModel->getFirstChartDiagram(); |
| 318 |
Diagram::tTemplateWithServiceName aTemplate; |
| 319 |
if (xDiagram) |
| 320 |
aTemplate = xDiagram->getTemplate( xChartTypeManager ); |
| 321 |
OUString aServiceName( aTemplate.sServiceName ); |
| 322 |
|
| 323 |
bool bFound = false; |
| 324 |
|
| 325 |
sal_uInt16 nM=0; |
| 326 |
for (auto const& elem : m_aChartTypeDialogControllerList) |
| 327 |
{ |
| 328 |
if( elem->isSubType(aServiceName) ) |
| 329 |
{ |
| 330 |
bFound = true; |
| 331 |
|
| 332 |
m_xMainTypeList->select(nM); |
| 333 |
showAllControls(*elem); |
| 334 |
uno::Reference< beans::XPropertySet > xTemplateProps( static_cast<cppu::OWeakObject*>(aTemplate.xChartTypeTemplate.get()), uno::UNO_QUERY ); |
| 335 |
ChartTypeParameter aParameter = elem->getChartTypeParameterForService( aServiceName, xTemplateProps ); |
| 336 |
m_pCurrentMainType = getSelectedMainType(); |
| 337 |
|
| 338 |
//set ThreeDLookScheme |
| 339 |
aParameter.eThreeDLookScheme = xDiagram->detectScheme(); |
| 340 |
if (!aParameter.b3DLook |
| 341 |
&& aParameter.eThreeDLookScheme != ThreeDLookScheme::ThreeDLookScheme_Realistic) |
| 342 |
aParameter.eThreeDLookScheme = ThreeDLookScheme::ThreeDLookScheme_Realistic; |
| 343 |
|
| 344 |
try |
| 345 |
{ |
| 346 |
xDiagram->getPropertyValue(CHART_UNONAME_SORT_BY_XVALUES) >>= aParameter.bSortByXValues; |
| 347 |
} |
| 348 |
catch (const uno::Exception&) |
| 349 |
{ |
| 350 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 351 |
} |
| 352 |
|
| 353 |
fillAllControls( aParameter ); |
| 354 |
if( m_pCurrentMainType ) |
| 355 |
m_pCurrentMainType->fillExtraControls(m_xChartModel,xTemplateProps); |
| 356 |
break; |
| 357 |
} |
| 358 |
++nM; |
| 359 |
} |
| 360 |
|
| 361 |
if( !bFound ) |
| 362 |
{ |
| 363 |
m_xMainTypeList->show(); |
| 364 |
m_xSubTypeList->Show(); |
| 365 |
m_pDim3DLookResourceGroup->showControls( false ); |
| 366 |
m_pStackingResourceGroup->showControls( false ); |
| 367 |
m_pSplineResourceGroup->showControls( false ); |
| 368 |
m_pGeometryResourceGroup->showControls( false ); |
| 369 |
m_pSortByXValuesResourceGroup->showControls( false ); |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
bool ChartTypeTabPage::commitPage( ::vcl::WizardTypes::CommitPageReason /*eReason*/ ) |
| 374 |
{ |
| 375 |
return true; // return false if this page should not be left |
| 376 |
} |
| 377 |
|
| 378 |
rtl::Reference< ChartTypeTemplate > ChartTypeTabPage::getCurrentTemplate() const |
| 379 |
{ |
| 380 |
if( m_pCurrentMainType && m_xChartModel.is() ) |
| 381 |
{ |
| 382 |
ChartTypeParameter aParameter( getCurrentParamter() ); |
| 383 |
m_pCurrentMainType->adjustParameterToSubType( aParameter ); |
| 384 |
rtl::Reference< ::chart::ChartTypeManager > xChartTypeManager = m_xChartModel->getTypeManager(); |
| 385 |
return m_pCurrentMainType->getCurrentTemplate( aParameter, xChartTypeManager ); |
| 386 |
} |
| 387 |
return nullptr; |
| 388 |
} |
| 389 |
|
| 390 |
} //namespace chart |
| 391 |
|
| 392 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |