]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/radiobox.cpp
disallow creation of wxDC objects and made wxDC an ABC; use wxDCTemp instead of wxDC...
[wxWidgets.git] / src / os2 / radiobox.cpp
index 3e52e2a3a2cabeac60baa62587c71a860cc629c4..67d6434a3248ed3d4fc6c2c0c429adc68d971244 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        radiobox.cpp
+// Name:        src/os2/radiobox.cpp
 // Purpose:     wxRadioBox
 // Author:      David Webster
 // Modified by:
@@ -68,7 +68,6 @@ wxRadioBox::wxRadioBox()
     m_nNoItems = 0;
     m_nNoRowsOrCols = 0;
     m_ahRadioButtons = NULL;
-    m_nMajorDim = 0;
     m_pnRadioWidth = NULL;
     m_pnRadioHeight = NULL;
 } // end of wxRadioBox::wxRadioBox
@@ -90,24 +89,22 @@ wxRadioBox::~wxRadioBox()
         delete[] m_pnRadioHeight;
 } // end of wxRadioBox::~wxRadioBox
 
-void wxRadioBox::AdjustButtons(
-  int                               nX
-, int                               nY
-, int                               nWidth
-, int                               nHeight
-, int                               nSizeFlags
-)
+void wxRadioBox::AdjustButtons( int nX,
+                                int nY,
+                                int nWidth,
+                                int nHeight,
+                                int WXUNUSED(nSizeFlags) )
 {
-    wxSize                          vMaxSize;
-    int                             nXOffset = nX;
-    int                             nYOffset = nY + nHeight;
-    int                             nCx1;
-    int                             nCy1;
-    int                             nStartX;
-    int                             nStartY;
-    int                             nMaxWidth;
-    int                             nMaxHeight;
-    wxFont                          vFont = GetFont();
+    wxSize vMaxSize;
+    int    nXOffset = nX;
+    int    nYOffset = nY + nHeight;
+    int    nCx1;
+    int    nCy1;
+    int    nStartX;
+    int    nStartY;
+    int    nMaxWidth;
+    int    nMaxHeight;
+    wxFont vFont = GetFont();
 
     wxGetCharSize( m_hWnd
                   ,&nCx1
@@ -141,20 +138,20 @@ void wxRadioBox::AdjustButtons(
             //
             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
             //
-            bIsLastInTheRow = i >= (m_nNoItems/m_nMajorDim) * m_nMajorDim;
+            bIsLastInTheRow = i >= (m_nNoItems/GetMajorDim()) * GetMajorDim();
         }
 
         //
         // 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)
             {
@@ -288,12 +285,12 @@ bool wxRadioBox::Create(
     wxColour                        vColour;
     LONG                            lColor;
 
-    vColour.Set(wxString("BLACK"));
+    vColour.Set(wxString(wxT("BLACK")));
     m_backgroundColour = pParent->GetBackgroundColour();
     m_nSelectedButton = -1;
     m_nNoItems = 0;
 
-    m_nMajorDim     = nMajorDim == 0 ? nNum : nMajorDim;
+    SetMajorDim(nMajorDim == 0 ? nNum : nMajorDim, lStyle);
     m_nNoRowsOrCols = nMajorDim;
 
     //
@@ -308,7 +305,7 @@ bool wxRadioBox::Create(
                        ,rsName
                       ))
         return false;
-    if (!OS2CreateControl( "STATIC"
+    if (!OS2CreateControl( wxT("STATIC")
                           ,SS_GROUPBOX
                           ,rPos
                           ,rSize
@@ -339,7 +336,7 @@ bool wxRadioBox::Create(
 
         HWND                        hWndBtn = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent)
                                                                          ,WC_BUTTON
-                                                                         ,asChoices[i]
+                                                                         ,::wxPMTextToLabel(asChoices[i])
                                                                          ,lStyleBtn
                                                                          ,0, 0, 0, 0
                                                                          ,GetWinHwnd(pParent)
@@ -378,16 +375,16 @@ bool wxRadioBox::Create(
     //
     // Create a dummy radio 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 ( GetHwndOf(pParent),
+                              WC_BUTTON,
+                              "",
+                              WS_GROUP | BS_AUTORADIOBUTTON,
+                              0, 0, 0, 0,
+                              GetWinHwnd(pParent),
+                              HWND_TOP,
+                              (HMENU)NewControlId(),
+                              NULL,
+                              NULL
                             );
     SetFont(*wxSMALL_FONT);
     fnWndProcRadioBox = (WXFARPROC)::WinSubclassWindow( GetHwnd()
@@ -474,9 +471,9 @@ void wxRadioBox::DoSetSize(
             ,&nHeightOld
            );
 
-    if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+    if (nX == wxDefaultCoord && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
         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;
@@ -580,20 +577,20 @@ void wxRadioBox::DoSetSize(
             //
             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
             //
-            bIsLastInTheRow = i >= (m_nNoItems/m_nMajorDim) * m_nMajorDim;
+            bIsLastInTheRow = i >= (m_nNoItems/GetMajorDim()) * GetMajorDim();
         }
 
         //
         // 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)
             {
@@ -646,7 +643,6 @@ void wxRadioBox::DoSetSize(
                           ,(LONG)nMaxHeight
                           ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
                          );
-        GetParent()->Refresh();
         //
         // Where do we put the next button?
         //
@@ -671,7 +667,7 @@ void wxRadioBox::DoSetSize(
 
 bool wxRadioBox::Enable(int nItem, bool bEnable)
 {
-    wxCHECK_MSG( nItem >= 0 && nItem < m_nNoItems, false,
+    wxCHECK_MSG( IsValid(nItem), false,
                  wxT("invalid item in wxRadioBox::Enable()") );
 
     ::WinEnableWindow((HWND) m_ahRadioButtons[nItem], bEnable);
@@ -689,33 +685,14 @@ bool wxRadioBox::Enable(
     return true;
 } // 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
 
-wxString wxRadioBox::GetLabel(
-  int                               nItem
-) const
+wxString wxRadioBox::GetLabel(int nItem) const
 {
-    wxCHECK_MSG(nItem >= 0 && nItem < m_nNoItems, wxEmptyString, wxT("invalid radiobox index") );
+    wxCHECK_MSG( IsValid(nItem), wxEmptyString, wxT("invalid radiobox index") );
 
     return wxGetWindowText(m_ahRadioButtons[nItem]);
 } // end of wxRadioBox::GetLabel
@@ -755,43 +732,15 @@ wxSize wxRadioBox::GetMaxButtonSize() const
         if (nHeightMax < nHeight )
             nHeightMax = nHeight;
     }
-    return(wxSize( nWidthMax
-                  ,nHeightMax
-                 )
-          );
+    wxSize maxsize( nWidthMax, nHeightMax);
+    return maxsize;
 } // 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
+void wxRadioBox::GetPosition( int* pnX,
+                              int* WXUNUSED(pnY) ) const
 {
     wxWindowOS2*                    pParent = GetParent();
-    RECT                            vRect = { -1, -1, -1, -1 };;
+    RECT                            vRect = { -1, -1, -1, -1 };
     POINTL                          vPoint;
     int                             i;
 
@@ -834,21 +783,13 @@ void wxRadioBox::GetPosition(
     *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
 
-void wxRadioBox::GetSize(
-  int*                              pnWidth
-, int*                              pnHeight
-) const
+void wxRadioBox::GetSize( int* pnWidth, int* pnHeight ) const
 {
     RECT                            vRect;
     int                             i;
@@ -893,79 +834,65 @@ wxString wxRadioBox::GetStringSelection() const
     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;
-    wxFont                          vFont = GetFont();
+    int    nCx1;
+    int    nCy1;
+    int    nHeight;
+    int    nWidth;
+    int    nWidthLabel = 0;
 
-    wxGetCharSize( m_hWnd
-                  ,&nCx1
-                  ,&nCy1
-                  ,&vFont
-                 );
-    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
     //
-    GetTextExtent( GetTitle()
-                  ,&nWidthLabel
-                  ,NULL
-                 );
-    nWidthLabel += RADIO_SIZE;
+    wxString                        sStr = wxGetWindowText(GetHwnd());
+    if (!sStr.IsEmpty())
+    {
+        GetTextExtent( sStr
+                      ,&nWidthLabel
+                      ,NULL
+                     );
+        nWidthLabel += 2*nCx1;
+    }
     if (nWidthLabel > nWidth)
         nWidth = nWidthLabel;
 
-    return(wxSize( nWidth
-                  ,nHeight
-                 )
-          );
+    wxSize total( nWidth, nHeight );
+    return total;
 } // 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);
 
-    wxColour                        vColBack = GetBackgroundColour();
+    wxColour vColBack = GetBackgroundColour();
 
     ::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
 
-bool wxRadioBox::OS2Command(
-  WXUINT                            uCmd
-, WXWORD                            wId
-)
+bool wxRadioBox::OS2Command( WXUINT uCmd,
+                             WXWORD wId)
 {
-    int                             nSelectedButton = -1;
+    int nSelectedButton = -1;
 
     if (uCmd == BN_CLICKED)
     {
@@ -1052,9 +979,9 @@ 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);
@@ -1067,17 +994,15 @@ void wxRadioBox::SetString(
 , 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;
-    ::WinSetWindowText((HWND)m_ahRadioButtons[nItem], rsLabel.c_str());
+    ::WinSetWindowText((HWND)m_ahRadioButtons[nItem], (PSZ)rsLabel.c_str());
 } // 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)
     {
@@ -1103,15 +1028,17 @@ bool wxRadioBox::Show(
 } // end of wxRadioBox::Show
 
 // Show a specific button
-void wxRadioBox::Show(
+bool wxRadioBox::Show(
   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);
+
+    return true;
 } // end of wxRadioBox::Show
 
 void wxRadioBox::SubclassRadioButton(
@@ -1220,18 +1147,14 @@ MRESULT wxRadioBtnWndProc(
                             );
 } // end of wxRadioBtnWndProc
 
-MRESULT EXPENTRY wxRadioBoxWndProc(
-  HWND                              hWnd
-, UINT                              uMessage
-, MPARAM                            wParam
-, MPARAM                            lParam
-)
+MRESULT EXPENTRY wxRadioBoxWndProc( HWND hWnd,
+                                    UINT uMessage,
+                                    MPARAM wParam,
+                                    MPARAM lParam )
 {
-    return (fnWndProcRadioBox( hWnd
-                              ,(ULONG)uMessage
-                              ,(MPARAM)wParam
-                              ,(MPARAM)lParam
-                             )
+    return (fnWndProcRadioBox( hWnd,
+                               (ULONG)uMessage,
+                               (MPARAM)wParam,
+                               (MPARAM)lParam )
            );
 } // end of wxRadioBoxWndProc
-