wxSize wxSlider::DoGetBestSize() const { // this value is arbitrary: static const int length = 100; int *width; wxSize size; if ( HasFlag(wxSL_VERTICAL) ) { size.x = THUMB; size.y = length; width = &size.x; if ( m_labels ) { int widthMin, widthMax; int hLabel = GetLabelsSize(&widthMin, &widthMax); // account for the labels if ( HasFlag(wxSL_MIN_MAX_LABELS) ) size.x += HGAP + wxMax(widthMin, widthMax); // labels are indented relative to the slider itself size.y += hLabel; } } else // horizontal { size.x = length; size.y = THUMB; width = &size.y; if ( m_labels ) { int labelSize = GetLabelsSize(); // Min/max labels are compensated by the ticks so we don't need // extra space for them if we're also showing ticks. if ( HasFlag(wxSL_MIN_MAX_LABELS) && !HasFlag(wxSL_TICKS) ) size.y += labelSize; // The value label is always on top of the control and so does need // extra space in any case. if ( HasFlag(wxSL_VALUE_LABEL) ) size.y += labelSize; } } // need extra space to show ticks if ( HasFlag(wxSL_TICKS) ) { *width += TICK; // and maybe twice as much if we show them on both sides if ( HasFlag(wxSL_BOTH) ) *width += TICK; } return size; }
void wxSlider::DoMoveWindow(int x, int y, int width, int height) { // all complications below are because we need to position the labels, // without them everything is easy if ( !m_labels ) { wxSliderBase::DoMoveWindow(x, y, width, height); return; } int minLabelWidth, maxLabelWidth; const int labelHeight = GetLabelsSize(&minLabelWidth, &maxLabelWidth); const int longestLabelWidth = wxMax(minLabelWidth, maxLabelWidth); if ( !HasFlag(wxSL_MIN_MAX_LABELS) ) { minLabelWidth = maxLabelWidth = 0; } int tickOffset = 0; if ( HasFlag(wxSL_TICKS)) tickOffset = TICK; if ( HasFlag(wxSL_BOTH)) tickOffset *= 2; // 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 if ( HasFlag(wxSL_VERTICAL) ) { int labelOffset = 0; int holdTopX; int holdBottomX; int xLabel = (wxMax((THUMB + (BORDERPAD * 2)), longestLabelWidth) / 2) - (longestLabelWidth / 2) + x; if ( HasFlag(wxSL_LEFT) ) { holdTopX = xLabel; holdBottomX = xLabel - (abs(maxLabelWidth - minLabelWidth) / 2); } else // wxSL_RIGHT { holdTopX = xLabel + longestLabelWidth + (abs(maxLabelWidth - minLabelWidth) / 2); holdBottomX = xLabel + longestLabelWidth; labelOffset = longestLabelWidth + HGAP; } if ( HasFlag(wxSL_MIN_MAX_LABELS) ) { if ( HasFlag(wxSL_INVERSE) ) { wxSwap(holdTopX, holdBottomX); } DoMoveSibling((HWND)(*m_labels)[SliderLabel_Min], holdTopX, y, minLabelWidth, labelHeight); DoMoveSibling((HWND)(*m_labels)[SliderLabel_Max], holdBottomX, y + height - labelHeight, maxLabelWidth, labelHeight); } if ( HasFlag(wxSL_VALUE_LABEL) ) { DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value], x + ( HasFlag(wxSL_LEFT) ? THUMB + tickOffset + HGAP : 0 ), y + (height - labelHeight)/2, longestLabelWidth, labelHeight); } // position the slider itself along the left/right edge wxSliderBase::DoMoveWindow( x + labelOffset, y + labelHeight, THUMB + tickOffset + HGAP, height - (labelHeight * 2)); } else // horizontal { int yLabelMinMax = (y + ((THUMB + tickOffset) / 2)) - (labelHeight / 2); int xLabelValue = x + minLabelWidth + ((width - (minLabelWidth + maxLabelWidth)) / 2) - (longestLabelWidth / 2); int ySlider = y; if ( HasFlag(wxSL_VALUE_LABEL) ) { DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value], xLabelValue, y + (HasFlag(wxSL_BOTTOM) ? 0 : THUMB + tickOffset), longestLabelWidth, labelHeight); if ( HasFlag(wxSL_BOTTOM) ) { ySlider += labelHeight; yLabelMinMax += labelHeight; } } if ( HasFlag(wxSL_MIN_MAX_LABELS) ) { DoMoveSibling((HWND)(*m_labels)[SliderLabel_Min], x, yLabelMinMax, minLabelWidth, labelHeight); DoMoveSibling((HWND)(*m_labels)[SliderLabel_Max], x + width - maxLabelWidth, yLabelMinMax, maxLabelWidth, labelHeight); } // position the slider itself along the top/bottom edge wxSliderBase::DoMoveWindow( x + minLabelWidth + VGAP, ySlider, width - (minLabelWidth + maxLabelWidth + (VGAP*2)), THUMB + tickOffset); } }