/src/libreoffice/sc/source/ui/dialogs/SparklineDialog.cxx
Line | Count | Source |
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 | | |
10 | | #include <SparklineDialog.hxx> |
11 | | #include <SparklineData.hxx> |
12 | | #include <SparklineGroup.hxx> |
13 | | #include <Sparkline.hxx> |
14 | | #include <reffact.hxx> |
15 | | |
16 | | #include <docfunc.hxx> |
17 | | |
18 | | #include <svx/colorbox.hxx> |
19 | | #include <vcl/formatter.hxx> |
20 | | |
21 | | namespace sc |
22 | | { |
23 | | SparklineDialog::SparklineDialog(SfxBindings* pBindings, SfxChildWindow* pChildWindow, |
24 | | weld::Window* pWindow, ScViewData& rViewData) |
25 | 0 | : ScAnyRefDlgController(pBindings, pChildWindow, pWindow, |
26 | 0 | u"modules/scalc/ui/sparklinedialog.ui"_ustr, u"SparklineDialog"_ustr) |
27 | 0 | , mrViewData(rViewData) |
28 | 0 | , mrDocument(rViewData.GetDocument()) |
29 | 0 | , mpActiveEdit(nullptr) |
30 | 0 | , mbDialogLostFocus(false) |
31 | 0 | , mxButtonOk(m_xBuilder->weld_button(u"ok"_ustr)) |
32 | 0 | , mxButtonCancel(m_xBuilder->weld_button(u"cancel"_ustr)) |
33 | 0 | , mxFrameData(m_xBuilder->weld_frame(u"frmData"_ustr)) |
34 | 0 | , mxInputRangeLabel(m_xBuilder->weld_label(u"lbInputRange"_ustr)) |
35 | 0 | , mxInputRangeEdit(new formula::RefEdit(m_xBuilder->weld_entry(u"edInputRange"_ustr))) |
36 | 0 | , mxInputRangeButton(new formula::RefButton(m_xBuilder->weld_button(u"btnInputRange"_ustr))) |
37 | 0 | , mxOutputRangeLabel(m_xBuilder->weld_label(u"lbOutputRange"_ustr)) |
38 | 0 | , mxOutputRangeEdit(new formula::RefEdit(m_xBuilder->weld_entry(u"edOutputRange"_ustr))) |
39 | 0 | , mxOutputRangeButton(new formula::RefButton(m_xBuilder->weld_button(u"btnOutputRange"_ustr))) |
40 | 0 | , mxColorSeries(new ColorListBox(m_xBuilder->weld_menu_button(u"colSeries"_ustr), |
41 | 0 | [pWindow] { return pWindow; })) |
42 | 0 | , mxColorNegative(new ColorListBox(m_xBuilder->weld_menu_button(u"colNegative"_ustr), |
43 | 0 | [pWindow] { return pWindow; })) |
44 | 0 | , mxColorMarker(new ColorListBox(m_xBuilder->weld_menu_button(u"colMarker"_ustr), |
45 | 0 | [pWindow] { return pWindow; })) |
46 | 0 | , mxColorHigh(new ColorListBox(m_xBuilder->weld_menu_button(u"colHigh"_ustr), |
47 | 0 | [pWindow] { return pWindow; })) |
48 | 0 | , mxColorLow(new ColorListBox(m_xBuilder->weld_menu_button(u"colLow"_ustr), |
49 | 0 | [pWindow] { return pWindow; })) |
50 | 0 | , mxColorFirst(new ColorListBox(m_xBuilder->weld_menu_button(u"colFirst"_ustr), |
51 | 0 | [pWindow] { return pWindow; })) |
52 | 0 | , mxColorLast(new ColorListBox(m_xBuilder->weld_menu_button(u"colLast"_ustr), |
53 | 0 | [pWindow] { return pWindow; })) |
54 | 0 | , mxCheckButtonNegative(m_xBuilder->weld_check_button(u"cbNegative"_ustr)) |
55 | 0 | , mxCheckButtonMarker(m_xBuilder->weld_check_button(u"cbMarker"_ustr)) |
56 | 0 | , mxCheckButtonHigh(m_xBuilder->weld_check_button(u"cbHigh"_ustr)) |
57 | 0 | , mxCheckButtonLow(m_xBuilder->weld_check_button(u"cbLow"_ustr)) |
58 | 0 | , mxCheckButtonFirst(m_xBuilder->weld_check_button(u"cbFirst"_ustr)) |
59 | 0 | , mxCheckButtonLast(m_xBuilder->weld_check_button(u"cbLast"_ustr)) |
60 | 0 | , mxSpinLineWidth(m_xBuilder->weld_spin_button(u"seLineWidth"_ustr)) |
61 | 0 | , mxType(m_xBuilder->weld_combo_box(u"cbType"_ustr)) |
62 | 0 | , mxCheckDisplayXAxis(m_xBuilder->weld_check_button(u"cbDisplayXAxis"_ustr)) |
63 | 0 | , mxCheckDisplayHidden(m_xBuilder->weld_check_button(u"cbHidden"_ustr)) |
64 | 0 | , mxCheckRightToLeft(m_xBuilder->weld_check_button(u"cbRTL"_ustr)) |
65 | 0 | , mxDisplayEmptyGap(m_xBuilder->weld_combo_box(u"cbEmptyCells"_ustr)) |
66 | 0 | , mxComboMinAxisType(m_xBuilder->weld_combo_box(u"cbMinAxisType"_ustr)) |
67 | 0 | , mxComboMaxAxisType(m_xBuilder->weld_combo_box(u"cbMaxAxisType"_ustr)) |
68 | 0 | , mxSpinCustomMin(m_xBuilder->weld_formatted_spin_button(u"seMinAxis"_ustr)) |
69 | 0 | , mxSpinCustomMax(m_xBuilder->weld_formatted_spin_button(u"seMaxAxis"_ustr)) |
70 | 0 | , mbEditMode(false) |
71 | 0 | { |
72 | 0 | mxInputRangeEdit->SetReferences(this, mxInputRangeLabel.get()); |
73 | 0 | mxInputRangeButton->SetReferences(this, mxInputRangeEdit.get()); |
74 | |
|
75 | 0 | mxOutputRangeEdit->SetReferences(this, mxOutputRangeLabel.get()); |
76 | 0 | mxOutputRangeButton->SetReferences(this, mxOutputRangeEdit.get()); |
77 | |
|
78 | 0 | mxButtonCancel->connect_clicked(LINK(this, SparklineDialog, ButtonClicked)); |
79 | 0 | mxButtonOk->connect_clicked(LINK(this, SparklineDialog, ButtonClicked)); |
80 | 0 | mxButtonOk->set_sensitive(false); |
81 | |
|
82 | 0 | Link<formula::RefEdit&, void> aEditLink = LINK(this, SparklineDialog, EditFocusHandler); |
83 | 0 | mxInputRangeEdit->SetGetFocusHdl(aEditLink); |
84 | 0 | mxOutputRangeEdit->SetGetFocusHdl(aEditLink); |
85 | 0 | aEditLink = LINK(this, SparklineDialog, LoseEditFocusHandler); |
86 | 0 | mxInputRangeEdit->SetLoseFocusHdl(aEditLink); |
87 | 0 | mxOutputRangeEdit->SetLoseFocusHdl(aEditLink); |
88 | |
|
89 | 0 | Link<formula::RefButton&, void> aButtonLink = LINK(this, SparklineDialog, ButtonFocusHandler); |
90 | 0 | mxInputRangeButton->SetGetFocusHdl(aButtonLink); |
91 | 0 | mxOutputRangeButton->SetGetFocusHdl(aButtonLink); |
92 | 0 | aButtonLink = LINK(this, SparklineDialog, LoseButtonFocusHandler); |
93 | 0 | mxInputRangeButton->SetLoseFocusHdl(aButtonLink); |
94 | 0 | mxOutputRangeButton->SetLoseFocusHdl(aButtonLink); |
95 | |
|
96 | 0 | Link<formula::RefEdit&, void> aModifyLink = LINK(this, SparklineDialog, RefInputModifyHandler); |
97 | 0 | mxInputRangeEdit->SetModifyHdl(aModifyLink); |
98 | 0 | mxOutputRangeEdit->SetModifyHdl(aModifyLink); |
99 | |
|
100 | 0 | mxType->connect_changed(LINK(this, SparklineDialog, SelectSparklineType)); |
101 | 0 | mxDisplayEmptyGap->connect_changed(LINK(this, SparklineDialog, SelectSparklineType)); |
102 | |
|
103 | 0 | Link<weld::Toggleable&, void> aLink = LINK(this, SparklineDialog, ToggleHandler); |
104 | 0 | mxCheckButtonNegative->connect_toggled(aLink); |
105 | 0 | mxCheckButtonMarker->connect_toggled(aLink); |
106 | 0 | mxCheckButtonHigh->connect_toggled(aLink); |
107 | 0 | mxCheckButtonLow->connect_toggled(aLink); |
108 | 0 | mxCheckButtonFirst->connect_toggled(aLink); |
109 | 0 | mxCheckButtonLast->connect_toggled(aLink); |
110 | 0 | mxCheckDisplayXAxis->connect_toggled(aLink); |
111 | 0 | mxCheckDisplayHidden->connect_toggled(aLink); |
112 | 0 | mxCheckRightToLeft->connect_toggled(aLink); |
113 | |
|
114 | 0 | mxSpinLineWidth->connect_value_changed(LINK(this, SparklineDialog, SpinLineWidthChanged)); |
115 | |
|
116 | 0 | mxComboMinAxisType->connect_changed(LINK(this, SparklineDialog, ComboValueChanged)); |
117 | 0 | mxComboMaxAxisType->connect_changed(LINK(this, SparklineDialog, ComboValueChanged)); |
118 | |
|
119 | 0 | mxSpinCustomMin->connect_value_changed(LINK(this, SparklineDialog, SpinCustomChanged)); |
120 | 0 | Formatter& rSpinCustomMinFormatter = mxSpinCustomMin->GetFormatter(); |
121 | 0 | rSpinCustomMinFormatter.ClearMinValue(); |
122 | 0 | rSpinCustomMinFormatter.ClearMaxValue(); |
123 | 0 | rSpinCustomMinFormatter.UseInputStringForFormatting(); |
124 | |
|
125 | 0 | mxSpinCustomMax->connect_value_changed(LINK(this, SparklineDialog, SpinCustomChanged)); |
126 | 0 | Formatter& rSpinCustomMaxFormatter = mxSpinCustomMax->GetFormatter(); |
127 | 0 | rSpinCustomMaxFormatter.ClearMinValue(); |
128 | 0 | rSpinCustomMaxFormatter.ClearMaxValue(); |
129 | 0 | rSpinCustomMaxFormatter.UseInputStringForFormatting(); |
130 | |
|
131 | 0 | setupValues(); |
132 | |
|
133 | 0 | mxOutputRangeEdit->GrabFocus(); |
134 | 0 | mxButtonOk->set_sensitive(checkValidInputOutput()); |
135 | 0 | } |
136 | | |
137 | 0 | SparklineDialog::~SparklineDialog() = default; |
138 | | |
139 | | void SparklineDialog::setInputSelection() |
140 | 0 | { |
141 | 0 | mrViewData.GetSimpleArea(maInputRange); |
142 | 0 | OUString aString = maInputRange.Format(mrDocument, ScRefFlags::VALID | ScRefFlags::TAB_3D, |
143 | 0 | mrDocument.GetAddressConvention()); |
144 | 0 | mxInputRangeEdit->SetRefString(aString); |
145 | 0 | } |
146 | | |
147 | | void SparklineDialog::setupValues() |
148 | 0 | { |
149 | 0 | ScRange aSelectionRange; |
150 | 0 | mrViewData.GetSimpleArea(aSelectionRange); |
151 | |
|
152 | 0 | if (mrDocument.HasOneSparklineGroup(aSelectionRange)) |
153 | 0 | { |
154 | 0 | if (auto pSparkline = mrDocument.GetSparkline(aSelectionRange.aStart)) |
155 | 0 | { |
156 | 0 | mpSparklineGroup = pSparkline->getSparklineGroup(); |
157 | 0 | maAttributes = mpSparklineGroup->getAttributes(); |
158 | 0 | mxFrameData->set_visible(false); |
159 | 0 | mbEditMode = true; |
160 | 0 | } |
161 | 0 | } |
162 | 0 | else |
163 | 0 | { |
164 | 0 | maInputRange = aSelectionRange; |
165 | 0 | } |
166 | |
|
167 | 0 | setInputSelection(); |
168 | |
|
169 | 0 | switch (maAttributes.getType()) |
170 | 0 | { |
171 | 0 | case sc::SparklineType::Line: |
172 | 0 | mxType->set_active(0); |
173 | 0 | break; |
174 | 0 | case sc::SparklineType::Column: |
175 | 0 | mxType->set_active(1); |
176 | 0 | break; |
177 | 0 | case sc::SparklineType::Stacked: |
178 | 0 | mxType->set_active(2); |
179 | 0 | break; |
180 | 0 | } |
181 | | |
182 | 0 | switch (maAttributes.getDisplayEmptyCellsAs()) |
183 | 0 | { |
184 | 0 | case sc::DisplayEmptyCellsAs::Gap: |
185 | 0 | mxDisplayEmptyGap->set_active(0); |
186 | 0 | break; |
187 | 0 | case sc::DisplayEmptyCellsAs::Zero: |
188 | 0 | mxDisplayEmptyGap->set_active(1); |
189 | 0 | break; |
190 | 0 | case sc::DisplayEmptyCellsAs::Span: |
191 | 0 | mxDisplayEmptyGap->set_active(2); |
192 | 0 | break; |
193 | 0 | } |
194 | | |
195 | 0 | mxColorSeries->SelectEntry(maAttributes.getColorSeries().getFinalColor()); |
196 | 0 | mxColorNegative->SelectEntry(maAttributes.getColorNegative().getFinalColor()); |
197 | 0 | mxColorMarker->SelectEntry(maAttributes.getColorMarkers().getFinalColor()); |
198 | 0 | mxColorHigh->SelectEntry(maAttributes.getColorHigh().getFinalColor()); |
199 | 0 | mxColorLow->SelectEntry(maAttributes.getColorLow().getFinalColor()); |
200 | 0 | mxColorFirst->SelectEntry(maAttributes.getColorFirst().getFinalColor()); |
201 | 0 | mxColorLast->SelectEntry(maAttributes.getColorLast().getFinalColor()); |
202 | |
|
203 | 0 | mxCheckButtonNegative->set_active(maAttributes.isNegative()); |
204 | 0 | mxCheckButtonMarker->set_active(maAttributes.isMarkers()); |
205 | 0 | mxCheckButtonHigh->set_active(maAttributes.isHigh()); |
206 | 0 | mxCheckButtonLow->set_active(maAttributes.isLow()); |
207 | 0 | mxCheckButtonFirst->set_active(maAttributes.isFirst()); |
208 | 0 | mxCheckButtonLast->set_active(maAttributes.isLast()); |
209 | |
|
210 | 0 | mxSpinLineWidth->set_value(sal_Int64(maAttributes.getLineWeight() * 100.0)); |
211 | |
|
212 | 0 | mxCheckDisplayXAxis->set_active(maAttributes.shouldDisplayXAxis()); |
213 | 0 | mxCheckDisplayHidden->set_active(maAttributes.shouldDisplayHidden()); |
214 | 0 | mxCheckRightToLeft->set_active(maAttributes.isRightToLeft()); |
215 | |
|
216 | 0 | switch (maAttributes.getMinAxisType()) |
217 | 0 | { |
218 | 0 | case sc::AxisType::Individual: |
219 | 0 | mxComboMinAxisType->set_active(0); |
220 | 0 | mxSpinCustomMin->GetFormatter().SetValue(0.0); |
221 | 0 | break; |
222 | 0 | case sc::AxisType::Group: |
223 | 0 | mxComboMinAxisType->set_active(1); |
224 | 0 | mxSpinCustomMin->GetFormatter().SetValue(0.0); |
225 | 0 | break; |
226 | 0 | case sc::AxisType::Custom: |
227 | 0 | mxComboMinAxisType->set_active(2); |
228 | 0 | if (maAttributes.getManualMin()) |
229 | 0 | mxSpinCustomMin->GetFormatter().SetValue(*maAttributes.getManualMin()); |
230 | 0 | break; |
231 | 0 | } |
232 | 0 | ComboValueChanged(*mxComboMinAxisType); |
233 | |
|
234 | 0 | switch (maAttributes.getMaxAxisType()) |
235 | 0 | { |
236 | 0 | case sc::AxisType::Individual: |
237 | 0 | mxComboMaxAxisType->set_active(0); |
238 | 0 | mxSpinCustomMax->GetFormatter().SetValue(0.0); |
239 | 0 | break; |
240 | 0 | case sc::AxisType::Group: |
241 | 0 | mxComboMaxAxisType->set_active(1); |
242 | 0 | mxSpinCustomMax->GetFormatter().SetValue(0.0); |
243 | 0 | break; |
244 | 0 | case sc::AxisType::Custom: |
245 | 0 | mxComboMaxAxisType->set_active(2); |
246 | 0 | if (maAttributes.getManualMax()) |
247 | 0 | mxSpinCustomMax->GetFormatter().SetValue(*maAttributes.getManualMax()); |
248 | 0 | break; |
249 | 0 | } |
250 | 0 | ComboValueChanged(*mxComboMaxAxisType); |
251 | 0 | } |
252 | | |
253 | 0 | void SparklineDialog::Close() { DoClose(sc::SparklineDialogWrapper::GetChildWindowId()); } |
254 | | |
255 | | void SparklineDialog::SetActive() |
256 | 0 | { |
257 | 0 | if (mbDialogLostFocus) |
258 | 0 | { |
259 | 0 | mbDialogLostFocus = false; |
260 | 0 | if (mpActiveEdit) |
261 | 0 | mpActiveEdit->GrabFocus(); |
262 | 0 | } |
263 | 0 | else |
264 | 0 | { |
265 | 0 | m_xDialog->grab_focus(); |
266 | 0 | } |
267 | 0 | RefInputDone(); |
268 | 0 | } |
269 | | |
270 | | void SparklineDialog::SetReference(const ScRange& rReferenceRange, ScDocument& rDocument) |
271 | 0 | { |
272 | 0 | if (mpActiveEdit) |
273 | 0 | { |
274 | 0 | if (rReferenceRange.aStart != rReferenceRange.aEnd) |
275 | 0 | RefInputStart(mpActiveEdit); |
276 | |
|
277 | 0 | OUString aString; |
278 | 0 | const ScRefFlags eFlags = ScRefFlags::VALID | ScRefFlags::TAB_3D; |
279 | 0 | auto eAddressConvention = rDocument.GetAddressConvention(); |
280 | |
|
281 | 0 | if (mpActiveEdit == mxInputRangeEdit.get()) |
282 | 0 | { |
283 | 0 | maInputRange = rReferenceRange; |
284 | 0 | aString = maInputRange.Format(rDocument, eFlags, eAddressConvention); |
285 | 0 | mxInputRangeEdit->SetRefString(aString); |
286 | 0 | } |
287 | 0 | else if (mpActiveEdit == mxOutputRangeEdit.get()) |
288 | 0 | { |
289 | 0 | maOutputRange = rReferenceRange; |
290 | 0 | aString = maOutputRange.Format(rDocument, eFlags, eAddressConvention); |
291 | 0 | mxOutputRangeEdit->SetRefString(aString); |
292 | 0 | } |
293 | 0 | } |
294 | |
|
295 | 0 | mxButtonOk->set_sensitive(checkValidInputOutput()); |
296 | 0 | } |
297 | | |
298 | | IMPL_LINK(SparklineDialog, EditFocusHandler, formula::RefEdit&, rEdit, void) |
299 | 0 | { |
300 | 0 | auto* pEdit = &rEdit; |
301 | |
|
302 | 0 | if (mxInputRangeEdit.get() == pEdit) |
303 | 0 | mpActiveEdit = mxInputRangeEdit.get(); |
304 | 0 | else if (mxOutputRangeEdit.get() == pEdit) |
305 | 0 | mpActiveEdit = mxOutputRangeEdit.get(); |
306 | 0 | else |
307 | 0 | mpActiveEdit = nullptr; |
308 | |
|
309 | 0 | if (mpActiveEdit) |
310 | 0 | mpActiveEdit->SelectAll(); |
311 | 0 | } |
312 | | |
313 | | IMPL_LINK(SparklineDialog, ButtonFocusHandler, formula::RefButton&, rButton, void) |
314 | 0 | { |
315 | 0 | auto* pButton = &rButton; |
316 | |
|
317 | 0 | if (mxInputRangeButton.get() == pButton) |
318 | 0 | mpActiveEdit = mxInputRangeEdit.get(); |
319 | 0 | else if (mxOutputRangeButton.get() == pButton) |
320 | 0 | mpActiveEdit = mxOutputRangeEdit.get(); |
321 | 0 | else |
322 | 0 | mpActiveEdit = nullptr; |
323 | |
|
324 | 0 | if (mpActiveEdit) |
325 | 0 | mpActiveEdit->SelectAll(); |
326 | 0 | } |
327 | | |
328 | | IMPL_LINK_NOARG(SparklineDialog, LoseEditFocusHandler, formula::RefEdit&, void) |
329 | 0 | { |
330 | 0 | mbDialogLostFocus = !m_xDialog->has_toplevel_focus(); |
331 | 0 | } |
332 | | |
333 | | IMPL_LINK_NOARG(SparklineDialog, LoseButtonFocusHandler, formula::RefButton&, void) |
334 | 0 | { |
335 | 0 | mbDialogLostFocus = !m_xDialog->has_toplevel_focus(); |
336 | 0 | } |
337 | | |
338 | | IMPL_LINK_NOARG(SparklineDialog, RefInputModifyHandler, formula::RefEdit&, void) |
339 | 0 | { |
340 | 0 | if (mpActiveEdit) |
341 | 0 | { |
342 | 0 | if (mpActiveEdit == mxInputRangeEdit.get()) |
343 | 0 | { |
344 | 0 | ScRangeList aRangeList; |
345 | 0 | bool bValid = ParseWithNames(aRangeList, mxInputRangeEdit->GetText(), mrDocument); |
346 | 0 | const ScRange* pRange = (bValid && aRangeList.size() == 1) ? &aRangeList[0] : nullptr; |
347 | 0 | if (pRange) |
348 | 0 | { |
349 | 0 | maInputRange = *pRange; |
350 | 0 | mxInputRangeEdit->StartUpdateData(); |
351 | 0 | } |
352 | 0 | else |
353 | 0 | { |
354 | 0 | maInputRange = ScRange(ScAddress::INITIALIZE_INVALID); |
355 | 0 | } |
356 | 0 | } |
357 | 0 | else if (mpActiveEdit == mxOutputRangeEdit.get()) |
358 | 0 | { |
359 | 0 | ScRangeList aRangeList; |
360 | 0 | bool bValid = ParseWithNames(aRangeList, mxOutputRangeEdit->GetText(), mrDocument); |
361 | 0 | const ScRange* pRange = (bValid && aRangeList.size() == 1) ? &aRangeList[0] : nullptr; |
362 | 0 | if (pRange) |
363 | 0 | { |
364 | 0 | maOutputRange = *pRange; |
365 | 0 | mxOutputRangeEdit->StartUpdateData(); |
366 | 0 | } |
367 | 0 | else |
368 | 0 | { |
369 | 0 | maOutputRange = ScRange(ScAddress::INITIALIZE_INVALID); |
370 | 0 | } |
371 | 0 | } |
372 | 0 | } |
373 | |
|
374 | 0 | mxButtonOk->set_sensitive(checkValidInputOutput()); |
375 | 0 | } |
376 | | |
377 | | IMPL_LINK(SparklineDialog, ButtonClicked, weld::Button&, rButton, void) |
378 | 0 | { |
379 | 0 | if (mxButtonOk.get() == &rButton) |
380 | 0 | { |
381 | 0 | perform(); |
382 | 0 | response(RET_OK); |
383 | 0 | } |
384 | 0 | else |
385 | 0 | { |
386 | 0 | response(RET_CANCEL); |
387 | 0 | } |
388 | 0 | } |
389 | | |
390 | | IMPL_LINK(SparklineDialog, ToggleHandler, weld::Toggleable&, rToggle, void) |
391 | 0 | { |
392 | 0 | if (mxCheckButtonNegative.get() == &rToggle) |
393 | 0 | maAttributes.setNegative(mxCheckButtonNegative->get_active()); |
394 | 0 | if (mxCheckButtonMarker.get() == &rToggle) |
395 | 0 | maAttributes.setMarkers(mxCheckButtonMarker->get_active()); |
396 | 0 | if (mxCheckButtonHigh.get() == &rToggle) |
397 | 0 | maAttributes.setHigh(mxCheckButtonHigh->get_active()); |
398 | 0 | if (mxCheckButtonLow.get() == &rToggle) |
399 | 0 | maAttributes.setLow(mxCheckButtonLow->get_active()); |
400 | 0 | if (mxCheckButtonFirst.get() == &rToggle) |
401 | 0 | maAttributes.setFirst(mxCheckButtonFirst->get_active()); |
402 | 0 | if (mxCheckButtonLast.get() == &rToggle) |
403 | 0 | maAttributes.setLast(mxCheckButtonLast->get_active()); |
404 | 0 | if (mxCheckDisplayXAxis.get() == &rToggle) |
405 | 0 | maAttributes.setDisplayXAxis(mxCheckDisplayXAxis->get_active()); |
406 | 0 | if (mxCheckDisplayHidden.get() == &rToggle) |
407 | 0 | maAttributes.setDisplayHidden(mxCheckDisplayHidden->get_active()); |
408 | 0 | if (mxCheckRightToLeft.get() == &rToggle) |
409 | 0 | maAttributes.setRightToLeft(mxCheckRightToLeft->get_active()); |
410 | 0 | } |
411 | | |
412 | | IMPL_LINK_NOARG(SparklineDialog, SelectSparklineType, weld::ComboBox&, void) |
413 | 0 | { |
414 | 0 | switch (mxType->get_active()) |
415 | 0 | { |
416 | 0 | case 0: |
417 | 0 | maAttributes.setType(sc::SparklineType::Line); |
418 | 0 | break; |
419 | 0 | case 1: |
420 | 0 | maAttributes.setType(sc::SparklineType::Column); |
421 | 0 | break; |
422 | 0 | case 2: |
423 | 0 | maAttributes.setType(sc::SparklineType::Stacked); |
424 | 0 | break; |
425 | 0 | } |
426 | 0 | switch (mxDisplayEmptyGap->get_active()) |
427 | 0 | { |
428 | 0 | case 1: |
429 | 0 | maAttributes.setDisplayEmptyCellsAs(sc::DisplayEmptyCellsAs::Gap); |
430 | 0 | break; |
431 | 0 | case 2: |
432 | 0 | maAttributes.setDisplayEmptyCellsAs(sc::DisplayEmptyCellsAs::Zero); |
433 | 0 | break; |
434 | 0 | case 3: |
435 | 0 | maAttributes.setDisplayEmptyCellsAs(sc::DisplayEmptyCellsAs::Span); |
436 | 0 | break; |
437 | 0 | } |
438 | 0 | } |
439 | | |
440 | | IMPL_LINK_NOARG(SparklineDialog, SpinLineWidthChanged, weld::SpinButton&, void) |
441 | 0 | { |
442 | 0 | double value = mxSpinLineWidth->get_value() / 100.0; |
443 | 0 | maAttributes.setLineWeight(value); |
444 | 0 | } |
445 | | |
446 | | IMPL_LINK(SparklineDialog, SpinCustomChanged, weld::FormattedSpinButton&, rFormatted, void) |
447 | 0 | { |
448 | 0 | if (mxSpinCustomMin.get() == &rFormatted) |
449 | 0 | { |
450 | 0 | maAttributes.setManualMin(rFormatted.GetFormatter().GetValue()); |
451 | 0 | } |
452 | 0 | else if (mxSpinCustomMax.get() == &rFormatted) |
453 | 0 | { |
454 | 0 | maAttributes.setManualMax(rFormatted.GetFormatter().GetValue()); |
455 | 0 | } |
456 | 0 | } |
457 | | |
458 | | IMPL_LINK(SparklineDialog, ComboValueChanged, weld::ComboBox&, rComboBox, void) |
459 | 0 | { |
460 | 0 | int nActive = rComboBox.get_active(); |
461 | |
|
462 | 0 | if (mxComboMinAxisType.get() == &rComboBox) |
463 | 0 | { |
464 | 0 | switch (nActive) |
465 | 0 | { |
466 | 0 | case 0: |
467 | 0 | maAttributes.setMinAxisType(sc::AxisType::Individual); |
468 | 0 | mxSpinCustomMin->set_sensitive(false); |
469 | 0 | break; |
470 | 0 | case 1: |
471 | 0 | maAttributes.setMinAxisType(sc::AxisType::Group); |
472 | 0 | mxSpinCustomMin->set_sensitive(false); |
473 | 0 | break; |
474 | 0 | case 2: |
475 | 0 | maAttributes.setMinAxisType(sc::AxisType::Custom); |
476 | 0 | mxSpinCustomMin->set_sensitive(true); |
477 | 0 | break; |
478 | 0 | default: |
479 | 0 | break; |
480 | 0 | } |
481 | 0 | } |
482 | 0 | else if (mxComboMaxAxisType.get() == &rComboBox) |
483 | 0 | { |
484 | 0 | switch (nActive) |
485 | 0 | { |
486 | 0 | case 0: |
487 | 0 | maAttributes.setMaxAxisType(sc::AxisType::Individual); |
488 | 0 | mxSpinCustomMax->set_sensitive(false); |
489 | 0 | break; |
490 | 0 | case 1: |
491 | 0 | maAttributes.setMaxAxisType(sc::AxisType::Group); |
492 | 0 | mxSpinCustomMax->set_sensitive(false); |
493 | 0 | break; |
494 | 0 | case 2: |
495 | 0 | maAttributes.setMaxAxisType(sc::AxisType::Custom); |
496 | 0 | mxSpinCustomMax->set_sensitive(true); |
497 | 0 | break; |
498 | 0 | default: |
499 | 0 | break; |
500 | 0 | } |
501 | 0 | } |
502 | 0 | } |
503 | | |
504 | | bool SparklineDialog::checkValidInputOutput() |
505 | 0 | { |
506 | 0 | if (mbEditMode) |
507 | 0 | return true; |
508 | | |
509 | 0 | if (!maInputRange.IsValid() || !maOutputRange.IsValid()) |
510 | 0 | return false; |
511 | | |
512 | 0 | sc::RangeOrientation eInputOrientation = sc::RangeOrientation::Unknown; |
513 | 0 | if (maOutputRange.aStart.Col() == maOutputRange.aEnd.Col()) |
514 | 0 | { |
515 | 0 | sal_Int32 nOutputRowSize = maOutputRange.aEnd.Row() - maOutputRange.aStart.Row(); |
516 | 0 | eInputOrientation = sc::calculateOrientation(nOutputRowSize, maInputRange); |
517 | 0 | } |
518 | 0 | else if (maOutputRange.aStart.Row() == maOutputRange.aEnd.Row()) |
519 | 0 | { |
520 | 0 | sal_Int32 nOutputColSize = maOutputRange.aEnd.Col() - maOutputRange.aStart.Col(); |
521 | 0 | eInputOrientation = sc::calculateOrientation(nOutputColSize, maInputRange); |
522 | 0 | } |
523 | |
|
524 | 0 | return eInputOrientation != sc::RangeOrientation::Unknown; |
525 | 0 | } |
526 | | |
527 | | void SparklineDialog::perform() |
528 | 0 | { |
529 | 0 | maAttributes.setColorSeries(mxColorSeries->GetSelectedEntry().getComplexColor()); |
530 | 0 | maAttributes.setColorNegative(mxColorNegative->GetSelectedEntry().getComplexColor()); |
531 | 0 | maAttributes.setColorMarkers(mxColorMarker->GetSelectedEntry().getComplexColor()); |
532 | 0 | maAttributes.setColorHigh(mxColorHigh->GetSelectedEntry().getComplexColor()); |
533 | 0 | maAttributes.setColorLow(mxColorLow->GetSelectedEntry().getComplexColor()); |
534 | 0 | maAttributes.setColorFirst(mxColorFirst->GetSelectedEntry().getComplexColor()); |
535 | 0 | maAttributes.setColorLast(mxColorLast->GetSelectedEntry().getComplexColor()); |
536 | |
|
537 | 0 | auto& rDocFunc = mrViewData.GetDocShell().GetDocFunc(); |
538 | |
|
539 | 0 | if (mpSparklineGroup) |
540 | 0 | { |
541 | 0 | rDocFunc.ChangeSparklineGroupAttributes(mpSparklineGroup, maAttributes); |
542 | 0 | } |
543 | 0 | else |
544 | 0 | { |
545 | 0 | auto pNewSparklineGroup = std::make_shared<sc::SparklineGroup>(maAttributes); |
546 | 0 | rDocFunc.InsertSparklines(maInputRange, maOutputRange, pNewSparklineGroup); |
547 | 0 | } |
548 | 0 | } |
549 | | |
550 | | } // end sc |
551 | | |
552 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |