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( 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_SETSEL
, TRUE
, MAKELONG( -1, 0 ) );
29 if (SendMessage16( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
30 SendMessage16( hwndCtrl
, EM_SETSEL
, FALSE
, MAKELONG( 0, -1 ) );
35 /***********************************************************************
38 static BOOL
DEFDLG_SaveFocus( HWND hwnd
, DIALOGINFO
*infoPtr
)
40 HWND hwndFocus
= GetFocus();
42 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return FALSE
;
43 if (!infoPtr
->hwndFocus
) return FALSE
; /* Already saved */
44 infoPtr
->hwndFocus
= hwndFocus
;
45 /* Remove default button */
50 /***********************************************************************
53 static BOOL
DEFDLG_RestoreFocus( HWND hwnd
, DIALOGINFO
*infoPtr
)
55 if (!infoPtr
->hwndFocus
|| IsIconic(hwnd
)) return FALSE
;
56 if (!IsWindow( infoPtr
->hwndFocus
)) return FALSE
;
57 DEFDLG_SetFocus( hwnd
, infoPtr
->hwndFocus
);
58 infoPtr
->hwndFocus
= 0;
63 #ifdef SUPERFLUOUS_FUNCTIONS
64 /***********************************************************************
65 * DEFDLG_FindDefButton
67 * Find the current default push-button.
69 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
71 HWND hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
74 if (SendMessage16( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
76 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
83 /***********************************************************************
86 * Set the new default button to be hwndNew.
88 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
,
92 !(SendMessage16(hwndNew
, WM_GETDLGCODE
, 0, 0 ) & DLGC_UNDEFPUSHBUTTON
))
93 return FALSE
; /* Destination is not a push button */
95 if (dlgInfo
->msgResult
) /* There's already a default pushbutton */
97 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->msgResult
);
98 if (SendMessage32A( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
99 SendMessage32A( hwndOld
, BM_SETSTYLE32
, BS_PUSHBUTTON
, TRUE
);
103 SendMessage32A( hwndNew
, BM_SETSTYLE32
, BS_DEFPUSHBUTTON
, TRUE
);
104 dlgInfo
->msgResult
= GetDlgCtrlID( hwndNew
);
106 else dlgInfo
->msgResult
= 0;
111 /***********************************************************************
114 * Implementation of DefDlgProc(). Only handle messages that need special
115 * handling for dialogs.
117 static LRESULT
DEFDLG_Proc( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
118 LPARAM lParam
, DIALOGINFO
*dlgInfo
)
126 FillWindow( hwnd
, hwnd
, (HDC
)wParam
, (HBRUSH
)CTLCOLOR_DLG
);
131 /* Free dialog heap (if created) */
132 if (dlgInfo
->hDialogHeap
)
134 GlobalUnlock16(dlgInfo
->hDialogHeap
);
135 GlobalFree16(dlgInfo
->hDialogHeap
);
136 dlgInfo
->hDialogHeap
= 0;
140 if (dlgInfo
->hUserFont
)
142 DeleteObject( dlgInfo
->hUserFont
);
143 dlgInfo
->hUserFont
= 0;
149 DestroyMenu( dlgInfo
->hMenu
);
153 /* Delete window procedure */
154 if (dlgInfo
->dlgProc
)
156 WINPROC_FreeWinProc( dlgInfo
->dlgProc
);
157 dlgInfo
->dlgProc
= 0;
160 /* Window clean-up */
161 return DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);
164 if (!wParam
) DEFDLG_SaveFocus( hwnd
, dlgInfo
);
165 return DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);
168 if (wParam
) DEFDLG_RestoreFocus( hwnd
, dlgInfo
);
169 else DEFDLG_SaveFocus( hwnd
, dlgInfo
);
173 DEFDLG_RestoreFocus( hwnd
, dlgInfo
);
177 if (dlgInfo
->fEnd
) return 1;
178 DEFDLG_SetDefButton( hwnd
, dlgInfo
,
179 wParam
? GetDlgItem( hwnd
, wParam
) : 0 );
183 if (dlgInfo
->fEnd
|| !dlgInfo
->msgResult
) return 0;
184 return MAKELONG( dlgInfo
->msgResult
, DC_HASDEFID
);
188 HWND hwndDest
= (HWND
)wParam
;
191 HWND hwndPrev
= GetFocus();
192 if (!hwndPrev
) /* Set focus to the first item */
193 hwndDest
= DIALOG_GetFirstTabItem( hwnd
);
195 hwndDest
= GetNextDlgTabItem( hwnd
, hwndPrev
, wParam
);
197 if (hwndDest
) DEFDLG_SetFocus( hwnd
, hwndDest
);
198 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
203 EndDialog( hwnd
, TRUE
);
204 DestroyWindow( hwnd
);
211 /***********************************************************************
212 * DefDlgProc16 (USER.308)
214 LRESULT
DefDlgProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
216 DIALOGINFO
* dlgInfo
;
217 BOOL16 result
= FALSE
;
218 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
220 if (!wndPtr
) return 0;
221 dlgInfo
= (DIALOGINFO
*)&wndPtr
->wExtra
;
223 dlgInfo
->msgResult
= 0;
224 if (dlgInfo
->dlgProc
)
226 /* Call dialog procedure */
227 result
= (BOOL16
)CallWindowProc16( (WNDPROC16
)dlgInfo
->dlgProc
, hwnd
,
228 msg
, wParam
, lParam
);
230 /* Check if window was destroyed by dialog procedure */
231 if (result
|| !IsWindow( hwnd
)) return result
;
246 return DEFDLG_Proc( (HWND32
)hwnd
, msg
, (WPARAM32
)wParam
,
250 return DefWindowProc16( hwnd
, msg
, wParam
, lParam
);
255 /***********************************************************************
256 * DefDlgProc32A (USER32.119)
258 LRESULT
DefDlgProc32A( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
260 DIALOGINFO
* dlgInfo
;
261 BOOL16 result
= FALSE
;
262 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
264 if (!wndPtr
) return 0;
265 dlgInfo
= (DIALOGINFO
*)&wndPtr
->wExtra
;
267 dlgInfo
->msgResult
= 0;
268 if (dlgInfo
->dlgProc
)
270 /* Call dialog procedure */
271 result
= (BOOL16
)CallWindowProc32A( (WNDPROC32
)dlgInfo
->dlgProc
, hwnd
,
272 msg
, wParam
, lParam
);
274 /* Check if window was destroyed by dialog procedure */
275 if (result
|| !IsWindow( hwnd
)) return result
;
290 return DEFDLG_Proc( hwnd
, msg
, wParam
, lParam
, dlgInfo
);
293 return DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);
298 /***********************************************************************
299 * DefDlgProc32W (USER32.120)
301 LRESULT
DefDlgProc32W( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
303 DIALOGINFO
* dlgInfo
;
304 BOOL16 result
= FALSE
;
305 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
307 if (!wndPtr
) return 0;
308 dlgInfo
= (DIALOGINFO
*)&wndPtr
->wExtra
;
310 dlgInfo
->msgResult
= 0;
311 if (dlgInfo
->dlgProc
)
313 /* Call dialog procedure */
314 result
= (BOOL16
)CallWindowProc32W( (WNDPROC32
)dlgInfo
->dlgProc
, hwnd
,
315 msg
, wParam
, lParam
);
317 /* Check if window was destroyed by dialog procedure */
318 if (result
|| !IsWindow( hwnd
)) return result
;
333 return DEFDLG_Proc( hwnd
, msg
, wParam
, lParam
, dlgInfo
);
336 return DefWindowProc32W( hwnd
, msg
, wParam
, lParam
);