From 16e79d48793b5be3cd7b98c12663de336f064dcf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 11 Jul 2011 22:49:33 +0000 Subject: [PATCH] Fix showing slider label in wxMSW when wxSL_MIN_MAX_LABELS was not used. wxSlider with wxSL_LABELS style but without wxSL_MIN_MAX_LABELS didn't show the current value because the width of the value label was 0. Fix this by always computing the widths of min and max labels and using the longest of them for the value label, even if we don't actually show them. Closes #13291. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68230 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/slider.h | 4 ++++ src/msw/slider.cpp | 20 +++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/wx/msw/slider.h b/include/wx/msw/slider.h index d6c2400cd3..23de38a607 100644 --- a/include/wx/msw/slider.h +++ b/include/wx/msw/slider.h @@ -106,6 +106,10 @@ protected: wxRect GetBoundingBox() const; // Get the height and, if the pointers are non NULL, widths of both labels. + // + // Notice that the return value will be 0 if we don't have wxSL_LABELS + // style but we do fill widthMin and widthMax even if we don't have + // wxSL_MIN_MAX_LABELS style set so the caller should account for it. int GetLabelsSize(int *widthMin = NULL, int *widthMax = NULL) const; diff --git a/src/msw/slider.cpp b/src/msw/slider.cpp index b2df912ba1..f7aefdd599 100644 --- a/src/msw/slider.cpp +++ b/src/msw/slider.cpp @@ -369,16 +369,8 @@ int wxSlider::GetLabelsSize(int *widthMin, int *widthMax) const { if ( widthMin && widthMax ) { - if ( HasFlag(wxSL_MIN_MAX_LABELS) ) - { - *widthMin = GetTextExtent(Format(m_rangeMin)).x; - *widthMax = GetTextExtent(Format(m_rangeMax)).x; - } - else - { - *widthMin = - *widthMax = 0; - } + *widthMin = GetTextExtent(Format(m_rangeMin)).x; + *widthMax = GetTextExtent(Format(m_rangeMax)).x; } return HasFlag(wxSL_LABELS) ? GetCharHeight() : 0; @@ -398,6 +390,11 @@ void wxSlider::DoMoveWindow(int x, int y, int width, int height) maxLabelWidth; const int labelHeight = GetLabelsSize(&minLabelWidth, &maxLabelWidth); const int longestLabelWidth = wxMax(minLabelWidth, maxLabelWidth); + if ( !HasFlag(wxSL_MIN_MAX_LABELS) ) + { + minLabelWidth = + maxLabelWidth = 0; + } int labelOffset = 0; int tickOffset = 0; @@ -594,7 +591,8 @@ wxSize wxSlider::DoGetBestSize() const int hLabel = GetLabelsSize(&widthMin, &widthMax); // account for the labels - size.x += HGAP + wxMax(widthMin, widthMax); + if ( HasFlag(wxSL_MIN_MAX_LABELS) ) + size.x += HGAP + wxMax(widthMin, widthMax); // labels are indented relative to the slider itself size.y += hLabel; -- 2.45.2