[USER32][COMCTL32] Move the auto radio button group logic from BM_SETCHECK to WM_LBUT...
[reactos.git] / dll / win32 / comctl32 / button.c
index 514d5a7..aacb96f 100644 (file)
@@ -785,7 +785,11 @@ static LRESULT CALLBACK BUTTON_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, L
                 SendMessageW( hWnd, BM_SETCHECK, !(infoPtr->state & BST_CHECKED), 0 );
                 break;
             case BS_AUTORADIOBUTTON:
+#ifdef __REACTOS__
+                BUTTON_CheckAutoRadioButton( hWnd );
+#else
                 SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 );
+#endif
                 break;
             case BS_AUTO3STATE:
                 SendMessageW( hWnd, BM_SETCHECK, (infoPtr->state & BST_INDETERMINATE) ? 0 :
@@ -941,6 +945,11 @@ static LRESULT CALLBACK BUTTON_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, L
         BOOL ret = FALSE;
         SIZE* pSize = (SIZE*)lParam;
 
+        if (!pSize)
+        {
+            return FALSE;
+        }
+
         if (btn_type == BS_PUSHBUTTON || 
             btn_type == BS_DEFPUSHBUTTON ||
             btn_type == BS_USERBUTTON)
@@ -1113,8 +1122,10 @@ static LRESULT CALLBACK BUTTON_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, L
             infoPtr->state = (infoPtr->state & ~3) | wParam;
             InvalidateRect( hWnd, NULL, FALSE );
         }
+#ifndef __REACTOS__
         if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD))
             BUTTON_CheckAutoRadioButton( hWnd );
+#endif
         break;
 
     case BM_GETSTATE:
@@ -1177,7 +1188,7 @@ static UINT BUTTON_CalcLabelRect(const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc)
    UINT        dtStyle = BUTTON_BStoDT( style, ex_style );
    RECT        r = *rc;
    INT         n;
-#if !defined(_USER32_) && defined(__REACTOS__)
+#ifdef __REACTOS__
     BOOL bHasIml = BUTTON_DrawIml(hdc, &infoPtr->imlData, &r, TRUE, 0);
 #endif
 
@@ -1229,7 +1240,7 @@ static UINT BUTTON_CalcLabelRect(const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc)
 
       default:
       empty_rect:
-#if !defined(_USER32_) && defined(__REACTOS__)
+#ifdef __REACTOS__
          if (bHasIml)
              break;
 #endif
@@ -1238,7 +1249,7 @@ static UINT BUTTON_CalcLabelRect(const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc)
          return (UINT)-1;
    }
 
-#if !defined(_USER32_) && defined(__REACTOS__)
+#ifdef __REACTOS__
    if (bHasIml)
    {
      if (infoPtr->imlData.uAlign == BUTTON_IMAGELIST_ALIGN_LEFT)
@@ -1273,7 +1284,11 @@ static UINT BUTTON_CalcLabelRect(const BUTTON_INFO *infoPtr, HDC hdc, RECT *rc)
    {
       case DT_TOP:     r.top++;  r.bottom++;  break;
       case DT_VCENTER: n = r.bottom - r.top;
+#ifdef __REACTOS__
+                       r.top    = rc->top + ((rc->bottom - 1 - rc->top) - n) / 2;
+#else
                        r.top    = rc->top + ((rc->bottom - rc->top) - n) / 2;
+#endif
                        r.bottom = r.top + n;  break;
       case DT_BOTTOM:  n = r.bottom - r.top;
                        r.bottom = rc->bottom - 1;
@@ -1322,7 +1337,7 @@ static void BUTTON_DrawLabel(const BUTTON_INFO *infoPtr, HDC hdc, UINT dtFlags,
     * I don't have Win31 on hand to verify that, so I leave it as is.
     */
 
-#if !defined(_USER32_) && defined(__REACTOS__)
+#ifdef __REACTOS__
     RECT rcText = *rc;
     BUTTON_DrawIml(hdc, &infoPtr->imlData, &rcText, FALSE, 0);
 #endif
@@ -1636,13 +1651,22 @@ static void BUTTON_CheckAutoRadioButton( HWND hwnd )
 
     parent = GetParent(hwnd);
     /* make sure that starting control is not disabled or invisible */
+#ifdef __REACTOS__
+    start = sibling = hwnd;
+#else
     start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
+#endif
     do
     {
         if (!sibling) break;
+#ifdef __REACTOS__
+        if (SendMessageW( sibling, WM_GETDLGCODE, 0, 0 ) == (DLGC_BUTTON | DLGC_RADIOBUTTON))
+            SendMessageW( sibling, BM_SETCHECK, sibling == hwnd ? BST_CHECKED : BST_UNCHECKED, 0 );
+#else
         if ((hwnd != sibling) &&
             ((GetWindowLongW( sibling, GWL_STYLE) & BS_TYPEMASK) == BS_AUTORADIOBUTTON))
             SendMessageW( sibling, BM_SETCHECK, BST_UNCHECKED, 0 );
+#endif
         sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
     } while (sibling != start);
 }
@@ -1837,6 +1861,9 @@ static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, Bu
     {
         DrawThemeText(theme, hDC, BP_PUSHBUTTON, state, text, lstrlenW(text), dtFlags, 0, &textRect);
         heap_free(text);
+#ifdef __REACTOS__
+        text = NULL;
+#endif
     }
 
     if (focused)
@@ -1858,6 +1885,7 @@ static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, Bu
     if (cdrf == CDRF_NOTIFYPOSTPAINT)
         BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTPAINT, &bgRect);
 cleanup:
+    if (text) heap_free(text);
 #endif
     if (hPrevFont) SelectObject(hDC, hPrevFont);
 }
@@ -1987,12 +2015,16 @@ static void CB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, Bu
         }
 
         heap_free(text);
+#ifdef __REACTOS__
+        text = NULL;
+#endif
     }
 
 #ifdef __REACTOS__
     if (cdrf == CDRF_NOTIFYPOSTPAINT)
         BUTTON_SendCustomDraw(infoPtr, hDC, CDDS_POSTPAINT, &bgRect);
 cleanup:
+    if (text) heap_free(text);
 #endif
     if (created_font) DeleteObject(font);
     if (hPrevFont) SelectObject(hDC, hPrevFont);
@@ -2104,8 +2136,8 @@ void BUTTON_Register(void)
 
 
 #ifdef __REACTOS__
-void BUTTON_Unregister()
+void BUTTON_Unregister(void)
 {
     UnregisterClassW(WC_BUTTONW, NULL);
 }
-#endif
\ No newline at end of file
+#endif