Sync with trunk r43123
[reactos.git] / reactos / dll / win32 / user32 / windows / defwnd.c
index 98648dd..52da270 100644 (file)
@@ -52,7 +52,7 @@ InitStockObjects(void)
              SysColors table - the pens, brushes and stock objects are not affected
              as their handles never change. But it'd be faster to map them, too. */
 
- // Done! g_psi!
+ // Done! gpsi!
 }
 
 /*
@@ -63,28 +63,13 @@ GetSysColor(int nIndex)
 {
   if(nIndex >= 0 && nIndex < NUM_SYSCOLORS)
   {
-    return g_psi->argbSystem[nIndex];
+    return gpsi->argbSystem[nIndex];
   }
 
   SetLastError(ERROR_INVALID_PARAMETER);
   return 0;
 }
 
-/*
- * @implemented
- */
-HPEN WINAPI
-GetSysColorPen(int nIndex)
-{
-  if(nIndex >= 0 && nIndex < NUM_SYSCOLORS)
-  {
-    return g_psi->SysColorPens[nIndex];
-  }
-
-  SetLastError(ERROR_INVALID_PARAMETER);
-  return NULL;
-}
-
 /*
  * @implemented
  */
@@ -93,7 +78,7 @@ GetSysColorBrush(int nIndex)
 {
   if(nIndex >= 0 && nIndex < NUM_SYSCOLORS)
   {
-    return g_psi->ahbrSystem[nIndex];
+    return gpsi->ahbrSystem[nIndex];
   }
 
   SetLastError(ERROR_INVALID_PARAMETER);
@@ -130,17 +115,17 @@ DefSetText(HWND hWnd, PCWSTR String, BOOL Ansi)
 }
 
 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)
     {
@@ -277,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)
     {
@@ -424,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;
 
@@ -482,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);
@@ -685,8 +670,9 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
 //#if 0
 //  if (ISITHOOKED(WH_CBT))
   {
-      if (NtUserMessageCall( hwnd, WM_CBT, HCBT_MOVESIZE, (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
   (void)NtUserSetGUIThreadHandle(MSQ_STATE_MOVESIZE, NULL);
@@ -773,8 +759,9 @@ DefWndHandleSysCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
 //#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
   switch (wParam & 0xfff0)
@@ -983,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
@@ -1161,7 +1148,7 @@ User32DefWindowProc(HWND hWnd,
             else
             {
                 POINT Pt;
-                DWORD Style;
+                LONG_PTR Style;
                 LONG HitCode;
 
                 Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
@@ -1258,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);
         }
 
@@ -1358,7 +1352,7 @@ User32DefWindowProc(HWND hWnd,
 
         case WM_SETCURSOR:
         {
-            ULONG Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
+            LONG_PTR Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
 
             if (Style & WS_CHILD)
             {
@@ -1476,6 +1470,13 @@ 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;
@@ -1524,7 +1525,15 @@ User32DefWindowProc(HWND hWnd,
             return ((LRESULT)LoadIconW(0, IDI_APPLICATION));
         }
 
-        /* FIXME: WM_ISACTIVEICON */
+        case WM_ISACTIVEICON:
+        {
+           PWND pWnd;
+           BOOL isai;
+           pWnd = ValidateHwnd(hWnd);
+           if (!pWnd) return 0;
+           isai = (pWnd->state & WNDS_ACTIVEFRAME) != 0;
+           return isai;
+        }
 
         case WM_NOTIFYFORMAT:
         {
@@ -1622,7 +1631,7 @@ User32DefWindowProc(HWND hWnd,
         case WM_QUERYUISTATE:
         {
             LRESULT Ret = 0;
-            PWINDOW Wnd = ValidateHwnd(hWnd);
+            PWND Wnd = ValidateHwnd(hWnd);
             if (Wnd != NULL)
             {
                 if (Wnd->HideFocus)
@@ -1638,7 +1647,7 @@ User32DefWindowProc(HWND hWnd,
             BOOL AlwaysShowCues = FALSE;
             WORD Action = LOWORD(wParam);
             WORD Flags = HIWORD(wParam);
-            PWINDOW Wnd;
+            PWND Wnd;
 
             SystemParametersInfoW(SPI_GETKEYBOARDCUES, 0, &AlwaysShowCues, 0);
             if (AlwaysShowCues)
@@ -1696,11 +1705,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
             {
@@ -1720,7 +1729,7 @@ User32DefWindowProc(HWND hWnd,
             BOOL AlwaysShowCues = FALSE;
             WORD Action = LOWORD(wParam);
             WORD Flags = HIWORD(wParam);
-            PWINDOW Wnd;
+            PWND Wnd;
 
             SystemParametersInfoW(SPI_GETKEYBOARDCUES, 0, &AlwaysShowCues, 0);
             if (AlwaysShowCues)
@@ -1783,7 +1792,7 @@ User32DefWindowProc(HWND hWnd,
             /* Pack the information and call win32k */
             if (Change)
             {
-                if (!NtUserCallTwoParam((DWORD)hWnd, (DWORD)Flags | ((DWORD)Action << 3), TWOPARAM_ROUTINE_ROS_UPDATEUISTATE))
+                if (!NtUserCallTwoParam((DWORD_PTR)hWnd, (DWORD_PTR)Flags | ((DWORD_PTR)Action << 3), TWOPARAM_ROUTINE_ROS_UPDATEUISTATE))
                     break;
             }
 
@@ -1870,26 +1879,30 @@ DefWndImmIsUIMessageW(HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam)
 
 
 LRESULT WINAPI
-DefWindowProcA(HWND hWnd,
-              UINT Msg,
-              WPARAM wParam,
-              LPARAM lParam)
+RealDefWindowProcA(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:
         {
-            LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
-            /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
-             * may have child window IDs instead of window name */
-
-             DefSetText(hWnd, (PCWSTR)cs->lpszName, TRUE);
-
-            Result = 1;
+            if (lParam)
+            {
+                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;
+            }
             break;
         }
 
@@ -1899,13 +1912,13 @@ 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;
                 }
@@ -1924,16 +1937,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,
@@ -2019,25 +2032,31 @@ DefWindowProcA(HWND hWnd,
 
 
 LRESULT WINAPI
-DefWindowProcW(HWND hWnd,
-              UINT Msg,
-              WPARAM wParam,
-              LPARAM lParam)
+RealDefWindowProcW(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:
         {
-            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 (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 */
 
-            DefSetText(hWnd, cs->lpszName, FALSE);
-            Result = 1;
+                if (HIWORD(cs->lpszName))
+                {
+                    DefSetText(hWnd, cs->lpszName, FALSE);
+                }
+                Result = 1;
+            }
             break;
         }
 
@@ -2047,15 +2066,15 @@ 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) (Wnd->WindowName.Length / sizeof(WCHAR));
+                    Result = (LRESULT) (Wnd->strName.Length / sizeof(WCHAR));
                 }
             }
             else Result = 0L;
@@ -2071,16 +2090,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));
@@ -2156,3 +2175,68 @@ DefWindowProcW(HWND hWnd,
     return Result;
 }
 
+LRESULT WINAPI
+DefWindowProcA(HWND hWnd,
+              UINT Msg,
+              WPARAM wParam,
+              LPARAM lParam)
+{
+   BOOL Hook, msgOverride = FALSE;
+   LRESULT Result = 0;
+
+   LOADUSERAPIHOOK
+
+   Hook = BeginIfHookedUserApiHook();
+   if (Hook)
+      msgOverride = IsMsgOverride(Msg, &guah.DefWndProcArray);
+
+   /* Bypass SEH and go direct. */
+   if (!Hook || !msgOverride)
+      return RealDefWindowProcA(hWnd, Msg, wParam, lParam);
+
+   _SEH2_TRY
+   {
+      Result = guah.DefWindowProcA(hWnd, Msg, wParam, lParam);
+   }
+   _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+   {
+   }
+   _SEH2_END;
+
+   EndUserApiHook();
+
+   return Result;
+}
+
+LRESULT WINAPI
+DefWindowProcW(HWND hWnd,
+              UINT Msg,
+              WPARAM wParam,
+              LPARAM lParam)
+{
+   BOOL Hook, msgOverride = FALSE;
+   LRESULT Result = 0;
+
+   LOADUSERAPIHOOK
+
+   Hook = BeginIfHookedUserApiHook();
+   if (Hook)
+      msgOverride = IsMsgOverride(Msg, &guah.DefWndProcArray);
+
+   /* Bypass SEH and go direct. */
+   if (!Hook || !msgOverride)
+      return RealDefWindowProcW(hWnd, Msg, wParam, lParam);
+
+   _SEH2_TRY
+   {
+      Result = guah.DefWindowProcW(hWnd, Msg, wParam, lParam);
+   }
+   _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+   {
+   }
+   _SEH2_END;
+
+   EndUserApiHook();
+
+   return Result;
+}