Improve wxRadioBox width on wxMSW

Do not use 'RADIO_SIZE 20' as the fixed width of the radio button, but use the actual width as returned by wxRendererNative.
wxRendererNative has no GetRadioButtonSize, so for now use GetCheckBoxSize. It returns the same sizes.
Also add a half character width to account for the space between the button and the label.
There is no need to add extra width to the label of the static box.

Closes #18010.
This commit is contained in:
Maarten Bent
2017-12-10 18:15:41 +01:00
parent 198adec748
commit febd929f0f
2 changed files with 11 additions and 4 deletions

View File

@@ -100,7 +100,6 @@ WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
#define CHECK_IS_FAFA FALSE #define CHECK_IS_FAFA FALSE
#define RADIO_CLASS wxT("BUTTON") #define RADIO_CLASS wxT("BUTTON")
#define RADIO_FLAGS (BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE) #define RADIO_FLAGS (BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE)
#define RADIO_SIZE 20
#define RADIO_IS_FAFA FALSE #define RADIO_IS_FAFA FALSE
#define PURE_WINDOWS #define PURE_WINDOWS
#define GROUP_CLASS wxT("BUTTON") #define GROUP_CLASS wxT("BUTTON")

View File

@@ -36,6 +36,7 @@
#endif #endif
#include "wx/msw/subwin.h" #include "wx/msw/subwin.h"
#include "wx/renderer.h"
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
#include "wx/tooltip.h" #include "wx/tooltip.h"
@@ -549,6 +550,15 @@ WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons)
wxSize wxRadioBox::GetMaxButtonSize() const wxSize wxRadioBox::GetMaxButtonSize() const
{ {
// We use GetCheckBox() because there is no dedicated GetRadioBox() method
// in wxRendererNative, but check and radio boxes are usually of the same
// size anyhow. We also add half a character of width to account for the
// extra space after the radio box itself.
const int radioWidth =
wxRendererNative::Get().GetCheckBoxSize(
reinterpret_cast<wxWindow*>(const_cast<wxRadioBox*>(this))).x
+ GetCharWidth() / 2;
// calculate the max button size // calculate the max button size
int widthMax = 0, int widthMax = 0,
heightMax = 0; heightMax = 0;
@@ -561,8 +571,7 @@ wxSize wxRadioBox::GetMaxButtonSize() const
GetTextExtent(wxGetWindowText((*m_radioButtons)[i]), &width, &height); GetTextExtent(wxGetWindowText((*m_radioButtons)[i]), &width, &height);
// adjust the size to take into account the radio box itself // adjust the size to take into account the radio box itself
// FIXME this is totally bogus! width += radioWidth;
width += RADIO_SIZE;
height *= 3; height *= 3;
height /= 2; height /= 2;
} }
@@ -599,7 +608,6 @@ wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
// and also wide enough for its label // and also wide enough for its label
int widthLabel; int widthLabel;
GetTextExtent(GetLabelText(), &widthLabel, NULL); GetTextExtent(GetLabelText(), &widthLabel, NULL);
widthLabel += RADIO_SIZE; // FIXME this is bogus too
if ( widthLabel > width ) if ( widthLabel > width )
width = widthLabel; width = widthLabel;