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 /**************************************************************************
23 * Dialog procedure for message boxes.
25 static LRESULT CALLBACK
MSGBOX_DlgProc( HWND hwnd
, UINT message
,
26 WPARAM wParam
, LPARAM lParam
)
28 static HFONT hFont
= 0;
35 int i
, buttons
, bwidth
, bheight
, theight
, wwidth
, bpos
;
36 int borheight
, iheight
, tiheight
;
40 lpmb
= (LPMSGBOXPARAMSA
)lParam
;
41 if (TWEAK_WineLook
>= WIN95_LOOK
) {
42 NONCLIENTMETRICSA nclm
;
44 nclm
.cbSize
= sizeof(NONCLIENTMETRICSA
);
45 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
46 hFont
= CreateFontIndirectA (&nclm
.lfMessageFont
);
49 SendDlgItemMessageA (hwnd
, i
, WM_SETFONT
, (WPARAM
)hFont
, 0);
51 SendDlgItemMessageA (hwnd
, 100, WM_SETFONT
, (WPARAM
)hFont
, 0);
53 if (lpmb
->lpszCaption
) SetWindowTextA(hwnd
, lpmb
->lpszCaption
);
54 SetWindowTextA(GetDlgItem(hwnd
, 100), lpmb
->lpszText
);
55 /* Hide not selected buttons */
56 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
58 ShowWindow(GetDlgItem(hwnd
, 2), SW_HIDE
);
61 ShowWindow(GetDlgItem(hwnd
, 3), SW_HIDE
);
62 ShowWindow(GetDlgItem(hwnd
, 4), SW_HIDE
);
63 ShowWindow(GetDlgItem(hwnd
, 5), SW_HIDE
);
64 ShowWindow(GetDlgItem(hwnd
, 6), SW_HIDE
);
65 ShowWindow(GetDlgItem(hwnd
, 7), SW_HIDE
);
67 case MB_ABORTRETRYIGNORE
:
68 ShowWindow(GetDlgItem(hwnd
, 1), SW_HIDE
);
69 ShowWindow(GetDlgItem(hwnd
, 2), SW_HIDE
);
70 ShowWindow(GetDlgItem(hwnd
, 6), SW_HIDE
);
71 ShowWindow(GetDlgItem(hwnd
, 7), SW_HIDE
);
74 ShowWindow(GetDlgItem(hwnd
, 2), SW_HIDE
);
77 ShowWindow(GetDlgItem(hwnd
, 1), SW_HIDE
);
78 ShowWindow(GetDlgItem(hwnd
, 3), SW_HIDE
);
79 ShowWindow(GetDlgItem(hwnd
, 4), SW_HIDE
);
80 ShowWindow(GetDlgItem(hwnd
, 5), SW_HIDE
);
84 switch(lpmb
->dwStyle
& MB_ICONMASK
) {
85 case MB_ICONEXCLAMATION
:
86 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
87 (WPARAM16
)LoadIcon16(0, IDI_EXCLAMATION16
), 0);
90 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
91 (WPARAM16
)LoadIcon16(0, IDI_QUESTION16
), 0);
94 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
95 (WPARAM16
)LoadIcon16(0, IDI_ASTERISK16
), 0);
99 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
100 (WPARAM16
)LoadIcon16(0, IDI_HAND16
), 0);
104 /* Position everything */
105 GetWindowRect(hwnd
, &rect
);
106 borheight
= rect
.bottom
- rect
.top
;
107 wwidth
= rect
.right
- rect
.left
;
108 GetClientRect(hwnd
, &rect
);
109 borheight
-= rect
.bottom
- rect
.top
;
111 /* Get the icon height */
112 GetWindowRect(GetDlgItem(hwnd
, 1088), &rect
);
113 iheight
= rect
.bottom
- rect
.top
;
115 /* Get the number of visible buttons and their width */
116 GetWindowRect(GetDlgItem(hwnd
, 2), &rect
);
117 bheight
= rect
.bottom
- rect
.top
;
119 GetWindowRect(GetDlgItem(hwnd
, 1), &rect
);
121 for (buttons
= 0, i
= 1; i
< 8; i
++)
123 hItem
= GetDlgItem(hwnd
, i
);
124 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
) buttons
++;
127 /* Get the text size */
128 hItem
= GetDlgItem(hwnd
, 100);
129 GetWindowRect(hItem
, &textrect
);
130 MapWindowPoints(0, hwnd
, (LPPOINT
)&textrect
, 2);
132 GetClientRect(hItem
, &rect
);
134 lRet
= DrawTextA( hdc
, lpmb
->lpszText
, -1, &rect
,
135 DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_CALCRECT
);
136 theight
= rect
.bottom
- rect
.top
;
137 tiheight
= 16 + MAX(iheight
, theight
);
138 ReleaseDC(hItem
, hdc
);
140 /* Position the text */
141 SetWindowPos(hItem
, 0, textrect
.left
, (tiheight
- theight
) / 2,
142 rect
.right
- rect
.left
, theight
,
143 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
145 /* Position the icon */
146 hItem
= GetDlgItem(hwnd
, 1088);
147 GetWindowRect(hItem
, &rect
);
148 MapWindowPoints(0, hwnd
, (LPPOINT
)&rect
, 2);
149 SetWindowPos(hItem
, 0, rect
.left
, (tiheight
- iheight
) / 2, 0, 0,
150 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
152 /* Resize the window */
153 SetWindowPos(hwnd
, 0, 0, 0, wwidth
, 8 + tiheight
+ bheight
+ borheight
,
154 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
156 /* Position the buttons */
157 bpos
= (wwidth
- bwidth
* buttons
) / 2;
158 GetWindowRect(GetDlgItem(hwnd
, 1), &rect
);
159 for (buttons
= i
= 0; i
< 7; i
++) {
160 /* some arithmetic to get the right order for YesNoCancel windows */
161 hItem
= GetDlgItem(hwnd
, (i
+ 5) % 7 + 1);
162 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
163 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
165 SendMessageA( hItem
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
167 SetWindowPos(hItem
, 0, bpos
, tiheight
, 0, 0,
168 SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
185 if ((TWEAK_WineLook
> WIN31_LOOK
) && hFont
)
186 DeleteObject (hFont
);
187 EndDialog(hwnd
, wParam
);
192 /* Ok. Ignore all the other messages */
193 TRACE("Message number %i is being ignored.\n", message
);
200 /**************************************************************************
201 * MessageBox16 (USER.1)
203 INT16 WINAPI
MessageBox16( HWND16 hwnd
, LPCSTR text
, LPCSTR title
, UINT16 type
)
205 WARN("Messagebox\n");
206 return MessageBoxA( hwnd
, text
, title
, type
);
210 /**************************************************************************
211 * MessageBox32A (USER32.391)
214 * The WARN is here to help debug erroneous MessageBoxes
215 * Use: -debugmsg warn+dialog,+relay
217 INT WINAPI
MessageBoxA(HWND hWnd
, LPCSTR text
, LPCSTR title
, UINT type
)
223 WARN("Messagebox\n");
225 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
227 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
230 if (!text
) text
="<WINE-NULL>";
233 mbox
.lpszCaption
= title
;
234 mbox
.lpszText
= text
;
236 return DialogBoxIndirectParamA( GetWindowLongA(hWnd
,GWL_HINSTANCE
), template,
237 hWnd
, (DLGPROC
)MSGBOX_DlgProc
, (LPARAM
)&mbox
);
241 /**************************************************************************
242 * MessageBox32W (USER32.396)
244 INT WINAPI
MessageBoxW( HWND hwnd
, LPCWSTR text
, LPCWSTR title
,
247 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
248 LPSTR textA
= HEAP_strdupWtoA( GetProcessHeap(), 0, text
);
251 WARN("Messagebox\n");
253 ret
= MessageBoxA( hwnd
, textA
, titleA
, type
);
254 HeapFree( GetProcessHeap(), 0, titleA
);
255 HeapFree( GetProcessHeap(), 0, textA
);
260 /**************************************************************************
261 * MessageBoxEx32A (USER32.392)
263 INT WINAPI
MessageBoxExA( HWND hWnd
, LPCSTR text
, LPCSTR title
,
264 UINT type
, WORD langid
)
266 WARN("Messagebox\n");
267 /* ignore language id for now */
268 return MessageBoxA(hWnd
,text
,title
,type
);
271 /**************************************************************************
272 * MessageBoxEx32W (USER32.393)
274 INT WINAPI
MessageBoxExW( HWND hWnd
, LPCWSTR text
, LPCWSTR title
,
275 UINT type
, WORD langid
)
277 WARN("Messagebox\n");
278 /* ignore language id for now */
279 return MessageBoxW(hWnd
,text
,title
,type
);
282 /**************************************************************************
283 * MessageBoxIndirect16 (USER.827)
285 INT16 WINAPI
MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox
)
289 MSGBOXPARAMSA msgbox32
;
291 WARN("Messagebox\n");
293 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
295 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
298 msgbox32
.cbSize
= msgbox
->cbSize
;
299 msgbox32
.hwndOwner
= msgbox
->hwndOwner
;
300 msgbox32
.hInstance
= msgbox
->hInstance
;
301 msgbox32
.lpszText
= PTR_SEG_TO_LIN(msgbox
->lpszText
);
302 msgbox32
.lpszCaption
= PTR_SEG_TO_LIN(msgbox
->lpszCaption
);
303 msgbox32
.dwStyle
= msgbox
->dwStyle
;
304 msgbox32
.lpszIcon
= PTR_SEG_TO_LIN(msgbox
->lpszIcon
);
305 msgbox32
.dwContextHelpId
= msgbox
->dwContextHelpId
;
306 msgbox32
.lpfnMsgBoxCallback
= msgbox
->lpfnMsgBoxCallback
;
307 msgbox32
.dwLanguageId
= msgbox
->dwLanguageId
;
309 return DialogBoxIndirectParamA( msgbox32
.hInstance
, template,
310 msgbox32
.hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
314 /**************************************************************************
315 * MessageBoxIndirect32A (USER32.394)
317 INT WINAPI
MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox
)
322 WARN("Messagebox\n");
324 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
326 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
329 return DialogBoxIndirectParamA( msgbox
->hInstance
, template,
330 msgbox
->hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
334 /**************************************************************************
335 * MessageBoxIndirect32W (USER32.395)
337 INT WINAPI
MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox
)
339 MSGBOXPARAMSA msgboxa
;
340 WARN("Messagebox\n");
342 memcpy(&msgboxa
,msgbox
,sizeof(msgboxa
));
343 if (msgbox
->lpszCaption
)
344 lstrcpyWtoA((LPSTR
)msgboxa
.lpszCaption
,msgbox
->lpszCaption
);
345 if (msgbox
->lpszText
)
346 lstrcpyWtoA((LPSTR
)msgboxa
.lpszText
,msgbox
->lpszText
);
348 return MessageBoxIndirectA(&msgboxa
);
352 /**************************************************************************
353 * FatalAppExit16 (KERNEL.137)
355 void WINAPI
FatalAppExit16( UINT16 action
, LPCSTR str
)
358 FatalAppExitA( action
, str
);
362 /**************************************************************************
363 * FatalAppExit32A (KERNEL32.108)
365 void WINAPI
FatalAppExitA( UINT action
, LPCSTR str
)
368 MessageBoxA( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);
373 /**************************************************************************
374 * FatalAppExit32W (KERNEL32.109)
376 void WINAPI
FatalAppExitW( UINT action
, LPCWSTR str
)
379 MessageBoxW( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);