From 687823a157c6bbec7e6911afef361c5283dd960b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin <vadim@wxwidgets.org> Date: Sun, 23 Sep 2012 22:47:52 +0000 Subject: [PATCH] Respect styles translated to WS_EX_XXX in wxMSW wxCheckBox and wxRadioButton. Take into account the window styles that translate to extended Windows styles at MSW level. Also override MSWGetStyle() in these classes, just as in most (all?) other ones, for consistency instead of doing wx-to-MSW styles translation directly in Create(). Notice that as a side effect of this change, border styles now work for wxCheckBox which wasn't the case before. It's not clear if this is really wanted but OTOH there doesn't seem to be any real reason to forbid them neither. Closes #14674. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72538 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/checkbox.h | 3 +++ src/msw/checkbox.cpp | 17 +++++++++++---- src/msw/radiobut.cpp | 44 +++++++++++++++++++-------------------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/include/wx/msw/checkbox.h b/include/wx/msw/checkbox.h index f00fe9cfe3..bdb5ae353f 100644 --- a/include/wx/msw/checkbox.h +++ b/include/wx/msw/checkbox.h @@ -55,6 +55,9 @@ public: // make the checkbox owner drawn or reset it to normal style void MSWMakeOwnerDrawn(bool ownerDrawn); + // implementation only from now on + virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle = NULL) const; + protected: virtual wxSize DoGetBestSize() const; diff --git a/src/msw/checkbox.cpp b/src/msw/checkbox.cpp index 85a52a49cc..82433cd966 100644 --- a/src/msw/checkbox.cpp +++ b/src/msw/checkbox.cpp @@ -104,7 +104,18 @@ bool wxCheckBox::Create(wxWindow *parent, if ( !CreateControl(parent, id, pos, size, style, validator, name) ) return false; - long msStyle = WS_TABSTOP; + WXDWORD exstyle; + WXDWORD msStyle = MSWGetStyle(style, &exstyle); + + msStyle |= wxMSWButton::GetMultilineStyle(label); + + return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, exstyle); +} + +WXDWORD wxCheckBox::MSWGetStyle(long style, WXDWORD *exstyle) const +{ + // buttons never have an external border, they draw their own one + WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); if ( style & wxCHK_3STATE ) msStyle |= BS_3STATE; @@ -116,9 +127,7 @@ bool wxCheckBox::Create(wxWindow *parent, msStyle |= BS_LEFTTEXT | BS_RIGHT; } - msStyle |= wxMSWButton::GetMultilineStyle(label); - - return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, 0); + return msStyle; } // ---------------------------------------------------------------------------- diff --git a/src/msw/radiobut.cpp b/src/msw/radiobut.cpp index bc0fa69092..6c8ed13480 100644 --- a/src/msw/radiobut.cpp +++ b/src/msw/radiobut.cpp @@ -61,25 +61,10 @@ bool wxRadioButton::Create(wxWindow *parent, if ( !CreateControl(parent, id, pos, size, style, validator, name) ) return false; - long msStyle = WS_TABSTOP; - if ( HasFlag(wxRB_GROUP) ) - msStyle |= WS_GROUP; + WXDWORD exstyle = 0; + WXDWORD msStyle = MSWGetStyle(style, &exstyle); - // we use BS_RADIOBUTTON and not BS_AUTORADIOBUTTON because the use of the - // latter can easily result in the application entering an infinite loop - // inside IsDialogMessage() - // - // we used to use BS_RADIOBUTTON only for wxRB_SINGLE buttons but there - // doesn't seem to be any harm to always use it and it prevents some hangs, - // see #9786 - msStyle |= BS_RADIOBUTTON; - - if ( HasFlag(wxCLIP_SIBLINGS) ) - msStyle |= WS_CLIPSIBLINGS; - if ( HasFlag(wxALIGN_RIGHT) ) - msStyle |= BS_LEFTTEXT | BS_RIGHT; - - if ( !MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, 0) ) + if ( !MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, exstyle) ) return false; // for compatibility with wxGTK, the first radio button in a group is @@ -289,12 +274,27 @@ wxSize wxRadioButton::DoGetBestSize() const WXDWORD wxRadioButton::MSWGetStyle(long style, WXDWORD *exstyle) const { - WXDWORD styleMSW = wxControl::MSWGetStyle(style, exstyle); + WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); + + if ( HasFlag(wxRB_GROUP) ) + msStyle |= WS_GROUP; + + // we use BS_RADIOBUTTON and not BS_AUTORADIOBUTTON because the use of the + // latter can easily result in the application entering an infinite loop + // inside IsDialogMessage() + // + // we used to use BS_RADIOBUTTON only for wxRB_SINGLE buttons but there + // doesn't seem to be any harm to always use it and it prevents some hangs, + // see #9786 + msStyle |= BS_RADIOBUTTON; + + if ( style & wxCLIP_SIBLINGS ) + msStyle |= WS_CLIPSIBLINGS; + if ( style & wxALIGN_RIGHT ) + msStyle |= BS_LEFTTEXT | BS_RIGHT; - if ( style & wxRB_GROUP ) - styleMSW |= WS_GROUP; - return styleMSW; + return msStyle; } #endif // wxUSE_RADIOBTN -- 2.47.2