/src/libreoffice/sc/source/ui/dialogs/SparklineDataRangeDialog.cxx
Line | Count | Source (jump to first uncovered line) |
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 <SparklineDataRangeDialog.hxx> |
11 | | #include <Sparkline.hxx> |
12 | | #include <reffact.hxx> |
13 | | #include <docfunc.hxx> |
14 | | |
15 | | namespace sc |
16 | | { |
17 | | SparklineDataRangeDialog::SparklineDataRangeDialog(SfxBindings* pBindings, |
18 | | SfxChildWindow* pChildWindow, |
19 | | weld::Window* pWindow, ScViewData& rViewData) |
20 | 0 | : ScAnyRefDlgController(pBindings, pChildWindow, pWindow, |
21 | 0 | u"modules/scalc/ui/sparklinedatarangedialog.ui"_ustr, |
22 | 0 | u"SparklineDataRangeDialog"_ustr) |
23 | 0 | , mrViewData(rViewData) |
24 | 0 | , mrDocument(rViewData.GetDocument()) |
25 | 0 | , mpActiveEdit(nullptr) |
26 | 0 | , mbDialogLostFocus(false) |
27 | 0 | , mxButtonOk(m_xBuilder->weld_button(u"ok"_ustr)) |
28 | 0 | , mxButtonCancel(m_xBuilder->weld_button(u"cancel"_ustr)) |
29 | 0 | , mxDataRangeLabel(m_xBuilder->weld_label(u"cell-range-label"_ustr)) |
30 | 0 | , mxDataRangeEdit(new formula::RefEdit(m_xBuilder->weld_entry(u"cell-range-edit"_ustr))) |
31 | 0 | , mxDataRangeButton(new formula::RefButton(m_xBuilder->weld_button(u"cell-range-button"_ustr))) |
32 | | |
33 | 0 | { |
34 | 0 | mxDataRangeEdit->SetReferences(this, mxDataRangeLabel.get()); |
35 | 0 | mxDataRangeButton->SetReferences(this, mxDataRangeEdit.get()); |
36 | |
|
37 | 0 | mxButtonCancel->connect_clicked(LINK(this, SparklineDataRangeDialog, ButtonClicked)); |
38 | 0 | mxButtonOk->connect_clicked(LINK(this, SparklineDataRangeDialog, ButtonClicked)); |
39 | |
|
40 | 0 | mxButtonOk->set_sensitive(false); |
41 | |
|
42 | 0 | Link<formula::RefEdit&, void> aEditLink |
43 | 0 | = LINK(this, SparklineDataRangeDialog, EditFocusHandler); |
44 | 0 | mxDataRangeEdit->SetGetFocusHdl(aEditLink); |
45 | 0 | aEditLink = LINK(this, SparklineDataRangeDialog, LoseEditFocusHandler); |
46 | 0 | mxDataRangeEdit->SetLoseFocusHdl(aEditLink); |
47 | |
|
48 | 0 | Link<formula::RefButton&, void> aButtonLink |
49 | 0 | = LINK(this, SparklineDataRangeDialog, ButtonFocusHandler); |
50 | 0 | mxDataRangeButton->SetGetFocusHdl(aButtonLink); |
51 | 0 | aButtonLink = LINK(this, SparklineDataRangeDialog, LoseButtonFocusHandler); |
52 | 0 | mxDataRangeButton->SetLoseFocusHdl(aButtonLink); |
53 | |
|
54 | 0 | Link<formula::RefEdit&, void> aModifyLink |
55 | 0 | = LINK(this, SparklineDataRangeDialog, RefInputModifyHandler); |
56 | 0 | mxDataRangeEdit->SetModifyHdl(aModifyLink); |
57 | |
|
58 | 0 | setupValues(); |
59 | |
|
60 | 0 | mxDataRangeEdit->GrabFocus(); |
61 | 0 | } |
62 | | |
63 | 0 | SparklineDataRangeDialog::~SparklineDataRangeDialog() = default; |
64 | | |
65 | | void SparklineDataRangeDialog::setupValues() |
66 | 0 | { |
67 | 0 | ScAddress aCurrentAddress = mrViewData.GetCurPos(); |
68 | 0 | mpSparkline = mrDocument.GetSparkline(aCurrentAddress); |
69 | |
|
70 | 0 | if (mpSparkline) |
71 | 0 | { |
72 | 0 | ScRangeList aRangeList(mpSparkline->getInputRange()); |
73 | 0 | if (!aRangeList.empty()) |
74 | 0 | { |
75 | 0 | maDataRange = aRangeList[0]; |
76 | 0 | OUString aString |
77 | 0 | = maDataRange.Format(mrDocument, ScRefFlags::VALID | ScRefFlags::TAB_3D, |
78 | 0 | mrDocument.GetAddressConvention()); |
79 | 0 | mxDataRangeEdit->SetRefString(aString); |
80 | 0 | mxButtonOk->set_sensitive(true); |
81 | 0 | } |
82 | 0 | } |
83 | 0 | } |
84 | | |
85 | | void SparklineDataRangeDialog::Close() |
86 | 0 | { |
87 | 0 | DoClose(sc::SparklineDataRangeDialogWrapper::GetChildWindowId()); |
88 | 0 | } |
89 | | |
90 | | void SparklineDataRangeDialog::SetActive() |
91 | 0 | { |
92 | 0 | if (mbDialogLostFocus) |
93 | 0 | { |
94 | 0 | mbDialogLostFocus = false; |
95 | 0 | if (mpActiveEdit) |
96 | 0 | mpActiveEdit->GrabFocus(); |
97 | 0 | } |
98 | 0 | else |
99 | 0 | { |
100 | 0 | m_xDialog->grab_focus(); |
101 | 0 | } |
102 | 0 | RefInputDone(); |
103 | 0 | } |
104 | | |
105 | | void SparklineDataRangeDialog::SetReference(const ScRange& rReferenceRange, ScDocument& rDocument) |
106 | 0 | { |
107 | 0 | if (mpActiveEdit) |
108 | 0 | { |
109 | 0 | if (rReferenceRange.aStart != rReferenceRange.aEnd) |
110 | 0 | RefInputStart(mpActiveEdit); |
111 | |
|
112 | 0 | OUString aString; |
113 | 0 | const ScRefFlags eFlags = ScRefFlags::VALID | ScRefFlags::TAB_3D; |
114 | 0 | auto eAddressConvention = rDocument.GetAddressConvention(); |
115 | |
|
116 | 0 | if (mpActiveEdit == mxDataRangeEdit.get()) |
117 | 0 | { |
118 | 0 | maDataRange = rReferenceRange; |
119 | 0 | aString = maDataRange.Format(rDocument, eFlags, eAddressConvention); |
120 | 0 | mxDataRangeEdit->SetRefString(aString); |
121 | 0 | } |
122 | 0 | } |
123 | 0 | } |
124 | | |
125 | | IMPL_LINK(SparklineDataRangeDialog, EditFocusHandler, formula::RefEdit&, rEdit, void) |
126 | 0 | { |
127 | 0 | if (mxDataRangeEdit.get() == &rEdit) |
128 | 0 | mpActiveEdit = mxDataRangeEdit.get(); |
129 | 0 | else |
130 | 0 | mpActiveEdit = nullptr; |
131 | |
|
132 | 0 | if (mpActiveEdit) |
133 | 0 | mpActiveEdit->SelectAll(); |
134 | 0 | } |
135 | | |
136 | | IMPL_LINK(SparklineDataRangeDialog, ButtonFocusHandler, formula::RefButton&, rButton, void) |
137 | 0 | { |
138 | 0 | if (mxDataRangeButton.get() == &rButton) |
139 | 0 | mpActiveEdit = mxDataRangeEdit.get(); |
140 | 0 | else |
141 | 0 | mpActiveEdit = nullptr; |
142 | |
|
143 | 0 | if (mpActiveEdit) |
144 | 0 | mpActiveEdit->SelectAll(); |
145 | 0 | } |
146 | | |
147 | | IMPL_LINK_NOARG(SparklineDataRangeDialog, LoseEditFocusHandler, formula::RefEdit&, void) |
148 | 0 | { |
149 | 0 | mbDialogLostFocus = !m_xDialog->has_toplevel_focus(); |
150 | 0 | } |
151 | | |
152 | | IMPL_LINK_NOARG(SparklineDataRangeDialog, LoseButtonFocusHandler, formula::RefButton&, void) |
153 | 0 | { |
154 | 0 | mbDialogLostFocus = !m_xDialog->has_toplevel_focus(); |
155 | 0 | } |
156 | | |
157 | | IMPL_LINK_NOARG(SparklineDataRangeDialog, RefInputModifyHandler, formula::RefEdit&, void) |
158 | 0 | { |
159 | 0 | if (mpActiveEdit) |
160 | 0 | { |
161 | 0 | if (mpActiveEdit == mxDataRangeEdit.get()) |
162 | 0 | { |
163 | 0 | ScRangeList aRangeList; |
164 | 0 | bool bValid = ParseWithNames(aRangeList, mxDataRangeEdit->GetText(), mrDocument); |
165 | 0 | const ScRange* pRange = (bValid && aRangeList.size() == 1) ? &aRangeList[0] : nullptr; |
166 | 0 | if (pRange) |
167 | 0 | { |
168 | 0 | maDataRange = *pRange; |
169 | 0 | mxDataRangeEdit->StartUpdateData(); |
170 | 0 | } |
171 | 0 | else |
172 | 0 | { |
173 | 0 | maDataRange = ScRange(ScAddress::INITIALIZE_INVALID); |
174 | 0 | } |
175 | 0 | } |
176 | 0 | } |
177 | 0 | } |
178 | | |
179 | | IMPL_LINK(SparklineDataRangeDialog, ButtonClicked, weld::Button&, rButton, void) |
180 | 0 | { |
181 | 0 | if (mxButtonOk.get() == &rButton) |
182 | 0 | { |
183 | 0 | perform(); |
184 | 0 | response(RET_OK); |
185 | 0 | } |
186 | 0 | else |
187 | 0 | { |
188 | 0 | response(RET_CANCEL); |
189 | 0 | } |
190 | 0 | } |
191 | | |
192 | | void SparklineDataRangeDialog::perform() |
193 | 0 | { |
194 | 0 | ScRangeList aList{ maDataRange }; |
195 | |
|
196 | 0 | auto& rDocFunc = mrViewData.GetDocShell().GetDocFunc(); |
197 | 0 | rDocFunc.ChangeSparkline(mpSparkline, mrViewData.GetTabNo(), aList); |
198 | 0 | } |
199 | | |
200 | | } // end sc |
201 | | |
202 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |