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

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

several fixes + changes

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