bool wxNotebook::Create( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) { m_macIsUserPane = false ; if (! (style & wxBK_ALIGN_MASK)) style |= wxBK_TOP; if ( !wxNotebookBase::Create( parent, id, pos, size, style, name ) ) return false; Rect bounds = wxMacGetBoundsForControl( this, pos, size ); if ( bounds.right <= bounds.left ) bounds.right = bounds.left + 100; if ( bounds.bottom <= bounds.top ) bounds.bottom = bounds.top + 100; UInt16 tabstyle = kControlTabDirectionNorth; if ( HasFlag(wxBK_LEFT) ) tabstyle = kControlTabDirectionWest; else if ( HasFlag( wxBK_RIGHT ) ) tabstyle = kControlTabDirectionEast; else if ( HasFlag( wxBK_BOTTOM ) ) tabstyle = kControlTabDirectionSouth; ControlTabSize tabsize; switch (GetWindowVariant()) { case wxWINDOW_VARIANT_MINI: if ( UMAGetSystemVersion() >= 0x1030 ) tabsize = 3 ; else tabsize = kControlSizeSmall; break; case wxWINDOW_VARIANT_SMALL: tabsize = kControlTabSizeSmall; break; default: tabsize = kControlTabSizeLarge; break; } m_peer = new wxMacControl( this ); OSStatus err = CreateTabsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, tabsize, tabstyle, 0, NULL, m_peer->GetControlRefAddr() ); verify_noerr( err ); MacPostControlCreate( pos, size ); return true ; }
wxSize wxRadioBox::DoGetBestSize() const { int charWidth, charHeight; int maxWidth, maxHeight; int eachWidth, eachHeight; int totWidth, totHeight; wxFont font = GetFont(); // GetParent()->GetFont() GetTextExtent( wxT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &charWidth, &charHeight, NULL, NULL, &font ); charWidth /= 52; maxWidth = -1; maxHeight = -1; wxSize bestSizeRadio ; if ( m_radioButtonCycle ) bestSizeRadio = m_radioButtonCycle->GetBestSize(); for (unsigned int i = 0 ; i < m_noItems; i++) { GetTextExtent(GetString(i), &eachWidth, &eachHeight, NULL, NULL, &font ); eachWidth = (eachWidth + RADIO_SIZE); eachHeight = wxMax(eachHeight, bestSizeRadio.y ); if (maxWidth < eachWidth) maxWidth = eachWidth; if (maxHeight < eachHeight) maxHeight = eachHeight; } // according to HIG (official space - 3 Pixels Diff between Frame and Layout size) int space = 3; if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI ) space = 2; totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * space; totWidth = GetColumnCount() * (maxWidth + charWidth); wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ); totWidth = sz.x; totHeight = sz.y; // optimum size is an additional 5 pt border to all sides totWidth += 10; totHeight += 10; // handle radio box title as well GetTextExtent( GetLabel(), &eachWidth, NULL ); eachWidth = (int)(eachWidth + RADIO_SIZE) + 3 * charWidth; if (totWidth < eachWidth) totWidth = eachWidth; return wxSize( totWidth, totHeight ); }
void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) { int i; wxRadioButton *current; // define the position int x_current, y_current; int x_offset, y_offset; int widthOld, heightOld; GetSize( &widthOld, &heightOld ); GetPosition( &x_current, &y_current ); x_offset = x; y_offset = y; if (!(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) { if (x == wxDefaultCoord) x_offset = x_current; if (y == wxDefaultCoord) y_offset = y_current; } // define size int charWidth, charHeight; int maxWidth, maxHeight; int eachWidth[128], eachHeight[128]; int totWidth, totHeight; GetTextExtent( wxT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &charWidth, &charHeight ); charWidth /= 52; maxWidth = -1; maxHeight = -1; wxSize bestSizeRadio ; if ( m_radioButtonCycle ) bestSizeRadio = m_radioButtonCycle->GetBestSize(); for (unsigned int i = 0 ; i < m_noItems; i++) { GetTextExtent(GetString(i), &eachWidth[i], &eachHeight[i] ); eachWidth[i] = eachWidth[i] + RADIO_SIZE; eachHeight[i] = wxMax( eachHeight[i], bestSizeRadio.y ); if (maxWidth < eachWidth[i]) maxWidth = eachWidth[i]; if (maxHeight < eachHeight[i]) maxHeight = eachHeight[i]; } // according to HIG (official space - 3 Pixels Diff between Frame and Layout size) int space = 3; if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI ) space = 2; totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * space; totWidth = GetColumnCount() * (maxWidth + charWidth); wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ; // change the width / height only when specified if ( width == wxDefaultCoord ) { if ( sizeFlags & wxSIZE_AUTO_WIDTH ) width = sz.x; else width = widthOld; } if ( height == wxDefaultCoord ) { if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) height = sz.y; else height = heightOld; } wxControl::DoSetSize( x_offset, y_offset, width, height, wxSIZE_AUTO ); // arrange radio buttons int x_start, y_start; x_start = ( width - sz.x ) / 2; y_start = ( height - sz.y ) / 2; x_offset = x_start; y_offset = y_start; current = m_radioButtonCycle; for (i = 0 ; i < (int)m_noItems; i++) { // not to do for the zero button! if ((i > 0) && ((i % GetMajorDim()) == 0)) { if (m_windowStyle & wxRA_SPECIFY_ROWS) { x_offset += maxWidth + charWidth; y_offset = y_start; } else { x_offset = x_start; y_offset += maxHeight + space; } } current->SetSize( x_offset, y_offset, eachWidth[i], eachHeight[i] ); current = current->NextInCycle(); if (m_windowStyle & wxRA_SPECIFY_ROWS) y_offset += maxHeight + space; else x_offset += maxWidth + charWidth; } }
wxSize wxButton::DoGetBestSize() const { if ( GetId() == wxID_HELP ) return wxSize( 20 , 20 ) ; wxSize sz = GetDefaultSize() ; switch (GetWindowVariant()) { case wxWINDOW_VARIANT_NORMAL: case wxWINDOW_VARIANT_LARGE: sz.y = 20 ; break; case wxWINDOW_VARIANT_SMALL: sz.y = 17 ; break; case wxWINDOW_VARIANT_MINI: sz.y = 15 ; break; default: break; } #if wxOSX_USE_CARBON Rect bestsize = { 0 , 0 , 0 , 0 } ; m_peer->GetBestRect( &bestsize ) ; int wBtn; if ( EmptyRect( &bestsize ) || ( GetWindowStyle() & wxBU_EXACTFIT) ) { Point bounds; ControlFontStyleRec controlFont; OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont ); verify_noerr( err ); // GetThemeTextDimensions will cache strings and the documentation // says not to use the NoCopy string creation calls. // This also means that we can't use CFSTR without // -fno-constant-cfstrings if the library might be unloaded, // as GetThemeTextDimensions may cache a pointer to our // unloaded segment. wxCFStringRef str( !m_label.empty() ? m_label : wxString(" "), GetFont().GetEncoding() ); #if wxOSX_USE_ATSU_TEXT SInt16 baseline; if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) { err = GetThemeTextDimensions( (CFStringRef)str, m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); verify_noerr( err ); } else #endif { wxClientDC dc(const_cast<wxButton*>(this)); wxCoord width, height ; dc.GetTextExtent( m_label , &width, &height); bounds.h = width; bounds.v = height; } wBtn = bounds.h + sz.y; } else { wBtn = bestsize.right - bestsize.left ; // non 'normal' window variants don't return the correct height // sz.y = bestsize.bottom - bestsize.top ; } if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT)) sz.x = wBtn; #endif return sz ; }
void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) { int i; wxRadioButton *current; // define the position int x_current, y_current; int x_offset, y_offset; int widthOld, heightOld; GetSize( &widthOld, &heightOld ); GetPosition( &x_current, &y_current ); x_offset = x; y_offset = y; if (!(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) { if (x == wxDefaultCoord) x_offset = x_current; if (y == wxDefaultCoord) y_offset = y_current; } // define size int charWidth, charHeight; int maxWidth, maxHeight; int eachWidth[128], eachHeight[128]; int totWidth, totHeight; GetTextExtent( wxT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &charWidth, &charHeight ); charWidth /= 52; maxWidth = -1; maxHeight = -1; wxSize bestSizeRadio ; if ( m_radioButtonCycle ) bestSizeRadio = m_radioButtonCycle->GetBestSize(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (unsigned int i = 0 ; i < m_noItems; i++) { GetTextExtent(GetString(i), &eachWidth[i], &eachHeight[i] ); eachWidth[i] = eachWidth[i] + RADIO_SIZE; eachHeight[i] = wxMax( eachHeight[i], bestSizeRadio.y ); if (maxWidth < eachWidth[i]) maxWidth = eachWidth[i]; if (maxHeight < eachHeight[i]) maxHeight = eachHeight[i]; } // according to HIG (official space - 3 Pixels Diff between Frame and Layout size) int space = 3; if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI ) space = 2; totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * space; totWidth = GetColumnCount() * (maxWidth + charWidth); // Determine the full size in case we need to use it as fallback. wxSize sz; if ( (width == wxDefaultCoord && (sizeFlags & wxSIZE_AUTO_WIDTH)) || (height == wxDefaultCoord && (sizeFlags & wxSIZE_AUTO_HEIGHT)) ) { sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ; } // change the width / height only when specified if ( width == wxDefaultCoord ) { if ( sizeFlags & wxSIZE_AUTO_WIDTH ) width = sz.x; else width = widthOld; } if ( height == wxDefaultCoord ) { if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) height = sz.y; else height = heightOld; } wxControl::DoSetSize( x_offset, y_offset, width, height, wxSIZE_AUTO ); // But now recompute the full size again because it could have changed. // This notably happens if the previous full size was too small to fully // fit the box margins. sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ; // arrange radio buttons int x_start, y_start; x_start = ( width - sz.x ) / 2; y_start = ( height - sz.y ) / 2; x_offset = x_start; y_offset = y_start; current = m_radioButtonCycle; #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (i = 0 ; i < (int)m_noItems; i++) { // not to do for the zero button! if ((i > 0) && ((i % GetMajorDim()) == 0)) { if (m_windowStyle & wxRA_SPECIFY_ROWS) { x_offset += maxWidth + charWidth; y_offset = y_start; } else { x_offset = x_start; y_offset += maxHeight + space; } } current->SetSize( x_offset, y_offset, eachWidth[i], eachHeight[i] ); current = current->NextInCycle(); if (m_windowStyle & wxRA_SPECIFY_ROWS) y_offset += maxHeight + space; else x_offset += maxWidth + charWidth; } }