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 WINPROC_FreeProc( dlgInfo
->dlgProc
);
155 dlgInfo
->dlgProc
= (HWINDOWPROC
)0;
157 /* Window clean-up */
158 return DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);
161 if (!wParam
) DEFDLG_SaveFocus( hwnd
, dlgInfo
);
162 return DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);
165 if (wParam
) DEFDLG_RestoreFocus( hwnd
, dlgInfo
);
166 else DEFDLG_SaveFocus( hwnd
, dlgInfo
);
170 DEFDLG_RestoreFocus( hwnd
, dlgInfo
);
174 if (dlgInfo
->fEnd
) return 1;
175 DEFDLG_SetDefButton( hwnd
, dlgInfo
,
176 wParam
? GetDlgItem( hwnd
, wParam
) : 0 );
180 if (dlgInfo
->fEnd
|| !dlgInfo
->msgResult
) return 0;
181 return MAKELONG( dlgInfo
->msgResult
, DC_HASDEFID
);
185 HWND hwndDest
= (HWND
)wParam
;
188 HWND hwndPrev
= GetFocus();
189 if (!hwndPrev
) /* Set focus to the first item */
190 hwndDest
= DIALOG_GetFirstTabItem( hwnd
);
192 hwndDest
= GetNextDlgTabItem( hwnd
, hwndPrev
, wParam
);
194 if (hwndDest
) DEFDLG_SetFocus( hwnd
, hwndDest
);
195 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
200 EndDialog( hwnd
, TRUE
);
201 DestroyWindow( hwnd
);
208 /***********************************************************************
209 * DefDlgProc16 (USER.308)
211 LRESULT
DefDlgProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
213 DIALOGINFO
* dlgInfo
;
214 BOOL16 result
= FALSE
;
215 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
217 if (!wndPtr
) return 0;
218 dlgInfo
= (DIALOGINFO
*)&wndPtr
->wExtra
;
220 dlgInfo
->msgResult
= 0;
221 if (dlgInfo
->dlgProc
)
223 /* Call dialog procedure */
224 result
= (BOOL16
)CallWindowProc16( (WNDPROC16
)dlgInfo
->dlgProc
,
225 hwnd
, msg
, wParam
, lParam
);
227 /* Check if window was destroyed by dialog procedure */
228 if (result
|| !IsWindow( hwnd
)) return result
;
243 return DEFDLG_Proc( (HWND32
)hwnd
, msg
, (WPARAM32
)wParam
,
247 return DefWindowProc16( hwnd
, msg
, wParam
, lParam
);
252 /***********************************************************************
253 * DefDlgProc32A (USER32.119)
255 LRESULT
DefDlgProc32A( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
257 DIALOGINFO
* dlgInfo
;
258 BOOL16 result
= FALSE
;
259 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
261 if (!wndPtr
) return 0;
262 dlgInfo
= (DIALOGINFO
*)&wndPtr
->wExtra
;
264 dlgInfo
->msgResult
= 0;
265 if (dlgInfo
->dlgProc
)
267 /* Call dialog procedure */
268 result
= (BOOL16
)CallWindowProc32A( (WNDPROC32
)dlgInfo
->dlgProc
,
269 hwnd
, msg
, wParam
, lParam
);
271 /* Check if window was destroyed by dialog procedure */
272 if (result
|| !IsWindow( hwnd
)) return result
;
287 return DEFDLG_Proc( hwnd
, msg
, wParam
, lParam
, dlgInfo
);
290 return DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);
295 /***********************************************************************
296 * DefDlgProc32W (USER32.120)
298 LRESULT
DefDlgProc32W( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
300 DIALOGINFO
* dlgInfo
;
301 BOOL16 result
= FALSE
;
302 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
304 if (!wndPtr
) return 0;
305 dlgInfo
= (DIALOGINFO
*)&wndPtr
->wExtra
;
307 dlgInfo
->msgResult
= 0;
308 if (dlgInfo
->dlgProc
)
310 /* Call dialog procedure */
311 result
= (BOOL16
)CallWindowProc32W( (WNDPROC32
)dlgInfo
->dlgProc
,
312 hwnd
, msg
, wParam
, lParam
);
314 /* Check if window was destroyed by dialog procedure */
315 if (result
|| !IsWindow( hwnd
)) return result
;
330 return DEFDLG_Proc( hwnd
, msg
, wParam
, lParam
, dlgInfo
);
333 return DefWindowProc32W( hwnd
, msg
, wParam
, lParam
);