From 8f3b87dce79a5b1a06864b1aa9d43e294becb567 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 31 Jan 2019 20:23:38 +0100 Subject: [PATCH] Fix wxSlider::SetThumbLength() on wxMSW It requires TBS_FIXEDLENGTH style. Call InvalidateBestSize because the size of the control might change. Call Layout in the widgets sample to adjust to the changed size. Use GetThumbLength() instead of the arbitrary defined THUMB size. --- samples/widgets/slider.cpp | 8 ++++++++ src/msw/slider.cpp | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/samples/widgets/slider.cpp b/samples/widgets/slider.cpp index 33edea188d..427e89a6ad 100644 --- a/samples/widgets/slider.cpp +++ b/samples/widgets/slider.cpp @@ -543,6 +543,14 @@ void SliderWidgetsPage::DoSetThumbLen() } m_slider->SetThumbLength(len); + + if ( m_slider->GetThumbLength() != len ) + { + wxLogWarning(wxString::Format("Invalid thumb length in slider: %d", + m_slider->GetThumbLength())); + } + + Layout(); } // ---------------------------------------------------------------------------- diff --git a/src/msw/slider.cpp b/src/msw/slider.cpp index 30eadaf490..558107053f 100644 --- a/src/msw/slider.cpp +++ b/src/msw/slider.cpp @@ -54,8 +54,7 @@ enum // the gaps between the slider and the labels, in pixels const int HGAP = 5; const int VGAP = 4; -// these 2 values are arbitrary: -const int THUMB = 24; +// this value is arbitrary: const int TICK = 8; } // anonymous namespace @@ -194,6 +193,9 @@ WXDWORD wxSlider::MSWGetStyle(long style, WXDWORD *exstyle) const // TBS_HORZ, TBS_RIGHT and TBS_BOTTOM are 0 but do include them for clarity msStyle |= style & wxSL_VERTICAL ? TBS_VERT : TBS_HORZ; + // allow setting thumb size + msStyle |= TBS_FIXEDLENGTH; + if ( style & wxSL_BOTH ) { // this fully specifies the style combined with TBS_VERT/HORZ above @@ -390,7 +392,7 @@ void wxSlider::DoMoveWindow(int x, int y, int width, int height) return; } - const int thumbSize = FromDIP(THUMB); + const int thumbSize = GetThumbLength(); const int tickSize = FromDIP(TICK); int minLabelWidth, @@ -540,7 +542,7 @@ wxSize wxSlider::DoGetBestSize() const { // this value is arbitrary: static const int length = FromDIP(100); - const int thumbSize = FromDIP(THUMB); + const int thumbSize = GetThumbLength(); const int tickSize = FromDIP(TICK); int *width; @@ -732,6 +734,8 @@ void wxSlider::SetSelection(int minPos, int maxPos) void wxSlider::SetThumbLength(int len) { ::SendMessage(GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0); + + InvalidateBestSize(); } int wxSlider::GetThumbLength() const