]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/radiobox.cpp
extracted OnSize() body in a new DoLayout() method so that it can be called from...
[wxWidgets.git] / src / os2 / radiobox.cpp
index 47a6fbdd9c0892761c6c05d8436600243ee8579a..14ba806ec589e42f3dfe3a592ac0b020476d7e46 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
@@ -86,7 +95,7 @@ void wxRadioBox::AdjustButtons(
 , int                               nY
 , int                               nWidth
 , int                               nHeight
-, long                              lSizeFlags
+, int                               nSizeFlags
 )
 {
     wxSize                          vMaxSize;
@@ -98,8 +107,6 @@ void wxRadioBox::AdjustButtons(
     int                             nStartY;
     int                             nMaxWidth;
     int                             nMaxHeight;
-    int                             nTotWidth;
-    int                             nTotHeight;
 
     wxGetCharSize( m_hWnd
                   ,&nCx1
@@ -244,6 +251,25 @@ bool wxRadioBox::ContainsHWND(
     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 +280,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 +298,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 +347,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;
         }
         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,12 +388,36 @@ 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
@@ -437,7 +476,10 @@ void wxRadioBox::DoSetSize(
         nXx = nCurrentX;
     if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
         nYy = nCurrentY;
-
+    if (nYy < 0)
+        nYy = 0;
+    if (nXx < 0)
+        nXx = 0;
 
     wxGetCharSize( m_hWnd
                   ,&nCx1
@@ -480,7 +522,9 @@ void wxRadioBox::DoSetSize(
 
     if (pParent)
     {
-        nYy = pParent->GetClientSize().y - (nYy + nHeight);
+        int                         nOS2Height = GetOS2ParentHeight(pParent);
+
+        nYy = nOS2Height - (nYy + nHeight);
         nYOffset = nYy + nHeight;
     }
     else
@@ -600,6 +644,7 @@ void wxRadioBox::DoSetSize(
                           ,(LONG)nMaxHeight
                           ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
                          );
+        GetParent()->Refresh();
         //
         // Where do we put the next button?
         //
@@ -823,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
@@ -936,10 +983,8 @@ 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...)
+            // Just ignore it
+            //
             return FALSE;
         }
         if (nSelectedButton != m_nSelectedButton)
@@ -990,8 +1035,6 @@ bool wxRadioBox::SetFont(
     //
     // 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];
@@ -1048,8 +1091,6 @@ bool wxRadioBox::Show(
   bool                              bShow
 )
 {
-    int                             nCmdShow = 0;
-
     if (!wxControl::Show(bShow))
         return FALSE;
 
@@ -1076,8 +1117,6 @@ void wxRadioBox::SubclassRadioButton(
   WXHWND                            hWndBtn
 )
 {
-    HWND                            hwndBtn = (HWND)hWndBtn;
-
     fnWndProcRadioBtn = (WXFARPROC)::WinSubclassWindow(hWndBtn, (PFNWP)wxRadioBtnWndProc);
 } // end of wxRadioBox::SubclassRadioButton
 
@@ -1180,3 +1219,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
+