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 <com/sun/star/chart2/LegendPosition.hpp>
21 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
22 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
23 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
24
25 #include <vcl/svapp.hxx>
26
27 #include "ChartElementsPanel.hxx"
28 #include <ChartController.hxx>
29 #include <comphelper/processfactory.hxx>
30
31 #include <LegendHelper.hxx>
32 #include <ChartModelHelper.hxx>
33 #include <AxisHelper.hxx>
34 #include <DiagramHelper.hxx>
35 #include <ChartTypeHelper.hxx>
36
37 #include <ChartModel.hxx>
38
39
40 using namespace css;
41 using namespace css::uno;
42
43 namespace chart::sidebar {
44
45 namespace {
46
47 enum class GridType
48 {
49 VERT_MAJOR,
50 VERT_MINOR,
51 HOR_MAJOR,
52 HOR_MINOR
53 };
54
55 enum class AxisType
56 {
57 X_MAIN,
58 Y_MAIN,
59 Z_MAIN,
60 X_SECOND,
61 Y_SECOND
62 };
63
getChartModel(const css::uno::Reference<css::frame::XModel> & xModel)64 ChartModel* getChartModel(const css::uno::Reference<css::frame::XModel>& xModel)
65 {
66 ChartModel* pModel = dynamic_cast<ChartModel*>(xModel.get());
67
68 return pModel;
69 }
70
isLegendVisible(const css::uno::Reference<css::frame::XModel> & xModel)71 bool isLegendVisible(const css::uno::Reference<css::frame::XModel>& xModel)
72 {
73 ChartModel* pModel = getChartModel(xModel);
74 if (!pModel)
75 return false;
76
77 Reference< beans::XPropertySet > xLegendProp( LegendHelper::getLegend(*pModel), uno::UNO_QUERY );
78 if( xLegendProp.is())
79 {
80 try
81 {
82 bool bShow = false;
83 if( xLegendProp->getPropertyValue( "Show") >>= bShow )
84 {
85 return bShow;
86 }
87 }
88 catch(const uno::Exception &)
89 {
90 }
91 }
92
93 return false;
94 }
95
setLegendVisible(const css::uno::Reference<css::frame::XModel> & xModel,bool bVisible)96 void setLegendVisible(const css::uno::Reference<css::frame::XModel>& xModel, bool bVisible)
97 {
98 ChartModel* pModel = getChartModel(xModel);
99 if (!pModel)
100 return;
101
102 if (bVisible)
103 LegendHelper::showLegend(*pModel, comphelper::getProcessComponentContext());
104 else
105 LegendHelper::hideLegend(*pModel);
106 }
107
isLegendOverlay(const css::uno::Reference<css::frame::XModel> & xModel)108 bool isLegendOverlay(const css::uno::Reference<css::frame::XModel>& xModel)
109 {
110 ChartModel* pModel = getChartModel(xModel);
111 if (!pModel)
112 return false;
113
114 Reference< beans::XPropertySet > xLegendProp(LegendHelper::getLegend(*pModel), uno::UNO_QUERY);
115 if( xLegendProp.is())
116 {
117 try
118 {
119 bool bOverlay = false;
120 if(xLegendProp->getPropertyValue("Overlay") >>= bOverlay)
121 {
122 return bOverlay;
123 }
124 }
125 catch(const uno::Exception &)
126 {
127 }
128 }
129
130 return false;
131 }
132
setLegendOverlay(const css::uno::Reference<css::frame::XModel> & xModel,bool bOverlay)133 void setLegendOverlay(const css::uno::Reference<css::frame::XModel>& xModel, bool bOverlay)
134 {
135 ChartModel* pModel = getChartModel(xModel);
136 if (!pModel)
137 return;
138
139 Reference<beans::XPropertySet> xLegendProp(LegendHelper::getLegend(*pModel), uno::UNO_QUERY);
140 if (!xLegendProp.is())
141 return;
142
143 xLegendProp->setPropertyValue("Overlay", css::uno::Any(bOverlay));
144 }
145
isTitleVisible(const css::uno::Reference<css::frame::XModel> & xModel,TitleHelper::eTitleType eTitle)146 bool isTitleVisible(const css::uno::Reference<css::frame::XModel>& xModel, TitleHelper::eTitleType eTitle)
147 {
148 css::uno::Reference<css::uno::XInterface> xTitle = TitleHelper::getTitle(eTitle, xModel);
149 if (!xTitle.is())
150 return false;
151
152 css::uno::Reference<css::beans::XPropertySet> xPropSet(xTitle, css::uno::UNO_QUERY_THROW);
153 css::uno::Any aAny = xPropSet->getPropertyValue("Visible");
154 bool bVisible = aAny.get<bool>();
155 return bVisible;
156 }
157
isGridVisible(const css::uno::Reference<css::frame::XModel> & xModel,GridType eType)158 bool isGridVisible(const css::uno::Reference<css::frame::XModel>& xModel, GridType eType)
159 {
160 Reference< chart2::XDiagram > xDiagram(ChartModelHelper::findDiagram(xModel));
161 if(xDiagram.is())
162 {
163 sal_Int32 nDimensionIndex = 0;
164 if (eType == GridType::HOR_MAJOR || eType == GridType::HOR_MINOR)
165 nDimensionIndex = 1;
166
167 bool bMajor = (eType == GridType::HOR_MAJOR || eType == GridType::VERT_MAJOR);
168
169 bool bHasGrid = AxisHelper::isGridShown(nDimensionIndex, 0, bMajor, xDiagram);
170 return bHasGrid;
171 }
172 return false;
173 }
174
setGridVisible(const css::uno::Reference<css::frame::XModel> & xModel,GridType eType,bool bVisible)175 void setGridVisible(const css::uno::Reference<css::frame::XModel>& xModel, GridType eType, bool bVisible)
176 {
177 Reference< chart2::XDiagram > xDiagram(ChartModelHelper::findDiagram(xModel));
178 if(!xDiagram.is())
179 return;
180
181 sal_Int32 nDimensionIndex = 0;
182 if (eType == GridType::HOR_MAJOR || eType == GridType::HOR_MINOR)
183 nDimensionIndex = 1;
184 sal_Int32 nCooSysIndex = 0;
185
186 bool bMajor = (eType == GridType::HOR_MAJOR || eType == GridType::VERT_MAJOR);
187
188 if (bVisible)
189 AxisHelper::showGrid(nDimensionIndex, nCooSysIndex, bMajor,
190 xDiagram);
191 else
192 AxisHelper::hideGrid(nDimensionIndex, nCooSysIndex, bMajor, xDiagram);
193 }
194
isAxisVisible(const css::uno::Reference<css::frame::XModel> & xModel,AxisType eType)195 bool isAxisVisible(const css::uno::Reference<css::frame::XModel>& xModel, AxisType eType)
196 {
197 Reference< chart2::XDiagram > xDiagram(ChartModelHelper::findDiagram(xModel));
198 if(xDiagram.is())
199 {
200 sal_Int32 nDimensionIndex = 0;
201 if (eType == AxisType::Y_MAIN || eType == AxisType::Y_SECOND)
202 nDimensionIndex = 1;
203 else if (eType == AxisType::Z_MAIN)
204 nDimensionIndex = 2;
205
206 bool bMajor = (eType != AxisType::X_SECOND && eType != AxisType::Y_SECOND);
207
208 bool bHasAxis = AxisHelper::isAxisShown(nDimensionIndex, bMajor, xDiagram);
209 return bHasAxis;
210 }
211 return false;
212 }
213
setAxisVisible(const css::uno::Reference<css::frame::XModel> & xModel,AxisType eType,bool bVisible)214 void setAxisVisible(const css::uno::Reference<css::frame::XModel>& xModel, AxisType eType, bool bVisible)
215 {
216 Reference< chart2::XDiagram > xDiagram(ChartModelHelper::findDiagram(xModel));
217 if(!xDiagram.is())
218 return;
219
220 sal_Int32 nDimensionIndex = 0;
221 if (eType == AxisType::Y_MAIN || eType == AxisType::Y_SECOND)
222 nDimensionIndex = 1;
223 else if (eType == AxisType::Z_MAIN)
224 nDimensionIndex = 2;
225
226 bool bMajor = (eType != AxisType::X_SECOND && eType != AxisType::Y_SECOND);
227
228 if (bVisible)
229 AxisHelper::showAxis(nDimensionIndex, bMajor, xDiagram, comphelper::getProcessComponentContext());
230 else
231 AxisHelper::hideAxis(nDimensionIndex, bMajor, xDiagram);
232 }
233
getLegendPos(const css::uno::Reference<css::frame::XModel> & xModel)234 sal_Int32 getLegendPos(const css::uno::Reference<css::frame::XModel>& xModel)
235 {
236 ChartModel* pModel = getChartModel(xModel);
237 if (!pModel)
238 return -1;
239
240 Reference< beans::XPropertySet > xLegendProp( LegendHelper::getLegend(*pModel), uno::UNO_QUERY );
241 if (!xLegendProp.is())
242 return -1;
243
244 chart2::LegendPosition eLegendPos = chart2::LegendPosition_LINE_END;
245 xLegendProp->getPropertyValue("AnchorPosition") >>= eLegendPos;
246 switch(eLegendPos)
247 {
248 case chart2::LegendPosition_LINE_START:
249 return 3;
250 case chart2::LegendPosition_LINE_END:
251 return 0;
252 case chart2::LegendPosition_PAGE_START:
253 return 1;
254 case chart2::LegendPosition_PAGE_END:
255 return 2;
256 default:
257 return -1;
258 }
259 }
260
setLegendPos(const css::uno::Reference<css::frame::XModel> & xModel,sal_Int32 nPos)261 void setLegendPos(const css::uno::Reference<css::frame::XModel>& xModel, sal_Int32 nPos)
262 {
263 ChartModel* pModel = getChartModel(xModel);
264 if (!pModel)
265 return;
266
267 Reference< beans::XPropertySet > xLegendProp( LegendHelper::getLegend(*pModel), uno::UNO_QUERY );
268 if (!xLegendProp.is())
269 return;
270
271 chart2::LegendPosition eLegendPos = chart2::LegendPosition_LINE_END;
272 css::chart::ChartLegendExpansion eExpansion = css::chart::ChartLegendExpansion_HIGH;
273 switch(nPos)
274 {
275 case 1:
276 eLegendPos = chart2::LegendPosition_PAGE_START;
277 eExpansion = css::chart::ChartLegendExpansion_WIDE;
278 break;
279 case 3:
280 eLegendPos = chart2::LegendPosition_LINE_START;
281 break;
282 case 0:
283 eLegendPos = chart2::LegendPosition_LINE_END;
284 break;
285 case 2:
286 eLegendPos = chart2::LegendPosition_PAGE_END;
287 eExpansion = css::chart::ChartLegendExpansion_WIDE;
288 break;
289 default:
290 assert(false);
291 }
292
293 xLegendProp->setPropertyValue("AnchorPosition", css::uno::Any(eLegendPos));
294 xLegendProp->setPropertyValue("Expansion", css::uno::Any(eExpansion));
295 xLegendProp->setPropertyValue("RelativePosition", uno::Any());
296 }
297
298 }
299
ChartElementsPanel(weld::Widget * pParent,ChartController * pController)300 ChartElementsPanel::ChartElementsPanel(
301 weld::Widget* pParent, ChartController* pController)
302 : PanelLayout(pParent, "ChartElementsPanel", "modules/schart/ui/sidebarelements.ui")
303 , mxCBTitle(m_xBuilder->weld_check_button("checkbutton_title"))
304 , mxEditTitle(m_xBuilder->weld_entry("edit_title"))
305 , mxCBSubtitle(m_xBuilder->weld_check_button("checkbutton_subtitle"))
306 , mxEditSubtitle(m_xBuilder->weld_entry("edit_subtitle"))
307 , mxCBXAxis(m_xBuilder->weld_check_button("checkbutton_x_axis"))
308 , mxCBXAxisTitle(m_xBuilder->weld_check_button("checkbutton_x_axis_title"))
309 , mxCBYAxis(m_xBuilder->weld_check_button("checkbutton_y_axis"))
310 , mxCBYAxisTitle(m_xBuilder->weld_check_button("checkbutton_y_axis_title"))
311 , mxCBZAxis(m_xBuilder->weld_check_button("checkbutton_z_axis"))
312 , mxCBZAxisTitle(m_xBuilder->weld_check_button("checkbutton_z_axis_title"))
313 , mxCB2ndXAxis(m_xBuilder->weld_check_button("checkbutton_2nd_x_axis"))
314 , mxCB2ndXAxisTitle(m_xBuilder->weld_check_button("checkbutton_2nd_x_axis_title"))
315 , mxCB2ndYAxis(m_xBuilder->weld_check_button("checkbutton_2nd_y_axis"))
316 , mxCB2ndYAxisTitle(m_xBuilder->weld_check_button("checkbutton_2nd_y_axis_title"))
317 , mxCBLegend(m_xBuilder->weld_check_button("checkbutton_legend"))
318 , mxCBLegendNoOverlay(m_xBuilder->weld_check_button("checkbutton_no_overlay"))
319 , mxCBGridVerticalMajor(m_xBuilder->weld_check_button("checkbutton_gridline_vertical_major"))
320 , mxCBGridHorizontalMajor(m_xBuilder->weld_check_button("checkbutton_gridline_horizontal_major"))
321 , mxCBGridVerticalMinor(m_xBuilder->weld_check_button("checkbutton_gridline_vertical_minor"))
322 , mxCBGridHorizontalMinor(m_xBuilder->weld_check_button("checkbutton_gridline_horizontal_minor"))
323 , mxTextTitle(m_xBuilder->weld_label("text_title"))
324 , mxTextSubTitle(m_xBuilder->weld_label("text_subtitle"))
325 , mxLBAxis(m_xBuilder->weld_label("label_axes"))
326 , mxLBGrid(m_xBuilder->weld_label("label_gri"))
327 , mxLBLegendPosition(m_xBuilder->weld_combo_box("comboboxtext_legend"))
328 , mxBoxLegend(m_xBuilder->weld_widget("box_legend"))
329 , maContext()
330 , mxModel(pController->getModel())
331 , mxListener(new ChartSidebarModifyListener(this))
332 , mbModelValid(true)
333 {
334 maTextTitle = mxTextTitle->get_label();
335 maTextSubTitle = mxTextSubTitle->get_label();
336
337 Initialize();
338 }
339
~ChartElementsPanel()340 ChartElementsPanel::~ChartElementsPanel()
341 {
342 doUpdateModel(nullptr);
343
344 mxCBTitle.reset();
345 mxEditTitle.reset();
346 mxCBSubtitle.reset();
347 mxEditSubtitle.reset();
348 mxCBXAxis.reset();
349 mxCBXAxisTitle.reset();
350 mxCBYAxis.reset();
351 mxCBYAxisTitle.reset();
352 mxCBZAxis.reset();
353 mxCBZAxisTitle.reset();
354 mxCB2ndXAxis.reset();
355 mxCB2ndXAxisTitle.reset();
356 mxCB2ndYAxis.reset();
357 mxCB2ndYAxisTitle.reset();
358 mxCBLegend.reset();
359 mxCBLegendNoOverlay.reset();
360 mxCBGridVerticalMajor.reset();
361 mxCBGridHorizontalMajor.reset();
362 mxCBGridVerticalMinor.reset();
363 mxCBGridHorizontalMinor.reset();
364
365 mxLBLegendPosition.reset();
366 mxBoxLegend.reset();
367
368 mxLBAxis.reset();
369 mxLBGrid.reset();
370
371 mxTextTitle.reset();
372 mxTextSubTitle.reset();
373 }
374
Initialize()375 void ChartElementsPanel::Initialize()
376 {
377 css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
378 xBroadcaster->addModifyListener(mxListener);
379 updateData();
380
381 Link<weld::Toggleable&,void> aLink = LINK(this, ChartElementsPanel, CheckBoxHdl);
382 mxCBTitle->connect_toggled(aLink);
383 mxCBSubtitle->connect_toggled(aLink);
384 mxCBXAxis->connect_toggled(aLink);
385 mxCBXAxisTitle->connect_toggled(aLink);
386 mxCBYAxis->connect_toggled(aLink);
387 mxCBYAxisTitle->connect_toggled(aLink);
388 mxCBZAxis->connect_toggled(aLink);
389 mxCBZAxisTitle->connect_toggled(aLink);
390 mxCB2ndXAxis->connect_toggled(aLink);
391 mxCB2ndXAxisTitle->connect_toggled(aLink);
392 mxCB2ndYAxis->connect_toggled(aLink);
393 mxCB2ndYAxisTitle->connect_toggled(aLink);
394 mxCBLegend->connect_toggled(aLink);
395 mxCBLegendNoOverlay->connect_toggled(aLink);
396 mxCBGridVerticalMajor->connect_toggled(aLink);
397 mxCBGridHorizontalMajor->connect_toggled(aLink);
398 mxCBGridVerticalMinor->connect_toggled(aLink);
399 mxCBGridHorizontalMinor->connect_toggled(aLink);
400
401 mxLBLegendPosition->connect_changed(LINK(this, ChartElementsPanel, LegendPosHdl));
402
403 Link<weld::Entry&, void> aEditLink = LINK(this, ChartElementsPanel, EditHdl);
404 mxEditTitle->connect_changed(aEditLink);
405 mxEditSubtitle->connect_changed(aEditLink);
406 }
407
408 namespace {
409
getChartType(const css::uno::Reference<css::frame::XModel> & xModel)410 css::uno::Reference<css::chart2::XChartType> getChartType(const css::uno::Reference<css::frame::XModel>& xModel)
411 {
412 css::uno::Reference<css::chart2::XChartDocument> xChartDoc(xModel, css::uno::UNO_QUERY_THROW);
413 css::uno::Reference<chart2::XDiagram > xDiagram = xChartDoc->getFirstDiagram();
414 if (!xDiagram.is()) {
415 return css::uno::Reference<css::chart2::XChartType>();
416 }
417
418 css::uno::Reference<css::chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, css::uno::UNO_QUERY_THROW );
419
420 css::uno::Sequence<css::uno::Reference<css::chart2::XCoordinateSystem>> xCooSysSequence(xCooSysContainer->getCoordinateSystems());
421
422 if (!xCooSysSequence.hasElements())
423 return css::uno::Reference<css::chart2::XChartType>();
424
425 css::uno::Reference<css::chart2::XChartTypeContainer> xChartTypeContainer(xCooSysSequence[0], css::uno::UNO_QUERY_THROW);
426
427 css::uno::Sequence<css::uno::Reference<css::chart2::XChartType>> xChartTypeSequence(xChartTypeContainer->getChartTypes());
428
429 if (!xChartTypeSequence.hasElements())
430 return css::uno::Reference<css::chart2::XChartType>();
431
432 return xChartTypeSequence[0];
433 }
434
435 }
436
updateData()437 void ChartElementsPanel::updateData()
438 {
439 if (!mbModelValid)
440 return;
441
442 Reference< chart2::XDiagram > xDiagram(ChartModelHelper::findDiagram(mxModel));
443 sal_Int32 nDimension = DiagramHelper::getDimension(xDiagram);
444 SolarMutexGuard aGuard;
445
446 mxCBLegend->set_active(isLegendVisible(mxModel));
447 mxCBLegendNoOverlay->set_sensitive(isLegendVisible(mxModel));
448 mxCBLegendNoOverlay->set_active(!isLegendOverlay(mxModel));
449 mxBoxLegend->set_sensitive(isLegendVisible(mxModel));
450
451 bool hasTitle = isTitleVisible(mxModel, TitleHelper::MAIN_TITLE);
452 mxCBTitle->set_active(hasTitle);
453
454 OUString title = mxEditTitle->get_text();
455 OUString newTitle = TitleHelper::getCompleteString(TitleHelper::getTitle(TitleHelper::MAIN_TITLE, mxModel));
456 if (title != newTitle)
457 mxEditTitle->set_text(newTitle);
458 if (mxEditTitle->get_sensitive() != hasTitle)
459 mxEditTitle->set_sensitive(hasTitle);
460
461 bool hasSubtitle = isTitleVisible(mxModel, TitleHelper::SUB_TITLE);
462 mxCBSubtitle->set_active(hasSubtitle);
463
464 OUString subtitle = mxEditSubtitle->get_text();
465 OUString newSubtitle = TitleHelper::getCompleteString(TitleHelper::getTitle(TitleHelper::SUB_TITLE, mxModel));
466 if (subtitle != newSubtitle)
467 mxEditSubtitle->set_text(newSubtitle);
468 if (mxEditSubtitle->get_sensitive() != hasSubtitle)
469 mxEditSubtitle->set_sensitive(hasSubtitle);
470
471 mxCBXAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::X_AXIS_TITLE));
472 mxCBYAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::Y_AXIS_TITLE));
473 mxCBZAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::Z_AXIS_TITLE));
474 mxCB2ndXAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::SECONDARY_X_AXIS_TITLE));
475 mxCB2ndYAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::SECONDARY_Y_AXIS_TITLE));
476 mxCBGridVerticalMajor->set_active(isGridVisible(mxModel, GridType::VERT_MAJOR));
477 mxCBGridHorizontalMajor->set_active(isGridVisible(mxModel, GridType::HOR_MAJOR));
478 mxCBGridVerticalMinor->set_active(isGridVisible(mxModel, GridType::VERT_MINOR));
479 mxCBGridHorizontalMinor->set_active(isGridVisible(mxModel, GridType::HOR_MINOR));
480 mxCBXAxis->set_active(isAxisVisible(mxModel, AxisType::X_MAIN));
481 mxCBYAxis->set_active(isAxisVisible(mxModel, AxisType::Y_MAIN));
482 mxCBZAxis->set_active(isAxisVisible(mxModel, AxisType::Z_MAIN));
483 mxCB2ndXAxis->set_active(isAxisVisible(mxModel, AxisType::X_SECOND));
484 mxCB2ndYAxis->set_active(isAxisVisible(mxModel, AxisType::Y_SECOND));
485
486 bool bSupportsMainAxis = ChartTypeHelper::isSupportingMainAxis(
487 getChartType(mxModel), 0, 0);
488 if (bSupportsMainAxis)
489 {
490 mxCBXAxis->show();
491 mxCBYAxis->show();
492 mxCBZAxis->show();
493 mxCBXAxisTitle->show();
494 mxCBYAxisTitle->show();
495 mxCBZAxisTitle->show();
496 mxCBGridVerticalMajor->show();
497 mxCBGridVerticalMinor->show();
498 mxCBGridHorizontalMajor->show();
499 mxCBGridHorizontalMinor->show();
500 mxLBAxis->show();
501 mxLBGrid->show();
502 }
503 else
504 {
505 mxCBXAxis->hide();
506 mxCBYAxis->hide();
507 mxCBZAxis->hide();
508 mxCBXAxisTitle->hide();
509 mxCBYAxisTitle->hide();
510 mxCBZAxisTitle->hide();
511 mxCBGridVerticalMajor->hide();
512 mxCBGridVerticalMinor->hide();
513 mxCBGridHorizontalMajor->hide();
514 mxCBGridHorizontalMinor->hide();
515 mxLBAxis->hide();
516 mxLBGrid->hide();
517 }
518
519 if (nDimension == 3)
520 {
521 mxCBZAxis->set_sensitive(true);
522 mxCBZAxisTitle->set_sensitive(true);
523 }
524 else
525 {
526 mxCBZAxis->set_sensitive(false);
527 mxCBZAxisTitle->set_sensitive(false);
528 }
529
530 mxLBLegendPosition->set_active(getLegendPos(mxModel));
531 }
532
Create(weld::Widget * pParent,ChartController * pController)533 std::unique_ptr<PanelLayout> ChartElementsPanel::Create (
534 weld::Widget* pParent,
535 ChartController* pController)
536 {
537 if (pParent == nullptr)
538 throw lang::IllegalArgumentException("no parent Window given to ChartElementsPanel::Create", nullptr, 0);
539 return std::make_unique<ChartElementsPanel>(pParent, pController);
540 }
541
DataChanged(const DataChangedEvent & rEvent)542 void ChartElementsPanel::DataChanged(const DataChangedEvent& rEvent)
543 {
544 PanelLayout::DataChanged(rEvent);
545 updateData();
546 }
547
HandleContextChange(const vcl::EnumContext & rContext)548 void ChartElementsPanel::HandleContextChange(
549 const vcl::EnumContext& rContext)
550 {
551 if(maContext == rContext)
552 {
553 // Nothing to do.
554 return;
555 }
556
557 maContext = rContext;
558 updateData();
559 }
560
modelInvalid()561 void ChartElementsPanel::modelInvalid()
562 {
563 mbModelValid = false;
564 }
565
doUpdateModel(css::uno::Reference<css::frame::XModel> xModel)566 void ChartElementsPanel::doUpdateModel(css::uno::Reference<css::frame::XModel> xModel)
567 {
568 if (mbModelValid)
569 {
570 css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
571 xBroadcaster->removeModifyListener(mxListener);
572 }
573
574 mxModel = xModel;
575 mbModelValid = mxModel.is();
576
577 if (!mbModelValid)
578 return;
579
580 css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW);
581 xBroadcasterNew->addModifyListener(mxListener);
582 }
583
updateModel(css::uno::Reference<css::frame::XModel> xModel)584 void ChartElementsPanel::updateModel(css::uno::Reference<css::frame::XModel> xModel)
585 {
586 doUpdateModel(xModel);
587 }
588
IMPL_LINK(ChartElementsPanel,CheckBoxHdl,weld::Toggleable &,rCheckBox,void)589 IMPL_LINK(ChartElementsPanel, CheckBoxHdl, weld::Toggleable&, rCheckBox, void)
590 {
591 bool bChecked = rCheckBox.get_active();
592 if (&rCheckBox == mxCBTitle.get())
593 setTitleVisible(TitleHelper::MAIN_TITLE, bChecked);
594 else if (&rCheckBox == mxCBSubtitle.get())
595 setTitleVisible(TitleHelper::SUB_TITLE, bChecked);
596 else if (&rCheckBox == mxCBXAxis.get())
597 setAxisVisible(mxModel, AxisType::X_MAIN, bChecked);
598 else if (&rCheckBox == mxCBXAxisTitle.get())
599 setTitleVisible(TitleHelper::X_AXIS_TITLE, bChecked);
600 else if (&rCheckBox == mxCBYAxis.get())
601 setAxisVisible(mxModel, AxisType::Y_MAIN, bChecked);
602 else if (&rCheckBox == mxCBYAxisTitle.get())
603 setTitleVisible(TitleHelper::Y_AXIS_TITLE, bChecked);
604 else if (&rCheckBox == mxCBZAxis.get())
605 setAxisVisible(mxModel, AxisType::Z_MAIN, bChecked);
606 else if (&rCheckBox == mxCBZAxisTitle.get())
607 setTitleVisible(TitleHelper::Z_AXIS_TITLE, bChecked);
608 else if (&rCheckBox == mxCB2ndXAxis.get())
609 setAxisVisible(mxModel, AxisType::X_SECOND, bChecked);
610 else if (&rCheckBox == mxCB2ndXAxisTitle.get())
611 setTitleVisible(TitleHelper::SECONDARY_X_AXIS_TITLE, bChecked);
612 else if (&rCheckBox == mxCB2ndYAxis.get())
613 setAxisVisible(mxModel, AxisType::Y_SECOND, bChecked);
614 else if (&rCheckBox == mxCB2ndYAxisTitle.get())
615 setTitleVisible(TitleHelper::SECONDARY_Y_AXIS_TITLE, bChecked);
616 else if (&rCheckBox == mxCBLegend.get())
617 {
618 mxBoxLegend->set_sensitive(bChecked);
619 mxCBLegendNoOverlay->set_sensitive(bChecked);
620 setLegendVisible(mxModel, bChecked);
621 }
622 else if (&rCheckBox == mxCBLegendNoOverlay.get())
623 setLegendOverlay(mxModel, !bChecked);
624 else if (&rCheckBox == mxCBGridVerticalMajor.get())
625 setGridVisible(mxModel, GridType::VERT_MAJOR, bChecked);
626 else if (&rCheckBox == mxCBGridHorizontalMajor.get())
627 setGridVisible(mxModel, GridType::HOR_MAJOR, bChecked);
628 else if (&rCheckBox == mxCBGridVerticalMinor.get())
629 setGridVisible(mxModel, GridType::VERT_MINOR, bChecked);
630 else if (&rCheckBox == mxCBGridHorizontalMinor.get())
631 setGridVisible(mxModel, GridType::HOR_MINOR, bChecked);
632 }
633
IMPL_LINK(ChartElementsPanel,EditHdl,weld::Entry &,rEdit,void)634 IMPL_LINK(ChartElementsPanel, EditHdl, weld::Entry&, rEdit, void)
635 {
636 // title or subtitle?
637 TitleHelper::eTitleType aTitleType = TitleHelper::MAIN_TITLE;
638 if (&rEdit == mxEditSubtitle.get())
639 aTitleType = TitleHelper::SUB_TITLE;
640
641 // set it
642 OUString aText(rEdit.get_text());
643 TitleHelper::setCompleteString(aText, TitleHelper::getTitle(aTitleType, mxModel), comphelper::getProcessComponentContext());
644 }
645
IMPL_LINK_NOARG(ChartElementsPanel,LegendPosHdl,weld::ComboBox &,void)646 IMPL_LINK_NOARG(ChartElementsPanel, LegendPosHdl, weld::ComboBox&, void)
647 {
648 sal_Int32 nPos = mxLBLegendPosition->get_active();
649 setLegendPos(mxModel, nPos);
650 }
651
setTitleVisible(TitleHelper::eTitleType eTitle,bool bVisible)652 void ChartElementsPanel::setTitleVisible(TitleHelper::eTitleType eTitle, bool bVisible)
653 {
654 if (bVisible)
655 {
656 OUString aText = eTitle == TitleHelper::SUB_TITLE ? maTextSubTitle : maTextTitle;
657 TitleHelper::createOrShowTitle(eTitle, aText, mxModel, comphelper::getProcessComponentContext());
658 }
659 else
660 {
661 TitleHelper::hideTitle(eTitle, mxModel);
662 }
663 }
664
665 } // end of namespace ::chart::sidebar
666
667 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
668