source: trunk/src/user32/windlgmsg.cpp@ 1036

Last change on this file since 1036 was 949, checked in by sandervl, 26 years ago

Moved new user32 here

File size: 9.9 KB
Line 
1/* $Id: windlgmsg.cpp,v 1.1 1999-09-15 23:19:02 sandervl Exp $ */
2/*
3 * Win32 dialog message APIs for OS/2
4 *
5 * Copyright 1999 Sander van Leeuwen (OS/2 port & adaption)
6 *
7 * Based on Wine code (990815: window\dialog.c)
8 *
9 * Copyright 1993, 1994, 1996 Alexandre Julliard
10 *
11 * TODO: Dialog accelerator
12 *
13 * Project Odin Software License can be found in LICENSE.TXT
14 *
15 */
16#include <os2win.h>
17#include <misc.h>
18#include "win32wbase.h"
19#include "win32dlg.h"
20
21//******************************************************************************
22//******************************************************************************
23LONG WIN32API SendDlgItemMessageA( HWND hwnd, int id, UINT Msg, WPARAM wParam, LPARAM lParam)
24{
25 Win32Dialog *dialog;
26 Win32BaseWindow *dlgcontrol;
27
28 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
29 if(!dialog || !dialog->IsDialog()) {
30 dprintf(("SendDlgItemMessageA, window %x not found", hwnd));
31 return 0;
32 }
33 dlgcontrol = dialog->getDlgItem(id);
34 if(dlgcontrol) {
35 return dlgcontrol->SendMessageA(Msg, wParam, lParam);
36 }
37 return 0;
38}
39//******************************************************************************
40//******************************************************************************
41LONG WIN32API SendDlgItemMessageW( HWND hwnd, int id, UINT Msg, WPARAM wParam, LPARAM lParam)
42{
43 Win32Dialog *dialog;
44 Win32BaseWindow *dlgcontrol;
45
46 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
47 if(!dialog || !dialog->IsDialog()) {
48 dprintf(("SendDlgItemMessageW, window %x not found", hwnd));
49 return 0;
50 }
51 dlgcontrol = dialog->getDlgItem(id);
52 if(dlgcontrol) {
53 return dlgcontrol->SendMessageW(Msg, wParam, lParam);
54 }
55 return 0;
56}
57//TODO
58#if 0
59/***********************************************************************
60 * DIALOG_IsAccelerator
61 */
62static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey )
63{
64 HWND hwndControl = hwnd;
65 HWND hwndNext;
66 WND *wndPtr;
67 BOOL RetVal = FALSE;
68 INT dlgCode;
69
70 if (vKey == VK_SPACE)
71 {
72 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
73 if (dlgCode & DLGC_BUTTON)
74 {
75 SendMessageA( hwndControl, WM_LBUTTONDOWN, 0, 0);
76 SendMessageA( hwndControl, WM_LBUTTONUP, 0, 0);
77 RetVal = TRUE;
78 }
79 }
80 else
81 {
82 do
83 {
84 wndPtr = WIN_FindWndPtr( hwndControl );
85 if ( (wndPtr != NULL) &&
86 ((wndPtr->dwStyle & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) )
87 {
88 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
89 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
90 (wndPtr->text!=NULL))
91 {
92 /* find the accelerator key */
93 LPSTR p = wndPtr->text - 2;
94 do
95 {
96 p = strchr( p + 2, '&' );
97 }
98 while (p != NULL && p[1] == '&');
99
100 /* and check if it's the one we're looking for */
101 if (p != NULL && toupper( p[1] ) == toupper( vKey ) )
102 {
103 if ((dlgCode & DLGC_STATIC) ||
104 (wndPtr->dwStyle & 0x0f) == BS_GROUPBOX )
105 {
106 /* set focus to the control */
107 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
108 hwndControl, 1);
109 /* and bump it on to next */
110 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
111 }
112 else if (dlgCode &
113 (DLGC_DEFPUSHBUTTON | DLGC_UNDEFPUSHBUTTON))
114 {
115 /* send command message as from the control */
116 SendMessageA( hwndDlg, WM_COMMAND,
117 MAKEWPARAM( LOWORD(wndPtr->wIDmenu),
118 BN_CLICKED ),
119 (LPARAM)hwndControl );
120 }
121 else
122 {
123 /* click the control */
124 SendMessageA( hwndControl, WM_LBUTTONDOWN, 0, 0);
125 SendMessageA( hwndControl, WM_LBUTTONUP, 0, 0);
126 }
127 RetVal = TRUE;
128 WIN_ReleaseWndPtr(wndPtr);
129 break;
130 }
131 }
132 hwndNext = GetWindow( hwndControl, GW_CHILD );
133 }
134 else
135 {
136 hwndNext = 0;
137 }
138 WIN_ReleaseWndPtr(wndPtr);
139 if (!hwndNext)
140 {
141 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
142 }
143 while (!hwndNext)
144 {
145 hwndControl = GetParent( hwndControl );
146 if (hwndControl == hwndDlg)
147 {
148 if(hwnd==hwndDlg){ /* prevent endless loop */
149 hwndNext=hwnd;
150 break;
151 }
152 hwndNext = GetWindow( hwndDlg, GW_CHILD );
153 }
154 else
155 {
156 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
157 }
158 }
159 hwndControl = hwndNext;
160 }
161 while (hwndControl != hwnd);
162 }
163 return RetVal;
164}
165#endif
166/***********************************************************************
167 * DIALOG_IsDialogMessage
168 */
169static BOOL DIALOG_IsDialogMessage( HWND hwnd, HWND hwndDlg,
170 UINT message, WPARAM wParam,
171 LPARAM lParam, BOOL *translate,
172 BOOL *dispatch, INT dlgCode )
173{
174 *translate = *dispatch = FALSE;
175
176 if (message == WM_PAINT)
177 {
178 /* Apparently, we have to handle this one as well */
179 *dispatch = TRUE;
180 return TRUE;
181 }
182
183 /* Only the key messages get special processing */
184 if ((message != WM_KEYDOWN) &&
185 (message != WM_SYSCHAR) &&
186 (message != WM_CHAR))
187 return FALSE;
188
189 if (dlgCode & DLGC_WANTMESSAGE)
190 {
191 *translate = *dispatch = TRUE;
192 return TRUE;
193 }
194
195 switch(message)
196 {
197 case WM_KEYDOWN:
198 switch(wParam)
199 {
200 case VK_TAB:
201 if (!(dlgCode & DLGC_WANTTAB))
202 {
203 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
204 (GetKeyState(VK_SHIFT) & 0x8000), 0 );
205 return TRUE;
206 }
207 break;
208
209 case VK_RIGHT:
210 case VK_DOWN:
211 case VK_LEFT:
212 case VK_UP:
213 if (!(dlgCode & DLGC_WANTARROWS))
214 {
215 BOOL fPrevious = (wParam == VK_LEFT || wParam == VK_UP);
216 HWND hwndNext =
217 GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
218 SendMessageA( hwndDlg, WM_NEXTDLGCTL, hwndNext, 1 );
219 return TRUE;
220 }
221 break;
222
223 case VK_ESCAPE:
224 SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL,
225 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
226 return TRUE;
227
228 case VK_RETURN:
229 {
230 DWORD dw = SendMessageA( hwndDlg, DM_GETDEFID, 0, 0 );
231 if (HIWORD(dw) == DC_HASDEFID)
232 {
233 SendMessageA( hwndDlg, WM_COMMAND,
234 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
235 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
236 }
237 else
238 {
239 SendMessageA( hwndDlg, WM_COMMAND, IDOK,
240 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
241
242 }
243 }
244 return TRUE;
245 }
246 *translate = TRUE;
247 break; /* case WM_KEYDOWN */
248
249 case WM_CHAR:
250 if (dlgCode & DLGC_WANTCHARS) break;
251 /* drop through */
252
253//TODO:
254#if 0
255 case WM_SYSCHAR:
256 if (DIALOG_IsAccelerator( hwnd, hwndDlg, wParam ))
257 {
258 /* don't translate or dispatch */
259 return TRUE;
260 }
261 break;
262#endif
263 }
264
265 /* If we get here, the message has not been treated specially */
266 /* and can be sent to its destination window. */
267 *dispatch = TRUE;
268 return TRUE;
269}
270//******************************************************************************
271//******************************************************************************
272BOOL WIN32API IsDialogMessageA( HWND hwndDlg, LPMSG msg)
273{
274 BOOL ret, translate, dispatch;
275 INT dlgCode;
276
277 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
278 return FALSE;
279
280 dlgCode = SendMessageA( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
281 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
282 msg->wParam, msg->lParam,
283 &translate, &dispatch, dlgCode );
284 if (translate) TranslateMessage( msg );
285 if (dispatch) DispatchMessageA( msg );
286
287 return ret;
288}
289//******************************************************************************
290//******************************************************************************
291BOOL WIN32API IsDialogMessageW(HWND hwndDlg, LPMSG msg)
292{
293 BOOL ret, translate, dispatch;
294 INT dlgCode;
295
296 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
297 return FALSE;
298
299 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
300 ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message,
301 msg->wParam, msg->lParam,
302 &translate, &dispatch, dlgCode );
303 if (translate) TranslateMessage( msg );
304 if (dispatch) DispatchMessageW( msg );
305 return ret;
306}
307//******************************************************************************
308//******************************************************************************
Note: See TracBrowser for help on using the repository browser.