From 041d0b32f53961d6f2429217f1a0365ef2bbbdca Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 14 Apr 2025 16:25:48 +0300 Subject: fix for a very old bug when sometimes not all groups were displayed in the contact list --- src/mir_app/mir_app.vcxproj.filters | 6 +-- src/mir_app/src/clc.cpp | 12 +++-- src/mir_app/src/clc.h | 6 ++- src/mir_app/src/clcitems.cpp | 8 +-- src/mir_app/src/clcmsgs.cpp | 16 ++++-- src/mir_app/src/clistgroups.cpp | 99 +++++++++++++++++-------------------- src/mir_app/src/cluiservices.cpp | 14 ------ src/mir_app/src/mir_app.def | 1 - src/mir_app/src/mir_app64.def | 1 - 9 files changed, 73 insertions(+), 90 deletions(-) (limited to 'src') diff --git a/src/mir_app/mir_app.vcxproj.filters b/src/mir_app/mir_app.vcxproj.filters index 5586935271..4fb2f19c70 100644 --- a/src/mir_app/mir_app.vcxproj.filters +++ b/src/mir_app/mir_app.vcxproj.filters @@ -386,9 +386,6 @@ Source Files\Contact list - - Source Files\MetaContacts - Source Files\Chats @@ -434,6 +431,9 @@ Source Files\Contact list + + Source Files\Contact list + diff --git a/src/mir_app/src/clc.cpp b/src/mir_app/src/clc.cpp index 6b8fadb013..788931360d 100644 --- a/src/mir_app/src/clc.cpp +++ b/src/mir_app/src/clc.cpp @@ -70,6 +70,12 @@ static int ClcSettingChanged(WPARAM hContact, LPARAM lParam) { DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam; + if (!strcmp(cws->szModule, GROUPS_MODULE)) { + if (!g_bGroupsLocked) + Clist_Broadcast(INTM_GROUPSCHANGED, hContact, lParam); + return 0; + } + if (!strcmp(cws->szModule, "CList")) { if (!strcmp(cws->szSetting, "MyHandle")) { g_clistApi.pfnInvalidateDisplayNameCacheEntry(hContact); @@ -375,12 +381,10 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam bool eq = !mir_wstrcmp(szFullName, pGroup->groupName); if (eq && contact->group->bHideOffline == ((pGroup->flags & GROUPF_HIDEOFFLINE) != 0)) break; // only expanded has changed: no action reqd - - Clist_SaveStateAndRebuildList(hwnd, dat); - break; } + Clist_SaveStateAndRebuildList(hwnd, dat); } - Clist_InitAutoRebuild(hwnd); + else Clist_InitAutoRebuild(hwnd); break; case INTM_NAMEORDERCHANGED: diff --git a/src/mir_app/src/clc.h b/src/mir_app/src/clc.h index 559db8dbaa..935baed370 100644 --- a/src/mir_app/src/clc.h +++ b/src/mir_app/src/clc.h @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma once #define MODULENAME "CList" +#define GROUPS_MODULE "ClistGroups" struct ClcContact : public ClcContactBase { @@ -176,9 +177,12 @@ struct CGroupInternal CGroupInternal(int _id, const wchar_t *_name, int _flags); ~CGroupInternal(); - int groupId, oldId = -1, flags; + int groupId, flags; bool bSaveExpanded; wchar_t *groupName; + void remove(); void save(); }; + +void Clist_RebuildGroups(HWND hwnd, ClcData *dat); diff --git a/src/mir_app/src/clcitems.cpp b/src/mir_app/src/clcitems.cpp index 2611c2a30d..df60a7ee3d 100644 --- a/src/mir_app/src/clcitems.cpp +++ b/src/mir_app/src/clcitems.cpp @@ -351,13 +351,7 @@ void fnRebuildEntireList(HWND hwnd, ClcData *dat) dat->list.totalMembers = 0; dat->selection = -1; - for (int i = 1;; i++) { - uint32_t groupFlags; - wchar_t *szGroupName = Clist_GroupGetName(i, &groupFlags); - if (szGroupName == nullptr) - break; - g_clistApi.pfnAddGroup(hwnd, dat, szGroupName, groupFlags, i, 0); - } + Clist_RebuildGroups(hwnd, dat); for (auto &hContact : Contacts()) { int nHiddenStatus = g_clistApi.pfnGetContactHiddenStatus(hContact, nullptr, dat); diff --git a/src/mir_app/src/clcmsgs.cpp b/src/mir_app/src/clcmsgs.cpp index 70c7e209f1..23260fd237 100644 --- a/src/mir_app/src/clcmsgs.cpp +++ b/src/mir_app/src/clcmsgs.cpp @@ -382,11 +382,17 @@ LRESULT fnProcessExternalMessages(HWND hwnd, ClcData *dat, UINT msg, WPARAM wPar break; case CLM_SETHIDEEMPTYGROUPS: - if (wParam) - SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | CLS_HIDEEMPTYGROUPS); - else - SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~CLS_HIDEEMPTYGROUPS); - Clist_InitAutoRebuild(hwnd); + { + BOOL oldVal = ((GetWindowLongPtr(hwnd, GWL_STYLE) & CLS_HIDEEMPTYGROUPS) != 0); + BOOL newVal = (wParam != 0); + if (newVal) + SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | CLS_HIDEEMPTYGROUPS); + else + SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~CLS_HIDEEMPTYGROUPS); + + if (newVal != oldVal) + Clist_InitAutoRebuild(hwnd); + } break; case CLM_SETHIDEOFFLINEROOT: diff --git a/src/mir_app/src/clistgroups.cpp b/src/mir_app/src/clistgroups.cpp index 37219791b3..96fff9ba8f 100644 --- a/src/mir_app/src/clistgroups.cpp +++ b/src/mir_app/src/clistgroups.cpp @@ -25,8 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "clc.h" -#define GROUPS_MODULE "ClistGroups" - #define MAX_GROUPNAME_LEN 256 HANDLE hGroupChangeEvent; @@ -51,28 +49,6 @@ static CGroupInternal* FindGroup(int key) return arByIds.find((CGroupInternal *)&key); } -///////////////////////////////////////////////////////////////////////////////////////// - -static CTimer *g_pTimer; - -struct CGroupImpl -{ - void OnTimer(CTimer *) - { - g_pTimer->Stop(); - - for (auto &it : arByIds) { - JSONNode grp; - grp << INT_PARAM("id", it->groupId) << WCHAR_PARAM("name", it->groupName) << INT_PARAM("flags", it->flags); - - char szSetting[40]; - itoa(it->groupId, szSetting, 10); - db_set_s(0, GROUPS_MODULE, szSetting, grp.write().c_str()); - } - } -} -g_impl; - ///////////////////////////////////////////////////////////////////////////////////////// // CGroupInternal members @@ -89,12 +65,23 @@ CGroupInternal::~CGroupInternal() mir_free(groupName); } +void CGroupInternal::remove() +{ + char szSetting[40]; + itoa(groupId, szSetting, 10); + db_unset(0, GROUPS_MODULE, szSetting); +} + void CGroupInternal::save() { Clist_BroadcastAsync(INTM_GROUPSCHANGED, 0, LPARAM(this)); - if (g_pTimer) - g_pTimer->Start(1000); + JSONNode grp; + grp << INT_PARAM("id", groupId) << WCHAR_PARAM("name", groupName) << INT_PARAM("flags", flags); + + char szSetting[40]; + itoa(groupId, szSetting, 10); + db_set_s(0, GROUPS_MODULE, szSetting, grp.write().c_str()); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -118,6 +105,28 @@ MIR_APP_DLL(MGROUP) Clist_GroupExists(LPCTSTR ptszGroupName) ///////////////////////////////////////////////////////////////////////////////////////// +void Clist_RebuildGroups(HWND hwnd, ClcData *dat) +{ + for (auto &it: arByIds) + g_clistApi.pfnAddGroup(hwnd, dat, it->groupName, it->flags, it->groupId+1, 0); +} + +void Clist_GroupAdded(MGROUP hGroup) +{ + // CLC does this automatically unless it's a new group + HWND hwndFocus = GetFocus(); + + wchar_t szFocusClass[64]; + GetClassName(hwndFocus, szFocusClass, _countof(szFocusClass)); + if (!mir_wstrcmp(szFocusClass, CLISTCONTROL_CLASSW)) { + HANDLE hItem = (HANDLE)SendMessage(hwndFocus, CLM_FINDGROUP, hGroup, 0); + if (hItem) + SendMessage(hwndFocus, CLM_EDITLABEL, (WPARAM)hItem, 0); + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + static INT_PTR CreateGroupInternal(MGROUP hParent, const wchar_t *ptszName) { wchar_t newBaseName[MAX_GROUPNAME_LEN-1], newName[MAX_GROUPNAME_LEN]; @@ -143,7 +152,7 @@ static INT_PTR CreateGroupInternal(MGROUP hParent, const wchar_t *ptszName) mir_snwprintf(newName, L"%s (%d)", newBaseName, idCopy); } - int newId = arByIds.getCount(); + int newId = arByIds.getCount() ? arByIds[arByIds.getCount() - 1]->groupId + 1 : 0; CGroupInternal *pNew = new CGroupInternal(newId, newName, GROUPF_EXPANDED); arByIds.insert(pNew); arByName.insert(pNew); @@ -244,25 +253,15 @@ MIR_APP_DLL(int) Clist_GroupDelete(MGROUP hGroup, bool bSilent) NotifyEventHooks(hGroupChangeEvent, hContact, (LPARAM)&grpChg); } - // shuffle list of groups up to fill gap - for (auto &it : arByIds) - it->oldId = it->groupId; - - int iGap = 0; - for (auto &it : arByIds.rev_iter()) { - if (!isParentOf(wszOldName, it->groupName)) - continue; - - iGap++; - arByName.remove(it); - arByIds.removeItem(&it); - } - - for (auto &it : arByIds) { - it->groupId = arByIds.indexOf(&it); - if (it->groupId != it->oldId) - it->save(); - } + // remove all child groups + for (auto &it : arByIds.rev_iter()) + if (isParentOf(wszOldName, it->groupName)) { + auto *p = it; + arByName.remove(it); + arByIds.removeItem(&it); + p->remove(); + delete p; + } SetCursor(LoadCursor(nullptr, IDC_ARROW)); Clist_LoadContactTree(); @@ -271,7 +270,6 @@ MIR_APP_DLL(int) Clist_GroupDelete(MGROUP hGroup, bool bSilent) const CLISTGROUPCHANGE grpChg = { wszOldName, nullptr }; NotifyEventHooks(hGroupChangeEvent, 0, (LPARAM)&grpChg); - delete pGroup; return 0; } @@ -579,9 +577,6 @@ static int enumGroups(const char *szSetting, void *) int InitGroupServices(void) { - g_pTimer = new CTimer(Miranda_GetSystemWindow(), UINT_PTR(&g_pTimer)); - g_pTimer->OnEvent = Callback(&g_impl, &CGroupImpl::OnTimer); - if (!db_get_b(0, "Compatibility", "Groups")) { char str[32]; for (int i = 0;; i++) { @@ -606,7 +601,6 @@ int InitGroupServices(void) arByIds.insert(p); arByName.insert(p); } - g_pTimer->Start(100); DeleteFileW(wszJson); } else db_enum_settings(0, &enumGroups, GROUPS_MODULE); @@ -618,9 +612,6 @@ int InitGroupServices(void) void UninitGroupServices(void) { - g_pTimer->OnTimer(); - delete g_pTimer; - for (auto &p : arByIds) delete p; diff --git a/src/mir_app/src/cluiservices.cpp b/src/mir_app/src/cluiservices.cpp index f4e2fee28f..9bab528b29 100644 --- a/src/mir_app/src/cluiservices.cpp +++ b/src/mir_app/src/cluiservices.cpp @@ -25,20 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "clc.h" -EXTERN_C MIR_APP_DLL(void) Clist_GroupAdded(MGROUP hGroup) -{ - // CLC does this automatically unless it's a new group - HWND hwndFocus = GetFocus(); - - wchar_t szFocusClass[64]; - GetClassName(hwndFocus, szFocusClass, _countof(szFocusClass)); - if (!mir_wstrcmp(szFocusClass, CLISTCONTROL_CLASSW)) { - HANDLE hItem = (HANDLE)SendMessage(hwndFocus, CLM_FINDGROUP, hGroup, 0); - if (hItem) - SendMessage(hwndFocus, CLM_EDITLABEL, (WPARAM)hItem, 0); - } -} - EXTERN_C MIR_APP_DLL(void) Clist_EndRebuild(void) { if (g_clistApi.hwndContactTree == nullptr) diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 66816d653b..af9cf10b8c 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -177,7 +177,6 @@ Clist_GroupSetFlags @256 Clist_GroupGetName @257 Clist_GroupRename @258 Clist_EndRebuild @259 -Clist_GroupAdded @260 ?GetInfo@Contact@@YGPA_WHIPBD@Z @261 NONAME Clist_ContactToHItem @262 NONAME Clist_ContactToItemHandle @263 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 4873b014dc..7b0063123a 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -177,7 +177,6 @@ Clist_GroupSetFlags @256 Clist_GroupGetName @257 Clist_GroupRename @258 Clist_EndRebuild @259 -Clist_GroupAdded @260 ?GetInfo@Contact@@YAPEA_WHIPEBD@Z @261 NONAME Clist_ContactToHItem @262 NONAME Clist_ContactToItemHandle @263 NONAME -- cgit v1.2.3