X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f607434a0f14d78d05e011f98fae56648cfde0c9..e09080ec62ad4a03d9efe7ef17bd225266fd4b81:/src/msw/radiobut.cpp diff --git a/src/msw/radiobut.cpp b/src/msw/radiobut.cpp index f63eed1028..dddab3e26a 100644 --- a/src/msw/radiobut.cpp +++ b/src/msw/radiobut.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: msw/radiobut.cpp +// Name: src/msw/radiobut.cpp // Purpose: wxRadioButton // Author: Julian Smart // Modified by: @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "radiobut.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -30,8 +26,9 @@ #if wxUSE_RADIOBTN +#include "wx/radiobut.h" + #ifndef WX_PRECOMP - #include "wx/radiobut.h" #include "wx/settings.h" #include "wx/dcscreen.h" #endif @@ -59,21 +56,21 @@ wxBEGIN_FLAGS( wxRadioButtonStyle ) wxFLAGS_MEMBER(wxBORDER_RAISED) wxFLAGS_MEMBER(wxBORDER_STATIC) wxFLAGS_MEMBER(wxBORDER_NONE) - + // old style border flags wxFLAGS_MEMBER(wxSIMPLE_BORDER) wxFLAGS_MEMBER(wxSUNKEN_BORDER) wxFLAGS_MEMBER(wxDOUBLE_BORDER) wxFLAGS_MEMBER(wxRAISED_BORDER) wxFLAGS_MEMBER(wxSTATIC_BORDER) - wxFLAGS_MEMBER(wxNO_BORDER) + wxFLAGS_MEMBER(wxBORDER) // standard window styles wxFLAGS_MEMBER(wxTAB_TRAVERSAL) wxFLAGS_MEMBER(wxCLIP_CHILDREN) wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) wxFLAGS_MEMBER(wxWANTS_CHARS) - wxFLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE) + wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) wxFLAGS_MEMBER(wxVSCROLL) wxFLAGS_MEMBER(wxHSCROLL) @@ -86,16 +83,16 @@ IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioButton, wxControl,"wx/radiobut.h") wxBEGIN_PROPERTIES_TABLE(wxRadioButton) wxEVENT_PROPERTY( Click , wxEVT_COMMAND_RADIOBUTTON_SELECTED , wxCommandEvent ) - wxPROPERTY( Font , wxFont , SetFont , GetFont , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) - wxPROPERTY( Value ,bool, SetValue, GetValue,, 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) - wxPROPERTY_FLAGS( WindowStyle , wxRadioButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style + wxPROPERTY( Value ,bool, SetValue, GetValue, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) + wxPROPERTY_FLAGS( WindowStyle , wxRadioButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style wxEND_PROPERTIES_TABLE() wxBEGIN_HANDLERS_TABLE(wxRadioButton) wxEND_HANDLERS_TABLE() -wxCONSTRUCTOR_6( wxRadioButton , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle ) +wxCONSTRUCTOR_6( wxRadioButton , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle ) #else IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) @@ -138,6 +135,8 @@ bool wxRadioButton::Create(wxWindow *parent, if ( HasFlag(wxCLIP_SIBLINGS) ) msStyle |= WS_CLIPSIBLINGS; + if ( HasFlag(wxALIGN_RIGHT) ) + msStyle |= BS_LEFTTEXT | BS_RIGHT; if ( !MSWCreateControl(_T("BUTTON"), msStyle, pos, size, label, 0) ) return false; @@ -158,9 +157,7 @@ bool wxRadioButton::Create(wxWindow *parent, void wxRadioButton::SetValue(bool value) { - // BST_CHECKED is defined as 1, BST_UNCHECKED as 0, so we can just pass - // value as is (we don't use BST_XXX here as they're not defined for Win16) - (void)::SendMessage(GetHwnd(), BM_SETCHECK, (WPARAM)value, 0L); + (void)::SendMessage(GetHwnd(), BM_SETCHECK, (value?BST_CHECKED:BST_UNCHECKED), 0L); m_isChecked = value; @@ -168,6 +165,12 @@ void wxRadioButton::SetValue(bool value) // buttons in the same group: Windows doesn't do it automatically if ( m_isChecked ) { + // If another radiobutton in the group currently has the focus, we have to + // set it to this radiobutton, else the old readiobutton will be reselected + // automatically, if a parent window loses the focus and regains it. + bool shouldSetFocus = false; + wxWindow* pFocusWnd = FindFocus(); + const wxWindowList& siblings = GetParent()->GetChildren(); wxWindowList::compatibility_iterator nodeThis = siblings.Find(this); wxCHECK_RET( nodeThis, _T("radio button not a child of its parent?") ); @@ -182,20 +185,25 @@ void wxRadioButton::SetValue(bool value) { wxRadioButton *btn = wxDynamicCast(nodeBefore->GetData(), wxRadioButton); - if ( !btn ) + if ( btn && btn->HasFlag(wxRB_SINGLE) ) { - // the radio buttons in a group must be consecutive, so - // there are no more of them + // A wxRB_SINGLE button isn't part of this group break; } - btn->SetValue(false); - - if ( btn->HasFlag(wxRB_GROUP) ) + if (btn) { - // even if there are other radio buttons before this one, - // they're not in the same group with us - break; + if (btn == pFocusWnd) + shouldSetFocus = true; + + btn->SetValue(false); + + if ( btn->HasFlag(wxRB_GROUP) ) + { + // even if there are other radio buttons before this one, + // they're not in the same group with us + break; + } } } } @@ -208,14 +216,22 @@ void wxRadioButton::SetValue(bool value) wxRadioButton *btn = wxDynamicCast(nodeAfter->GetData(), wxRadioButton); - if ( !btn || btn->HasFlag(wxRB_GROUP) ) + if ( btn && (btn->HasFlag(wxRB_GROUP) || btn->HasFlag(wxRB_SINGLE) ) ) { // no more buttons or the first button of the next group break; } - btn->SetValue(false); + if (btn) + { + if (btn == pFocusWnd) + shouldSetFocus = true; + + btn->SetValue(false); + } } + if (shouldSetFocus) + SetFocus(); } } @@ -234,7 +250,7 @@ bool wxRadioButton::GetValue() const void wxRadioButton::Command (wxCommandEvent& event) { - SetValue(event.m_commandInt != 0); + SetValue(event.GetInt() != 0); ProcessCommand(event); } @@ -281,7 +297,7 @@ wxSize wxRadioButton::DoGetBestSize() const int wRadio, hRadio; if ( !str.empty() ) { - GetTextExtent(str, &wRadio, &hRadio); + GetTextExtent(GetLabelText(str), &wRadio, &hRadio); wRadio += s_radioSize + GetCharWidth(); if ( hRadio < s_radioSize ) @@ -293,8 +309,19 @@ wxSize wxRadioButton::DoGetBestSize() const hRadio = s_radioSize; } - return wxSize(wRadio, hRadio); + wxSize best(wRadio, hRadio); + CacheBestSize(best); + return best; } -#endif // wxUSE_RADIOBTN +WXDWORD wxRadioButton::MSWGetStyle(long style, WXDWORD *exstyle) const +{ + WXDWORD styleMSW = wxControl::MSWGetStyle(style, exstyle); + + if ( style & wxRB_GROUP ) + styleMSW |= WS_GROUP; + return styleMSW; +} + +#endif // wxUSE_RADIOBTN