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

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

hittest workaround for static controls + registerwindowmessage rewrite

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