void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) { int widthBtn = wxSpinButton::DoGetBestSize().x; int widthText = width - widthBtn - MARGIN_BETWEEN; if ( widthText < 0 ) { // This can happen during the initial window layout when it's total // size is too small to accommodate all the controls and usually is not // a problem because the window will be relaid out with enough space // later. Of course, if it isn't and this is our final size, then we // have a real problem but as we don't know if this is going to be the // case or not, just hope for the best -- we used to give a debug // warning here and this was annoying as it could result in dozens of // perfectly harmless warnings. widthText = 0; } // 1) The buddy window DoMoveSibling(m_hwndBuddy, x, y, widthText, height); // 2) The button window if ( widthText > 0 ) x += widthText + MARGIN_BETWEEN; wxSpinButton::DoMoveWindow(x, y, widthBtn, height); }
void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) { int widthBtn = wxSpinButton::DoGetBestSize().x; int widthText = width - widthBtn - MARGIN_BETWEEN; if ( widthText < 0 ) { // This can happen during the initial window layout when it's total // size is too small to accommodate all the controls and usually is not // a problem because the window will be relaid out with enough space // later. Of course, if it isn't and this is our final size, then we // have a real problem but as we don't know if this is going to be the // case or not, just hope for the best -- we used to give a debug // warning here and this was annoying as it could result in dozens of // perfectly harmless warnings. widthText = 0; } // Because both subcontrols are positioned relatively // to the parent which can have different layout direction // then our control, we need to mirror their positions manually. if ( GetParent()->GetLayoutDirection() == GetLayoutDirection() ) { // Logical positions: x(Text) < x(Button) // 1) The buddy window DoMoveSibling(m_hwndBuddy, x, y, widthText, height); // 2) The button window if ( widthText > 0 ) x += widthText + MARGIN_BETWEEN; wxSpinButton::DoMoveWindow(x, y, widthBtn, height); } else { // Logical positions: x(Button) < x(Text) // 1) The button window wxSpinButton::DoMoveWindow(x, y, widthBtn, height); // 2) The buddy window x += widthBtn + MARGIN_BETWEEN; DoMoveSibling(m_hwndBuddy, x, y, widthText, height); } }
void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height) { int widthBtn = wxSpinButton::DoGetBestSize().x; int widthText = width - widthBtn - MARGIN_BETWEEN; if ( widthText <= 0 ) { wxLogDebug(_T("not enough space for wxSpinCtrl!")); } // 1) The buddy window DoMoveSibling(m_hwndBuddy, x, y, widthText, height); // 2) The button window x += widthText + MARGIN_BETWEEN; wxSpinButton::DoMoveWindow(x, y, widthBtn, height); }
void wxRadioBox::PositionAllButtons(int x, int y, int width, int WXUNUSED(height)) { wxSize maxSize = GetMaxButtonSize(); int maxWidth = maxSize.x, maxHeight = maxSize.y; // Now position all the buttons: the current button will be put at // wxPoint(x_offset, y_offset) and the new row/column will start at // startX/startY. The size of all buttons will be the same wxSize(maxWidth, // maxHeight) except for the buttons in the last column which should extend // to the right border of radiobox and thus can be wider than this. // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in // left to right order and GetMajorDim() is the number of columns while // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and // GetMajorDim() is the number of rows. int cx1, cy1; wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont()); int x_offset = x + cx1; int y_offset = y + cy1; // Add extra space under the label, if it exists. if (!wxControl::GetLabel().empty()) y_offset += cy1/2; int startX = x_offset; int startY = y_offset; const unsigned int count = GetCount(); for (unsigned int i = 0; i < count; i++) { // the last button in the row may be wider than the other ones as the // radiobox may be wider than the sum of the button widths (as it // happens, for example, when the radiobox label is very long) bool isLastInTheRow; if ( m_windowStyle & wxRA_SPECIFY_COLS ) { // item is the last in its row if it is a multiple of the number of // columns or if it is just the last item unsigned int n = i + 1; isLastInTheRow = ((n % GetMajorDim()) == 0) || (n == count); } else // wxRA_SPECIFY_ROWS { // item is the last in the row if it is in the last columns isLastInTheRow = i >= (count/GetMajorDim())*GetMajorDim(); } // is this the start of new row/column? if ( i && (i % GetMajorDim() == 0) ) { if ( m_windowStyle & wxRA_SPECIFY_ROWS ) { // start of new column y_offset = startY; x_offset += maxWidth + cx1; } else // start of new row { x_offset = startX; y_offset += maxHeight; if (m_radioWidth[0]>0) y_offset += cy1/2; } } int widthBtn; if ( isLastInTheRow ) { // make the button go to the end of radio box widthBtn = startX + width - x_offset - 2*cx1; if ( widthBtn < maxWidth ) widthBtn = maxWidth; } else { // normal button, always of the same size widthBtn = maxWidth; } // make all buttons of the same, maximal size - like this they cover // the radiobox entirely and the radiobox tooltips are always shown // (otherwise they are not when the mouse pointer is in the radiobox // part not belonging to any radiobutton) DoMoveSibling((*m_radioButtons)[i], x_offset, y_offset, widthBtn, maxHeight); // where do we put the next button? if ( m_windowStyle & wxRA_SPECIFY_ROWS ) { // below this one y_offset += maxHeight; if (m_radioWidth[0]>0) y_offset += cy1/2; } else { // to the right of this one x_offset += widthBtn + cx1; } } }
// Restored old code. void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) { int currentX, currentY; GetPosition(¤tX, ¤tY); int widthOld, heightOld; GetSize(&widthOld, &heightOld); int xx = x; int yy = y; if (x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) xx = currentX; if (y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) yy = currentY; int y_offset = yy; int x_offset = xx; int cx1, cy1; wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont()); // Attempt to have a look coherent with other platforms: We compute the // biggest toggle dim, then we align all items according this value. wxSize maxSize = GetMaxButtonSize(); int maxWidth = maxSize.x, maxHeight = maxSize.y; wxSize totSize = GetTotalButtonSize(maxSize); int totWidth = totSize.x, totHeight = totSize.y; // only change our width/height if asked for if ( width == wxDefaultCoord ) { if ( sizeFlags & wxSIZE_AUTO_WIDTH ) width = totWidth; else width = widthOld; } if ( height == wxDefaultCoord ) { if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) height = totHeight; else height = heightOld; } DoMoveWindow(xx, yy, width, height); // Now position all the buttons: the current button will be put at // wxPoint(x_offset, y_offset) and the new row/column will start at // startX/startY. The size of all buttons will be the same wxSize(maxWidth, // maxHeight) except for the buttons in the last column which should extend // to the right border of radiobox and thus can be wider than this. // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in // left to right order and m_majorDim is the number of columns while // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and // m_majorDim is the number of rows. x_offset += cx1; y_offset += cy1; // Add extra space under the label, if it exists. if (!wxControl::GetLabel().empty()) y_offset += cy1/2; int startX = x_offset; int startY = y_offset; const int count = GetCount(); for ( int i = 0; i < count; i++ ) { // the last button in the row may be wider than the other ones as the // radiobox may be wider than the sum of the button widths (as it // happens, for example, when the radiobox label is very long) bool isLastInTheRow; if ( m_windowStyle & wxRA_SPECIFY_COLS ) { // item is the last in its row if it is a multiple of the number of // columns or if it is just the last item int n = i + 1; isLastInTheRow = ((n % m_majorDim) == 0) || (n == count); } else // wxRA_SPECIFY_ROWS { // item is the last in the row if it is in the last columns isLastInTheRow = i >= (count/m_majorDim)*m_majorDim; } // is this the start of new row/column? if ( i && (i % m_majorDim == 0) ) { if ( m_windowStyle & wxRA_SPECIFY_ROWS ) { // start of new column y_offset = startY; x_offset += maxWidth + cx1; } else // start of new row { x_offset = startX; y_offset += maxHeight; if (m_radioWidth[0]>0) y_offset += cy1/2; } } int widthBtn; if ( isLastInTheRow ) { // make the button go to the end of radio box widthBtn = startX + width - x_offset - 2*cx1; if ( widthBtn < maxWidth ) widthBtn = maxWidth; } else { // normal button, always of the same size widthBtn = maxWidth; } // make all buttons of the same, maximal size - like this they cover // the radiobox entirely and the radiobox tooltips are always shown // (otherwise they are not when the mouse pointer is in the radiobox // part not belonging to any radiobutton) DoMoveSibling((*m_radioButtons)[i], x_offset, y_offset, widthBtn, maxHeight); // where do we put the next button? if ( m_windowStyle & wxRA_SPECIFY_ROWS ) { // below this one y_offset += maxHeight; if (m_radioWidth[0]>0) y_offset += cy1/2; } else { // to the right of this one x_offset += widthBtn + cx1; } } }
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); } }