[PATCH 0/2] MR11087: comdlg32: Add support for print setup dialog hooks.
From: Andrew Nguyen <arethusa26@gmail.com> --- dlls/comdlg32/tests/printdlg.c | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/dlls/comdlg32/tests/printdlg.c b/dlls/comdlg32/tests/printdlg.c index 347f7ddd7b1..c17d8153e7c 100644 --- a/dlls/comdlg32/tests/printdlg.c +++ b/dlls/comdlg32/tests/printdlg.c @@ -147,6 +147,29 @@ static UINT_PTR CALLBACK printer_properties_hook_procA(HWND hdlg, UINT msg, WPAR return 0; } +static UINT_PTR CALLBACK check_hook_proc_msg_handlingA(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) +{ + if (msg == WM_INITDIALOG) + { + PRINTDLGA* dlg = (PRINTDLGA*)lp; + BOOL* hook_inited = (BOOL*)dlg->lCustData; + + *hook_inited = TRUE; + + PostMessageA(hdlg, WM_COMMAND, IDCANCEL, 0); + } + else if (msg == WM_COMMAND && wp == IDCANCEL) + { + PostMessageA(hdlg, WM_COMMAND, IDOK, 0); + + /* Returning a non-zero value for IDCANCEL should prevent the message + * from being processed further. Otherwise, it would result in the + * dialog closing and PrintDlgA returning FALSE. */ + return TRUE; + } + return 0; +} + static void test_PrintDlgA(void) { DWORD res, n_copies = 0; @@ -158,6 +181,7 @@ static void test_PrintDlgA(void) CHAR buffer[MAX_PATH]; LPSTR ptr; DEVMODEA *dm; + BOOL hook_inited; pDlg = malloc((sizeof(PRINTDLGA)) * 2); if (!pDlg) return; @@ -311,6 +335,17 @@ static void test_PrintDlgA(void) GlobalUnlock(pDlg->hDevMode); GlobalFree(pDlg->hDevMode); + /* Validate some message handling behaviors of a print dialog hook. */ + ZeroMemory(pDlg, sizeof(*pDlg)); + hook_inited = FALSE; + pDlg->lStructSize = sizeof(*pDlg); + pDlg->Flags = PD_ENABLEPRINTHOOK; + pDlg->lpfnPrintHook = check_hook_proc_msg_handlingA; + pDlg->lCustData = (LPARAM)&hook_inited; + res = PrintDlgA(pDlg); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + free(pDlg); } @@ -336,11 +371,35 @@ static UINT_PTR CALLBACK printer_properties_hook_procW(HWND hdlg, UINT msg, WPAR return 0; } +static UINT_PTR CALLBACK check_hook_proc_msg_handlingW(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) +{ + if (msg == WM_INITDIALOG) + { + PRINTDLGW* dlg = (PRINTDLGW*)lp; + BOOL* hook_inited = (BOOL*)dlg->lCustData; + + *hook_inited = TRUE; + + PostMessageW(hdlg, WM_COMMAND, IDCANCEL, 0); + } + else if (msg == WM_COMMAND && wp == IDCANCEL) + { + PostMessageW(hdlg, WM_COMMAND, IDOK, 0); + + /* Returning a non-zero value for IDCANCEL should prevent the message + * from being processed further. Otherwise, it would result in the + * dialog closing and PrintDlgW returning FALSE. */ + return TRUE; + } + return 0; +} + void test_PrintDlgW(void) { PRINTDLGW pd = { 0 }; DEVMODEW* dm; DWORD name_size = 0; + BOOL res, hook_inited; GetDefaultPrinterW(NULL, &name_size); if(name_size == 0) @@ -367,6 +426,17 @@ void test_PrintDlgW(void) ok(dm->dmPaperSize == 888, "expected 888, but got %d.\n", dm->dmPaperSize); GlobalUnlock(pd.hDevMode); GlobalFree(pd.hDevMode); + + /* Validate some message handling behaviors of a print dialog hook. */ + ZeroMemory(&pd, sizeof(pd)); + hook_inited = FALSE; + pd.lStructSize = sizeof(pd); + pd.Flags = PD_ENABLEPRINTHOOK; + pd.lpfnPrintHook = check_hook_proc_msg_handlingW; + pd.lCustData = (LPARAM)&hook_inited; + res = PrintDlgW(&pd); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); } /* ########################### */ -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11087
From: Andrew Nguyen <arethusa26@gmail.com> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=23326 --- dlls/comdlg32/printdlg.c | 77 ++++++++++++++++++++++++++-------- dlls/comdlg32/tests/printdlg.c | 74 ++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 17 deletions(-) diff --git a/dlls/comdlg32/printdlg.c b/dlls/comdlg32/printdlg.c index 6fed7f124b0..b798e74de6d 100644 --- a/dlls/comdlg32/printdlg.c +++ b/dlls/comdlg32/printdlg.c @@ -2073,6 +2073,7 @@ static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { PRINT_PTRA* PrintStructures; + DWORD hook_flags; INT_PTR res = FALSE; if (uMsg!=WM_INITDIALOG) { @@ -2087,21 +2088,40 @@ static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, EndDialog(hDlg,FALSE); return FALSE; } - res = PRINTDLG_WMInitDialog(hDlg, PrintStructures); + res = PRINTDLG_WMInitDialog(hDlg, PrintStructures); + + hook_flags = PrintStructures->lpPrintDlg->Flags & + (PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK); + + if (hook_flags == PD_ENABLEPRINTHOOK) { + res = PrintStructures->lpPrintDlg->lpfnPrintHook( + hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg + ); + } else if (hook_flags == (PD_PRINTSETUP | PD_ENABLESETUPHOOK)) { + res = PrintStructures->lpPrintDlg->lpfnSetupHook( + hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg + ); + } - if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) - res = PrintStructures->lpPrintDlg->lpfnPrintHook( - hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg - ); - return res; + return res; } - if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) { - res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, - lParam); - if(res) return res; + hook_flags = PrintStructures->lpPrintDlg->Flags & + (PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK); + + if (hook_flags == PD_ENABLEPRINTHOOK) { + res = PrintStructures->lpPrintDlg->lpfnPrintHook( + hDlg, uMsg, wParam, lParam + ); + } else if (hook_flags == (PD_PRINTSETUP | PD_ENABLESETUPHOOK)) { + res = PrintStructures->lpPrintDlg->lpfnSetupHook( + hDlg, uMsg, wParam, lParam + ); } + if(res) + return res; + switch (uMsg) { case WM_COMMAND: return PRINTDLG_WMCommandA(hDlg, wParam, PrintStructures); @@ -2122,6 +2142,7 @@ static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { PRINT_PTRW* PrintStructures; + DWORD hook_flags; INT_PTR res = FALSE; if (uMsg!=WM_INITDIALOG) { @@ -2136,18 +2157,40 @@ static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, EndDialog(hDlg,FALSE); return FALSE; } - res = PRINTDLG_WMInitDialogW(hDlg, PrintStructures); + res = PRINTDLG_WMInitDialogW(hDlg, PrintStructures); + + hook_flags = PrintStructures->lpPrintDlg->Flags & + (PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK); + + if (hook_flags == PD_ENABLEPRINTHOOK) { + res = PrintStructures->lpPrintDlg->lpfnPrintHook( + hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg + ); + } else if (hook_flags == (PD_PRINTSETUP | PD_ENABLESETUPHOOK)) { + res = PrintStructures->lpPrintDlg->lpfnSetupHook( + hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg + ); + } - if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) - res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg); - return res; + return res; } - if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) { - res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam); - if(res) return res; + hook_flags = PrintStructures->lpPrintDlg->Flags & + (PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK); + + if (hook_flags == PD_ENABLEPRINTHOOK) { + res = PrintStructures->lpPrintDlg->lpfnPrintHook( + hDlg, uMsg, wParam, lParam + ); + } else if (hook_flags == (PD_PRINTSETUP | PD_ENABLESETUPHOOK)) { + res = PrintStructures->lpPrintDlg->lpfnSetupHook( + hDlg, uMsg, wParam, lParam + ); } + if(res) + return res; + switch (uMsg) { case WM_COMMAND: return PRINTDLG_WMCommandW(hDlg, wParam, PrintStructures); diff --git a/dlls/comdlg32/tests/printdlg.c b/dlls/comdlg32/tests/printdlg.c index c17d8153e7c..8412892b349 100644 --- a/dlls/comdlg32/tests/printdlg.c +++ b/dlls/comdlg32/tests/printdlg.c @@ -147,6 +147,12 @@ static UINT_PTR CALLBACK printer_properties_hook_procA(HWND hdlg, UINT msg, WPAR return 0; } +static UINT_PTR CALLBACK check_hook_proc_not_called(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) +{ + ok(0, "Hook proc should not be called\n"); + return 0; +} + static UINT_PTR CALLBACK check_hook_proc_msg_handlingA(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) { if (msg == WM_INITDIALOG) @@ -346,6 +352,40 @@ static void test_PrintDlgA(void) ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + /* Validate some message handling behaviors of a setup dialog hook. */ + ZeroMemory(pDlg, sizeof(*pDlg)); + hook_inited = FALSE; + pDlg->lStructSize = sizeof(*pDlg); + pDlg->Flags = PD_PRINTSETUP | PD_ENABLESETUPHOOK; + pDlg->lpfnSetupHook = check_hook_proc_msg_handlingA; + pDlg->lCustData = (LPARAM)&hook_inited; + res = PrintDlgA(pDlg); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + + /* If both hooks are specified, only the appropriate one for the specified mode is invoked. */ + ZeroMemory(pDlg, sizeof(*pDlg)); + hook_inited = FALSE; + pDlg->lStructSize = sizeof(*pDlg); + pDlg->Flags = PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK; + pDlg->lpfnPrintHook = check_hook_proc_msg_handlingA; + pDlg->lpfnSetupHook = check_hook_proc_not_called; + pDlg->lCustData = (LPARAM)&hook_inited; + res = PrintDlgA(pDlg); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + + ZeroMemory(pDlg, sizeof(*pDlg)); + hook_inited = FALSE; + pDlg->lStructSize = sizeof(*pDlg); + pDlg->Flags = PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK; + pDlg->lpfnPrintHook = check_hook_proc_not_called; + pDlg->lpfnSetupHook = check_hook_proc_msg_handlingA; + pDlg->lCustData = (LPARAM)&hook_inited; + res = PrintDlgA(pDlg); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + free(pDlg); } @@ -437,6 +477,40 @@ void test_PrintDlgW(void) res = PrintDlgW(&pd); ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + + /* Validate some message handling behaviors of a setup dialog hook. */ + ZeroMemory(&pd, sizeof(pd)); + hook_inited = FALSE; + pd.lStructSize = sizeof(pd); + pd.Flags = PD_PRINTSETUP | PD_ENABLESETUPHOOK; + pd.lpfnSetupHook = check_hook_proc_msg_handlingW; + pd.lCustData = (LPARAM)&hook_inited; + res = PrintDlgW(&pd); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + + /* If both hooks are specified, only the appropriate one for the specified mode is invoked. */ + ZeroMemory(&pd, sizeof(pd)); + hook_inited = FALSE; + pd.lStructSize = sizeof(pd); + pd.Flags = PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK; + pd.lpfnPrintHook = check_hook_proc_msg_handlingW; + pd.lpfnSetupHook = check_hook_proc_not_called; + pd.lCustData = (LPARAM)&hook_inited; + res = PrintDlgW(&pd); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + + ZeroMemory(&pd, sizeof(pd)); + hook_inited = FALSE; + pd.lStructSize = sizeof(pd); + pd.Flags = PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK; + pd.lpfnPrintHook = check_hook_proc_not_called; + pd.lpfnSetupHook = check_hook_proc_msg_handlingW; + pd.lCustData = (LPARAM)&hook_inited; + res = PrintDlgW(&pd); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); } /* ########################### */ -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11087
participants (2)
-
Andrew Nguyen -
Andrew Nguyen (@arethusa)