[USER32][COMCTL32] Move the auto radio button group logic from BM_SETCHECK to WM_LBUT...
[reactos.git] / win32ss / user / user32 / controls / button.c
index 1dc8af3..a9afe49 100644 (file)
  *  - Button_SetImageList
  *  - Button_SetTextMargin
  */
+
 #include <user32.h>
 
-#include <wine/debug.h>
 WINE_DEFAULT_DEBUG_CHANNEL(button);
 
 /* GetWindowLong offsets for window extra information */
 #define STATE_GWL_OFFSET  0
-#define HFONT_GWL_OFFSET  (sizeof(LONG))
-#define HIMAGE_GWL_OFFSET (HFONT_GWL_OFFSET+sizeof(HFONT))
-#define UISTATE_GWL_OFFSET (HIMAGE_GWL_OFFSET+sizeof(HFONT))
-#define NB_EXTRA_BYTES    (UISTATE_GWL_OFFSET+sizeof(LONG))
+#define BUTTON_HFONT_GWL_OFFSET  (sizeof(LONG))
+#define HIMAGE_GWL_OFFSET (BUTTON_HFONT_GWL_OFFSET+sizeof(HFONT))
+#define BUTTON_UISTATE_GWL_OFFSET (HIMAGE_GWL_OFFSET+sizeof(HFONT))
+#define NB_EXTRA_BYTES    (BUTTON_UISTATE_GWL_OFFSET+sizeof(LONG))
 
 /* undocumented flags */
 #define BUTTON_NSTATES         0x0F
@@ -117,9 +117,9 @@ static const WORD maxCheckState[MAX_BTN_TYPE] =
     BST_UNCHECKED       /* BS_OWNERDRAW */
 };
 
-typedef void (*pfPaint)( HWND hwnd, HDC hdc, UINT action );
+typedef void (*pfButtonPaint)( HWND hwnd, HDC hdc, UINT action );
 
-static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
+static const pfButtonPaint btnPaintFunc[MAX_BTN_TYPE] =
 {
     PB_Paint,    /* BS_PUSHBUTTON */
     PB_Paint,    /* BS_DEFPUSHBUTTON */
@@ -169,24 +169,24 @@ static inline void set_button_state( HWND hwnd, LONG state )
 
 static __inline void set_ui_state( HWND hwnd, LONG flags )
 {
-    SetWindowLongPtrW( hwnd, UISTATE_GWL_OFFSET, flags );
+    SetWindowLongPtrW( hwnd, BUTTON_UISTATE_GWL_OFFSET, flags );
 }
 
 static __inline LONG get_ui_state( HWND hwnd )
 {
-    return GetWindowLongPtrW( hwnd, UISTATE_GWL_OFFSET );
+    return GetWindowLongPtrW( hwnd, BUTTON_UISTATE_GWL_OFFSET );
 }
 
 #endif /* __REACTOS__ */
 
 static inline HFONT get_button_font( HWND hwnd )
 {
-    return (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
+    return (HFONT)GetWindowLongPtrW( hwnd, BUTTON_HFONT_GWL_OFFSET );
 }
 
 static inline void set_button_font( HWND hwnd, HFONT font )
 {
-    SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, (LONG_PTR)font );
+    SetWindowLongPtrW( hwnd, BUTTON_HFONT_GWL_OFFSET, (LONG_PTR)font );
 }
 
 static inline UINT get_button_type( LONG window_style )
@@ -412,7 +412,7 @@ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
                 SendMessageW( hWnd, BM_SETCHECK, !(state & BST_CHECKED), 0 );
                 break;
             case BS_AUTORADIOBUTTON:
-                SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 );
+                BUTTON_CheckAutoRadioButton( hWnd );
                 break;
             case BS_AUTO3STATE:
                 SendMessageW( hWnd, BM_SETCHECK,
@@ -624,8 +624,6 @@ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg,
             set_button_state( hWnd, (state & ~3) | wParam );
             paint_button( hWnd, btn_type, ODA_SELECT );
         }
-        if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD))
-            BUTTON_CheckAutoRadioButton( hWnd );
         break;
 
     case BM_GETSTATE:
@@ -832,7 +830,11 @@ static UINT BUTTON_CalcLabelRect(HWND hwnd, 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;
@@ -1184,13 +1186,12 @@ static void BUTTON_CheckAutoRadioButton( HWND hwnd )
 
     parent = GetParent(hwnd);
     /* make sure that starting control is not disabled or invisible */
-    start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
+    start = sibling = hwnd;
     do
     {
         if (!sibling) break;
-        if ((hwnd != sibling) &&
-            ((GetWindowLongPtrW( sibling, GWL_STYLE) & BS_TYPEMASK) == BS_AUTORADIOBUTTON))
-            SendMessageW( sibling, BM_SETCHECK, BST_UNCHECKED, 0 );
+        if (SendMessageW( sibling, WM_GETDLGCODE, 0, 0 ) == (DLGC_BUTTON | DLGC_RADIOBUTTON))
+            SendMessageW( sibling, BM_SETCHECK, sibling == hwnd ? BST_CHECKED : BST_UNCHECKED, 0 );
         sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
     } while (sibling != start);
 }