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 HWND32 hwndPrev
= GetFocus32();
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 ) );
31 SetFocus32( hwndCtrl
);
35 /***********************************************************************
38 static BOOL
DEFDLG_SaveFocus( HWND hwnd
, DIALOGINFO
*infoPtr
)
40 HWND32 hwndFocus
= GetFocus32();
42 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return FALSE
;
43 infoPtr
->hwndFocus
= hwndFocus
;
44 /* Remove default button */
49 /***********************************************************************
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 infoPtr
->hwndFocus
= 0;
62 /***********************************************************************
63 * DEFDLG_FindDefButton
65 * Find the current default push-button.
67 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
69 HWND hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
72 if (SendMessage16( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
74 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
80 /***********************************************************************
83 * Set the new default button to be hwndNew.
85 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
,
89 !(SendMessage16(hwndNew
, WM_GETDLGCODE
, 0, 0 ) & DLGC_UNDEFPUSHBUTTON
))
90 return FALSE
; /* Destination is not a push button */
92 if (dlgInfo
->msgResult
) /* There's already a default pushbutton */
94 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->msgResult
);
95 if (SendMessage32A( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
96 SendMessage32A( hwndOld
, BM_SETSTYLE32
, BS_PUSHBUTTON
, TRUE
);
100 SendMessage32A( hwndNew
, BM_SETSTYLE32
, BS_DEFPUSHBUTTON
, TRUE
);
101 dlgInfo
->msgResult
= GetDlgCtrlID( hwndNew
);
103 else dlgInfo
->msgResult
= 0;
108 /***********************************************************************
111 * Implementation of DefDlgProc(). Only handle messages that need special
112 * handling for dialogs.
114 static LRESULT
DEFDLG_Proc( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
115 LPARAM lParam
, DIALOGINFO
*dlgInfo
)
125 FillWindow( hwnd
, hwnd
, (HDC16
)wParam
, (HBRUSH16
)CTLCOLOR_DLG
);
130 /* Free dialog heap (if created) */
131 if (dlgInfo
->hDialogHeap
)
133 GlobalUnlock16(dlgInfo
->hDialogHeap
);
134 GlobalFree16(dlgInfo
->hDialogHeap
);
135 dlgInfo
->hDialogHeap
= 0;
139 if (dlgInfo
->hUserFont
)
141 DeleteObject( dlgInfo
->hUserFont
);
142 dlgInfo
->hUserFont
= 0;
148 DestroyMenu( dlgInfo
->hMenu
);
152 /* Delete window procedure */
153 WINPROC_FreeProc( dlgInfo
->dlgProc
);
154 dlgInfo
->dlgProc
= (HWINDOWPROC
)0;
156 /* Window clean-up */
157 return DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);
160 if (!wParam
) DEFDLG_SaveFocus( hwnd
, dlgInfo
);
161 return DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);
164 if (wParam
) DEFDLG_RestoreFocus( hwnd
, dlgInfo
);
165 else DEFDLG_SaveFocus( hwnd
, dlgInfo
);
169 DEFDLG_RestoreFocus( hwnd
, dlgInfo
);
173 if (dlgInfo
->fEnd
) return 1;
174 DEFDLG_SetDefButton( hwnd
, dlgInfo
,
175 wParam
? GetDlgItem( hwnd
, wParam
) : 0 );
179 if (dlgInfo
->fEnd
) return 0;
180 if (dlgInfo
->msgResult
)
181 return MAKELONG( dlgInfo
->msgResult
, DC_HASDEFID
);
182 hwndDefId
= DEFDLG_FindDefButton( hwnd
);
184 return MAKELONG( GetDlgCtrlID( hwndDefId
), DC_HASDEFID
);
189 HWND hwndDest
= (HWND
)wParam
;
191 hwndDest
= GetNextDlgTabItem32(hwnd
, GetFocus32(), wParam
);
192 if (hwndDest
) DEFDLG_SetFocus( hwnd
, hwndDest
);
193 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
198 EndDialog( hwnd
, TRUE
);
199 DestroyWindow( hwnd
);
206 /***********************************************************************
207 * DefDlgProc16 (USER.308)
209 LRESULT
DefDlgProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
211 DIALOGINFO
* dlgInfo
;
212 BOOL16 result
= FALSE
;
213 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
215 if (!wndPtr
) return 0;
216 dlgInfo
= (DIALOGINFO
*)&wndPtr
->wExtra
;
218 dlgInfo
->msgResult
= 0;
219 if (dlgInfo
->dlgProc
)
221 /* Call dialog procedure */
222 result
= (BOOL16
)CallWindowProc16( (WNDPROC16
)dlgInfo
->dlgProc
,
223 hwnd
, msg
, wParam
, lParam
);
225 /* Check if window was destroyed by dialog procedure */
226 if (result
|| !IsWindow( hwnd
)) return result
;
241 return DEFDLG_Proc( (HWND32
)hwnd
, msg
, (WPARAM32
)wParam
,
245 return DefWindowProc16( hwnd
, msg
, wParam
, lParam
);
250 /***********************************************************************
251 * DefDlgProc32A (USER32.119)
253 LRESULT
DefDlgProc32A( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
255 DIALOGINFO
* dlgInfo
;
256 BOOL16 result
= FALSE
;
257 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
259 if (!wndPtr
) return 0;
260 dlgInfo
= (DIALOGINFO
*)&wndPtr
->wExtra
;
262 dlgInfo
->msgResult
= 0;
263 if (dlgInfo
->dlgProc
)
265 /* Call dialog procedure */
266 result
= (BOOL16
)CallWindowProc32A( (WNDPROC32
)dlgInfo
->dlgProc
,
267 hwnd
, msg
, wParam
, lParam
);
269 /* Check if window was destroyed by dialog procedure */
270 if (result
|| !IsWindow( hwnd
)) return result
;
285 return DEFDLG_Proc( hwnd
, msg
, wParam
, lParam
, dlgInfo
);
288 return DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);
293 /***********************************************************************
294 * DefDlgProc32W (USER32.120)
296 LRESULT
DefDlgProc32W( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
298 DIALOGINFO
* dlgInfo
;
299 BOOL16 result
= FALSE
;
300 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
302 if (!wndPtr
) return 0;
303 dlgInfo
= (DIALOGINFO
*)&wndPtr
->wExtra
;
305 dlgInfo
->msgResult
= 0;
306 if (dlgInfo
->dlgProc
)
308 /* Call dialog procedure */
309 result
= (BOOL16
)CallWindowProc32W( (WNDPROC32
)dlgInfo
->dlgProc
,
310 hwnd
, msg
, wParam
, lParam
);
312 /* Check if window was destroyed by dialog procedure */
313 if (result
|| !IsWindow( hwnd
)) return result
;
328 return DEFDLG_Proc( hwnd
, msg
, wParam
, lParam
, dlgInfo
);
331 return DefWindowProc32W( hwnd
, msg
, wParam
, lParam
);