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/utils/windowlist.cpp | 67 ++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 30 deletions(-) (limited to 'src/modules/utils/windowlist.cpp') 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