Replace SendMessage16 by SendMessageW where possible.
[wine/wine-kai.git] / windows / defwnd.c
blobcf329b470ce83217af147a1617759819663a0c9e
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( WND *wndPtr, UINT flags )
40 WPARAM wp = SIZE_RESTORED;
42 if (!(flags & SWP_NOCLIENTMOVE))
43 SendMessageW( wndPtr->hwndSelf, WM_MOVE, 0,
44 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top));
45 if (!(flags & SWP_NOCLIENTSIZE))
47 if (wndPtr->dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
48 else if (wndPtr->dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
50 SendMessageW( wndPtr->hwndSelf, WM_SIZE, wp,
51 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
52 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
57 /***********************************************************************
58 * DEFWND_SetTextA
60 * Set the window text.
62 void DEFWND_SetTextA( WND *wndPtr, LPCSTR text )
64 int count;
66 if (!text) text = "";
67 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
69 if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
70 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
71 MultiByteToWideChar( CP_ACP, 0, text, -1, wndPtr->text, count );
72 else
73 ERR("Not enough memory for window text\n");
75 if (USER_Driver.pSetWindowText)
76 USER_Driver.pSetWindowText(wndPtr->hwndSelf, wndPtr->text);
79 /***********************************************************************
80 * DEFWND_SetTextW
82 * Set the window text.
84 void DEFWND_SetTextW( WND *wndPtr, LPCWSTR text )
86 static const WCHAR empty_string[] = {0};
87 int count;
89 if (!text) text = empty_string;
90 count = strlenW(text) + 1;
92 if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
93 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
94 strcpyW( wndPtr->text, text );
95 else
96 ERR("Not enough memory for window text\n");
98 if (USER_Driver.pSetWindowText)
99 USER_Driver.pSetWindowText(wndPtr->hwndSelf, wndPtr->text);
102 /***********************************************************************
103 * DEFWND_ControlColor
105 * Default colors for control painting.
107 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
109 if( ctlType == CTLCOLOR_SCROLLBAR)
111 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
112 if (TWEAK_WineLook == WIN31_LOOK) {
113 SetTextColor( hDC, RGB(0, 0, 0) );
114 SetBkColor( hDC, RGB(255, 255, 255) );
115 } else {
116 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
117 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
118 SetBkColor( hDC, bk);
120 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
121 * we better use 0x55aa bitmap brush to make scrollbar's background
122 * look different from the window background.
124 if (bk == GetSysColor(COLOR_WINDOW)) {
125 return CACHE_GetPattern55AABrush();
128 UnrealizeObject( hb );
129 return hb;
132 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
134 if (TWEAK_WineLook > WIN31_LOOK) {
135 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
136 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
137 else {
138 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
139 return GetSysColorBrush(COLOR_3DFACE);
142 else
143 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
144 return GetSysColorBrush(COLOR_WINDOW);
148 /***********************************************************************
149 * DEFWND_SetRedraw
151 static void DEFWND_SetRedraw( WND* wndPtr, WPARAM wParam )
153 BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
155 TRACE("%04x %i\n", wndPtr->hwndSelf, (wParam!=0) );
157 if( wParam )
159 if( !bVisible )
161 wndPtr->dwStyle |= WS_VISIBLE;
162 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
165 else if( bVisible )
167 if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
168 else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
170 RedrawWindow( wndPtr->hwndSelf, NULL, 0, wParam );
171 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
172 wndPtr->dwStyle &= ~WS_VISIBLE;
176 /***********************************************************************
177 * DEFWND_Print
179 * This method handles the default behavior for the WM_PRINT message.
181 static void DEFWND_Print(
182 WND* wndPtr,
183 HDC hdc,
184 ULONG uFlags)
187 * Visibility flag.
189 if ( (uFlags & PRF_CHECKVISIBLE) &&
190 !IsWindowVisible(wndPtr->hwndSelf) )
191 return;
194 * Unimplemented flags.
196 if ( (uFlags & PRF_CHILDREN) ||
197 (uFlags & PRF_OWNED) ||
198 (uFlags & PRF_NONCLIENT) )
200 WARN("WM_PRINT message with unsupported flags\n");
204 * Background
206 if ( uFlags & PRF_ERASEBKGND)
207 SendMessageW(wndPtr->hwndSelf, WM_ERASEBKGND, (WPARAM)hdc, 0);
210 * Client area
212 if ( uFlags & PRF_CLIENT)
213 SendMessageW(wndPtr->hwndSelf, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
218 * helpers for calling IMM32
220 * WM_IME_* messages are generated only by IMM32,
221 * so I assume imm32 is already LoadLibrary-ed.
223 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
225 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
226 HWND WINAPI (*pFunc)(HWND);
227 HWND hwndRet = 0;
229 if (!hInstIMM)
231 ERR( "cannot get IMM32 handle\n" );
232 return 0;
235 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
236 if ( pFunc != NULL )
237 hwndRet = (*pFunc)( hwnd );
239 return hwndRet;
242 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
244 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
245 BOOL WINAPI (*pFunc)(HWND,UINT,WPARAM,LPARAM);
246 BOOL fRet = FALSE;
248 if (!hInstIMM)
250 ERR( "cannot get IMM32 handle\n" );
251 return FALSE;
254 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
255 if ( pFunc != NULL )
256 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
258 return fRet;
261 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
263 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
264 BOOL WINAPI (*pFunc)(HWND,UINT,WPARAM,LPARAM);
265 BOOL fRet = FALSE;
267 if (!hInstIMM)
269 ERR( "cannot get IMM32 handle\n" );
270 return FALSE;
273 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
274 if ( pFunc != NULL )
275 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
277 return fRet;
282 /***********************************************************************
283 * DEFWND_DefWinProc
285 * Default window procedure for messages that are the same in Win16 and Win32.
287 static LRESULT DEFWND_DefWinProc( WND *wndPtr, UINT msg, WPARAM wParam,
288 LPARAM lParam, BOOL unicode )
290 LRESULT (WINAPI *pSendMessage)(HWND, UINT, WPARAM, LPARAM);
291 BOOL (WINAPI *pPostMessage)(HWND, UINT, WPARAM, LPARAM);
293 pSendMessage = unicode ? SendMessageW : SendMessageA;
294 pPostMessage = unicode ? PostMessageW : PostMessageA;
296 switch(msg)
298 case WM_NCPAINT:
299 return NC_HandleNCPaint( wndPtr->hwndSelf, (HRGN)wParam );
301 case WM_NCHITTEST:
303 POINT pt;
304 pt.x = SLOWORD(lParam);
305 pt.y = SHIWORD(lParam);
306 return NC_HandleNCHitTest( wndPtr->hwndSelf, pt );
309 case WM_NCLBUTTONDOWN:
310 return NC_HandleNCLButtonDown( wndPtr, wParam, lParam );
312 case WM_LBUTTONDBLCLK:
313 case WM_NCLBUTTONDBLCLK:
314 return NC_HandleNCLButtonDblClk( wndPtr, wParam, lParam );
316 case WM_NCRBUTTONDOWN:
317 /* in Windows, capture is taken when right-clicking on the caption bar */
318 if (wParam==HTCAPTION)
320 SetCapture(wndPtr->hwndSelf);
322 break;
324 case WM_RBUTTONUP:
326 POINT pt;
328 if (wndPtr->hwndSelf == GetCapture())
329 /* release capture if we took it on WM_NCRBUTTONDOWN */
330 ReleaseCapture();
332 pt.x = SLOWORD(lParam);
333 pt.y = SHIWORD(lParam);
334 ClientToScreen(wndPtr->hwndSelf, &pt);
335 pSendMessage( wndPtr->hwndSelf, WM_CONTEXTMENU,
336 wndPtr->hwndSelf, MAKELPARAM(pt.x, pt.y) );
338 break;
340 case WM_NCRBUTTONUP:
342 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
343 * in Windows), but what _should_ we do? According to MSDN :
344 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
345 * message to the window". When is it appropriate?
347 break;
349 case WM_CONTEXTMENU:
350 if( wndPtr->dwStyle & WS_CHILD )
351 pSendMessage( wndPtr->parent->hwndSelf, msg, wParam, lParam );
352 else if (wndPtr->hSysMenu)
354 LONG hitcode;
355 POINT pt;
356 pt.x = SLOWORD(lParam);
357 pt.y = SHIWORD(lParam);
360 * WM_CONTEXTMENU coordinates are relative to screen, but
361 * NC_HandleNCHitTest expects coordinates relative to the parent's
362 * client area (to compare with the rectangle returned by
363 * GetWindowRect)
365 if (wndPtr->parent)
366 ScreenToClient(wndPtr->parent->hwndSelf, &pt);
368 hitcode = NC_HandleNCHitTest(wndPtr->hwndSelf, pt);
370 /* Track system popup if click was in the caption area. */
371 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
372 TrackPopupMenu(GetSystemMenu(wndPtr->hwndSelf, FALSE),
373 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
374 pt.x, pt.y, 0, wndPtr->hwndSelf, NULL);
376 break;
378 case WM_NCACTIVATE:
379 return NC_HandleNCActivate( wndPtr, wParam );
381 case WM_NCDESTROY:
382 if (wndPtr->text) HeapFree( GetProcessHeap(), 0, wndPtr->text );
383 wndPtr->text = NULL;
384 if (wndPtr->pVScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pVScroll );
385 if (wndPtr->pHScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pHScroll );
386 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
387 return 0;
389 case WM_PRINT:
390 DEFWND_Print(wndPtr, (HDC)wParam, lParam);
391 return 0;
393 case WM_PAINTICON:
394 case WM_PAINT:
396 PAINTSTRUCT ps;
397 HDC hdc = BeginPaint( wndPtr->hwndSelf, &ps );
398 if( hdc )
400 HICON hIcon;
401 if( (wndPtr->dwStyle & WS_MINIMIZE) && ((hIcon = GetClassLongW( wndPtr->hwndSelf, GCL_HICON))) )
403 int x = (wndPtr->rectWindow.right - wndPtr->rectWindow.left -
404 GetSystemMetrics(SM_CXICON))/2;
405 int y = (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top -
406 GetSystemMetrics(SM_CYICON))/2;
407 TRACE("Painting class icon: vis rect=(%i,%i - %i,%i)\n",
408 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
409 DrawIcon( hdc, x, y, hIcon );
411 EndPaint( wndPtr->hwndSelf, &ps );
413 return 0;
416 case WM_SYNCPAINT:
417 RedrawWindow ( wndPtr->hwndSelf, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
418 return 0;
420 case WM_SETREDRAW:
421 DEFWND_SetRedraw( wndPtr, wParam );
422 return 0;
424 case WM_CLOSE:
425 DestroyWindow( wndPtr->hwndSelf );
426 return 0;
428 case WM_MOUSEACTIVATE:
429 if (wndPtr->dwStyle & WS_CHILD)
431 LONG ret = pSendMessage( wndPtr->parent->hwndSelf,
432 WM_MOUSEACTIVATE, wParam, lParam );
433 if (ret) return ret;
436 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
437 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
439 case WM_ACTIVATE:
440 /* The default action in Windows is to set the keyboard focus to
441 * the window, if it's being activated and not minimized */
442 if (LOWORD(wParam) != WA_INACTIVE) {
443 if (!(wndPtr->dwStyle & WS_MINIMIZE))
444 SetFocus(wndPtr->hwndSelf);
446 break;
448 case WM_MOUSEWHEEL:
449 if (wndPtr->dwStyle & WS_CHILD)
451 return pSendMessage( wndPtr->parent->hwndSelf,
452 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( wndPtr->hwndSelf, GCL_HBRBACKGROUND );
462 if (!hbr) return 0;
464 /* GetClientRect used to be GetClipBox, but it is not what
465 * Windows does, and it breaks badly with CS_PARENTDC */
466 GetClientRect( wndPtr->hwndSelf, &rect );
467 DPtoLP( hdc, (LPPOINT)&rect, 2 );
468 FillRect( hdc, &rect, hbr );
469 return 1;
472 case WM_GETDLGCODE:
473 return 0;
475 case WM_CTLCOLORMSGBOX:
476 case WM_CTLCOLOREDIT:
477 case WM_CTLCOLORLISTBOX:
478 case WM_CTLCOLORBTN:
479 case WM_CTLCOLORDLG:
480 case WM_CTLCOLORSTATIC:
481 case WM_CTLCOLORSCROLLBAR:
482 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
484 case WM_CTLCOLOR:
485 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
487 case WM_SETCURSOR:
488 if (wndPtr->dwStyle & WS_CHILD)
490 /* with the exception of the border around a resizable wnd,
491 * give the parent first chance to set the cursor */
492 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
494 if (pSendMessage(wndPtr->parent->hwndSelf, WM_SETCURSOR, wParam, lParam))
495 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 pPostMessage( 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 pSendMessage( wndPtr->hwndSelf, WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE );
537 break;
539 case WM_KEYUP:
540 case WM_SYSKEYUP:
541 /* Press and release F10 or ALT */
542 if (((wParam == VK_MENU) && iMenuSysKey) ||
543 ((wParam == VK_F10) && iF10Key))
544 pSendMessage( WIN_GetTopParent(wndPtr->hwndSelf),
545 WM_SYSCOMMAND, SC_KEYMENU, 0L );
546 iMenuSysKey = iF10Key = 0;
547 break;
549 case WM_SYSCHAR:
550 iMenuSysKey = 0;
551 if (wParam == VK_RETURN && (wndPtr->dwStyle & WS_MINIMIZE))
553 pPostMessage( wndPtr->hwndSelf, WM_SYSCOMMAND, SC_RESTORE, 0L );
554 break;
556 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
558 if (wParam == VK_TAB || wParam == VK_ESCAPE) break;
559 if (wParam == VK_SPACE && (wndPtr->dwStyle & WS_CHILD))
560 pSendMessage( wndPtr->parent->hwndSelf, msg, wParam, lParam );
561 else
562 pSendMessage( wndPtr->hwndSelf, WM_SYSCOMMAND, SC_KEYMENU, wParam );
564 else /* check for Ctrl-Esc */
565 if (wParam != VK_ESCAPE) MessageBeep(0);
566 break;
568 case WM_SHOWWINDOW:
569 if (!lParam) return 0; /* sent from ShowWindow */
570 if (!(wndPtr->dwStyle & WS_POPUP) || !wndPtr->owner) return 0;
571 if ((wndPtr->dwStyle & WS_VISIBLE) && wParam) return 0;
572 else if (!(wndPtr->dwStyle & WS_VISIBLE) && !wParam) return 0;
573 ShowWindow( wndPtr->hwndSelf, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
574 break;
576 case WM_CANCELMODE:
577 if (wndPtr->parent == WIN_GetDesktop()) EndMenu();
578 if (GetCapture() == wndPtr->hwndSelf) ReleaseCapture();
579 WIN_ReleaseDesktop();
580 break;
582 case WM_VKEYTOITEM:
583 case WM_CHARTOITEM:
584 return -1;
586 case WM_DROPOBJECT:
587 return DRAG_FILE;
589 case WM_QUERYDROPOBJECT:
590 if (wndPtr->dwExStyle & WS_EX_ACCEPTFILES) return 1;
591 break;
593 case WM_QUERYDRAGICON:
595 UINT len;
597 HICON hIcon = GetClassLongW( wndPtr->hwndSelf, GCL_HICON );
598 if (hIcon) return hIcon;
599 for(len=1; len<64; len++)
600 if((hIcon = LoadIconW(wndPtr->hInstance, MAKEINTRESOURCEW(len))))
601 return (LRESULT)hIcon;
602 return (LRESULT)LoadIconW(0, IDI_APPLICATIONW);
604 break;
606 case WM_ISACTIVEICON:
607 return ((wndPtr->flags & WIN_NCACTIVATED) != 0);
609 case WM_NOTIFYFORMAT:
610 if (IsWindowUnicode(wndPtr->hwndSelf)) return NFR_UNICODE;
611 else return NFR_ANSI;
613 case WM_QUERYOPEN:
614 case WM_QUERYENDSESSION:
615 return 1;
617 case WM_SETICON:
618 if (USER_Driver.pSetWindowIcon)
619 return USER_Driver.pSetWindowIcon( wndPtr->hwndSelf, lParam, (wParam != ICON_SMALL) );
620 else
622 int index = (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM;
623 HICON hOldIcon = GetClassLongW(wndPtr->hwndSelf, index);
624 SetClassLongW(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);
629 return hOldIcon;
632 case WM_GETICON:
634 int index = (wParam != ICON_SMALL) ? GCL_HICON : GCL_HICONSM;
635 return GetClassLongW(wndPtr->hwndSelf, index);
638 case WM_HELP:
639 pSendMessage( wndPtr->parent->hwndSelf, msg, wParam, lParam );
640 break;
643 return 0;
648 /***********************************************************************
649 * DefWindowProc (USER.107)
651 LRESULT WINAPI DefWindowProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
652 LPARAM lParam )
654 WND * wndPtr = WIN_FindWndPtr( hwnd );
655 LRESULT result = 0;
657 if (!wndPtr) return 0;
658 SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
660 switch(msg)
662 case WM_NCCREATE:
664 CREATESTRUCT16 *cs = MapSL(lParam);
665 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
666 * may have child window IDs instead of window name */
667 if (HIWORD(cs->lpszName))
668 DEFWND_SetTextA( wndPtr, MapSL(cs->lpszName) );
669 result = 1;
671 break;
673 case WM_NCCALCSIZE:
675 RECT rect32;
676 CONV_RECT16TO32( MapSL(lParam), &rect32 );
677 result = NC_HandleNCCalcSize( wndPtr, &rect32 );
678 CONV_RECT32TO16( &rect32, MapSL(lParam) );
680 break;
682 case WM_WINDOWPOSCHANGING:
683 result = WINPOS_HandleWindowPosChanging16( wndPtr, MapSL(lParam) );
684 break;
686 case WM_WINDOWPOSCHANGED:
688 WINDOWPOS16 * winPos = MapSL(lParam);
689 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
691 break;
693 case WM_GETTEXTLENGTH:
694 if (wndPtr->text)
695 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
696 NULL, 0, NULL, NULL );
697 break;
699 case WM_GETTEXT:
700 if (wParam && wndPtr->text)
702 LPSTR dest = MapSL(lParam);
703 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1, dest, wParam, NULL, NULL ))
704 dest[wParam-1] = 0;
705 result = strlen(dest);
707 break;
709 case WM_SETTEXT:
710 DEFWND_SetTextA( wndPtr, MapSL(lParam) );
711 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
712 NC_HandleNCPaint( hwnd , (HRGN)1 );
713 result = 1; /* success. FIXME: check text length */
714 break;
716 default:
717 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam, FALSE );
718 break;
721 WIN_ReleaseWndPtr(wndPtr);
722 SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result, wParam, lParam );
723 return result;
727 /***********************************************************************
728 * DefWindowProcA (USER32.@)
731 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam,
732 LPARAM lParam )
734 WND * wndPtr = WIN_FindWndPtr( hwnd );
735 LRESULT result = 0;
737 if (!wndPtr) return 0;
738 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
740 switch(msg)
742 case WM_NCCREATE:
744 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
745 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
746 * may have child window IDs instead of window name */
747 if (HIWORD(cs->lpszName))
748 DEFWND_SetTextA( wndPtr, cs->lpszName );
749 result = 1;
751 break;
753 case WM_NCCALCSIZE:
754 result = NC_HandleNCCalcSize( wndPtr, (RECT *)lParam );
755 break;
757 case WM_WINDOWPOSCHANGING:
758 result = WINPOS_HandleWindowPosChanging( wndPtr,
759 (WINDOWPOS *)lParam );
760 break;
762 case WM_WINDOWPOSCHANGED:
764 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
765 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
767 break;
769 case WM_GETTEXTLENGTH:
770 if (wndPtr->text)
771 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
772 NULL, 0, NULL, NULL );
773 break;
775 case WM_GETTEXT:
776 if (wParam && wndPtr->text)
778 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
779 (LPSTR)lParam, wParam, NULL, NULL ))
780 ((LPSTR)lParam)[wParam-1] = 0;
781 result = (LRESULT)strlen( (LPSTR)lParam );
783 break;
785 case WM_SETTEXT:
786 DEFWND_SetTextA( wndPtr, (LPCSTR)lParam );
787 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
788 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
789 result = 1; /* success. FIXME: check text length */
790 break;
792 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
793 case WM_IME_CHAR:
795 CHAR chChar1 = (CHAR)( (wParam>>8) & 0xff );
796 CHAR chChar2 = (CHAR)( wParam & 0xff );
798 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar1, lParam );
799 if ( IsDBCSLeadByte( chChar1 ) )
800 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar2, lParam );
802 break;
803 case WM_IME_KEYDOWN:
804 result = SendMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
805 break;
806 case WM_IME_KEYUP:
807 result = SendMessageA( hwnd, WM_KEYUP, wParam, lParam );
808 break;
810 case WM_IME_STARTCOMPOSITION:
811 case WM_IME_COMPOSITION:
812 case WM_IME_ENDCOMPOSITION:
813 case WM_IME_SELECT:
815 HWND hwndIME;
817 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
818 if (hwndIME)
819 result = SendMessageA( hwndIME, msg, wParam, lParam );
821 break;
822 case WM_IME_SETCONTEXT:
824 HWND hwndIME;
826 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
827 if (hwndIME)
828 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
830 break;
832 default:
833 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam, FALSE );
834 break;
837 WIN_ReleaseWndPtr(wndPtr);
838 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
839 return result;
843 /***********************************************************************
844 * DefWindowProcW (USER32.@) Calls default window message handler
846 * Calls default window procedure for messages not processed
847 * by application.
849 * RETURNS
850 * Return value is dependent upon the message.
852 LRESULT WINAPI DefWindowProcW(
853 HWND hwnd, /* [in] window procedure receiving message */
854 UINT msg, /* [in] message identifier */
855 WPARAM wParam, /* [in] first message parameter */
856 LPARAM lParam ) /* [in] second message parameter */
858 WND * wndPtr = WIN_FindWndPtr( hwnd );
859 LRESULT result = 0;
861 if (!wndPtr) return 0;
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( wndPtr, cs->lpszName );
873 result = 1;
875 break;
877 case WM_NCCALCSIZE:
878 result = NC_HandleNCCalcSize( wndPtr, (RECT *)lParam );
879 break;
881 case WM_WINDOWPOSCHANGING:
882 result = WINPOS_HandleWindowPosChanging( wndPtr,
883 (WINDOWPOS *)lParam );
884 break;
886 case WM_WINDOWPOSCHANGED:
888 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
889 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
891 break;
893 case WM_GETTEXTLENGTH:
894 if (wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
895 break;
897 case WM_GETTEXT:
898 if (wParam && wndPtr->text)
900 lstrcpynW( (LPWSTR)lParam, wndPtr->text, wParam );
901 result = strlenW( (LPWSTR)lParam );
903 break;
905 case WM_SETTEXT:
906 DEFWND_SetTextW( wndPtr, (LPCWSTR)lParam );
907 if( (wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION )
908 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
909 result = 1; /* success. FIXME: check text length */
910 break;
912 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
913 case WM_IME_CHAR:
914 SendMessageW( hwnd, WM_CHAR, wParam, lParam );
915 break;
916 case WM_IME_SETCONTEXT:
918 HWND hwndIME;
920 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
921 if (hwndIME)
922 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
924 break;
926 default:
927 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam, TRUE );
928 break;
930 WIN_ReleaseWndPtr(wndPtr);
931 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
932 return result;