[COMCTL32] -Rename BUTTON_Paint to BUTTON_PaintWithTheme and use it in the newly...
authorGiannis Adamopoulos <gadamopoulos@reactos.org>
Tue, 21 Feb 2017 21:47:41 +0000 (21:47 +0000)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Tue, 21 Feb 2017 21:47:41 +0000 (21:47 +0000)
svn path=/trunk/; revision=73873

reactos/dll/win32/comctl32/button.c
reactos/dll/win32/comctl32/theme_button.c

index de7004d..9ad2e99 100644 (file)
@@ -205,7 +205,7 @@ HRGN set_control_clipping( HDC hdc, const RECT *rect )
     return hrgn;
 }
 
-BOOL BUTTON_Paint(HTHEME theme, HWND hwnd, HDC hParamDC, UINT action);
+BOOL BUTTON_PaintWithTheme(HTHEME theme, HWND hwnd, HDC hParamDC);
 
 #endif
 
@@ -227,12 +227,31 @@ static inline UINT get_button_type( LONG window_style )
 /* paint a button of any type */
 static inline void paint_button( HWND hwnd, LONG style, UINT action )
 {
+#ifndef _USER32_
+    HTHEME theme = GetWindowTheme(hwnd);
+    RECT rc;
+    HDC hdc = GetDC( hwnd );
+    /* GetDC appears to give a dc with a clip rect that includes the whoe parent, not sure if it is correct or not. */
+    GetClientRect(hwnd, &rc);
+    IntersectClipRect (hdc, rc.left, rc. top, rc.right, rc.bottom);
+    if (theme && BUTTON_PaintWithTheme(theme, hwnd, hdc))
+    {
+        ReleaseDC( hwnd, hdc );
+        return;
+    }
+    if (btnPaintFunc[style] && IsWindowVisible(hwnd))
+    {
+        btnPaintFunc[style]( hwnd, hdc, action );
+    }
+    ReleaseDC( hwnd, hdc );
+#elif
     if (btnPaintFunc[style] && IsWindowVisible(hwnd))
     {
         HDC hdc = GetDC( hwnd );
         btnPaintFunc[style]( hwnd, hdc, action );
         ReleaseDC( hwnd, hdc );
     }
+#endif
 }
 
 /* retrieve the button text; returned buffer must be freed by caller */
@@ -342,6 +361,9 @@ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
         set_button_state( hWnd, BST_UNCHECKED );
 #ifdef __REACTOS__
         button_update_uistate( hWnd, unicode );
+#endif
+#ifndef _USER32_
+        OpenThemeData(hWnd, WC_BUTTONW);
 #endif
         return 0;
 
@@ -351,7 +373,31 @@ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
     case WM_DESTROY:
         break;
 #endif
+#ifndef _USER32_
+    case WM_DESTROY:
+        CloseThemeData (GetWindowTheme(hWnd));
+        break;
+    case WM_THEMECHANGED:
+        CloseThemeData (GetWindowTheme(hWnd));
+        OpenThemeData(hWnd, WC_BUTTONW);
+        break;
+
+    case WM_MOUSEHOVER:
+    {
+        int state = (int)SendMessageW(hWnd, BM_GETSTATE, 0, 0);
+        SetWindowLongW(hWnd, 0, state|BST_HOT);
+        InvalidateRect(hWnd, NULL, FALSE);
+        break;
+    }
 
+    case WM_MOUSELEAVE:
+    {
+        int state = (int)SendMessageW(hWnd, BM_GETSTATE, 0, 0);
+        SetWindowLongW(hWnd, 0, state&(~BST_HOT));
+        InvalidateRect(hWnd, NULL, FALSE);
+        break;
+    }
+#endif
     case WM_ERASEBKGND:
         if (btn_type == BS_OWNERDRAW)
         {
@@ -378,6 +424,14 @@ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
     {
         PAINTSTRUCT ps;
         HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
+#ifndef _USER32_
+        HTHEME theme = GetWindowTheme(hWnd);
+        if (theme && BUTTON_PaintWithTheme(theme, hWnd, hdc))
+        {
+            if ( !wParam ) EndPaint( hWnd, &ps );
+            return 0;
+        }
+#endif
         if (btnPaintFunc[btn_type])
         {
             int nOldMode = SetBkMode( hdc, OPAQUE );
@@ -480,6 +534,21 @@ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
         break;
 
     case WM_MOUSEMOVE:
+#ifndef _USER32_
+    {
+        TRACKMOUSEEVENT mouse_event;
+        mouse_event.cbSize = sizeof(TRACKMOUSEEVENT);
+        mouse_event.dwFlags = TME_QUERY;
+        if(!TrackMouseEvent(&mouse_event) || !(mouse_event.dwFlags&(TME_HOVER|TME_LEAVE)))
+        {
+            mouse_event.dwFlags = TME_HOVER|TME_LEAVE;
+            mouse_event.hwndTrack = hWnd;
+            mouse_event.dwHoverTime = 1;
+            TrackMouseEvent(&mouse_event);
+        }
+    }
+#endif
+
         if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
         {
             GetClientRect( hWnd, &rect );
index bdf57e3..b8008f2 100644 (file)
@@ -294,16 +294,16 @@ static const pfThemedPaint btnThemedPaintFunc[BUTTON_TYPE + 1] =
     NULL, /* Not defined */
 };
 
-static BOOL BUTTON_Paint(HTHEME theme, HWND hwnd, HDC hParamDC)
+BOOL BUTTON_PaintWithTheme(HTHEME theme, HWND hwnd, HDC hParamDC)
 {
-    PAINTSTRUCT ps;
-    HDC hDC;
     DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
     DWORD dwStyleEx = GetWindowLongW(hwnd, GWL_EXSTYLE);
     UINT dtFlags = get_drawtext_flags(dwStyle, dwStyleEx);
     int state = (int)SendMessageW(hwnd, BM_GETSTATE, 0, 0);
     ButtonState drawState;
     pfThemedPaint paint = btnThemedPaintFunc[ dwStyle & BUTTON_TYPE ];
+    if (!paint)
+        return FALSE;
 
     if(IsWindowEnabled(hwnd))
     {
@@ -314,105 +314,6 @@ static BOOL BUTTON_Paint(HTHEME theme, HWND hwnd, HDC hParamDC)
     }
     else drawState = STATE_DISABLED;
 
-    hDC = hParamDC ? hParamDC : BeginPaint(hwnd, &ps);
-    if (paint) paint(theme, hwnd, hDC, drawState, dtFlags, state & BST_FOCUS);
-    if (!hParamDC) EndPaint(hwnd, &ps);
+    paint(theme, hwnd, hParamDC, drawState, dtFlags, state & BST_FOCUS);
     return TRUE;
 }
-
-/**********************************************************************
- * The button control subclass window proc.
- */
-LRESULT CALLBACK THEMING_ButtonSubclassProc(HWND hwnd, UINT msg,
-                                            WPARAM wParam, LPARAM lParam,
-                                            ULONG_PTR dwRefData)
-{
-    const WCHAR* themeClass = WC_BUTTONW;
-    HTHEME theme;
-    LRESULT result;
-
-    switch (msg)
-    {
-    case WM_CREATE:
-        result = THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
-        OpenThemeData(hwnd, themeClass);
-        return result;
-
-    case WM_DESTROY:
-        theme = GetWindowTheme(hwnd);
-        CloseThemeData (theme);
-        return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
-
-    case WM_THEMECHANGED:
-        theme = GetWindowTheme(hwnd);
-        CloseThemeData (theme);
-        OpenThemeData(hwnd, themeClass);
-        break;
-
-    case WM_SYSCOLORCHANGE:
-        theme = GetWindowTheme(hwnd);
-       if (!theme) return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
-        /* Do nothing. When themed, a WM_THEMECHANGED will be received, too,
-        * which will do the repaint. */
-        break;
-
-    case WM_PAINT:
-        theme = GetWindowTheme(hwnd);
-        if (theme && BUTTON_Paint(theme, hwnd, (HDC)wParam))
-            return 0;
-        else
-            return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
-
-    case WM_ENABLE:
-        theme = GetWindowTheme(hwnd);
-        if (theme) {
-            RedrawWindow(hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
-            return 0;
-        } else
-            return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
-
-    case WM_MOUSEMOVE:
-    {
-        TRACKMOUSEEVENT mouse_event;
-        mouse_event.cbSize = sizeof(TRACKMOUSEEVENT);
-        mouse_event.dwFlags = TME_QUERY;
-        if(!TrackMouseEvent(&mouse_event) || !(mouse_event.dwFlags&(TME_HOVER|TME_LEAVE)))
-        {
-            mouse_event.dwFlags = TME_HOVER|TME_LEAVE;
-            mouse_event.hwndTrack = hwnd;
-            mouse_event.dwHoverTime = 1;
-            TrackMouseEvent(&mouse_event);
-        }
-        break;
-    }
-
-    case WM_MOUSEHOVER:
-    {
-        int state = (int)SendMessageW(hwnd, BM_GETSTATE, 0, 0);
-        SetWindowLongW(hwnd, 0, state|BST_HOT);
-        InvalidateRect(hwnd, NULL, FALSE);
-        break;
-    }
-
-    case WM_MOUSELEAVE:
-    {
-        int state = (int)SendMessageW(hwnd, BM_GETSTATE, 0, 0);
-        SetWindowLongW(hwnd, 0, state&(~BST_HOT));
-        InvalidateRect(hwnd, NULL, FALSE);
-        break;
-    }
-
-    case BM_SETCHECK:
-    case BM_SETSTATE:
-        theme = GetWindowTheme(hwnd);
-        if (theme) {
-            InvalidateRect(hwnd, NULL, FALSE);
-        }
-        return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
-
-    default:
-       /* Call old proc */
-       return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
-    }
-    return 0;
-}