Index: win32ss/user/user32/windows/messagebox.c =================================================================== --- win32ss/user/user32/windows/messagebox.c (revision 69570) +++ win32ss/user/user32/windows/messagebox.c (working copy) @@ -62,6 +62,42 @@ #define MSGBOXEX_MAXBTNSTR (32) #define MSGBOXEX_MAXBTNS (4) +/* Rescale logical coordinates */ +#define RESCALE_X(_x, _unit) (((_x) * 4 + LOWORD(_unit) - 1) / LOWORD(_unit)) +#define RESCALE_Y(_y, _unit) (((_y) * 8 + HIWORD(_unit) - 1) / HIWORD(_unit)) + +#define DECLARE_MB_1(_btn0) \ + { 1, { ID##_btn0, 0, 0 }, { IDS_##_btn0, 0, 0 } } + +#define DECLARE_MB_2(_btn0, _btn1) \ + { 2, { ID##_btn0, ID##_btn1, 0 }, { IDS_##_btn0, IDS_##_btn1, 0 } } + +#define DECLARE_MB_3(_btn0, _btn1, _btn2) \ + { 3, { ID##_btn0, ID##_btn1, ID##_btn2 }, { IDS_##_btn0, IDS_##_btn1, IDS_##_btn2 } } + +typedef struct { + LONG bntCnt; + LONG btnIdx[MSGBOXEX_MAXBTNS]; + UINT btnIds[MSGBOXEX_MAXBTNS]; +} MSGBTNINFO, *PMSGBTNINFO; + +static const MSGBTNINFO MsgBtnInfo[] = { + /* MB_OK (0) */ + DECLARE_MB_1(OK), + /* MB_OKCANCEL (1) */ + DECLARE_MB_2(OK, CANCEL), + /* MB_ABORTRETRYIGNORE (2) */ + DECLARE_MB_3(ABORT, RETRY, IGNORE), + /* MB_YESNOCANCEL (3) */ + DECLARE_MB_3(YES, NO, CANCEL), + /* MB_YESNO (4) */ + DECLARE_MB_2(YES, NO), + /* MB_RETRYCANCEL (5) */ + DECLARE_MB_2(RETRY, CANCEL), + /* MB_CANCELTRYCONTINUE (6) */ + DECLARE_MB_3(CANCEL, TRYAGAIN, CONTINUE) +}; + typedef struct _MSGBOXINFO { MSGBOXPARAMSW; // Wine passes this too. // ReactOS @@ -328,7 +364,6 @@ DLGTEMPLATE *tpl; DLGITEMTEMPLATE *iico, *itxt; NONCLIENTMETRICSW nclm; - WCHAR capbuf[32]; LPVOID buf; BYTE *dest; LPCWSTR caption, text; @@ -335,9 +370,9 @@ HFONT hFont; HICON Icon; HDC hDC; - int bufsize, ret, caplen, textlen, btnlen, i, btnleft, btntop, lmargin, nButtons = 0; - LONG Buttons[MSGBOXEX_MAXBTNS]; - WCHAR ButtonText[MSGBOXEX_MAXBTNS][MSGBOXEX_MAXBTNSTR]; + int bufsize, ret, caplen, textlen, i, btnleft, btntop, lmargin; + LPCWSTR ButtonText[MSGBOXEX_MAXBTNS]; + int ButtonLen[MSGBOXEX_MAXBTNS]; DLGITEMTEMPLATE *ibtn[MSGBOXEX_MAXBTNS]; RECT btnrect, txtrect, rc; SIZE btnsize; @@ -344,69 +379,54 @@ MSGBOXINFO mbi; BOOL defbtn = FALSE; DWORD units = GetDialogBaseUnits(); + MSGBTNINFO Buttons; - if(!lpMsgBoxParams->lpszCaption || !HIWORD((LPWSTR)lpMsgBoxParams->lpszCaption)) + if(!lpMsgBoxParams->lpszCaption) { - LoadStringW(User32Instance, IDS_ERROR, &capbuf[0], 32); - caption = &capbuf[0]; + caplen = LoadStringW(User32Instance, IDS_ERROR, (LPWSTR)&caption, 0); } else + if (IS_INTRESOURCE(lpMsgBoxParams->lpszCaption)) + { + caplen = LoadStringW(User32Instance, (UINT)(lpMsgBoxParams->lpszCaption), (LPWSTR)&caption, 0); + } + else { caption = (LPWSTR)lpMsgBoxParams->lpszCaption; + caplen = strlenW(caption); + } - if(!lpMsgBoxParams->lpszText || !HIWORD(lpMsgBoxParams->lpszText)) + if(!lpMsgBoxParams->lpszText) + { text = L""; + textlen = 0; + } else + if (IS_INTRESOURCE(lpMsgBoxParams->lpszText)) + { + textlen = LoadStringW(User32Instance, (UINT)(lpMsgBoxParams->lpszText), (LPWSTR)&text, 0); + } + else { text = lpMsgBoxParams->lpszText; + textlen = strlenW(text); + } - caplen = strlenW(caption); - textlen = strlenW(text); + /* Create selected buttons */ + i = lpMsgBoxParams->dwStyle & MB_TYPEMASK; - /* Create selected buttons */ - switch(lpMsgBoxParams->dwStyle & MB_TYPEMASK) + /* Unknown types will fall to MB_OK */ + if (i >= (sizeof(MsgBtnInfo)/sizeof(MsgBtnInfo[0]))) + i = MB_OK; + + /* Get buttons IDs */ + Buttons = MsgBtnInfo[i]; + + /* Create Help button */ + if(lpMsgBoxParams->dwStyle & MB_HELP) { - case MB_OKCANCEL: - Buttons[0] = IDOK; - Buttons[1] = IDCANCEL; - nButtons = 2; - break; - case MB_CANCELTRYCONTINUE: - Buttons[0] = IDCANCEL; - Buttons[1] = IDTRYAGAIN; - Buttons[2] = IDCONTINUE; - nButtons = 3; - break; - case MB_ABORTRETRYIGNORE: - Buttons[0] = IDABORT; - Buttons[1] = IDRETRY; - Buttons[2] = IDIGNORE; - nButtons = 3; - break; - case MB_YESNO: - Buttons[0] = IDYES; - Buttons[1] = IDNO; - nButtons = 2; - break; - case MB_YESNOCANCEL: - Buttons[0] = IDYES; - Buttons[1] = IDNO; - Buttons[2] = IDCANCEL; - nButtons = 3; - break; - case MB_RETRYCANCEL: - Buttons[0] = IDRETRY; - Buttons[1] = IDCANCEL; - nButtons = 2; - break; - case MB_OK: - /* fall through */ - default: - Buttons[0] = IDOK; - nButtons = 1; - break; + Buttons.btnIdx[Buttons.bntCnt] = IDHELP; + Buttons.btnIds[Buttons.bntCnt] = IDS_HELP; + Buttons.bntCnt++; } - /* Create Help button */ - if(lpMsgBoxParams->dwStyle & MB_HELP) - Buttons[nButtons++] = IDHELP; switch(lpMsgBoxParams->dwStyle & MB_ICONMASK) { @@ -460,43 +480,15 @@ (textlen + 1) * sizeof(WCHAR); - for(i = 0; i < nButtons; i++) + for (i = 0; i < Buttons.bntCnt; i++) { - switch(Buttons[i]) + if (Buttons.btnIds[i]) + ButtonLen[i] = + LoadStringW(User32Instance, Buttons.btnIds[i], (LPWSTR)&ButtonText[i], 0); + else { - case IDOK: - LoadStringW(User32Instance, IDS_OK, ButtonText[i], MSGBOXEX_MAXBTNSTR - 1); - break; - case IDCANCEL: - LoadStringW(User32Instance, IDS_CANCEL, ButtonText[i], MSGBOXEX_MAXBTNSTR - 1); - break; - case IDYES: - LoadStringW(User32Instance, IDS_YES, ButtonText[i], MSGBOXEX_MAXBTNSTR - 1); - break; - case IDNO: - LoadStringW(User32Instance, IDS_NO, ButtonText[i], MSGBOXEX_MAXBTNSTR - 1); - break; - case IDTRYAGAIN: - LoadStringW(User32Instance, IDS_TRYAGAIN, ButtonText[i], MSGBOXEX_MAXBTNSTR - 1); - break; - case IDCONTINUE: - LoadStringW(User32Instance, IDS_CONTINUE, ButtonText[i], MSGBOXEX_MAXBTNSTR - 1); - break; - case IDABORT: - LoadStringW(User32Instance, IDS_ABORT, ButtonText[i], MSGBOXEX_MAXBTNSTR - 1); - break; - case IDRETRY: - LoadStringW(User32Instance, IDS_RETRY, ButtonText[i], MSGBOXEX_MAXBTNSTR - 1); - break; - case IDIGNORE: - LoadStringW(User32Instance, IDS_IGNORE, ButtonText[i], MSGBOXEX_MAXBTNSTR - 1); - break; - case IDHELP: - LoadStringW(User32Instance, IDS_HELP, ButtonText[i], MSGBOXEX_MAXBTNSTR - 1); - break; - default: - ButtonText[i][0] = (WCHAR)0; - break; + ButtonText[i] = L""; + ButtonLen[i] = 0; } /* Space for buttons */ @@ -503,7 +495,7 @@ bufsize = (bufsize + 3) & ~3; bufsize += sizeof(DLGITEMTEMPLATE) + 3 * sizeof(WORD) + - (wcslen(ButtonText[i]) + 1) * sizeof(WCHAR); + (ButtonLen[i] + 1) * sizeof(WCHAR); } buf = RtlAllocateHeap(GetProcessHeap(), 0, bufsize); @@ -529,7 +521,7 @@ tpl->dwExtendedStyle |= WS_EX_RIGHT; tpl->x = 100; tpl->y = 100; - tpl->cdit = nButtons + ((Icon != (HICON)0) ? 1 : 0) + 1; + tpl->cdit = Buttons.bntCnt + ((Icon != (HICON)0) ? 1 : 0) + 1; dest = (BYTE *)(tpl + 1); @@ -589,7 +581,10 @@ btnsize.cx = BTN_CX; btnsize.cy = BTN_CY; btnrect.left = btnrect.top = 0; - for(i = 0; i < nButtons; i++) + + SelectObject(hDC, hFont); + + for(i = 0; i < Buttons.bntCnt; i++) { dest = (BYTE*)(((UINT_PTR)dest + 3) & ~3); ibtn[i] = (DLGITEMTEMPLATE *)dest; @@ -597,27 +592,26 @@ if(!defbtn && (i == ((lpMsgBoxParams->dwStyle & MB_DEFMASK) >> 8))) { ibtn[i]->style |= BS_DEFPUSHBUTTON; - mbi.DefBtn = Buttons[i]; + mbi.DefBtn = Buttons.btnIdx[i]; defbtn = TRUE; } else ibtn[i]->style |= BS_PUSHBUTTON; ibtn[i]->dwExtendedStyle = 0; - ibtn[i]->id = Buttons[i]; + ibtn[i]->id = (WORD)Buttons.btnIdx[i]; dest += sizeof(DLGITEMTEMPLATE); *(WORD*)dest = 0xFFFF; dest += sizeof(WORD); *(WORD*)dest = 0x0080; /* button control */ dest += sizeof(WORD); - btnlen = strlenW(ButtonText[i]); - memcpy(dest, ButtonText[i], btnlen * sizeof(WCHAR)); - dest += btnlen * sizeof(WCHAR); + memcpy(dest, ButtonText[i], ButtonLen[i] * sizeof(WCHAR)); + dest += ButtonLen[i] * sizeof(WCHAR); *(WORD*)dest = 0; dest += sizeof(WORD); *(WORD*)dest = 0; dest += sizeof(WORD); - SelectObject(hDC, hFont); - DrawTextW(hDC, ButtonText[i], btnlen, &btnrect, DT_LEFT | DT_SINGLELINE | DT_CALCRECT); + btnrect.right = btnrect.bottom = 0; + DrawTextW(hDC, ButtonText[i], ButtonLen[i], &btnrect, DT_LEFT | DT_SINGLELINE | DT_CALCRECT); btnsize.cx = max(btnsize.cx, btnrect.right); btnsize.cy = max(btnsize.cy, btnrect.bottom); } @@ -627,7 +621,7 @@ { ibtn[0]->style &= ~BS_PUSHBUTTON; ibtn[0]->style |= BS_DEFPUSHBUTTON; - mbi.DefBtn = Buttons[0]; + mbi.DefBtn = Buttons.btnIdx[0]; } /* calculate position and size of controls */ @@ -661,7 +655,7 @@ #else rc.top = MSGBOXEX_MARGIN; #endif - btnleft = (nButtons * (btnsize.cx + MSGBOXEX_BUTTONSPACING)) - MSGBOXEX_BUTTONSPACING; + btnleft = (Buttons.bntCnt * (btnsize.cx + MSGBOXEX_BUTTONSPACING)) - MSGBOXEX_BUTTONSPACING; if(btnleft > txtrect.right + rc.right + MSGBOXEX_SPACING) { #ifdef MSGBOX_TEXTHCENTER @@ -677,16 +671,17 @@ btnleft = MSGBOXEX_MARGIN + ((txtrect.right + rc.right + MSGBOXEX_SPACING) / 2) - (btnleft / 2); } rc.left = lmargin; - iico->x = (rc.left * 4) / LOWORD(units); - iico->y = (rc.top * 8) / HIWORD(units); - iico->cx = (rc.right * 4) / LOWORD(units); - iico->cy = (rc.bottom * 8) / HIWORD(units); + iico->x = RESCALE_X(rc.left, units); + iico->y = RESCALE_Y(rc.top, units); + iico->cx = RESCALE_X(rc.right, units); + iico->cy = RESCALE_Y(rc.bottom, units); + btntop = rc.top + rc.bottom + MSGBOXEX_SPACING; rc.left += rc.right + MSGBOXEX_SPACING; } else { - btnleft = (nButtons * (btnsize.cx + MSGBOXEX_BUTTONSPACING)) - MSGBOXEX_BUTTONSPACING; + btnleft = (Buttons.bntCnt * (btnsize.cx + MSGBOXEX_BUTTONSPACING)) - MSGBOXEX_BUTTONSPACING; if(btnleft > txtrect.right) { #ifdef MSGBOX_TEXTHCENTER @@ -708,12 +703,12 @@ rc.top = max(rc.top, MSGBOXEX_MARGIN); /* calculate position of the buttons */ btntop = max(rc.top + txtrect.bottom + MSGBOXEX_SPACING, btntop); - for(i = 0; i < nButtons; i++) + for(i = 0; i < Buttons.bntCnt; i++) { - ibtn[i]->x = (btnleft * 4) / LOWORD(units); - ibtn[i]->y = (btntop * 8) / HIWORD(units); - ibtn[i]->cx = (btnsize.cx * 4) / LOWORD(units); - ibtn[i]->cy = (btnsize.cy * 8) / HIWORD(units); + ibtn[i]->x = RESCALE_X(btnleft, units); + ibtn[i]->y = RESCALE_Y(btntop, units); + ibtn[i]->cx = RESCALE_X(btnsize.cx, units); + ibtn[i]->cy = RESCALE_Y(btnsize.cy, units); btnleft += btnsize.cx + MSGBOXEX_BUTTONSPACING; } /* calculate size and position of the messagebox window */ @@ -721,13 +716,13 @@ btnleft += MSGBOXEX_MARGIN; btntop += btnsize.cy + MSGBOXEX_MARGIN; /* set size and position of the message static */ - itxt->x = (rc.left * 4) / LOWORD(units); - itxt->y = (rc.top * 8) / HIWORD(units); - itxt->cx = (((btnleft - rc.left - MSGBOXEX_MARGIN) * 4) / LOWORD(units)); - itxt->cy = ((txtrect.bottom * 8) / HIWORD(units)); + itxt->x = RESCALE_X(rc.left, units); + itxt->y = RESCALE_Y(rc.top, units); + itxt->cx = RESCALE_X(btnleft - rc.left - MSGBOXEX_MARGIN, units); + itxt->cy = RESCALE_Y(txtrect.bottom, units); /* set size of the window */ - tpl->cx = (btnleft * 4) / LOWORD(units); - tpl->cy = (btntop * 8) / HIWORD(units); + tpl->cx = RESCALE_X(btnleft, units); + tpl->cy = RESCALE_Y(btntop, units); /* finally show the messagebox */ mbi.Icon = Icon; @@ -735,8 +730,8 @@ mbi.dwContextHelpId = lpMsgBoxParams->dwContextHelpId; mbi.lpfnMsgBoxCallback = lpMsgBoxParams->lpfnMsgBoxCallback; mbi.dwStyle = lpMsgBoxParams->dwStyle; - mbi.nButtons = nButtons; - mbi.Btns = &Buttons[0]; + mbi.nButtons = Buttons.bntCnt; + mbi.Btns = Buttons.btnIdx; mbi.Timeout = Timeout; /* Pass on to Justin Case so he can peek the message? */