tdf#108259 Fix nested checkbox handling in autofilter popup

The regression breaks autofilter with hierarchy (date for example).

Commit id which introduces the regression 511fb8e80d298d42f5c45e7410bf64f2a25b441e

Change-Id: If15f32db6b8c1a90d96fefe9740173c2cbfb919a
Reviewed-on: https://gerrit.libreoffice.org/38343
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx
index 66251017..d4ff05e 100644
--- a/sc/source/ui/cctrl/checklistmenu.cxx
+++ b/sc/source/ui/cctrl/checklistmenu.cxx
@@ -1639,21 +1639,39 @@ void ScCheckListBox::Init()
    SetNodeDefaultImages();
}

void ScCheckListBox::GetRecursiveChecked(SvTreeListEntry* pEntry, std::unordered_set<OUString, OUStringHash>& vOut, SvTreeListEntry* pParent)
{
    if (GetCheckButtonState(pEntry) == SvButtonState::Checked)
    {
        // we have to hash both parent and child together
        OUString aName = GetEntryText(pEntry);
        if (pParent) aName += GetEntryText(pParent);
        vOut.insert(aName);
    }

    if (pEntry->HasChildren())
    {
        const SvTreeListEntries& rChildren = pEntry->GetChildEntries();
        for (auto& rChild : rChildren)
        {
            GetRecursiveChecked(rChild.get(), vOut, pEntry);
        }
    }

}

std::unordered_set<OUString, OUStringHash> ScCheckListBox::GetAllChecked()
{
    std::unordered_set<OUString, OUStringHash> results(0);
    std::unordered_set<OUString, OUStringHash> vResults(0);
    sal_uInt32 nRootPos = 0;
    SvTreeListEntry* pEntry = GetEntry(nRootPos);
    while (pEntry)
    {
        if (GetCheckButtonState(pEntry) == SvButtonState::Checked)
        {
            results.insert(GetEntryText(pEntry));
        }
        GetRecursiveChecked(pEntry, vResults, nullptr);
        pEntry = GetEntry(++nRootPos);
    }

    return results;
    return vResults;
}

bool ScCheckListBox::IsChecked( const OUString& sName, SvTreeListEntry* pParent )
@@ -1924,7 +1942,7 @@ bool ScCheckListMenuWindow::isAllSelected() const
void ScCheckListMenuWindow::getResult(ResultType& rResult)
{
    ResultType aResult;
    std::unordered_set<OUString, OUStringHash> checkeds = maChecks->GetAllChecked();
    std::unordered_set<OUString, OUStringHash> vCheckeds = maChecks->GetAllChecked();
    size_t n = maMembers.size();
    for (size_t i = 0; i < n; ++i)
    {
@@ -1933,7 +1951,10 @@ void ScCheckListMenuWindow::getResult(ResultType& rResult)
            OUString aLabel = maMembers[i].maName;
            if (aLabel.isEmpty())
                aLabel = ScGlobal::GetRscString(STR_EMPTYDATA);
            bool bState = checkeds.find(aLabel) != checkeds.end();

            bool bState = vCheckeds.find(maMembers[i].mpParent ?
                    aLabel.copy(0).concat(maChecks->GetEntryText(maMembers[i].mpParent)) :
                    aLabel) != vCheckeds.end();
            ResultEntry aResultEntry;
            aResultEntry.bValid = bState;
            if ( maMembers[i].mbDate )
diff --git a/sc/source/ui/inc/checklistmenu.hxx b/sc/source/ui/inc/checklistmenu.hxx
index 7bae385..6ac7c48 100644
--- a/sc/source/ui/inc/checklistmenu.hxx
+++ b/sc/source/ui/inc/checklistmenu.hxx
@@ -240,6 +240,7 @@ class ScCheckListBox : public SvTreeListBox
    void CheckEntry( const OUString& sName, SvTreeListEntry* pParent, bool bCheck );
    void CheckEntry( SvTreeListEntry* pEntry, bool bCheck );
    SvTreeListEntry* ShowCheckEntry( const OUString& sName, ScCheckListMember& rMember, bool bShow = true, bool bCheck = true );
    void GetRecursiveChecked(SvTreeListEntry* pEntry, std::unordered_set<OUString, OUStringHash>& vOut, SvTreeListEntry* pParent);
    std::unordered_set<OUString, OUStringHash> GetAllChecked();
    bool IsChecked( const OUString& sName, SvTreeListEntry* pParent );
    SvTreeListEntry* FindEntry( SvTreeListEntry* pParent, const OUString& sNode );