X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/789f6795165f19cd16f0ba9f799add6a92720454..75e275af320f70d9bb57dd30494f6cc2c100dc25:/src/msw/radiobox.cpp diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index f4a4178a0e..baeb42a491 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: msw/radiobox.cpp +// Name: src/msw/radiobox.cpp // Purpose: wxRadioBox implementation // Author: Julian Smart // Modified by: @@ -17,10 +17,6 @@ // headers // --------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "radiobox.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -165,9 +161,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 +170,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 +179,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 +202,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()); @@ -372,6 +365,8 @@ void wxRadioBox::SetString(int item, const wxString& label) m_radioHeight[item] = wxDefaultCoord; ::SetWindowText((*m_radioButtons)[item], label.c_str()); + + InvalidateBestSize(); } void wxRadioBox::SetSelection(int N) @@ -426,7 +421,10 @@ bool wxRadioBox::Show(int item, bool show) BOOL ret = ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE); - return (ret != 0) == show; + bool changed = (ret != 0) == show; + if( changed ) + InvalidateBestSize(); + return changed; } WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons) @@ -486,7 +484,7 @@ wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const // and also wide enough for its label int widthLabel; - GetTextExtent(GetTitle(), &widthLabel, NULL); + GetTextExtent(GetLabel(), &widthLabel, NULL); widthLabel += RADIO_SIZE; // FIXME this is bogus too if ( widthLabel > width ) width = widthLabel; @@ -496,7 +494,9 @@ wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const wxSize wxRadioBox::DoGetBestSize() const { - return GetTotalButtonSize(GetMaxButtonSize()); + wxSize best = GetTotalButtonSize(GetMaxButtonSize()); + CacheBestSize(best); + return best; } // Restored old code. @@ -515,8 +515,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()); @@ -548,7 +548,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) height = heightOld; } - ::MoveWindow(GetHwnd(), xx, yy, width, height, TRUE); + DoMoveWindow(xx, yy, width, height); // Now position all the buttons: the current button will be put at // wxPoint(x_offset, y_offset) and the new row/column will start at @@ -647,6 +647,49 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) } } +// ---------------------------------------------------------------------------- +// radio box drawing +// ---------------------------------------------------------------------------- + +#ifndef __WXWINCE__ + +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) +{ + // FIXME: Without this, the radiobox corrupts other controls as it moves + // in a dynamic layout. Refreshing causes flicker, but it's better than + // leaving droppings. Note that for some reason, wxStaticBox doesn't need + // this (perhaps because it has no real children?) + if ( nMsg == WM_MOVE ) + { + WXLRESULT res = wxControl::MSWWindowProc(nMsg, wParam, lParam); + wxRect rect = GetRect(); + GetParent()->Refresh(true, & rect); + return res; + } + + return wxStaticBox::MSWWindowProc(nMsg, wParam, lParam); +} + +#endif // __WXWINCE__ + // --------------------------------------------------------------------------- // window proc for radio buttons // --------------------------------------------------------------------------- @@ -810,9 +853,8 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd, if ( processed ) return 0; - - break; } + break; #endif // !__WXWINCE__ } @@ -820,4 +862,3 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd, } #endif // wxUSE_RADIOBOX -