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

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

Dinput additions + PostThreadMessageA/W fix

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