X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d6f93922574f0733fde4817445c3575398e2bf7a..e538985edcc645878a1bbeb3dc3e898e9d29ad11:/src/osx/radiobox_osx.cpp diff --git a/src/osx/radiobox_osx.cpp b/src/osx/radiobox_osx.cpp index 6ad4a138f9..3b1b220205 100644 --- a/src/osx/radiobox_osx.cpp +++ b/src/osx/radiobox_osx.cpp @@ -22,6 +22,10 @@ #include "wx/osx/private.h" +// regarding layout: note that there are differences in inter-control +// spacing between InterfaceBuild and the Human Interface Guidelines, we stick +// to the latter, as those are also used eg in the System Preferences Dialogs + IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) @@ -52,7 +56,7 @@ wxRadioBox::wxRadioBox() wxRadioBox::~wxRadioBox() { - m_isBeingDeleted = true; + SendDestroyEvent(); wxRadioButton *next, *current; @@ -355,7 +359,12 @@ void wxRadioBox::SetFocus() // Simulates the effect of the user issuing a command to the item // -#define RADIO_SIZE 20 +#if wxOSX_USE_CARBON + #define RADIO_SIZE 20 +#else + // Cocoa has an additional border are of about 3 pixels + #define RADIO_SIZE 23 +#endif void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) { @@ -395,11 +404,15 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) 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] = (int)(eachWidth[i] + RADIO_SIZE); - eachHeight[i] = (int)((3 * eachHeight[i]) / 2); + eachWidth[i] = eachWidth[i] + RADIO_SIZE; + eachHeight[i] = wxMax( eachHeight[i], bestSizeRadio.y ); if (maxWidth < eachWidth[i]) maxWidth = eachWidth[i]; @@ -407,7 +420,12 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) maxHeight = eachHeight[i]; } - totHeight = GetRowCount() * maxHeight; + // 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 ) ) ; @@ -434,8 +452,8 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) // arrange radio buttons int x_start, y_start; - x_start = 0; - y_start = 0; + x_start = ( width - sz.x ) / 2; + y_start = ( height - sz.y ) / 2; x_offset = x_start; y_offset = y_start; @@ -454,15 +472,15 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) else { x_offset = x_start; - y_offset += maxHeight ; //+ charHeight / 2 + y_offset += maxHeight + space; } } - current->SetSize( x_offset, y_offset, eachWidth[i], eachHeight[i]); + current->SetSize( x_offset, y_offset, eachWidth[i], eachHeight[i] ); current = current->NextInCycle(); if (m_windowStyle & wxRA_SPECIFY_ROWS) - y_offset += maxHeight ; // + charHeight / 2 + y_offset += maxHeight + space; else x_offset += maxWidth + charWidth; } @@ -485,24 +503,37 @@ wxSize wxRadioBox::DoGetBestSize() const 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 = (int)(eachWidth + RADIO_SIZE); - eachHeight = (int)((3 * eachHeight) / 2); + eachWidth = (eachWidth + RADIO_SIZE); + eachHeight = wxMax(eachHeight, bestSizeRadio.y ); if (maxWidth < eachWidth) maxWidth = eachWidth; if (maxHeight < eachHeight) maxHeight = eachHeight; } - totHeight = GetRowCount() * maxHeight; + // 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; @@ -512,4 +543,15 @@ wxSize wxRadioBox::DoGetBestSize() const return wxSize( totWidth, totHeight ); } +bool wxRadioBox::SetFont(const wxFont& font) +{ + bool retval = wxWindowBase::SetFont( font ); + + // dont' update the native control, it has its own small font + + // should we iterate over the children ? + + return retval; +} + #endif // wxUSE_RADIOBOX