wxSize wxBannerWindow::DoGetBestClientSize() const { if ( m_bitmap.IsOk() ) { return m_bitmap.GetSize(); } else { wxClientDC dc(const_cast<wxBannerWindow *>(this)); const wxSize sizeText = dc.GetMultiLineTextExtent(m_message); dc.SetFont(GetTitleFont()); const wxSize sizeTitle = dc.GetTextExtent(m_title); wxSize sizeWin(wxMax(sizeTitle.x, sizeText.x), sizeTitle.y + sizeText.y); // If we draw the text vertically width and height are swapped. if ( m_direction == wxLEFT || m_direction == wxRIGHT ) wxSwap(sizeWin.x, sizeWin.y); sizeWin += 2*wxSize(MARGIN_X, MARGIN_Y); return sizeWin; } }
int wxSlider::GetLabelsSize(int *widthMin, int *widthMax) const { if ( widthMin && widthMax ) { *widthMin = GetTextExtent(Format(m_rangeMin)).x; *widthMax = GetTextExtent(Format(m_rangeMax)).x; if ( HasFlag(wxSL_INVERSE) ) { wxSwap(*widthMin, *widthMax); } } return HasFlag(wxSL_LABELS) ? GetCharHeight() : 0; }
void wxRearrangeList::Swap(int pos1, int pos2) { // update the internally stored order wxSwap(m_order[pos1], m_order[pos2]); // and now also swap all the attributes of the items // first the label const wxString stringTmp = GetString(pos1); SetString(pos1, GetString(pos2)); SetString(pos2, stringTmp); // then the checked state const bool checkedTmp = IsChecked(pos1); wxCheckListBox::Check(pos1, IsChecked(pos2)); wxCheckListBox::Check(pos2, checkedTmp); // and finally the client data, if necessary switch ( GetClientDataType() ) { case wxClientData_None: // nothing to do break; case wxClientData_Object: { wxClientData * const dataTmp = DetachClientObject(pos1); SetClientObject(pos1, DetachClientObject(pos2)); SetClientObject(pos2, dataTmp); } break; case wxClientData_Void: { void * const dataTmp = GetClientData(pos1); SetClientData(pos1, GetClientData(pos2)); SetClientData(pos2, dataTmp); } break; } }
void EditPrint::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) { // initialize values *minPage = 0; *maxPage = 0; *selPageFrom = 0; *selPageTo = 0; // scale DC if possible wxDC *dc = GetDC(); if (!dc) return; PrintScaling (dc); // get print page informations and convert to printer pixels wxSize ppiScr; GetPPIScreen (&ppiScr.x, &ppiScr.y); wxSize page = g_pageSetupData->GetPaperSize(); page.x = static_cast<int> (page.x * ppiScr.x / 25.4); page.y = static_cast<int> (page.y * ppiScr.y / 25.4); // In landscape mode we need to swap the width and height if ( g_pageSetupData->GetPrintData().GetOrientation() == wxLANDSCAPE ) { wxSwap(page.x, page.y); } m_pageRect = wxRect (0, 0, page.x, page.y); // get margins informations and convert to printer pixels wxPoint pt = g_pageSetupData->GetMarginTopLeft(); int left = pt.x; int top = pt.y; pt = g_pageSetupData->GetMarginBottomRight(); int right = pt.x; int bottom = pt.y; top = static_cast<int> (top * ppiScr.y / 25.4); bottom = static_cast<int> (bottom * ppiScr.y / 25.4); left = static_cast<int> (left * ppiScr.x / 25.4); right = static_cast<int> (right * ppiScr.x / 25.4); m_printRect = wxRect (left, top, page.x - (left + right), page.y - (top + bottom)); // count pages m_pageEnds.Clear(); int printed = 0; while ( printed < m_edit->GetLength() ) { printed = m_edit->FormatRange(false, printed, m_edit->GetLength(), dc, dc, m_printRect, m_pageRect); m_pageEnds.Add(printed); *maxPage += 1; } if (*maxPage > 0) *minPage = 1; *selPageFrom = *minPage; *selPageTo = *maxPage; }
void clTabInfo::CalculateOffsets(size_t style) { wxBitmap b(1, 1); wxMemoryDC memDC(b); m_bmpCloseX = wxNOT_FOUND; m_bmpCloseY = wxNOT_FOUND; wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); memDC.SetFont(font); wxSize sz = memDC.GetTextExtent(m_label); wxSize fixedHeight = memDC.GetTextExtent("Tp"); if(IS_VERTICAL_TABS(style)) { m_height = fixedHeight.GetHeight() + (5 * m_tabCtrl->GetArt()->ySpacer); } else { m_height = fixedHeight.GetHeight() + (4 * m_tabCtrl->GetArt()->ySpacer); } #ifdef __WXGTK__ // On GTK, limit the tab height if(m_height >= 30) { m_height = 30; } #endif m_width = 0; if(!IS_VERTICAL_TABS(style) || true) { m_width += m_tabCtrl->GetArt()->majorCurveWidth; m_width += m_tabCtrl->GetArt()->smallCurveWidth; } m_width += m_tabCtrl->GetArt()->xSpacer; // bitmap m_bmpX = wxNOT_FOUND; m_bmpY = wxNOT_FOUND; if(m_bitmap.IsOk()) { m_bmpX = m_width; m_width += m_tabCtrl->GetArt()->xSpacer; m_width += m_bitmap.GetScaledWidth(); m_bmpY = ((m_height - m_bitmap.GetScaledHeight()) / 2); } // Text m_textX = m_width; m_textY = ((m_height - sz.y) / 2); m_width += sz.x; // x button if((style & kNotebook_CloseButtonOnActiveTab)) { m_width += m_tabCtrl->GetArt()->xSpacer; m_bmpCloseX = m_width; m_bmpCloseY = ((m_height - 12) / 2); m_width += 12; // X button is 10 pixels in size } m_width += m_tabCtrl->GetArt()->xSpacer; if(!IS_VERTICAL_TABS(style) || true) { m_width += m_tabCtrl->GetArt()->majorCurveWidth; m_width += m_tabCtrl->GetArt()->smallCurveWidth; } // Update the rect width m_rect.SetWidth(m_width); if((style & kNotebook_RightTabs) || (style & kNotebook_LeftTabs)) { // swap the x and y coordinates wxSwap(m_height, m_width); wxSwap(m_bmpCloseY, m_bmpCloseX); wxSwap(m_bmpY, m_bmpX); wxSwap(m_textX, m_textY); m_width = m_tabCtrl->GetSize().GetWidth(); m_textX += 1; m_rect.SetWidth(m_width); m_rect.SetHeight(m_height); m_rect.SetX(0); m_rect.SetY(0); } }
void BoxSizerTestCase::Size3() { // check that various combinations of minimal sizes and proportions work as // expected for different window sizes static const struct LayoutTestData { // proportions of the elements int prop[3]; // minimal sizes of the elements in the sizer direction int minsize[3]; // total size and the expected sizes of the elements int x, sizes[3]; // if true, don't try the permutations of our test data bool dontPermute; // Add the given window to the sizer with the corresponding parameters void AddToSizer(wxSizer *sizer, wxWindow *win, int n) const { sizer->Add(win, wxSizerFlags(prop[n])); sizer->SetItemMinSize(win, wxSize(minsize[n], -1)); } } layoutTestData[] = { // some really simple cases (no need to permute those, they're // symmetrical anyhow) { { 1, 1, 1, }, { 50, 50, 50, }, 150, { 50, 50, 50, }, true }, { { 2, 2, 2, }, { 50, 50, 50, }, 600, { 200, 200, 200, }, true }, // items with different proportions and min sizes when there is enough // space to lay them out { { 1, 2, 3, }, { 0, 0, 0, }, 600, { 100, 200, 300, } }, { { 1, 2, 3, }, { 100, 100, 100, }, 600, { 100, 200, 300, } }, { { 1, 2, 3, }, { 100, 50, 50, }, 600, { 100, 200, 300, } }, { { 0, 1, 1, }, { 200, 100, 100, }, 600, { 200, 200, 200, } }, { { 0, 1, 2, }, { 300, 100, 100, }, 600, { 300, 100, 200, } }, { { 0, 1, 1, }, { 100, 50, 50, }, 300, { 100, 100, 100, } }, { { 0, 1, 2, }, { 100, 50, 50, }, 400, { 100, 100, 200, } }, // cases when there is not enough space to lay out the items correctly // while still respecting their min sizes { { 0, 1, 1, }, { 100, 150, 50, }, 300, { 100, 150, 50, } }, { { 1, 2, 3, }, { 100, 100, 100, }, 300, { 100, 100, 100, } }, { { 1, 2, 3, }, { 100, 50, 50, }, 300, { 100, 80, 120, } }, { { 1, 2, 3, }, { 100, 10, 10, }, 150, { 100, 20, 30, } }, // cases when there is not enough space even for the min sizes (don't // permute in these cases as the layout does depend on the item order // because the first ones have priority) { { 1, 2, 3, }, { 100, 50, 50, }, 150, { 100, 50, 0, }, true }, { { 1, 2, 3, }, { 100, 100, 100, }, 200, { 100, 100, 0, }, true }, { { 1, 2, 3, }, { 100, 100, 100, }, 150, { 100, 50, 0, }, true }, { { 1, 2, 3, }, { 100, 100, 100, }, 50, { 50, 0, 0, }, true }, { { 1, 2, 3, }, { 100, 100, 100, }, 0, { 0, 0, 0, }, true }, }; wxWindow *child[3]; child[0] = new wxWindow(m_win, wxID_ANY); child[1] = new wxWindow(m_win, wxID_ANY); child[2] = new wxWindow(m_win, wxID_ANY); for ( unsigned i = 0; i < WXSIZEOF(layoutTestData); i++ ) { LayoutTestData ltd = layoutTestData[i]; // the results shouldn't depend on the order of items except in the // case when there is not enough space for even the fixed width items // (in which case the first ones might get enough of it but not the // last ones) so test a couple of permutations of test data unless // specifically disabled for this test case for ( unsigned p = 0; p < 3; p++) { switch ( p ) { case 0: // nothing to do, use original data break; case 1: // exchange first and last elements wxSwap(ltd.prop[0], ltd.prop[2]); wxSwap(ltd.minsize[0], ltd.minsize[2]); wxSwap(ltd.sizes[0], ltd.sizes[2]); break; case 2: // exchange the original third and second elements wxSwap(ltd.prop[0], ltd.prop[1]); wxSwap(ltd.minsize[0], ltd.minsize[1]); wxSwap(ltd.sizes[0], ltd.sizes[1]); break; } m_sizer->Clear(); unsigned j; for ( j = 0; j < WXSIZEOF(child); j++ ) ltd.AddToSizer(m_sizer, child[j], j); m_win->SetClientSize(ltd.x, -1); m_win->Layout(); for ( j = 0; j < WXSIZEOF(child); j++ ) { WX_ASSERT_EQUAL_MESSAGE ( ( "test %lu, permutation #%lu: wrong size for child #%d " "for total size %d", static_cast<unsigned long>(i), static_cast<unsigned long>(p), j, ltd.x ), ltd.sizes[j], child[j]->GetSize().x ); } // don't try other permutations if explicitly disabled if ( ltd.dontPermute ) break; } } }
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); } }