officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu |    8 
 sc/Library_sc.mk                                                  |    2 
 sc/UIConfig_scalc.mk                                              |    1 
 sc/inc/globstr.hrc                                                |    1 
 sc/inc/sc.hrc                                                     |    4 
 sc/qa/unit/SparklineTest.cxx                                      |   64 +++
 sc/sdi/cellsh.sdi                                                 |    1 
 sc/sdi/scalc.sdi                                                  |   17 
 sc/source/ui/app/scdll.cxx                                        |    1 
 sc/source/ui/dialogs/SparklineDataRangeDialog.cxx                 |  202 
++++++++++
 sc/source/ui/docshell/docfunc.cxx                                 |   12 
 sc/source/ui/inc/SparklineDataRangeDialog.hxx                     |   66 +++
 sc/source/ui/inc/docfunc.hxx                                      |    2 
 sc/source/ui/inc/gridwin.hxx                                      |    3 
 sc/source/ui/inc/reffact.hxx                                      |    7 
 sc/source/ui/inc/undo/UndoEditSparkline.hxx                       |   47 ++
 sc/source/ui/undo/UndoEditSparkline.cxx                           |   63 +++
 sc/source/ui/view/cellsh.cxx                                      |    6 
 sc/source/ui/view/cellsh1.cxx                                     |   10 
 sc/source/ui/view/gridwin.cxx                                     |   67 +++
 sc/source/ui/view/tabvwsh.cxx                                     |    1 
 sc/source/ui/view/tabvwshc.cxx                                    |    6 
 sc/uiconfig/scalc/popupmenu/cell.xml                              |    1 
 sc/uiconfig/scalc/ui/sparklinedatarangedialog.ui                  |  148 
+++++++
 24 files changed, 738 insertions(+), 2 deletions(-)

New commits:
commit 3b8fd7dd69fd4d775e296cbbd3bf50c2efb41b39
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sat Apr 9 14:30:22 2022 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Wed Apr 13 01:35:08 2022 +0200

    sc: add UI, undo/redo and test to change sparkline data range
    
    This adds a "edit sparkline" action to the context menu and a
    dialog to change the data range of a sparkline. To change a
    sparkline using undo/redo, a new class UndoEditSparkline  was
    added, which allows to change the attributes of a sparkline and
    revert back the old attributes when undoing. This is then used in
    the Dialog when setting the changed data range of a sparkline.
    
    To make sure that undo/redo works correctly, a simple unit tests
    was added.
    
    Change-Id: I08af1813fa288278bc0d33b0540660b325b17235
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132748
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit a08f9ed2341bc60faae6b86538661fea40417ace)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132924
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index 55835e2b7c74..7f244744d2a7 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -1114,6 +1114,14 @@
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:EditSparkline" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Edit Sparkline...</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
       <node oor:name=".uno:EditSparklineGroup" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">Edit Sparkline Group...</value>
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 0c32f743c44d..eb81a6817ab2 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -419,6 +419,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/ui/dbgui/validate \
     sc/source/ui/dialogs/searchresults \
     sc/source/ui/dialogs/SparklineDialog \
+    sc/source/ui/dialogs/SparklineDataRangeDialog \
     sc/source/ui/docshell/arealink \
     sc/source/ui/docshell/autostyl \
     sc/source/ui/docshell/datastream \
@@ -559,6 +560,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/ui/undo/UndoDeleteSparklineGroup \
     sc/source/ui/undo/UndoUngroupSparklines \
     sc/source/ui/undo/UndoGroupSparklines \
+    sc/source/ui/undo/UndoEditSparkline \
     sc/source/ui/unoobj/ChartRangeSelectionListener \
     sc/source/ui/unoobj/addruno \
     sc/source/ui/unoobj/afmtuno \
diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk
index 302f08ff3fb3..643645ee7432 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -245,6 +245,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
        sc/uiconfig/scalc/ui/sortoptionspage \
        sc/uiconfig/scalc/ui/sortwarning \
        sc/uiconfig/scalc/ui/sparklinedialog \
+       sc/uiconfig/scalc/ui/sparklinedatarangedialog \
        sc/uiconfig/scalc/ui/splitcolumnentry \
        sc/uiconfig/scalc/ui/subtotaldialog \
        sc/uiconfig/scalc/ui/subtotaloptionspage \
diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index c4889fb1176c..b76f84a1d72e 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -545,6 +545,7 @@
 #define STR_UNDO_EDIT_SPARKLINE_GROUP           
NC_("STR_UNDO_EDIT_SPARKLINE_GROUP", "Edit Sparkline Group")
 #define STR_UNDO_GROUP_SPARKLINES               
NC_("STR_UNDO_GROUP_SPARKLINES", "Group Sparklines")
 #define STR_UNDO_UNGROUP_SPARKLINES             
NC_("STR_UNDO_UNGROUP_SPARKLINES", "Ungroup Sparklines")
+#define STR_UNDO_EDIT_SPARKLINE                 NC_("STR_UNDO_EDIT_SPARKLINE", 
"Edit Sparkline")
 
 #endif
 
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index ab1d4bc27487..1392cd6f20b4 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -236,6 +236,7 @@
 #define SID_ROW_OPERATIONS                  (SC_MESSAGE_START + 87)
 #define SID_FOURIER_ANALYSIS_DIALOG         (SC_MESSAGE_START + 88)
 #define SID_SPARKLINE_DIALOG                (SC_MESSAGE_START + 89)
+#define SID_SPARKLINE_DATA_RANGE_DIALOG     (SC_MESSAGE_START + 90)
 
 
 // functions
@@ -311,7 +312,8 @@
 #define SID_DELETE_SPARKLINE_GROUP   (INSERT_MENU_START + 28)
 #define SID_GROUP_SPARKLINES    (INSERT_MENU_START + 29)
 #define SID_UNGROUP_SPARKLINES  (INSERT_MENU_START + 30)
-#define INSERT_MENU_END         (INSERT_MENU_START + 31)
+#define SID_EDIT_SPARKLINE      (INSERT_MENU_START + 31)
+#define INSERT_MENU_END         (INSERT_MENU_START + 32)
 
 #define FORMAT_MENU_START       (INSERT_MENU_END)
 #define FID_CELL_FORMAT         (FORMAT_MENU_START)
diff --git a/sc/qa/unit/SparklineTest.cxx b/sc/qa/unit/SparklineTest.cxx
index f8d07edc53e6..9c52ab1d1c65 100644
--- a/sc/qa/unit/SparklineTest.cxx
+++ b/sc/qa/unit/SparklineTest.cxx
@@ -58,6 +58,7 @@ public:
     void testUndoRedoEditSparklineGroup();
     void testUndoRedoUngroupSparklines();
     void testUndoRedoGroupSparklines();
+    void testUndoRedoEditSparkline();
     void testSparklineList();
 
     CPPUNIT_TEST_SUITE(SparklineTest);
@@ -72,6 +73,7 @@ public:
     CPPUNIT_TEST(testUndoRedoEditSparklineGroup);
     CPPUNIT_TEST(testUndoRedoUngroupSparklines);
     CPPUNIT_TEST(testUndoRedoGroupSparklines);
+    CPPUNIT_TEST(testUndoRedoEditSparkline);
     CPPUNIT_TEST(testSparklineList);
     CPPUNIT_TEST_SUITE_END();
 };
@@ -867,6 +869,68 @@ void SparklineTest::testUndoRedoGroupSparklines()
     xDocSh->DoClose();
 }
 
+void SparklineTest::testUndoRedoEditSparkline()
+{
+    ScDocShellRef xDocSh = loadEmptyDocument();
+    CPPUNIT_ASSERT(xDocSh);
+
+    ScDocument& rDocument = xDocSh->GetDocument();
+    ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
+    CPPUNIT_ASSERT(pViewShell);
+
+    auto& rDocFunc = xDocSh->GetDocFunc();
+
+    // Try to delete sparkline that doesn't exist - returns false
+    CPPUNIT_ASSERT(!rDocFunc.DeleteSparkline(ScAddress(0, 6, 0)));
+
+    // insert test data - A1:A6
+    insertTestData(rDocument);
+
+    // Sparkline range
+    ScAddress aAddress(0, 6, 0);
+    ScRange aRange(aAddress);
+
+    // Check Sparkline at cell A7 doesn't exists
+    auto pSparkline = rDocument.GetSparkline(aAddress);
+    CPPUNIT_ASSERT(!pSparkline);
+
+    auto pSparklineGroup = std::make_shared<sc::SparklineGroup>();
+    CPPUNIT_ASSERT(rDocFunc.InsertSparklines(ScRange(0, 0, 0, 0, 5, 0), 
aRange, pSparklineGroup));
+
+    // Check Sparkline at cell A7
+    pSparkline = rDocument.GetSparkline(aAddress);
+    CPPUNIT_ASSERT(pSparkline);
+    CPPUNIT_ASSERT_EQUAL(size_t(1), pSparkline->getInputRange().size());
+    CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 0, 5, 0), 
pSparkline->getInputRange()[0]);
+
+    // Change Sparkline
+    CPPUNIT_ASSERT(
+        rDocFunc.ChangeSparkline(pSparkline, SCTAB(0), ScRangeList(ScRange(0, 
1, 0, 0, 4, 0))));
+
+    pSparkline = rDocument.GetSparkline(aAddress);
+    CPPUNIT_ASSERT(pSparkline);
+    CPPUNIT_ASSERT_EQUAL(size_t(1), pSparkline->getInputRange().size());
+    CPPUNIT_ASSERT_EQUAL(ScRange(0, 1, 0, 0, 4, 0), 
pSparkline->getInputRange()[0]);
+
+    // Undo
+    rDocument.GetUndoManager()->Undo();
+
+    pSparkline = rDocument.GetSparkline(aAddress);
+    CPPUNIT_ASSERT(pSparkline);
+    CPPUNIT_ASSERT_EQUAL(size_t(1), pSparkline->getInputRange().size());
+    CPPUNIT_ASSERT_EQUAL(ScRange(0, 0, 0, 0, 5, 0), 
pSparkline->getInputRange()[0]);
+
+    // Redo
+    rDocument.GetUndoManager()->Redo();
+
+    pSparkline = rDocument.GetSparkline(aAddress);
+    CPPUNIT_ASSERT(pSparkline);
+    CPPUNIT_ASSERT_EQUAL(size_t(1), pSparkline->getInputRange().size());
+    CPPUNIT_ASSERT_EQUAL(ScRange(0, 1, 0, 0, 4, 0), 
pSparkline->getInputRange()[0]);
+
+    xDocSh->DoClose();
+}
+
 void SparklineTest::testSparklineList()
 {
     ScDocShellRef xDocSh = loadEmptyDocument();
diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index 8fb939d9bf74..38eb86cb27b9 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -238,6 +238,7 @@ interface CellSelection
     SID_INSERT_SPARKLINE                [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
     SID_DELETE_SPARKLINE                [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
     SID_EDIT_SPARKLINE_GROUP            [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
+    SID_EDIT_SPARKLINE                  [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
     SID_DELETE_SPARKLINE_GROUP          [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
     SID_GROUP_SPARKLINES                [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
     SID_UNGROUP_SPARKLINES              [ ExecMethod = ExecuteEdit; 
StateMethod = GetBlockState; ]
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index 76156b805717..bb438041a892 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -2321,6 +2321,23 @@ SfxVoidItem DeleteSparkline SID_DELETE_SPARKLINE
     GroupId = SfxGroupId::Edit;
 ]
 
+SfxVoidItem EditSparkline SID_EDIT_SPARKLINE
+()
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    ToolBoxConfig = TRUE,
+    GroupId = SfxGroupId::Edit;
+]
+
 SfxVoidItem EditSparklineGroup SID_EDIT_SPARKLINE_GROUP
 ()
 [
diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx
index a0bdf08b16c0..58efb29ecb9a 100644
--- a/sc/source/ui/app/scdll.cxx
+++ b/sc/source/ui/app/scdll.cxx
@@ -207,6 +207,7 @@ void ScDLL::Init()
     ScChiSquareTestDialogWrapper        ::RegisterChildWindow(false, pMod);
     ScFourierAnalysisDialogWrapper      ::RegisterChildWindow(false, pMod);
     sc::SparklineDialogWrapper          ::RegisterChildWindow(false, pMod);
+    sc::SparklineDataRangeDialogWrapper ::RegisterChildWindow(false, pMod);
 
     // Redlining Window
     ScAcceptChgDlgWrapper       ::RegisterChildWindow(false, pMod);
diff --git a/sc/source/ui/dialogs/SparklineDataRangeDialog.cxx 
b/sc/source/ui/dialogs/SparklineDataRangeDialog.cxx
new file mode 100644
index 000000000000..f085e737c77c
--- /dev/null
+++ b/sc/source/ui/dialogs/SparklineDataRangeDialog.cxx
@@ -0,0 +1,202 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <SparklineDataRangeDialog.hxx>
+#include <Sparkline.hxx>
+#include <reffact.hxx>
+#include <docfunc.hxx>
+
+namespace sc
+{
+SparklineDataRangeDialog::SparklineDataRangeDialog(SfxBindings* pBindings,
+                                                   SfxChildWindow* 
pChildWindow,
+                                                   weld::Window* pWindow, 
ScViewData& rViewData)
+    : ScAnyRefDlgController(pBindings, pChildWindow, pWindow,
+                            u"modules/scalc/ui/sparklinedatarangedialog.ui",
+                            "SparklineDataRangeDialog")
+    , mrViewData(rViewData)
+    , mrDocument(rViewData.GetDocument())
+    , mpActiveEdit(nullptr)
+    , mbDialogLostFocus(false)
+    , mxButtonOk(m_xBuilder->weld_button("ok"))
+    , mxButtonCancel(m_xBuilder->weld_button("cancel"))
+    , mxDataRangeLabel(m_xBuilder->weld_label("cell-range-label"))
+    , mxDataRangeEdit(new 
formula::RefEdit(m_xBuilder->weld_entry("cell-range-edit")))
+    , mxDataRangeButton(new 
formula::RefButton(m_xBuilder->weld_button("cell-range-button")))
+
+{
+    mxDataRangeEdit->SetReferences(this, mxDataRangeLabel.get());
+    mxDataRangeButton->SetReferences(this, mxDataRangeEdit.get());
+
+    mxButtonCancel->connect_clicked(LINK(this, SparklineDataRangeDialog, 
ButtonClicked));
+    mxButtonOk->connect_clicked(LINK(this, SparklineDataRangeDialog, 
ButtonClicked));
+
+    mxButtonOk->set_sensitive(false);
+
+    Link<formula::RefEdit&, void> aEditLink
+        = LINK(this, SparklineDataRangeDialog, EditFocusHandler);
+    mxDataRangeEdit->SetGetFocusHdl(aEditLink);
+    aEditLink = LINK(this, SparklineDataRangeDialog, LoseEditFocusHandler);
+    mxDataRangeEdit->SetLoseFocusHdl(aEditLink);
+
+    Link<formula::RefButton&, void> aButtonLink
+        = LINK(this, SparklineDataRangeDialog, ButtonFocusHandler);
+    mxDataRangeButton->SetGetFocusHdl(aButtonLink);
+    aButtonLink = LINK(this, SparklineDataRangeDialog, LoseButtonFocusHandler);
+    mxDataRangeButton->SetLoseFocusHdl(aButtonLink);
+
+    Link<formula::RefEdit&, void> aModifyLink
+        = LINK(this, SparklineDataRangeDialog, RefInputModifyHandler);
+    mxDataRangeEdit->SetModifyHdl(aModifyLink);
+
+    setupValues();
+
+    mxDataRangeEdit->GrabFocus();
+}
+
+SparklineDataRangeDialog::~SparklineDataRangeDialog() = default;
+
+void SparklineDataRangeDialog::setupValues()
+{
+    ScAddress aCurrentAddress = mrViewData.GetCurPos();
+    mpSparkline = mrDocument.GetSparkline(aCurrentAddress);
+
+    if (mpSparkline)
+    {
+        ScRangeList aRangeList(mpSparkline->getInputRange());
+        if (!aRangeList.empty())
+        {
+            maDataRange = aRangeList[0];
+            OUString aString
+                = maDataRange.Format(mrDocument, ScRefFlags::VALID | 
ScRefFlags::TAB_3D,
+                                     mrDocument.GetAddressConvention());
+            mxDataRangeEdit->SetRefString(aString);
+            mxButtonOk->set_sensitive(true);
+        }
+    }
+}
+
+void SparklineDataRangeDialog::Close()
+{
+    DoClose(sc::SparklineDataRangeDialogWrapper::GetChildWindowId());
+}
+
+void SparklineDataRangeDialog::SetActive()
+{
+    if (mbDialogLostFocus)
+    {
+        mbDialogLostFocus = false;
+        if (mpActiveEdit)
+            mpActiveEdit->GrabFocus();
+    }
+    else
+    {
+        m_xDialog->grab_focus();
+    }
+    RefInputDone();
+}
+
+void SparklineDataRangeDialog::SetReference(const ScRange& rReferenceRange, 
ScDocument& rDocument)
+{
+    if (mpActiveEdit)
+    {
+        if (rReferenceRange.aStart != rReferenceRange.aEnd)
+            RefInputStart(mpActiveEdit);
+
+        OUString aString;
+        const ScRefFlags eFlags = ScRefFlags::VALID | ScRefFlags::TAB_3D;
+        auto eAddressConvention = rDocument.GetAddressConvention();
+
+        if (mpActiveEdit == mxDataRangeEdit.get())
+        {
+            maDataRange = rReferenceRange;
+            aString = maDataRange.Format(rDocument, eFlags, 
eAddressConvention);
+            mxDataRangeEdit->SetRefString(aString);
+        }
+    }
+}
+
+IMPL_LINK(SparklineDataRangeDialog, EditFocusHandler, formula::RefEdit&, 
rEdit, void)
+{
+    if (mxDataRangeEdit.get() == &rEdit)
+        mpActiveEdit = mxDataRangeEdit.get();
+    else
+        mpActiveEdit = nullptr;
+
+    if (mpActiveEdit)
+        mpActiveEdit->SelectAll();
+}
+
+IMPL_LINK(SparklineDataRangeDialog, ButtonFocusHandler, formula::RefButton&, 
rButton, void)
+{
+    if (mxDataRangeButton.get() == &rButton)
+        mpActiveEdit = mxDataRangeEdit.get();
+    else
+        mpActiveEdit = nullptr;
+
+    if (mpActiveEdit)
+        mpActiveEdit->SelectAll();
+}
+
+IMPL_LINK_NOARG(SparklineDataRangeDialog, LoseEditFocusHandler, 
formula::RefEdit&, void)
+{
+    mbDialogLostFocus = !m_xDialog->has_toplevel_focus();
+}
+
+IMPL_LINK_NOARG(SparklineDataRangeDialog, LoseButtonFocusHandler, 
formula::RefButton&, void)
+{
+    mbDialogLostFocus = !m_xDialog->has_toplevel_focus();
+}
+
+IMPL_LINK_NOARG(SparklineDataRangeDialog, RefInputModifyHandler, 
formula::RefEdit&, void)
+{
+    if (mpActiveEdit)
+    {
+        if (mpActiveEdit == mxDataRangeEdit.get())
+        {
+            ScRangeList aRangeList;
+            bool bValid = ParseWithNames(aRangeList, 
mxDataRangeEdit->GetText(), mrDocument);
+            const ScRange* pRange = (bValid && aRangeList.size() == 1) ? 
&aRangeList[0] : nullptr;
+            if (pRange)
+            {
+                maDataRange = *pRange;
+                mxDataRangeEdit->StartUpdateData();
+            }
+            else
+            {
+                maDataRange = ScRange(ScAddress::INITIALIZE_INVALID);
+            }
+        }
+    }
+}
+
+IMPL_LINK(SparklineDataRangeDialog, ButtonClicked, weld::Button&, rButton, 
void)
+{
+    if (mxButtonOk.get() == &rButton)
+    {
+        perform();
+        response(RET_OK);
+    }
+    else
+    {
+        response(RET_CANCEL);
+    }
+}
+
+void SparklineDataRangeDialog::perform()
+{
+    ScRangeList aList{ maDataRange };
+
+    auto& rDocFunc = mrViewData.GetDocShell()->GetDocFunc();
+    rDocFunc.ChangeSparkline(mpSparkline, mrViewData.GetTabNo(), aList);
+}
+
+} // end sc
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/docshell/docfunc.cxx 
b/sc/source/ui/docshell/docfunc.cxx
index 04ab0088dd04..46aeb7e2aa62 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -103,6 +103,7 @@
 #include <undo/UndoEditSparklineGroup.hxx>
 #include <undo/UndoUngroupSparklines.hxx>
 #include <undo/UndoGroupSparklines.hxx>
+#include <undo/UndoEditSparkline.hxx>
 #include <config_features.h>
 
 #include <memory>
@@ -5893,7 +5894,7 @@ bool 
ScDocFunc::ChangeSparklineGroupAttributes(std::shared_ptr<sc::SparklineGrou
 bool ScDocFunc::GroupSparklines(ScRange const& rRange, 
std::shared_ptr<sc::SparklineGroup> const& rpGroup)
 {
     auto pUndo = std::make_unique<sc::UndoGroupSparklines>(rDocShell, rRange, 
rpGroup);
-    // ungroup sparklines by "redoing"
+    // group sparklines by "redoing"
     pUndo->Redo();
     rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo));
     return true;
@@ -5908,4 +5909,13 @@ bool ScDocFunc::UngroupSparklines(ScRange const& rRange)
     return true;
 }
 
+bool ScDocFunc::ChangeSparkline(std::shared_ptr<sc::Sparkline> const& 
rpSparkline, SCTAB nTab, ScRangeList const& rDataRange)
+{
+    auto pUndo = std::make_unique<sc::UndoEditSparkline>(rDocShell, 
rpSparkline, nTab, rDataRange);
+    // change sparkline by "redoing"
+    pUndo->Redo();
+    rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo));
+    return true;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/SparklineDataRangeDialog.hxx 
b/sc/source/ui/inc/SparklineDataRangeDialog.hxx
new file mode 100644
index 000000000000..41d882c8bc40
--- /dev/null
+++ b/sc/source/ui/inc/SparklineDataRangeDialog.hxx
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <address.hxx>
+#include "anyrefdg.hxx"
+#include "viewdata.hxx"
+
+#include <SparklineGroup.hxx>
+#include <SparklineAttributes.hxx>
+
+class ColorListBox;
+
+namespace sc
+{
+class SparklineDataRangeDialog : public ScAnyRefDlgController
+{
+private:
+    ScViewData& mrViewData;
+    ScDocument& mrDocument;
+
+    std::shared_ptr<sc::Sparkline> mpSparkline;
+
+    ScRange maDataRange;
+
+    formula::RefEdit* mpActiveEdit;
+    bool mbDialogLostFocus;
+
+    std::unique_ptr<weld::Button> mxButtonOk;
+    std::unique_ptr<weld::Button> mxButtonCancel;
+
+    std::unique_ptr<weld::Label> mxDataRangeLabel;
+    std::unique_ptr<formula::RefEdit> mxDataRangeEdit;
+    std::unique_ptr<formula::RefButton> mxDataRangeButton;
+
+    DECL_LINK(ButtonClicked, weld::Button&, void);
+    DECL_LINK(EditFocusHandler, formula::RefEdit&, void);
+    DECL_LINK(ButtonFocusHandler, formula::RefButton&, void);
+    DECL_LINK(LoseEditFocusHandler, formula::RefEdit&, void);
+    DECL_LINK(LoseButtonFocusHandler, formula::RefButton&, void);
+    DECL_LINK(RefInputModifyHandler, formula::RefEdit&, void);
+
+    void setupValues();
+
+    void perform();
+    bool checkValidInputOutput();
+
+public:
+    SparklineDataRangeDialog(SfxBindings* pBindings, SfxChildWindow* 
pChildWindow,
+                             weld::Window* pWindow, ScViewData& rViewData);
+    virtual ~SparklineDataRangeDialog() override;
+
+    void SetReference(const ScRange& rRef, ScDocument& rDocument) override;
+    void SetActive() override;
+    void Close() override;
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index 7f8e770756b3..a71391de23cc 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -56,6 +56,7 @@ namespace sc
     struct ColRowSpan;
     class SparklineAttributes;
     class SparklineGroup;
+    class Sparkline;
 }
 
 class ScDocFunc
@@ -246,6 +247,7 @@ public:
                                                      sc::SparklineAttributes 
const& rNewAttributes);
     SC_DLLPUBLIC bool GroupSparklines(ScRange const& rRange, 
std::shared_ptr<sc::SparklineGroup> const& rpGroup);
     SC_DLLPUBLIC bool UngroupSparklines(ScRange const& rRange);
+    SC_DLLPUBLIC bool ChangeSparkline(std::shared_ptr<sc::Sparkline> const& 
rpSparkline, SCTAB nTab, ScRangeList const& rDataRange);
 
 private:
     void ProtectDocument(const ScDocProtection& rProtect);
diff --git a/sc/source/ui/inc/reffact.hxx b/sc/source/ui/inc/reffact.hxx
index 4bf1254b4556..1394418ffa85 100644
--- a/sc/source/ui/inc/reffact.hxx
+++ b/sc/source/ui/inc/reffact.hxx
@@ -157,6 +157,13 @@ private:
     SparklineDialogWrapper() = delete;
 };
 
+class SparklineDataRangeDialogWrapper :
+    public ChildControllerWrapper<SID_SPARKLINE_DATA_RANGE_DIALOG>
+{
+private:
+    SparklineDataRangeDialogWrapper() = delete;
+};
+
 }
 
 class ScAcceptChgDlgWrapper : public SfxChildWindow
diff --git a/sc/source/ui/inc/undo/UndoEditSparkline.hxx 
b/sc/source/ui/inc/undo/UndoEditSparkline.hxx
new file mode 100644
index 000000000000..4e33eaa1f5df
--- /dev/null
+++ b/sc/source/ui/inc/undo/UndoEditSparkline.hxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include <undobase.hxx>
+#include <address.hxx>
+#include <rangelst.hxx>
+#include <memory>
+
+namespace sc
+{
+class Sparkline;
+struct SparklineData;
+
+/** Undo action for editing a Sparkline */
+class UndoEditSparkline : public ScSimpleUndo
+{
+private:
+    std::shared_ptr<sc::Sparkline> mpSparkline;
+    SCTAB mnTab;
+    ScRangeList maOldDataRange;
+    ScRangeList maNewDataRange;
+
+public:
+    UndoEditSparkline(ScDocShell& rDocShell, std::shared_ptr<sc::Sparkline> 
const& rpSparkline,
+                      SCTAB nTab, ScRangeList const& rDataRange);
+
+    virtual ~UndoEditSparkline() override;
+
+    void Undo() override;
+    void Redo() override;
+    bool CanRepeat(SfxRepeatTarget& rTarget) const override;
+    void Repeat(SfxRepeatTarget& rTarget) override;
+    OUString GetComment() const override;
+};
+
+} // namespace sc
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/undo/UndoEditSparkline.cxx 
b/sc/source/ui/undo/UndoEditSparkline.cxx
new file mode 100644
index 000000000000..b1f6f38f5dc4
--- /dev/null
+++ b/sc/source/ui/undo/UndoEditSparkline.cxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <undo/UndoEditSparkline.hxx>
+#include <globstr.hrc>
+#include <scresid.hxx>
+
+#include <Sparkline.hxx>
+#include <SparklineGroup.hxx>
+
+namespace sc
+{
+UndoEditSparkline::UndoEditSparkline(ScDocShell& rDocShell,
+                                     std::shared_ptr<sc::Sparkline> const& 
rpSparkline, SCTAB nTab,
+                                     ScRangeList const& rDataRange)
+    : ScSimpleUndo(&rDocShell)
+    , mpSparkline(rpSparkline)
+    , mnTab(nTab)
+    , maOldDataRange(mpSparkline->getInputRange())
+    , maNewDataRange(rDataRange)
+{
+}
+
+UndoEditSparkline::~UndoEditSparkline() = default;
+
+void UndoEditSparkline::Undo()
+{
+    BeginUndo();
+
+    mpSparkline->setInputRange(maOldDataRange);
+
+    pDocShell->PostPaintCell(ScAddress(mpSparkline->getColumn(), 
mpSparkline->getRow(), mnTab));
+
+    EndUndo();
+}
+
+void UndoEditSparkline::Redo()
+{
+    BeginRedo();
+
+    mpSparkline->setInputRange(maNewDataRange);
+
+    pDocShell->PostPaintCell(ScAddress(mpSparkline->getColumn(), 
mpSparkline->getRow(), mnTab));
+
+    EndRedo();
+}
+
+void UndoEditSparkline::Repeat(SfxRepeatTarget& /*rTarget*/) {}
+
+bool UndoEditSparkline::CanRepeat(SfxRepeatTarget& /*rTarget*/) const { return 
false; }
+
+OUString UndoEditSparkline::GetComment() const { return 
ScResId(STR_UNDO_EDIT_SPARKLINE); }
+
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index c3e7aab1d1dc..5fb5efd3d44f 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -194,6 +194,12 @@ void ScCellShell::GetBlockState( SfxItemSet& rSet )
             }
             break;
 
+            case SID_EDIT_SPARKLINE:
+            {
+                bDisable = !rDoc.HasSparkline(GetViewData().GetCurPos());
+            }
+            break;
+
             case SID_DELETE_SPARKLINE:
             case SID_EDIT_SPARKLINE_GROUP:
             case SID_DELETE_SPARKLINE_GROUP:
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 21b899c1786c..31b2a6fdd3fc 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -1065,6 +1065,16 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
         }
         break;
 
+        case SID_EDIT_SPARKLINE:
+        {
+            sal_uInt16 nId  = 
sc::SparklineDataRangeDialogWrapper::GetChildWindowId();
+            SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
+            SfxChildWindow* pWindow = pViewFrame->GetChildWindow(nId);
+            pScMod->SetRefDialog(nId, pWindow == nullptr);
+            rReq.Done();
+        }
+        break;
+
         case SID_DELETE_SPARKLINE:
         {
             pTabViewShell->DeleteContents(InsertDeleteFlags::SPARKLINES);
diff --git a/sc/source/ui/view/tabvwsh.cxx b/sc/source/ui/view/tabvwsh.cxx
index 7337b5cc2f0d..669c7554f3bd 100644
--- a/sc/source/ui/view/tabvwsh.cxx
+++ b/sc/source/ui/view/tabvwsh.cxx
@@ -98,6 +98,7 @@ void ScTabViewShell::InitInterface_Impl()
     
GetStaticInterface()->RegisterChildWindow(ScFourierAnalysisDialogWrapper::GetChildWindowId());
     
GetStaticInterface()->RegisterChildWindow(ScCondFormatDlgWrapper::GetChildWindowId());
     
GetStaticInterface()->RegisterChildWindow(sc::SparklineDialogWrapper::GetChildWindowId());
+    
GetStaticInterface()->RegisterChildWindow(sc::SparklineDataRangeDialogWrapper::GetChildWindowId());
 }
 
 SFX_IMPL_NAMED_VIEWFACTORY( ScTabViewShell, "Default" )
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index 667992e57da9..5ea8701a0dbe 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -70,6 +70,7 @@
 
 #include <PivotLayoutDialog.hxx>
 #include <SparklineDialog.hxx>
+#include <SparklineDataRangeDialog.hxx>
 
 #include <comphelper/lok.hxx>
 #include <o3tl/make_shared.hxx>
@@ -242,6 +243,11 @@ std::shared_ptr<SfxModelessDialogController> 
ScTabViewShell::CreateRefDialogCont
             xResult = std::make_shared<sc::SparklineDialog>(pB, pCW, pParent, 
GetViewData());
             break;
         }
+        case SID_SPARKLINE_DATA_RANGE_DIALOG:
+        {
+            xResult = std::make_shared<sc::SparklineDataRangeDialog>(pB, pCW, 
pParent, GetViewData());
+            break;
+        }
         case SID_DEFINE_DBNAME:
         {
             // when called for an existing range, then mark
diff --git a/sc/uiconfig/scalc/popupmenu/cell.xml 
b/sc/uiconfig/scalc/popupmenu/cell.xml
index 1de462b89fe1..fb7f4ff9ecd8 100644
--- a/sc/uiconfig/scalc/popupmenu/cell.xml
+++ b/sc/uiconfig/scalc/popupmenu/cell.xml
@@ -69,6 +69,7 @@
       <menu:menuitem menu:id=".uno:DeleteSparkline"/>
       <menu:menuitem menu:id=".uno:DeleteSparklineGroup"/>
       <menu:menuitem menu:id=".uno:EditSparklineGroup"/>
+      <menu:menuitem menu:id=".uno:EditSparkline"/>
       <menu:menuitem menu:id=".uno:GroupSparklines"/>
       <menu:menuitem menu:id=".uno:UngroupSparklines"/>
     </menu:menupopup>
diff --git a/sc/uiconfig/scalc/ui/sparklinedatarangedialog.ui 
b/sc/uiconfig/scalc/ui/sparklinedatarangedialog.ui
new file mode 100644
index 000000000000..1e1412e01981
--- /dev/null
+++ b/sc/uiconfig/scalc/ui/sparklinedatarangedialog.ui
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2 -->
+<interface domain="sc">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkDialog" id="SparklineDataRangeDialog">
+    <property name="can-focus">False</property>
+    <property name="border-width">6</property>
+    <property name="title" translatable="yes" 
context="SparklineDialog">Sparkline Data Range Dialog</property>
+    <property name="type-hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can-focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can-focus">False</property>
+            <property name="layout-style">end</property>
+            <child>
+              <object class="GtkButton" id="ok">
+                <property name="label" translatable="yes" 
context="stock">_OK</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="can-default">True</property>
+                <property name="has-default">True</property>
+                <property name="receives-default">True</property>
+                <property name="use-underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="cancel">
+                <property name="label" translatable="yes" 
context="stock">_Close</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="can-default">True</property>
+                <property name="receives-default">True</property>
+                <property name="use-underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="help">
+                <property name="label" translatable="yes" 
context="stock">_Help</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">True</property>
+                <property name="use-underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">3</property>
+                <property name="secondary">True</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack-type">end</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <!-- n-columns=3 n-rows=1 -->
+          <object class="GtkGrid">
+            <property name="visible">True</property>
+            <property name="can-focus">False</property>
+            <property name="margin-start">12</property>
+            <property name="margin-end">6</property>
+            <property name="margin-top">6</property>
+            <property name="margin-bottom">6</property>
+            <property name="row-spacing">6</property>
+            <property name="column-spacing">6</property>
+            <child>
+              <object class="GtkButton" id="cell-range-button">
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">True</property>
+                <accessibility>
+                  <relation type="labelled-by" target="cell-range-label"/>
+                </accessibility>
+              </object>
+              <packing>
+                <property name="left-attach">2</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="cell-range-edit">
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="valign">center</property>
+                <property name="hexpand">True</property>
+                <property name="activates-default">True</property>
+                <property name="width-chars">30</property>
+                <property name="truncate-multiline">True</property>
+                <accessibility>
+                  <relation type="labelled-by" target="cell-range-label"/>
+                </accessibility>
+              </object>
+              <packing>
+                <property name="left-attach">1</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="cell-range-label">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <property name="label" translatable="yes" 
context="SparklineDataRangeDialog|cell-range-label">Data range:</property>
+                <property name="use-underline">True</property>
+                <property name="xalign">0</property>
+                <accessibility>
+                  <relation type="label-for" target="cell-range-button"/>
+                  <relation type="label-for" target="cell-range-edit"/>
+                </accessibility>
+              </object>
+              <packing>
+                <property name="left-attach">0</property>
+                <property name="top-attach">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-5">ok</action-widget>
+      <action-widget response="-6">cancel</action-widget>
+      <action-widget response="-11">help</action-widget>
+    </action-widgets>
+  </object>
+</interface>
commit 041e4760453787283d6cb19327b53cc3642d91fc
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Apr 8 13:12:50 2022 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Wed Apr 13 01:34:54 2022 +0200

    sc: add an overlay to show sparklines in a sparkline group
    
    This adds an overlay that shows/selects all sparklines in a
    sparkline group for the cursor cell sparkline, if the cursor cell
    has an associated sparkline.
    
    Change-Id: I60a5873ebdf8606f262d217caf6011c4a003801a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132692
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit 34a97838137f6e54405722d607b7f414084f526e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132923
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index 00f6a80bab5d..645ed286e140 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -105,6 +105,7 @@ class SAL_DLLPUBLIC_RTTI ScGridWindow : public vcl::Window, 
public DropTargetHel
     std::unique_ptr<sdr::overlay::OverlayObjectList> mpOODragRect;
     std::unique_ptr<sdr::overlay::OverlayObjectList> mpOOHeader;
     std::unique_ptr<sdr::overlay::OverlayObjectList> mpOOShrink;
+    std::unique_ptr<sdr::overlay::OverlayObjectList> mpOOSparklineGroup;
 
     std::optional<tools::Rectangle> mpAutoFillRect;
 
@@ -461,6 +462,8 @@ public:
     const std::vector<editeng::MisspellRanges>* GetAutoSpellData( SCCOL nPosX, 
SCROW nPosY );
     bool InsideVisibleRange( SCCOL nPosX, SCROW nPosY );
 
+    void UpdateSparklineGroupOverlay();
+    void DeleteSparklineGroupOverlay();
     void            DeleteCopySourceOverlay();
     void            UpdateCopySourceOverlay();
     void            DeleteCursorOverlay();
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 747875042946..9982f3dbf24a 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -127,6 +127,7 @@
 #include <datamapper.hxx>
 #include <inputopt.hxx>
 #include <queryparam.hxx>
+#include <SparklineList.hxx>
 
 #include <officecfg/Office/Common.hxx>
 
@@ -6024,6 +6025,7 @@ void ScGridWindow::CursorChanged()
     // now, just re-create them
 
     UpdateCursorOverlay();
+    UpdateSparklineGroupOverlay();
 }
 
 void ScGridWindow::ImpCreateOverlayObjects()
@@ -6035,6 +6037,7 @@ void ScGridWindow::ImpCreateOverlayObjects()
     UpdateDragRectOverlay();
     UpdateHeaderOverlay();
     UpdateShrinkOverlay();
+    UpdateSparklineGroupOverlay();
 }
 
 void ScGridWindow::ImpDestroyOverlayObjects()
@@ -6046,6 +6049,7 @@ void ScGridWindow::ImpDestroyOverlayObjects()
     DeleteDragRectOverlay();
     DeleteHeaderOverlay();
     DeleteShrinkOverlay();
+    DeleteSparklineGroupOverlay();
 }
 
 void ScGridWindow::UpdateAllOverlays()
@@ -6953,6 +6957,69 @@ void ScGridWindow::UpdateShrinkOverlay()
         SetMapMode( aOldMode );
 }
 
+void ScGridWindow::DeleteSparklineGroupOverlay()
+{
+    mpOOSparklineGroup.reset();
+}
+
+void ScGridWindow::UpdateSparklineGroupOverlay()
+{
+    MapMode aDrawMode = GetDrawMapMode();
+
+    MapMode aOldMode = GetMapMode();
+    if (aOldMode != aDrawMode)
+        SetMapMode(aDrawMode);
+
+    DeleteSparklineGroupOverlay();
+
+    ScAddress aCurrentAddress = mrViewData.GetCurPos();
+
+    ScDocument& rDocument = mrViewData.GetDocument();
+    if (auto pSparkline = rDocument.GetSparkline(aCurrentAddress))
+    {
+        mpOOSparklineGroup.reset(new sdr::overlay::OverlayObjectList);
+
+        rtl::Reference<sdr::overlay::OverlayManager> xOverlayManager = 
getOverlayManager();
+        if (xOverlayManager.is())
+        {
+            auto* pList = rDocument.GetSparklineList(aCurrentAddress.Tab());
+            if (pList)
+            {
+                auto const& pSparklines = 
pList->getSparklinesFor(pSparkline->getSparklineGroup());
+
+                Color aColor = SvtOptionsDrawinglayer::getHilightColor();
+
+                std::vector<basegfx::B2DRange> aRanges;
+                const basegfx::B2DHomMatrix 
aTransform(GetOutDev()->GetInverseViewTransformation());
+
+                for (auto const& pCurrentSparkline : pSparklines)
+                {
+                    SCCOL nColumn = pCurrentSparkline->getColumn();
+                    SCROW nRow = pCurrentSparkline->getRow();
+
+                    Point aStart = mrViewData.GetScrPos(nColumn, nRow, eWhich);
+                    Point aEnd = mrViewData.GetScrPos(nColumn + 1, nRow + 1, 
eWhich);
+
+                    basegfx::B2DRange aRange(aStart.X(), aStart.Y(), aEnd.X(), 
aEnd.Y());
+
+                    aRange.transform(aTransform);
+                    aRanges.push_back(aRange);
+                }
+
+                std::unique_ptr<sdr::overlay::OverlayObject> pOverlay(new 
sdr::overlay::OverlaySelection(
+                        sdr::overlay::OverlayType::Transparent,
+                        aColor, std::move(aRanges), true));
+
+                xOverlayManager->add(*pOverlay);
+                mpOOSparklineGroup->append(std::move(pOverlay));
+            }
+        }
+    }
+
+    if (aOldMode != aDrawMode)
+        SetMapMode(aOldMode);
+}
+
 // #i70788# central method to get the OverlayManager safely
 rtl::Reference<sdr::overlay::OverlayManager> ScGridWindow::getOverlayManager() 
const
 {

Reply via email to