Apply changes from r42521 to DefWndProcW as well
[reactos.git] / reactos / dll / win32 / user32 / windows / defwnd.c
index 8205bb2..e6ef792 100644 (file)
@@ -58,12 +58,12 @@ InitStockObjects(void)
 /*
  * @implemented
  */
-DWORD STDCALL
+DWORD WINAPI
 GetSysColor(int nIndex)
 {
-  if(nIndex >= 0 && nIndex <= NUM_SYSCOLORS)
+  if(nIndex >= 0 && nIndex < NUM_SYSCOLORS)
   {
-    return g_psi->SysColors[nIndex];
+    return g_psi->argbSystem[nIndex];
   }
 
   SetLastError(ERROR_INVALID_PARAMETER);
@@ -73,27 +73,12 @@ GetSysColor(int nIndex)
 /*
  * @implemented
  */
-HPEN STDCALL
-GetSysColorPen(int nIndex)
-{
-  if(nIndex >= 0 && nIndex <= NUM_SYSCOLORS)
-  {
-    return g_psi->SysColorPens[nIndex];
-  }
-
-  SetLastError(ERROR_INVALID_PARAMETER);
-  return NULL;
-}
-
-/*
- * @implemented
- */
-HBRUSH STDCALL
+HBRUSH WINAPI
 GetSysColorBrush(int nIndex)
 {
-  if(nIndex >= 0 && nIndex <= NUM_SYSCOLORS)
+  if(nIndex >= 0 && nIndex < NUM_SYSCOLORS)
   {
-    return g_psi->SysColorBrushes[nIndex];
+    return g_psi->ahbrSystem[nIndex];
   }
 
   SetLastError(ERROR_INVALID_PARAMETER);
@@ -104,7 +89,7 @@ GetSysColorBrush(int nIndex)
  * @implemented
  */
 BOOL
-STDCALL
+WINAPI
 SetSysColors(
   int cElements,
   CONST INT *lpaElements,
@@ -113,18 +98,34 @@ SetSysColors(
   return NtUserSetSysColors(cElements, lpaElements, lpaRgbValues, 0);
 }
 
+BOOL
+FASTCALL
+DefSetText(HWND hWnd, PCWSTR String, BOOL Ansi)
+{
+  LARGE_STRING lsString;
+
+  if ( String )
+  {
+     if ( Ansi )
+        RtlInitLargeAnsiString((PLARGE_ANSI_STRING)&lsString, (PCSZ)String, 0);
+     else
+        RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING)&lsString, String, 0);
+  }
+  return NtUserDefSetText(hWnd, (String ? &lsString : NULL));
+}
+
 void
-UserGetInsideRectNC(PWINDOW Wnd, RECT *rect)
+UserGetInsideRectNC(PWND Wnd, RECT *rect)
 {
     ULONG Style;
     ULONG ExStyle;
 
-    Style = Wnd->Style;
+    Style = Wnd->style;
     ExStyle = Wnd->ExStyle;
 
     rect->top    = rect->left = 0;
-    rect->right  = Wnd->WindowRect.right - Wnd->WindowRect.left;
-    rect->bottom = Wnd->WindowRect.bottom - Wnd->WindowRect.top;
+    rect->right  = Wnd->rcWindow.right - Wnd->rcWindow.left;
+    rect->bottom = Wnd->rcWindow.bottom - Wnd->rcWindow.top;
 
     if (Style & WS_ICONIC)
     {
@@ -162,13 +163,13 @@ UserGetInsideRectNC(PWINDOW Wnd, RECT *rect)
 VOID
 DefWndSetRedraw(HWND hWnd, WPARAM wParam)
 {
-    LONG Style = GetWindowLong(hWnd, GWL_STYLE);
+    LONG Style = GetWindowLongPtr(hWnd, GWL_STYLE);
     /* Content can be redrawn after a change. */
     if (wParam)
     {
        if (!(Style & WS_VISIBLE)) /* Not Visible */
        {
-          SetWindowLong(hWnd, GWL_STYLE, WS_VISIBLE);
+          SetWindowLongPtr(hWnd, GWL_STYLE, WS_VISIBLE);
        }
     }
     else /* Content cannot be redrawn after a change. */
@@ -177,7 +178,7 @@ DefWndSetRedraw(HWND hWnd, WPARAM wParam)
        {
             RedrawWindow( hWnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE );
             Style &= ~WS_VISIBLE;
-            SetWindowLong(hWnd, GWL_STYLE, Style); /* clear bits */
+            SetWindowLongPtr(hWnd, GWL_STYLE, Style); /* clear bits */
        }
     }
     return;
@@ -208,7 +209,7 @@ DefWndHandleSetCursor(HWND hWnd, WPARAM wParam, LPARAM lParam, ULONG Style)
 
     case HTCLIENT:
       {
-       HICON hCursor = (HICON)GetClassLongW(hWnd, GCL_HCURSOR);
+       HICON hCursor = (HICON)GetClassLongPtrW(hWnd, GCL_HCURSOR);
        if (hCursor)
          {
            SetCursor(hCursor);
@@ -250,7 +251,7 @@ DefWndHandleSetCursor(HWND hWnd, WPARAM wParam, LPARAM lParam, ULONG Style)
     case HTBOTTOMLEFT:
     case HTTOPRIGHT:
       {
-        if (GetWindowLongW(hWnd, GWL_STYLE) & WS_MAXIMIZE)
+        if (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_MAXIMIZE)
         {
           break;
         }
@@ -261,15 +262,15 @@ DefWndHandleSetCursor(HWND hWnd, WPARAM wParam, LPARAM lParam, ULONG Style)
 }
 
 static LONG
-DefWndStartSizeMove(HWND hWnd, PWINDOW Wnd, WPARAM wParam, POINT *capturePoint)
+DefWndStartSizeMove(HWND hWnd, PWND Wnd, WPARAM wParam, POINT *capturePoint)
 {
   LONG hittest = 0;
   POINT pt;
   MSG msg;
   RECT rectWindow;
-  ULONG Style = Wnd->Style;
+  ULONG Style = Wnd->style;
 
-  rectWindow = Wnd->WindowRect;
+  rectWindow = Wnd->rcWindow;
 
   if ((wParam & 0xfff0) == SC_MOVE)
     {
@@ -408,13 +409,13 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
   DWORD dwPoint = GetMessagePos();
   BOOL DragFullWindows = FALSE;
   HWND hWndParent = NULL;
-  PWINDOW Wnd;
+  PWND Wnd;
 
   Wnd = ValidateHwnd(hwnd);
   if (!Wnd)
       return;
 
-  Style = Wnd->Style;
+  Style = Wnd->style;
   ExStyle = Wnd->ExStyle;
   iconic = (Style & WS_MINIMIZE) != 0;
 
@@ -466,7 +467,7 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
   /* Get min/max info */
 
   WinPosGetMinMaxInfo(hwnd, NULL, NULL, &minTrack, &maxTrack);
-  sizingRect = Wnd->WindowRect;
+  sizingRect = Wnd->rcWindow;
   if (Style & WS_CHILD)
     {
       hWndParent = GetParent(hwnd);
@@ -538,7 +539,7 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
 
   if( iconic ) /* create a cursor for dragging */
     {
-      HICON hIcon = (HICON)GetClassLongW(hwnd, GCL_HICON);
+      HICON hIcon = (HICON)GetClassLongPtrW(hwnd, GCL_HICON);
       if(!hIcon) hIcon = (HICON)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
       if( hIcon ) hDragCursor = CursorIconToCursor( hIcon, TRUE );
       if( !hDragCursor ) iconic = FALSE;
@@ -666,13 +667,14 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
       DeleteObject(DesktopRgn);
     }
   }
-#if 0
-  if (ISITHOOKED(WH_CBT))
+//#if 0
+//  if (ISITHOOKED(WH_CBT))
   {
-      if (NtUserMessageCall( hWnd, WM_SYSCOMMAND, wParam, (LPARAM)&sizingRect, 0, FNID_DEFWINDOWPROC, FALSE))
-         moved = FALSE;
+      LRESULT lResult;
+      NtUserMessageCall( hwnd, WM_CBT, HCBT_MOVESIZE, (LPARAM)&sizingRect, (ULONG_PTR)&lResult, FNID_DEFWINDOWPROC, FALSE);
+      if (lResult) moved = FALSE;
   }
-#endif
+//#endif
   (void)NtUserSetGUIThreadHandle(MSQ_STATE_MOVESIZE, NULL);
   SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
   SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
@@ -752,13 +754,16 @@ DefWndHandleSysCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
   WINDOWPLACEMENT wp;
   POINT Pt;
 
-#if 0
-  if (ISITHOOKED(WH_CBT))
+  if (!IsWindowEnabled( hWnd )) return 0;
+
+//#if 0
+//  if (ISITHOOKED(WH_CBT))
   {
-     if (NtUserMessageCall( hWnd, WM_SYSCOMMAND, wParam, lParam, 0, FNID_DEFWINDOWPROC, FALSE))
-        return 0;
+     LRESULT lResult;
+     NtUserMessageCall( hWnd, WM_SYSCOMMAND, wParam, lParam, (ULONG_PTR)&lResult, FNID_DEFWINDOWPROC, FALSE);
+     if (lResult) return 0;
   }
-#endif
+//#endif
   switch (wParam & 0xfff0)
     {
       case SC_MOVE:
@@ -790,8 +795,8 @@ DefWndHandleSysCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
         }
         break;
       case SC_CLOSE:
-        SendMessageA(hWnd, WM_CLOSE, 0, 0);
-        break;
+        return SendMessageW(hWnd, WM_CLOSE, 0, 0);
+
       case SC_MOUSEMENU:
         {
           Pt.x = (short)LOWORD(lParam);
@@ -824,7 +829,7 @@ LRESULT
 DefWndHandleWindowPosChanging(HWND hWnd, WINDOWPOS* Pos)
 {
     POINT maxTrack, minTrack;
-    LONG style = GetWindowLongA(hWnd, GWL_STYLE);
+    LONG style = GetWindowLongPtrA(hWnd, GWL_STYLE);
 
     if (Pos->flags & SWP_NOSIZE) return 0;
     if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
@@ -856,7 +861,7 @@ DefWndHandleWindowPosChanged(HWND hWnd, WINDOWPOS* Pos)
   RECT Rect;
 
   GetClientRect(hWnd, &Rect);
-  MapWindowPoints(hWnd, (GetWindowLongW(hWnd, GWL_STYLE) & WS_CHILD ?
+  MapWindowPoints(hWnd, (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CHILD ?
                          GetParent(hWnd) : NULL), (LPPOINT) &Rect, 2);
 
   if (! (Pos->flags & SWP_NOCLIENTMOVE))
@@ -965,7 +970,7 @@ static void DefWndPrint( HWND hwnd, HDC hdc, ULONG uFlags)
    * Client area
    */
   if ( uFlags & PRF_CLIENT)
-    SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
+    SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, uFlags);
 }
 
 static BOOL CALLBACK
@@ -1013,7 +1018,7 @@ DefWndScreenshot(HWND hWnd)
 
 
 
-LRESULT STDCALL
+LRESULT WINAPI
 User32DefWindowProc(HWND hWnd,
                    UINT Msg,
                    WPARAM wParam,
@@ -1032,6 +1037,18 @@ User32DefWindowProc(HWND hWnd,
             return DefWndNCCalcSize(hWnd, (BOOL)wParam, (RECT*)lParam);
         }
 
+        case WM_POPUPSYSTEMMENU:
+        {
+            /* This is an undocumented message used by the windows taskbar to
+               display the system menu of windows that belong to other processes. */
+            HMENU menu = GetSystemMenu(hWnd, FALSE);
+
+            if (menu)
+                TrackPopupMenu(menu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
+                               LOWORD(lParam), HIWORD(lParam), 0, hWnd, NULL);
+            return 0;
+        }
+
         case WM_NCACTIVATE:
         {
             return DefWndNCActivate(hWnd, wParam);
@@ -1117,7 +1134,7 @@ User32DefWindowProc(HWND hWnd,
 
         case WM_CONTEXTMENU:
         {
-            if (GetWindowLongW(hWnd, GWL_STYLE) & WS_CHILD)
+            if (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CHILD)
             {
                 if (bUnicode)
                 {
@@ -1131,10 +1148,10 @@ User32DefWindowProc(HWND hWnd,
             else
             {
                 POINT Pt;
-                DWORD Style;
+                LONG_PTR Style;
                 LONG HitCode;
 
-                Style = GetWindowLongW(hWnd, GWL_STYLE);
+                Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
 
                 Pt.x = GET_X_LPARAM(lParam);
                 Pt.y = GET_Y_LPARAM(lParam);
@@ -1152,8 +1169,8 @@ User32DefWindowProc(HWND hWnd,
 
                     if((SystemMenu = GetSystemMenu(hWnd, FALSE)))
                     {
-                      MenuInitSysMenuPopup(SystemMenu, GetWindowLongW(hWnd, GWL_STYLE),
-                                           GetClassLongW(hWnd, GCL_STYLE), HitCode);
+                      MenuInitSysMenuPopup(SystemMenu, GetWindowLongPtrW(hWnd, GWL_STYLE),
+                                           GetClassLongPtrW(hWnd, GCL_STYLE), HitCode);
 
                       if(HitCode == HTCAPTION)
                         Flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON;
@@ -1174,6 +1191,18 @@ User32DefWindowProc(HWND hWnd,
             return (0);
         }
 
+        case WM_SYSCOLORCHANGE:
+        {
+            /* force to redraw non-client area */
+            DefWndNCPaint(hWnd, (HRGN)1, -1);
+            /* Use InvalidateRect to redraw client area, enable
+             * erase to redraw all subcontrols otherwise send the
+             * WM_SYSCOLORCHANGE to child windows/controls is required
+             */
+            InvalidateRect(hWnd,NULL,TRUE);
+            return (0);
+        }
+
         case WM_PAINTICON:
         case WM_PAINT:
         {
@@ -1182,8 +1211,9 @@ User32DefWindowProc(HWND hWnd,
             if (hDC)
             {
                 HICON hIcon;
-                if (GetWindowLongW(hWnd, GWL_STYLE) & WS_MINIMIZE &&
-                    (hIcon = (HICON)GetClassLongW(hWnd, GCL_HICON)) != NULL)
+
+                if (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_MINIMIZE &&
+                    (hIcon = (HICON)GetClassLongPtrW(hWnd, GCL_HICON)) != NULL)
                 {
                     RECT ClientRect;
                     INT x, y;
@@ -1215,7 +1245,14 @@ User32DefWindowProc(HWND hWnd,
 
         case WM_SETREDRAW:
         {
-            DefWndSetRedraw(hWnd, wParam);
+            LONG_PTR Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
+            if (wParam) SetWindowLongPtr(hWnd, GWL_STYLE, Style | WS_VISIBLE);
+            else
+            {
+                RedrawWindow(hWnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE);
+                Style &= ~WS_VISIBLE;
+                SetWindowLongPtr(hWnd, GWL_STYLE, Style);
+            }
             return (0);
         }
 
@@ -1227,7 +1264,7 @@ User32DefWindowProc(HWND hWnd,
 
         case WM_MOUSEACTIVATE:
         {
-            if (GetWindowLongW(hWnd, GWL_STYLE) & WS_CHILD)
+            if (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CHILD)
             {
                 LONG Ret;
                 if (bUnicode)
@@ -1252,7 +1289,7 @@ User32DefWindowProc(HWND hWnd,
         {
             /* Check if the window is minimized. */
             if (LOWORD(wParam) != WA_INACTIVE &&
-                !(GetWindowLongW(hWnd, GWL_STYLE) & WS_MINIMIZE))
+                !(GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_MINIMIZE))
             {
                 SetFocus(hWnd);
             }
@@ -1261,7 +1298,7 @@ User32DefWindowProc(HWND hWnd,
 
         case WM_MOUSEWHEEL:
         {
-            if (GetWindowLongW(hWnd, GWL_STYLE) & WS_CHILD)
+            if (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CHILD)
             {
                 if (bUnicode)
                 {
@@ -1281,13 +1318,13 @@ User32DefWindowProc(HWND hWnd,
         case WM_ICONERASEBKGND:
         {
             RECT Rect;
-            HBRUSH hBrush = (HBRUSH)GetClassLongW(hWnd, GCL_HBRBACKGROUND);
+            HBRUSH hBrush = (HBRUSH)GetClassLongPtrW(hWnd, GCL_HBRBACKGROUND);
 
             if (NULL == hBrush)
             {
                 return 0;
             }
-            if (GetClassLongW(hWnd, GCL_STYLE) & CS_PARENTDC)
+            if (GetClassLongPtrW(hWnd, GCL_STYLE) & CS_PARENTDC)
             {
                 /* can't use GetClipBox with a parent DC or we fill the whole parent */
                 GetClientRect(hWnd, &Rect);
@@ -1315,7 +1352,7 @@ User32DefWindowProc(HWND hWnd,
 
         case WM_SETCURSOR:
         {
-            ULONG Style = GetWindowLongW(hWnd, GWL_STYLE);
+            LONG_PTR Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
 
             if (Style & WS_CHILD)
             {
@@ -1353,10 +1390,15 @@ User32DefWindowProc(HWND hWnd,
         {
             if (HIWORD(lParam) & KEYDATA_ALT)
             {
+                HWND top = GetAncestor(hWnd, GA_ROOT);
              /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
                 if ( (wParam == VK_MENU || wParam == VK_LMENU
                                     || wParam == VK_RMENU) && !iMenuSysKey )
+                {
                    iMenuSysKey = 1;
+                   /* mimic behaviour of XP, sending a WM_SYSCOMMAND when pressing <alt> */
+                   SendMessageW( top, WM_SYSCOMMAND, SC_KEYMENU, 0L );
+                }
                 else
                    iMenuSysKey = 0;
 
@@ -1364,8 +1406,7 @@ User32DefWindowProc(HWND hWnd,
 
                 if (wParam == VK_F4) /* Try to close the window */
                 {
-                    HWND top = GetAncestor(hWnd, GA_ROOT);
-                    if (!(GetClassLongW(top, GCL_STYLE) & CS_NOCLOSE))
+                    if (!(GetClassLongPtrW(top, GCL_STYLE) & CS_NOCLOSE))
                     {
                         if (bUnicode)
                             PostMessageW(top, WM_SYSCOMMAND, SC_CLOSE, 0);
@@ -1412,7 +1453,7 @@ User32DefWindowProc(HWND hWnd,
             if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
             {
                 if (wParam == '\t' || wParam == '\x1b') break;
-                if (wParam == ' ' && (GetWindowLongW( hWnd, GWL_STYLE ) & WS_CHILD))
+                if (wParam == ' ' && (GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD))
                     SendMessageW( GetParent(hWnd), Msg, wParam, lParam );
                 else
                     SendMessageW( hWnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
@@ -1429,11 +1470,18 @@ User32DefWindowProc(HWND hWnd,
             break;
         }
 
+        case WM_CLIENTSHUTDOWN:
+        {
+            LRESULT lResult;
+            NtUserMessageCall( hWnd, Msg, wParam, lParam, (ULONG_PTR)&lResult, FNID_DEFWINDOWPROC, FALSE);
+            return lResult;   
+        }
+
         case WM_CANCELMODE:
         {
             iMenuSysKey = 0;
             /* FIXME: Check for a desktop. */
-            if (!(GetWindowLongW( hWnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
+            if (!(GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
             if (GetCapture() == hWnd)
             {
                 ReleaseCapture();
@@ -1450,7 +1498,7 @@ User32DefWindowProc(HWND hWnd,
 */
         case WM_QUERYDROPOBJECT:
         {
-            if (GetWindowLongW(hWnd, GWL_EXSTYLE) & WS_EX_ACCEPTFILES)
+            if (GetWindowLongPtrW(hWnd, GWL_EXSTYLE) & WS_EX_ACCEPTFILES)
             {
                 return(1);
             }
@@ -1462,7 +1510,7 @@ User32DefWindowProc(HWND hWnd,
             UINT Len;
             HICON hIcon;
 
-            hIcon = (HICON)GetClassLongW(hWnd, GCL_HICON);
+            hIcon = (HICON)GetClassLongPtrW(hWnd, GCL_HICON);
             if (hIcon)
             {
                 return ((LRESULT)hIcon);
@@ -1489,8 +1537,8 @@ User32DefWindowProc(HWND hWnd,
         case WM_SETICON:
         {
            INT Index = (wParam != 0) ? GCL_HICON : GCL_HICONSM;
-           HICON hOldIcon = (HICON)GetClassLongW(hWnd, Index);
-           SetClassLongW(hWnd, Index, lParam);
+           HICON hOldIcon = (HICON)GetClassLongPtrW(hWnd, Index);
+           SetClassLongPtrW(hWnd, Index, lParam);
            SetWindowPos(hWnd, 0, 0, 0, 0, 0,
                       SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
                       SWP_NOACTIVATE | SWP_NOZORDER);
@@ -1500,7 +1548,7 @@ User32DefWindowProc(HWND hWnd,
         case WM_GETICON:
         {
             INT Index = (wParam == ICON_BIG) ? GCL_HICON : GCL_HICONSM;
-            return (GetClassLongW(hWnd, Index));
+            return (GetClassLongPtrW(hWnd, Index));
         }
 
         case WM_HELP:
@@ -1561,18 +1609,21 @@ User32DefWindowProc(HWND hWnd,
 
         case WM_INPUTLANGCHANGE:
         {
-            //FIXME: What to do?
-            return TRUE;
-        }
+            int count = 0;
+            HWND *win_array = WIN_ListChildren( hWnd );
 
-        case WM_ENDSESSION:
-            if (wParam) PostQuitMessage(0);
-            return 0;
+            if (!win_array)
+                break;
+            while (win_array[count])
+                SendMessageW( win_array[count++], WM_INPUTLANGCHANGE, wParam, lParam);
+            HeapFree(GetProcessHeap(),0,win_array);
+            break;
+        }
 
         case WM_QUERYUISTATE:
         {
             LRESULT Ret = 0;
-            PWINDOW Wnd = ValidateHwnd(hWnd);
+            PWND Wnd = ValidateHwnd(hWnd);
             if (Wnd != NULL)
             {
                 if (Wnd->HideFocus)
@@ -1585,10 +1636,10 @@ User32DefWindowProc(HWND hWnd,
 
         case WM_CHANGEUISTATE:
         {
-            BOOL AlwaysShowCues = TRUE;
+            BOOL AlwaysShowCues = FALSE;
             WORD Action = LOWORD(wParam);
             WORD Flags = HIWORD(wParam);
-            PWINDOW Wnd;
+            PWND Wnd;
 
             SystemParametersInfoW(SPI_GETKEYBOARDCUES, 0, &AlwaysShowCues, 0);
             if (AlwaysShowCues)
@@ -1608,7 +1659,7 @@ User32DefWindowProc(HWND hWnd,
 
             if (Action == UIS_INITIALIZE)
             {
-                PDESKTOP Desk = GetThreadDesktopInfo();
+                PDESKTOPINFO Desk = GetThreadDesktopInfo();
                 if (Desk == NULL)
                     break;
 
@@ -1646,11 +1697,11 @@ User32DefWindowProc(HWND hWnd,
                     break;
             }
 
-            if ((Wnd->Style & WS_CHILD) && Wnd->Parent != NULL)
+            if ((Wnd->style & WS_CHILD) && Wnd->spwndParent != NULL)
             {
                 /* We're a child window and we need to pass this message down until
                    we reach the root */
-                hWnd = UserHMGetHandle((PWINDOW)DesktopPtrToUser(Wnd->Parent));
+                hWnd = UserHMGetHandle((PWND)DesktopPtrToUser(Wnd->spwndParent));
             }
             else
             {
@@ -1667,10 +1718,10 @@ User32DefWindowProc(HWND hWnd,
         case WM_UPDATEUISTATE:
         {
             BOOL Change = TRUE;
-            BOOL AlwaysShowCues = TRUE;
+            BOOL AlwaysShowCues = FALSE;
             WORD Action = LOWORD(wParam);
             WORD Flags = HIWORD(wParam);
-            PWINDOW Wnd;
+            PWND Wnd;
 
             SystemParametersInfoW(SPI_GETKEYBOARDCUES, 0, &AlwaysShowCues, 0);
             if (AlwaysShowCues)
@@ -1690,7 +1741,7 @@ User32DefWindowProc(HWND hWnd,
 
             if (Action == UIS_INITIALIZE)
             {
-                PDESKTOP Desk = GetThreadDesktopInfo();
+                PDESKTOPINFO Desk = GetThreadDesktopInfo();
                 if (Desk == NULL)
                     break;
 
@@ -1750,37 +1801,100 @@ User32DefWindowProc(HWND hWnd,
 }
 
 
-LRESULT STDCALL
+/*
+ * helpers for calling IMM32 (from Wine 10/22/2008)
+ *
+ * WM_IME_* messages are generated only by IMM32,
+ * so I assume imm32 is already LoadLibrary-ed.
+ */
+static HWND
+DefWndImmGetDefaultIMEWnd(HWND hwnd)
+{
+    HINSTANCE hInstIMM = GetModuleHandleW(L"imm32\0");
+    HWND (WINAPI *pFunc)(HWND);
+    HWND hwndRet = 0;
+
+    if (!hInstIMM)
+    {
+        ERR("cannot get IMM32 handle\n");
+        return 0;
+    }
+
+    pFunc = (void*) GetProcAddress(hInstIMM, "ImmGetDefaultIMEWnd");
+    if (pFunc != NULL)
+        hwndRet = (*pFunc)(hwnd);
+
+    return hwndRet;
+}
+
+
+static BOOL
+DefWndImmIsUIMessageA(HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    HINSTANCE hInstIMM = GetModuleHandleW(L"imm32\0");
+    BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
+    BOOL fRet = FALSE;
+
+    if (!hInstIMM)
+    {
+        ERR("cannot get IMM32 handle\n");
+        return FALSE;
+    }
+
+    pFunc = (void*) GetProcAddress(hInstIMM, "ImmIsUIMessageA");
+    if (pFunc != NULL)
+        fRet = (*pFunc)(hwndIME, msg, wParam, lParam);
+
+    return fRet;
+}
+
+
+static BOOL
+DefWndImmIsUIMessageW(HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    HINSTANCE hInstIMM = GetModuleHandleW(L"imm32\0");
+    BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
+    BOOL fRet = FALSE;
+
+    if (!hInstIMM)
+    {
+        ERR("cannot get IMM32 handle\n");
+        return FALSE;
+    }
+
+    pFunc = (void*) GetProcAddress(hInstIMM, "ImmIsUIMessageW");
+    if (pFunc != NULL)
+        fRet = (*pFunc)(hwndIME, msg, wParam, lParam);
+
+    return fRet;
+}
+
+
+LRESULT WINAPI
 DefWindowProcA(HWND hWnd,
               UINT Msg,
               WPARAM wParam,
               LPARAM lParam)
 {
     LRESULT Result = 0;
-    PWINDOW Wnd;
+    PWND Wnd;
 
     SPY_EnterMessage(SPY_DEFWNDPROC, hWnd, Msg, wParam, lParam);
     switch (Msg)
     {
         case WM_NCCREATE:
         {
-            ANSI_STRING AnsiString;
-            UNICODE_STRING UnicodeString;
-            LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
-            /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
-             * may have child window IDs instead of window name */
-
-            if(cs->lpszName)
+            if (lParam)
             {
-              RtlInitAnsiString(&AnsiString, (LPSTR)cs->lpszName);
-              RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString, TRUE);
-              NtUserDefSetText(hWnd, &UnicodeString);
-              RtlFreeUnicodeString(&UnicodeString);
+                LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
+                /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
+                 * may have child window IDs instead of window name */
+                if (HIWORD(cs->lpszName))
+                {
+                    DefSetText(hWnd, (PCWSTR)cs->lpszName, TRUE);
+                }
+                Result = 1;
             }
-            else
-              NtUserDefSetText(hWnd, NULL);
-
-            Result = 1;
             break;
         }
 
@@ -1790,17 +1904,19 @@ DefWindowProcA(HWND hWnd,
             ULONG len;
 
             Wnd = ValidateHwnd(hWnd);
-            if (Wnd != NULL && Wnd->WindowName.Length != 0)
+            if (Wnd != NULL && Wnd->strName.Length != 0)
             {
-                buf = DesktopPtrToUser(Wnd->WindowName.Buffer);
+                buf = DesktopPtrToUser(Wnd->strName.Buffer);
                 if (buf != NULL &&
                     NT_SUCCESS(RtlUnicodeToMultiByteSize(&len,
                                                          buf,
-                                                         Wnd->WindowName.Length)))
+                                                         Wnd->strName.Length)))
                 {
-                    Result = (LRESULT)len;
+                    Result = (LRESULT) len;
                 }
             }
+            else Result = 0L;
+
             break;
         }
 
@@ -1813,16 +1929,16 @@ DefWindowProcA(HWND hWnd,
             Wnd = ValidateHwnd(hWnd);
             if (Wnd != NULL && wParam != 0)
             {
-                if (Wnd->WindowName.Buffer != NULL)
-                    buf = DesktopPtrToUser(Wnd->WindowName.Buffer);
+                if (Wnd->strName.Buffer != NULL)
+                    buf = DesktopPtrToUser(Wnd->strName.Buffer);
                 else
                     outbuf[0] = L'\0';
 
                 if (buf != NULL)
                 {
-                    if (Wnd->WindowName.Length != 0)
+                    if (Wnd->strName.Length != 0)
                     {
-                        copy = min(Wnd->WindowName.Length / sizeof(WCHAR), wParam - 1);
+                        copy = min(Wnd->strName.Length / sizeof(WCHAR), wParam - 1);
                         Result = WideCharToMultiByte(CP_ACP,
                                                      0,
                                                      buf,
@@ -1842,20 +1958,9 @@ DefWindowProcA(HWND hWnd,
 
         case WM_SETTEXT:
         {
-            ANSI_STRING AnsiString;
-            UNICODE_STRING UnicodeString;
-
-            if(lParam)
-            {
-              RtlInitAnsiString(&AnsiString, (LPSTR)lParam);
-              RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString, TRUE);
-              NtUserDefSetText(hWnd, &UnicodeString);
-              RtlFreeUnicodeString(&UnicodeString);
-            }
-            else
-              NtUserDefSetText(hWnd, NULL);
+            DefSetText(hWnd, (PCWSTR)lParam, TRUE);
 
-            if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION)
+            if ((GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION)
             {
                 DefWndNCPaint(hWnd, (HRGN)1, -1);
             }
@@ -1864,16 +1969,50 @@ DefWindowProcA(HWND hWnd,
             break;
         }
 
-/*      FIXME: Implement these. */
-        case WM_IME_CHAR:
         case WM_IME_KEYDOWN:
+        {
+            Result = PostMessageA(hWnd, WM_KEYDOWN, wParam, lParam);
+            break;
+        }
+
         case WM_IME_KEYUP:
+        {
+            Result = PostMessageA(hWnd, WM_KEYUP, wParam, lParam);
+            break;
+        }
+
+        case WM_IME_CHAR:
+        {
+            if (HIBYTE(wParam))
+                PostMessageA(hWnd, WM_CHAR, HIBYTE(wParam), lParam);
+            PostMessageA(hWnd, WM_CHAR, LOBYTE(wParam), lParam);
+            break;
+        }
+
         case WM_IME_STARTCOMPOSITION:
         case WM_IME_COMPOSITION:
         case WM_IME_ENDCOMPOSITION:
         case WM_IME_SELECT:
+        case WM_IME_NOTIFY:
+        {
+            HWND hwndIME;
+
+            hwndIME = DefWndImmGetDefaultIMEWnd(hWnd);
+            if (hwndIME)
+                Result = SendMessageA(hwndIME, Msg, wParam, lParam);
+            break;
+        }
+
         case WM_IME_SETCONTEXT:
-            FIXME("FIXME: WM_IME_* conversion isn't implemented yet!");
+        {
+            HWND hwndIME;
+
+            hwndIME = DefWndImmGetDefaultIMEWnd(hWnd);
+            if (hwndIME)
+                Result = DefWndImmIsUIMessageA(hwndIME, Msg, wParam, lParam);
+            break;
+        }
+
         /* fall through */
         default:
             Result = User32DefWindowProc(hWnd, Msg, wParam, lParam, FALSE);
@@ -1884,30 +2023,32 @@ DefWindowProcA(HWND hWnd,
 }
 
 
-LRESULT STDCALL
+LRESULT WINAPI
 DefWindowProcW(HWND hWnd,
               UINT Msg,
               WPARAM wParam,
               LPARAM lParam)
 {
     LRESULT Result = 0;
-    PWINDOW Wnd;
+    PWND Wnd;
 
     SPY_EnterMessage(SPY_DEFWNDPROC, hWnd, Msg, wParam, lParam);
     switch (Msg)
     {
         case WM_NCCREATE:
         {
-            UNICODE_STRING UnicodeString;
-            LPCREATESTRUCTW cs = (LPCREATESTRUCTW)lParam;
-            /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
-             * may have child window IDs instead of window name */
-
-            if(cs->lpszName)
-              RtlInitUnicodeString(&UnicodeString, (LPWSTR)cs->lpszName);
+            if (lParam)
+            {
+                LPCREATESTRUCTW cs = (LPCREATESTRUCTW)lParam;
+                /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
+                 * may have child window IDs instead of window name */
 
-            NtUserDefSetText( hWnd, (cs->lpszName ? &UnicodeString : NULL));
-            Result = 1;
+                if (HIWORD(cs->lpszName))
+                {
+                    DefSetText(hWnd, cs->lpszName, FALSE);
+                }
+                Result = 1;
+            }
             break;
         }
 
@@ -1917,17 +2058,19 @@ DefWindowProcW(HWND hWnd,
             ULONG len;
 
             Wnd = ValidateHwnd(hWnd);
-            if (Wnd != NULL && Wnd->WindowName.Length != 0)
+            if (Wnd != NULL && Wnd->strName.Length != 0)
             {
-                buf = DesktopPtrToUser(Wnd->WindowName.Buffer);
+                buf = DesktopPtrToUser(Wnd->strName.Buffer);
                 if (buf != NULL &&
                     NT_SUCCESS(RtlUnicodeToMultiByteSize(&len,
                                                          buf,
-                                                         Wnd->WindowName.Length)))
+                                                         Wnd->strName.Length)))
                 {
-                    Result = (LRESULT)len;
+                    Result = (LRESULT) (Wnd->strName.Length / sizeof(WCHAR));
                 }
             }
+            else Result = 0L;
+
             break;
         }
 
@@ -1939,16 +2082,16 @@ DefWindowProcW(HWND hWnd,
             Wnd = ValidateHwnd(hWnd);
             if (Wnd != NULL && wParam != 0)
             {
-                if (Wnd->WindowName.Buffer != NULL)
-                    buf = DesktopPtrToUser(Wnd->WindowName.Buffer);
+                if (Wnd->strName.Buffer != NULL)
+                    buf = DesktopPtrToUser(Wnd->strName.Buffer);
                 else
                     outbuf[0] = L'\0';
 
                 if (buf != NULL)
                 {
-                    if (Wnd->WindowName.Length != 0)
+                    if (Wnd->strName.Length != 0)
                     {
-                        Result = min(Wnd->WindowName.Length / sizeof(WCHAR), wParam - 1);
+                        Result = min(Wnd->strName.Length / sizeof(WCHAR), wParam - 1);
                         RtlCopyMemory(outbuf,
                                       buf,
                                       Result * sizeof(WCHAR));
@@ -1963,14 +2106,9 @@ DefWindowProcW(HWND hWnd,
 
         case WM_SETTEXT:
         {
-            UNICODE_STRING UnicodeString;
-
-            if(lParam)
-              RtlInitUnicodeString(&UnicodeString, (LPWSTR)lParam);
+            DefSetText(hWnd, (PCWSTR)lParam, FALSE);
 
-            NtUserDefSetText(hWnd, (lParam ? &UnicodeString : NULL));
-
-            if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION)
+            if ((GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION)
             {
                 DefWndNCPaint(hWnd, (HRGN)1, -1);
             }
@@ -1980,16 +2118,44 @@ DefWindowProcW(HWND hWnd,
 
         case WM_IME_CHAR:
         {
-            SendMessageW(hWnd, WM_CHAR, wParam, lParam);
+            PostMessageW(hWnd, WM_CHAR, wParam, lParam);
             Result = 0;
             break;
         }
 
+        case WM_IME_KEYDOWN:
+        {
+            Result = PostMessageW(hWnd, WM_KEYDOWN, wParam, lParam);
+            break;
+        }
+
+        case WM_IME_KEYUP:
+        {
+            Result = PostMessageW(hWnd, WM_KEYUP, wParam, lParam);
+            break;
+        }
+
+        case WM_IME_STARTCOMPOSITION:
+        case WM_IME_COMPOSITION:
+        case WM_IME_ENDCOMPOSITION:
+        case WM_IME_SELECT:
+        case WM_IME_NOTIFY:
+        {
+            HWND hwndIME;
+
+            hwndIME = DefWndImmGetDefaultIMEWnd(hWnd);
+            if (hwndIME)
+                Result = SendMessageW(hwndIME, Msg, wParam, lParam);
+            break;
+        }
+
         case WM_IME_SETCONTEXT:
         {
-            /* FIXME */
-            FIXME("FIXME: WM_IME_SETCONTEXT is not implemented!");
-            Result = 0;
+            HWND hwndIME;
+
+            hwndIME = DefWndImmGetDefaultIMEWnd(hWnd);
+            if (hwndIME)
+                Result = DefWndImmIsUIMessageW(hwndIME, Msg, wParam, lParam);
             break;
         }