diff options
author | George Hazan <george.hazan@gmail.com> | 2013-03-21 15:37:17 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-03-21 15:37:17 +0000 |
commit | 85bc1059e1d3e415c467821eb5f18af8fc0a9468 (patch) | |
tree | f4677690848b34a64818e097043f9a550c7801d1 /protocols | |
parent | 8e88506457722bc5d834fcdd623cc73aa64c1982 (diff) |
fixed crash in GTalkExt popups
git-svn-id: http://svn.miranda-ng.org/main/trunk@4147 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/GTalkExt/src/GTalkExt.cpp | 74 | ||||
-rw-r--r-- | protocols/GTalkExt/src/avatar.cpp | 8 | ||||
-rw-r--r-- | protocols/GTalkExt/src/dllmain.cpp | 4 | ||||
-rw-r--r-- | protocols/GTalkExt/src/notifications.cpp | 159 | ||||
-rw-r--r-- | protocols/GTalkExt/src/notifications.h | 4 | ||||
-rw-r--r-- | protocols/GTalkExt/src/options.cpp | 6 | ||||
-rw-r--r-- | protocols/GTalkExt/src/stdafx.h | 2 |
7 files changed, 121 insertions, 136 deletions
diff --git a/protocols/GTalkExt/src/GTalkExt.cpp b/protocols/GTalkExt/src/GTalkExt.cpp index 463f1985b8..a449435cb3 100644 --- a/protocols/GTalkExt/src/GTalkExt.cpp +++ b/protocols/GTalkExt/src/GTalkExt.cpp @@ -23,16 +23,17 @@ #include "stdafx.h"
#include "options.h"
+#include "notifications.h"
#include "handlers.h"
#include "tipper_items.h"
#include "avatar.h"
#include "menu.h"
+int hLangpack;
+HICON g_hPopupIcon = 0;
-int hLangpack;
-
-
-PLUGININFOEX pluginInfo={
+PLUGININFOEX pluginInfo =
+{
sizeof(PLUGININFOEX),
PLUGIN_DESCRIPTION,
PLUGIN_VERSION_DWORD,
@@ -50,38 +51,57 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD miranda return &pluginInfo;
}
-HANDLE hModulesLoaded = 0;
-HANDLE hAccListChanged = 0;
+/////////////////////////////////////////////////////////////////////////////////////////
-extern "C" int __declspec(dllexport) Unload(void)
+LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- UnhookOptionsInitialization();
- InitMenus(FALSE);
- InitAvaUnit(FALSE);
- if (hAccListChanged) UnhookEvent(hAccListChanged);
- if (hModulesLoaded) UnhookEvent(hModulesLoaded);
- return 0;
-}
+ switch (msg) {
+ case WM_NCCREATE:
+ return 1;
-HICON g_hPopupIcon = 0;
-extern HINSTANCE hInst;
+ case WM_GETMINMAXINFO:
+ PMINMAXINFO info = (PMINMAXINFO)lParam;
+ info->ptMaxPosition.x = -100;
+ info->ptMaxPosition.y = -100;
+ info->ptMaxSize.x = 10;
+ info->ptMaxSize.y = 10;
+ info->ptMaxTrackSize.x = 10;
+ info->ptMaxTrackSize.y = 10;
+ info->ptMinTrackSize.x = 10;
+ info->ptMinTrackSize.y = 10;
+ return 0;
+ }
+ return DefWindowProc(wnd, msg, wParam, lParam);
+}
extern "C" int __declspec(dllexport) Load(void)
{
- g_hPopupIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_POPUP));
+ mir_getLP(&pluginInfo);
+ mir_getXI(&xi);
+
+ WNDCLASS cls = {0};
+ cls.lpfnWndProc = WndProc;
+ cls.lpszClassName = TEMP_WINDOW_CLASS_NAME;
+ RegisterClass(&cls);
+ g_hPopupIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_POPUP));
- mir_getLP(&pluginInfo);
- if (
- !mir_getXI(&xi) ||
- !(hModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded)) ||
- !(hAccListChanged = HookEvent(ME_PROTO_ACCLISTCHANGED, AccListChanged)) ||
- !InitAvaUnit(TRUE) ||
- !InitMenus(TRUE)
- )
- {Unload(); return 1;};
+ InitAvaUnit(TRUE);
+ InitMenus(TRUE);
+
+ HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);
+ HookEvent(ME_PROTO_ACCLISTCHANGED, AccListChanged);
AddTipperItem();
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+extern "C" int __declspec(dllexport) Unload(void)
+{
+ UnhookOptionsInitialization();
+ InitMenus(FALSE);
+ InitAvaUnit(FALSE);
return 0;
-}
\ No newline at end of file +}
diff --git a/protocols/GTalkExt/src/avatar.cpp b/protocols/GTalkExt/src/avatar.cpp index c78073ec0a..42bf059dae 100644 --- a/protocols/GTalkExt/src/avatar.cpp +++ b/protocols/GTalkExt/src/avatar.cpp @@ -96,20 +96,20 @@ LPSTR CreateAvaFile(HANDLE *hFile) }
}
-extern HINSTANCE hInst;
+extern HINSTANCE g_hInst;
BOOL SaveAvatar(HANDLE hFile)
{
- HRSRC hres = FindResource(hInst, MAKEINTRESOURCE(IDI_PSEUDOAVA), AVA_RES_TYPE);
+ HRSRC hres = FindResource(g_hInst, MAKEINTRESOURCE(IDI_PSEUDOAVA), AVA_RES_TYPE);
if (!hres) return FALSE;
- HGLOBAL hglob = LoadResource(hInst, hres);
+ HGLOBAL hglob = LoadResource(g_hInst, hres);
if (!hglob) return FALSE;
PVOID p = LockResource(hglob);
if (!p) return FALSE;
- DWORD l = SizeofResource(hInst, hres);
+ DWORD l = SizeofResource(g_hInst, hres);
if (!l) return FALSE;
DWORD written;
diff --git a/protocols/GTalkExt/src/dllmain.cpp b/protocols/GTalkExt/src/dllmain.cpp index bcc54371fb..a59974f883 100644 --- a/protocols/GTalkExt/src/dllmain.cpp +++ b/protocols/GTalkExt/src/dllmain.cpp @@ -23,7 +23,7 @@ #include "notifications.h"
#include "options.h"
-HINSTANCE hInst = 0;
+HINSTANCE g_hInst = 0;
DWORD itlsSettings = TLS_OUT_OF_INDEXES;
DWORD itlsRecursion = TLS_OUT_OF_INDEXES;
@@ -32,7 +32,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID) {
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
- hInst = hinstDLL;
+ g_hInst = hinstDLL;
if (((itlsSettings = TlsAlloc()) == TLS_OUT_OF_INDEXES) ||
((itlsRecursion = TlsAlloc()) == TLS_OUT_OF_INDEXES))
return FALSE;
diff --git a/protocols/GTalkExt/src/notifications.cpp b/protocols/GTalkExt/src/notifications.cpp index d20dd09360..ba9b9b14de 100644 --- a/protocols/GTalkExt/src/notifications.cpp +++ b/protocols/GTalkExt/src/notifications.cpp @@ -26,21 +26,21 @@ #include "avatar.h"
#include "inbox.h"
-static const LPTSTR TEMP_WINDOW_CLASS_NAME = _T("AntiShittyFullscreenDetectionWindowClass");
-static const LPTSTR _T(NUMBER_EMAILS_MESSAGE) = LPGENT("You've received an e-mail\n%s unread threads");
+const LPTSTR _T(NUMBER_EMAILS_MESSAGE) = LPGENT("You've received an e-mail\n%s unread threads");
-static const LPTSTR PLUGIN_DATA_PROP_NAME = _T("{DB5CE833-C3AC-4851-831C-DDEBD9FA0508}");
-static const LPTSTR EVT_DELETED_HOOK_PROP_NAME = _T("{87CBD2BC-8806-413C-8FD5-1D61ABCA4AF8}");
+const LPTSTR PLUGIN_DATA_PROP_NAME = _T("{DB5CE833-C3AC-4851-831C-DDEBD9FA0508}");
+const LPTSTR EVT_DELETED_HOOK_PROP_NAME = _T("{87CBD2BC-8806-413C-8FD5-1D61ABCA4AF8}");
#define EVENT_DELETED_MSG RegisterWindowMessage(_T("{B9B00536-86A0-4BCE-B2FE-4ABD409C22AE}"))
#define MESSAGE_CLOSEPOPUP RegisterWindowMessage(_T("{7A60EA87-3E77-41DF-8A69-59B147F0C9C6}"))
-static const LPSTR CLIST_MODULE_NAME = "CList";
-static const LPSTR CONTACT_DISPLAY_NAME_SETTING = "MyHandle";
-static const LPSTR STATUS_MSG_SETTING = "StatusMsg";
-static const LPSTR UNREAD_THREADS_SETTING = "UnreadThreads";
+const LPSTR CLIST_MODULE_NAME = "CList";
+const LPSTR CONTACT_DISPLAY_NAME_SETTING = "MyHandle";
+const LPSTR STATUS_MSG_SETTING = "StatusMsg";
+const LPSTR UNREAD_THREADS_SETTING = "UnreadThreads";
-struct POPUP_DATA_HEADER {
+struct POPUP_DATA_HEADER
+{
BOOL MarkRead;
HANDLE hDbEvent;
HANDLE hContact;
@@ -50,27 +50,6 @@ struct POPUP_DATA_HEADER { extern DWORD itlsSettings;
-LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg) {
- case WM_NCCREATE:
- return 1;
-
- case WM_GETMINMAXINFO:
- PMINMAXINFO info = (PMINMAXINFO)lParam;
- info->ptMaxPosition.x = -100;
- info->ptMaxPosition.y = -100;
- info->ptMaxSize.x = 10;
- info->ptMaxSize.y = 10;
- info->ptMaxTrackSize.x = 10;
- info->ptMaxTrackSize.y = 10;
- info->ptMinTrackSize.x = 10;
- info->ptMinTrackSize.y = 10;
- return 0;
- }
- return DefWindowProc(wnd, msg, wParam, lParam);
-}
-
LPCSTR GetJidAcc(LPCTSTR jid)
{
int count = 0;
@@ -78,7 +57,7 @@ LPCSTR GetJidAcc(LPCTSTR jid) ProtoEnumAccounts(&count, &protos);
DBVARIANT dbv;
- for (int i = 0; i < count; i++)
+ for (int i=0; i < count; i++)
if (getJabberApi(protos[i]->szModuleName))
if (!DBGetContactSettingTString(0, protos[i]->szModuleName, "jid", &dbv))
__try {
@@ -99,7 +78,6 @@ void MarkEventRead(HANDLE hCnt, HANDLE hEvt) ReadCheckbox(0, IDC_MARKEVENTREAD, settings) &&
(CallService(MS_DB_EVENT_MARKREAD, (WPARAM)hCnt, (LPARAM)hEvt) != (INT_PTR)-1))
CallService(MS_CLIST_REMOVEEVENT, (WPARAM)hCnt, (LPARAM)hEvt);
-
}
int OnEventDeleted(WPARAM hContact, LPARAM hDbEvent, LPARAM wnd)
@@ -114,84 +92,74 @@ int OnEventDeleted(WPARAM hContact, LPARAM hDbEvent, LPARAM wnd) LRESULT CALLBACK PopupProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
+ POPUP_DATA_HEADER *ppdh = (POPUP_DATA_HEADER*)PUGetPluginData(wnd);
+ LPCSTR acc;
+
if (EVENT_DELETED_MSG == msg) {
- POPUP_DATA_HEADER *ppdh = (POPUP_DATA_HEADER*)PUGetPluginData(wnd);
if ((HANDLE)lParam == ppdh->hDbEvent)
ppdh->hDbEvent = NULL;
return 0;
}
if (MESSAGE_CLOSEPOPUP == msg) {
- POPUP_DATA_HEADER *ppdh = (POPUP_DATA_HEADER*)PUGetPluginData(wnd);
ppdh->MarkRead = TRUE;
PUDeletePopUp(wnd);
}
switch (msg) {
- case UM_INITPOPUP: {
- POPUP_DATA_HEADER *ppdh = (POPUP_DATA_HEADER*)PUGetPluginData(wnd);
- SetProp(wnd, PLUGIN_DATA_PROP_NAME, (HANDLE)ppdh);
- SetProp(wnd, EVT_DELETED_HOOK_PROP_NAME,
- HookEventParam(ME_DB_EVENT_DELETED, OnEventDeleted, (LPARAM)wnd));
- return 0;
- }
+ case UM_INITPOPUP:
+ SetProp(wnd, PLUGIN_DATA_PROP_NAME, (HANDLE)ppdh);
+ SetProp(wnd, EVT_DELETED_HOOK_PROP_NAME,
+ HookEventParam(ME_DB_EVENT_DELETED, OnEventDeleted, (LPARAM)wnd));
+ return 0;
- case UM_FREEPLUGINDATA: {
+ case UM_FREEPLUGINDATA:
+ {
HANDLE hHook = GetProp(wnd, EVT_DELETED_HOOK_PROP_NAME);
RemoveProp(wnd, EVT_DELETED_HOOK_PROP_NAME);
UnhookEvent(hHook);
+ }
- LPCSTR acc = NULL;
- POPUP_DATA_HEADER *ppdh = (POPUP_DATA_HEADER*)PUGetPluginData(wnd);
- __try {
- if (ppdh->MarkRead && ppdh->hDbEvent && (acc = GetJidAcc(ppdh->jid))) {
- ReadNotificationSettings(acc);
- MarkEventRead(ppdh->hContact, ppdh->hDbEvent);
- CallService(MS_CLIST_REMOVEEVENT, (WPARAM)ppdh->hContact, (LPARAM)ppdh->hDbEvent);
- }
-
- }
- __finally {
- RemoveProp(wnd, PLUGIN_DATA_PROP_NAME);
- free(ppdh);
+ __try {
+ if (ppdh->MarkRead && ppdh->hDbEvent && (acc = GetJidAcc(ppdh->jid))) {
+ ReadNotificationSettings(acc);
+ MarkEventRead(ppdh->hContact, ppdh->hDbEvent);
+ CallService(MS_CLIST_REMOVEEVENT, (WPARAM)ppdh->hContact, (LPARAM)ppdh->hDbEvent);
}
-
- return 0;
+ }
+ __finally {
+ RemoveProp(wnd, PLUGIN_DATA_PROP_NAME);
+ free(ppdh);
}
- case WM_LBUTTONUP: {
- LPCSTR acc = NULL;
- POPUP_DATA_HEADER *ppdh = (POPUP_DATA_HEADER*)PUGetPluginData(wnd);
- __try {
- if (!(acc = GetJidAcc(ppdh->jid))) return 0;
+ return 0;
- ReadNotificationSettings(acc);
- OpenUrl(acc, ppdh->jid, ppdh->url);
- }
- __finally {
- CloseNotifications(acc, ppdh->url, ppdh->jid, TRUE);
- }
- return 0;
+ case WM_LBUTTONUP:
+ acc = NULL;
+ __try {
+ if (!(acc = GetJidAcc(ppdh->jid))) return 0;
+
+ ReadNotificationSettings(acc);
+ OpenUrl(acc, ppdh->jid, ppdh->url);
}
+ __finally {
+ CloseNotifications(acc, ppdh->url, ppdh->jid, TRUE);
+ }
+ return 0;
- case WM_RBUTTONUP:
- SendMessage(wnd, MESSAGE_CLOSEPOPUP, 0, 0);
- return 0;
+ case WM_RBUTTONUP:
+ SendMessage(wnd, MESSAGE_CLOSEPOPUP, 0, 0);
+ return 0;
}
return DefWindowProc(wnd, msg, wParam, lParam);
}
-HWND DoAddPopup(POPUPDATAT *data)
+static bool DoAddPopup(POPUPDATAT *data)
{
- WNDCLASS cls = {0};
- cls.lpfnWndProc = WndProc;
- cls.lpszClassName = TEMP_WINDOW_CLASS_NAME;
-
- HWND result = 0;
+ bool result = false;
HWND handle = 0;
__try {
if (ReadCheckbox(0, IDC_POPUPSINFULLSCREEN, (DWORD)TlsGetValue(itlsSettings))) {
- RegisterClass(&cls);
handle = CreateWindowEx(WS_EX_TOOLWINDOW, TEMP_WINDOW_CLASS_NAME, NULL, WS_OVERLAPPED | WS_VISIBLE,
-100, -100, 10, 10, NULL, NULL, NULL, NULL);
if (handle) {
@@ -199,7 +167,7 @@ HWND DoAddPopup(POPUPDATAT *data) ShowWindow(handle, SW_RESTORE);
}
}
- result = (HWND)CallService(MS_POPUP_ADDPOPUPT, (WPARAM) data, APF_RETURN_HWND);
+ result = PUAddPopUpT(data) == 0;
}
__finally {
if (handle) DestroyWindow(handle);
@@ -304,28 +272,21 @@ void ShowNotification(LPCSTR acc, POPUPDATAT *data, LPCTSTR jid, LPCTSTR url, LP data->PluginWindowProc = PopupProc;
int lurl = (lstrlen(url) + 1) * sizeof(TCHAR);
int ljid = (lstrlen(jid) + 1) * sizeof(TCHAR);
- data->PluginData = malloc(sizeof(POPUP_DATA_HEADER) + lurl + ljid);
- __try {
- POPUP_DATA_HEADER *ppdh = (POPUP_DATA_HEADER*)data->PluginData;
-
- ppdh->MarkRead = FALSE;
- ppdh->hContact = hCnt;
- ppdh->hDbEvent = hEvt;
+
+ POPUP_DATA_HEADER *ppdh = (POPUP_DATA_HEADER*)malloc(sizeof(POPUP_DATA_HEADER) + lurl + ljid);
+ ppdh->MarkRead = FALSE;
+ ppdh->hContact = hCnt;
+ ppdh->hDbEvent = hEvt;
- ppdh->jid = (LPTSTR)((PBYTE)ppdh + sizeof(*ppdh));
- memcpy(ppdh->jid, jid, ljid);
+ ppdh->jid = (LPTSTR)((PBYTE)ppdh + sizeof(*ppdh));
+ memcpy(ppdh->jid, jid, ljid);
- ppdh->url = (LPTSTR)((PBYTE)ppdh->jid + ljid);
- memcpy(ppdh->url, url, lurl);
+ ppdh->url = (LPTSTR)((PBYTE)ppdh->jid + ljid);
+ memcpy(ppdh->url, url, lurl);
+ data->PluginData = ppdh;
- HWND code = DoAddPopup(data);
- if (code == (HWND)-1 || !code)
- return;
- data->PluginData = NULL; // freed in popup wndproc
- }
- __finally {
+ if ( !DoAddPopup(data))
free(data->PluginData);
- }
}
void UnreadMailNotification(LPCSTR acc, LPCTSTR jid, LPCTSTR url, LPCTSTR unreadCount)
@@ -411,4 +372,4 @@ void CloseNotifications(LPCSTR acc, LPCTSTR url, LPCTSTR jid, BOOL PopupsOnly) POPUP_IDENT_STRINGS pis = {url, jid};
EnumWindows(ClosePopupFunc, (LPARAM)&pis);
-}
\ No newline at end of file +}
diff --git a/protocols/GTalkExt/src/notifications.h b/protocols/GTalkExt/src/notifications.h index 94d6e6353f..02780ae2b0 100644 --- a/protocols/GTalkExt/src/notifications.h +++ b/protocols/GTalkExt/src/notifications.h @@ -21,7 +21,9 @@ #pragma once
-static const int SENDER_COUNT = 10;
+const LPTSTR TEMP_WINDOW_CLASS_NAME = _T("AntiShittyFullscreenDetectionWindowClass");
+
+const int SENDER_COUNT = 10;
struct SENDER {
LPCTSTR name;
diff --git a/protocols/GTalkExt/src/options.cpp b/protocols/GTalkExt/src/options.cpp index 6febd4892a..810dead8ec 100644 --- a/protocols/GTalkExt/src/options.cpp +++ b/protocols/GTalkExt/src/options.cpp @@ -41,7 +41,7 @@ static const LPTSTR TEST_LETTER_SNIP = LPGENT("* No exceptions");
HANDLE hOptionsHook = 0;
-extern HINSTANCE hInst;
+extern HINSTANCE g_hInst;
void CheckControlsEnabled(HWND wnd)
{
@@ -244,7 +244,7 @@ void AddPopupsPage(WPARAM wParam) odp.ptszTitle = MAIL_NOTIFICATIONS;
odp.pfnDlgProc = PopupsOptionsDlgProc;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_POPUPSETTINGS);
- odp.hInstance = hInst;
+ odp.hInstance = g_hInst;
odp.ptszGroup = POPUPS_OPTIONS_GROUP;
odp.flags = ODPF_UNICODE | ODPF_USERINFOTAB;
@@ -258,7 +258,7 @@ void AddAccPage(LPTSTR acc, LPCSTR mod, WPARAM wParam) odp.ptszTitle = acc;
odp.pfnDlgProc = AccOptionsDlgProc;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_MAILSETTINGS);
- odp.hInstance = hInst;
+ odp.hInstance = g_hInst;
odp.ptszGroup = NETWORK_OPTIONS_GROUP;
odp.flags = ODPF_UNICODE | ODPF_USERINFOTAB | ODPF_DONTTRANSLATE;
odp.ptszTab = MAIL_NOTIFICATIONS;
diff --git a/protocols/GTalkExt/src/stdafx.h b/protocols/GTalkExt/src/stdafx.h index ded641295b..7e272e900f 100644 --- a/protocols/GTalkExt/src/stdafx.h +++ b/protocols/GTalkExt/src/stdafx.h @@ -67,3 +67,5 @@ #define _tstoi64 _ttoi
#define _tcstoui64(A,B,C) _ttoi(A)
#endif
+
+extern HINSTANCE g_hInst;
|