[Win32k|User32]
authorJames Tabor <james.tabor@reactos.org>
Fri, 4 Nov 2011 13:16:48 +0000 (13:16 +0000)
committerJames Tabor <james.tabor@reactos.org>
Fri, 4 Nov 2011 13:16:48 +0000 (13:16 +0000)
- Move control color support to Win32k.

svn path=/trunk/; revision=54288

reactos/dll/win32/user32/controls/button.c
reactos/dll/win32/user32/controls/listbox.c
reactos/dll/win32/user32/include/ntwrapper.h
reactos/dll/win32/user32/include/user32p.h
reactos/dll/win32/user32/misc/misc.c
reactos/subsystems/win32/win32k/ntuser/defwnd.c
reactos/subsystems/win32/win32k/ntuser/misc.c
reactos/subsystems/win32/win32k/ntuser/ntstubs.c

index bc5cb41..af205c5 100644 (file)
@@ -335,10 +335,7 @@ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
             HBRUSH hBrush;
             HWND parent = GetParent(hWnd);
             if (!parent) parent = hWnd;
-            hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hdc, (LPARAM)hWnd);
-            if (!hBrush) /* did the app forget to call defwindowproc ? */
-                hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN,
-                                                (WPARAM)hdc, (LPARAM)hWnd);
+            hBrush = GetControlColor( parent, hWnd, hdc, WM_CTLCOLORBTN);
             GetClientRect(hWnd, &rc);
             FillRect(hdc, &rc, hBrush);
         }
@@ -885,7 +882,7 @@ static void PB_Paint( HWND hwnd, HDC hDC, UINT action )
     if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
     parent = GetParent(hwnd);
     if (!parent) parent = hwnd;
-    SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd );
+    GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN);
 
     setup_clipping( hwnd, hDC );
 #ifdef __REACTOS__
@@ -1175,10 +1172,7 @@ static void UB_Paint( HWND hwnd, HDC hDC, UINT action )
 
     parent = GetParent(hwnd);
     if (!parent) parent = hwnd;
-    hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd);
-    if (!hBrush) /* did the app forget to call defwindowproc ? */
-        hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN,
-                                       (WPARAM)hDC, (LPARAM)hwnd);
+    hBrush = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN);
 
     FillRect( hDC, &rc, hBrush );
     if ((action == ODA_FOCUS) ||
@@ -1219,7 +1213,7 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action )
     if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hDC, hFont );
     parent = GetParent(hwnd);
     if (!parent) parent = hwnd;
-    SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd );
+    GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN);
 
     setup_clipping( hwnd, hDC );
 
index 2dafc92..07165d3 100644 (file)
@@ -660,8 +660,7 @@ static void LISTBOX_RepaintItem( LB_DESCR *descr, INT index, UINT action )
     if (LISTBOX_GetItemRect( descr, index, &rect ) != 1) return;
     if (!(hdc = GetDCEx( descr->self, 0, DCX_CACHE ))) return;
     if (descr->font) oldFont = SelectObject( hdc, descr->font );
-    hbrush = (HBRUSH)SendMessageW( descr->owner, WM_CTLCOLORLISTBOX,
-                                  (WPARAM)hdc, (LPARAM)descr->self );
+    hbrush = GetControlColor( descr->owner, descr->self, hdc, WM_CTLCOLORLISTBOX);
     if (hbrush) oldBrush = SelectObject( hdc, hbrush );
     if (!IsWindowEnabled(descr->self))
         SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
@@ -1032,8 +1031,7 @@ static LRESULT LISTBOX_Paint( LB_DESCR *descr, HDC hdc )
     }
 
     if (descr->font) oldFont = SelectObject( hdc, descr->font );
-    hbrush = (HBRUSH)SendMessageW( descr->owner, WM_CTLCOLORLISTBOX,
-                                  (WPARAM)hdc, (LPARAM)descr->self );
+    hbrush = GetControlColor( descr->owner, descr->self, hdc, WM_CTLCOLORLISTBOX);
     if (hbrush) oldBrush = SelectObject( hdc, hbrush );
     if (!IsWindowEnabled(descr->self)) SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
 
@@ -3162,8 +3160,7 @@ LRESULT WINAPI ListBoxWndProc_common( HWND hwnd, UINT msg,
         if ((IS_OWNERDRAW(descr)) && !(descr->style & LBS_DISPLAYCHANGED))
         {
             RECT rect;
-            HBRUSH hbrush = (HBRUSH)SendMessageW( descr->owner, WM_CTLCOLORLISTBOX,
-                                              wParam, (LPARAM)descr->self );
+            HBRUSH hbrush = GetControlColor( descr->owner, descr->self, (HDC)wParam, WM_CTLCOLORLISTBOX);
            TRACE("hbrush = %p\n", hbrush);
            if(!hbrush)
                hbrush = GetSysColorBrush(COLOR_WINDOW);
index 3ba2d50..7e7873d 100644 (file)
@@ -240,6 +240,16 @@ GetClipCursor(LPRECT lpRect)
     return NtUserGetClipCursor(lpRect);
 }
 
+EXTINLINE HBRUSH WINAPI GetControlBrush(HWND hwnd, HDC  hdc, UINT ctlType)
+{
+    return NtUserGetControlBrush(hwnd, hdc, ctlType);
+}
+
+EXTINLINE HBRUSH WINAPI GetControlColor(HWND hwndParent, HWND hwnd, HDC hdc, UINT CtlMsg)
+{
+    return NtUserGetControlColor(hwndParent, hwnd, hdc, CtlMsg);
+}
+
 EXTINLINE BOOL WINAPI
 GetCursorInfo(PCURSORINFO pci)
 {
index 82f6872..b7d8aff 100644 (file)
@@ -100,7 +100,5 @@ BOOL UserDrawSysMenuButton( HWND hWnd, HDC hDC, LPRECT, BOOL down );
 HWND* WIN_ListChildren (HWND hWndparent);
 VOID DeleteFrameBrushes(VOID);
 BOOL WINAPI GdiValidateHandle(HGDIOBJ);
-HBRUSH FASTCALL GetControlColor(HWND,HWND,HDC,UINT);
-HBRUSH FASTCALL GetControlBrush(HWND,HDC,UINT);
 
 /* EOF */
index 33e1ca7..b729f3d 100644 (file)
@@ -481,45 +481,6 @@ ValidateHwndOrDesk(HWND hwnd)
     return ValidateHwnd(hwnd);
 }
 
-HBRUSH
-FASTCALL
-GetControlColor(
-   HWND hwndParent,
-   HWND hwnd,
-   HDC hdc,
-   UINT CtlMsg)
-{
-    PWND pwnd;
-    HBRUSH hBrush;
-
-    if (!hwndParent) hwndParent = hwnd;
-
-    pwnd = ValidateHwnd(hwndParent);
-    if (pwnd && !TestWindowProcess(pwnd))
-    {
-       return (HBRUSH)DefWindowProcW( hwndParent, CtlMsg, (WPARAM)hdc, (LPARAM)hwnd);
-    }
-
-    hBrush = (HBRUSH)SendMessageW( hwndParent, CtlMsg, (WPARAM)hdc, (LPARAM)hwnd);
-
-    if (!hBrush || !GdiValidateHandle(hBrush))
-    {
-       hBrush = (HBRUSH)DefWindowProcW( hwndParent, CtlMsg, (WPARAM)hdc, (LPARAM)hwnd);
-    }
-    return hBrush;
-}
-
-HBRUSH
-FASTCALL
-GetControlBrush(
-   HWND hwnd,
-   HDC  hdc,
-   UINT ctlType)
-{
-    HWND hwndParent = GetParent(hwnd);
-    return GetControlColor( hwndParent, hwnd, hdc, ctlType);
-}
-
 /*
  * @implemented
  */
index b52f2b3..b56a111 100644 (file)
@@ -94,6 +94,43 @@ IntClientShutdown(
    return lResult;
 }
 
+HBRUSH FASTCALL
+DefWndControlColor(HDC hDC, UINT ctlType)
+{
+  if (ctlType == CTLCOLOR_SCROLLBAR)
+  {
+      HBRUSH hb = IntGetSysColorBrush(COLOR_SCROLLBAR);
+      COLORREF bk = IntGetSysColor(COLOR_3DHILIGHT);
+      IntGdiSetTextColor(hDC, IntGetSysColor(COLOR_3DFACE));
+      IntGdiSetBkColor(hDC, bk);
+
+      /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
+       * we better use 0x55aa bitmap brush to make scrollbar's background
+       * look different from the window background.
+       */
+      if ( bk == IntGetSysColor(COLOR_WINDOW))
+          return gpsi->hbrGray;
+
+      NtGdiUnrealizeObject( hb );
+      return hb;
+  }
+
+  IntGdiSetTextColor(hDC, IntGetSysColor(COLOR_WINDOWTEXT));
+
+  if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
+  {
+      IntGdiSetBkColor(hDC, IntGetSysColor(COLOR_WINDOW));
+  }
+  else
+  {
+      IntGdiSetBkColor(hDC, IntGetSysColor(COLOR_3DFACE));
+      return IntGetSysColorBrush(COLOR_3DFACE);
+  }
+
+  return IntGetSysColorBrush(COLOR_WINDOW);
+}
+
+
 LRESULT FASTCALL
 DefWndHandleSysCommand(PWND pWnd, WPARAM wParam, LPARAM lParam)
 {
@@ -168,11 +205,31 @@ IntDefWindowProc(
       case WM_CLIENTSHUTDOWN:
          return IntClientShutdown(Wnd, wParam, lParam);
 
+      case WM_CTLCOLORMSGBOX:
+      case WM_CTLCOLOREDIT:
+      case WM_CTLCOLORLISTBOX:
+      case WM_CTLCOLORBTN:
+      case WM_CTLCOLORDLG:
+      case WM_CTLCOLORSTATIC:
+      case WM_CTLCOLORSCROLLBAR:
+           return (LRESULT) DefWndControlColor((HDC)wParam, Msg - WM_CTLCOLORMSGBOX);
+
+      case WM_CTLCOLOR:
+           return (LRESULT) DefWndControlColor((HDC)wParam, HIWORD(lParam));
+
       case WM_GETHOTKEY:
          return DefWndGetHotKey(UserHMGetHandle(Wnd));                
       case WM_SETHOTKEY:
          return DefWndSetHotKey(Wnd, wParam);
 
+      case WM_NCHITTEST:
+      {
+         POINT Point;
+         Point.x = GET_X_LPARAM(lParam);
+         Point.y = GET_Y_LPARAM(lParam);
+         return GetNCHitEx(Wnd, Point);
+      }
+
       /* ReactOS only. */
       case WM_CBT:
       {
index 35cced1..4542a26 100644 (file)
@@ -55,6 +55,90 @@ IntGdiGetLanguageID(VOID)
   return (SHORT) Ret;
 }
 
+HBRUSH
+FASTCALL
+GetControlColor(
+   PWND pwndParent,
+   PWND pwnd,
+   HDC hdc,
+   UINT CtlMsg)
+{
+    HBRUSH hBrush;
+
+    if (!pwndParent) pwndParent = pwnd;
+
+    if ( pwndParent->head.pti->ppi != PsGetCurrentProcessWin32Process())
+    {
+       return (HBRUSH)IntDefWindowProc( pwndParent, CtlMsg, (WPARAM)hdc, (LPARAM)UserHMGetHandle(pwnd), FALSE);
+    }
+
+    hBrush = (HBRUSH)co_IntSendMessage( UserHMGetHandle(pwndParent), CtlMsg, (WPARAM)hdc, (LPARAM)UserHMGetHandle(pwnd));
+
+    if (!hBrush || !GreIsHandleValid(hBrush))
+    {
+       hBrush = (HBRUSH)IntDefWindowProc( pwndParent, CtlMsg, (WPARAM)hdc, (LPARAM)UserHMGetHandle(pwnd), FALSE);
+    }
+    return hBrush;
+}
+
+HBRUSH
+FASTCALL
+GetControlBrush(
+   PWND pwnd,
+   HDC  hdc,
+   UINT ctlType)
+{
+    PWND pwndParent = IntGetParent(pwnd);
+    return GetControlColor( pwndParent, pwnd, hdc, ctlType);
+}
+
+HBRUSH
+APIENTRY
+NtUserGetControlBrush(
+   HWND hwnd,
+   HDC  hdc,
+   UINT ctlType)
+{
+   PWND pwnd;
+   HBRUSH hBrush = NULL;
+
+   UserEnterExclusive();
+   if ( (pwnd = UserGetWindowObject(hwnd)) &&
+       ((ctlType - WM_CTLCOLORMSGBOX) < CTLCOLOR_MAX) &&
+        hdc )
+   {
+      hBrush = GetControlBrush(pwnd, hdc, ctlType);
+   }
+   UserLeave();
+   return hBrush;
+}
+
+/*
+ * Called from PaintRect, works almost like wine PaintRect16 but returns hBrush.
+ */
+HBRUSH
+APIENTRY
+NtUserGetControlColor(
+   HWND hwndParent,
+   HWND hwnd,
+   HDC hdc,
+   UINT CtlMsg) // Wine PaintRect: WM_CTLCOLORMSGBOX + hbrush
+{
+   PWND pwnd, pwndParent = NULL;
+   HBRUSH hBrush = NULL;
+
+   UserEnterExclusive();
+   if ( (pwnd = UserGetWindowObject(hwnd)) &&
+       ((CtlMsg - WM_CTLCOLORMSGBOX) < CTLCOLOR_MAX) &&
+        hdc )
+   {
+      if (hwndParent) pwndParent = UserGetWindowObject(hwndParent);
+      hBrush = GetControlColor( pwndParent, pwnd, hdc, CtlMsg);
+   }
+   UserLeave();
+   return hBrush;
+}
+
 /*
  * @unimplemented
  */
index d0cd8e9..2160be9 100644 (file)
@@ -208,35 +208,6 @@ NtUserGetAltTabInfo(
    return 0;
 }
 
-HBRUSH
-APIENTRY
-NtUserGetControlBrush(
-   HWND hwnd,
-   HDC  hdc,
-   UINT ctlType)
-{
-   STUB
-
-   return 0;
-}
-
-
-/*
- * Called from PaintRect, works almost like wine PaintRect16 but returns hBrush.
- */
-HBRUSH
-APIENTRY
-NtUserGetControlColor(
-   HWND hwndParent,
-   HWND hwnd,
-   HDC hdc,
-   UINT CtlMsg) // Wine PaintRect: WM_CTLCOLORMSGBOX + hbrush
-{
-   STUB
-
-   return 0;
-}
-
 DWORD
 APIENTRY
 NtUserGetImeHotKey(