tdf#133785 autofilter with dates crashes when search entry is used and cleared
restore original logic, and just keep the clear-all optimization for the
non-hierarchical case
Change-Id: Iafcd934c7e6e48e7e11f7fca9e51478e7e678b44
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95793
Tested-by: Jenkins
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx
index 02ed5ed..2797664 100644
--- a/sc/source/ui/cctrl/checklistmenu.cxx
+++ b/sc/source/ui/cctrl/checklistmenu.cxx
@@ -888,7 +888,8 @@
maBtnCancel(VclPtr<CancelButton>::Create(this)),
maWndSize(),
mePrevToggleAllState(TRISTATE_INDET),
maTabStops(this)
maTabStops(this),
mbHasDates(false)
{
maChkToggleAll->EnableTriState(true);
@@ -1227,7 +1228,7 @@
maChecks->SetUpdateMode(false);
if (bSearchTextEmpty)
if (bSearchTextEmpty && !mbHasDates)
{
// when there are a lot of rows, it is cheaper to simply clear the tree and re-initialise
maChecks->Clear();
@@ -1244,14 +1245,28 @@
if ( aLabelDisp.isEmpty() )
aLabelDisp = ScResId( STR_EMPTYDATA );
if ( !bIsDate )
bPartialMatch = ( ScGlobal::getCharClassPtr()->lowercase( aLabelDisp ).indexOf( aSearchText ) != -1 );
else if ( maMembers[i].meDatePartType == ScCheckListMember::DAY ) // Match with both numerical and text version of month
bPartialMatch = (ScGlobal::getCharClassPtr()->lowercase( OUString(
maMembers[i].maRealName + maMembers[i].maDateParts[1] )).indexOf( aSearchText ) != -1);
else
if ( !bSearchTextEmpty )
{
if ( !bIsDate )
bPartialMatch = ( ScGlobal::getCharClassPtr()->lowercase( aLabelDisp ).indexOf( aSearchText ) != -1 );
else if ( maMembers[i].meDatePartType == ScCheckListMember::DAY ) // Match with both numerical and text version of month
bPartialMatch = (ScGlobal::getCharClassPtr()->lowercase( OUString(
maMembers[i].maRealName + maMembers[i].maDateParts[1] )).indexOf( aSearchText ) != -1);
else
continue;
}
else if ( bIsDate && maMembers[i].meDatePartType != ScCheckListMember::DAY )
continue;
if ( bSearchTextEmpty )
{
SvTreeListEntry* pLeaf = maChecks->ShowCheckEntry( aLabelDisp, maMembers[i], true, maMembers[i].mbVisible );
updateMemberParents( pLeaf, i );
if ( maMembers[i].mbVisible )
++nSelCount;
continue;
}
if ( bPartialMatch )
{
SvTreeListEntry* pLeaf = maChecks->ShowCheckEntry( aLabelDisp, maMembers[i] );
@@ -1881,9 +1896,10 @@
void ScCheckListMenuWindow::setHasDates(bool bHasDates)
{
mbHasDates = bHasDates;
// Enables type-ahead search in the check list box.
maChecks->SetQuickSearch(true);
if (bHasDates)
if (mbHasDates)
maChecks->SetStyle(WB_HASBUTTONS | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONSATROOT);
else
maChecks->SetStyle(WB_HASBUTTONS);
@@ -1894,7 +1910,6 @@
size_t n = maMembers.size();
size_t nVisMemCount = 0;
maChecks->SetUpdateMode(false);
maChecks->GetModel()->EnableInvalidate(false);
diff --git a/sc/source/ui/inc/checklistmenu.hxx b/sc/source/ui/inc/checklistmenu.hxx
index d0ce251..5e988e3 100644
--- a/sc/source/ui/inc/checklistmenu.hxx
+++ b/sc/source/ui/inc/checklistmenu.hxx
@@ -439,6 +439,7 @@
Size maMenuSize; /// size of all menu items combined.
TriState mePrevToggleAllState;
ScTabStops maTabStops;
bool mbHasDates;
};
#endif