2 * Default dialog procedure
4 * Copyright 1993 Alexandre Julliard
6 static char Copyright[] = "Copyright Alexandre Julliard, 1993";
13 /* #define DEBUG_DIALOG */
16 /***********************************************************************
19 * Set the focus to a control of the dialog, selecting the text if
20 * the control is an edit dialog.
22 static void DEFDLG_SetFocus( HWND hwndDlg
, HWND hwndCtrl
)
24 HWND hwndPrev
= GetFocus();
26 if (IsChild( hwndDlg
, hwndPrev
))
28 if (SendMessage( hwndPrev
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
29 SendMessage( hwndPrev
, EM_SETSEL
, TRUE
, MAKELONG( -1, 0 ) );
31 if (SendMessage( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
32 SendMessage( hwndCtrl
, EM_SETSEL
, FALSE
, MAKELONG( 0, -1 ) );
37 /***********************************************************************
40 static BOOL
DEFDLG_SaveFocus( HWND hwnd
, DIALOGINFO
*infoPtr
)
42 HWND hwndFocus
= GetFocus();
44 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return FALSE
;
45 if (!infoPtr
->hwndFocus
) return FALSE
; /* Already saved */
46 infoPtr
->hwndFocus
= hwndFocus
;
47 /* Remove default button */
52 /***********************************************************************
55 static BOOL
DEFDLG_RestoreFocus( HWND hwnd
, DIALOGINFO
*infoPtr
)
57 if (!infoPtr
->hwndFocus
|| IsIconic(hwnd
)) return FALSE
;
58 if (!IsWindow( infoPtr
->hwndFocus
)) return FALSE
;
59 DEFDLG_SetFocus( hwnd
, infoPtr
->hwndFocus
);
60 infoPtr
->hwndFocus
= 0;
65 #ifdef SUPERFLUOUS_FUNCTIONS
66 /***********************************************************************
67 * DEFDLG_FindDefButton
69 * Find the current default push-button.
71 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
73 HWND hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
76 if (SendMessage( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
78 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
85 /***********************************************************************
88 * Set the new default button to be hwndNew.
90 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
,
94 !(SendMessage( hwndNew
, WM_GETDLGCODE
, 0, 0 ) & DLGC_UNDEFPUSHBUTTON
))
95 return FALSE
; /* Destination is not a push button */
97 if (dlgInfo
->msgResult
) /* There's already a default pushbutton */
99 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->msgResult
);
100 if (SendMessage( hwndOld
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
101 SendMessage( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
105 SendMessage( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
106 dlgInfo
->msgResult
= GetDlgCtrlID( hwndNew
);
108 else dlgInfo
->msgResult
= 0;
113 /***********************************************************************
114 * DefDlgProc (USER.308)
116 LRESULT
DefDlgProc( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
118 DIALOGINFO
* dlgInfo
;
120 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
122 if (!wndPtr
) return 0;
123 dlgInfo
= (DIALOGINFO
*)&wndPtr
->wExtra
;
125 dprintf_dialog(stddeb
, "DefDlgProc: "NPFMT
" %04x %ld %08lx\n",
126 hwnd
, msg
, (DWORD
)wParam
, lParam
);
128 dlgInfo
->msgResult
= 0;
129 if (dlgInfo
->dlgProc
)
131 /* Call dialog procedure */
132 result
= (BOOL
)CallWindowProc( dlgInfo
->dlgProc
, hwnd
,
133 msg
, wParam
, lParam
);
135 /* Check if window destroyed by dialog procedure */
136 wndPtr
= WIN_FindWndPtr( hwnd
);
137 if (!wndPtr
) return result
;
140 if (!result
) switch(msg
)
146 FillWindow( hwnd
, hwnd
, (HDC
)wParam
, (HBRUSH
)CTLCOLOR_DLG
);
151 /* Free dialog heap (if created) */
152 if (dlgInfo
->hDialogHeap
)
154 GlobalUnlock(dlgInfo
->hDialogHeap
);
155 GlobalFree(dlgInfo
->hDialogHeap
);
156 dlgInfo
->hDialogHeap
= 0;
160 if (dlgInfo
->hUserFont
)
162 DeleteObject( dlgInfo
->hUserFont
);
163 dlgInfo
->hUserFont
= 0;
169 DestroyMenu( dlgInfo
->hMenu
);
173 /* Window clean-up */
174 DefWindowProc( hwnd
, msg
, wParam
, lParam
);
178 if (!wParam
) DEFDLG_SaveFocus( hwnd
, dlgInfo
);
179 return DefWindowProc( hwnd
, msg
, wParam
, lParam
);
182 if (wParam
) DEFDLG_RestoreFocus( hwnd
, dlgInfo
);
183 else DEFDLG_SaveFocus( hwnd
, dlgInfo
);
187 DEFDLG_RestoreFocus( hwnd
, dlgInfo
);
191 if (dlgInfo
->fEnd
) return TRUE
;
192 DEFDLG_SetDefButton( hwnd
, dlgInfo
,
193 wParam
? GetDlgItem( hwnd
, wParam
) : 0 );
197 if (dlgInfo
->fEnd
|| !dlgInfo
->msgResult
) return 0;
198 return MAKELONG( dlgInfo
->msgResult
, DC_HASDEFID
);
202 HWND hwndDest
= (HWND
)wParam
;
205 HWND hwndPrev
= GetFocus();
206 if (!hwndPrev
) /* Set focus to the first item */
207 hwndDest
= DIALOG_GetFirstTabItem( hwnd
);
209 hwndDest
= GetNextDlgTabItem( hwnd
, hwndPrev
, wParam
);
211 if (hwndDest
) DEFDLG_SetFocus( hwnd
, hwndDest
);
212 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
217 EndDialog( hwnd
, TRUE
);
218 DestroyWindow( hwnd
);
222 return DefWindowProc( hwnd
, msg
, wParam
, lParam
);