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.
This commit is contained in:
@@ -543,6 +543,14 @@ void SliderWidgetsPage::DoSetThumbLen()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_slider->SetThumbLength(len);
|
m_slider->SetThumbLength(len);
|
||||||
|
|
||||||
|
if ( m_slider->GetThumbLength() != len )
|
||||||
|
{
|
||||||
|
wxLogWarning(wxString::Format("Invalid thumb length in slider: %d",
|
||||||
|
m_slider->GetThumbLength()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -54,8 +54,7 @@ enum
|
|||||||
// the gaps between the slider and the labels, in pixels
|
// the gaps between the slider and the labels, in pixels
|
||||||
const int HGAP = 5;
|
const int HGAP = 5;
|
||||||
const int VGAP = 4;
|
const int VGAP = 4;
|
||||||
// these 2 values are arbitrary:
|
// this value is arbitrary:
|
||||||
const int THUMB = 24;
|
|
||||||
const int TICK = 8;
|
const int TICK = 8;
|
||||||
|
|
||||||
} // anonymous namespace
|
} // 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
|
// TBS_HORZ, TBS_RIGHT and TBS_BOTTOM are 0 but do include them for clarity
|
||||||
msStyle |= style & wxSL_VERTICAL ? TBS_VERT : TBS_HORZ;
|
msStyle |= style & wxSL_VERTICAL ? TBS_VERT : TBS_HORZ;
|
||||||
|
|
||||||
|
// allow setting thumb size
|
||||||
|
msStyle |= TBS_FIXEDLENGTH;
|
||||||
|
|
||||||
if ( style & wxSL_BOTH )
|
if ( style & wxSL_BOTH )
|
||||||
{
|
{
|
||||||
// this fully specifies the style combined with TBS_VERT/HORZ above
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int thumbSize = FromDIP(THUMB);
|
const int thumbSize = GetThumbLength();
|
||||||
const int tickSize = FromDIP(TICK);
|
const int tickSize = FromDIP(TICK);
|
||||||
|
|
||||||
int minLabelWidth,
|
int minLabelWidth,
|
||||||
@@ -540,7 +542,7 @@ wxSize wxSlider::DoGetBestSize() const
|
|||||||
{
|
{
|
||||||
// this value is arbitrary:
|
// this value is arbitrary:
|
||||||
static const int length = FromDIP(100);
|
static const int length = FromDIP(100);
|
||||||
const int thumbSize = FromDIP(THUMB);
|
const int thumbSize = GetThumbLength();
|
||||||
const int tickSize = FromDIP(TICK);
|
const int tickSize = FromDIP(TICK);
|
||||||
|
|
||||||
int *width;
|
int *width;
|
||||||
@@ -732,6 +734,8 @@ void wxSlider::SetSelection(int minPos, int maxPos)
|
|||||||
void wxSlider::SetThumbLength(int len)
|
void wxSlider::SetThumbLength(int len)
|
||||||
{
|
{
|
||||||
::SendMessage(GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0);
|
::SendMessage(GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0);
|
||||||
|
|
||||||
|
InvalidateBestSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxSlider::GetThumbLength() const
|
int wxSlider::GetThumbLength() const
|
||||||
|
Reference in New Issue
Block a user