00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <os2win.h>
00018 #include <misc.h>
00019 #include <string.h>
00020 #include <ctype.h>
00021 #include "win32wbase.h"
00022 #include "win32dlg.h"
00023 #include <winnls.h>
00024 #include <wine\unicode.h>
00025
00026 #define DBG_LOCALLOG DBG_windlgmsg
00027 #include "dbglocal.h"
00028
00029
00030
00031 LONG WIN32API SendDlgItemMessageA( HWND hwnd, int id, UINT Msg, WPARAM wParam, LPARAM lParam)
00032 {
00033 Win32Dialog *dialog;
00034 HWND hwndDlgItem;
00035
00036 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
00037 if(!dialog) {
00038 dprintf(("SendDlgItemMessageA, window %x not found", hwnd));
00039 return 0;
00040 }
00041 hwndDlgItem = dialog->getDlgItem(id);
00042 RELEASE_WNDOBJ(dialog);
00043 if(hwndDlgItem) {
00044 return SendMessageA(hwndDlgItem, Msg, wParam, lParam);
00045 }
00046 return 0;
00047 }
00048
00049
00050 LONG WIN32API SendDlgItemMessageW( HWND hwnd, int id, UINT Msg, WPARAM wParam, LPARAM lParam)
00051 {
00052 Win32Dialog *dialog;
00053 HWND hwndDlgItem;
00054
00055 dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
00056 if(!dialog) {
00057 dprintf(("SendDlgItemMessageW, window %x not found", hwnd));
00058 return 0;
00059 }
00060 hwndDlgItem = dialog->getDlgItem(id);
00061 RELEASE_WNDOBJ(dialog);
00062 if(hwndDlgItem) {
00063 return SendMessageW(hwndDlgItem, Msg, wParam, lParam);
00064 }
00065 return 0;
00066 }
00067
00068
00069
00070 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey )
00071 {
00072 HWND hwndControl = hwnd;
00073 HWND hwndNext;
00074 BOOL RetVal = FALSE;
00075 WCHAR buffer[128];
00076 INT dlgCode;
00077
00078 if (vKey == VK_SPACE)
00079 {
00080 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
00081 if (dlgCode & DLGC_BUTTON)
00082 {
00083
00084 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
00085 return TRUE;
00086 }
00087 }
00088
00089 do
00090 {
00091 DWORD style = GetWindowLongW( hwndControl, GWL_STYLE );
00092 if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE)
00093 {
00094 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
00095 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
00096 GetWindowTextW( hwndControl, buffer, sizeof(buffer)/sizeof(WCHAR) ))
00097 {
00098
00099 LPWSTR p = buffer - 2;
00100 char a_char = vKey;
00101 WCHAR w_char = 0;
00102
00103 do
00104 {
00105 p = strchrW( p + 2, '&' );
00106 }
00107 while (p != NULL && p[1] == '&');
00108
00109
00110 MultiByteToWideChar(CP_ACP, 0, &a_char, 1, &w_char, 1);
00111 if (p != NULL && toupperW( p[1] ) == toupperW( w_char ) )
00112 {
00113 if ((dlgCode & DLGC_STATIC) || (style & 0x0f) == BS_GROUPBOX )
00114 {
00115
00116 SendMessageA( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndControl, 1);
00117
00118 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
00119 }
00120 else if (dlgCode & DLGC_BUTTON)
00121 {
00122
00123 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
00124 }
00125 return TRUE;
00126 }
00127 }
00128 hwndNext = GetWindow( hwndControl, GW_CHILD );
00129 }
00130 else hwndNext = 0;
00131
00132 if (!hwndNext) hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
00133
00134 while (!hwndNext && hwndControl)
00135 {
00136 hwndControl = GetParent( hwndControl );
00137 if (hwndControl == hwndDlg)
00138 {
00139 if(hwnd==hwndDlg)
00140 {
00141 hwndNext=hwnd;
00142 break;
00143 }
00144 hwndNext = GetWindow( hwndDlg, GW_CHILD );
00145 }
00146 else
00147 #ifdef __WIN32OS2__
00148 {
00149 if(hwndControl == 0) {
00150 dprintf(("WARNING: DIALOG_IsAccelerator %x %x -> hwndControl == 0", hwnd, hwndDlg));
00151 return FALSE;
00152 }
00153 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
00154 }
00155 #else
00156 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
00157 #endif
00158 }
00159 hwndControl = hwndNext;
00160 }
00161 while (hwndControl && (hwndControl != hwnd));
00162
00163 return FALSE;
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
00177 {
00178 while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
00179 {
00180 Win32BaseWindow *pParent;
00181 HWND hParent = GetParent(hwndDlg);
00182 if (!hParent) break;
00183
00184 pParent = Win32BaseWindow::GetWindowFromHandle(hParent);
00185 if (!pParent) break;
00186
00187 if (!pParent->IsDialog()) {
00188 RELEASE_WNDOBJ(pParent);
00189 break;
00190 }
00191 RELEASE_WNDOBJ(pParent);
00192 hwndDlg = hParent;
00193 }
00194
00195 return hwndDlg;
00196 }
00197
00198
00199
00200
00201 static BOOL DIALOG_IsDialogMessage( HWND hwndDlg, BOOL *translate, BOOL *dispatch, INT dlgCode, LPMSG msg )
00202 {
00203 *translate = *dispatch = FALSE;
00204
00205 if (msg->message == WM_PAINT)
00206 {
00207
00208 *dispatch = TRUE;
00209 return TRUE;
00210 }
00211
00212
00213 if ((msg->message != WM_KEYDOWN) &&
00214 (msg->message != WM_SYSCHAR) &&
00215 (msg->message != WM_CHAR))
00216 return FALSE;
00217
00218 if (dlgCode & DLGC_WANTMESSAGE)
00219 {
00220 *translate = *dispatch = TRUE;
00221 return TRUE;
00222 }
00223
00224 hwndDlg = DIALOG_FindMsgDestination(hwndDlg);
00225
00226 switch(msg->message)
00227 {
00228 case WM_KEYDOWN:
00229 switch(msg->wParam)
00230 {
00231 case VK_TAB:
00232 if (!(dlgCode & DLGC_WANTTAB))
00233 {
00234 SendMessageA( hwndDlg, WM_NEXTDLGCTL,
00235 (GetKeyState(VK_SHIFT) & 0x8000), 0 );
00236 return TRUE;
00237 }
00238 break;
00239
00240 case VK_RIGHT:
00241 case VK_DOWN:
00242 case VK_LEFT:
00243 case VK_UP:
00244 if (!(dlgCode & DLGC_WANTARROWS))
00245 {
00246 BOOL fPrevious = (msg->wParam == VK_LEFT || msg->wParam == VK_UP);
00247 HWND hwndNext =
00248 GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious );
00249 SendMessageA( hwndDlg, WM_NEXTDLGCTL, hwndNext, 1 );
00250 return TRUE;
00251 }
00252 break;
00253
00254 case VK_ESCAPE:
00255 SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL,
00256 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
00257 return TRUE;
00258
00259 case VK_RETURN:
00260 {
00261 DWORD dw = SendMessageA( hwndDlg, DM_GETDEFID, 0, 0 );
00262 if (HIWORD(dw) == DC_HASDEFID)
00263 {
00264 SendMessageA( hwndDlg, WM_COMMAND,
00265 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
00266 (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw)));
00267 }
00268 else
00269 {
00270 SendMessageA( hwndDlg, WM_COMMAND, IDOK,
00271 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
00272
00273 }
00274
00275 return TRUE;
00276 }
00277 }
00278 *translate = TRUE;
00279 break;
00280
00281 case WM_CHAR:
00282 if (dlgCode & DLGC_WANTCHARS) break;
00283
00284
00285 case WM_SYSCHAR:
00286 if (DIALOG_IsAccelerator( msg->hwnd, hwndDlg, msg->wParam ))
00287 {
00288
00289 return TRUE;
00290 }
00291 break;
00292 }
00293
00294
00295
00296 *dispatch = TRUE;
00297 return TRUE;
00298 }
00299
00300
00301 BOOL WIN32API IsDialogMessageA( HWND hwndDlg, LPMSG msg)
00302 {
00303 BOOL ret, translate, dispatch;
00304 INT dlgCode;
00305
00306 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
00307 return FALSE;
00308
00309 dlgCode = SendMessageA( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
00310 ret = DIALOG_IsDialogMessage(hwndDlg,&translate,&dispatch,dlgCode,msg);
00311 if (translate) TranslateMessage( msg );
00312 if (dispatch) DispatchMessageA( msg );
00313
00314 return ret;
00315 }
00316
00317
00318 BOOL WIN32API IsDialogMessageW(HWND hwndDlg, LPMSG msg)
00319 {
00320 BOOL ret, translate, dispatch;
00321 INT dlgCode;
00322
00323 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd ))
00324 return FALSE;
00325
00326 dlgCode = SendMessageW( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg);
00327 ret = DIALOG_IsDialogMessage(hwndDlg,&translate,&dispatch,dlgCode,msg);
00328 if (translate) TranslateMessage( msg );
00329 if (dispatch) DispatchMessageW( msg );
00330 return ret;
00331 }
00332
00333