diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-17 08:35:51 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-17 08:35:51 +0000 |
commit | ee2e419778605a5445474a33a29f2cfbb7eed245 (patch) | |
tree | 404194e1d202f6433693f3833792e940c04e2d7e /plugins/YAPP | |
parent | 1ca120b165c2f2d9f521a04bfc31c7956d2ce422 (diff) |
bunch of fixes for various memory-related problems
git-svn-id: http://svn.miranda-ng.org/main/trunk@1001 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/YAPP')
-rw-r--r-- | plugins/YAPP/message_pump.cpp | 116 | ||||
-rw-r--r-- | plugins/YAPP/popwin.cpp | 39 | ||||
-rw-r--r-- | plugins/YAPP/popwin.h | 26 | ||||
-rw-r--r-- | plugins/YAPP/services.cpp | 91 |
4 files changed, 133 insertions, 139 deletions
diff --git a/plugins/YAPP/message_pump.cpp b/plugins/YAPP/message_pump.cpp index 4a2b05b081..7e2cea5f0c 100644 --- a/plugins/YAPP/message_pump.cpp +++ b/plugins/YAPP/message_pump.cpp @@ -72,7 +72,8 @@ bool is_workstation_locked() }
-unsigned __stdcall MessagePumpThread(void* param) {
+unsigned __stdcall MessagePumpThread(void* param)
+{
InitWindowStack();
if(param) SetEvent((HANDLE)param);
@@ -81,65 +82,64 @@ unsigned __stdcall MessagePumpThread(void* param) { while(GetMessage(&hwndMsg, 0, 0, 0) > 0 && !Miranda_Terminated()) {
if (!IsDialogMessage(hwndMsg.hwnd, &hwndMsg)) {
switch(hwndMsg.message) {
- case MUM_CREATEPOPUP:
- {
- bool enabled = true;
- int status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0);
- if(status >= ID_STATUS_OFFLINE && status <= ID_STATUS_OUTTOLUNCH && options.disable_status[status - ID_STATUS_OFFLINE])
- enabled = false;
- if ((options.disable_full_screen && is_full_screen()) || is_workstation_locked())
- enabled = false;
-
- PopupData *pd = (PopupData *)hwndMsg.lParam;
- if(enabled && num_popups < MAX_POPUPS) {
- //HWND hwnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, POP_WIN_CLASS, _T("Popup"), WS_POPUP, 0, 0, 0, 0, GetDesktopWindow(), 0, hInst, (LPVOID)hwndMsg.lParam);
- HWND hwnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, POP_WIN_CLASS, _T("Popup"), WS_POPUP, 0, 0, 0, 0, 0, 0, hInst, (LPVOID)hwndMsg.lParam);
- num_popups++;
- if(hwndMsg.wParam) // set notifyer handle
- SendMessage(hwnd, PUM_SETNOTIFYH, hwndMsg.wParam, 0);
- } else {
- if (pd) {
- mir_free(pd->pwzTitle);
- mir_free(pd->pwzText);
- mir_free(pd);
- }
- }
- }
- break;
-
- case MUM_DELETEPOPUP:
- {
- HWND hwnd = (HWND)hwndMsg.lParam;
- if(IsWindow(hwnd)) {
- DestroyWindow(hwnd);
- num_popups--;
+ case MUM_CREATEPOPUP:
+ {
+ bool enabled = true;
+ int status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0);
+ if(status >= ID_STATUS_OFFLINE && status <= ID_STATUS_OUTTOLUNCH && options.disable_status[status - ID_STATUS_OFFLINE])
+ enabled = false;
+ if ((options.disable_full_screen && is_full_screen()) || is_workstation_locked())
+ enabled = false;
+
+ PopupData *pd = (PopupData *)hwndMsg.lParam;
+ if(enabled && num_popups < MAX_POPUPS) {
+ //HWND hwnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, POP_WIN_CLASS, _T("Popup"), WS_POPUP, 0, 0, 0, 0, GetDesktopWindow(), 0, hInst, (LPVOID)hwndMsg.lParam);
+ HWND hwnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, POP_WIN_CLASS, _T("Popup"), WS_POPUP, 0, 0, 0, 0, 0, 0, hInst, (LPVOID)hwndMsg.lParam);
+ num_popups++;
+ if(hwndMsg.wParam) // set notifyer handle
+ SendMessage(hwnd, PUM_SETNOTIFYH, hwndMsg.wParam, 0);
+ } else {
+ if (pd) {
+ mir_free(pd->pwzTitle);
+ mir_free(pd->pwzText);
+ mir_free(pd);
}
}
- break;
- case MUM_NMUPDATE:
- {
- HANDLE hNotify = (HANDLE)hwndMsg.wParam;
- BroadcastMessage(PUM_UPDATENOTIFY, (WPARAM)hNotify, 0);
- }
- break;
- case MUM_NMREMOVE:
- {
- HANDLE hNotify = (HANDLE)hwndMsg.wParam;
- BroadcastMessage(PUM_KILLNOTIFY, (WPARAM)hNotify, 0);
- }
- break;
- case MUM_NMAVATAR:
- RepositionWindows();
- break;
- default:
- {
- TranslateMessage(&hwndMsg);
- DispatchMessage(&hwndMsg);
- // do this here in case the window has gone
- if(hwndMsg.message == PUM_CHANGE || hwndMsg.message == PUM_SETTEXT)
- mir_free((void *)hwndMsg.lParam);
+ }
+ break;
+
+ case MUM_DELETEPOPUP:
+ {
+ HWND hwnd = (HWND)hwndMsg.lParam;
+ if(IsWindow(hwnd)) {
+ DestroyWindow(hwnd);
+ num_popups--;
}
- break;
+ }
+ break;
+
+ case MUM_NMUPDATE:
+ {
+ HANDLE hNotify = (HANDLE)hwndMsg.wParam;
+ BroadcastMessage(PUM_UPDATENOTIFY, (WPARAM)hNotify, 0);
+ }
+ break;
+
+ case MUM_NMREMOVE:
+ {
+ HANDLE hNotify = (HANDLE)hwndMsg.wParam;
+ BroadcastMessage(PUM_KILLNOTIFY, (WPARAM)hNotify, 0);
+ }
+ break;
+
+ case MUM_NMAVATAR:
+ RepositionWindows();
+ break;
+
+ default:
+ TranslateMessage(&hwndMsg);
+ DispatchMessage(&hwndMsg);
+ break;
}
}
}
@@ -149,7 +149,7 @@ unsigned __stdcall MessagePumpThread(void* param) { //if(param) SetEvent((HANDLE)param);
- DeinitOptions();
+ DeinitOptions();
DeinitServices();
return 0;
diff --git a/plugins/YAPP/popwin.cpp b/plugins/YAPP/popwin.cpp index 50e99cdd36..682a3f7b05 100644 --- a/plugins/YAPP/popwin.cpp +++ b/plugins/YAPP/popwin.cpp @@ -523,6 +523,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa //}
}
return 0;
+
case WM_DESTROY:
if(pwd->mouse_in) global_mouse_in--;
@@ -546,8 +547,8 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa }
mir_free(pwd); pwd = 0; pd = 0;
SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
-
break;
+
case PUM_UPDATERGN:
// round corners
if(pwd->is_round) {
@@ -566,32 +567,24 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa return TRUE;
case PUM_MOVE:
- {
- if(options.animate) {
- KillTimer(hwnd, ID_MOVETIMER);
- pwd->new_x = (int)wParam;
- pwd->new_y = (int)lParam;
- SetTimer(hwnd, ID_MOVETIMER, 10, 0);
- } else {
- SetWindowPos(hwnd, 0, (int)wParam, (int)lParam, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
- if (!IsWindowVisible(hwnd)) {
- ShowWindow(hwnd, SW_SHOWNOACTIVATE);
- UpdateWindow(hwnd);
- }
+ if(options.animate) {
+ KillTimer(hwnd, ID_MOVETIMER);
+ pwd->new_x = (int)wParam;
+ pwd->new_y = (int)lParam;
+ SetTimer(hwnd, ID_MOVETIMER, 10, 0);
+ } else {
+ SetWindowPos(hwnd, 0, (int)wParam, (int)lParam, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
+ if (!IsWindowVisible(hwnd)) {
+ ShowWindow(hwnd, SW_SHOWNOACTIVATE);
+ UpdateWindow(hwnd);
}
}
return TRUE;
+
case PUM_SETTEXT:
- {
- mir_free(pd->pszText);
- if(lParam)
- pd->pwzText = mir_wstrdup((wchar_t *)lParam);
- else
- pd->pwzText = NULL;
- // mir_free((void *)lParam); // freed in message pump in case the window has gone
- InvalidateRect(hwnd, 0, TRUE);
- RepositionWindows();
- }
+ replaceStrT(pd->ptzText, (TCHAR*)lParam);
+ InvalidateRect(hwnd, 0, TRUE);
+ RepositionWindows();
return TRUE;
case PUM_GETCONTACT:
diff --git a/plugins/YAPP/popwin.h b/plugins/YAPP/popwin.h index 63038c470b..4d826ceade 100644 --- a/plugins/YAPP/popwin.h +++ b/plugins/YAPP/popwin.h @@ -1,19 +1,19 @@ #ifndef _POPWIN_INC
#define _POPWIN_INC
-#define POP_WIN_CLASS _T(MODULE) _T("YAPPWindowClass")
-
-#define PUM_SETTEXT (WM_USER + 0x020)
-#define PUM_GETCONTACT (WM_USER + 0x021)
-#define PUM_GETOPAQUE (WM_USER + 0x022)
-#define PUM_CHANGE (WM_USER + 0x023)
-#define PUM_MOVE (WM_USER + 0x024)
-#define PUM_GETHEIGHT (WM_USER + 0x025)
-#define PUM_UPDATERGN (WM_USER + 0x026)
-
-#define PUM_SETNOTIFYH (WM_USER + 0x030)
-#define PUM_KILLNOTIFY (WM_USER + 0x031)
-#define PUM_UPDATENOTIFY (WM_USER + 0x032)
+#define POP_WIN_CLASS _T(MODULE) _T("YAPPWindowClass")
+
+#define PUM_SETTEXT (WM_USER + 0x020)
+#define PUM_GETCONTACT (WM_USER + 0x021)
+#define PUM_GETOPAQUE (WM_USER + 0x022)
+#define PUM_CHANGE (WM_USER + 0x023)
+#define PUM_MOVE (WM_USER + 0x024)
+#define PUM_GETHEIGHT (WM_USER + 0x025)
+#define PUM_UPDATERGN (WM_USER + 0x026)
+
+#define PUM_SETNOTIFYH (WM_USER + 0x030)
+#define PUM_KILLNOTIFY (WM_USER + 0x031)
+#define PUM_UPDATENOTIFY (WM_USER + 0x032)
void InitWindowStack();
void DeinitWindowStack();
diff --git a/plugins/YAPP/services.cpp b/plugins/YAPP/services.cpp index ea60b013b4..84e4330151 100644 --- a/plugins/YAPP/services.cpp +++ b/plugins/YAPP/services.cpp @@ -155,13 +155,14 @@ INT_PTR OldCreatePopupW(WPARAM wParam, LPARAM lParam) { return 0;
}
-INT_PTR ChangeTextW(WPARAM wParam, LPARAM lParam) {
+INT_PTR ChangeTextW(WPARAM wParam, LPARAM lParam)
+{
HWND hwndPop = (HWND)wParam;
- wchar_t *newText = mir_wstrdup((wchar_t *)lParam);
+ wchar_t *newText = NEWWSTR_ALLOCA((wchar_t *)lParam);
StripBBCodesInPlace(newText);
if(IsWindow(hwndPop))
- PostMessage(hwndPop, PUM_SETTEXT, 0, (LPARAM)newText);
+ SendMessage(hwndPop, PUM_SETTEXT, 0, (LPARAM)newText);
else
mir_free(newText);
return 0;
@@ -174,9 +175,9 @@ INT_PTR ChangeTextA(WPARAM wParam, LPARAM lParam) { StripBBCodesInPlace(buff);
if(IsWindow(hwndPop))
- PostMessage(hwndPop, PUM_SETTEXT, 0, (LPARAM)buff);
- else
- mir_free(buff);
+ SendMessage(hwndPop, PUM_SETTEXT, 0, (LPARAM)buff);
+
+ mir_free(buff);
return 0;
}
@@ -286,32 +287,32 @@ INT_PTR PopupChangeA(WPARAM wParam, LPARAM lParam) { POPUPDATAEX *pd_in = (POPUPDATAEX *)lParam;
if(IsWindow(hwndPop)) {
- PopupData *pd_out = (PopupData *)mir_alloc(sizeof(PopupData));
- pd_out->cbSize = sizeof(PopupData);
- pd_out->flags = PDF_UNICODE;
+ PopupData pd_out;
+ pd_out.cbSize = sizeof(PopupData);
+ pd_out.flags = PDF_UNICODE;
- pd_out->pwzTitle = mir_a2u(pd_in->lpzContactName);
- pd_out->pwzText = mir_a2u(pd_in->lpzText);
- StripBBCodesInPlace(pd_out->pwzTitle);
- StripBBCodesInPlace(pd_out->pwzText);
+ pd_out.pwzTitle = mir_a2u(pd_in->lpzContactName);
+ pd_out.pwzText = mir_a2u(pd_in->lpzText);
+ StripBBCodesInPlace(pd_out.pwzTitle);
+ StripBBCodesInPlace(pd_out.pwzText);
- pd_out->hContact = pd_in->lchContact;
- pd_out->hIcon = pd_in->lchIcon;
+ pd_out.hContact = pd_in->lchContact;
+ pd_out.hIcon = pd_in->lchIcon;
if(pd_in->colorBack == 0xffffffff) // that's the old #define for 'skinned bg'
- pd_out->colorBack = pd_out->colorText = 0;
+ pd_out.colorBack = pd_out.colorText = 0;
else {
- pd_out->colorBack = pd_in->colorBack & 0xFFFFFF;
- pd_out->colorText = pd_in->colorText & 0xFFFFFF;
+ pd_out.colorBack = pd_in->colorBack & 0xFFFFFF;
+ pd_out.colorText = pd_in->colorText & 0xFFFFFF;
}
- pd_out->colorBack = pd_in->colorBack;
- pd_out->colorText = pd_in->colorText;
- pd_out->windowProc = pd_in->PluginWindowProc;
- pd_out->opaque = pd_in->PluginData;
- pd_out->timeout = pd_in->iSeconds;
+ pd_out.colorBack = pd_in->colorBack;
+ pd_out.colorText = pd_in->colorText;
+ pd_out.windowProc = pd_in->PluginWindowProc;
+ pd_out.opaque = pd_in->PluginData;
+ pd_out.timeout = pd_in->iSeconds;
- lstPopupHistory.Add(pd_out->pwzTitle, pd_out->pwzText, time(0));
-
- PostMessage(hwndPop, PUM_CHANGE, 0, (LPARAM)pd_out);
+ lstPopupHistory.Add(pd_out.pwzTitle, pd_out.pwzText, time(0));
+
+ SendMessage(hwndPop, PUM_CHANGE, 0, (LPARAM)&pd_out);
}
return 0;
}
@@ -321,32 +322,32 @@ INT_PTR PopupChangeW(WPARAM wParam, LPARAM lParam) { POPUPDATAW *pd_in = (POPUPDATAW *)lParam;
if(IsWindow(hwndPop)) {
- PopupData *pd_out = (PopupData *)mir_alloc(sizeof(PopupData));
- pd_out->cbSize = sizeof(PopupData);
- pd_out->flags = PDF_UNICODE;
+ PopupData pd_out;
+ pd_out.cbSize = sizeof(PopupData);
+ pd_out.flags = PDF_UNICODE;
- pd_out->pwzTitle = mir_wstrdup(pd_in->lpwzContactName);
- pd_out->pwzText = mir_wstrdup(pd_in->lpwzText);
- StripBBCodesInPlace(pd_out->pwzTitle);
- StripBBCodesInPlace(pd_out->pwzText);
+ pd_out.pwzTitle = mir_wstrdup(pd_in->lpwzContactName);
+ pd_out.pwzText = mir_wstrdup(pd_in->lpwzText);
+ StripBBCodesInPlace(pd_out.pwzTitle);
+ StripBBCodesInPlace(pd_out.pwzText);
- pd_out->hContact = pd_in->lchContact;
- pd_out->hIcon = pd_in->lchIcon;
+ pd_out.hContact = pd_in->lchContact;
+ pd_out.hIcon = pd_in->lchIcon;
if(pd_in->colorBack == 0xffffffff) // that's the old #define for 'skinned bg'
- pd_out->colorBack = pd_out->colorText = 0;
+ pd_out.colorBack = pd_out.colorText = 0;
else {
- pd_out->colorBack = pd_in->colorBack & 0xFFFFFF;
- pd_out->colorText = pd_in->colorText & 0xFFFFFF;
+ pd_out.colorBack = pd_in->colorBack & 0xFFFFFF;
+ pd_out.colorText = pd_in->colorText & 0xFFFFFF;
}
- pd_out->colorBack = pd_in->colorBack;
- pd_out->colorText = pd_in->colorText;
- pd_out->windowProc = pd_in->PluginWindowProc;
- pd_out->opaque = pd_in->PluginData;
- pd_out->timeout = pd_in->iSeconds;
+ pd_out.colorBack = pd_in->colorBack;
+ pd_out.colorText = pd_in->colorText;
+ pd_out.windowProc = pd_in->PluginWindowProc;
+ pd_out.opaque = pd_in->PluginData;
+ pd_out.timeout = pd_in->iSeconds;
- lstPopupHistory.Add(pd_out->pwzTitle, pd_out->pwzText, time(0));
+ lstPopupHistory.Add(pd_out.pwzTitle, pd_out.pwzText, time(0));
- PostMessage(hwndPop, PUM_CHANGE, 0, (LPARAM)pd_out);
+ SendMessage(hwndPop, PUM_CHANGE, 0, (LPARAM)&pd_out);
}
return 0;
}
|