X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/11e62fe658531aaa2891351f19bd0a4c076717ae..a7d5151df02bf70a9f6ff1c5c7fd33ab07bf409c:/src/os2/radiobox.cpp diff --git a/src/os2/radiobox.cpp b/src/os2/radiobox.cpp index af010f9576..3b93efcba8 100644 --- a/src/os2/radiobox.cpp +++ b/src/os2/radiobox.cpp @@ -46,10 +46,11 @@ MRESULT EXPENTRY wxRadioBoxWndProc( HWND hWnd // 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 fnWndProcRadioBox = NULL; @@ -66,9 +67,7 @@ wxRadioBox::wxRadioBox() { m_nSelectedButton = -1; m_nNoItems = 0; - m_nNoRowsOrCols = 0; m_ahRadioButtons = NULL; - m_nMajorDim = 0; m_pnRadioWidth = NULL; m_pnRadioHeight = NULL; } // end of wxRadioBox::wxRadioBox @@ -77,11 +76,17 @@ wxRadioBox::~wxRadioBox() { m_isBeingDeleted = true; + if (m_hWnd) + wxRemoveHandleAssociation(this); 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]); + } delete[] m_ahRadioButtons; } if (m_pnRadioWidth) @@ -90,143 +95,6 @@ wxRadioBox::~wxRadioBox() delete[] m_pnRadioHeight; } // end of wxRadioBox::~wxRadioBox -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(); - - wxGetCharSize( m_hWnd - ,&nCx1 - ,&nCy1 - ,&vFont - ); - 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 ) @@ -285,15 +153,13 @@ bool wxRadioBox::Create( { wxColour vColour; LONG lColor; + HWND hWndParent = GetHwndOf(pParent); vColour.Set(wxString(wxT("BLACK"))); m_backgroundColour = pParent->GetBackgroundColour(); m_nSelectedButton = -1; m_nNoItems = 0; - m_nMajorDim = nMajorDim == 0 ? nNum : nMajorDim; - m_nNoRowsOrCols = nMajorDim; - // // Common initialization // @@ -317,10 +183,11 @@ bool wxRadioBox::Create( 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; - (void)NewControlId(); + SetMajorDim(nMajorDim == 0 ? nNum : nMajorDim, lStyle); + m_ahRadioButtons = new WXHWND[nNum]; m_pnRadioWidth = new int[nNum]; m_pnRadioHeight = new int[nNum]; @@ -328,41 +195,42 @@ bool wxRadioBox::Create( 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(); - if (i == 0 && lStyle == 0) - lStyleBtn |= WS_GROUP; - - HWND hWndBtn = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent) - ,WC_BUTTON - ,(PSZ)asChoices[i].c_str() - ,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)m_backgroundColour.GetPixel(); + 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); @@ -374,20 +242,19 @@ bool wxRadioBox::Create( } // - // 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(*wxSMALL_FONT); fnWndProcRadioBox = (WXFARPROC)::WinSubclassWindow( GetHwnd() ,(PFNWP)wxRadioBoxWndProc ); @@ -398,23 +265,13 @@ bool wxRadioBox::Create( ,sizeof(LONG) ,(PVOID)&lColor ); - ::WinSetPresParam( m_hWnd - ,PP_BORDERDARKCOLOR - ,sizeof(LONG) - ,(PVOID)&lColor - ); - lColor = (LONG)m_backgroundColour.GetPixel(); + 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); @@ -429,7 +286,7 @@ bool wxRadioBox::Create( wxSize wxRadioBox::DoGetBestSize() const { return (GetTotalButtonSize(GetMaxButtonSize())); -} // end of WinGuiBase_CRadioBox::DoGetBestSize +} // end of wxRadioBox::DoGetBestSize void wxRadioBox::DoSetSize( int nX @@ -439,19 +296,17 @@ void wxRadioBox::DoSetSize( , int nSizeFlags ) { + // + // Input parameters assume wxWidgets coordinate system + // 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; -#endif int nCx1; int nCy1; wxSize vMaxSize = GetMaxButtonSize(); @@ -518,22 +373,19 @@ void wxRadioBox::DoSetSize( nHeight = nHeightOld; } + // + // Now convert to OS/2 coordinate system + // wxWindowOS2* pParent = (wxWindowOS2*)GetParent(); - if (pParent) - { - int nOS2Height = GetOS2ParentHeight(pParent); - - nYy = nOS2Height - (nYy + nHeight); - nYOffset = nYy + nHeight; - } + nYy = GetOS2ParentHeight(pParent) - nYy - nHeight; else { RECTL vRect; - ::WinQueryWindowRect(HWND_DESKTOP, &vRect); - nYy = vRect.yTop - (nYy + nHeight); + nYy = vRect.yTop - nYy - nHeight; } + nYOffset = nYy + nHeight; ::WinSetWindowPos( GetHwnd() ,HWND_TOP ,(LONG)nXx @@ -578,24 +430,23 @@ 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) { - // // Start of new column // @@ -634,10 +485,10 @@ 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 - // radiobox part not beinting to any radiobutton) + // radiobox part not belonging to any radiobutton) // ::WinSetWindowPos( (HWND)m_ahRadioButtons[i] - ,HWND_TOP + ,HWND_BOTTOM ,(LONG)nXOffset ,(LONG)nYOffset ,(LONG)nWidthBtn @@ -686,11 +537,6 @@ bool wxRadioBox::Enable( return true; } // end of wxRadioBox::Enable -int wxRadioBox::GetColumnCount() const -{ - return GetNumHor(); -} // end of wxRadioBox::GetColumnCount - int wxRadioBox::GetCount() const { return m_nNoItems; @@ -742,95 +588,15 @@ wxSize wxRadioBox::GetMaxButtonSize() const 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* WXUNUSED(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 -void wxRadioBox::GetSize( - int* pnWidth -, int* pnHeight -) const +void wxRadioBox::GetSize( int* pnWidth, int* pnHeight ) const { RECT vRect; - int i; vRect.xLeft = -1; vRect.xRight = -1; @@ -842,7 +608,7 @@ void wxRadioBox::GetSize( ,&vRect ); - for (i = 0; i < m_nNoItems; i++) + for (int i = 0; i < m_nNoItems; i++) wxFindMaxSize( m_ahRadioButtons[i] ,&vRect ); @@ -858,6 +624,7 @@ wxString wxRadioBox::GetString( int nNum ) const { + wxCHECK_MSG( IsValid(nNum), wxString(""), wxT("invalid radiobox index") ); return wxGetWindowText(m_ahRadioButtons[nNum]); } // end of wxRadioBox::GetString @@ -876,26 +643,27 @@ wxSize wxRadioBox::GetTotalButtonSize( const wxSize& rSizeBtn ) const { int nCx1; int nCy1; - int nExtraHeight; int nHeight; int nWidth; - int nWidthLabel; - wxFont vFont = GetFont(); + 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; @@ -936,7 +704,6 @@ bool wxRadioBox::OS2Command( WXUINT uCmd, if (wId == GetId()) return true; - for (int i = 0; i < m_nNoItems; i++) { if (wId == wxGetWindowId(m_ahRadioButtons[i])) @@ -1128,11 +895,11 @@ MRESULT wxRadioBtnWndProc( switch(uVk) { case VK_LEFT: - eDir = wxDOWN; + eDir = wxLEFT; break; case VK_RIGHT: - eDir = wxDOWN; + eDir = wxRIGHT; break; case VK_DOWN: @@ -1184,17 +951,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