LibreOffice Module sc (master) 1
SparklineDataRangeDialog.cxx
Go to the documentation of this file.
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
11#include <Sparkline.hxx>
12#include <reffact.hxx>
13#include <docfunc.hxx>
14
15namespace sc
16{
18 SfxChildWindow* pChildWindow,
19 weld::Window* pWindow, ScViewData& rViewData)
20 : ScAnyRefDlgController(pBindings, pChildWindow, pWindow,
21 u"modules/scalc/ui/sparklinedatarangedialog.ui",
22 "SparklineDataRangeDialog")
23 , mrViewData(rViewData)
24 , mrDocument(rViewData.GetDocument())
25 , mpActiveEdit(nullptr)
26 , mbDialogLostFocus(false)
27 , mxButtonOk(m_xBuilder->weld_button("ok"))
28 , mxButtonCancel(m_xBuilder->weld_button("cancel"))
29 , mxDataRangeLabel(m_xBuilder->weld_label("cell-range-label"))
30 , mxDataRangeEdit(new formula::RefEdit(m_xBuilder->weld_entry("cell-range-edit")))
31 , mxDataRangeButton(new formula::RefButton(m_xBuilder->weld_button("cell-range-button")))
32
33{
34 mxDataRangeEdit->SetReferences(this, mxDataRangeLabel.get());
35 mxDataRangeButton->SetReferences(this, mxDataRangeEdit.get());
36
37 mxButtonCancel->connect_clicked(LINK(this, SparklineDataRangeDialog, ButtonClicked));
38 mxButtonOk->connect_clicked(LINK(this, SparklineDataRangeDialog, ButtonClicked));
39
40 mxButtonOk->set_sensitive(false);
41
43 = LINK(this, SparklineDataRangeDialog, EditFocusHandler);
44 mxDataRangeEdit->SetGetFocusHdl(aEditLink);
45 aEditLink = LINK(this, SparklineDataRangeDialog, LoseEditFocusHandler);
46 mxDataRangeEdit->SetLoseFocusHdl(aEditLink);
47
49 = LINK(this, SparklineDataRangeDialog, ButtonFocusHandler);
50 mxDataRangeButton->SetGetFocusHdl(aButtonLink);
51 aButtonLink = LINK(this, SparklineDataRangeDialog, LoseButtonFocusHandler);
52 mxDataRangeButton->SetLoseFocusHdl(aButtonLink);
53
55 = LINK(this, SparklineDataRangeDialog, RefInputModifyHandler);
56 mxDataRangeEdit->SetModifyHdl(aModifyLink);
57
59
60 mxDataRangeEdit->GrabFocus();
61}
62
64
66{
67 ScAddress aCurrentAddress = mrViewData.GetCurPos();
68 mpSparkline = mrDocument.GetSparkline(aCurrentAddress);
69
70 if (mpSparkline)
71 {
72 ScRangeList aRangeList(mpSparkline->getInputRange());
73 if (!aRangeList.empty())
74 {
75 maDataRange = aRangeList[0];
76 OUString aString
79 mxDataRangeEdit->SetRefString(aString);
80 mxButtonOk->set_sensitive(true);
81 }
82 }
83}
84
86{
88}
89
91{
93 {
94 mbDialogLostFocus = false;
95 if (mpActiveEdit)
97 }
98 else
99 {
100 m_xDialog->grab_focus();
101 }
102 RefInputDone();
103}
104
105void SparklineDataRangeDialog::SetReference(const ScRange& rReferenceRange, ScDocument& rDocument)
106{
107 if (mpActiveEdit)
108 {
109 if (rReferenceRange.aStart != rReferenceRange.aEnd)
111
112 OUString aString;
114 auto eAddressConvention = rDocument.GetAddressConvention();
115
116 if (mpActiveEdit == mxDataRangeEdit.get())
117 {
118 maDataRange = rReferenceRange;
119 aString = maDataRange.Format(rDocument, eFlags, eAddressConvention);
120 mxDataRangeEdit->SetRefString(aString);
121 }
122 }
123}
124
125IMPL_LINK(SparklineDataRangeDialog, EditFocusHandler, formula::RefEdit&, rEdit, void)
126{
127 if (mxDataRangeEdit.get() == &rEdit)
128 mpActiveEdit = mxDataRangeEdit.get();
129 else
130 mpActiveEdit = nullptr;
131
132 if (mpActiveEdit)
133 mpActiveEdit->SelectAll();
134}
135
136IMPL_LINK(SparklineDataRangeDialog, ButtonFocusHandler, formula::RefButton&, rButton, void)
137{
138 if (mxDataRangeButton.get() == &rButton)
139 mpActiveEdit = mxDataRangeEdit.get();
140 else
141 mpActiveEdit = nullptr;
142
143 if (mpActiveEdit)
144 mpActiveEdit->SelectAll();
145}
146
148{
149 mbDialogLostFocus = !m_xDialog->has_toplevel_focus();
150}
151
153{
154 mbDialogLostFocus = !m_xDialog->has_toplevel_focus();
155}
156
158{
159 if (mpActiveEdit)
160 {
161 if (mpActiveEdit == mxDataRangeEdit.get())
162 {
163 ScRangeList aRangeList;
164 bool bValid = ParseWithNames(aRangeList, mxDataRangeEdit->GetText(), mrDocument);
165 const ScRange* pRange = (bValid && aRangeList.size() == 1) ? &aRangeList[0] : nullptr;
166 if (pRange)
167 {
168 maDataRange = *pRange;
169 mxDataRangeEdit->StartUpdateData();
170 }
171 else
172 {
174 }
175 }
176 }
177}
178
179IMPL_LINK(SparklineDataRangeDialog, ButtonClicked, weld::Button&, rButton, void)
180{
181 if (mxButtonOk.get() == &rButton)
182 {
183 perform();
184 response(RET_OK);
185 }
186 else
187 {
188 response(RET_CANCEL);
189 }
190}
191
193{
194 ScRangeList aList{ maDataRange };
195
196 auto& rDocFunc = mrViewData.GetDocShell()->GetDocFunc();
198}
199
200} // end sc
201
202/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScRefFlags
Definition: address.hxx:158
Reference< XExecutableDialog > m_xDialog
@ INITIALIZE_INVALID
Definition: address.hxx:221
SC_DLLPUBLIC bool ChangeSparkline(std::shared_ptr< sc::Sparkline > const &rpSparkline, SCTAB nTab, ScRangeList const &rDataRange)
Definition: docfunc.cxx:5913
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:221
SC_DLLPUBLIC std::shared_ptr< sc::Sparkline > GetSparkline(ScAddress const &rPosition)
Returns sparkline at the address if it exists.
Definition: document.cxx:6495
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:492
bool empty() const
Definition: rangelst.hxx:88
size_t size() const
Definition: rangelst.hxx:89
OUString Format(const ScDocument &rDocument, ScRefFlags nFlags=ScRefFlags::ZERO, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, bool bFullAddressNotation=false) const
Returns string with formatted cell range from aStart to aEnd, according to provided address conventio...
Definition: address.cxx:2170
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
virtual void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton=nullptr) override
Definition: anyrefdg.cxx:745
virtual void RefInputDone(bool bForced=false) override
Definition: anyrefdg.cxx:775
bool DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:714
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScAddress GetCurPos() const
Definition: viewdata.cxx:4119
Dialog to change input data range for a sparkline
SparklineDataRangeDialog(SfxBindings *pBindings, SfxChildWindow *pChildWindow, weld::Window *pWindow, ScViewData &rViewData)
std::unique_ptr< weld::Label > mxDataRangeLabel
std::shared_ptr< sc::Sparkline > mpSparkline
void SetReference(const ScRange &rRef, ScDocument &rDocument) override
std::unique_ptr< formula::RefEdit > mxDataRangeEdit
virtual ~SparklineDataRangeDialog() override
std::unique_ptr< weld::Button > mxButtonOk
std::unique_ptr< formula::RefButton > mxDataRangeButton
std::unique_ptr< weld::Button > mxButtonCancel
float u
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
IMPL_LINK_NOARG(SharedStringPoolPurge, timerHandler, Timer *, void)
IMPL_LINK(SearchResultsDlg, HeaderBarClick, int, nColumn, void)
RET_OK
RET_CANCEL