X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bd0a76e228b5ce47c648c2e52857e77cf79e6ae5..0c8b041f147ff9bb6ce38f0e2da1fd82f6484523:/src/msw/radiobox.cpp?ds=sidebyside diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index c6e913c1c2..253c31204d 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -165,9 +165,6 @@ bool wxRadioBox::Create(wxWindow *parent, wxUnusedVar(val); #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS - // and now create the buttons - HWND hwndParent = GetHwndOf(parent); - m_radioButtons = new wxSubwindows(n); m_radioWidth = new int[n]; m_radioHeight = new int[n]; @@ -177,7 +174,7 @@ bool wxRadioBox::Create(wxWindow *parent, m_radioWidth[i] = m_radioHeight[i] = wxDefaultCoord; long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE; - if ( i == 0 && style == 0 ) + if ( i == 0 ) styleBtn |= WS_GROUP; long newId = NewControlId(); @@ -186,7 +183,7 @@ bool wxRadioBox::Create(wxWindow *parent, choices[i], styleBtn, 0, 0, 0, 0, // will be set in SetSize() - hwndParent, + GetHwnd(), (HMENU)newId, wxGetInstance(), NULL); @@ -209,7 +206,7 @@ bool wxRadioBox::Create(wxWindow *parent, (void)::CreateWindow(_T("BUTTON"), wxEmptyString, WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD, - 0, 0, 0, 0, hwndParent, + 0, 0, 0, 0, GetHwnd(), (HMENU)NewControlId(), wxGetInstance(), NULL); m_radioButtons->SetFont(GetFont()); @@ -315,7 +312,7 @@ bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id) void wxRadioBox::Command(wxCommandEvent & event) { - SetSelection (event.m_commandInt); + SetSelection (event.GetInt()); SetFocus(); ProcessCommand(event); } @@ -366,7 +363,7 @@ int wxRadioBox::GetNumHor() const void wxRadioBox::SetString(int item, const wxString& label) { - wxCHECK_RET( item >= 0 && item < GetCount(), wxT("invalid radiobox index") ); + wxCHECK_RET( IsValid(item), wxT("invalid radiobox index") ); m_radioWidth[item] = m_radioHeight[item] = wxDefaultCoord; @@ -376,8 +373,13 @@ void wxRadioBox::SetString(int item, const wxString& label) void wxRadioBox::SetSelection(int N) { - wxCHECK_RET( (N >= 0) && (N < GetCount()), wxT("invalid radiobox index") ); + wxCHECK_RET( IsValid(N), wxT("invalid radiobox index") ); + + // unselect the old button + if ( m_selectedButton != wxNOT_FOUND ) + ::SendMessage((*m_radioButtons)[m_selectedButton], BM_SETCHECK, 0, 0L); + // and select the new one ::SendMessage((*m_radioButtons)[N], BM_SETCHECK, 1, 0L); m_selectedButton = N; @@ -386,7 +388,7 @@ void wxRadioBox::SetSelection(int N) // Find string for position wxString wxRadioBox::GetString(int item) const { - wxCHECK_MSG( item >= 0 && item < GetCount(), wxEmptyString, + wxCHECK_MSG( IsValid(item), wxEmptyString, wxT("invalid radiobox index") ); return wxGetWindowText((*m_radioButtons)[item]); @@ -403,21 +405,25 @@ void wxRadioBox::SetFocus() } // Enable a specific button -void wxRadioBox::Enable(int item, bool enable) +bool wxRadioBox::Enable(int item, bool enable) { - wxCHECK_RET( item >= 0 && item < GetCount(), + wxCHECK_MSG( IsValid(item), false, wxT("invalid item in wxRadioBox::Enable()") ); - ::EnableWindow((*m_radioButtons)[item], enable); + BOOL ret = ::EnableWindow((*m_radioButtons)[item], enable); + + return (ret == 0) == enable; } // Show a specific button -void wxRadioBox::Show(int item, bool show) +bool wxRadioBox::Show(int item, bool show) { - wxCHECK_RET( item >= 0 && item < GetCount(), + wxCHECK_MSG( IsValid(item), false, wxT("invalid item in wxRadioBox::Show()") ); - ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE); + BOOL ret = ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE); + + return (ret != 0) == show; } WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons) @@ -472,7 +478,7 @@ wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const int width = GetNumHor() * (sizeBtn.x + cx1) + cx1; // Add extra space under the label, if it exists. - if (!wxControl::GetLabel().IsEmpty()) + if (!wxControl::GetLabel().empty()) height += cy1/2; // and also wide enough for its label @@ -506,8 +512,8 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) yy = currentY; - int y_offset = yy; - int x_offset = xx; + int y_offset = 0; + int x_offset = 0; int cx1, cy1; wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont()); @@ -556,7 +562,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) y_offset += cy1; // Add extra space under the label, if it exists. - if (!wxControl::GetLabel().IsEmpty()) + if (!wxControl::GetLabel().empty()) y_offset += cy1/2; int startX = x_offset; @@ -810,5 +816,51 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd, return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, message, wParam, lParam); } +WXHRGN wxRadioBox::MSWGetRegionWithoutChildren() +{ + RECT rc; + ::GetWindowRect(GetHwnd(), &rc); + HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1); + + const size_t count = GetCount(); + for ( size_t i = 0; i < count; ++i ) + { + ::GetWindowRect((*m_radioButtons)[i], &rc); + AutoHRGN hrgnchild(::CreateRectRgnIndirect(&rc)); + ::CombineRgn(hrgn, hrgn, hrgnchild, RGN_DIFF); + } + + return (WXHRGN)hrgn; +} + +WXLRESULT wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) +{ +#ifndef __WXWINCE__ + if ( nMsg == WM_PRINTCLIENT ) + { + // first check to see if a parent window knows how to paint us better + for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) + if ( win->MSWPrintChild(this, wParam, lParam) ) + return true; + + // nope, so lets do it ourselves + RECT rc; + WXHBRUSH hbr = DoMSWControlColor((HDC)wParam, wxNullColour); + if ( !hbr ) + { + wxBrush *brush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); + hbr = (WXHBRUSH)brush->GetResourceHandle(); + } + + ::GetClientRect(GetHwnd(), &rc); + ::FillRect((HDC)wParam, &rc, (HBRUSH)hbr); + + return true; + } +#endif + // __WXWINCE__ + + return wxStaticBox::MSWWindowProc(nMsg, wParam, lParam); +} #endif // wxUSE_RADIOBOX