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

Last change on this file since 2084 was 2084, checked in by sandervl, 26 years ago

sendmessage + hook updates + misc fixes

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