Moved scrollbar tracking code to scroll.c.
[wine/multimedia.git] / windows / defwnd.c
blob69649cc48c1cffbb741ca6bad4f62426276d35d3
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 "nonclient.h"
13 #include "winpos.h"
14 #include "dce.h"
15 #include "debugtools.h"
16 #include "spy.h"
17 #include "windef.h"
18 #include "wingdi.h"
19 #include "winnls.h"
20 #include "wine/unicode.h"
21 #include "wine/winuser16.h"
22 #include "imm.h"
24 DEFAULT_DEBUG_CHANNEL(win);
26 /* bits in the dwKeyData */
27 #define KEYDATA_ALT 0x2000
28 #define KEYDATA_PREVSTATE 0x4000
30 static short iF10Key = 0;
31 static short iMenuSysKey = 0;
33 /***********************************************************************
34 * DEFWND_HandleWindowPosChanged
36 * Handle the WM_WINDOWPOSCHANGED message.
38 static void DEFWND_HandleWindowPosChanged( HWND hwnd, UINT flags )
40 RECT rect;
41 WND *wndPtr = WIN_GetPtr( hwnd );
43 rect = wndPtr->rectClient;
44 WIN_ReleasePtr( wndPtr );
46 if (!(flags & SWP_NOCLIENTMOVE))
47 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG(rect.left, rect.top));
49 if (!(flags & SWP_NOCLIENTSIZE))
51 WPARAM wp = SIZE_RESTORED;
52 if (IsZoomed(hwnd)) wp = SIZE_MAXIMIZED;
53 else if (IsIconic(hwnd)) wp = SIZE_MINIMIZED;
55 SendMessageW( hwnd, WM_SIZE, wp, MAKELONG(rect.right-rect.left, rect.bottom-rect.top) );
60 /***********************************************************************
61 * DEFWND_SetTextA
63 * Set the window text.
65 static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
67 int count;
68 WCHAR *textW;
69 WND *wndPtr;
71 if (!text) text = "";
72 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
74 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return;
75 if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
76 if ((wndPtr->text = textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
77 MultiByteToWideChar( CP_ACP, 0, text, -1, wndPtr->text, count );
78 else
79 ERR("Not enough memory for window text\n");
80 WIN_ReleaseWndPtr( wndPtr );
82 if (USER_Driver.pSetWindowText) USER_Driver.pSetWindowText( hwnd, textW );
85 /***********************************************************************
86 * DEFWND_SetTextW
88 * Set the window text.
90 static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
92 static const WCHAR empty_string[] = {0};
93 WND *wndPtr;
94 int count;
96 if (!text) text = empty_string;
97 count = strlenW(text) + 1;
99 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
100 if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
101 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
102 strcpyW( wndPtr->text, text );
103 else
104 ERR("Not enough memory for window text\n");
105 text = wndPtr->text;
106 WIN_ReleasePtr( wndPtr );
108 if (USER_Driver.pSetWindowText) USER_Driver.pSetWindowText( hwnd, text );
111 /***********************************************************************
112 * DEFWND_ControlColor
114 * Default colors for control painting.
116 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
118 if( ctlType == CTLCOLOR_SCROLLBAR)
120 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
121 if (TWEAK_WineLook == WIN31_LOOK) {
122 SetTextColor( hDC, RGB(0, 0, 0) );
123 SetBkColor( hDC, RGB(255, 255, 255) );
124 } else {
125 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
126 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
127 SetBkColor( hDC, bk);
129 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
130 * we better use 0x55aa bitmap brush to make scrollbar's background
131 * look different from the window background.
133 if (bk == GetSysColor(COLOR_WINDOW)) {
134 return CACHE_GetPattern55AABrush();
137 UnrealizeObject( hb );
138 return hb;
141 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
143 if (TWEAK_WineLook > WIN31_LOOK) {
144 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
145 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
146 else {
147 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
148 return GetSysColorBrush(COLOR_3DFACE);
151 else
152 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
153 return GetSysColorBrush(COLOR_WINDOW);
157 /***********************************************************************
158 * DEFWND_SetRedraw
160 static void DEFWND_SetRedraw( HWND hwnd, WPARAM wParam )
162 WND *wndPtr = WIN_FindWndPtr( hwnd );
163 BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
165 TRACE("%04x %i\n", hwnd, (wParam!=0) );
167 if( wParam )
169 if( !bVisible )
171 wndPtr->dwStyle |= WS_VISIBLE;
172 if (USER_Driver.pSetWindowStyle)
173 USER_Driver.pSetWindowStyle( hwnd, wndPtr->dwStyle & ~WS_VISIBLE );
174 DCE_InvalidateDCE( hwnd, &wndPtr->rectWindow );
177 else if( bVisible )
179 if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
180 else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
182 RedrawWindow( hwnd, NULL, 0, wParam );
183 DCE_InvalidateDCE( hwnd, &wndPtr->rectWindow );
184 wndPtr->dwStyle &= ~WS_VISIBLE;
185 if (USER_Driver.pSetWindowStyle)
186 USER_Driver.pSetWindowStyle( hwnd, wndPtr->dwStyle | WS_VISIBLE );
188 WIN_ReleaseWndPtr( wndPtr );
191 /***********************************************************************
192 * DEFWND_Print
194 * This method handles the default behavior for the WM_PRINT message.
196 static void DEFWND_Print( HWND hwnd, HDC hdc, ULONG uFlags)
199 * Visibility flag.
201 if ( (uFlags & PRF_CHECKVISIBLE) &&
202 !IsWindowVisible(hwnd) )
203 return;
206 * Unimplemented flags.
208 if ( (uFlags & PRF_CHILDREN) ||
209 (uFlags & PRF_OWNED) ||
210 (uFlags & PRF_NONCLIENT) )
212 WARN("WM_PRINT message with unsupported flags\n");
216 * Background
218 if ( uFlags & PRF_ERASEBKGND)
219 SendMessageW(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
222 * Client area
224 if ( uFlags & PRF_CLIENT)
225 SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
230 * helpers for calling IMM32
232 * WM_IME_* messages are generated only by IMM32,
233 * so I assume imm32 is already LoadLibrary-ed.
235 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
237 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
238 HWND WINAPI (*pFunc)(HWND);
239 HWND hwndRet = 0;
241 if (!hInstIMM)
243 ERR( "cannot get IMM32 handle\n" );
244 return 0;
247 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
248 if ( pFunc != NULL )
249 hwndRet = (*pFunc)( hwnd );
251 return hwndRet;
254 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
256 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
257 BOOL WINAPI (*pFunc)(HWND,UINT,WPARAM,LPARAM);
258 BOOL fRet = FALSE;
260 if (!hInstIMM)
262 ERR( "cannot get IMM32 handle\n" );
263 return FALSE;
266 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
267 if ( pFunc != NULL )
268 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
270 return fRet;
273 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
275 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
276 BOOL WINAPI (*pFunc)(HWND,UINT,WPARAM,LPARAM);
277 BOOL fRet = FALSE;
279 if (!hInstIMM)
281 ERR( "cannot get IMM32 handle\n" );
282 return FALSE;
285 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
286 if ( pFunc != NULL )
287 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
289 return fRet;
294 /***********************************************************************
295 * DEFWND_DefWinProc
297 * Default window procedure for messages that are the same in Win16 and Win32.
299 static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
301 switch(msg)
303 case WM_NCPAINT:
304 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
306 case WM_NCHITTEST:
308 POINT pt;
309 pt.x = SLOWORD(lParam);
310 pt.y = SHIWORD(lParam);
311 return NC_HandleNCHitTest( hwnd, pt );
314 case WM_NCLBUTTONDOWN:
315 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
317 case WM_LBUTTONDBLCLK:
318 case WM_NCLBUTTONDBLCLK:
319 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
321 case WM_NCRBUTTONDOWN:
322 /* in Windows, capture is taken when right-clicking on the caption bar */
323 if (wParam==HTCAPTION)
325 SetCapture(hwnd);
327 break;
329 case WM_RBUTTONUP:
331 POINT pt;
333 if (hwnd == GetCapture())
334 /* release capture if we took it on WM_NCRBUTTONDOWN */
335 ReleaseCapture();
337 pt.x = SLOWORD(lParam);
338 pt.y = SHIWORD(lParam);
339 ClientToScreen(hwnd, &pt);
340 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
342 break;
344 case WM_NCRBUTTONUP:
346 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
347 * in Windows), but what _should_ we do? According to MSDN :
348 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
349 * message to the window". When is it appropriate?
351 break;
353 case WM_CONTEXTMENU:
354 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
355 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
356 else
358 LONG hitcode;
359 POINT pt;
360 WND *wndPtr = WIN_GetPtr( hwnd );
361 HMENU hMenu = wndPtr->hSysMenu;
362 WIN_ReleasePtr( wndPtr );
363 if (!hMenu) return 0;
364 pt.x = SLOWORD(lParam);
365 pt.y = SHIWORD(lParam);
366 hitcode = NC_HandleNCHitTest(hwnd, pt);
368 /* Track system popup if click was in the caption area. */
369 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
370 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
371 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
372 pt.x, pt.y, 0, hwnd, NULL);
374 break;
376 case WM_NCACTIVATE:
377 return NC_HandleNCActivate( hwnd, wParam );
379 case WM_NCDESTROY:
381 WND *wndPtr = WIN_GetPtr( hwnd );
382 if (!wndPtr) return 0;
383 if (wndPtr->text) HeapFree( GetProcessHeap(), 0, wndPtr->text );
384 wndPtr->text = NULL;
385 if (wndPtr->pVScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pVScroll );
386 if (wndPtr->pHScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pHScroll );
387 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
388 WIN_ReleasePtr( wndPtr );
389 return 0;
392 case WM_PRINT:
393 DEFWND_Print(hwnd, (HDC)wParam, lParam);
394 return 0;
396 case WM_PAINTICON:
397 case WM_PAINT:
399 PAINTSTRUCT ps;
400 HDC hdc = BeginPaint( hwnd, &ps );
401 if( hdc )
403 HICON hIcon;
404 if (IsIconic(hwnd) && ((hIcon = GetClassLongW( hwnd, GCL_HICON))) )
406 RECT rc;
407 int x, y;
409 GetClientRect( hwnd, &rc );
410 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
411 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
412 TRACE("Painting class icon: vis rect=(%i,%i - %i,%i)\n",
413 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
414 DrawIcon( hdc, x, y, hIcon );
416 EndPaint( hwnd, &ps );
418 return 0;
421 case WM_SYNCPAINT:
422 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
423 return 0;
425 case WM_SETREDRAW:
426 DEFWND_SetRedraw( hwnd, wParam );
427 return 0;
429 case WM_CLOSE:
430 DestroyWindow( hwnd );
431 return 0;
433 case WM_MOUSEACTIVATE:
434 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
436 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
437 if (ret) return ret;
440 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
441 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
443 case WM_ACTIVATE:
444 /* The default action in Windows is to set the keyboard focus to
445 * the window, if it's being activated and not minimized */
446 if (LOWORD(wParam) != WA_INACTIVE) {
447 if (!IsIconic(hwnd)) SetFocus(hwnd);
449 break;
451 case WM_MOUSEWHEEL:
452 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
453 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
454 break;
456 case WM_ERASEBKGND:
457 case WM_ICONERASEBKGND:
459 RECT rect;
460 HDC hdc = (HDC)wParam;
461 HBRUSH hbr = GetClassLongW( hwnd, GCL_HBRBACKGROUND );
462 if (!hbr) return 0;
464 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
466 /* can't use GetClipBox with a parent DC or we fill the whole parent */
467 GetClientRect( hwnd, &rect );
468 DPtoLP( hdc, (LPPOINT)&rect, 2 );
470 else GetClipBox( hdc, &rect );
471 FillRect( hdc, &rect, hbr );
472 return 1;
475 case WM_GETDLGCODE:
476 return 0;
478 case WM_CTLCOLORMSGBOX:
479 case WM_CTLCOLOREDIT:
480 case WM_CTLCOLORLISTBOX:
481 case WM_CTLCOLORBTN:
482 case WM_CTLCOLORDLG:
483 case WM_CTLCOLORSTATIC:
484 case WM_CTLCOLORSCROLLBAR:
485 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
487 case WM_CTLCOLOR:
488 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
490 case WM_SETCURSOR:
491 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
493 /* with the exception of the border around a resizable wnd,
494 * give the parent first chance to set the cursor */
495 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
497 if (SendMessageW(GetParent(hwnd), WM_SETCURSOR, wParam, lParam)) return TRUE;
500 return NC_HandleSetCursor( hwnd, wParam, lParam );
502 case WM_SYSCOMMAND:
503 return NC_HandleSysCommand( hwnd, wParam, lParam );
505 case WM_KEYDOWN:
506 if(wParam == VK_F10) iF10Key = VK_F10;
507 break;
509 case WM_SYSKEYDOWN:
510 if( HIWORD(lParam) & KEYDATA_ALT )
512 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
513 if( wParam == VK_MENU && !iMenuSysKey )
514 iMenuSysKey = 1;
515 else
516 iMenuSysKey = 0;
518 iF10Key = 0;
520 if( wParam == VK_F4 ) /* try to close the window */
522 HWND top = GetAncestor( hwnd, GA_ROOT );
523 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
524 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
527 else if( wParam == VK_F10 )
528 iF10Key = 1;
529 else
530 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
531 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE );
532 break;
534 case WM_KEYUP:
535 case WM_SYSKEYUP:
536 /* Press and release F10 or ALT */
537 if (((wParam == VK_MENU) && iMenuSysKey) ||
538 ((wParam == VK_F10) && iF10Key))
539 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
540 iMenuSysKey = iF10Key = 0;
541 break;
543 case WM_SYSCHAR:
544 iMenuSysKey = 0;
545 if (wParam == VK_RETURN && IsIconic(hwnd))
547 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
548 break;
550 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
552 if (wParam == VK_TAB || wParam == VK_ESCAPE) break;
553 if (wParam == VK_SPACE && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
554 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
555 else
556 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
558 else /* check for Ctrl-Esc */
559 if (wParam != VK_ESCAPE) MessageBeep(0);
560 break;
562 case WM_SHOWWINDOW:
564 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
565 if (!lParam) return 0; /* sent from ShowWindow */
566 if (!(style & WS_POPUP)) return 0;
567 if ((style & WS_VISIBLE) && wParam) return 0;
568 if (!(style & WS_VISIBLE) && !wParam) return 0;
569 if (!GetWindow( hwnd, GW_OWNER )) return 0;
570 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
571 break;
574 case WM_CANCELMODE:
575 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
576 if (GetCapture() == hwnd) ReleaseCapture();
577 break;
579 case WM_VKEYTOITEM:
580 case WM_CHARTOITEM:
581 return -1;
583 case WM_DROPOBJECT:
584 return DRAG_FILE;
586 case WM_QUERYDROPOBJECT:
587 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
589 case WM_QUERYDRAGICON:
591 UINT len;
593 HICON hIcon = GetClassLongW( hwnd, GCL_HICON );
594 HINSTANCE instance = GetWindowLongW( hwnd, GWL_HINSTANCE );
595 if (hIcon) return hIcon;
596 for(len=1; len<64; len++)
597 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
598 return (LRESULT)hIcon;
599 return (LRESULT)LoadIconW(0, IDI_APPLICATIONW);
601 break;
603 case WM_ISACTIVEICON:
605 WND *wndPtr = WIN_GetPtr( hwnd );
606 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
607 WIN_ReleasePtr( wndPtr );
608 return ret;
611 case WM_NOTIFYFORMAT:
612 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
613 else return NFR_ANSI;
615 case WM_QUERYOPEN:
616 case WM_QUERYENDSESSION:
617 return 1;
619 case WM_SETICON:
620 if (USER_Driver.pSetWindowIcon)
621 return USER_Driver.pSetWindowIcon( hwnd, lParam, (wParam != ICON_SMALL) );
622 else
624 HICON hOldIcon = SetClassLongW( hwnd, (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM,
625 lParam);
626 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE |
627 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
628 return hOldIcon;
631 case WM_GETICON:
632 return GetClassLongW( hwnd, (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM );
634 case WM_HELP:
635 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
636 break;
639 return 0;
644 /***********************************************************************
645 * DefWindowProc (USER.107)
647 LRESULT WINAPI DefWindowProc16( HWND16 hwnd16, UINT16 msg, WPARAM16 wParam,
648 LPARAM lParam )
650 LRESULT result = 0;
651 HWND hwnd = WIN_Handle32( hwnd16 );
653 if (!WIN_IsCurrentProcess( hwnd ))
655 if (!IsWindow( hwnd )) return 0;
656 ERR( "called for other process window %x\n", hwnd );
657 return 0;
659 SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
661 switch(msg)
663 case WM_NCCREATE:
665 CREATESTRUCT16 *cs = MapSL(lParam);
666 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
667 * may have child window IDs instead of window name */
668 if (HIWORD(cs->lpszName))
669 DEFWND_SetTextA( hwnd, MapSL(cs->lpszName) );
670 result = 1;
672 break;
674 case WM_NCCALCSIZE:
676 RECT rect32;
677 CONV_RECT16TO32( MapSL(lParam), &rect32 );
678 result = NC_HandleNCCalcSize( hwnd, &rect32 );
679 CONV_RECT32TO16( &rect32, MapSL(lParam) );
681 break;
683 case WM_WINDOWPOSCHANGING:
684 result = WINPOS_HandleWindowPosChanging16( hwnd, MapSL(lParam) );
685 break;
687 case WM_WINDOWPOSCHANGED:
689 WINDOWPOS16 * winPos = MapSL(lParam);
690 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
692 break;
694 case WM_GETTEXT:
695 case WM_SETTEXT:
696 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)MapSL(lParam) );
697 break;
699 default:
700 result = DefWindowProcA( hwnd, msg, wParam, lParam );
701 break;
704 SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result, wParam, lParam );
705 return result;
709 /***********************************************************************
710 * DefWindowProcA (USER32.@)
713 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
715 LRESULT result = 0;
716 HWND full_handle;
718 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
720 if (!IsWindow( hwnd )) return 0;
721 ERR( "called for other process window %x\n", hwnd );
722 return 0;
724 hwnd = full_handle;
726 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
728 switch(msg)
730 case WM_NCCREATE:
732 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
733 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
734 * may have child window IDs instead of window name */
735 if (HIWORD(cs->lpszName))
736 DEFWND_SetTextA( hwnd, cs->lpszName );
737 result = 1;
739 break;
741 case WM_NCCALCSIZE:
742 result = NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
743 break;
745 case WM_WINDOWPOSCHANGING:
746 result = WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
747 break;
749 case WM_WINDOWPOSCHANGED:
751 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
752 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
754 break;
756 case WM_GETTEXTLENGTH:
758 WND *wndPtr = WIN_GetPtr( hwnd );
759 if (wndPtr && wndPtr->text)
760 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
761 NULL, 0, NULL, NULL );
762 WIN_ReleasePtr( wndPtr );
764 break;
766 case WM_GETTEXT:
768 WND *wndPtr = WIN_GetPtr( hwnd );
769 if (wParam && wndPtr && wndPtr->text)
771 LPSTR dest = (LPSTR)lParam;
772 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
773 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
774 result = strlen( dest );
776 WIN_ReleasePtr( wndPtr );
778 break;
780 case WM_SETTEXT:
781 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
782 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
783 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
784 result = 1; /* success. FIXME: check text length */
785 break;
787 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
788 case WM_IME_CHAR:
790 CHAR chChar1 = (CHAR)( (wParam>>8) & 0xff );
791 CHAR chChar2 = (CHAR)( wParam & 0xff );
793 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar1, lParam );
794 if ( IsDBCSLeadByte( chChar1 ) )
795 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar2, lParam );
797 break;
798 case WM_IME_KEYDOWN:
799 result = SendMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
800 break;
801 case WM_IME_KEYUP:
802 result = SendMessageA( hwnd, WM_KEYUP, wParam, lParam );
803 break;
805 case WM_IME_STARTCOMPOSITION:
806 case WM_IME_COMPOSITION:
807 case WM_IME_ENDCOMPOSITION:
808 case WM_IME_SELECT:
810 HWND hwndIME;
812 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
813 if (hwndIME)
814 result = SendMessageA( hwndIME, msg, wParam, lParam );
816 break;
817 case WM_IME_SETCONTEXT:
819 HWND hwndIME;
821 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
822 if (hwndIME)
823 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
825 break;
827 default:
828 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
829 break;
832 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
833 return result;
837 /***********************************************************************
838 * DefWindowProcW (USER32.@) Calls default window message handler
840 * Calls default window procedure for messages not processed
841 * by application.
843 * RETURNS
844 * Return value is dependent upon the message.
846 LRESULT WINAPI DefWindowProcW(
847 HWND hwnd, /* [in] window procedure receiving message */
848 UINT msg, /* [in] message identifier */
849 WPARAM wParam, /* [in] first message parameter */
850 LPARAM lParam ) /* [in] second message parameter */
852 LRESULT result = 0;
853 HWND full_handle;
855 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
857 if (!IsWindow( hwnd )) return 0;
858 ERR( "called for other process window %x\n", hwnd );
859 return 0;
861 hwnd = full_handle;
862 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
864 switch(msg)
866 case WM_NCCREATE:
868 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
869 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
870 * may have child window IDs instead of window name */
871 if (HIWORD(cs->lpszName))
872 DEFWND_SetTextW( hwnd, cs->lpszName );
873 result = 1;
875 break;
877 case WM_NCCALCSIZE:
878 result = NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
879 break;
881 case WM_WINDOWPOSCHANGING:
882 result = WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
883 break;
885 case WM_WINDOWPOSCHANGED:
887 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
888 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
890 break;
892 case WM_GETTEXTLENGTH:
894 WND *wndPtr = WIN_GetPtr( hwnd );
895 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
896 WIN_ReleasePtr( wndPtr );
898 break;
900 case WM_GETTEXT:
902 WND *wndPtr = WIN_GetPtr( hwnd );
903 if (wParam && wndPtr && wndPtr->text)
905 LPWSTR dest = (LPWSTR)lParam;
906 lstrcpynW( dest, wndPtr->text, wParam );
907 result = strlenW( dest );
909 WIN_ReleasePtr( wndPtr );
911 break;
913 case WM_SETTEXT:
914 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
915 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
916 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
917 result = 1; /* success. FIXME: check text length */
918 break;
920 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
921 case WM_IME_CHAR:
922 SendMessageW( hwnd, WM_CHAR, wParam, lParam );
923 break;
924 case WM_IME_SETCONTEXT:
926 HWND hwndIME;
928 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
929 if (hwndIME)
930 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
932 break;
934 default:
935 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
936 break;
938 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
939 return result;