]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/radiobox.cpp
Use wxMBConvUTF8 when G_FILENAME_ENCODING is UTF-8, and set
[wxWidgets.git] / src / os2 / radiobox.cpp
index fa32d2ccadc66792b342bd71625eed1ded32314c..1f789a294ff9bf3f903f7253ebb0d288afcdb079 100644 (file)
@@ -36,13 +36,22 @@ MRESULT EXPENTRY wxRadioBtnWndProc( HWND hWnd
                                    ,MPARAM wParam
                                    ,MPARAM lParam
                                   );
+MRESULT EXPENTRY wxRadioBoxWndProc( HWND   hWnd
+                                   ,UINT   uMessage
+                                   ,MPARAM wParam
+                                   ,MPARAM lParam
+                                  );
 
 // ---------------------------------------------------------------------------
 // global vars
 // ---------------------------------------------------------------------------
 
 // the pointer to standard radio button wnd proc
+extern void  wxAssociateWinWithHandle( HWND         hWnd
+                                      ,wxWindowOS2* pWin
+                                     );
 static WXFARPROC                    fnWndProcRadioBtn = NULL;
+static WXFARPROC                    fnWndProcRadioBox = NULL;
 
 // ===========================================================================
 // implementation
@@ -66,7 +75,7 @@ wxRadioBox::wxRadioBox()
 
 wxRadioBox::~wxRadioBox()
 {
-    m_isBeingDeleted = TRUE;
+    m_isBeingDeleted = true;
 
     if (m_ahRadioButtons)
     {
@@ -98,13 +107,12 @@ void wxRadioBox::AdjustButtons(
     int                             nStartY;
     int                             nMaxWidth;
     int                             nMaxHeight;
-    int                             nTotWidth;
-    int                             nTotHeight;
+    wxFont                          vFont = GetFont();
 
     wxGetCharSize( m_hWnd
                   ,&nCx1
                   ,&nCy1
-                  ,&GetFont()
+                  ,&vFont
                  );
     vMaxSize   = GetMaxButtonSize();
     nMaxWidth  = vMaxSize.x;
@@ -239,11 +247,30 @@ bool wxRadioBox::ContainsHWND(
     for (i = 0; i < nCount; i++)
     {
         if (GetRadioButtons()[i] == hWnd)
-            return TRUE;
+            return true;
     }
-    return FALSE;
+    return false;
 } // 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
@@ -254,24 +281,17 @@ bool wxRadioBox::Create(
 , const wxString                    asChoices[]
 , int                               nMajorDim
 , long                              lStyle
-#if wxUSE_VALIDATORS
 , const wxValidator&                rVal
-#endif
 , const wxString&                   rsName
 )
 {
-    //
-    // System fonts are too big in OS/2 and they are blue
-    // We want smaller fonts and black by default.
-    //
-    wxFont&                         rFont = *wxSMALL_FONT;
     wxColour                        vColour;
     LONG                            lColor;
 
     vColour.Set(wxString("BLACK"));
-    lColor = (LONG)vColour.GetPixel();
+    m_backgroundColour = pParent->GetBackgroundColour();
     m_nSelectedButton = -1;
-    m_nNoItems        = nNum;
+    m_nNoItems = 0;
 
     m_nMajorDim     = nMajorDim == 0 ? nNum : nMajorDim;
     m_nNoRowsOrCols = nMajorDim;
@@ -279,47 +299,34 @@ bool wxRadioBox::Create(
     //
     // Common initialization
     //
-    if (!OS2CreateControl( pParent
-                          ,vId
-                          ,rPos
-                          ,rSize
-                          ,lStyle
-#if wxUSE_VALIDATORS
-                          ,rVal
-#endif
-                          ,rsName
-                         ))
-
-
-
-
+    if (!CreateControl( pParent
+                       ,vId
+                       ,rPos
+                       ,rSize
+                       ,lStyle
+                       ,rVal
+                       ,rsName
+                      ))
+        return false;
     if (!OS2CreateControl( "STATIC"
-                          ,SS_GROUPBOX | WS_GROUP
+                          ,SS_GROUPBOX
                           ,rPos
                           ,rSize
                           ,rsTitle
                          ))
+        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.
     //
+    m_nNoItems = nNum;
     (void)NewControlId();
     m_ahRadioButtons = new WXHWND[nNum];
     m_pnRadioWidth   = new int[nNum];
     m_pnRadioHeight  = new int[nNum];
 
-    if (rFont.Ok())
-    {
-        hFont = rFont.GetResourceHandle();
-    }
-
     for (int i = 0; i < nNum; i++)
     {
         m_pnRadioWidth[i] = m_pnRadioHeight[i] = -1;
@@ -341,19 +348,28 @@ bool wxRadioBox::Create(
                                                                          ,NULL
                                                                          ,NULL
                                                                         );
+        lColor = (LONG)vColour.GetPixel();
         ::WinSetPresParam( hWndBtn
                           ,PP_FOREGROUNDCOLOR
                           ,sizeof(LONG)
                           ,(PVOID)&lColor
                          );
+        lColor = (LONG)m_backgroundColour.GetPixel();
+
+        ::WinSetPresParam( hWndBtn
+                          ,PP_BACKGROUNDCOLOR
+                          ,sizeof(LONG)
+                          ,(PVOID)&lColor
+                         );
         if (!hWndBtn)
         {
-            return FALSE;
+            return false;
         }
         m_ahRadioButtons[i] = (WXHWND)hWndBtn;
         SubclassRadioButton((WXHWND)hWndBtn);
+        wxAssociateWinWithHandle(hWndBtn, this);
         wxOS2SetFont( hWndBtn
-                     ,rFont
+                     ,*wxSMALL_FONT
                     );
         ::WinSetWindowULong(hWndBtn, QWL_USER, (ULONG)this);
         m_aSubControls.Add(nNewId);
@@ -373,19 +389,43 @@ bool wxRadioBox::Create(
                              ,NULL
                              ,NULL
                             );
-     SetFont(*wxSMALL_FONT);
+    SetFont(*wxSMALL_FONT);
+    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
                      );
+    ::WinSetPresParam( m_hWnd
+                      ,PP_BORDERDARKCOLOR
+                      ,sizeof(LONG)
+                      ,(PVOID)&lColor
+                     );
+    lColor = (LONG)m_backgroundColour.GetPixel();
+
+    ::WinSetPresParam( m_hWnd
+                      ,PP_BACKGROUNDCOLOR
+                      ,sizeof(LONG)
+                      ,(PVOID)&lColor
+                     );
+    ::WinSetPresParam( m_hWnd
+                      ,PP_BORDERLIGHTCOLOR
+                      ,sizeof(LONG)
+                      ,(PVOID)&lColor
+                     );
+    SetXComp(0);
+    SetYComp(0);
     SetSelection(0);
     SetSize( rPos.x
             ,rPos.y
             ,rSize.x
             ,rSize.y
            );
-    return TRUE;
+    return true;
 } // end of wxRadioBox::Create
 
 wxSize wxRadioBox::DoGetBestSize() const
@@ -424,6 +464,7 @@ void wxRadioBox::DoSetSize(
     int                             nTotHeight;
     int                             nStartX;
     int                             nStartY;
+    wxFont                          vFont = GetFont();
 
     m_nSizeFlags = nSizeFlags;
     GetPosition( &nCurrentX
@@ -433,16 +474,19 @@ 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;
+    if (nXx < 0)
+        nXx = 0;
 
     wxGetCharSize( m_hWnd
                   ,&nCx1
                   ,&nCy1
-                  ,&GetFont()
+                  ,&vFont
                  );
 
     //
@@ -602,6 +646,7 @@ void wxRadioBox::DoSetSize(
                           ,(LONG)nMaxHeight
                           ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
                          );
+        GetParent()->Refresh();
         //
         // Where do we put the next button?
         //
@@ -624,15 +669,13 @@ void 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);
+    return true;
 } // end of wxRadioBox::Enable
 
 bool wxRadioBox::Enable(
@@ -640,10 +683,10 @@ bool wxRadioBox::Enable(
 )
 {
     if ( !wxControl::Enable(bEnable) )
-        return FALSE;
+        return false;
     for (int i = 0; i < m_nNoItems; i++)
         ::WinEnableWindow((HWND)m_ahRadioButtons[i], bEnable);
-    return TRUE;
+    return true;
 } // end of wxRadioBox::Enable
 
 int wxRadioBox::FindString(
@@ -672,7 +715,7 @@ 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
@@ -825,8 +868,10 @@ void wxRadioBox::GetSize(
                       ,&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
@@ -858,11 +903,12 @@ wxSize wxRadioBox::GetTotalButtonSize(
     int                             nHeight;
     int                             nWidth;
     int                             nWidthLabel;
+    wxFont                          vFont = GetFont();
 
     wxGetCharSize( m_hWnd
                   ,&nCx1
                   ,&nCy1
-                  ,(wxFont*)&GetFont()
+                  ,&vFont
                  );
     nExtraHeight = nCy1;
 
@@ -924,7 +970,7 @@ bool wxRadioBox::OS2Command(
     if (uCmd == BN_CLICKED)
     {
         if (wId == GetId())
-            return TRUE;
+            return true;
 
 
         for (int i = 0; i < m_nNoItems; i++)
@@ -938,21 +984,19 @@ bool wxRadioBox::OS2Command(
         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();
         }
-        return TRUE;
+        return true;
     }
     else
-        return FALSE;
+        return false;
 } // end of wxRadioBox::OS2Command
 
 void wxRadioBox::SendNotificationEvent()
@@ -987,13 +1031,11 @@ bool wxRadioBox::SetFont(
         //
         // Nothing to do
         //
-        return FALSE;
+        return false;
     }
     //
     // 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];
@@ -1003,16 +1045,16 @@ bool wxRadioBox::SetFont(
                     );
         ::WinInvalidateRect(hWndBtn, NULL, FALSE);
     }
-    return TRUE;
+    return true;
 } // 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);
@@ -1025,7 +1067,7 @@ 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());
@@ -1040,46 +1082,44 @@ bool wxRadioBox::SetStringSelection(
     if (nSel > -1)
     {
         SetSelection(nSel);
-        return TRUE;
+        return true;
     }
     else
-        return FALSE;
+        return false;
 } // end of wxRadioBox::SetStringSelection
 
 bool wxRadioBox::Show(
   bool                              bShow
 )
 {
-    int                             nCmdShow = 0;
-
     if (!wxControl::Show(bShow))
-        return FALSE;
+        return false;
 
     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
-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(
   WXHWND                            hWndBtn
 )
 {
-    HWND                            hwndBtn = (HWND)hWndBtn;
-
     fnWndProcRadioBtn = (WXFARPROC)::WinSubclassWindow(hWndBtn, (PFNWP)wxRadioBtnWndProc);
 } // end of wxRadioBox::SubclassRadioButton
 
@@ -1120,7 +1160,7 @@ MRESULT wxRadioBtnWndProc(
                                                                                                 ,QWL_USER
                                                                                                );
                         USHORT                  uVk = SHORT2FROMMP((MPARAM)lParam);
-                        bool                    bProcessed = TRUE;
+                        bool                    bProcessed = true;
                         wxDirection             eDir;
 
                         switch(uVk)
@@ -1142,7 +1182,7 @@ MRESULT wxRadioBtnWndProc(
                                 break;
 
                             default:
-                                bProcessed = FALSE;
+                                bProcessed = false;
 
                                 //
                                 // Just to suppress the compiler warning
@@ -1182,3 +1222,18 @@ MRESULT 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
+