Added a more truthful message about what really is wrong.
[wine/multimedia.git] / windows / defwnd.c
blob0c230d41788e1cde4324814ea3ef903578476cbf
1 /*
2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
5 * 1995 Alex Korobka
6 */
8 #include <string.h>
10 #include "win.h"
11 #include "user.h"
12 #include "heap.h"
13 #include "nonclient.h"
14 #include "winpos.h"
15 #include "dce.h"
16 #include "debugtools.h"
17 #include "spy.h"
18 #include "tweak.h"
19 #include "cache.h"
20 #include "windef.h"
21 #include "wingdi.h"
22 #include "winnls.h"
23 #include "wine/unicode.h"
24 #include "wine/winuser16.h"
25 #include "imm.h"
27 DEFAULT_DEBUG_CHANNEL(win);
29 /* bits in the dwKeyData */
30 #define KEYDATA_ALT 0x2000
31 #define KEYDATA_PREVSTATE 0x4000
33 static short iF10Key = 0;
34 static short iMenuSysKey = 0;
36 /***********************************************************************
37 * DEFWND_HandleWindowPosChanged
39 * Handle the WM_WINDOWPOSCHANGED message.
41 static void DEFWND_HandleWindowPosChanged( WND *wndPtr, UINT flags )
43 WPARAM16 wp = SIZE_RESTORED;
45 if (!(flags & SWP_NOCLIENTMOVE))
46 SendMessage16( wndPtr->hwndSelf, WM_MOVE, 0,
47 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top));
48 if (!(flags & SWP_NOCLIENTSIZE))
50 if (wndPtr->dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
51 else if (wndPtr->dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
53 SendMessage16( wndPtr->hwndSelf, WM_SIZE, wp,
54 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
55 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
60 /***********************************************************************
61 * DEFWND_SetTextA
63 * Set the window text.
65 void DEFWND_SetTextA( WND *wndPtr, LPCSTR text )
67 int count;
69 if (!text) text = "";
70 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
72 if (wndPtr->text) HeapFree(SystemHeap, 0, wndPtr->text);
73 if ((wndPtr->text = HeapAlloc(SystemHeap, 0, count * sizeof(WCHAR))))
74 MultiByteToWideChar( CP_ACP, 0, text, -1, wndPtr->text, count );
75 else
76 ERR("Not enough memory for window text");
78 wndPtr->pDriver->pSetText(wndPtr, wndPtr->text);
81 /***********************************************************************
82 * DEFWND_SetTextW
84 * Set the window text.
86 void DEFWND_SetTextW( WND *wndPtr, LPCWSTR text )
88 static const WCHAR empty_string[] = {0};
89 int count;
91 if (!text) text = empty_string;
92 count = strlenW(text) + 1;
94 if (wndPtr->text) HeapFree(SystemHeap, 0, wndPtr->text);
95 if ((wndPtr->text = HeapAlloc(SystemHeap, 0, count * sizeof(WCHAR))))
96 strcpyW( wndPtr->text, text );
97 else
98 ERR("Not enough memory for window text");
100 wndPtr->pDriver->pSetText(wndPtr, wndPtr->text);
103 /***********************************************************************
104 * DEFWND_ControlColor
106 * Default colors for control painting.
108 HBRUSH DEFWND_ControlColor( HDC hDC, UINT16 ctlType )
110 if( ctlType == CTLCOLOR_SCROLLBAR)
112 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
113 if (TWEAK_WineLook == WIN31_LOOK) {
114 SetTextColor( hDC, RGB(0, 0, 0) );
115 SetBkColor( hDC, RGB(255, 255, 255) );
116 } else {
117 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
118 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
119 SetBkColor( hDC, bk);
121 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
122 * we better use 0x55aa bitmap brush to make scrollbar's background
123 * look different from the window background.
125 if (bk == GetSysColor(COLOR_WINDOW)) {
126 return CACHE_GetPattern55AABrush();
129 UnrealizeObject( hb );
130 return hb;
133 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
135 if (TWEAK_WineLook > WIN31_LOOK) {
136 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
137 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
138 else {
139 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
140 return GetSysColorBrush(COLOR_3DFACE);
143 else
144 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
145 return GetSysColorBrush(COLOR_WINDOW);
149 /***********************************************************************
150 * DEFWND_SetRedraw
152 static void DEFWND_SetRedraw( WND* wndPtr, WPARAM wParam )
154 BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
156 TRACE("%04x %i\n", wndPtr->hwndSelf, (wParam!=0) );
158 if( wParam )
160 if( !bVisible )
162 wndPtr->dwStyle |= WS_VISIBLE;
163 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
166 else if( bVisible )
168 if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
169 else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
171 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, wParam, 0 );
172 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
173 wndPtr->dwStyle &= ~WS_VISIBLE;
177 /***********************************************************************
178 * DEFWND_Print
180 * This method handles the default behavior for the WM_PRINT message.
182 static void DEFWND_Print(
183 WND* wndPtr,
184 HDC hdc,
185 ULONG uFlags)
188 * Visibility flag.
190 if ( (uFlags & PRF_CHECKVISIBLE) &&
191 !IsWindowVisible(wndPtr->hwndSelf) )
192 return;
195 * Unimplemented flags.
197 if ( (uFlags & PRF_CHILDREN) ||
198 (uFlags & PRF_OWNED) ||
199 (uFlags & PRF_NONCLIENT) )
201 WARN("WM_PRINT message with unsupported flags\n");
205 * Background
207 if ( uFlags & PRF_ERASEBKGND)
208 SendMessageA(wndPtr->hwndSelf, WM_ERASEBKGND, (WPARAM)hdc, 0);
211 * Client area
213 if ( uFlags & PRF_CLIENT)
214 SendMessageA(wndPtr->hwndSelf, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
219 * helpers for calling IMM32
221 * WM_IME_* messages are generated only by IMM32,
222 * so I assume imm32 is already LoadLibrary-ed.
224 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
226 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
227 HWND (WINAPI* pFunc)(HWND);
228 HWND hwndRet = 0;
230 if (!hInstIMM)
232 ERR( "cannot get IMM32 handle\n" );
233 return 0;
236 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
237 if ( pFunc != NULL )
238 hwndRet = (*pFunc)( hwnd );
240 return hwndRet;
243 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
245 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
246 BOOL (WINAPI* pFunc)(HWND,UINT,WPARAM,LPARAM);
247 BOOL fRet = FALSE;
249 if (!hInstIMM)
251 ERR( "cannot get IMM32 handle\n" );
252 return FALSE;
255 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
256 if ( pFunc != NULL )
257 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
259 return fRet;
262 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
264 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
265 BOOL (WINAPI* pFunc)(HWND,UINT,WPARAM,LPARAM);
266 BOOL fRet = FALSE;
268 if (!hInstIMM)
270 ERR( "cannot get IMM32 handle\n" );
271 return FALSE;
274 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
275 if ( pFunc != NULL )
276 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
278 return fRet;
283 /***********************************************************************
284 * DEFWND_DefWinProc
286 * Default window procedure for messages that are the same in Win16 and Win32.
288 static LRESULT DEFWND_DefWinProc( WND *wndPtr, UINT msg, WPARAM wParam,
289 LPARAM lParam )
291 switch(msg)
293 case WM_NCPAINT:
294 return NC_HandleNCPaint( wndPtr->hwndSelf, (HRGN)wParam );
296 case WM_NCHITTEST:
298 POINT pt;
299 pt.x = SLOWORD(lParam);
300 pt.y = SHIWORD(lParam);
301 return NC_HandleNCHitTest( wndPtr->hwndSelf, pt );
304 case WM_NCLBUTTONDOWN:
305 return NC_HandleNCLButtonDown( wndPtr, wParam, lParam );
307 case WM_LBUTTONDBLCLK:
308 case WM_NCLBUTTONDBLCLK:
309 return NC_HandleNCLButtonDblClk( wndPtr, wParam, lParam );
311 case WM_NCRBUTTONDOWN:
312 /* in Windows, capture is taken when right-clicking on the caption bar */
313 if (wParam==HTCAPTION)
315 SetCapture(wndPtr->hwndSelf);
317 break;
319 case WM_RBUTTONUP:
320 if (wndPtr->hwndSelf == GetCapture())
322 /* release capture if we took it on WM_NCRBUTTONDOWN */
323 ReleaseCapture();
325 if ((wndPtr->flags & WIN_ISWIN32) || (TWEAK_WineLook > WIN31_LOOK))
327 ClientToScreen16(wndPtr->hwndSelf, (LPPOINT16)&lParam);
328 SendMessageA( wndPtr->hwndSelf, WM_CONTEXTMENU,
329 wndPtr->hwndSelf, lParam);
331 break;
333 case WM_NCRBUTTONUP:
335 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
336 * in Windows), but what _should_ we do? According to MSDN :
337 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
338 * message to the window". When is it appropriate?
340 break;
342 case WM_CONTEXTMENU:
343 if( wndPtr->dwStyle & WS_CHILD )
344 SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam );
345 else if (wndPtr->hSysMenu)
347 LONG hitcode;
348 POINT pt;
349 pt.x = SLOWORD(lParam);
350 pt.y = SHIWORD(lParam);
353 * WM_CONTEXTMENU coordinates are relative to screen, but
354 * NC_HandleNCHitTest expects coordinates relative to the parent's
355 * client area (to compare with the rectangle returned by
356 * GetWindowRect)
358 if (wndPtr->parent)
359 ScreenToClient(wndPtr->parent->hwndSelf, &pt);
361 hitcode = NC_HandleNCHitTest(wndPtr->hwndSelf, pt);
363 /* Track system popup if click was in the caption area. */
364 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
365 TrackPopupMenu(GetSystemMenu(wndPtr->hwndSelf, FALSE),
366 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
367 pt.x, pt.y, 0, wndPtr->hwndSelf, NULL);
369 break;
371 case WM_NCACTIVATE:
372 return NC_HandleNCActivate( wndPtr, wParam );
374 case WM_NCDESTROY:
375 if (wndPtr->text) HeapFree( SystemHeap, 0, wndPtr->text );
376 wndPtr->text = NULL;
377 if (wndPtr->pVScroll) HeapFree( SystemHeap, 0, wndPtr->pVScroll );
378 if (wndPtr->pHScroll) HeapFree( SystemHeap, 0, wndPtr->pHScroll );
379 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
380 return 0;
382 case WM_PRINT:
383 DEFWND_Print(wndPtr, (HDC)wParam, lParam);
384 return 0;
386 case WM_PAINTICON:
387 case WM_PAINT:
389 PAINTSTRUCT16 ps;
390 HDC16 hdc = BeginPaint16( wndPtr->hwndSelf, &ps );
391 if( hdc )
393 HICON hIcon;
394 if( (wndPtr->dwStyle & WS_MINIMIZE) && ((hIcon = GetClassLongA( wndPtr->hwndSelf, GCL_HICON))) )
396 int x = (wndPtr->rectWindow.right - wndPtr->rectWindow.left -
397 GetSystemMetrics(SM_CXICON))/2;
398 int y = (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top -
399 GetSystemMetrics(SM_CYICON))/2;
400 TRACE("Painting class icon: vis rect=(%i,%i - %i,%i)\n",
401 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
402 DrawIcon( hdc, x, y, hIcon );
404 EndPaint16( wndPtr->hwndSelf, &ps );
406 return 0;
409 case WM_SYNCPAINT:
410 if (wndPtr->hrgnUpdate)
412 RedrawWindow ( wndPtr->hwndSelf, 0, wndPtr->hrgnUpdate,
413 RDW_ERASENOW | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
415 return 0;
417 case WM_SETREDRAW:
418 DEFWND_SetRedraw( wndPtr, wParam );
419 return 0;
421 case WM_CLOSE:
422 DestroyWindow( wndPtr->hwndSelf );
423 return 0;
425 case WM_MOUSEACTIVATE:
426 if (wndPtr->dwStyle & WS_CHILD)
428 LONG ret = SendMessage16( wndPtr->parent->hwndSelf,
429 WM_MOUSEACTIVATE, wParam, lParam );
430 if (ret) return ret;
433 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
434 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
436 case WM_ACTIVATE:
437 /* The default action in Windows is to set the keyboard focus to
438 * the window, if it's being activated and not minimized */
439 if (LOWORD(wParam) != WA_INACTIVE) {
440 if (!(wndPtr->dwStyle & WS_MINIMIZE))
441 SetFocus(wndPtr->hwndSelf);
443 break;
445 case WM_MOUSEWHEEL:
446 if (wndPtr->dwStyle & WS_CHILD)
448 return SendMessageA( wndPtr->parent->hwndSelf,
449 WM_MOUSEWHEEL, wParam, lParam );
451 break;
453 case WM_ERASEBKGND:
454 case WM_ICONERASEBKGND:
456 RECT rect;
457 HBRUSH hbr = GetClassLongA( wndPtr->hwndSelf, GCL_HBRBACKGROUND );
458 if (!hbr) return 0;
460 /* Since WM_ERASEBKGND may receive either a window dc or a */
461 /* client dc, the area to be erased has to be retrieved from */
462 /* the device context. */
463 GetClipBox( (HDC)wParam, &rect );
465 /* Always call the Win32 variant of FillRect even on Win16,
466 * since despite the fact that Win16, as well as Win32,
467 * supports special background brushes for a window class,
468 * the Win16 variant of FillRect does not.
470 FillRect( (HDC) wParam, &rect, hbr );
471 return 1;
474 case WM_GETDLGCODE:
475 return 0;
477 case WM_CTLCOLORMSGBOX:
478 case WM_CTLCOLOREDIT:
479 case WM_CTLCOLORLISTBOX:
480 case WM_CTLCOLORBTN:
481 case WM_CTLCOLORDLG:
482 case WM_CTLCOLORSTATIC:
483 case WM_CTLCOLORSCROLLBAR:
484 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
486 case WM_CTLCOLOR:
487 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
489 case WM_GETTEXTLENGTH:
490 if (wndPtr->text) return (LRESULT)strlenW(wndPtr->text);
491 return 0;
493 case WM_SETCURSOR:
494 if (wndPtr->dwStyle & WS_CHILD)
495 if (SendMessage16(wndPtr->parent->hwndSelf, WM_SETCURSOR,
496 wParam, lParam))
497 return TRUE;
498 return NC_HandleSetCursor( wndPtr->hwndSelf, wParam, lParam );
500 case WM_SYSCOMMAND:
502 POINT pt;
503 pt.x = SLOWORD(lParam);
504 pt.y = SHIWORD(lParam);
505 return NC_HandleSysCommand( wndPtr->hwndSelf, wParam, pt );
508 case WM_KEYDOWN:
509 if(wParam == VK_F10) iF10Key = VK_F10;
510 break;
512 case WM_SYSKEYDOWN:
513 if( HIWORD(lParam) & KEYDATA_ALT )
515 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
516 if( wParam == VK_MENU && !iMenuSysKey )
517 iMenuSysKey = 1;
518 else
519 iMenuSysKey = 0;
521 iF10Key = 0;
523 if( wParam == VK_F4 ) /* try to close the window */
525 HWND hWnd = WIN_GetTopParent( wndPtr->hwndSelf );
526 wndPtr = WIN_FindWndPtr( hWnd );
527 if( wndPtr && !(wndPtr->clsStyle & CS_NOCLOSE) )
528 PostMessage16( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 );
529 WIN_ReleaseWndPtr(wndPtr);
532 else if( wParam == VK_F10 )
533 iF10Key = 1;
534 else
535 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
536 SendMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
537 (WPARAM16)SC_KEYMENU, (LPARAM)VK_SPACE);
538 break;
540 case WM_KEYUP:
541 case WM_SYSKEYUP:
542 /* Press and release F10 or ALT */
543 if (((wParam == VK_MENU) && iMenuSysKey) ||
544 ((wParam == VK_F10) && iF10Key))
545 SendMessage16( WIN_GetTopParent(wndPtr->hwndSelf),
546 WM_SYSCOMMAND, SC_KEYMENU, 0L );
547 iMenuSysKey = iF10Key = 0;
548 break;
550 case WM_SYSCHAR:
551 iMenuSysKey = 0;
552 if (wParam == VK_RETURN && (wndPtr->dwStyle & WS_MINIMIZE))
554 PostMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
555 (WPARAM16)SC_RESTORE, 0L );
556 break;
558 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
560 if (wParam == VK_TAB || wParam == VK_ESCAPE) break;
561 if (wParam == VK_SPACE && (wndPtr->dwStyle & WS_CHILD))
562 SendMessage16( wndPtr->parent->hwndSelf, msg, wParam, lParam );
563 else
564 SendMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
565 (WPARAM16)SC_KEYMENU, (LPARAM)(DWORD)wParam );
567 else /* check for Ctrl-Esc */
568 if (wParam != VK_ESCAPE) MessageBeep(0);
569 break;
571 case WM_SHOWWINDOW:
572 if (!lParam) return 0; /* sent from ShowWindow */
573 if (!(wndPtr->dwStyle & WS_POPUP) || !wndPtr->owner) return 0;
574 if ((wndPtr->dwStyle & WS_VISIBLE) && wParam) return 0;
575 else if (!(wndPtr->dwStyle & WS_VISIBLE) && !wParam) return 0;
576 ShowWindow( wndPtr->hwndSelf, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
577 break;
579 case WM_CANCELMODE:
580 if (wndPtr->parent == WIN_GetDesktop()) EndMenu();
581 if (GetCapture() == wndPtr->hwndSelf) ReleaseCapture();
582 WIN_ReleaseDesktop();
583 break;
585 case WM_VKEYTOITEM:
586 case WM_CHARTOITEM:
587 return -1;
589 case WM_DROPOBJECT:
590 return DRAG_FILE;
592 case WM_QUERYDROPOBJECT:
593 if (wndPtr->dwExStyle & WS_EX_ACCEPTFILES) return 1;
594 break;
596 case WM_QUERYDRAGICON:
598 UINT16 len;
600 HICON hIcon = GetClassLongA( wndPtr->hwndSelf, GCL_HICON );
601 if (hIcon) return hIcon;
602 for(len=1; len<64; len++)
603 if((hIcon=LoadIconA(wndPtr->hInstance,MAKEINTRESOURCEA(len))))
604 return (LRESULT)hIcon;
605 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
607 break;
609 case WM_ISACTIVEICON:
610 return ((wndPtr->flags & WIN_NCACTIVATED) != 0);
612 case WM_NOTIFYFORMAT:
613 if (IsWindowUnicode(wndPtr->hwndSelf)) return NFR_UNICODE;
614 else return NFR_ANSI;
616 case WM_QUERYOPEN:
617 case WM_QUERYENDSESSION:
618 return 1;
620 case WM_SETICON:
622 int index = (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM;
623 HICON16 hOldIcon = GetClassLongA(wndPtr->hwndSelf, index);
624 SetClassLongA(wndPtr->hwndSelf, index, lParam);
626 SetWindowPos(wndPtr->hwndSelf, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
627 | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE
628 | SWP_NOZORDER);
630 if( wndPtr->flags & WIN_NATIVE )
631 wndPtr->pDriver->pSetHostAttr(wndPtr, HAK_ICONS, 0);
633 return hOldIcon;
636 case WM_GETICON:
638 int index = (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM;
639 return GetClassLongA(wndPtr->hwndSelf, index);
642 case WM_HELP:
643 SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam );
644 break;
647 return 0;
652 /***********************************************************************
653 * DefWindowProc (USER.107)
655 LRESULT WINAPI DefWindowProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
656 LPARAM lParam )
658 WND * wndPtr = WIN_FindWndPtr( hwnd );
659 LRESULT result = 0;
661 if (!wndPtr) return 0;
662 SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
664 switch(msg)
666 case WM_NCCREATE:
668 CREATESTRUCT16 *cs = MapSL(lParam);
669 if (cs->lpszName)
670 DEFWND_SetTextA( wndPtr, MapSL(cs->lpszName) );
671 result = 1;
673 break;
675 case WM_NCCALCSIZE:
677 RECT rect32;
678 CONV_RECT16TO32( MapSL(lParam), &rect32 );
679 result = NC_HandleNCCalcSize( wndPtr, &rect32 );
680 CONV_RECT32TO16( &rect32, MapSL(lParam) );
682 break;
684 case WM_WINDOWPOSCHANGING:
685 result = WINPOS_HandleWindowPosChanging16( wndPtr, MapSL(lParam) );
686 break;
688 case WM_WINDOWPOSCHANGED:
690 WINDOWPOS16 * winPos = MapSL(lParam);
691 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
693 break;
695 case WM_GETTEXT:
696 if (wParam && wndPtr->text)
698 LPSTR dest = MapSL(lParam);
699 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1, dest, wParam, NULL, NULL ))
700 dest[wParam-1] = 0;
701 result = strlen(dest);
703 break;
705 case WM_SETTEXT:
706 DEFWND_SetTextA( wndPtr, MapSL(lParam) );
707 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
708 NC_HandleNCPaint( hwnd , (HRGN)1 );
709 result = 1; /* success. FIXME: check text length */
710 break;
712 default:
713 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam );
714 break;
717 WIN_ReleaseWndPtr(wndPtr);
718 SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result, wParam, lParam );
719 return result;
723 /***********************************************************************
724 * DefWindowProcA (USER32.@)
727 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam,
728 LPARAM lParam )
730 WND * wndPtr = WIN_FindWndPtr( hwnd );
731 LRESULT result = 0;
733 if (!wndPtr) return 0;
734 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
736 switch(msg)
738 case WM_NCCREATE:
740 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
741 if (cs->lpszName) DEFWND_SetTextA( wndPtr, cs->lpszName );
742 result = 1;
744 break;
746 case WM_NCCALCSIZE:
747 result = NC_HandleNCCalcSize( wndPtr, (RECT *)lParam );
748 break;
750 case WM_WINDOWPOSCHANGING:
751 result = WINPOS_HandleWindowPosChanging( wndPtr,
752 (WINDOWPOS *)lParam );
753 break;
755 case WM_WINDOWPOSCHANGED:
757 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
758 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
760 break;
762 case WM_GETTEXT:
763 if (wParam && wndPtr->text)
765 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
766 (LPSTR)lParam, wParam, NULL, NULL ))
767 ((LPSTR)lParam)[wParam-1] = 0;
768 result = (LRESULT)strlen( (LPSTR)lParam );
770 break;
772 case WM_SETTEXT:
773 DEFWND_SetTextA( wndPtr, (LPCSTR)lParam );
774 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
775 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
776 result = 1; /* success. FIXME: check text length */
777 break;
779 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
780 case WM_IME_CHAR:
782 CHAR chChar1 = (CHAR)( (wParam>>8) & 0xff );
783 CHAR chChar2 = (CHAR)( wParam & 0xff );
785 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar1, lParam );
786 if ( IsDBCSLeadByte( chChar1 ) )
787 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar2, lParam );
789 break;
790 case WM_IME_KEYDOWN:
791 result = SendMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
792 break;
793 case WM_IME_KEYUP:
794 result = SendMessageA( hwnd, WM_KEYUP, wParam, lParam );
795 break;
797 case WM_IME_STARTCOMPOSITION:
798 case WM_IME_COMPOSITION:
799 case WM_IME_ENDCOMPOSITION:
800 case WM_IME_SELECT:
802 HWND hwndIME;
804 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
805 if (hwndIME)
806 result = SendMessageA( hwndIME, msg, wParam, lParam );
808 break;
809 case WM_IME_SETCONTEXT:
811 HWND hwndIME;
813 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
814 if (hwndIME)
815 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
817 break;
819 default:
820 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam );
821 break;
824 WIN_ReleaseWndPtr(wndPtr);
825 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
826 return result;
830 /***********************************************************************
831 * DefWindowProcW (USER32.@) Calls default window message handler
833 * Calls default window procedure for messages not processed
834 * by application.
836 * RETURNS
837 * Return value is dependent upon the message.
839 LRESULT WINAPI DefWindowProcW(
840 HWND hwnd, /* [in] window procedure recieving message */
841 UINT msg, /* [in] message identifier */
842 WPARAM wParam, /* [in] first message parameter */
843 LPARAM lParam ) /* [in] second message parameter */
845 WND * wndPtr = WIN_FindWndPtr( hwnd );
846 LRESULT result = 0;
848 if (!wndPtr) return 0;
849 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
851 switch(msg)
853 case WM_NCCREATE:
855 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
856 if (cs->lpszName) DEFWND_SetTextW( wndPtr, cs->lpszName );
857 result = 1;
859 break;
861 case WM_GETTEXT:
862 if (wParam && wndPtr->text)
864 lstrcpynW( (LPWSTR)lParam, wndPtr->text, wParam );
865 result = strlenW( (LPWSTR)lParam );
867 break;
869 case WM_SETTEXT:
870 DEFWND_SetTextW( wndPtr, (LPCWSTR)lParam );
871 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
872 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
873 result = 1; /* success. FIXME: check text length */
874 break;
876 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
877 case WM_IME_CHAR:
878 SendMessageW( hwnd, WM_CHAR, wParam, lParam );
879 break;
880 case WM_IME_SETCONTEXT:
882 HWND hwndIME;
884 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
885 if (hwndIME)
886 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
888 break;
890 default:
891 result = DefWindowProcA( hwnd, msg, wParam, lParam );
892 break;
894 WIN_ReleaseWndPtr(wndPtr);
895 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
896 return result;