Handle suspend/resume_thread requests in phase STARTING correctly.
[wine/hacks.git] / windows / defdlg.c
blob95052cbccdc4254aa0d654c2c1eb8827a2bbb809
1 /*
2 * Default dialog procedure
4 * Copyright 1993, 1996 Alexandre Julliard
6 */
8 #include "wine/winuser16.h"
9 #include "dialog.h"
10 #include "win.h"
11 #include "winproc.h"
14 /***********************************************************************
15 * DEFDLG_SetFocus
17 * Set the focus to a control of the dialog, selecting the text if
18 * the control is an edit dialog.
20 static void DEFDLG_SetFocus( HWND hwndDlg, HWND hwndCtrl )
22 HWND hwndPrev = GetFocus();
24 if (IsChild( hwndDlg, hwndPrev ))
26 if (SendMessage16( hwndPrev, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
27 SendMessage16( hwndPrev, EM_SETSEL16, TRUE, MAKELONG( -1, 0 ) );
29 if (SendMessage16( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
30 SendMessage16( hwndCtrl, EM_SETSEL16, FALSE, MAKELONG( 0, -1 ) );
31 SetFocus( hwndCtrl );
35 /***********************************************************************
36 * DEFDLG_SaveFocus
38 static BOOL DEFDLG_SaveFocus( HWND hwnd, DIALOGINFO *infoPtr )
40 HWND hwndFocus = GetFocus();
42 if (!hwndFocus || !IsChild( hwnd, hwndFocus )) return FALSE;
43 infoPtr->hwndFocus = hwndFocus;
44 /* Remove default button */
45 return TRUE;
49 /***********************************************************************
50 * DEFDLG_RestoreFocus
52 static BOOL DEFDLG_RestoreFocus( HWND hwnd, DIALOGINFO *infoPtr )
54 if (!infoPtr->hwndFocus || IsIconic(hwnd)) return FALSE;
55 if (!IsWindow( infoPtr->hwndFocus )) return FALSE;
56 DEFDLG_SetFocus( hwnd, infoPtr->hwndFocus );
57 /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
58 sometimes losing focus when receiving WM_SETFOCUS messages. */
59 return TRUE;
63 /***********************************************************************
64 * DEFDLG_FindDefButton
66 * Find the current default push-button.
68 static HWND DEFDLG_FindDefButton( HWND hwndDlg )
70 HWND hwndChild = GetWindow( hwndDlg, GW_CHILD );
71 while (hwndChild)
73 if (SendMessage16( hwndChild, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
74 break;
75 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
77 return hwndChild;
81 /***********************************************************************
82 * DEFDLG_SetDefButton
84 * Set the new default button to be hwndNew.
86 static BOOL DEFDLG_SetDefButton( HWND hwndDlg, DIALOGINFO *dlgInfo,
87 HWND hwndNew )
89 if (hwndNew &&
90 !(SendMessage16(hwndNew, WM_GETDLGCODE, 0, 0 ) & DLGC_UNDEFPUSHBUTTON))
91 return FALSE; /* Destination is not a push button */
93 if (dlgInfo->idResult) /* There's already a default pushbutton */
95 HWND hwndOld = GetDlgItem( hwndDlg, dlgInfo->idResult );
96 if (SendMessageA( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
97 SendMessageA( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
99 if (hwndNew)
101 SendMessageA( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
102 dlgInfo->idResult = GetDlgCtrlID( hwndNew );
104 else dlgInfo->idResult = 0;
105 return TRUE;
109 /***********************************************************************
110 * DEFDLG_Proc
112 * Implementation of DefDlgProc(). Only handle messages that need special
113 * handling for dialogs.
115 static LRESULT DEFDLG_Proc( HWND hwnd, UINT msg, WPARAM wParam,
116 LPARAM lParam, DIALOGINFO *dlgInfo )
118 switch(msg)
120 case WM_ERASEBKGND:
121 FillWindow16( hwnd, hwnd, (HDC16)wParam, (HBRUSH16)CTLCOLOR_DLG );
122 return 1;
124 case WM_NCDESTROY:
126 /* Free dialog heap (if created) */
127 if (dlgInfo->hDialogHeap)
129 GlobalUnlock16(dlgInfo->hDialogHeap);
130 GlobalFree16(dlgInfo->hDialogHeap);
131 dlgInfo->hDialogHeap = 0;
134 /* Delete font */
135 if (dlgInfo->hUserFont)
137 DeleteObject( dlgInfo->hUserFont );
138 dlgInfo->hUserFont = 0;
141 /* Delete menu */
142 if (dlgInfo->hMenu)
144 DestroyMenu( dlgInfo->hMenu );
145 dlgInfo->hMenu = 0;
148 /* Delete window procedure */
149 WINPROC_FreeProc( dlgInfo->dlgProc, WIN_PROC_WINDOW );
150 dlgInfo->dlgProc = (HWINDOWPROC)0;
151 dlgInfo->flags |= DF_END; /* just in case */
153 /* Window clean-up */
154 return DefWindowProcA( hwnd, msg, wParam, lParam );
156 case WM_SHOWWINDOW:
157 if (!wParam) DEFDLG_SaveFocus( hwnd, dlgInfo );
158 return DefWindowProcA( hwnd, msg, wParam, lParam );
160 case WM_ACTIVATE:
161 if (wParam) DEFDLG_RestoreFocus( hwnd, dlgInfo );
162 else DEFDLG_SaveFocus( hwnd, dlgInfo );
163 return 0;
165 case WM_SETFOCUS:
166 DEFDLG_RestoreFocus( hwnd, dlgInfo );
167 return 0;
169 case DM_SETDEFID:
170 if (dlgInfo->flags & DF_END) return 1;
171 DEFDLG_SetDefButton( hwnd, dlgInfo,
172 wParam ? GetDlgItem( hwnd, wParam ) : 0 );
173 return 1;
175 case DM_GETDEFID:
177 HWND hwndDefId;
178 if (dlgInfo->flags & DF_END) return 0;
179 if (dlgInfo->idResult)
180 return MAKELONG( dlgInfo->idResult, DC_HASDEFID );
181 if ((hwndDefId = DEFDLG_FindDefButton( hwnd )))
182 return MAKELONG( GetDlgCtrlID( hwndDefId ), DC_HASDEFID);
184 return 0;
186 case WM_NEXTDLGCTL:
188 HWND hwndDest = (HWND)wParam;
189 if (!lParam)
190 hwndDest = GetNextDlgTabItem(hwnd, GetFocus(), wParam);
191 if (hwndDest) DEFDLG_SetFocus( hwnd, hwndDest );
192 DEFDLG_SetDefButton( hwnd, dlgInfo, hwndDest );
194 return 0;
196 case WM_ENTERMENULOOP:
197 case WM_LBUTTONDOWN:
198 case WM_NCLBUTTONDOWN:
200 HWND hwndFocus = GetFocus();
201 if (hwndFocus)
203 WND *wnd = WIN_FindWndPtr( hwndFocus );
205 if( wnd )
207 /* always make combo box hide its listbox control */
209 if( WIDGETS_IsControl( wnd, BIC32_COMBO ) )
210 SendMessageA( hwndFocus, CB_SHOWDROPDOWN,
211 FALSE, 0 );
212 else if( WIDGETS_IsControl( wnd, BIC32_EDIT ) &&
213 WIDGETS_IsControl( wnd->parent,
214 BIC32_COMBO ))
215 SendMessageA( wnd->parent->hwndSelf,
216 CB_SHOWDROPDOWN, FALSE, 0 );
218 WIN_ReleaseWndPtr(wnd);
221 return DefWindowProcA( hwnd, msg, wParam, lParam );
223 case WM_GETFONT:
224 return dlgInfo->hUserFont;
226 case WM_CLOSE:
227 PostMessageA( hwnd, WM_COMMAND, IDCANCEL,
228 (LPARAM)GetDlgItem( hwnd, IDCANCEL ) );
229 return 0;
231 return 0;
234 /***********************************************************************
235 * DEFDLG_Epilog
237 static LRESULT DEFDLG_Epilog(DIALOGINFO* dlgInfo, UINT msg, BOOL fResult)
239 /* see SDK 3.1 */
241 if ((msg >= WM_CTLCOLORMSGBOX && msg <= WM_CTLCOLORSTATIC) ||
242 msg == WM_CTLCOLOR || msg == WM_COMPAREITEM ||
243 msg == WM_VKEYTOITEM || msg == WM_CHARTOITEM ||
244 msg == WM_QUERYDRAGICON || msg == WM_INITDIALOG)
245 return fResult;
247 return dlgInfo->msgResult;
250 /***********************************************************************
251 * DefDlgProc16 (USER.308)
253 LRESULT WINAPI DefDlgProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
254 LPARAM lParam )
256 DIALOGINFO * dlgInfo;
257 BOOL result = FALSE;
258 WND * wndPtr = WIN_FindWndPtr( hwnd );
260 if (!wndPtr) return 0;
261 dlgInfo = (DIALOGINFO *)&wndPtr->wExtra;
262 dlgInfo->msgResult = 0;
264 if (dlgInfo->dlgProc) { /* Call dialog procedure */
265 result = CallWindowProc16( (WNDPROC16)dlgInfo->dlgProc,
266 hwnd, msg, wParam, lParam );
267 /* 16 bit dlg procs only return BOOL16 */
268 if( WINPROC_GetProcType( dlgInfo->dlgProc ) == WIN_PROC_16 )
269 result = LOWORD(result);
272 if (!result && IsWindow(hwnd))
274 /* callback didn't process this message */
276 switch(msg)
278 case WM_ERASEBKGND:
279 case WM_SHOWWINDOW:
280 case WM_ACTIVATE:
281 case WM_SETFOCUS:
282 case DM_SETDEFID:
283 case DM_GETDEFID:
284 case WM_NEXTDLGCTL:
285 case WM_GETFONT:
286 case WM_CLOSE:
287 case WM_NCDESTROY:
288 case WM_ENTERMENULOOP:
289 case WM_LBUTTONDOWN:
290 case WM_NCLBUTTONDOWN:
291 WIN_ReleaseWndPtr(wndPtr);
292 return DEFDLG_Proc( (HWND)hwnd, msg,
293 (WPARAM)wParam, lParam, dlgInfo );
294 case WM_INITDIALOG:
295 case WM_VKEYTOITEM:
296 case WM_COMPAREITEM:
297 case WM_CHARTOITEM:
298 break;
300 default:
301 WIN_ReleaseWndPtr(wndPtr);
302 return DefWindowProc16( hwnd, msg, wParam, lParam );
305 WIN_ReleaseWndPtr(wndPtr);
306 return DEFDLG_Epilog(dlgInfo, msg, result);
310 /***********************************************************************
311 * DefDlgProc32A (USER32.120)
313 LRESULT WINAPI DefDlgProcA( HWND hwnd, UINT msg,
314 WPARAM wParam, LPARAM lParam )
316 DIALOGINFO * dlgInfo;
317 BOOL result = FALSE;
318 WND * wndPtr = WIN_FindWndPtr( hwnd );
320 if (!wndPtr) return 0;
321 dlgInfo = (DIALOGINFO *)&wndPtr->wExtra;
322 dlgInfo->msgResult = 0;
324 if (dlgInfo->dlgProc) { /* Call dialog procedure */
325 result = CallWindowProcA( (WNDPROC)dlgInfo->dlgProc,
326 hwnd, msg, wParam, lParam );
327 /* 16 bit dlg procs only return BOOL16 */
328 if( WINPROC_GetProcType( dlgInfo->dlgProc ) == WIN_PROC_16 )
329 result = LOWORD(result);
332 if (!result && IsWindow(hwnd))
334 /* callback didn't process this message */
336 switch(msg)
338 case WM_ERASEBKGND:
339 case WM_SHOWWINDOW:
340 case WM_ACTIVATE:
341 case WM_SETFOCUS:
342 case DM_SETDEFID:
343 case DM_GETDEFID:
344 case WM_NEXTDLGCTL:
345 case WM_GETFONT:
346 case WM_CLOSE:
347 case WM_NCDESTROY:
348 case WM_ENTERMENULOOP:
349 case WM_LBUTTONDOWN:
350 case WM_NCLBUTTONDOWN:
351 WIN_ReleaseWndPtr(wndPtr);
352 return DEFDLG_Proc( (HWND)hwnd, msg,
353 (WPARAM)wParam, lParam, dlgInfo );
354 case WM_INITDIALOG:
355 case WM_VKEYTOITEM:
356 case WM_COMPAREITEM:
357 case WM_CHARTOITEM:
358 break;
360 default:
361 WIN_ReleaseWndPtr(wndPtr);
362 return DefWindowProcA( hwnd, msg, wParam, lParam );
365 WIN_ReleaseWndPtr(wndPtr);
366 return DEFDLG_Epilog(dlgInfo, msg, result);
370 /***********************************************************************
371 * DefDlgProc32W (USER32.121)
373 LRESULT WINAPI DefDlgProcW( HWND hwnd, UINT msg, WPARAM wParam,
374 LPARAM lParam )
376 DIALOGINFO * dlgInfo;
377 BOOL result = FALSE;
378 WND * wndPtr = WIN_FindWndPtr( hwnd );
380 if (!wndPtr) return 0;
381 dlgInfo = (DIALOGINFO *)&wndPtr->wExtra;
382 dlgInfo->msgResult = 0;
384 if (dlgInfo->dlgProc) { /* Call dialog procedure */
385 result = CallWindowProcW( (WNDPROC)dlgInfo->dlgProc,
386 hwnd, msg, wParam, lParam );
387 /* 16 bit dlg procs only return BOOL16 */
388 if( WINPROC_GetProcType( dlgInfo->dlgProc ) == WIN_PROC_16 )
389 result = LOWORD(result);
392 if (!result && IsWindow(hwnd))
394 /* callback didn't process this message */
396 switch(msg)
398 case WM_ERASEBKGND:
399 case WM_SHOWWINDOW:
400 case WM_ACTIVATE:
401 case WM_SETFOCUS:
402 case DM_SETDEFID:
403 case DM_GETDEFID:
404 case WM_NEXTDLGCTL:
405 case WM_GETFONT:
406 case WM_CLOSE:
407 case WM_NCDESTROY:
408 case WM_ENTERMENULOOP:
409 case WM_LBUTTONDOWN:
410 case WM_NCLBUTTONDOWN:
411 WIN_ReleaseWndPtr(wndPtr);
412 return DEFDLG_Proc( (HWND)hwnd, msg,
413 (WPARAM)wParam, lParam, dlgInfo );
414 case WM_INITDIALOG:
415 case WM_VKEYTOITEM:
416 case WM_COMPAREITEM:
417 case WM_CHARTOITEM:
418 break;
420 default:
421 WIN_ReleaseWndPtr(wndPtr);
422 return DefWindowProcW( hwnd, msg, wParam, lParam );
425 WIN_ReleaseWndPtr(wndPtr);
426 return DEFDLG_Epilog(dlgInfo, msg, result);