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