From 405f1a1f9238fa24f749350a762695ad6e42361f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 19 Jul 2012 18:18:58 +0000 Subject: quick search code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@1049 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/clist/clc.cpp | 25 ++++++++----------------- src/modules/clist/clcitems.cpp | 20 +++++++++----------- src/modules/clist/clcutils.cpp | 35 +++++++++++++++++++++-------------- 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/modules/clist/clc.cpp b/src/modules/clist/clc.cpp index 4097f5a0f3..49b8dd6870 100644 --- a/src/modules/clist/clc.cpp +++ b/src/modules/clist/clc.cpp @@ -738,15 +738,11 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, case VK_END: dat->selection = cli.pfnGetGroupContentsCount(&dat->list, 1) - 1; selMoved = 1; break; case VK_LEFT: changeGroupExpand = 1; break; case VK_RIGHT: changeGroupExpand = 2; break; - case VK_RETURN: cli.pfnDoSelectionDefaultAction(hwnd, dat); - // TODO: clear filtering here somehow? - /*if (dat->filterSearch) { - dat->szQuickSearch[0] = 0; + case VK_RETURN: + cli.pfnDoSelectionDefaultAction(hwnd, dat); + dat->szQuickSearch[0] = 0; + if (dat->filterSearch) cli.pfnSaveStateAndRebuildList(hwnd, dat); - //cli.pfnRebuildEntireList(hwnd, dat); - } else { - dat->szQuickSearch[0] = 0; - }*/ return 0; case VK_F2: cli.pfnBeginRenameSelection(hwnd, dat); return 0; case VK_DELETE: cli.pfnDeleteFromContactList(hwnd, dat); return 0; @@ -766,11 +762,8 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, int hit; ClcContact *contact; ClcGroup *group; - if (dat->filterSearch) { - // this shouldn't clear filtering, but it should refresh highlighting somehow? - } else { + if (!dat->filterSearch) dat->szQuickSearch[0] = 0; - } hit = cli.pfnGetRowByIndex(dat, dat->selection, &contact, &group); if (hit != -1) { if (changeGroupExpand == 1 && contact->type == CLCIT_CONTACT) { @@ -1237,11 +1230,6 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, cli.pfnHideInfoTip(hwnd, dat); KillTimer(hwnd, TIMERID_RENAME); KillTimer(hwnd, TIMERID_INFOTIP); - if (dat->filterSearch) { - // this should remove filtering (same as pressing ENTER)? - } else { - dat->szQuickSearch[0] = 0; - } dat->selection = cli.pfnHitTest(hwnd, dat, (short) LOWORD(lParam), (short) HIWORD(lParam), &contact, NULL, &hitFlags); cli.pfnInvalidateRect(hwnd, NULL, FALSE); if (dat->selection != -1) @@ -1250,6 +1238,9 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, break; UpdateWindow(hwnd); cli.pfnDoSelectionDefaultAction(hwnd, dat); + dat->szQuickSearch[0] = 0; + if (dat->filterSearch) + cli.pfnSaveStateAndRebuildList(hwnd, dat); break; } case WM_CONTEXTMENU: diff --git a/src/modules/clist/clcitems.cpp b/src/modules/clist/clcitems.cpp index 554cb80dcf..77ae140f73 100644 --- a/src/modules/clist/clcitems.cpp +++ b/src/modules/clist/clcitems.cpp @@ -394,17 +394,15 @@ void fnRebuildEntireList(HWND hwnd, struct ClcData *dat) if (group != NULL) { group->totalMembers++; - /*if (dat->filterSearch && dat->szQuickSearch) { - // search filtering - - // how to get contact's visible name? this code is crashing :) - ClcCacheEntryBase* cache = cli.pfnGetCacheEntry(hContact); - if (cache) { - //if (!_tcsstr(CharLowerW(pdnce->tszName), CharLowerW(dat->szQuickSearch))) - if (_tcsnicmp(dat->szQuickSearch, cache->tszName, lstrlen(dat->szQuickSearch))) - cli.pfnAddContactToGroup(dat, group, hContact); - } - } else*/ if ( !(style & CLS_NOHIDEOFFLINE) && (style & CLS_HIDEOFFLINE || group->hideOffline)) { + + if (dat->filterSearch && dat->szQuickSearch[0] != '\0') { + TCHAR *name = cli.pfnGetContactDisplayName(hContact, GCDNF_TCHAR); + TCHAR *lowered_name = CharLowerW(NEWTSTR_ALLOCA(name)); + TCHAR *lowered_search = CharLowerW(NEWTSTR_ALLOCA(dat->szQuickSearch)); + + if (_tcsstr(lowered_name, lowered_search)) + cli.pfnAddContactToGroup(dat, group, hContact); + } else if ( !(style & CLS_NOHIDEOFFLINE) && (style & CLS_HIDEOFFLINE || group->hideOffline)) { szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if (szProto == NULL) { if ( !cli.pfnIsHiddenMode(dat, ID_STATUS_OFFLINE)) diff --git a/src/modules/clist/clcutils.cpp b/src/modules/clist/clcutils.cpp index 6323d4c863..dc3acdfe9e 100644 --- a/src/modules/clist/clcutils.cpp +++ b/src/modules/clist/clcutils.cpp @@ -369,21 +369,28 @@ int fnFindRowByText(HWND hwnd, struct ClcData *dat, const TCHAR *text, int prefi continue; } if (group->cl.items[group->scanIndex]->type != CLCIT_DIVIDER) { - if ((prefixOk && !_tcsnicmp(text, group->cl.items[group->scanIndex]->szText, testlen)) || - ( !prefixOk && !lstrcmpi(text, group->cl.items[group->scanIndex]->szText))) { - ClcGroup *contactGroup = group; - int contactScanIndex = group->scanIndex; - for (; group; group = group->parent) - cli.pfnSetGroupExpand(hwnd, dat, group, 1); - return cli.pfnGetRowsPriorTo(&dat->list, contactGroup, contactScanIndex); - } - if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) { - if ( !(dat->exStyle & CLS_EX_QUICKSEARCHVISONLY) || group->cl.items[group->scanIndex]->group->expanded) { - group = group->cl.items[group->scanIndex]->group; - group->scanIndex = 0; - continue; - } + bool show; + if (dat->filterSearch) { + TCHAR *lowered_szText = CharLowerW(NEWTSTR_ALLOCA(group->cl.items[group->scanIndex]->szText)); + TCHAR *lowered_text = CharLowerW(NEWTSTR_ALLOCA(text)); + show = _tcsstr(lowered_szText, lowered_text) != NULL; + } + else show = ((prefixOk && !_tcsnicmp(text, group->cl.items[group->scanIndex]->szText, testlen)) || ( !prefixOk && !lstrcmpi(text, group->cl.items[group->scanIndex]->szText))); + + if (show) { + ClcGroup *contactGroup = group; + int contactScanIndex = group->scanIndex; + for (; group; group = group->parent) + cli.pfnSetGroupExpand(hwnd, dat, group, 1); + return cli.pfnGetRowsPriorTo(&dat->list, contactGroup, contactScanIndex); + } + if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) { + if ( !(dat->exStyle & CLS_EX_QUICKSEARCHVISONLY) || group->cl.items[group->scanIndex]->group->expanded) { + group = group->cl.items[group->scanIndex]->group; + group->scanIndex = 0; + continue; } + } } group->scanIndex++; } -- cgit v1.2.3