4 * Copyright 1995 Bernd Schmidt
9 #include "wine/winbase16.h"
10 #include "wine/winuser16.h"
14 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(dialog
)
20 #define MSGBOX_IDICON 1088
21 #define MSGBOX_IDTEXT 100
23 static HFONT
MSGBOX_OnInit(HWND hwnd
, LPMSGBOXPARAMSA lpmb
)
25 static HFONT hFont
= 0, hPrevFont
= 0;
30 int bspace
, bw
, bh
, theight
, tleft
, wwidth
, wheight
, bpos
;
31 int borheight
, borwidth
, iheight
, ileft
, iwidth
, twidth
, tiheight
;
33 if (TWEAK_WineLook
>= WIN95_LOOK
) {
34 NONCLIENTMETRICSA nclm
;
36 nclm
.cbSize
= sizeof(NONCLIENTMETRICSA
);
37 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
38 hFont
= CreateFontIndirectA (&nclm
.lfMessageFont
);
41 SendDlgItemMessageA (hwnd
, i
, WM_SETFONT
, (WPARAM
)hFont
, 0);
43 SendDlgItemMessageA (hwnd
, MSGBOX_IDTEXT
, WM_SETFONT
, (WPARAM
)hFont
, 0);
45 if (lpmb
->lpszCaption
) SetWindowTextA(hwnd
, lpmb
->lpszCaption
);
46 SetWindowTextA(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), lpmb
->lpszText
);
47 /* Hide not selected buttons */
48 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
50 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
53 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
54 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
55 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
56 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
57 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
59 case MB_ABORTRETRYIGNORE
:
60 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
61 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
62 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
63 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
66 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
69 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
70 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
71 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
72 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
75 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
76 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
77 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
78 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
79 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
83 switch(lpmb
->dwStyle
& MB_ICONMASK
) {
84 case MB_ICONEXCLAMATION
:
85 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
86 (WPARAM16
)LoadIcon16(0, IDI_EXCLAMATION16
), 0);
89 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
90 (WPARAM16
)LoadIcon16(0, IDI_QUESTION16
), 0);
93 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
94 (WPARAM16
)LoadIcon16(0, IDI_ASTERISK16
), 0);
98 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
99 (WPARAM16
)LoadIcon16(0, IDI_HAND16
), 0);
103 /* Position everything */
104 GetWindowRect(hwnd
, &rect
);
105 borheight
= rect
.bottom
- rect
.top
;
106 borwidth
= rect
.right
- rect
.left
;
107 GetClientRect(hwnd
, &rect
);
108 borheight
-= rect
.bottom
- rect
.top
;
109 borwidth
-= rect
.right
- rect
.left
;
111 /* Get the icon height */
112 GetWindowRect(GetDlgItem(hwnd
, MSGBOX_IDICON
), &rect
);
113 MapWindowPoints(0, hwnd
, (LPPOINT
)&rect
, 2);
114 iheight
= rect
.bottom
- rect
.top
;
116 iwidth
= rect
.right
- ileft
;
120 hPrevFont
= SelectObject(hdc
, hFont
);
122 /* Get the number of visible buttons and their size */
123 bh
= bw
= 1; /* Minimum button sizes */
124 for (buttons
= 0, i
= 1; i
< 8; i
++)
126 hItem
= GetDlgItem(hwnd
, i
);
127 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
)
129 char buttonText
[1024];
132 if (GetWindowTextA(hItem
, buttonText
, sizeof buttonText
))
134 DrawTextA( hdc
, buttonText
, -1, &rect
, DT_LEFT
| DT_EXPANDTABS
| DT_CALCRECT
);
135 h
= rect
.bottom
- rect
.top
;
136 w
= rect
.right
- rect
.left
;
142 bw
= MAX(bw
, bh
* 2);
143 /* Button white space */
146 bspace
= bw
/3; /* Space between buttons */
148 /* Get the text size */
149 GetClientRect(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), &rect
);
150 rect
.top
= rect
.left
= rect
.bottom
= 0;
151 DrawTextA( hdc
, lpmb
->lpszText
, -1, &rect
,
152 DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_CALCRECT
);
153 /* Min text width corresponds to space for the buttons */
154 tleft
= 2 * ileft
+ iwidth
;
155 twidth
= MAX((bw
+ bspace
) * buttons
+ bspace
- tleft
, rect
.right
);
156 theight
= rect
.bottom
;
159 SelectObject(hdc
, hPrevFont
);
160 ReleaseDC(hItem
, hdc
);
162 tiheight
= 16 + MAX(iheight
, theight
);
163 wwidth
= tleft
+ twidth
+ ileft
+ borwidth
;
164 wheight
= 8 + tiheight
+ bh
+ borheight
;
166 /* Resize the window */
167 SetWindowPos(hwnd
, 0, 0, 0, wwidth
, wheight
,
168 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
170 /* Position the icon */
171 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDICON
), 0, ileft
, (tiheight
- iheight
) / 2, 0, 0,
172 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
174 /* Position the text */
175 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), 0, tleft
, (tiheight
- theight
) / 2, twidth
, theight
,
176 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
178 /* Position the buttons */
179 bpos
= (wwidth
- (bw
+ bspace
) * buttons
+ bspace
) / 2;
180 for (buttons
= i
= 0; i
< 7; i
++) {
181 /* some arithmetic to get the right order for YesNoCancel windows */
182 hItem
= GetDlgItem(hwnd
, (i
+ 5) % 7 + 1);
183 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
184 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
186 SendMessageA( hItem
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
188 SetWindowPos(hItem
, 0, bpos
, tiheight
, bw
, bh
,
189 SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
197 /**************************************************************************
200 * Dialog procedure for message boxes.
202 static LRESULT CALLBACK
MSGBOX_DlgProc( HWND hwnd
, UINT message
,
203 WPARAM wParam
, LPARAM lParam
)
208 hFont
= MSGBOX_OnInit(hwnd
, (LPMSGBOXPARAMSA
)lParam
);
221 EndDialog(hwnd
, wParam
);
228 /* Ok. Ignore all the other messages */
229 TRACE("Message number %i is being ignored.\n", message
);
236 /**************************************************************************
237 * MessageBox16 (USER.1)
239 INT16 WINAPI
MessageBox16( HWND16 hwnd
, LPCSTR text
, LPCSTR title
, UINT16 type
)
241 WARN("Messagebox\n");
242 return MessageBoxA( hwnd
, text
, title
, type
);
246 /**************************************************************************
247 * MessageBox32A (USER32.391)
250 * The WARN is here to help debug erroneous MessageBoxes
251 * Use: -debugmsg warn+dialog,+relay
253 INT WINAPI
MessageBoxA(HWND hWnd
, LPCSTR text
, LPCSTR title
, UINT type
)
259 WARN("Messagebox\n");
261 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
263 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
266 if (!text
) text
="<WINE-NULL>";
269 mbox
.lpszCaption
= title
;
270 mbox
.lpszText
= text
;
272 return DialogBoxIndirectParamA( GetWindowLongA(hWnd
,GWL_HINSTANCE
), template,
273 hWnd
, (DLGPROC
)MSGBOX_DlgProc
, (LPARAM
)&mbox
);
277 /**************************************************************************
278 * MessageBox32W (USER32.396)
280 INT WINAPI
MessageBoxW( HWND hwnd
, LPCWSTR text
, LPCWSTR title
,
283 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
284 LPSTR textA
= HEAP_strdupWtoA( GetProcessHeap(), 0, text
);
287 WARN("Messagebox\n");
289 ret
= MessageBoxA( hwnd
, textA
, titleA
, type
);
290 HeapFree( GetProcessHeap(), 0, titleA
);
291 HeapFree( GetProcessHeap(), 0, textA
);
296 /**************************************************************************
297 * MessageBoxEx32A (USER32.392)
299 INT WINAPI
MessageBoxExA( HWND hWnd
, LPCSTR text
, LPCSTR title
,
300 UINT type
, WORD langid
)
302 WARN("Messagebox\n");
303 /* ignore language id for now */
304 return MessageBoxA(hWnd
,text
,title
,type
);
307 /**************************************************************************
308 * MessageBoxEx32W (USER32.393)
310 INT WINAPI
MessageBoxExW( HWND hWnd
, LPCWSTR text
, LPCWSTR title
,
311 UINT type
, WORD langid
)
313 WARN("Messagebox\n");
314 /* ignore language id for now */
315 return MessageBoxW(hWnd
,text
,title
,type
);
318 /**************************************************************************
319 * MessageBoxIndirect16 (USER.827)
321 INT16 WINAPI
MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox
)
325 MSGBOXPARAMSA msgbox32
;
327 WARN("Messagebox\n");
329 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
331 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
334 msgbox32
.cbSize
= msgbox
->cbSize
;
335 msgbox32
.hwndOwner
= msgbox
->hwndOwner
;
336 msgbox32
.hInstance
= msgbox
->hInstance
;
337 msgbox32
.lpszText
= PTR_SEG_TO_LIN(msgbox
->lpszText
);
338 msgbox32
.lpszCaption
= PTR_SEG_TO_LIN(msgbox
->lpszCaption
);
339 msgbox32
.dwStyle
= msgbox
->dwStyle
;
340 msgbox32
.lpszIcon
= PTR_SEG_TO_LIN(msgbox
->lpszIcon
);
341 msgbox32
.dwContextHelpId
= msgbox
->dwContextHelpId
;
342 msgbox32
.lpfnMsgBoxCallback
= msgbox
->lpfnMsgBoxCallback
;
343 msgbox32
.dwLanguageId
= msgbox
->dwLanguageId
;
345 return DialogBoxIndirectParamA( msgbox32
.hInstance
, template,
346 msgbox32
.hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
350 /**************************************************************************
351 * MessageBoxIndirect32A (USER32.394)
353 INT WINAPI
MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox
)
358 WARN("Messagebox\n");
360 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
362 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
365 return DialogBoxIndirectParamA( msgbox
->hInstance
, template,
366 msgbox
->hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
370 /**************************************************************************
371 * MessageBoxIndirect32W (USER32.395)
373 INT WINAPI
MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox
)
375 MSGBOXPARAMSA msgboxa
;
376 WARN("Messagebox\n");
378 memcpy(&msgboxa
,msgbox
,sizeof(msgboxa
));
379 if (msgbox
->lpszCaption
)
380 lstrcpyWtoA((LPSTR
)msgboxa
.lpszCaption
,msgbox
->lpszCaption
);
381 if (msgbox
->lpszText
)
382 lstrcpyWtoA((LPSTR
)msgboxa
.lpszText
,msgbox
->lpszText
);
384 return MessageBoxIndirectA(&msgboxa
);
388 /**************************************************************************
389 * FatalAppExit16 (KERNEL.137)
391 void WINAPI
FatalAppExit16( UINT16 action
, LPCSTR str
)
394 FatalAppExitA( action
, str
);
398 /**************************************************************************
399 * FatalAppExit32A (KERNEL32.108)
401 void WINAPI
FatalAppExitA( UINT action
, LPCSTR str
)
404 MessageBoxA( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);
409 /**************************************************************************
410 * FatalAppExit32W (KERNEL32.109)
412 void WINAPI
FatalAppExitW( UINT action
, LPCWSTR str
)
415 MessageBoxW( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);