user32/msgbox: Support WM_COPY Message

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=17205

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
This commit is contained in:
Alistair Leslie-Hughes 2024-03-06 20:21:36 +11:00
parent 7c5b9304a6
commit 375ff622d1

View file

@ -41,6 +41,11 @@ struct ThreadWindows
HWND *handles;
};
/* Index the order the buttons need to appear to an ID* constant */
static const int buttonOrder[10] = { IDYES, IDNO, IDOK, IDABORT, IDRETRY,
IDCANCEL, IDIGNORE, IDTRYAGAIN,
IDCONTINUE, IDHELP };
static BOOL CALLBACK MSGBOX_EnumProc(HWND hwnd, LPARAM lParam)
{
struct ThreadWindows *threadWindows = (struct ThreadWindows *)lParam;
@ -74,11 +79,6 @@ static void MSGBOX_OnInit(HWND hwnd, LPMSGBOXPARAMSW lpmb)
WCHAR *buffer = NULL;
const WCHAR *ptr;
/* Index the order the buttons need to appear to an ID* constant */
static const int buttonOrder[10] = { IDYES, IDNO, IDOK, IDABORT, IDRETRY,
IDCANCEL, IDIGNORE, IDTRYAGAIN,
IDCONTINUE, IDHELP };
nclm.cbSize = sizeof(nclm);
SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
@ -320,6 +320,79 @@ static void MSGBOX_OnInit(HWND hwnd, LPMSGBOXPARAMSW lpmb)
HeapFree( GetProcessHeap(), 0, buffer );
}
static void MSGBOX_CopyToClipbaord( HWND hwnd )
{
int i;
static const WCHAR line[] = L"---------------------------\r\n";
static const WCHAR carriage[] = L"\r\n";
static const WCHAR spaces[] = L" ";
int lenTitle = GetWindowTextLengthW(hwnd) + 1;
int lenMsg = GetWindowTextLengthW(GetDlgItem(hwnd, MSGBOX_IDTEXT)) + 1;
HGLOBAL hMem;
WCHAR *data;
/*
---------------------------
Dialog Title
---------------------------
Dialog Message
---------------------------
Button(s) Text. OK
---------------------------
*/
int len = ((wcslen(carriage) * 3) + (wcslen(line) * 4) + lenTitle + lenMsg) * sizeof(WCHAR);
WCHAR *text = malloc(len);
if (!text)
return;
lstrcpyW(text, line);
if (!GetWindowTextW(hwnd, text + lstrlenW(text), lenTitle))
{
free(text);
return;
}
lstrcatW(text, carriage);
lstrcatW(text, line);
GetWindowTextW(GetDlgItem(hwnd, MSGBOX_IDTEXT), text + lstrlenW(text), lenMsg);
lstrcatW(text, carriage);
lstrcatW(text, line);
for (i = 0; i < ARRAY_SIZE(buttonOrder); i++)
{
HWND hItem = GetDlgItem(hwnd, buttonOrder[i]);
if (GetWindowLongW(hItem, GWL_STYLE) & WS_VISIBLE)
{
WCHAR buffer[1024] = {0};
int j = 0, k = lstrlenW(text);
GetWindowTextW(hItem, buffer, 1024);
while(buffer[j] != 0)
{
if(buffer[j] != '&')
text[k++] = buffer[j];
j++;
}
text[k] = 0;
lstrcatW(text, spaces);
}
}
lstrcatW(text, carriage);
lstrcatW(text, line);
hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, len);
data = GlobalLock(hMem);
lstrcpyW(data, text);
GlobalUnlock(hMem);
OpenClipboard(hwnd);
NtUserEmptyClipboard();
SetClipboardData(CF_UNICODETEXT, hMem);
NtUserCloseClipboard();
free(text);
}
/**************************************************************************
* MSGBOX_DlgProc
@ -339,6 +412,10 @@ static INT_PTR CALLBACK MSGBOX_DlgProc( HWND hwnd, UINT message,
break;
}
case WM_COPY:
MSGBOX_CopyToClipbaord(hwnd);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{