source: trunk/src/user32/windowmsg.cpp@ 7620

Last change on this file since 7620 was 7620, checked in by sandervl, 24 years ago

SendInput fix + handle Alt-F4 in default window handler

File size: 41.1 KB
Line 
1/* $Id: windowmsg.cpp,v 1.31 2001-12-12 16:40:44 sandervl Exp $ */
2/*
3 * Win32 window message APIs for OS/2
4 *
5 * Copyright 1999 Sander van Leeuwen
6 *
7 * Parts based on Wine Windows code (windows\message.c) 990508
8 *
9 * Copyright 1993, 1994 Alexandre Julliard
10 *
11 * TODO: GetQueueStatus: QS_HOTKEY (oslibmsg.cpp) & low word bits
12 * TODO: MsgWaitForMultipleObjects: timeout isn't handled correctly (can return too late)
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17
18#include <odin.h>
19#include <odinwrap.h>
20#include <os2sel.h>
21
22#include <os2win.h>
23#include <misc.h>
24#include <win32wbase.h>
25#include <win.h>
26#include <heapstring.h>
27#include <handlemanager.h>
28#include "oslibutil.h"
29#include "oslibwin.h"
30#include "oslibmsg.h"
31#include "hook.h"
32
33#define DBG_LOCALLOG DBG_windowmsg
34#include "dbglocal.h"
35
36ODINDEBUGCHANNEL(USER32-WINDOWMSG)
37
38
39//******************************************************************************
40//******************************************************************************
41VOID WIN32API PostQuitMessage( int nExitCode)
42{
43 dprintf(("USER32: PostQuitMessage\n"));
44 OSLibWinPostQuitMessage(nExitCode);
45}
46//******************************************************************************
47//******************************************************************************
48LONG WIN32API DispatchMessageA(const MSG * msg)
49{
50 dprintf2(("DispatchMessageA %x %x %x %x %x", msg->hwnd, msg->message, msg->wParam, msg->lParam, msg->time));
51 return OSLibWinDispatchMsg((MSG *)msg);
52}
53//******************************************************************************
54//******************************************************************************
55LONG WIN32API DispatchMessageW( const MSG * msg)
56{
57 dprintf2(("DispatchMessageW %x %x %x %x %x", msg->hwnd, msg->message, msg->wParam, msg->lParam, msg->time));
58 return OSLibWinDispatchMsg((MSG *)msg, TRUE);
59}
60//******************************************************************************
61//******************************************************************************
62BOOL WIN32API TranslateMessage(const MSG *msg)
63{
64 // check the message code
65 if ( (msg->message < WM_KEYDOWN) ||
66 (msg->message > WM_SYSKEYUP)||
67 (msg->message == WM_CHAR) ||
68 (msg->message == WM_DEADCHAR) )
69 {
70 SetLastError(ERROR_INVALID_PARAMETER);
71 return FALSE;
72 }
73
74 // only WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP
75 // can go into TranslateMessage
76
77 return OSLibWinTranslateMessage((MSG *)msg);
78}
79//******************************************************************************
80//******************************************************************************
81BOOL WIN32API GetMessageA( LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax)
82{
83 BOOL ret;
84
85 dprintf2(("GetMessageA %x %x-%x", hwnd, uMsgFilterMin, uMsgFilterMax));
86 ret = OSLibWinGetMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax);
87 if(ret) dprintf2(("GetMessageA %x %x %x %x", hwnd, pMsg->message, pMsg->wParam, pMsg->lParam));
88 HOOK_CallHooksA(WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)pMsg);
89 return ret;
90}
91//******************************************************************************
92//******************************************************************************
93BOOL WIN32API GetMessageW( LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax)
94{
95 BOOL ret;
96
97 dprintf2(("GetMessageW %x %x-%x", hwnd, uMsgFilterMin, uMsgFilterMax));
98 ret = OSLibWinGetMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, TRUE);
99 HOOK_CallHooksW(WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)pMsg);
100 return ret;
101}
102//******************************************************************************
103//******************************************************************************
104BOOL WIN32API PeekMessageA(LPMSG msg, HWND hwndOwner, UINT uMsgFilterMin,
105 UINT uMsgFilterMax, UINT fuRemoveMsg)
106{
107 BOOL fFoundMsg;
108
109 dprintf2(("PeekMessageA %x %d-%d %d", hwndOwner, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg));
110 fFoundMsg = OSLibWinPeekMsg(msg, hwndOwner, uMsgFilterMin, uMsgFilterMax,
111 fuRemoveMsg, FALSE);
112 if(fFoundMsg) {
113 dprintf2(("PeekMessageA %x %d-%d %d found message %x %d %x %x", hwndOwner, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg, msg->hwnd, msg->message, msg->wParam, msg->lParam));
114 HOOK_CallHooksA(WH_GETMESSAGE, HC_ACTION, fuRemoveMsg & PM_REMOVE, (LPARAM)msg );
115 if (msg->message == WM_QUIT && (fuRemoveMsg & PM_REMOVE)) {
116 //TODO: Post WM_QUERYENDSESSION message when WM_QUIT received and system is shutting down
117 }
118 }
119 return fFoundMsg;
120}
121//******************************************************************************
122//******************************************************************************
123BOOL WIN32API PeekMessageW(LPMSG msg, HWND hwndOwner, UINT uMsgFilterMin,
124 UINT uMsgFilterMax, UINT fuRemoveMsg)
125{
126 BOOL fFoundMsg;
127
128 dprintf2(("PeekMessageW %x %d-%d %d", hwndOwner, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg));
129 fFoundMsg = OSLibWinPeekMsg(msg, hwndOwner, uMsgFilterMin, uMsgFilterMax,
130 fuRemoveMsg, TRUE);
131 if(fFoundMsg) {
132 dprintf2(("PeekMessageW %x %d-%d %d found message %x %d %x %x", hwndOwner, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg, msg->hwnd, msg->message, msg->wParam, msg->lParam));
133 HOOK_CallHooksW(WH_GETMESSAGE, HC_ACTION, fuRemoveMsg & PM_REMOVE, (LPARAM)msg );
134 if (msg->message == WM_QUIT && (fuRemoveMsg & (PM_REMOVE))) {
135 //TODO: Post WM_QUERYENDSESSION message when WM_QUIT received and system is shutting down
136 }
137 }
138 return fFoundMsg;
139}
140//******************************************************************************
141//TODO:
142//******************************************************************************
143LONG WIN32API GetMessageExtraInfo()
144{
145 dprintf(("USER32: GetMessageExtraInfo %x", GetThreadMessageExtraInfo()));
146 return GetThreadMessageExtraInfo();
147}
148//******************************************************************************
149//******************************************************************************
150LPARAM WIN32API SetMessageExtraInfo(LPARAM lParam)
151{
152 dprintf(("USER32: SetMessageExtraInfo %x", lParam));
153 return SetThreadMessageExtraInfo(lParam);
154}
155//******************************************************************************
156//******************************************************************************
157DWORD WIN32API GetMessagePos(void)
158{
159 DWORD pos;
160
161 pos = OSLibWinGetMessagePos();
162 dprintf(("USER32: GetMessagePos -> (%d,%d)", HIWORD(pos), LOWORD(pos)));
163 return pos;
164}
165//******************************************************************************
166//******************************************************************************
167LONG WIN32API GetMessageTime(void)
168{
169 dprintf(("USER32: GetMessageTime"));
170 return OSLibWinGetMessageTime();
171}
172//******************************************************************************
173//******************************************************************************
174LRESULT WIN32API SendMessageA(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
175{
176 Win32BaseWindow *window;
177 LRESULT result;
178
179 if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
180 {
181 Win32BaseWindow::BroadcastMessageA(BROADCAST_SEND, msg, wParam, lParam);
182 return TRUE;
183 }
184
185 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
186 if(!window) {
187 dprintf(("SendMessageA, %x %x %x window %x not found", msg, wParam, lParam, hwnd));
188 return 0;
189 }
190 result = window->SendMessageA(msg, wParam, lParam);
191 RELEASE_WNDOBJ(window);
192 return result;
193}
194//******************************************************************************
195//******************************************************************************
196LRESULT WIN32API SendMessageW(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
197{
198 Win32BaseWindow *window;
199 LRESULT result;
200
201 if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
202 {
203 Win32BaseWindow::BroadcastMessageW(BROADCAST_SEND, msg, wParam, lParam);
204 return TRUE;
205 }
206
207 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
208 if(!window) {
209 dprintf(("SendMessageW, window %x not found", hwnd));
210 return 0;
211 }
212 result = window->SendMessageW(msg, wParam, lParam);
213 RELEASE_WNDOBJ(window);
214 return result;
215}
216//******************************************************************************
217//******************************************************************************
218BOOL WIN32API PostMessageA(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
219{
220 Win32BaseWindow *window;
221 HWND hwndOS2;
222
223 if (hwnd == HWND_BROADCAST) //Not HWND_TOPMOST???
224 {
225 Win32BaseWindow::BroadcastMessageA(BROADCAST_POST, msg, wParam, lParam);
226 return TRUE;
227 }
228
229 if(hwnd == NULL)
230 return PostThreadMessageA(GetCurrentThreadId(), msg, wParam, lParam);
231
232 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
233 if(!window) {
234 dprintf(("PostMessageA, window %x not found", hwnd));
235 return FALSE;
236 }
237 hwndOS2 = window->getOS2WindowHandle();
238 RELEASE_WNDOBJ(window);
239 dprintf(("PostMessageA, %x %x %x %x", hwnd, msg, wParam, lParam));
240 return OSLibPostMessage(hwndOS2, msg, wParam, lParam, FALSE);
241}
242//******************************************************************************
243//******************************************************************************
244BOOL WIN32API PostMessageW(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
245{
246 Win32BaseWindow *window;
247 HWND hwndOS2;
248
249 if (hwnd == HWND_BROADCAST) //Not HWND_TOPMOST???
250 {
251 Win32BaseWindow::BroadcastMessageW(BROADCAST_POST, msg, wParam, lParam);
252 return TRUE;
253 }
254
255 if(hwnd == NULL)
256 return PostThreadMessageW(GetCurrentThreadId(), msg, wParam, lParam);
257
258 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
259 if(!window) {
260 dprintf(("PostMessageW, window %x not found", hwnd));
261 return FALSE;
262 }
263 hwndOS2 = window->getOS2WindowHandle();
264 RELEASE_WNDOBJ(window);
265 dprintf(("PostMessageW, %x %x %x %x", hwnd, msg, wParam, lParam));
266 return OSLibPostMessage(hwndOS2, msg, wParam, lParam, TRUE);
267}
268//******************************************************************************
269//******************************************************************************
270BOOL WIN32API PostThreadMessageA( DWORD threadid, UINT msg, WPARAM wParam, LPARAM lParam)
271{
272 return OSLibPostThreadMessage(threadid, msg, wParam, lParam, FALSE);
273}
274//******************************************************************************
275//******************************************************************************
276BOOL WIN32API PostThreadMessageW( DWORD threadid, UINT msg, WPARAM wParam, LPARAM lParam)
277{
278 return OSLibPostThreadMessage(threadid, msg, wParam, lParam, TRUE);
279}
280//******************************************************************************
281//******************************************************************************
282BOOL WIN32API WaitMessage(void)
283{
284 dprintf2(("USER32: WaitMessage"));
285 return OSLibWinWaitMessage();
286}
287//******************************************************************************
288//******************************************************************************
289BOOL WIN32API InSendMessage(void)
290{
291 dprintf(("USER32: InSendMessage"));
292 return OSLibWinInSendMessage();
293}
294//******************************************************************************
295//******************************************************************************
296BOOL WIN32API ReplyMessage(LRESULT result)
297{
298 dprintf(("USER32: ReplyMessage %x", result));
299 return OSLibWinReplyMessage(result);
300}
301//******************************************************************************
302//******************************************************************************
303UINT WIN32API RegisterWindowMessageA(LPCSTR lpString)
304{
305 UINT rc;
306
307 rc = GlobalAddAtomA(lpString);
308 dprintf(("USER32: RegisterWindowMessageA %s returned %X\n", lpString, rc));
309 return(rc);
310}
311//******************************************************************************
312//******************************************************************************
313UINT WIN32API RegisterWindowMessageW( LPCWSTR lpString)
314{
315 dprintf(("USER32: RegisterWindowMessageW\n"));
316 return GlobalAddAtomW(lpString);
317}
318//******************************************************************************
319//No need to support this (obsolete, not implemented by Win32)
320//******************************************************************************
321BOOL WIN32API SetMessageQueue(int cMessagesMax)
322{
323 dprintf(("USER32: SetMessageQueue\n"));
324 return(TRUE);
325}
326//******************************************************************************
327//******************************************************************************
328LRESULT WIN32API SendMessageTimeoutA(HWND hwnd, UINT Msg, WPARAM wParam,
329 LPARAM lParam, UINT fuFlags, UINT uTimeOut,
330 LPDWORD lpdwResult)
331{
332 dprintf(("USER32: SendMessageTimeoutA, partially implemented\n"));
333 //ignore fuFlags & wTimeOut
334 *lpdwResult = SendMessageA(hwnd, Msg, wParam, lParam);
335 return(TRUE);
336}
337//******************************************************************************
338//******************************************************************************
339LRESULT WIN32API SendMessageTimeoutW(HWND hwnd, UINT Msg, WPARAM wParam,
340 LPARAM lParam, UINT fuFlags, UINT uTimeOut,
341 LPDWORD lpdwResult)
342{
343 dprintf(("USER32: SendMessageTimeoutW, partially implemented\n"));
344 return(SendMessageTimeoutA(hwnd, Msg, wParam, lParam, fuFlags, uTimeOut, lpdwResult));
345}
346//******************************************************************************
347//******************************************************************************
348BOOL WIN32API SendNotifyMessageA(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
349{
350 dprintf(("USER32: SendNotifyMessageA, not completely implemented\n"));
351 return(SendMessageA(hwnd, Msg, wParam, lParam));
352}
353//******************************************************************************
354//******************************************************************************
355BOOL WIN32API SendNotifyMessageW(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
356{
357 dprintf(("USER32: SendNotifyMessageW, not completely implemented\n"));
358 return(SendMessageA(hwnd, Msg, wParam, lParam));
359}
360/*****************************************************************************
361 * Name : BOOL WIN32API SendMessageCallbackA
362 * Purpose : The SendMessageCallback function sends the specified message to
363 * a window or windows. The function calls the window procedure for
364 * the specified window and returns immediately. After the window
365 * procedure processes the message, the system calls the specified
366 * callback function, passing the result of the message processing
367 * and an application-defined value to the callback function.
368 * Parameters: HWND hwnd handle of destination window
369 * UINT uMsg message to send
370 * WPARAM wParam first message parameter
371 * LPARAM lParam second message parameter
372 * SENDASYNCPROC lpResultCallBack function to receive message value
373 * DWORD dwData value to pass to callback function
374 * Variables :
375 * Result : If the function succeeds, the return value is TRUE.
376 * If the function fails, the return value is FALSE. To get extended
377 * error information, call GetLastError.
378 * Remark :
379 * Status : UNTESTED STUB
380 *
381 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
382 *****************************************************************************/
383
384BOOL WIN32API SendMessageCallbackA(HWND hWnd,
385 UINT uMsg,
386 WPARAM wParam,
387 LPARAM lParam,
388 SENDASYNCPROC lpResultCallBack,
389 DWORD dwData)
390{
391 dprintf(("USER32:SendMessageCallBackA (%08xh,%08xh,%08xh,%08xh,%08xh,%08x) not implemented.\n",
392 hWnd,
393 uMsg,
394 wParam,
395 lParam,
396 lpResultCallBack,
397 dwData));
398
399 return (FALSE);
400}
401
402
403/*****************************************************************************
404 * Name : BOOL WIN32API SendMessageCallbackW
405 * Purpose : The SendMessageCallback function sends the specified message to
406 * a window or windows. The function calls the window procedure for
407 * the specified window and returns immediately. After the window
408 * procedure processes the message, the system calls the specified
409 * callback function, passing the result of the message processing
410 * and an application-defined value to the callback function.
411 * Parameters: HWND hwnd handle of destination window
412 * UINT uMsg message to send
413 * WPARAM wParam first message parameter
414 * LPARAM lParam second message parameter
415 * SENDASYNCPROC lpResultCallBack function to receive message value
416 * DWORD dwData value to pass to callback function
417 * Variables :
418 * Result : If the function succeeds, the return value is TRUE.
419 * If the function fails, the return value is FALSE. To get extended
420 * error information, call GetLastError.
421 * Remark :
422 * Status : UNTESTED STUB
423 *
424 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
425 *****************************************************************************/
426
427BOOL WIN32API SendMessageCallbackW(HWND hWnd,
428 UINT uMsg,
429 WPARAM wParam,
430 LPARAM lParam,
431 SENDASYNCPROC lpResultCallBack,
432 DWORD dwData)
433{
434 dprintf(("USER32:SendMessageCallBackW (%08xh,%08xh,%08xh,%08xh,%08xh,%08x) not implemented.\n",
435 hWnd,
436 uMsg,
437 wParam,
438 lParam,
439 lpResultCallBack,
440 dwData));
441
442 return (FALSE);
443}
444/*****************************************************************************
445 * Name : long WIN32API BroadcastSystemMessage
446 * Purpose : The BroadcastSystemMessage function sends a message to the given
447 * recipients. The recipients can be applications, installable
448 * drivers, Windows-based network drivers, system-level device
449 * drivers, or any combination of these system components.
450 * Parameters: DWORD dwFlags,
451 LPDWORD lpdwRecipients,
452 UINT uiMessage,
453 WPARAM wParam,
454 LPARAM lParam
455 * Variables :
456 * Result : If the function succeeds, the return value is a positive value.
457 * If the function is unable to broadcast the message, the return value is -1.
458 * If the dwFlags parameter is BSF_QUERY and at least one recipient returned FALSE to the corresponding message, the return value is zero.
459 * Remark :
460 * Status : UNTESTED STUB
461 *
462 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
463 *****************************************************************************/
464
465long WIN32API BroadcastSystemMessage(DWORD dwFlags,
466 LPDWORD lpdwRecipients,
467 UINT uiMessage,
468 WPARAM wParam,
469 LPARAM lParam)
470{
471 dprintf(("USER32:BroadcastSystemMessage(%08xh,%08xh,%08xh,%08xh,%08x) not implemented.\n",
472 dwFlags,
473 lpdwRecipients,
474 uiMessage,
475 wParam,
476 lParam));
477
478 return (-1);
479}
480//******************************************************************************
481//******************************************************************************
482/**********************************************************************
483 * WINPROC_TestCBForStr
484 *
485 * Return TRUE if the lparam is a string
486 */
487BOOL WINPROC_TestCBForStr ( HWND hwnd )
488{
489 BOOL retvalue;
490 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
491 retvalue = ( !(LOWORD(dwStyle) & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) ||
492 (LOWORD(dwStyle) & CBS_HASSTRINGS) );
493 return retvalue;
494}
495/**********************************************************************
496 * WINPROC_TestLBForStr
497 *
498 * Return TRUE if the lparam is a string
499 */
500BOOL WINPROC_TestLBForStr ( HWND hwnd )
501{
502 BOOL retvalue;
503 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
504 retvalue = ( !(LOWORD(dwStyle) & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) ||
505 (LOWORD(dwStyle) & LBS_HASSTRINGS) );
506 return retvalue;
507}
508
509/**********************************************************************
510 * WINPROC_MapMsg32ATo32W
511 *
512 * Map a message from Ansi to Unicode.
513 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
514 *
515 * FIXME:
516 * WM_CHAR, WM_CHARTOITEM, WM_DEADCHAR, WM_MENUCHAR, WM_SYSCHAR, WM_SYSDEADCHAR
517 *
518 * FIXME:
519 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
520 * the first four bytes are the handle of the icon
521 * when the WM_SETTEXT message has been used to set the icon
522 */
523INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM *plparam )
524{
525 switch(msg)
526 {
527 case WM_GETTEXT:
528 {
529 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
530 wParam * sizeof(WCHAR) + sizeof(LPARAM) );
531 if (!ptr) return -1;
532 *ptr++ = *plparam; /* Store previous lParam */
533 *plparam = (LPARAM)ptr;
534 }
535 return 1;
536 /* lparam is string (0-terminated) */
537 case WM_SETTEXT:
538 case WM_WININICHANGE:
539 case CB_DIR:
540 case LB_DIR:
541 case LB_ADDFILE:
542#ifndef __WIN32OS2__
543 case CB_FINDSTRING:
544 case CB_FINDSTRINGEXACT:
545 case CB_SELECTSTRING:
546 case LB_FINDSTRING:
547 case LB_SELECTSTRING:
548#endif
549 case EM_REPLACESEL:
550 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
551 return (*plparam ? 1 : -1);
552
553 case WM_NCCREATE:
554 case WM_CREATE:
555 {
556 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
557 sizeof(*cs) );
558 if (!cs) return -1;
559 *cs = *(CREATESTRUCTW *)*plparam;
560 if (HIWORD(cs->lpszName))
561 cs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
562 (LPCSTR)cs->lpszName );
563 if (HIWORD(cs->lpszClass))
564 cs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
565 (LPCSTR)cs->lpszClass );
566 *plparam = (LPARAM)cs;
567 }
568 return 1;
569 case WM_MDICREATE:
570 {
571 MDICREATESTRUCTW *cs =
572 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
573 if (!cs) return -1;
574 *cs = *(MDICREATESTRUCTW *)*plparam;
575 if (HIWORD(cs->szClass))
576 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
577 (LPCSTR)cs->szClass );
578 if (HIWORD(cs->szTitle))
579 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
580 (LPCSTR)cs->szTitle );
581 *plparam = (LPARAM)cs;
582 }
583 return 1;
584
585/* Listbox */
586 case LB_ADDSTRING:
587#ifdef __WIN32OS2__
588 case LB_FINDSTRING:
589 case LB_FINDSTRINGEXACT:
590 case LB_SELECTSTRING:
591#endif
592 case LB_INSERTSTRING:
593 if ( WINPROC_TestLBForStr( hwnd ))
594 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
595 return (*plparam ? 1 : -1);
596
597 case LB_GETTEXT: /* fixme: fixed sized buffer */
598 { if ( WINPROC_TestLBForStr( hwnd ))
599 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
600 if (!ptr) return -1;
601 *ptr++ = *plparam; /* Store previous lParam */
602 *plparam = (LPARAM)ptr;
603 }
604 }
605 return 1;
606
607/* Combobox */
608 case CB_ADDSTRING:
609#ifdef __WIN32OS2__
610 case CB_FINDSTRING:
611 case CB_FINDSTRINGEXACT:
612 case CB_SELECTSTRING:
613#endif
614 case CB_INSERTSTRING:
615 if ( WINPROC_TestCBForStr( hwnd ))
616 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
617 return (*plparam ? 1 : -1);
618
619 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
620 { if ( WINPROC_TestCBForStr( hwnd ))
621 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
622 if (!ptr) return -1;
623 *ptr++ = *plparam; /* Store previous lParam */
624 *plparam = (LPARAM)ptr;
625 }
626 }
627 return 1;
628
629/* Multiline edit */
630 case EM_GETLINE:
631 { WORD len = (WORD)*plparam;
632 LPARAM *ptr = (LPARAM *) HEAP_xalloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
633 if (!ptr) return -1;
634 *ptr++ = *plparam; /* Store previous lParam */
635 *((WORD *) ptr) = len; /* Store the length */
636 *plparam = (LPARAM)ptr;
637 }
638 return 1;
639
640 case WM_ASKCBFORMATNAME:
641 case WM_DEVMODECHANGE:
642 case WM_PAINTCLIPBOARD:
643 case WM_SIZECLIPBOARD:
644 case EM_SETPASSWORDCHAR:
645 // FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg), msg );
646 return -1;
647 default: /* No translation needed */
648 return 0;
649 }
650}
651
652
653/**********************************************************************
654 * WINPROC_UnmapMsg32ATo32W
655 *
656 * Unmap a message that was mapped from Ansi to Unicode.
657 */
658void WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
659{
660 switch(msg)
661 {
662 case WM_GETTEXT:
663 {
664 LPARAM *ptr = (LPARAM *)lParam - 1;
665 lstrcpynWtoA( (LPSTR)*ptr, (LPWSTR)lParam, wParam );
666 HeapFree( GetProcessHeap(), 0, ptr );
667 }
668 break;
669
670 case WM_NCCREATE:
671 case WM_CREATE:
672 {
673 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
674 if (HIWORD(cs->lpszName))
675 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
676 if (HIWORD(cs->lpszClass))
677 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
678 HeapFree( GetProcessHeap(), 0, cs );
679 }
680 break;
681
682 case WM_MDICREATE:
683 {
684 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
685 if (HIWORD(cs->szTitle))
686 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
687 if (HIWORD(cs->szClass))
688 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
689 HeapFree( GetProcessHeap(), 0, cs );
690 }
691 break;
692
693 case WM_SETTEXT:
694 case WM_WININICHANGE:
695 case CB_DIR:
696 case LB_DIR:
697 case LB_ADDFILE:
698#ifndef __WIN32OS2__
699 case CB_FINDSTRING:
700 case CB_FINDSTRINGEXACT:
701 case CB_SELECTSTRING:
702 case LB_FINDSTRING:
703 case LB_SELECTSTRING:
704#endif
705 case EM_REPLACESEL:
706 HeapFree( GetProcessHeap(), 0, (void *)lParam );
707 break;
708
709/* Listbox */
710 case LB_ADDSTRING:
711#ifdef __WIN32OS2__
712 case LB_FINDSTRING:
713 case LB_FINDSTRINGEXACT:
714 case LB_SELECTSTRING:
715#endif
716 case LB_INSERTSTRING:
717 if ( WINPROC_TestLBForStr( hwnd ))
718 HeapFree( GetProcessHeap(), 0, (void *)lParam );
719 break;
720
721 case LB_GETTEXT:
722 { if ( WINPROC_TestLBForStr( hwnd ))
723 { LPARAM *ptr = (LPARAM *)lParam - 1;
724 lstrcpyWtoA( (LPSTR)*ptr, (LPWSTR)(lParam) );
725 HeapFree( GetProcessHeap(), 0, ptr );
726 }
727 }
728 break;
729
730/* Combobox */
731 case CB_ADDSTRING:
732#ifdef __WIN32OS2__
733 case CB_FINDSTRING:
734 case CB_FINDSTRINGEXACT:
735 case CB_SELECTSTRING:
736#endif
737 case CB_INSERTSTRING:
738 if ( WINPROC_TestCBForStr( hwnd ))
739 HeapFree( GetProcessHeap(), 0, (void *)lParam );
740 break;
741
742 case CB_GETLBTEXT:
743 { if ( WINPROC_TestCBForStr( hwnd ))
744 { LPARAM *ptr = (LPARAM *)lParam - 1;
745 lstrcpyWtoA( (LPSTR)*ptr, (LPWSTR)(lParam) );
746 HeapFree( GetProcessHeap(), 0, ptr );
747 }
748 }
749 break;
750
751/* Multiline edit */
752 case EM_GETLINE:
753 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
754 WORD len = *(WORD *) lParam;
755 lstrcpynWtoA( (LPSTR)*ptr , (LPWSTR)lParam, len );
756 HeapFree( GetProcessHeap(), 0, ptr );
757 }
758 break;
759 }
760}
761
762
763/**********************************************************************
764 * WINPROC_MapMsg32WTo32A
765 *
766 * Map a message from Unicode to Ansi.
767 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
768 */
769INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM *plparam)
770{ switch(msg)
771 {
772 case WM_GETTEXT:
773 {
774 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
775 wParam + sizeof(LPARAM) );
776 if (!ptr) return -1;
777 *ptr++ = *plparam; /* Store previous lParam */
778 *plparam = (LPARAM)ptr;
779 }
780 return 1;
781
782 case WM_SETTEXT:
783 case WM_WININICHANGE:
784 case CB_DIR:
785 case LB_DIR:
786 case LB_ADDFILE:
787#ifndef __WIN32OS2__
788 case CB_FINDSTRING:
789 case CB_FINDSTRINGEXACT:
790 case CB_SELECTSTRING:
791 case LB_FINDSTRING:
792 case LB_SELECTSTRING:
793#endif
794 case EM_REPLACESEL:
795 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
796 return (*plparam ? 1 : -1);
797
798 case WM_NCCREATE:
799 case WM_CREATE:
800 {
801 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
802 sizeof(*cs) );
803 if (!cs) return -1;
804 *cs = *(CREATESTRUCTA *)*plparam;
805 if (HIWORD(cs->lpszName))
806 cs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
807 (LPCWSTR)cs->lpszName );
808 if (HIWORD(cs->lpszClass))
809 cs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
810 (LPCWSTR)cs->lpszClass);
811 *plparam = (LPARAM)cs;
812 }
813 return 1;
814 case WM_MDICREATE:
815 {
816 MDICREATESTRUCTA *cs =
817 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
818
819 if (!cs) return -1;
820 *cs = *(MDICREATESTRUCTA *)*plparam;
821 if (HIWORD(cs->szTitle))
822 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
823 (LPCWSTR)cs->szTitle );
824 if (HIWORD(cs->szClass))
825 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
826 (LPCWSTR)cs->szClass );
827 *plparam = (LPARAM)cs;
828 }
829 return 1;
830
831/* Listbox */
832 case LB_ADDSTRING:
833#ifdef __WIN32OS2__
834 case LB_FINDSTRING:
835 case LB_FINDSTRINGEXACT:
836 case LB_SELECTSTRING:
837#endif
838 case LB_INSERTSTRING:
839 if ( WINPROC_TestLBForStr( hwnd ))
840 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
841 return (*plparam ? 1 : -1);
842
843 case LB_GETTEXT: /* fixme: fixed sized buffer */
844 { if ( WINPROC_TestLBForStr( hwnd ))
845 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
846 if (!ptr) return -1;
847 *ptr++ = *plparam; /* Store previous lParam */
848 *plparam = (LPARAM)ptr;
849 }
850 }
851 return 1;
852
853/* Combobox */
854 case CB_ADDSTRING:
855#ifdef __WIN32OS2__
856 case CB_FINDSTRING:
857 case CB_FINDSTRINGEXACT:
858 case CB_SELECTSTRING:
859#endif
860 case CB_INSERTSTRING:
861 if ( WINPROC_TestCBForStr( hwnd ))
862 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
863 return (*plparam ? 1 : -1);
864
865 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
866 { if ( WINPROC_TestCBForStr( hwnd ))
867 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
868 if (!ptr) return -1;
869 *ptr++ = *plparam; /* Store previous lParam */
870 *plparam = (LPARAM)ptr;
871 }
872 }
873 return 1;
874
875/* Multiline edit */
876 case EM_GETLINE:
877 { WORD len = (WORD)*plparam;
878 LPARAM *ptr = (LPARAM *) HEAP_xalloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
879 if (!ptr) return -1;
880 *ptr++ = *plparam; /* Store previous lParam */
881 *((WORD *) ptr) = len; /* Store the length */
882 *plparam = (LPARAM)ptr;
883 }
884 return 1;
885
886 case WM_ASKCBFORMATNAME:
887 case WM_DEVMODECHANGE:
888 case WM_PAINTCLIPBOARD:
889 case WM_SIZECLIPBOARD:
890 case EM_SETPASSWORDCHAR:
891 // FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg),msg );
892 return -1;
893 default: /* No translation needed */
894 return 0;
895 }
896}
897
898
899/**********************************************************************
900 * WINPROC_UnmapMsg32WTo32A
901 *
902 * Unmap a message that was mapped from Unicode to Ansi.
903 */
904void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
905{
906 switch(msg)
907 {
908 case WM_GETTEXT:
909 {
910 LPARAM *ptr = (LPARAM *)lParam - 1;
911 lstrcpynAtoW( (LPWSTR)*ptr, (LPSTR)lParam, wParam );
912 HeapFree( GetProcessHeap(), 0, ptr );
913 }
914 break;
915
916 case WM_SETTEXT:
917 case WM_WININICHANGE:
918 case CB_DIR:
919 case LB_DIR:
920 case LB_ADDFILE:
921#ifndef __WIN32OS2__
922 case CB_FINDSTRING:
923 case CB_FINDSTRINGEXACT:
924 case CB_SELECTSTRING:
925 case LB_FINDSTRING:
926 case LB_SELECTSTRING:
927#endif
928 case EM_REPLACESEL:
929 HeapFree( GetProcessHeap(), 0, (void *)lParam );
930 break;
931
932 case WM_NCCREATE:
933 case WM_CREATE:
934 {
935 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
936 if (HIWORD(cs->lpszName))
937 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
938 if (HIWORD(cs->lpszClass))
939 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
940 HeapFree( GetProcessHeap(), 0, cs );
941 }
942 break;
943
944 case WM_MDICREATE:
945 {
946 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
947 if (HIWORD(cs->szTitle))
948 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
949 if (HIWORD(cs->szClass))
950 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
951 HeapFree( GetProcessHeap(), 0, cs );
952 }
953 break;
954
955/* Listbox */
956 case LB_ADDSTRING:
957#ifdef __WIN32OS2__
958 case LB_FINDSTRING:
959 case LB_FINDSTRINGEXACT:
960 case LB_SELECTSTRING:
961#endif
962 case LB_INSERTSTRING:
963 if ( WINPROC_TestLBForStr( hwnd ))
964 HeapFree( GetProcessHeap(), 0, (void *)lParam );
965 break;
966
967 case LB_GETTEXT:
968 { if ( WINPROC_TestLBForStr( hwnd ))
969 { LPARAM *ptr = (LPARAM *)lParam - 1;
970 lstrcpyAtoW( (LPWSTR)*ptr, (LPSTR)(lParam) );
971 HeapFree(GetProcessHeap(), 0, ptr );
972 }
973 }
974 break;
975
976/* Combobox */
977 case CB_ADDSTRING:
978#ifdef __WIN32OS2__
979 case CB_FINDSTRING:
980 case CB_FINDSTRINGEXACT:
981 case CB_SELECTSTRING:
982#endif
983 case CB_INSERTSTRING:
984 if ( WINPROC_TestCBForStr( hwnd ))
985 HeapFree( GetProcessHeap(), 0, (void *)lParam );
986 break;
987
988 case CB_GETLBTEXT:
989 { if ( WINPROC_TestCBForStr( hwnd ))
990 { LPARAM *ptr = (LPARAM *)lParam - 1;
991 lstrcpyAtoW( (LPWSTR)*ptr, (LPSTR)(lParam) );
992 HeapFree( GetProcessHeap(), 0, ptr );
993 }
994 }
995 break;
996
997/* Multiline edit */
998 case EM_GETLINE:
999 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1000 WORD len = *(WORD *)ptr;
1001 lstrcpynAtoW( (LPWSTR) *ptr, (LPSTR)lParam, len );
1002 HeapFree( GetProcessHeap(), 0, ptr );
1003 }
1004 break;
1005 }
1006}
1007
1008/**********************************************************************
1009 * WINPROC_CallProc32ATo32W
1010 *
1011 * Call a window procedure, translating args from Ansi to Unicode.
1012 */
1013LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
1014 UINT msg, WPARAM wParam,
1015 LPARAM lParam )
1016{
1017 LRESULT result;
1018
1019 if (WINPROC_MapMsg32ATo32W( hwnd, msg, wParam, &lParam ) == -1) return 0;
1020 result = func( hwnd, msg, wParam, lParam );
1021 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
1022 return result;
1023}
1024
1025/**********************************************************************
1026 * WINPROC_CallProc32WTo32A
1027 *
1028 * Call a window procedure, translating args from Unicode to Ansi.
1029 */
1030LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
1031 UINT msg, WPARAM wParam,
1032 LPARAM lParam )
1033{
1034 LRESULT result;
1035
1036 if (WINPROC_MapMsg32WTo32A( hwnd, msg, wParam, &lParam ) == -1) return 0;
1037
1038 result = func( hwnd, msg, wParam, lParam );
1039 WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
1040 return result;
1041}
1042//******************************************************************************
1043//TODO: QS_HOTKEY (oslibmsg.cpp) & low word bits
1044//high word = messages currently in queue
1045//low word = messages that have been added to the queue and are still in the
1046// queue since the last call to GetQueueStatus
1047//******************************************************************************
1048DWORD WIN32API GetQueueStatus( UINT flags)
1049{
1050 DWORD queueStatus;
1051
1052 queueStatus = OSLibWinQueryQueueStatus();
1053 queueStatus = MAKELONG(queueStatus, queueStatus);
1054
1055 dprintf(("USER32: GetQueueStatus %x returned %x", flags, queueStatus & MAKELONG(flags, flags)));
1056
1057 return queueStatus & MAKELONG(flags, flags);
1058}
1059/*****************************************************************************
1060 * Name : BOOL WIN32API GetInputState
1061 * Purpose : The GetInputState function determines whether there are
1062 * mouse-button or keyboard messages in the calling thread's message queue.
1063 * Parameters:
1064 * Variables :
1065 * Result : If the queue contains one or more new mouse-button or keyboard
1066 * messages, the return value is TRUE.
1067 * If the function fails, the return value is FALSE.
1068 * Remark :
1069 * Status : UNTESTED STUB
1070 *
1071 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1072 *****************************************************************************/
1073BOOL WIN32API GetInputState(VOID)
1074{
1075 DWORD queueStatus;
1076 BOOL rc;
1077
1078 queueStatus = OSLibWinQueryQueueStatus();
1079
1080 rc = (queueStatus & (QS_KEY | QS_MOUSEBUTTON)) ? TRUE : FALSE;
1081 dprintf(("USER32:GetInputState() returned %d", rc));
1082 return rc;
1083}
1084//******************************************************************************
1085/* Synchronization Functions */
1086//******************************************************************************
1087DWORD WIN32API MsgWaitForMultipleObjects(DWORD nCount, LPHANDLE pHandles, BOOL fWaitAll,
1088 DWORD dwMilliseconds, DWORD dwWakeMask)
1089{
1090 DWORD curtime, endtime, ret;
1091 MSG msg;
1092
1093 dprintf(("MsgWaitForMultipleObjects %x %x %d %d %x", nCount, pHandles, fWaitAll, dwMilliseconds, dwWakeMask));
1094 // @@@PH this is a temporary bugfix for WINFILE.EXE
1095 if (nCount == 0)
1096 {
1097 if(dwMilliseconds == 0) {
1098 if(GetQueueStatus(dwWakeMask) == 0) {
1099 return WAIT_TIMEOUT;
1100 }
1101 return WAIT_OBJECT_0;
1102 }
1103 //SvL: Check time, wait for any message, check msg type and determine if
1104 // we have to return
1105 //TODO: Timeout isn't handled correctly (can return too late)
1106 curtime = GetCurrentTime();
1107 endtime = curtime + dwMilliseconds;
1108 while(curtime < endtime || dwMilliseconds == INFINITE) {
1109 if(OSLibWinWaitMessage() == FALSE) {
1110 dprintf(("OSLibWinWaitMessage returned FALSE!"));
1111 return WAIT_ABANDONED;
1112 }
1113 if(GetQueueStatus(dwWakeMask) != 0) {
1114 return WAIT_OBJECT_0;
1115 }
1116 //TODO: Ignoring all messages could be dangerous. But processing them,
1117 //while the app doesn't expect any, isn't safe either.
1118 if(PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
1119 {
1120 if (msg.message == WM_QUIT) {
1121 dprintf(("ERROR: MsgWaitForMultipleObjects call abandoned because WM_QUIT msg was received!!"));
1122 return WAIT_ABANDONED;
1123 }
1124
1125 /* otherwise dispatch it */
1126 DispatchMessageA(&msg);
1127 }
1128 curtime = GetCurrentTime();
1129 }
1130 return WAIT_TIMEOUT;
1131 }
1132 //SvL: Call handlemanager function as we need to translate handles
1133 //TODO: doesn't work at all if waiting for message
1134 ret = HMMsgWaitForMultipleObjects(nCount,pHandles,fWaitAll,dwMilliseconds,dwWakeMask);
1135 return ret;
1136}
Note: See TracBrowser for help on using the repository browser.