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

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

mouse message translation + dc reset after resize fixes

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