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

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

desktop + misc updates

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