2 * Default dialog procedure
4 * Copyright 1993, 1996 Alexandre Julliard
14 /***********************************************************************
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( HWND32 hwndDlg, HWND32 hwndCtrl )
22 HWND32 hwndPrev = GetFocus32();
24 if (IsChild32( 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 SetFocus32( hwndCtrl );
35 /***********************************************************************
38 static BOOL32 DEFDLG_SaveFocus( HWND32 hwnd, DIALOGINFO *infoPtr )
40 HWND32 hwndFocus = GetFocus32();
42 if (!hwndFocus || !IsChild32( hwnd, hwndFocus )) return FALSE;
43 infoPtr->hwndFocus = hwndFocus;
44 /* Remove default button */
49 /***********************************************************************
52 static BOOL32 DEFDLG_RestoreFocus( HWND32 hwnd, DIALOGINFO *infoPtr )
54 if (!infoPtr->hwndFocus || IsIconic32(hwnd)) return FALSE;
55 if (!IsWindow32( 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. */
63 /***********************************************************************
64 * DEFDLG_FindDefButton
66 * Find the current default push-button.
68 static HWND32 DEFDLG_FindDefButton( HWND32 hwndDlg )
70 HWND32 hwndChild = GetWindow32( hwndDlg, GW_CHILD );
73 if (SendMessage16( hwndChild, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
75 hwndChild = GetWindow32( hwndChild, GW_HWNDNEXT );
81 /***********************************************************************
84 * Set the new default button to be hwndNew.
86 static BOOL32 DEFDLG_SetDefButton( HWND32 hwndDlg, DIALOGINFO *dlgInfo,
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 HWND32 hwndOld = GetDlgItem32( hwndDlg, dlgInfo->idResult );
96 if (SendMessage32A( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
97 SendMessage32A( hwndOld, BM_SETSTYLE32, BS_PUSHBUTTON, TRUE );
101 SendMessage32A( hwndNew, BM_SETSTYLE32, BS_DEFPUSHBUTTON, TRUE );
102 dlgInfo->idResult = GetDlgCtrlID32( hwndNew );
104 else dlgInfo->idResult = 0;
109 /***********************************************************************
112 * Implementation of DefDlgProc(). Only handle messages that need special
113 * handling for dialogs.
115 static LRESULT DEFDLG_Proc( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
116 LPARAM lParam, DIALOGINFO *dlgInfo )
121 FillWindow( hwnd, hwnd, (HDC16)wParam, (HBRUSH16)CTLCOLOR_DLG );
126 /* Free dialog heap (if created) */
127 if (dlgInfo->hDialogHeap)
129 GlobalUnlock16(dlgInfo->hDialogHeap);
130 GlobalFree16(dlgInfo->hDialogHeap);
131 dlgInfo->hDialogHeap = 0;
135 if (dlgInfo->hUserFont)
137 DeleteObject32( dlgInfo->hUserFont );
138 dlgInfo->hUserFont = 0;
144 DestroyMenu32( dlgInfo->hMenu );
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 DefWindowProc32A( hwnd, msg, wParam, lParam );
157 if (!wParam) DEFDLG_SaveFocus( hwnd, dlgInfo );
158 return DefWindowProc32A( hwnd, msg, wParam, lParam );
161 if (wParam) DEFDLG_RestoreFocus( hwnd, dlgInfo );
162 else DEFDLG_SaveFocus( hwnd, dlgInfo );
166 DEFDLG_RestoreFocus( hwnd, dlgInfo );
170 if (dlgInfo->flags & DF_END) return 1;
171 DEFDLG_SetDefButton( hwnd, dlgInfo,
172 wParam ? GetDlgItem32( hwnd, wParam ) : 0 );
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( GetDlgCtrlID32( hwndDefId ), DC_HASDEFID);
188 HWND32 hwndDest = (HWND32)wParam;
190 hwndDest = GetNextDlgTabItem32(hwnd, GetFocus32(), wParam);
191 if (hwndDest) DEFDLG_SetFocus( hwnd, hwndDest );
192 DEFDLG_SetDefButton( hwnd, dlgInfo, hwndDest );
196 case WM_ENTERMENULOOP:
198 case WM_NCLBUTTONDOWN:
200 HWND32 hwndFocus = GetFocus32();
203 WND *wnd = WIN_FindWndPtr( hwndFocus );
207 /* always make combo box hide its listbox control */
209 if( WIDGETS_IsControl32( wnd, BIC32_COMBO ) )
210 SendMessage32A( hwndFocus, CB_SHOWDROPDOWN32,
212 else if( WIDGETS_IsControl32( wnd, BIC32_EDIT ) &&
213 WIDGETS_IsControl32( wnd->parent,
215 SendMessage32A( wnd->parent->hwndSelf,
216 CB_SHOWDROPDOWN32, FALSE, 0 );
220 return DefWindowProc32A( hwnd, msg, wParam, lParam );
223 return dlgInfo->hUserFont;
226 EndDialog32( hwnd, TRUE );
227 DestroyWindow32( hwnd );
233 /***********************************************************************
236 static LRESULT DEFDLG_Epilog(DIALOGINFO* dlgInfo, UINT32 msg, BOOL16 fResult)
240 if ((msg >= WM_CTLCOLORMSGBOX && msg <= WM_CTLCOLORSTATIC) ||
241 msg == WM_CTLCOLOR || msg == WM_COMPAREITEM ||
242 msg == WM_VKEYTOITEM || msg == WM_CHARTOITEM ||
243 msg == WM_QUERYDRAGICON || msg == WM_INITDIALOG)
246 return dlgInfo->msgResult;
249 /***********************************************************************
250 * DefDlgProc16 (USER.308)
252 LRESULT WINAPI DefDlgProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
255 DIALOGINFO * dlgInfo;
256 BOOL16 result = FALSE;
257 WND * wndPtr = WIN_FindWndPtr( hwnd );
259 if (!wndPtr) return 0;
260 dlgInfo = (DIALOGINFO *)&wndPtr->wExtra;
261 dlgInfo->msgResult = 0;
263 if (dlgInfo->dlgProc) /* Call dialog procedure */
264 result = (BOOL16)CallWindowProc16( (WNDPROC16)dlgInfo->dlgProc,
265 hwnd, msg, wParam, lParam );
267 /* Check if window was destroyed by dialog procedure */
269 if (!result && IsWindow32(hwnd))
271 /* callback didn't process this message */
285 case WM_ENTERMENULOOP:
287 case WM_NCLBUTTONDOWN:
288 return DEFDLG_Proc( (HWND32)hwnd, msg,
289 (WPARAM32)wParam, lParam, dlgInfo );
297 return DefWindowProc16( hwnd, msg, wParam, lParam );
300 return DEFDLG_Epilog(dlgInfo, msg, result);
304 /***********************************************************************
305 * DefDlgProc32A (USER32.120)
307 LRESULT WINAPI DefDlgProc32A( HWND32 hwnd, UINT32 msg,
308 WPARAM32 wParam, LPARAM lParam )
310 DIALOGINFO * dlgInfo;
311 BOOL16 result = FALSE;
312 WND * wndPtr = WIN_FindWndPtr( hwnd );
314 if (!wndPtr) return 0;
315 dlgInfo = (DIALOGINFO *)&wndPtr->wExtra;
316 dlgInfo->msgResult = 0;
318 if (dlgInfo->dlgProc) /* Call dialog procedure */
319 result = (BOOL16)CallWindowProc32A( (WNDPROC32)dlgInfo->dlgProc,
320 hwnd, msg, wParam, lParam );
322 /* Check if window was destroyed by dialog procedure */
324 if (!result && IsWindow32(hwnd))
326 /* callback didn't process this message */
340 case WM_ENTERMENULOOP:
342 case WM_NCLBUTTONDOWN:
343 return DEFDLG_Proc( (HWND32)hwnd, msg,
344 (WPARAM32)wParam, lParam, dlgInfo );
352 return DefWindowProc32A( hwnd, msg, wParam, lParam );
355 return DEFDLG_Epilog(dlgInfo, msg, result);
359 /***********************************************************************
360 * DefDlgProc32W (USER32.121)
362 LRESULT WINAPI DefDlgProc32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
365 DIALOGINFO * dlgInfo;
366 BOOL16 result = FALSE;
367 WND * wndPtr = WIN_FindWndPtr( hwnd );
369 if (!wndPtr) return 0;
370 dlgInfo = (DIALOGINFO *)&wndPtr->wExtra;
371 dlgInfo->msgResult = 0;
373 if (dlgInfo->dlgProc) /* Call dialog procedure */
374 result = (BOOL16)CallWindowProc32W( (WNDPROC32)dlgInfo->dlgProc,
375 hwnd, msg, wParam, lParam );
377 /* Check if window was destroyed by dialog procedure */
379 if (!result && IsWindow32(hwnd))
381 /* callback didn't process this message */
395 case WM_ENTERMENULOOP:
397 case WM_NCLBUTTONDOWN:
398 return DEFDLG_Proc( (HWND32)hwnd, msg,
399 (WPARAM32)wParam, lParam, dlgInfo );
407 return DefWindowProc32W( hwnd, msg, wParam, lParam );
410 return DEFDLG_Epilog(dlgInfo, msg, result);