#include <commctrl.h>
#endif
+#define USE_DEFERRED_SIZING 1
+
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// TBS_HORZ, TBS_RIGHT and TBS_BOTTOM are 0 but do include them for clarity
msStyle |= style & wxSL_VERTICAL ? TBS_VERT : TBS_HORZ;
- if ( style & wxSL_LEFT )
- msStyle |= TBS_LEFT;
- else if ( style & wxSL_RIGHT )
- msStyle |= TBS_RIGHT;
- else if ( style & wxSL_TOP )
- msStyle |= TBS_TOP;
- else if ( style & wxSL_BOTTOM )
- msStyle |= TBS_BOTTOM;
-
if ( style & wxSL_BOTH )
+ {
+ // this fully specifies the style combined with TBS_VERT/HORZ above
msStyle |= TBS_BOTH;
+ }
+ else // choose one direction
+ {
+ if ( style & wxSL_LEFT )
+ msStyle |= TBS_LEFT;
+ else if ( style & wxSL_RIGHT )
+ msStyle |= TBS_RIGHT;
+ else if ( style & wxSL_TOP )
+ msStyle |= TBS_TOP;
+ else if ( style & wxSL_BOTTOM )
+ msStyle |= TBS_BOTTOM;
+ }
if ( style & wxSL_AUTOTICKS )
msStyle |= TBS_AUTOTICKS;
return;
}
+ // if our parent had prepared a defer window handle for us, use it (unless
+ // we are a top level window)
+ wxWindowMSW *parent = GetParent();
+
+#if USE_DEFERRED_SIZING
+ HDWP hdwp = parent && !IsTopLevel() ? (HDWP)parent->m_hDWP : NULL;
+#else
+ HDWP hdwp = 0;
+#endif
+
// be careful to position the slider itself after moving the labels as
// otherwise our GetBoundingBox(), which is called from WM_SIZE handler,
// would return a wrong result and wrong size would be cached internally
// position all labels: min at the top, value in the middle and max at
// the bottom
- ::MoveWindow((*m_labels)[SliderLabel_Min],
- xLabel, y, wLabel, hLabel, TRUE);
+ wxMoveWindowDeferred(hdwp, this, (*m_labels)[SliderLabel_Min],
+ xLabel, y, wLabel, hLabel);
- ::MoveWindow((*m_labels)[SliderLabel_Value],
- xLabel, y + (height - hLabel)/2, wLabel, hLabel, TRUE);
+ wxMoveWindowDeferred(hdwp, this, (*m_labels)[SliderLabel_Value],
+ xLabel, y + (height - hLabel)/2, wLabel, hLabel);
- ::MoveWindow((*m_labels)[SliderLabel_Max],
- xLabel, y + height - hLabel, wLabel, hLabel, TRUE);
+ wxMoveWindowDeferred(hdwp, this, (*m_labels)[SliderLabel_Max],
+ xLabel, y + height - hLabel, wLabel, hLabel);
// position the slider itself along the left/right edge
- ::MoveWindow(GetHwnd(),
+ wxMoveWindowDeferred(hdwp, this, GetHwnd(),
HasFlag(wxSL_LEFT) ? x : x + wLabel + HGAP,
y + hLabel/2,
width - wLabel - HGAP,
- height - hLabel,
- TRUE);
+ height - hLabel);
}
else // horizontal
{
// position all labels: min on the left, value in the middle and max to
// the right
- ::MoveWindow((*m_labels)[SliderLabel_Min],
- x, yLabel, wLabel, hLabel, TRUE);
+ wxMoveWindowDeferred(hdwp, this, (*m_labels)[SliderLabel_Min],
+ x, yLabel, wLabel, hLabel);
- ::MoveWindow((*m_labels)[SliderLabel_Value],
- x + (width - wLabel)/2, yLabel, wLabel, hLabel, TRUE);
+ wxMoveWindowDeferred(hdwp, this, (*m_labels)[SliderLabel_Value],
+ x + (width - wLabel)/2, yLabel, wLabel, hLabel);
- ::MoveWindow((*m_labels)[SliderLabel_Max],
- x + width - wLabel, yLabel, wLabel, hLabel, TRUE);
+ wxMoveWindowDeferred(hdwp, this, (*m_labels)[SliderLabel_Max],
+ x + width - wLabel, yLabel, wLabel, hLabel);
// position the slider itself along the top/bottom edge
- ::MoveWindow(GetHwnd(),
+ wxMoveWindowDeferred(hdwp, this, GetHwnd(),
x,
HasFlag(wxSL_TOP) ? y : y + hLabel,
width,
- height - hLabel,
- TRUE);
+ height - hLabel);
}
+
+#if USE_DEFERRED_SIZING
+ if ( parent )
+ {
+ // hdwp must be updated as it may have been changed
+ parent->m_hDWP = (WXHANDLE)hdwp;
+ }
+#endif
}
wxSize wxSlider::DoGetBestSize() const
{
// these values are arbitrary
static const int length = 100;
- static const int thickness = 26;
+ static const int thumb = 24;
+ static const int ticks = 8;
+ int *width;
wxSize size;
if ( HasFlag(wxSL_VERTICAL) )
{
- size.x = thickness;
+ size.x = thumb;
size.y = length;
+ width = &size.x;
if ( m_labels )
{
else // horizontal
{
size.x = length;
- size.y = thickness;
+ size.y = thumb;
+ width = &size.y;
if ( m_labels )
{
}
}
+ // need extra space to show ticks
+ if ( HasFlag(wxSL_TICKS) )
+ {
+ *width += ticks;
+
+ // and maybe twice as much if we show them on both sides
+ if ( HasFlag(wxSL_BOTH) )
+ *width += ticks;
+ }
+
return size;
}