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

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

reference count (window + class objects) rewrite

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