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

Last change on this file since 5124 was 5124, checked in by sandervl, 25 years ago

MN: fixed wrong listbox/combobox asci<->unicode translation for some messages

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