tdf#119178: use current range as a range for conditional format
During addition of new conditional format it is possible to select
different range, not one used initially. And new range should be
used for correct relative reference in formula evaluation.`
Change-Id: If73a0ddbb268c86e8c99f0703db1a5a97fb6ca66
Reviewed-on: https://gerrit.libreoffice.org/58800
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx
index eddbb15..6495210 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -38,6 +38,7 @@ ScCondFormatList::ScCondFormatList(vcl::Window* pParent, WinBits nStyle)
: Control(pParent, nStyle | WB_DIALOGCONTROL)
, mbHasScrollBar(false)
, mbFrozen(false)
, mbNewEntry(false)
, mpScrollBar(VclPtr<ScrollBar>::Create(this, WB_VERT ))
, mpDoc(nullptr)
, mpDialogParent(nullptr)
@@ -138,6 +139,7 @@ void ScCondFormatList::init(ScDocument* pDoc, ScCondFormatDlg* pDialogParent,
case condformat::dialog::NONE:
break;
}
mbNewEntry = true;
}
Thaw();
RecalcAll();
@@ -150,6 +152,11 @@ void ScCondFormatList::init(ScDocument* pDoc, ScCondFormatDlg* pDialogParent,
RecalcAll();
}
void ScCondFormatList::SetRange(const ScRangeList& rRange)
{
maRanges = rRange;
}
VCL_BUILDER_FACTORY_CONSTRUCTOR(ScCondFormatList, 0)
Size ScCondFormatList::GetOptimalSize() const
@@ -179,9 +186,20 @@ ScConditionalFormat* ScCondFormatList::GetConditionalFormat() const
ScConditionalFormat* pFormat = new ScConditionalFormat(0, mpDoc);
pFormat->SetRange(maRanges);
for(EntryContainer::const_iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
for(auto & rEntry: maEntries)
{
ScFormatEntry* pEntry = (*itr)->GetEntry();
// tdf#119178: Sometimes initial apply-to range (the one this dialog
// was opened with) is different from the final apply-to range
// (as edited by the user)
// If this format entry is new, take top-left corner of the final range
// and use it to create the initial entry (token array therein, if applicable)
if (mbNewEntry)
rEntry->SetPos(maRanges.GetTopLeftCorner());
// else do nothing: setting new position when editing recompiles formulas
// in entries and nobody wants that
ScFormatEntry* pEntry = rEntry->GetEntry();
if(pEntry)
pFormat->AddEntry(pEntry);
}
@@ -672,6 +690,7 @@ ScConditionalFormat* ScCondFormatDlg::GetConditionalFormat() const
ScRangeList aRange;
ScRefFlags nFlags = aRange.Parse(aRangeStr, mpViewData->GetDocument(),
mpViewData->GetDocument()->GetAddressConvention(), maPos.Tab());
mpCondFormList->SetRange(aRange);
ScConditionalFormat* pFormat = mpCondFormList->GetConditionalFormat();
if((nFlags & ScRefFlags::VALID) && !aRange.empty() && pFormat)
diff --git a/sc/source/ui/inc/condformatdlg.hxx b/sc/source/ui/inc/condformatdlg.hxx
index 684fd75..9c9706c 100644
--- a/sc/source/ui/inc/condformatdlg.hxx
+++ b/sc/source/ui/inc/condformatdlg.hxx
@@ -39,6 +39,7 @@ private:
bool mbHasScrollBar;
bool mbFrozen;
bool mbNewEntry;
VclPtr<ScrollBar> mpScrollBar;
ScDocument* mpDoc;
@@ -57,6 +58,8 @@ public:
const ScRangeList& rRanges, const ScAddress& rPos,
condformat::dialog::ScCondFormatDialogType eType);
void SetRange(const ScRangeList& rRange);
virtual Size GetOptimalSize() const override;
virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override;
virtual void Resize() override;
diff --git a/sc/source/ui/inc/condformatdlgentry.hxx b/sc/source/ui/inc/condformatdlgentry.hxx
index f949b0c..223d179 100644
--- a/sc/source/ui/inc/condformatdlgentry.hxx
+++ b/sc/source/ui/inc/condformatdlgentry.hxx
@@ -79,6 +79,7 @@ public:
virtual bool EventNotify( NotifyEvent& rNEvt ) override;
virtual void SetPos(const ScAddress& rPos) { maPos = rPos; };
bool IsSelected() const { return mbActive;}
void SetIndex(sal_Int32 nIndex);
void SetHeight();