X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/789f6795165f19cd16f0ba9f799add6a92720454..3c203a185145a1aa720faf53e7f6fbebb35bce7a:/src/msw/radiobox.cpp?ds=sidebyside diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index f4a4178a0e..b5cdc6eeda 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -40,6 +40,11 @@ #include "wx/msw/subwin.h" +// This is switched off because in some situations, the radiobox +// buttons simply don't appear when deferred sizing is on. +// Instead, refreshing on WM_MOVE seems to at least cure the droppings. +#define USE_DEFERRED_SIZING 0 + #if wxUSE_TOOLTIPS #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__) #include @@ -165,9 +170,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 +179,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 +188,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 +211,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 +374,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 +430,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) @@ -496,7 +503,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 +524,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 +557,17 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) height = heightOld; } - ::MoveWindow(GetHwnd(), xx, yy, width, height, TRUE); + // if our parent had prepared a defer window handle for us, use it (unless + // we are a top level window) + +#if USE_DEFERRED_SIZING + wxWindowMSW *parent = GetParent(); + HDWP hdwp = parent && !IsTopLevel() ? (HDWP)parent->m_hDWP : NULL; +#else + HDWP hdwp = 0; +#endif + + wxMoveWindowDeferred(hdwp, this, GetHwnd(), 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 @@ -645,8 +664,76 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) x_offset += widthBtn + cx1; } } + +#if USE_DEFERRED_SIZING + if (parent) + { + // hdwp must be updated as it may have been changed + parent->m_hDWP = (WXHANDLE)hdwp; + } +#endif } +// ---------------------------------------------------------------------------- +// 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) +{ + if ( nMsg == WM_PRINTCLIENT ) + { + // we have to process WM_PRINTCLIENT ourselves as otherwise the radio + // buttons background would never be drawn unless we have a parent with + // non default background + + // so check first if we have one + if ( !HandlePrintClient((WXHDC)wParam) ) + { + // no, we don't, erase the background ourselves (don't use our own + // colour as with static box, see comments there) + wxBrush brush(GetParent()->GetBackgroundColour()); + wxFillRect(GetHwnd(), (HDC)wParam, GetHbrushOf(brush)); + } + + return 0; + } + // 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?) + else 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 +897,8 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd, if ( processed ) return 0; - - break; } + break; #endif // !__WXWINCE__ }