From ef0abe4f9f67eeff4007f4839ba08a503472c74c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 21 Jan 2014 23:24:02 +0000 Subject: - new typed helper, WindowList_Create, to create a window list - new service, WindowList_Destroy, to destroy a window list - internal windowlist.cpp implementation rewritten to LIST<> git-svn-id: http://svn.miranda-ng.org/main/trunk@7823 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/chat/chat_svc.cpp | 1 + src/modules/clist/clc.cpp | 3 +- src/modules/utils/utils.cpp | 3 -- src/modules/utils/windowlist.cpp | 67 ++++++++++++++++++++++------------------ 4 files changed, 40 insertions(+), 34 deletions(-) (limited to 'src/modules') diff --git a/src/modules/chat/chat_svc.cpp b/src/modules/chat/chat_svc.cpp index 0644d3e983..73b77c48f7 100644 --- a/src/modules/chat/chat_svc.cpp +++ b/src/modules/chat/chat_svc.cpp @@ -610,6 +610,7 @@ int LoadChatModule(void) void UnloadChatModule(void) { + FreeMsgLogBitmaps(); OptionsUnInit(); DeleteCriticalSection(&cs); diff --git a/src/modules/clist/clc.cpp b/src/modules/clist/clc.cpp index 6e24efeb82..d223f59307 100644 --- a/src/modules/clist/clc.cpp +++ b/src/modules/clist/clc.cpp @@ -212,7 +212,7 @@ int LoadCLCModule(void) g_IconWidth = GetSystemMetrics(SM_CXSMICON); g_IconHeight = GetSystemMetrics(SM_CYSMICON); - hClcWindowList = (HANDLE) CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0); + hClcWindowList = WindowList_Create(); hShowInfoTipEvent = CreateHookableEvent(ME_CLC_SHOWINFOTIP); hHideInfoTipEvent = CreateHookableEvent(ME_CLC_HIDEINFOTIP); CreateServiceFunction(MS_CLC_SETINFOTIPHOVERTIME, SetInfoTipHoverTime); @@ -238,6 +238,7 @@ void UnloadClcModule() if (!bModuleInitialized) return; mir_free(cli.clcProto); + WindowList_Destroy(hClcWindowList); FreeDisplayNameCache(); diff --git a/src/modules/utils/utils.cpp b/src/modules/utils/utils.cpp index 36815e0a26..deb41b3e90 100644 --- a/src/modules/utils/utils.cpp +++ b/src/modules/utils/utils.cpp @@ -28,8 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. INT_PTR ResizeDialog(WPARAM wParam, LPARAM lParam); -void FreeWindowList(void); - int InitOpenUrl(void); int InitWindowList(void); int InitPathUtils(void); @@ -493,5 +491,4 @@ void UnloadUtilsModule(void) return; UninitCrypt(); - FreeWindowList(); } diff --git a/src/modules/utils/windowlist.cpp b/src/modules/utils/windowlist.cpp index 04f5963ca9..1b3c3493ab 100644 --- a/src/modules/utils/windowlist.cpp +++ b/src/modules/utils/windowlist.cpp @@ -24,62 +24,79 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\..\core\commonheaders.h" -static WINDOWLISTENTRY *windowList = NULL; -static int windowListCount = 0; -static int nextWindowListId = 1; +struct TWindowListItem +{ + TWindowListItem(HANDLE _contact, HWND _wnd) : + hContact(_contact), + hWnd(_wnd) + {} + + HANDLE hContact; + HWND hWnd; +}; + +typedef OBJLIST TWindowList; static INT_PTR AllocWindowList(WPARAM, LPARAM) { - return nextWindowListId++; + return (INT_PTR)new TWindowList(10, HandleKeySortT); +} + +static INT_PTR DestroyWindowList(WPARAM wParam, LPARAM) +{ + delete (TWindowList*)wParam; + return 0; } static INT_PTR AddToWindowList(WPARAM, LPARAM lParam) { - windowList = (WINDOWLISTENTRY*)mir_realloc(windowList, sizeof(WINDOWLISTENTRY)*(windowListCount + 1)); - windowList[windowListCount++] = *(WINDOWLISTENTRY*)lParam; + WINDOWLISTENTRY *pEntry = (WINDOWLISTENTRY*)lParam; + TWindowList *pList = (TWindowList*)pEntry->hList; + pList->insert(new TWindowListItem(pEntry->hContact, pEntry->hwnd)); return 0; } static INT_PTR RemoveFromWindowList(WPARAM wParam, LPARAM lParam) { - for (int i = 0; i < windowListCount; i++) - if (windowList[i].hwnd == (HWND)lParam && windowList[i].hList == (HANDLE)wParam) { - MoveMemory(&windowList[i], &windowList[i + 1], sizeof(WINDOWLISTENTRY)*(windowListCount - i - 1)); - windowListCount--; + TWindowList &pList = *(TWindowList*)wParam; + for (int i = 0; i < pList.getCount(); i++) { + if (pList[i].hWnd == (HWND)lParam) { + pList.remove(i); return 0; } + } return 1; } static INT_PTR FindInWindowList(WPARAM wParam, LPARAM lParam) { - for (int i = 0; i < windowListCount; i++) - if (windowList[i].hContact == (HANDLE)lParam && windowList[i].hList == (HANDLE)wParam) - return (INT_PTR)windowList[i].hwnd; - return 0; + TWindowList &pList = *(TWindowList*)wParam; + TWindowListItem *p = pList.find((TWindowListItem*)&lParam); + return (p == NULL) ? 0 : (INT_PTR)p->hWnd; } static INT_PTR BroadcastToWindowList(WPARAM wParam, LPARAM lParam) { MSG *msg = (MSG*)lParam; - for (int i = windowListCount-1; i >= 0; i--) - if (windowList[i].hList == (HANDLE)wParam) - SendMessage(windowList[i].hwnd, msg->message, msg->wParam, msg->lParam); + TWindowList &pList = *(TWindowList*)wParam; + for (int i = pList.getCount()-1; i >= 0; i--) + SendMessage(pList[i].hWnd, msg->message, msg->wParam, msg->lParam); return 0; } static INT_PTR BroadcastToWindowListAsync(WPARAM wParam, LPARAM lParam) { MSG *msg = (MSG*)lParam; - for (int i = windowListCount - 1; i >= 0; i--) - if (windowList[i].hList == (HANDLE)wParam) - PostMessage(windowList[i].hwnd, msg->message, msg->wParam, msg->lParam); + TWindowList &pList = *(TWindowList*)wParam; + for (int i = pList.getCount()-1; i >= 0; i--) + PostMessage(pList[i].hWnd, msg->message, msg->wParam, msg->lParam); return 0; } int InitWindowList(void) { CreateServiceFunction(MS_UTILS_ALLOCWINDOWLIST, AllocWindowList); + CreateServiceFunction(MS_UTILS_DESTROYWINDOWLIST, DestroyWindowList); CreateServiceFunction(MS_UTILS_ADDTOWINDOWLIST, AddToWindowList); CreateServiceFunction(MS_UTILS_REMOVEFROMWINDOWLIST, RemoveFromWindowList); CreateServiceFunction(MS_UTILS_BROADCASTTOWINDOWLIST, BroadcastToWindowList); @@ -87,13 +104,3 @@ int InitWindowList(void) CreateServiceFunction(MS_UTILS_FINDWINDOWINLIST, FindInWindowList); return 0; } - -void FreeWindowList(void) -{ - if (windowList) { - mir_free(windowList); - windowList = NULL; - } - windowListCount = 0; - nextWindowListId = 1; -} -- cgit v1.2.3