]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/radiobox.cpp
Don't assume that msw.remap was 1, instead change it back to what it
[wxWidgets.git] / src / os2 / radiobox.cpp
index 8a11e966c4d52475a1e7ef6ee0b34f5f63afe856..fa60f8f8dee91ed1e47afab56cbc34fce32de232 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        radiobox.cpp
+// Name:        src/os2/radiobox.cpp
 // Purpose:     wxRadioBox
 // Author:      David Webster
 // Modified by:
 // Purpose:     wxRadioBox
 // Author:      David Webster
 // Modified by:
@@ -14,7 +14,6 @@
 
 #ifndef WX_PRECOMP
     #include <stdio.h>
 
 #ifndef WX_PRECOMP
     #include <stdio.h>
-    #include "wx/setup.h"
     #include "wx/wxchar.h"
     #include "wx/string.h"
     #include "wx/bitmap.h"
     #include "wx/wxchar.h"
     #include "wx/string.h"
     #include "wx/bitmap.h"
@@ -36,13 +35,23 @@ MRESULT EXPENTRY wxRadioBtnWndProc( HWND hWnd
                                    ,MPARAM wParam
                                    ,MPARAM lParam
                                   );
                                    ,MPARAM wParam
                                    ,MPARAM lParam
                                   );
+MRESULT EXPENTRY wxRadioBoxWndProc( HWND   hWnd
+                                   ,UINT   uMessage
+                                   ,MPARAM wParam
+                                   ,MPARAM lParam
+                                  );
 
 // ---------------------------------------------------------------------------
 // global vars
 // ---------------------------------------------------------------------------
 
 
 // ---------------------------------------------------------------------------
 // global vars
 // ---------------------------------------------------------------------------
 
-// the pointer to standard radio button wnd proc
+extern void  wxAssociateWinWithHandle( HWND         hWnd
+                                      ,wxWindowOS2* pWin
+                                     );
+extern void wxRemoveHandleAssociation( wxWindowOS2 *pWin );
+// the pointer to standard radio button & box wnd procs
 static WXFARPROC                    fnWndProcRadioBtn = NULL;
 static WXFARPROC                    fnWndProcRadioBtn = NULL;
+static WXFARPROC                    fnWndProcRadioBox = NULL;
 
 // ===========================================================================
 // implementation
 
 // ===========================================================================
 // implementation
@@ -57,22 +66,26 @@ wxRadioBox::wxRadioBox()
 {
     m_nSelectedButton = -1;
     m_nNoItems = 0;
 {
     m_nSelectedButton = -1;
     m_nNoItems = 0;
-    m_nNoRowsOrCols = 0;
     m_ahRadioButtons = NULL;
     m_ahRadioButtons = NULL;
-    m_nMajorDim = 0;
     m_pnRadioWidth = NULL;
     m_pnRadioHeight = NULL;
 } // end of wxRadioBox::wxRadioBox
 
 wxRadioBox::~wxRadioBox()
 {
     m_pnRadioWidth = NULL;
     m_pnRadioHeight = NULL;
 } // end of wxRadioBox::wxRadioBox
 
 wxRadioBox::~wxRadioBox()
 {
-    m_isBeingDeleted = TRUE;
+    m_isBeingDeleted = true;
 
 
+    if (m_hWnd)
+        wxRemoveHandleAssociation(this);
     if (m_ahRadioButtons)
     {
     if (m_ahRadioButtons)
     {
-        int                         i;
-        for (i = 0; i < m_nNoItems; i++)
+        for (int i = 0; i < m_nNoItems; i++)
+        {
+            wxWindow* pWin = wxFindWinFromHandle((WXHWND)m_ahRadioButtons[i]);
+            wxRemoveHandleAssociation(pWin);
+
             ::WinDestroyWindow((HWND)m_ahRadioButtons[i]);
             ::WinDestroyWindow((HWND)m_ahRadioButtons[i]);
+    }
         delete[] m_ahRadioButtons;
     }
     if (m_pnRadioWidth)
         delete[] m_ahRadioButtons;
     }
     if (m_pnRadioWidth)
@@ -81,146 +94,6 @@ wxRadioBox::~wxRadioBox()
         delete[] m_pnRadioHeight;
 } // end of wxRadioBox::~wxRadioBox
 
         delete[] m_pnRadioHeight;
 } // end of wxRadioBox::~wxRadioBox
 
-void wxRadioBox::AdjustButtons(
-  int                               nX
-, int                               nY
-, int                               nWidth
-, int                               nHeight
-, int                               nSizeFlags
-)
-{
-    wxSize                          vMaxSize;
-    int                             nXOffset = nX;
-    int                             nYOffset = nY + nHeight;
-    int                             nCx1;
-    int                             nCy1;
-    int                             nStartX;
-    int                             nStartY;
-    int                             nMaxWidth;
-    int                             nMaxHeight;
-    int                             nTotWidth;
-    int                             nTotHeight;
-
-    wxGetCharSize( m_hWnd
-                  ,&nCx1
-                  ,&nCy1
-                  ,&GetFont()
-                 );
-    vMaxSize   = GetMaxButtonSize();
-    nMaxWidth  = vMaxSize.x;
-    nMaxHeight = vMaxSize.y;
-
-    nXOffset += nCx1;
-    nYOffset -= (nMaxHeight + ((3*nCy1)/2));
-
-    nStartX = nXOffset;
-    nStartY = nYOffset;
-
-    for (int i = 0; i < m_nNoItems; i++)
-    {
-        //
-        // The last button in the row may be wider than the other ones as the
-        // radiobox may be wider than the sum of the button widths (as it
-        // happens, for example, when the radiobox label is very long)
-        //
-        bool                        bIsLastInTheRow;
-
-        if (m_windowStyle & wxRA_SPECIFY_COLS)
-        {
-            //
-            // Item is the last in its row if it is a multiple of the number of
-            // columns or if it is just the last item
-            //
-            int                     n = i + 1;
-
-            bIsLastInTheRow = ((n % m_nMajorDim) == 0) || (n == m_nNoItems);
-        }
-        else // winRA_SPECIFY_ROWS
-        {
-            //
-            // Item is the last in the row if it is in the last columns
-            //
-            bIsLastInTheRow = i >= (m_nNoItems/m_nMajorDim) * m_nMajorDim;
-        }
-
-        //
-        // Is this the start of new row/column?
-        //
-        if (i && (i % m_nMajorDim == 0))
-        {
-            if (m_windowStyle & wxRA_SPECIFY_ROWS)
-            {
-
-                //
-                // Start of new column
-                //
-                nYOffset = nStartY;
-                nXOffset += nMaxWidth + nCx1;
-            }
-            else // start of new row
-            {
-                nXOffset = nStartX;
-                nYOffset -= nMaxHeight;
-                if (m_pnRadioWidth[0] > 0L)
-                    nYOffset -= nCy1/2;
-            }
-        }
-
-        int                         nWidthBtn;
-
-        if (bIsLastInTheRow)
-        {
-            //
-            // Make the button go to the end of radio box
-            //
-            nWidthBtn = nStartX + nWidth - nXOffset - (2 * nCx1);
-            if (nWidthBtn < nMaxWidth)
-                nWidthBtn = nMaxWidth;
-        }
-        else
-        {
-            //
-            // Normal button, always of the same size
-            //
-            nWidthBtn = nMaxWidth;
-        }
-
-        //
-        // Make all buttons of the same, maximal size - like this they
-        // cover the radiobox entirely and the radiobox tooltips are always
-        // shown (otherwise they are not when the mouse pointer is in the
-        // radiobox part not beYInt32ing to any radiobutton)
-        //
-        ::WinSetWindowPos( (HWND)m_ahRadioButtons[i]
-                          ,HWND_TOP
-                          ,(LONG)nXOffset
-                          ,(LONG)nYOffset
-                          ,(LONG)nWidthBtn
-                          ,(LONG)nMaxHeight
-                          ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
-                         );
-        //
-        // Where do we put the next button?
-        //
-        if (m_windowStyle & wxRA_SPECIFY_ROWS)
-        {
-            //
-            // Below this one
-            //
-            nYOffset -= nMaxHeight;
-            if (m_pnRadioWidth[0] > 0)
-                nYOffset -= nCy1/2;
-        }
-        else
-        {
-            //
-            // To the right of this one
-            //
-            nXOffset += nWidthBtn + nCx1;
-        }
-    }
-} // end of wxRadioBox::AdjustButtons
-
 void wxRadioBox::Command (
   wxCommandEvent&                   rEvent
 )
 void wxRadioBox::Command (
   wxCommandEvent&                   rEvent
 )
@@ -239,11 +112,30 @@ bool wxRadioBox::ContainsHWND(
     for (i = 0; i < nCount; i++)
     {
         if (GetRadioButtons()[i] == hWnd)
     for (i = 0; i < nCount; i++)
     {
         if (GetRadioButtons()[i] == hWnd)
-            return TRUE;
+            return true;
     }
     }
-    return FALSE;
+    return false;
 } // end of wxRadioBox::ContainsHWND
 
 } // end of wxRadioBox::ContainsHWND
 
+bool wxRadioBox::Create(
+  wxWindow*                         pParent
+, wxWindowID                        vId
+, const wxString&                   rsTitle
+, const wxPoint&                    rPos
+, const wxSize&                     rSize
+, const wxArrayString&              asChoices
+, int                               nMajorDim
+, long                              lStyle
+, const wxValidator&                rVal
+, const wxString&                   rsName
+)
+{
+    wxCArrayString chs(asChoices);
+
+    return Create(pParent, vId, rsTitle, rPos, rSize, chs.GetCount(),
+                  chs.GetStrings(), nMajorDim, lStyle, rVal, rsName);
+}
+
 bool wxRadioBox::Create(
   wxWindow*                         pParent
 , wxWindowID                        vId
 bool wxRadioBox::Create(
   wxWindow*                         pParent
 , wxWindowID                        vId
@@ -254,33 +146,19 @@ bool wxRadioBox::Create(
 , const wxString                    asChoices[]
 , int                               nMajorDim
 , long                              lStyle
 , const wxString                    asChoices[]
 , int                               nMajorDim
 , long                              lStyle
-#if wxUSE_VALIDATORS
 , const wxValidator&                rVal
 , const wxValidator&                rVal
-#endif
 , const wxString&                   rsName
 )
 {
 , const wxString&                   rsName
 )
 {
-    //
-    // System fonts are too big in OS/2 and they are blue
-    // We want smaller fonts and black by default.
-    //
-    wxFont*                          pTextFont = new wxFont( 10
-                                                            ,wxMODERN
-                                                            ,wxNORMAL
-                                                            ,wxNORMAL
-                                                           );
     wxColour                        vColour;
     LONG                            lColor;
     wxColour                        vColour;
     LONG                            lColor;
+    HWND                            hWndParent = GetHwndOf(pParent);
 
 
-    vColour.Set(wxString("BLACK"));
-    lColor = (LONG)vColour.GetPixel();
+    vColour.Set(wxString(wxT("BLACK")));
     m_backgroundColour = pParent->GetBackgroundColour();
     m_nSelectedButton = -1;
     m_nNoItems = 0;
 
     m_backgroundColour = pParent->GetBackgroundColour();
     m_nSelectedButton = -1;
     m_nNoItems = 0;
 
-    m_nMajorDim     = nMajorDim == 0 ? nNum : nMajorDim;
-    m_nNoRowsOrCols = nMajorDim;
-
     //
     // Common initialization
     //
     //
     // Common initialization
     //
@@ -289,115 +167,105 @@ bool wxRadioBox::Create(
                        ,rPos
                        ,rSize
                        ,lStyle
                        ,rPos
                        ,rSize
                        ,lStyle
-#if wxUSE_VALIDATORS
                        ,rVal
                        ,rVal
-#endif
                        ,rsName
                       ))
                        ,rsName
                       ))
-        return FALSE;
-    if (!OS2CreateControl( "STATIC"
-#if RADIOBTN_PARENT_IS_RADIOBOX
-                          ,SS_GROUPBOX | WS_GROUP | WS_CLIPCHILDREN
-#else
-                          ,SS_GROUPBOX | WS_GROUP | WS_CLIPSIBLINGS
-#endif
+        return false;
+    if (!OS2CreateControl( wxT("STATIC")
+                          ,SS_GROUPBOX
                           ,rPos
                           ,rSize
                           ,rsTitle
                          ))
                           ,rPos
                           ,rSize
                           ,rsTitle
                          ))
-        return FALSE;
+        return false;
 
 
-#if RADIOBTN_PARENT_IS_RADIOBOX
-    HWND                            hWndParent = GetHwnd();
-#else
-    HWND                            hWndParent = GetHwndOf(pParent);
-#endif
-    HFONT                           hFont;
+    wxAssociateWinWithHandle(m_hWnd, this);
 
     //
 
     //
-    // Some radio boxes test consecutive id.
+    // Now we can set m_nNoItems and let SetMajorDim set m_numCols/m_numRows
     //
     m_nNoItems = nNum;
     //
     m_nNoItems = nNum;
-    (void)NewControlId();
+    SetMajorDim(nMajorDim == 0 ? nNum : nMajorDim, lStyle);
+
     m_ahRadioButtons = new WXHWND[nNum];
     m_pnRadioWidth   = new int[nNum];
     m_pnRadioHeight  = new int[nNum];
 
     m_ahRadioButtons = new WXHWND[nNum];
     m_pnRadioWidth   = new int[nNum];
     m_pnRadioHeight  = new int[nNum];
 
-    if (pTextFont->Ok())
-    {
-        hFont = pTextFont->GetResourceHandle();
-    }
-
     for (int i = 0; i < nNum; i++)
     {
         m_pnRadioWidth[i] = m_pnRadioHeight[i] = -1;
     for (int i = 0; i < nNum; i++)
     {
         m_pnRadioWidth[i] = m_pnRadioHeight[i] = -1;
-
-        long                        lStyleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE;
+        long                        lStyleBtn = BS_AUTORADIOBUTTON | WS_VISIBLE;
         int                         nNewId = NewControlId();
 
         int                         nNewId = NewControlId();
 
-        if (i == 0 && lStyle == 0)
-            lStyleBtn |= WS_GROUP;
-
-        HWND                        hWndBtn = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent)
-                                                                         ,WC_BUTTON
-                                                                         ,asChoices[i]
-                                                                         ,lStyleBtn
-                                                                         ,0, 0, 0, 0
-                                                                         ,GetWinHwnd(pParent)
-                                                                         ,HWND_TOP
-                                                                         ,(HMENU)nNewId
-                                                                         ,NULL
-                                                                         ,NULL
+        if (i == 0)
+            lStyleBtn |= WS_GROUP | WS_TABSTOP;
+
+        wxString                    sLabel = ::wxPMTextToLabel(asChoices[i]);
+
+        HWND                        hWndBtn = (WXHWND)::WinCreateWindow ( hWndParent,
+                                                                          WC_BUTTON,
+                                                                          sLabel.c_str(),
+                                                                          lStyleBtn,
+                                                                          0, 0, 0, 0,
+                                                                          hWndParent,
+                                                                          HWND_BOTTOM,
+                                                                          (HMENU)nNewId,
+                                                                          NULL,
+                                                                          NULL
                                                                         );
                                                                         );
+        if (!hWndBtn)
+        {
+            return false;
+        }
         lColor = (LONG)vColour.GetPixel();
         ::WinSetPresParam( hWndBtn
                           ,PP_FOREGROUNDCOLOR
                           ,sizeof(LONG)
                           ,(PVOID)&lColor
                          );
         lColor = (LONG)vColour.GetPixel();
         ::WinSetPresParam( hWndBtn
                           ,PP_FOREGROUNDCOLOR
                           ,sizeof(LONG)
                           ,(PVOID)&lColor
                          );
-        lColor = (LONG)m_backgroundColour.GetPixel();
 
 
+        lColor = (LONG)m_backgroundColour.GetPixel();
         ::WinSetPresParam( hWndBtn
                           ,PP_BACKGROUNDCOLOR
                           ,sizeof(LONG)
                           ,(PVOID)&lColor
                          );
         ::WinSetPresParam( hWndBtn
                           ,PP_BACKGROUNDCOLOR
                           ,sizeof(LONG)
                           ,(PVOID)&lColor
                          );
-        if (!hWndBtn)
-        {
-            return FALSE;
-        }
         m_ahRadioButtons[i] = (WXHWND)hWndBtn;
         SubclassRadioButton((WXHWND)hWndBtn);
         m_ahRadioButtons[i] = (WXHWND)hWndBtn;
         SubclassRadioButton((WXHWND)hWndBtn);
+        wxAssociateWinWithHandle(hWndBtn, this);
         wxOS2SetFont( hWndBtn
         wxOS2SetFont( hWndBtn
-                     ,*pTextFont
+                     ,*wxSMALL_FONT
                     );
         ::WinSetWindowULong(hWndBtn, QWL_USER, (ULONG)this);
         m_aSubControls.Add(nNewId);
     }
 
     //
                     );
         ::WinSetWindowULong(hWndBtn, QWL_USER, (ULONG)this);
         m_aSubControls.Add(nNewId);
     }
 
     //
-    // Create a dummy radio control to end the group.
+    // Create a dummy control to end the group.
     //
     //
-    (void)::WinCreateWindow ( GetHwndOf(pParent)
-                             ,WC_BUTTON
-                             ,""
-                             ,WS_GROUP | BS_AUTORADIOBUTTON
-                             ,0, 0, 0, 0
-                             ,GetWinHwnd(pParent)
-                             ,HWND_TOP
-                             ,(HMENU)NewControlId()
-                             ,NULL
-                             ,NULL
+    (void)::WinCreateWindow ( hWndParent,
+                              WC_BUTTON,
+                              "",
+                              WS_GROUP,
+                              0, 0, 0, 0,
+                              hWndParent,
+                              HWND_TOP,
+                              (HMENU)NewControlId(),
+                              NULL,
+                              NULL
                             );
                             );
-    SetFont(*pTextFont);
+    fnWndProcRadioBox = (WXFARPROC)::WinSubclassWindow( GetHwnd()
+                                                       ,(PFNWP)wxRadioBoxWndProc
+                                                      );
+    ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this);
     lColor = (LONG)vColour.GetPixel();
     ::WinSetPresParam( m_hWnd
                       ,PP_FOREGROUNDCOLOR
                       ,sizeof(LONG)
                       ,(PVOID)&lColor
                      );
     lColor = (LONG)vColour.GetPixel();
     ::WinSetPresParam( m_hWnd
                       ,PP_FOREGROUNDCOLOR
                       ,sizeof(LONG)
                       ,(PVOID)&lColor
                      );
-    lColor = (LONG)m_backgroundColour.GetPixel();
 
 
+    lColor = (LONG)m_backgroundColour.GetPixel();
     ::WinSetPresParam( m_hWnd
                       ,PP_BACKGROUNDCOLOR
                       ,sizeof(LONG)
     ::WinSetPresParam( m_hWnd
                       ,PP_BACKGROUNDCOLOR
                       ,sizeof(LONG)
@@ -411,14 +279,13 @@ bool wxRadioBox::Create(
             ,rSize.x
             ,rSize.y
            );
             ,rSize.x
             ,rSize.y
            );
-    delete pTextFont;
-    return TRUE;
+    return true;
 } // end of wxRadioBox::Create
 
 wxSize wxRadioBox::DoGetBestSize() const
 {
     return (GetTotalButtonSize(GetMaxButtonSize()));
 } // end of wxRadioBox::Create
 
 wxSize wxRadioBox::DoGetBestSize() const
 {
     return (GetTotalButtonSize(GetMaxButtonSize()));
-} // end of WinGuiBase_CRadioBox::DoGetBestSize
+} // end of wxRadioBox::DoGetBestSize
 
 void wxRadioBox::DoSetSize(
   int                               nX
 
 void wxRadioBox::DoSetSize(
   int                               nX
@@ -428,19 +295,17 @@ void wxRadioBox::DoSetSize(
 , int                               nSizeFlags
 )
 {
 , int                               nSizeFlags
 )
 {
+    //
+    // Input parameters assume wxWidgets coordinate system
+    //
     int                             nCurrentX;
     int                             nCurrentY;
     int                             nWidthOld;
     int                             nHeightOld;
     int                             nXx = nX;
     int                             nYy = nY;
     int                             nCurrentX;
     int                             nCurrentY;
     int                             nWidthOld;
     int                             nHeightOld;
     int                             nXx = nX;
     int                             nYy = nY;
-#if RADIOBTN_PARENT_IS_RADIOBOX
-    int                             nXOffset = 0;
-    int                             nYOffset = 0;
-#else
     int                             nXOffset = nXx;
     int                             nYOffset = nYy;
     int                             nXOffset = nXx;
     int                             nYOffset = nYy;
-#endif
     int                             nCx1;
     int                             nCy1;
     wxSize                          vMaxSize = GetMaxButtonSize();
     int                             nCx1;
     int                             nCy1;
     wxSize                          vMaxSize = GetMaxButtonSize();
@@ -451,6 +316,7 @@ void wxRadioBox::DoSetSize(
     int                             nTotHeight;
     int                             nStartX;
     int                             nStartY;
     int                             nTotHeight;
     int                             nStartX;
     int                             nStartY;
+    wxFont                          vFont = GetFont();
 
     m_nSizeFlags = nSizeFlags;
     GetPosition( &nCurrentX
 
     m_nSizeFlags = nSizeFlags;
     GetPosition( &nCurrentX
@@ -460,9 +326,9 @@ void wxRadioBox::DoSetSize(
             ,&nHeightOld
            );
 
             ,&nHeightOld
            );
 
-    if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+    if (nX == wxDefaultCoord && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
         nXx = nCurrentX;
         nXx = nCurrentX;
-    if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+    if (nY == wxDefaultCoord && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
         nYy = nCurrentY;
     if (nYy < 0)
         nYy = 0;
         nYy = nCurrentY;
     if (nYy < 0)
         nYy = 0;
@@ -472,7 +338,7 @@ void wxRadioBox::DoSetSize(
     wxGetCharSize( m_hWnd
                   ,&nCx1
                   ,&nCy1
     wxGetCharSize( m_hWnd
                   ,&nCx1
                   ,&nCy1
-                  ,&GetFont()
+                  ,&vFont
                  );
 
     //
                  );
 
     //
@@ -506,22 +372,19 @@ void wxRadioBox::DoSetSize(
             nHeight = nHeightOld;
     }
 
             nHeight = nHeightOld;
     }
 
+    //
+    // Now convert to OS/2 coordinate system
+    //
     wxWindowOS2*                    pParent = (wxWindowOS2*)GetParent();
     wxWindowOS2*                    pParent = (wxWindowOS2*)GetParent();
-
     if (pParent)
     if (pParent)
-    {
-        int                         nOS2Height = GetOS2ParentHeight(pParent);
-
-        nYy = nOS2Height - (nYy + nHeight);
-        nYOffset = nYy + nHeight;
-    }
+        nYy = GetOS2ParentHeight(pParent) - nYy - nHeight;
     else
     {
         RECTL                       vRect;
     else
     {
         RECTL                       vRect;
-
         ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
         ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
-        nYy = vRect.yTop - (nYy + nHeight);
+        nYy = vRect.yTop - nYy - nHeight;
     }
     }
+    nYOffset = nYy + nHeight;
     ::WinSetWindowPos( GetHwnd()
                       ,HWND_TOP
                       ,(LONG)nXx
     ::WinSetWindowPos( GetHwnd()
                       ,HWND_TOP
                       ,(LONG)nXx
@@ -566,24 +429,23 @@ void wxRadioBox::DoSetSize(
             //
             int                  n = i + 1;
 
             //
             int                  n = i + 1;
 
-            bIsLastInTheRow = ((n % m_nMajorDim) == 0) || (n == m_nNoItems);
+            bIsLastInTheRow = ((n % GetMajorDim()) == 0) || (n == m_nNoItems);
         }
         else // winRA_SPECIFY_ROWS
         {
             //
             // Item is the last in the row if it is in the last columns
             //
         }
         else // winRA_SPECIFY_ROWS
         {
             //
             // Item is the last in the row if it is in the last columns
             //
-            bIsLastInTheRow = i >= (m_nNoItems/m_nMajorDim) * m_nMajorDim;
+            bIsLastInTheRow = i >= (m_nNoItems/GetMajorDim()) * GetMajorDim();
         }
 
         //
         // Is this the start of new row/column?
         //
         }
 
         //
         // Is this the start of new row/column?
         //
-        if (i && (i % m_nMajorDim == 0))
+        if (i && (i % GetMajorDim() == 0))
         {
             if (m_windowStyle & wxRA_SPECIFY_ROWS)
             {
         {
             if (m_windowStyle & wxRA_SPECIFY_ROWS)
             {
-
                 //
                 // Start of new column
                 //
                 //
                 // Start of new column
                 //
@@ -622,17 +484,16 @@ void wxRadioBox::DoSetSize(
         // Make all buttons of the same, maximal size - like this they
         // cover the radiobox entirely and the radiobox tooltips are always
         // shown (otherwise they are not when the mouse pointer is in the
         // Make all buttons of the same, maximal size - like this they
         // cover the radiobox entirely and the radiobox tooltips are always
         // shown (otherwise they are not when the mouse pointer is in the
-        // radiobox part not beinting to any radiobutton)
+        // radiobox part not belonging to any radiobutton)
         //
         ::WinSetWindowPos( (HWND)m_ahRadioButtons[i]
         //
         ::WinSetWindowPos( (HWND)m_ahRadioButtons[i]
-                          ,HWND_TOP
+                          ,HWND_BOTTOM
                           ,(LONG)nXOffset
                           ,(LONG)nYOffset
                           ,(LONG)nWidthBtn
                           ,(LONG)nMaxHeight
                           ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
                          );
                           ,(LONG)nXOffset
                           ,(LONG)nYOffset
                           ,(LONG)nWidthBtn
                           ,(LONG)nMaxHeight
                           ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
                          );
-        GetParent()->Refresh();
         //
         // Where do we put the next button?
         //
         //
         // Where do we put the next button?
         //
@@ -655,15 +516,13 @@ void wxRadioBox::DoSetSize(
     }
 } // end of wxRadioBox::DoSetSize
 
     }
 } // end of wxRadioBox::DoSetSize
 
-void wxRadioBox::Enable(
-  int                               nItem
-, bool                              bEnable
-)
+bool wxRadioBox::Enable(int nItem, bool bEnable)
 {
 {
-    wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems,
+    wxCHECK_MSG( IsValid(nItem), false,
                  wxT("invalid item in wxRadioBox::Enable()") );
 
     ::WinEnableWindow((HWND) m_ahRadioButtons[nItem], bEnable);
                  wxT("invalid item in wxRadioBox::Enable()") );
 
     ::WinEnableWindow((HWND) m_ahRadioButtons[nItem], bEnable);
+    return true;
 } // end of wxRadioBox::Enable
 
 bool wxRadioBox::Enable(
 } // end of wxRadioBox::Enable
 
 bool wxRadioBox::Enable(
@@ -671,39 +530,20 @@ bool wxRadioBox::Enable(
 )
 {
     if ( !wxControl::Enable(bEnable) )
 )
 {
     if ( !wxControl::Enable(bEnable) )
-        return FALSE;
+        return false;
     for (int i = 0; i < m_nNoItems; i++)
         ::WinEnableWindow((HWND)m_ahRadioButtons[i], bEnable);
     for (int i = 0; i < m_nNoItems; i++)
         ::WinEnableWindow((HWND)m_ahRadioButtons[i], bEnable);
-    return TRUE;
+    return true;
 } // end of wxRadioBox::Enable
 
 } // end of wxRadioBox::Enable
 
-int wxRadioBox::FindString(
-  const wxString&                   rsStr
-) const
-{
-    for (int i = 0; i < m_nNoItems; i++)
-    {
-        if (rsStr == wxGetWindowText(m_ahRadioButtons[i]) )
-            return i;
-    }
-    return wxNOT_FOUND;
-} // end of wxRadioBox::FindString
-
-int wxRadioBox::GetColumnCount() const
-{
-    return GetNumHor();
-} // end of wxRadioBox::GetColumnCount
-
 int wxRadioBox::GetCount() const
 {
     return m_nNoItems;
 } // end of wxRadioBox::GetCount
 
 int wxRadioBox::GetCount() const
 {
     return m_nNoItems;
 } // end of wxRadioBox::GetCount
 
-wxString wxRadioBox::GetLabel(
-  int                               nItem
-) const
+wxString wxRadioBox::GetLabel(int nItem) const
 {
 {
-    wxCHECK_MSG(nItem >= 0 && nItem < m_nNoItems, wxT(""), wxT("invalid radiobox index") );
+    wxCHECK_MSG( IsValid(nItem), wxEmptyString, wxT("invalid radiobox index") );
 
     return wxGetWindowText(m_ahRadioButtons[nItem]);
 } // end of wxRadioBox::GetLabel
 
     return wxGetWindowText(m_ahRadioButtons[nItem]);
 } // end of wxRadioBox::GetLabel
@@ -743,103 +583,19 @@ wxSize wxRadioBox::GetMaxButtonSize() const
         if (nHeightMax < nHeight )
             nHeightMax = nHeight;
     }
         if (nHeightMax < nHeight )
             nHeightMax = nHeight;
     }
-    return(wxSize( nWidthMax
-                  ,nHeightMax
-                 )
-          );
+    wxSize maxsize( nWidthMax, nHeightMax);
+    return maxsize;
 } // end of wxRadioBox::GetMaxButtonSize
 
 } // end of wxRadioBox::GetMaxButtonSize
 
-int wxRadioBox::GetNumHor() const
-{
-    if ( m_windowStyle & wxRA_SPECIFY_ROWS )
-    {
-        return (m_nNoItems + m_nMajorDim - 1)/m_nMajorDim;
-    }
-    else
-    {
-        return m_nMajorDim;
-    }
-} // end of wxRadioBox::GetNumHor
-
-int wxRadioBox::GetNumVer() const
-{
-    if ( m_windowStyle & wxRA_SPECIFY_ROWS )
-    {
-        return m_nMajorDim;
-    }
-    else
-    {
-        return (m_nNoItems + m_nMajorDim - 1)/m_nMajorDim;
-    }
-} // end of wxRadioBox::GetNumVer
-
-void wxRadioBox::GetPosition(
-  int*                              pnX
-, int*                              pnY
-) const
-{
-    wxWindowOS2*                    pParent = GetParent();
-    RECT                            vRect = { -1, -1, -1, -1 };;
-    POINTL                          vPoint;
-    int                             i;
-
-    for (i = 0; i < m_nNoItems; i++)
-        wxFindMaxSize( m_ahRadioButtons[i]
-                      ,&vRect
-                     );
-    if (m_hWnd)
-        wxFindMaxSize( m_hWnd
-                      ,&vRect
-                     );
-
-    //
-    // Since we now have the absolute screen coords, if there's a parent we
-    // must subtract its top left corner
-    //
-    vPoint.x = vRect.xLeft;
-    vPoint.y = vRect.yTop;
-    if (pParent)
-    {
-        SWP                             vSwp;
-
-        ::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp);
-        vPoint.x = vSwp.x;
-        vPoint.y = vSwp.y;
-    }
-
-    //
-    // We may be faking the client origin. So a window that's really at (0, 30)
-    // may appear (to wxWin apps) to be at (0, 0).
-    //
-    if (GetParent())
-    {
-        wxPoint                     vPt(GetParent()->GetClientAreaOrigin());
-
-        vPoint.x = vPt.x;
-        vPoint.y = vPt.y;
-    }
-    *pnX = vPoint.x;
-    *pnX = vPoint.y;
-} // end of wxRadioBox::GetPosition
-
-int wxRadioBox::GetRowCount() const
-{
-    return GetNumVer();
-} // end of wxRadioBox::GetRowCount
-
 // Get single selection, for single choice list items
 int wxRadioBox::GetSelection() const
 {
     return m_nSelectedButton;
 } // end of wxRadioBox::GetSelection
 
 // Get single selection, for single choice list items
 int wxRadioBox::GetSelection() const
 {
     return m_nSelectedButton;
 } // end of wxRadioBox::GetSelection
 
-void wxRadioBox::GetSize(
-  int*                              pnWidth
-, int*                              pnHeight
-) const
+void wxRadioBox::GetSize( int* pnWidth, int* pnHeight ) const
 {
     RECT                            vRect;
 {
     RECT                            vRect;
-    int                             i;
 
     vRect.xLeft   = -1;
     vRect.xRight  = -1;
 
     vRect.xLeft   = -1;
     vRect.xRight  = -1;
@@ -851,20 +607,21 @@ void wxRadioBox::GetSize(
                       ,&vRect
                      );
 
                       ,&vRect
                      );
 
-    for (i = 0; i < m_nNoItems; i++)
+    for (int i = 0; i < m_nNoItems; i++)
         wxFindMaxSize( m_ahRadioButtons[i]
                       ,&vRect
                      );
 
         wxFindMaxSize( m_ahRadioButtons[i]
                       ,&vRect
                      );
 
-    *pnWidth  = vRect.xRight - vRect.xLeft;
-    *pnHeight = vRect.yBottom - vRect.yTop;
+    if (pnWidth)
+        *pnWidth  = vRect.xRight - vRect.xLeft;
+    if (pnHeight)
+        *pnHeight = vRect.yTop - vRect.yBottom;
 } // end of wxRadioBox::GetSize
 
 // Find string for position
 } // end of wxRadioBox::GetSize
 
 // Find string for position
-wxString wxRadioBox::GetString(
-  int                               nNum
-) const
+wxString wxRadioBox::GetString( int nNum ) const
 {
 {
+    wxCHECK_MSG( IsValid(nNum), wxEmptyString, wxT("invalid radiobox index") );
     return wxGetWindowText(m_ahRadioButtons[nNum]);
 } // end of wxRadioBox::GetString
 
     return wxGetWindowText(m_ahRadioButtons[nNum]);
 } // end of wxRadioBox::GetString
 
@@ -879,84 +636,70 @@ wxString wxRadioBox::GetStringSelection() const
     return sResult;
 } // end of wxRadioBox::GetStringSelection
 
     return sResult;
 } // end of wxRadioBox::GetStringSelection
 
-wxSize wxRadioBox::GetTotalButtonSize(
-  const wxSize&                     rSizeBtn
-) const
+wxSize wxRadioBox::GetTotalButtonSize( const wxSize& rSizeBtn ) const
 {
 {
-    int                             nCx1;
-    int                             nCy1;
-    int                             nExtraHeight;
-    int                             nHeight;
-    int                             nWidth;
-    int                             nWidthLabel;
+    int    nCx1;
+    int    nCy1;
+    int    nHeight;
+    int    nWidth;
+    int    nWidthLabel = 0;
 
 
-    wxGetCharSize( m_hWnd
-                  ,&nCx1
-                  ,&nCy1
-                  ,(wxFont*)&GetFont()
-                 );
-    nExtraHeight = nCy1;
-
-    nHeight = GetNumVer() * rSizeBtn.y + (2 * nCy1);
-    nWidth  = GetNumHor() * (rSizeBtn.x + nCx1) + nCx1;
+    nCx1 = GetCharWidth();
+    nCy1 = GetCharHeight();
+    nHeight = GetRowCount() * rSizeBtn.y + (2 * nCy1);
+    nWidth  = GetColumnCount() * (rSizeBtn.x + nCx1) + nCx1;
 
     //
     // And also wide enough for its label
     //
 
     //
     // And also wide enough for its label
     //
-    GetTextExtent( GetTitle()
-                  ,&nWidthLabel
-                  ,NULL
-                 );
-    nWidthLabel += RADIO_SIZE;
+    wxString sStr = wxGetWindowText(GetHwnd());
+    if (!sStr.empty())
+    {
+        GetTextExtent( sStr
+                      ,&nWidthLabel
+                      ,NULL
+                     );
+        nWidthLabel += 2*nCx1;
+    }
     if (nWidthLabel > nWidth)
         nWidth = nWidthLabel;
 
     if (nWidthLabel > nWidth)
         nWidth = nWidthLabel;
 
-    return(wxSize( nWidth
-                  ,nHeight
-                 )
-          );
+    wxSize total( nWidth, nHeight );
+    return total;
 } // end of wxRadioBox::GetTotalButtonSize
 
 } // end of wxRadioBox::GetTotalButtonSize
 
-WXHBRUSH wxRadioBox::OnCtlColor(
-  WXHDC                             hwinDC
-, WXHWND                            hWnd
-, WXUINT                            uCtlColor
-, WXUINT                            uMessage
-, WXWPARAM                          wParam
-, WXLPARAM                          lParam
-)
+WXHBRUSH wxRadioBox::OnCtlColor( WXHDC    hwinDC,
+                                 WXHWND   WXUNUSED(hWnd),
+                                 WXUINT   WXUNUSED(uCtlColor),
+                                 WXUINT   WXUNUSED(uMessage),
+                                 WXWPARAM WXUNUSED(wParam),
+                                 WXLPARAM WXUNUSED(lParam) )
 {
 {
-    HPS                             hPS = (HPS)hwinDC; // pass in a PS handle in OS/2
+    HPS hPS = (HPS)hwinDC; // pass in a PS handle in OS/2
 
     if (GetParent()->GetTransparentBackground())
         ::GpiSetBackMix(hPS, BM_LEAVEALONE);
     else
         ::GpiSetBackMix(hPS, BM_OVERPAINT);
 
 
     if (GetParent()->GetTransparentBackground())
         ::GpiSetBackMix(hPS, BM_LEAVEALONE);
     else
         ::GpiSetBackMix(hPS, BM_OVERPAINT);
 
-    wxColour                        vColBack = GetBackgroundColour();
+    wxColour vColBack = GetBackgroundColour();
 
     ::GpiSetBackColor(hPS, vColBack.GetPixel());
     ::GpiSetColor(hPS, vColBack.GetPixel());
 
 
     ::GpiSetBackColor(hPS, vColBack.GetPixel());
     ::GpiSetColor(hPS, vColBack.GetPixel());
 
-
-    wxBrush*                        pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
-                                                                               ,wxSOLID
-                                                                              );
+    wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack, wxSOLID );
     return ((WXHBRUSH)pBrush->GetResourceHandle());
 } // end of wxRadioBox::OnCtlColor
 
     return ((WXHBRUSH)pBrush->GetResourceHandle());
 } // end of wxRadioBox::OnCtlColor
 
-bool wxRadioBox::OS2Command(
-  WXUINT                            uCmd
-, WXWORD                            wId
-)
+bool wxRadioBox::OS2Command( WXUINT uCmd,
+                             WXWORD wId)
 {
 {
-    int                             nSelectedButton = -1;
+    int nSelectedButton = -1;
 
     if (uCmd == BN_CLICKED)
     {
         if (wId == GetId())
 
     if (uCmd == BN_CLICKED)
     {
         if (wId == GetId())
-            return TRUE;
-
+            return true;
 
         for (int i = 0; i < m_nNoItems; i++)
         {
 
         for (int i = 0; i < m_nNoItems; i++)
         {
@@ -969,21 +712,19 @@ bool wxRadioBox::OS2Command(
         if (nSelectedButton == -1)
         {
             //
         if (nSelectedButton == -1)
         {
             //
-            // Just ignore it - due to a hack with WM_NCHITTEST handling in our
-            // wnd proc, we can receive dummy click messages when we click near
-            // the radiobox edge (this is ugly but Julian wouldn't let me get
-            // rid of this...)
-            return FALSE;
+            // Just ignore it
+            //
+            return false;
         }
         if (nSelectedButton != m_nSelectedButton)
         {
             m_nSelectedButton = nSelectedButton;
             SendNotificationEvent();
         }
         }
         if (nSelectedButton != m_nSelectedButton)
         {
             m_nSelectedButton = nSelectedButton;
             SendNotificationEvent();
         }
-        return TRUE;
+        return true;
     }
     else
     }
     else
-        return FALSE;
+        return false;
 } // end of wxRadioBox::OS2Command
 
 void wxRadioBox::SendNotificationEvent()
 } // end of wxRadioBox::OS2Command
 
 void wxRadioBox::SendNotificationEvent()
@@ -1018,13 +759,11 @@ bool wxRadioBox::SetFont(
         //
         // Nothing to do
         //
         //
         // Nothing to do
         //
-        return FALSE;
+        return false;
     }
     //
     // Also set the font of our radio buttons
     //
     }
     //
     // Also set the font of our radio buttons
     //
-    WXHFONT                         hFont = wxFont(rFont).GetResourceHandle();
-
     for (int n = 0; n < (int)m_nNoItems; n++)
     {
         HWND                        hWndBtn = (HWND)m_ahRadioButtons[n];
     for (int n = 0; n < (int)m_nNoItems; n++)
     {
         HWND                        hWndBtn = (HWND)m_ahRadioButtons[n];
@@ -1034,16 +773,16 @@ bool wxRadioBox::SetFont(
                     );
         ::WinInvalidateRect(hWndBtn, NULL, FALSE);
     }
                     );
         ::WinInvalidateRect(hWndBtn, NULL, FALSE);
     }
-    return TRUE;
+    return true;
 } // end of wxRadioBox::SetFont
 
 void wxRadioBox::SetSelection(
   int                               nNum
 )
 {
 } // end of wxRadioBox::SetFont
 
 void wxRadioBox::SetSelection(
   int                               nNum
 )
 {
-    wxCHECK_RET( (nNum >= 0) && (nNum < m_nNoItems), wxT("invalid radiobox index") );
+    wxCHECK_RET( IsValid(nNum), wxT("invalid radiobox index") );
 
 
-    if (m_nSelectedButton >= 0 && m_nSelectedButton < m_nNoItems)
+    if ( IsValid(m_nSelectedButton) )
         ::WinSendMsg((HWND)m_ahRadioButtons[m_nSelectedButton], BM_SETCHECK, (MPARAM)0, (MPARAM)0);
 
     ::WinSendMsg((HWND)m_ahRadioButtons[nNum], BM_SETCHECK, (MPARAM)1, (MPARAM)0);
         ::WinSendMsg((HWND)m_ahRadioButtons[m_nSelectedButton], BM_SETCHECK, (MPARAM)0, (MPARAM)0);
 
     ::WinSendMsg((HWND)m_ahRadioButtons[nNum], BM_SETCHECK, (MPARAM)1, (MPARAM)0);
@@ -1056,61 +795,57 @@ void wxRadioBox::SetString(
 , const wxString&                   rsLabel
 )
 {
 , const wxString&                   rsLabel
 )
 {
-    wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems, wxT("invalid radiobox index") );
+    wxCHECK_RET( IsValid(nItem), wxT("invalid radiobox index") );
 
     m_pnRadioWidth[nItem] = m_pnRadioHeight[nItem] = -1;
 
     m_pnRadioWidth[nItem] = m_pnRadioHeight[nItem] = -1;
-    ::WinSetWindowText((HWND)m_ahRadioButtons[nItem], rsLabel.c_str());
+    ::WinSetWindowText((HWND)m_ahRadioButtons[nItem], (PSZ)rsLabel.c_str());
 } // end of wxRadioBox::SetString
 
 } // end of wxRadioBox::SetString
 
-bool wxRadioBox::SetStringSelection(
-  const wxString&                   rsStr
-)
+bool wxRadioBox::SetStringSelection(const wxString& rsStr)
 {
 {
-    int                             nSel = FindString(rsStr);
+    int nSel = FindString(rsStr);
 
     if (nSel > -1)
     {
         SetSelection(nSel);
 
     if (nSel > -1)
     {
         SetSelection(nSel);
-        return TRUE;
+        return true;
     }
     else
     }
     else
-        return FALSE;
+        return false;
 } // end of wxRadioBox::SetStringSelection
 
 bool wxRadioBox::Show(
   bool                              bShow
 )
 {
 } // end of wxRadioBox::SetStringSelection
 
 bool wxRadioBox::Show(
   bool                              bShow
 )
 {
-    int                             nCmdShow = 0;
-
     if (!wxControl::Show(bShow))
     if (!wxControl::Show(bShow))
-        return FALSE;
+        return false;
 
     for (int i = 0; i < m_nNoItems; i++)
     {
         ::WinShowWindow((HWND)m_ahRadioButtons[i], (BOOL)bShow);
     }
 
     for (int i = 0; i < m_nNoItems; i++)
     {
         ::WinShowWindow((HWND)m_ahRadioButtons[i], (BOOL)bShow);
     }
-    return TRUE;
+    return true;
 } // end of wxRadioBox::Show
 
 // Show a specific button
 } // end of wxRadioBox::Show
 
 // Show a specific button
-void wxRadioBox::Show(
+bool wxRadioBox::Show(
   int                               nItem
 , bool                              bShow
 )
 {
   int                               nItem
 , bool                              bShow
 )
 {
-    wxCHECK_RET( nItem >= 0 && nItem < m_nNoItems,
+    wxCHECK_MSG( IsValid(nItem), false,
                  wxT("invalid item in wxRadioBox::Show()") );
 
     ::WinShowWindow((HWND)m_ahRadioButtons[nItem], bShow);
                  wxT("invalid item in wxRadioBox::Show()") );
 
     ::WinShowWindow((HWND)m_ahRadioButtons[nItem], bShow);
+
+    return true;
 } // end of wxRadioBox::Show
 
 void wxRadioBox::SubclassRadioButton(
   WXHWND                            hWndBtn
 )
 {
 } // end of wxRadioBox::Show
 
 void wxRadioBox::SubclassRadioButton(
   WXHWND                            hWndBtn
 )
 {
-    HWND                            hwndBtn = (HWND)hWndBtn;
-
     fnWndProcRadioBtn = (WXFARPROC)::WinSubclassWindow(hWndBtn, (PFNWP)wxRadioBtnWndProc);
 } // end of wxRadioBox::SubclassRadioButton
 
     fnWndProcRadioBtn = (WXFARPROC)::WinSubclassWindow(hWndBtn, (PFNWP)wxRadioBtnWndProc);
 } // end of wxRadioBox::SubclassRadioButton
 
@@ -1151,17 +886,17 @@ MRESULT wxRadioBtnWndProc(
                                                                                                 ,QWL_USER
                                                                                                );
                         USHORT                  uVk = SHORT2FROMMP((MPARAM)lParam);
                                                                                                 ,QWL_USER
                                                                                                );
                         USHORT                  uVk = SHORT2FROMMP((MPARAM)lParam);
-                        bool                    bProcessed = TRUE;
+                        bool                    bProcessed = true;
                         wxDirection             eDir;
 
                         switch(uVk)
                         {
                             case VK_LEFT:
                         wxDirection             eDir;
 
                         switch(uVk)
                         {
                             case VK_LEFT:
-                                eDir = wxDOWN;
+                                eDir = wxLEFT;
                                 break;
 
                             case VK_RIGHT:
                                 break;
 
                             case VK_RIGHT:
-                                eDir = wxDOWN;
+                                eDir = wxRIGHT;
                                 break;
 
                             case VK_DOWN:
                                 break;
 
                             case VK_DOWN:
@@ -1173,7 +908,7 @@ MRESULT wxRadioBtnWndProc(
                                 break;
 
                             default:
                                 break;
 
                             default:
-                                bProcessed = FALSE;
+                                bProcessed = false;
 
                                 //
                                 // Just to suppress the compiler warning
 
                                 //
                                 // Just to suppress the compiler warning
@@ -1213,3 +948,14 @@ MRESULT wxRadioBtnWndProc(
                             );
 } // end of wxRadioBtnWndProc
 
                             );
 } // end of wxRadioBtnWndProc
 
+MRESULT EXPENTRY wxRadioBoxWndProc( HWND hWnd,
+                                    UINT uMessage,
+                                    MPARAM wParam,
+                                    MPARAM lParam )
+{
+    return (fnWndProcRadioBox( hWnd,
+                               (ULONG)uMessage,
+                               (MPARAM)wParam,
+                               (MPARAM)lParam )
+           );
+} // end of wxRadioBoxWndProc