4 * Copyright 1995 Bernd Schmidt
11 #include "wine/winbase16.h"
12 #include "wine/winuser16.h"
16 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(dialog
)
21 #define MSGBOX_IDICON 1088
22 #define MSGBOX_IDTEXT 100
24 static HFONT
MSGBOX_OnInit(HWND hwnd
, LPMSGBOXPARAMSA lpmb
)
26 static HFONT hFont
= 0, hPrevFont
= 0;
31 int bspace
, bw
, bh
, theight
, tleft
, wwidth
, wheight
, bpos
;
32 int borheight
, borwidth
, iheight
, ileft
, iwidth
, twidth
, tiheight
;
36 if (TWEAK_WineLook
>= WIN95_LOOK
) {
37 NONCLIENTMETRICSA nclm
;
39 nclm
.cbSize
= sizeof(NONCLIENTMETRICSA
);
40 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
41 hFont
= CreateFontIndirectA (&nclm
.lfMessageFont
);
44 SendDlgItemMessageA (hwnd
, i
, WM_SETFONT
, (WPARAM
)hFont
, 0);
46 SendDlgItemMessageA (hwnd
, MSGBOX_IDTEXT
, WM_SETFONT
, (WPARAM
)hFont
, 0);
48 if (HIWORD(lpmb
->lpszCaption
)) {
49 SetWindowTextA(hwnd
, lpmb
->lpszCaption
);
51 if (LoadStringA(lpmb
->hInstance
, LOWORD(lpmb
->lpszCaption
), buf
, sizeof(buf
)))
52 SetWindowTextA(hwnd
, buf
);
54 if (HIWORD(lpmb
->lpszText
)) {
55 lpszText
= lpmb
->lpszText
;
58 if (!LoadStringA(lpmb
->hInstance
, LOWORD(lpmb
->lpszText
), buf
, sizeof(buf
)))
59 *buf
= 0; /* FIXME ?? */
61 SetWindowTextA(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), lpszText
);
63 /* Hide not selected buttons */
64 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
66 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
69 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
70 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
71 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
72 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
73 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
75 case MB_ABORTRETRYIGNORE
:
76 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
77 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
78 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
79 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
82 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
85 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
86 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
87 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
88 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
91 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
92 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
93 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
94 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
95 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
99 switch(lpmb
->dwStyle
& MB_ICONMASK
) {
100 case MB_ICONEXCLAMATION
:
101 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
102 (WPARAM16
)LoadIcon16(0, IDI_EXCLAMATION16
), 0);
104 case MB_ICONQUESTION
:
105 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
106 (WPARAM16
)LoadIcon16(0, IDI_QUESTION16
), 0);
108 case MB_ICONASTERISK
:
109 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
110 (WPARAM16
)LoadIcon16(0, IDI_ASTERISK16
), 0);
114 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
115 (WPARAM16
)LoadIcon16(0, IDI_HAND16
), 0);
119 /* Position everything */
120 GetWindowRect(hwnd
, &rect
);
121 borheight
= rect
.bottom
- rect
.top
;
122 borwidth
= rect
.right
- rect
.left
;
123 GetClientRect(hwnd
, &rect
);
124 borheight
-= rect
.bottom
- rect
.top
;
125 borwidth
-= rect
.right
- rect
.left
;
127 /* Get the icon height */
128 GetWindowRect(GetDlgItem(hwnd
, MSGBOX_IDICON
), &rect
);
129 MapWindowPoints(0, hwnd
, (LPPOINT
)&rect
, 2);
130 iheight
= rect
.bottom
- rect
.top
;
132 iwidth
= rect
.right
- ileft
;
136 hPrevFont
= SelectObject(hdc
, hFont
);
138 /* Get the number of visible buttons and their size */
139 bh
= bw
= 1; /* Minimum button sizes */
140 for (buttons
= 0, i
= 1; i
< 8; i
++)
142 hItem
= GetDlgItem(hwnd
, i
);
143 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
)
145 char buttonText
[1024];
148 if (GetWindowTextA(hItem
, buttonText
, sizeof buttonText
))
150 DrawTextA( hdc
, buttonText
, -1, &rect
, DT_LEFT
| DT_EXPANDTABS
| DT_CALCRECT
);
151 h
= rect
.bottom
- rect
.top
;
152 w
= rect
.right
- rect
.left
;
158 bw
= MAX(bw
, bh
* 2);
159 /* Button white space */
162 bspace
= bw
/3; /* Space between buttons */
164 /* Get the text size */
165 GetClientRect(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), &rect
);
166 rect
.top
= rect
.left
= rect
.bottom
= 0;
167 DrawTextA( hdc
, lpszText
, -1, &rect
,
168 DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_CALCRECT
);
169 /* Min text width corresponds to space for the buttons */
170 tleft
= 2 * ileft
+ iwidth
;
171 twidth
= MAX((bw
+ bspace
) * buttons
+ bspace
- tleft
, rect
.right
);
172 theight
= rect
.bottom
;
175 SelectObject(hdc
, hPrevFont
);
176 ReleaseDC(hItem
, hdc
);
178 tiheight
= 16 + MAX(iheight
, theight
);
179 wwidth
= tleft
+ twidth
+ ileft
+ borwidth
;
180 wheight
= 8 + tiheight
+ bh
+ borheight
;
182 /* Resize the window */
183 SetWindowPos(hwnd
, 0, 0, 0, wwidth
, wheight
,
184 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
186 /* Position the icon */
187 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDICON
), 0, ileft
, (tiheight
- iheight
) / 2, 0, 0,
188 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
190 /* Position the text */
191 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), 0, tleft
, (tiheight
- theight
) / 2, twidth
, theight
,
192 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
194 /* Position the buttons */
195 bpos
= (wwidth
- (bw
+ bspace
) * buttons
+ bspace
) / 2;
196 for (buttons
= i
= 0; i
< 7; i
++) {
197 /* some arithmetic to get the right order for YesNoCancel windows */
198 hItem
= GetDlgItem(hwnd
, (i
+ 5) % 7 + 1);
199 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
200 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
202 SendMessageA( hItem
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
204 SetWindowPos(hItem
, 0, bpos
, tiheight
, bw
, bh
,
205 SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
213 /**************************************************************************
216 * Dialog procedure for message boxes.
218 static LRESULT CALLBACK
MSGBOX_DlgProc( HWND hwnd
, UINT message
,
219 WPARAM wParam
, LPARAM lParam
)
224 hFont
= MSGBOX_OnInit(hwnd
, (LPMSGBOXPARAMSA
)lParam
);
237 EndDialog(hwnd
, wParam
);
244 /* Ok. Ignore all the other messages */
245 TRACE("Message number %i is being ignored.\n", message
);
252 /**************************************************************************
253 * MessageBox16 (USER.1)
255 INT16 WINAPI
MessageBox16( HWND16 hwnd
, LPCSTR text
, LPCSTR title
, UINT16 type
)
257 WARN("Messagebox\n");
258 return MessageBoxA( hwnd
, text
, title
, type
);
262 /**************************************************************************
263 * MessageBox32A (USER32.391)
266 * The WARN is here to help debug erroneous MessageBoxes
267 * Use: -debugmsg warn+dialog,+relay
269 INT WINAPI
MessageBoxA(HWND hWnd
, LPCSTR text
, LPCSTR title
, UINT type
)
275 WARN("Messagebox\n");
277 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
279 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
282 if (!text
) text
="<WINE-NULL>";
285 mbox
.lpszCaption
= title
;
286 mbox
.lpszText
= text
;
288 return DialogBoxIndirectParamA( GetWindowLongA(hWnd
,GWL_HINSTANCE
), template,
289 hWnd
, (DLGPROC
)MSGBOX_DlgProc
, (LPARAM
)&mbox
);
293 /**************************************************************************
294 * MessageBox32W (USER32.396)
296 INT WINAPI
MessageBoxW( HWND hwnd
, LPCWSTR text
, LPCWSTR title
,
299 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
300 LPSTR textA
= HEAP_strdupWtoA( GetProcessHeap(), 0, text
);
303 WARN("Messagebox\n");
305 ret
= MessageBoxA( hwnd
, textA
, titleA
, type
);
306 HeapFree( GetProcessHeap(), 0, titleA
);
307 HeapFree( GetProcessHeap(), 0, textA
);
312 /**************************************************************************
313 * MessageBoxEx32A (USER32.392)
315 INT WINAPI
MessageBoxExA( HWND hWnd
, LPCSTR text
, LPCSTR title
,
316 UINT type
, WORD langid
)
318 WARN("Messagebox\n");
319 /* ignore language id for now */
320 return MessageBoxA(hWnd
,text
,title
,type
);
323 /**************************************************************************
324 * MessageBoxEx32W (USER32.393)
326 INT WINAPI
MessageBoxExW( HWND hWnd
, LPCWSTR text
, LPCWSTR title
,
327 UINT type
, WORD langid
)
329 WARN("Messagebox\n");
330 /* ignore language id for now */
331 return MessageBoxW(hWnd
,text
,title
,type
);
334 /**************************************************************************
335 * MessageBoxIndirect16 (USER.827)
337 INT16 WINAPI
MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox
)
341 MSGBOXPARAMSA msgbox32
;
343 WARN("Messagebox\n");
345 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
347 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
350 msgbox32
.cbSize
= msgbox
->cbSize
;
351 msgbox32
.hwndOwner
= msgbox
->hwndOwner
;
352 msgbox32
.hInstance
= msgbox
->hInstance
;
353 msgbox32
.lpszText
= PTR_SEG_TO_LIN(msgbox
->lpszText
);
354 msgbox32
.lpszCaption
= PTR_SEG_TO_LIN(msgbox
->lpszCaption
);
355 msgbox32
.dwStyle
= msgbox
->dwStyle
;
356 msgbox32
.lpszIcon
= PTR_SEG_TO_LIN(msgbox
->lpszIcon
);
357 msgbox32
.dwContextHelpId
= msgbox
->dwContextHelpId
;
358 msgbox32
.lpfnMsgBoxCallback
= msgbox
->lpfnMsgBoxCallback
;
359 msgbox32
.dwLanguageId
= msgbox
->dwLanguageId
;
361 return DialogBoxIndirectParamA( msgbox32
.hInstance
, template,
362 msgbox32
.hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
366 /**************************************************************************
367 * MessageBoxIndirect32A (USER32.394)
369 INT WINAPI
MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox
)
374 WARN("Messagebox\n");
376 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
378 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
381 return DialogBoxIndirectParamA( msgbox
->hInstance
, template,
382 msgbox
->hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
386 /**************************************************************************
387 * MessageBoxIndirect32W (USER32.395)
389 INT WINAPI
MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox
)
391 MSGBOXPARAMSA msgboxa
;
392 WARN("Messagebox\n");
394 memcpy(&msgboxa
,msgbox
,sizeof(msgboxa
));
395 if (msgbox
->lpszCaption
)
396 lstrcpyWtoA((LPSTR
)msgboxa
.lpszCaption
,msgbox
->lpszCaption
);
397 if (msgbox
->lpszText
)
398 lstrcpyWtoA((LPSTR
)msgboxa
.lpszText
,msgbox
->lpszText
);
400 return MessageBoxIndirectA(&msgboxa
);
404 /**************************************************************************
405 * FatalAppExit16 (KERNEL.137)
407 void WINAPI
FatalAppExit16( UINT16 action
, LPCSTR str
)
410 FatalAppExitA( action
, str
);
414 /**************************************************************************
415 * FatalAppExit32A (KERNEL32.108)
417 void WINAPI
FatalAppExitA( UINT action
, LPCSTR str
)
420 MessageBoxA( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);
425 /**************************************************************************
426 * FatalAppExit32W (KERNEL32.109)
428 void WINAPI
FatalAppExitW( UINT action
, LPCWSTR str
)
431 MessageBoxW( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);