2 * Default dialog procedure
4 * Copyright 1993, 1996 Alexandre Julliard
11 #include "wine/winuser16.h"
15 #include "debugtools.h"
17 DEFAULT_DEBUG_CHANNEL(dialog
);
20 /***********************************************************************
23 static WNDPROC
DEFDLG_GetDlgProc( HWND hwnd
)
26 WND
*wndPtr
= WIN_GetPtr( hwnd
);
28 if (!wndPtr
) return 0;
29 if (wndPtr
== WND_OTHER_PROCESS
)
31 ERR( "cannot get dlg proc %x from other process\n", hwnd
);
34 ret
= *(WNDPROC
*)((char *)wndPtr
->wExtra
+ DWL_DLGPROC
);
35 WIN_ReleasePtr( wndPtr
);
39 /***********************************************************************
42 * Set the focus to a control of the dialog, selecting the text if
43 * the control is an edit dialog.
45 static void DEFDLG_SetFocus( HWND hwndDlg
, HWND hwndCtrl
)
47 HWND hwndPrev
= GetFocus();
49 if (IsChild( hwndDlg
, hwndPrev
))
51 if (SendMessageW( hwndPrev
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
52 SendMessageW( hwndPrev
, EM_SETSEL
, -1, 0 );
54 if (SendMessageW( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
55 SendMessageW( hwndCtrl
, EM_SETSEL
, 0, -1 );
60 /***********************************************************************
63 static void DEFDLG_SaveFocus( HWND hwnd
)
66 HWND hwndFocus
= GetFocus();
68 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return;
69 if (!(infoPtr
= DIALOG_get_info( hwnd
))) return;
70 infoPtr
->hwndFocus
= hwndFocus
;
71 /* Remove default button */
75 /***********************************************************************
78 static void DEFDLG_RestoreFocus( HWND hwnd
)
82 if (IsIconic( hwnd
)) return;
83 if (!(infoPtr
= DIALOG_get_info( hwnd
))) return;
84 if (!IsWindow( infoPtr
->hwndFocus
)) return;
85 /* Don't set the focus back to controls if EndDialog is already called.*/
86 if (!(infoPtr
->flags
& DF_END
))
88 DEFDLG_SetFocus( hwnd
, infoPtr
->hwndFocus
);
91 /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
92 sometimes losing focus when receiving WM_SETFOCUS messages. */
96 /***********************************************************************
97 * DEFDLG_FindDefButton
99 * Find the current default push-button.
101 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
103 HWND hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
106 if (SendMessageW( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
108 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
114 /***********************************************************************
115 * DEFDLG_SetDefButton
117 * Set the new default button to be hwndNew.
119 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
,
123 !(SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ) & DLGC_UNDEFPUSHBUTTON
))
124 return FALSE
; /* Destination is not a push button */
126 if (dlgInfo
->idResult
) /* There's already a default pushbutton */
128 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->idResult
);
129 if (SendMessageA( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
130 SendMessageA( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
134 SendMessageA( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
135 dlgInfo
->idResult
= GetDlgCtrlID( hwndNew
);
137 else dlgInfo
->idResult
= 0;
142 /***********************************************************************
145 * Implementation of DefDlgProc(). Only handle messages that need special
146 * handling for dialogs.
148 static LRESULT
DEFDLG_Proc( HWND hwnd
, UINT msg
, WPARAM wParam
,
149 LPARAM lParam
, DIALOGINFO
*dlgInfo
)
155 HBRUSH brush
= SendMessageW( hwnd
, WM_CTLCOLORDLG
, wParam
, (LPARAM
)hwnd
);
156 if (!brush
) brush
= DefWindowProcW( hwnd
, WM_CTLCOLORDLG
, wParam
, (LPARAM
)hwnd
);
160 HDC hdc
= (HDC
)wParam
;
161 GetClientRect( hwnd
, &rect
);
162 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
163 FillRect( hdc
, &rect
, brush
);
168 if ((dlgInfo
= (DIALOGINFO
*)SetWindowLongW( hwnd
, DWL_WINE_DIALOGINFO
, 0 )))
170 /* Free dialog heap (if created) */
171 if (dlgInfo
->hDialogHeap
)
173 GlobalUnlock16(dlgInfo
->hDialogHeap
);
174 GlobalFree16(dlgInfo
->hDialogHeap
);
176 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
177 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
178 WINPROC_FreeProc( DEFDLG_GetDlgProc( hwnd
), WIN_PROC_WINDOW
);
179 HeapFree( GetProcessHeap(), 0, dlgInfo
);
181 /* Window clean-up */
182 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
185 if (!wParam
) DEFDLG_SaveFocus( hwnd
);
186 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
189 if (wParam
) DEFDLG_RestoreFocus( hwnd
);
190 else DEFDLG_SaveFocus( hwnd
);
194 DEFDLG_RestoreFocus( hwnd
);
198 if (dlgInfo
->flags
& DF_END
) return 1;
199 DEFDLG_SetDefButton( hwnd
, dlgInfo
,
200 wParam
? GetDlgItem( hwnd
, wParam
) : 0 );
206 if (dlgInfo
->flags
& DF_END
) return 0;
207 if (dlgInfo
->idResult
)
208 return MAKELONG( dlgInfo
->idResult
, DC_HASDEFID
);
209 if ((hwndDefId
= DEFDLG_FindDefButton( hwnd
)))
210 return MAKELONG( GetDlgCtrlID( hwndDefId
), DC_HASDEFID
);
216 HWND hwndDest
= (HWND
)wParam
;
218 hwndDest
= GetNextDlgTabItem(hwnd
, GetFocus(), wParam
);
219 if (hwndDest
) DEFDLG_SetFocus( hwnd
, hwndDest
);
220 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
224 case WM_ENTERMENULOOP
:
226 case WM_NCLBUTTONDOWN
:
228 HWND hwndFocus
= GetFocus();
231 /* always make combo box hide its listbox control */
232 if (!SendMessageA( hwndFocus
, CB_SHOWDROPDOWN
, FALSE
, 0 ))
233 SendMessageA( GetParent(hwndFocus
), CB_SHOWDROPDOWN
, FALSE
, 0 );
236 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
239 return dlgInfo
->hUserFont
;
242 PostMessageA( hwnd
, WM_COMMAND
, IDCANCEL
,
243 (LPARAM
)GetDlgItem( hwnd
, IDCANCEL
) );
246 case WM_NOTIFYFORMAT
:
247 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
252 /***********************************************************************
255 static LRESULT
DEFDLG_Epilog(HWND hwnd
, UINT msg
, BOOL fResult
)
259 if ((msg
>= WM_CTLCOLORMSGBOX
&& msg
<= WM_CTLCOLORSTATIC
) ||
260 msg
== WM_CTLCOLOR
|| msg
== WM_COMPAREITEM
||
261 msg
== WM_VKEYTOITEM
|| msg
== WM_CHARTOITEM
||
262 msg
== WM_QUERYDRAGICON
|| msg
== WM_INITDIALOG
)
265 return GetWindowLongA( hwnd
, DWL_MSGRESULT
);
268 /***********************************************************************
269 * DefDlgProc (USER.308)
271 LRESULT WINAPI
DefDlgProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
275 HWND hwnd32
= WIN_Handle32( hwnd
);
278 SetWindowLongW( hwnd32
, DWL_MSGRESULT
, 0 );
280 if ((dlgproc
= (WNDPROC16
)DEFDLG_GetDlgProc( hwnd32
)))
282 /* Call dialog procedure */
283 result
= CallWindowProc16( dlgproc
, hwnd
, msg
, wParam
, lParam
);
284 /* 16 bit dlg procs only return BOOL16 */
285 if( WINPROC_GetProcType( dlgproc
) == WIN_PROC_16
)
286 result
= LOWORD(result
);
289 if (!result
&& IsWindow(hwnd32
))
291 /* callback didn't process this message */
305 case WM_ENTERMENULOOP
:
307 case WM_NCLBUTTONDOWN
:
308 return DEFDLG_Proc( hwnd32
, msg
, (WPARAM
)wParam
, lParam
, DIALOG_get_info(hwnd32
) );
316 return DefWindowProc16( hwnd
, msg
, wParam
, lParam
);
319 return DEFDLG_Epilog( hwnd32
, msg
, result
);
323 /***********************************************************************
324 * DefDlgProcA (USER32.@)
326 LRESULT WINAPI
DefDlgProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
331 SetWindowLongW( hwnd
, DWL_MSGRESULT
, 0 );
333 if ((dlgproc
= DEFDLG_GetDlgProc( hwnd
)))
335 /* Call dialog procedure */
336 result
= CallWindowProcA( dlgproc
, hwnd
, msg
, wParam
, lParam
);
337 /* 16 bit dlg procs only return BOOL16 */
338 if( WINPROC_GetProcType( dlgproc
) == WIN_PROC_16
)
339 result
= LOWORD(result
);
342 if (!result
&& IsWindow(hwnd
))
344 /* callback didn't process this message */
358 case WM_ENTERMENULOOP
:
360 case WM_NCLBUTTONDOWN
:
361 return DEFDLG_Proc( hwnd
, msg
, wParam
, lParam
, DIALOG_get_info(hwnd
) );
369 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
372 return DEFDLG_Epilog(hwnd
, msg
, result
);
376 /***********************************************************************
377 * DefDlgProcW (USER32.@)
379 LRESULT WINAPI
DefDlgProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
384 SetWindowLongW( hwnd
, DWL_MSGRESULT
, 0 );
386 if ((dlgproc
= DEFDLG_GetDlgProc( hwnd
)))
388 /* Call dialog procedure */
389 result
= CallWindowProcW( dlgproc
, hwnd
, msg
, wParam
, lParam
);
390 /* 16 bit dlg procs only return BOOL16 */
391 if( WINPROC_GetProcType( dlgproc
) == WIN_PROC_16
)
392 result
= LOWORD(result
);
395 if (!result
&& IsWindow(hwnd
))
397 /* callback didn't process this message */
411 case WM_ENTERMENULOOP
:
413 case WM_NCLBUTTONDOWN
:
414 return DEFDLG_Proc( hwnd
, msg
, wParam
, lParam
, DIALOG_get_info(hwnd
) );
422 return DefWindowProcW( hwnd
, msg
, wParam
, lParam
);
425 return DEFDLG_Epilog(hwnd
, msg
, result
);