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