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