[USER32] Specify the font to be used for the message-box in its dialog template, using DS_SETFONT and a font point size of 0x7FFF, instead of passing a font handle and setting the font of each control manually.

Also improve the flags used in the DrawTextW() call for calculating
the size to be taken by the message-box text.
This commit is contained in:
Hermès Bélusca-Maïto 2018-08-10 18:20:53 +02:00
parent ed1de7184c
commit cb77cc707f
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -57,8 +57,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(user32);
#define MSGBOXEX_MAXBTNS (4) #define MSGBOXEX_MAXBTNS (4)
/* Rescale logical coordinates */ /* Rescale logical coordinates */
#define RESCALE_X(_x, _unit) (((_x) * 4 + LOWORD(_unit) - 1) / LOWORD(_unit)) #define RESCALE_X(_x, _units) (((_x) * 4 + (_units).cx - 1) / (_units).cx)
#define RESCALE_Y(_y, _unit) (((_y) * 8 + HIWORD(_unit) - 1) / HIWORD(_unit)) #define RESCALE_Y(_y, _units) (((_y) * 8 + (_units).cy - 1) / (_units).cy)
/* MessageBox button helpers */ /* MessageBox button helpers */
@ -103,7 +103,6 @@ typedef struct _MSGBOXINFO
MSGBOXPARAMSW; // Wine passes this too. MSGBOXPARAMSW; // Wine passes this too.
// ReactOS // ReactOS
HICON Icon; HICON Icon;
HFONT Font;
int DefBtn; int DefBtn;
int nButtons; int nButtons;
LONG *Btns; LONG *Btns;
@ -220,7 +219,7 @@ static INT_PTR CALLBACK MessageBoxProc(
HWND hwnd, UINT message, HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam) WPARAM wParam, LPARAM lParam)
{ {
int i, Alert; int Alert;
PMSGBOXINFO mbi; PMSGBOXINFO mbi;
HELPINFO hi; HELPINFO hi;
HWND owner; HWND owner;
@ -267,12 +266,6 @@ static INT_PTR CALLBACK MessageBoxProc(
/* Send out the alert notifications. */ /* Send out the alert notifications. */
NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd, OBJID_ALERT, Alert); NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd, OBJID_ALERT, Alert);
/* set control fonts */
SendDlgItemMessageW(hwnd, MSGBOX_IDTEXT, WM_SETFONT, (WPARAM)mbi->Font, 0);
for (i = 0; i < mbi->nButtons; i++)
{
SendDlgItemMessageW(hwnd, mbi->Btns[i], WM_SETFONT, (WPARAM)mbi->Font, 0);
}
switch (mbi->dwStyle & MB_TYPEMASK) switch (mbi->dwStyle & MB_TYPEMASK)
{ {
case MB_ABORTRETRYIGNORE: case MB_ABORTRETRYIGNORE:
@ -372,9 +365,11 @@ MessageBoxTimeoutIndirectW(
LPVOID buf; LPVOID buf;
BYTE *dest; BYTE *dest;
LPCWSTR caption, text; LPCWSTR caption, text;
HFONT hFont; HFONT hFont, hOldFont;
HICON Icon; HICON Icon;
HWND hDCWnd;
HDC hDC; HDC hDC;
SIZE units;
int bufsize, ret, caplen, textlen, i, btnleft, btntop, lmargin; int bufsize, ret, caplen, textlen, i, btnleft, btntop, lmargin;
MSGBTNINFO Buttons; MSGBTNINFO Buttons;
LPCWSTR ButtonText[MSGBOXEX_MAXBTNS]; LPCWSTR ButtonText[MSGBOXEX_MAXBTNS];
@ -384,7 +379,6 @@ MessageBoxTimeoutIndirectW(
SIZE btnsize; SIZE btnsize;
MSGBOXINFO mbi; MSGBOXINFO mbi;
BOOL defbtn = FALSE; BOOL defbtn = FALSE;
DWORD units = GetDialogBaseUnits();
if (!lpMsgBoxParams->lpszCaption) if (!lpMsgBoxParams->lpszCaption)
{ {
@ -470,8 +464,9 @@ MessageBoxTimeoutIndirectW(
/* Basic space */ /* Basic space */
bufsize = sizeof(DLGTEMPLATE) + bufsize = sizeof(DLGTEMPLATE) +
2 * sizeof(WORD) + /* menu and class */ 2 * sizeof(WORD) + /* menu and class */
(caplen + 1) * sizeof(WCHAR); /* title */ (caplen + 1) * sizeof(WCHAR) + /* title */
sizeof(WORD); /* font height */
/* Space for icon */ /* Space for icon */
if (NULL != Icon) if (NULL != Icon)
@ -510,18 +505,22 @@ MessageBoxTimeoutIndirectW(
buf = RtlAllocateHeap(GetProcessHeap(), 0, bufsize); buf = RtlAllocateHeap(GetProcessHeap(), 0, bufsize);
if (!buf) if (!buf)
{
return 0; return 0;
}
iico = itxt = NULL; iico = itxt = NULL;
nclm.cbSize = sizeof(nclm); nclm.cbSize = sizeof(nclm);
SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0); SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(nclm), &nclm, 0);
hFont = CreateFontIndirectW(&nclm.lfMessageFont); hFont = CreateFontIndirectW(&nclm.lfMessageFont);
if (!hFont)
{
ERR("Cannot retrieve nclm.lfMessageFont!\n");
goto Quit;
}
tpl = (DLGTEMPLATE *)buf; tpl = (DLGTEMPLATE *)buf;
tpl->style = WS_CAPTION | WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_SYSMENU | DS_CENTER | DS_MODALFRAME | DS_NOIDLEMSG; tpl->style = WS_CAPTION | WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_SYSMENU | DS_CENTER | DS_SETFONT | DS_MODALFRAME | DS_NOIDLEMSG;
tpl->dwExtendedStyle = WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT; tpl->dwExtendedStyle = WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT;
if (lpMsgBoxParams->dwStyle & MB_TOPMOST) if (lpMsgBoxParams->dwStyle & MB_TOPMOST)
tpl->dwExtendedStyle |= WS_EX_TOPMOST; tpl->dwExtendedStyle |= WS_EX_TOPMOST;
@ -541,6 +540,13 @@ MessageBoxTimeoutIndirectW(
*(WCHAR*)dest = L'\0'; *(WCHAR*)dest = L'\0';
dest += sizeof(WCHAR); dest += sizeof(WCHAR);
/*
* A font point size (height) of 0x7FFF means that we use
* the message box font (NONCLIENTMETRICSW.lfMessageFont).
*/
*(WORD*)dest = 0x7FFF;
dest += sizeof(WORD);
/* Create icon */ /* Create icon */
if (Icon) if (Icon)
{ {
@ -585,8 +591,30 @@ MessageBoxTimeoutIndirectW(
*(WORD*)dest = 0; *(WORD*)dest = 0;
dest += sizeof(WORD); dest += sizeof(WORD);
hDC = CreateCompatibleDC(0); hDCWnd = NULL;
SelectObject(hDC, hFont); hDC = GetDCEx(hDCWnd, NULL, DCX_WINDOW | DCX_CACHE);
if (!hDC)
{
/* Retry with the DC of the owner window */
hDCWnd = lpMsgBoxParams->hwndOwner;
hDC = GetDCEx(hDCWnd, NULL, DCX_WINDOW | DCX_CACHE);
}
if (!hDC)
{
ERR("GetDCEx() failed, bail out!\n");
goto Quit;
}
hOldFont = SelectObject(hDC, hFont);
units.cx = GdiGetCharDimensions(hDC, NULL, &units.cy);
if (!units.cx)
{
DWORD defUnits;
ERR("GdiGetCharDimensions() failed, falling back to default values!\n");
defUnits = GetDialogBaseUnits();
units.cx = LOWORD(defUnits);
units.cy = HIWORD(defUnits);
}
/* create buttons */ /* create buttons */
btnsize.cx = BTN_CX; btnsize.cx = BTN_CX;
@ -643,7 +671,7 @@ MessageBoxTimeoutIndirectW(
txtrect.top = txtrect.left = txtrect.bottom = 0; txtrect.top = txtrect.left = txtrect.bottom = 0;
if (textlen != 0) if (textlen != 0)
{ {
DrawTextW(hDC, text, textlen, &txtrect, DT_LEFT | DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); DrawTextW(hDC, text, textlen, &txtrect, DT_LEFT | DT_NOPREFIX | DT_WORDBREAK | DT_EXPANDTABS | DT_EXTERNALLEADING | DT_EDITCONTROL | DT_CALCRECT);
} }
else else
{ {
@ -652,8 +680,13 @@ MessageBoxTimeoutIndirectW(
} }
txtrect.right++; txtrect.right++;
if (hDC) if (hOldFont)
DeleteDC(hDC); SelectObject(hDC, hOldFont);
ReleaseDC(hDCWnd, hDC);
if (hFont)
DeleteObject(hFont);
/* calculate position and size of the icon */ /* calculate position and size of the icon */
rc.left = rc.bottom = rc.right = 0; rc.left = rc.bottom = rc.right = 0;
@ -739,7 +772,6 @@ MessageBoxTimeoutIndirectW(
/* finally show the messagebox */ /* finally show the messagebox */
mbi.Icon = Icon; mbi.Icon = Icon;
mbi.Font = hFont;
mbi.dwContextHelpId = lpMsgBoxParams->dwContextHelpId; mbi.dwContextHelpId = lpMsgBoxParams->dwContextHelpId;
mbi.lpfnMsgBoxCallback = lpMsgBoxParams->lpfnMsgBoxCallback; mbi.lpfnMsgBoxCallback = lpMsgBoxParams->lpfnMsgBoxCallback;
mbi.dwStyle = lpMsgBoxParams->dwStyle; mbi.dwStyle = lpMsgBoxParams->dwStyle;
@ -759,9 +791,7 @@ MessageBoxTimeoutIndirectW(
ret = DialogBoxIndirectParamW(lpMsgBoxParams->hInstance, tpl, lpMsgBoxParams->hwndOwner, ret = DialogBoxIndirectParamW(lpMsgBoxParams->hInstance, tpl, lpMsgBoxParams->hwndOwner,
MessageBoxProc, (LPARAM)&mbi); MessageBoxProc, (LPARAM)&mbi);
if (hFont) Quit:
DeleteObject(hFont);
RtlFreeHeap(GetProcessHeap(), 0, buf); RtlFreeHeap(GetProcessHeap(), 0, buf);
return ret; return ret;
} }