summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-07-13 15:37:55 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-07-13 15:37:55 +0300
commita70adea1ff04895cc68a09e8209504cf2ffe89b9 (patch)
tree694a7962512783b03dc2d745a38085df82d33b31 /src
parent0ad8eab5c34ae3fc474cf1f1ef1fa78ccec63910 (diff)
no need to hook ME_SYSTEM_PRESHUTDOWN in each window separately
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/file.cpp16
-rw-r--r--src/mir_app/src/file.h5
-rw-r--r--src/mir_app/src/fileexistsdlg.cpp9
-rw-r--r--src/mir_app/src/fileopts.cpp2
-rw-r--r--src/mir_app/src/filerecvdlg.cpp4
-rw-r--r--src/mir_app/src/filesenddlg.cpp3
-rw-r--r--src/mir_app/src/filexferdlg.cpp1
-rw-r--r--src/mir_app/src/ftmanager.cpp18
8 files changed, 32 insertions, 26 deletions
diff --git a/src/mir_app/src/file.cpp b/src/mir_app/src/file.cpp
index 74e842b9a7..1aa3851a32 100644
--- a/src/mir_app/src/file.cpp
+++ b/src/mir_app/src/file.cpp
@@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
#include "file.h"
+MWindowList g_hFileWindows;
HANDLE hDlgSucceeded, hDlgCanceled;
wchar_t* PFTS_StringToTchar(int flags, const wchar_t* s);
@@ -293,6 +294,16 @@ static int SRFileModulesLoaded(WPARAM, LPARAM)
return 0;
}
+static int SRFilePreShutdown(WPARAM, LPARAM)
+{
+ if (g_hFileWindows) {
+ WindowList_Broadcast(g_hFileWindows, WM_CLOSE, 0, 1);
+ WindowList_Destroy(g_hFileWindows);
+ g_hFileWindows = 0;
+ }
+ return 0;
+}
+
INT_PTR FtMgrShowCommand(WPARAM, LPARAM)
{
FtMgr_Show(true, true);
@@ -397,6 +408,8 @@ MEVENT Proto_RecvFile(MCONTACT hContact, PROTORECVFILE *pre)
int LoadSendRecvFileModule(void)
{
+ g_hFileWindows = WindowList_Create();
+
CreateServiceFunction("FtMgr/Show", FtMgrShowCommand);
CMenuItem mi(&g_plugin);
@@ -408,7 +421,8 @@ int LoadSendRecvFileModule(void)
Menu_AddMainMenuItem(&mi);
HookEvent(ME_SYSTEM_MODULESLOADED, SRFileModulesLoaded);
- HookEvent(ME_OPT_INITIALISE, FileOptInitialise);
+ HookEvent(ME_SYSTEM_PRESHUTDOWN, SRFilePreShutdown);
+ HookEvent(ME_OPT_INITIALISE, SRFileOptInitialise);
HookEvent(ME_CLIST_PREBUILDCONTACTMENU, SRFilePreBuildMenu);
HookEvent(ME_PROTO_ACK, SRFileProtoAck);
diff --git a/src/mir_app/src/file.h b/src/mir_app/src/file.h
index c9b882f9bf..a57f2e9f18 100644
--- a/src/mir_app/src/file.h
+++ b/src/mir_app/src/file.h
@@ -39,7 +39,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define FILERESUME_CANCEL 0xFFFFFFFF
#define M_FILEEXISTSDLGREPLY (WM_USER+200)
-#define M_PRESHUTDOWN (WM_USER+201)
struct FileSendData
{
@@ -68,7 +67,6 @@ struct FileDlgData : public MZeroedObject
int waitingForAcceptance;
PROTOFILETRANSFERSTATUS transferStatus;
int *fileVirusScanned;
- HANDLE hPreshutdownEvent;
uint32_t dwTicks;
wchar_t szSavePath[MAX_PATH];
@@ -115,7 +113,7 @@ INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
// fileopts.c
-int FileOptInitialise(WPARAM wParam, LPARAM lParam);
+int SRFileOptInitialise(WPARAM wParam, LPARAM lParam);
// ftmanager.c
#define WM_FT_ADD (WM_USER+701)
@@ -132,6 +130,7 @@ void FtMgr_Destroy();
void FtMgr_AddTransfer(FileDlgData *dat);
extern HANDLE hDlgSucceeded, hDlgCanceled;
+extern MWindowList g_hFileWindows;
namespace File
{
diff --git a/src/mir_app/src/fileexistsdlg.cpp b/src/mir_app/src/fileexistsdlg.cpp
index d75e2f6eae..0c290ffc3e 100644
--- a/src/mir_app/src/fileexistsdlg.cpp
+++ b/src/mir_app/src/fileexistsdlg.cpp
@@ -206,7 +206,7 @@ INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
struct _stati64 statbuf;
auto *dat = (TDlgProcFileExistsParam *)lParam;
- SetPropA(hwndDlg, "Miranda.Preshutdown", HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN));
+ WindowList_Add(g_hFileWindows, hwndDlg);
SetPropA(hwndDlg, "Miranda.ParentWnd", dat->hwndParent);
fts = (PROTOFILETRANSFERSTATUS *)mir_alloc(sizeof(PROTOFILETRANSFERSTATUS));
@@ -322,13 +322,8 @@ INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDCANCEL));
break;
- case M_PRESHUTDOWN:
- PostMessage(hwndDlg, WM_CLOSE, 0, 0);
- break;
-
case WM_DESTROY:
- UnhookEvent(GetPropA(hwndDlg, "Miranda.Preshutdown")); // GetProp() will return NULL if it couldnt find anything
- RemovePropA(hwndDlg, "Miranda.Preshutdown");
+ WindowList_Remove(g_hFileWindows, hwndDlg);
RemovePropA(hwndDlg, "Miranda.ParentWnd");
DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_EXISTINGICON, STM_GETICON, 0, 0));
DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_NEWICON, STM_GETICON, 0, 0));
diff --git a/src/mir_app/src/fileopts.cpp b/src/mir_app/src/fileopts.cpp
index d3a94c5b18..b511bd6c79 100644
--- a/src/mir_app/src/fileopts.cpp
+++ b/src/mir_app/src/fileopts.cpp
@@ -228,7 +228,7 @@ public:
}
};
-int FileOptInitialise(WPARAM wParam, LPARAM)
+int SRFileOptInitialise(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
odp.position = 900000000;
diff --git a/src/mir_app/src/filerecvdlg.cpp b/src/mir_app/src/filerecvdlg.cpp
index f1b32d9e1e..7dfa5c8a41 100644
--- a/src/mir_app/src/filerecvdlg.cpp
+++ b/src/mir_app/src/filerecvdlg.cpp
@@ -211,10 +211,9 @@ public:
bool OnInitDialog() override
{
char *szProto = Proto_GetBaseAccountName(dat->hContact);
+ WindowList_Add(g_hFileWindows, m_hwnd);
dat->hNotifyEvent = HookEventMessage(ME_PROTO_ACK, m_hwnd, HM_RECVEVENT);
- dat->hPreshutdownEvent = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, m_hwnd, M_PRESHUTDOWN);
-
SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)dat);
EnumChildWindows(m_hwnd, ClipSiblingsChildEnumProc, 0);
@@ -320,6 +319,7 @@ public:
void OnDestroy() override
{
+ WindowList_Remove(g_hFileWindows, m_hwnd);
Window_FreeIcon_IcoLib(m_hwnd);
delete dat; dat = nullptr;
diff --git a/src/mir_app/src/filesenddlg.cpp b/src/mir_app/src/filesenddlg.cpp
index 1c1a1af606..3f19d4d5f7 100644
--- a/src/mir_app/src/filesenddlg.cpp
+++ b/src/mir_app/src/filesenddlg.cpp
@@ -204,6 +204,7 @@ INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
+ WindowList_Add(g_hFileWindows, hwndDlg);
{
FileSendData *fsd = (FileSendData *)lParam;
@@ -211,7 +212,6 @@ INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
dat->hContact = fsd->hContact;
dat->send = 1;
- dat->hPreshutdownEvent = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN);
dat->fs = nullptr;
dat->dwTicks = GetTickCount();
@@ -321,6 +321,7 @@ INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
break;
case WM_DESTROY:
+ WindowList_Remove(g_hFileWindows, hwndDlg);
Window_FreeIcon_IcoLib(hwndDlg);
Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS);
Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY);
diff --git a/src/mir_app/src/filexferdlg.cpp b/src/mir_app/src/filexferdlg.cpp
index 3fe3249a22..1a366fa7b0 100644
--- a/src/mir_app/src/filexferdlg.cpp
+++ b/src/mir_app/src/filexferdlg.cpp
@@ -738,7 +738,6 @@ FileDlgData::~FileDlgData()
if (fs)
ProtoChainSend(hContact, PSS_FILECANCEL, (WPARAM)fs, 0);
- UnhookEvent(hPreshutdownEvent);
UnhookEvent(hNotifyEvent);
FreeProtoFileTransferStatus(&transferStatus);
diff --git a/src/mir_app/src/ftmanager.cpp b/src/mir_app/src/ftmanager.cpp
index 04221b7956..464ff3b17a 100644
--- a/src/mir_app/src/ftmanager.cpp
+++ b/src/mir_app/src/ftmanager.cpp
@@ -34,11 +34,11 @@ struct TFtMgrData
HWND hwndIncoming;
HWND hwndOutgoing;
- HANDLE hhkPreshutdown;
TBPFLAG errorState;
};
#define M_CALCPROGRESS (WM_USER + 200)
+#define M_PRESHUTDOWN (WM_USER + 201)
struct TFtProgressData
{
@@ -264,6 +264,7 @@ static INT_PTR CALLBACK FtMgrDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
switch (msg) {
case WM_INITDIALOG:
+ WindowList_Add(g_hFileWindows, hwnd);
{
TranslateDialogDefault(hwnd);
Window_SetSkinIcon_IcoLib(hwnd, SKINICON_EVENT_FILE);
@@ -272,8 +273,6 @@ static INT_PTR CALLBACK FtMgrDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat);
- dat->hhkPreshutdown = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwnd, M_PRESHUTDOWN);
-
dat->hwndIncoming = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_FTPAGE), hwnd, FtMgrPageDlgProc);
dat->hwndOutgoing = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_FTPAGE), hwnd, FtMgrPageDlgProc);
ShowWindow(dat->hwndIncoming, SW_SHOW);
@@ -390,13 +389,12 @@ static INT_PTR CALLBACK FtMgrDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
}
break;
- case M_PRESHUTDOWN:
- SendMessage(dat->hwndIncoming, M_PRESHUTDOWN, 0, 0);
- SendMessage(dat->hwndOutgoing, M_PRESHUTDOWN, 0, 0);
- DestroyWindow(hwnd);
- break;
-
case WM_CLOSE:
+ if (lParam) {
+ SendMessage(dat->hwndIncoming, M_PRESHUTDOWN, 0, 0);
+ SendMessage(dat->hwndOutgoing, M_PRESHUTDOWN, 0, 0);
+ }
+
ShowWindow(hwnd, SW_HIDE);
if (File::bAutoClear) {
PostMessage(dat->hwndIncoming, WM_FT_CLEANUP, 0, 0);
@@ -405,7 +403,7 @@ static INT_PTR CALLBACK FtMgrDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
return TRUE; /* Disable default IDCANCEL notification */
case WM_DESTROY:
- UnhookEvent(dat->hhkPreshutdown);
+ WindowList_Remove(g_hFileWindows, hwnd);
Window_FreeIcon_IcoLib(hwnd);
DestroyWindow(dat->hwndIncoming);
DestroyWindow(dat->hwndOutgoing);