changing layout to better adhere to HIG, fixing truncation on cocoa, fixes #10584

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59560 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2009-03-15 14:12:33 +00:00
parent f834ee4859
commit ae255e2948
2 changed files with 40 additions and 11 deletions

View File

@@ -2,7 +2,7 @@
// Name: src/osx/cocoa/radiobut.mm // Name: src/osx/cocoa/radiobut.mm
// Purpose: wxRadioButton // Purpose: wxRadioButton
// Author: Stefan Csomor // Author: Stefan Csomor
// Modified by: JS Lair (99/11/15) adding the cyclic group notion for radiobox // Modified by:
// Created: ??/??/98 // Created: ??/??/98
// RCS-ID: $Id: radiobut.cpp 54129 2008-06-11 19:30:52Z SC $ // RCS-ID: $Id: radiobut.cpp 54129 2008-06-11 19:30:52Z SC $
// Copyright: (c) AUTHOR // Copyright: (c) AUTHOR

View File

@@ -22,6 +22,10 @@
#include "wx/osx/private.h" #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) IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
@@ -355,7 +359,12 @@ void wxRadioBox::SetFocus()
// Simulates the effect of the user issuing a command to the item // Simulates the effect of the user issuing a command to the item
// //
#if wxOSX_USE_CARBON
#define RADIO_SIZE 20 #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) 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; maxWidth = -1;
maxHeight = -1; maxHeight = -1;
wxSize bestSizeRadio ;
if ( m_radioButtonCycle )
bestSizeRadio = m_radioButtonCycle->GetBestSize();
for (unsigned int i = 0 ; i < m_noItems; i++) for (unsigned int i = 0 ; i < m_noItems; i++)
{ {
GetTextExtent(GetString(i), &eachWidth[i], &eachHeight[i] ); GetTextExtent(GetString(i), &eachWidth[i], &eachHeight[i] );
eachWidth[i] = (int)(eachWidth[i] + RADIO_SIZE); eachWidth[i] = eachWidth[i] + RADIO_SIZE;
eachHeight[i] = (int) eachHeight[i]; eachHeight[i] = wxMax( eachHeight[i], bestSizeRadio.y );
if (maxWidth < eachWidth[i]) if (maxWidth < eachWidth[i])
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]; maxHeight = eachHeight[i];
} }
totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * maxHeight / 2; // 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); totWidth = GetColumnCount() * (maxWidth + charWidth);
wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ; wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ;
@@ -454,7 +472,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
else else
{ {
x_offset = x_start; x_offset = x_start;
y_offset += 3 * maxHeight / 2 ; //+ charHeight / 2 y_offset += maxHeight + space;
} }
} }
@@ -462,7 +480,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
current = current->NextInCycle(); current = current->NextInCycle();
if (m_windowStyle & wxRA_SPECIFY_ROWS) if (m_windowStyle & wxRA_SPECIFY_ROWS)
y_offset += 3 * maxHeight / 2 ; // + charHeight / 2 y_offset += maxHeight + space;
else else
x_offset += maxWidth + charWidth; x_offset += maxWidth + charWidth;
} }
@@ -485,18 +503,27 @@ wxSize wxRadioBox::DoGetBestSize() const
maxWidth = -1; maxWidth = -1;
maxHeight = -1; maxHeight = -1;
wxSize bestSizeRadio ;
if ( m_radioButtonCycle )
bestSizeRadio = m_radioButtonCycle->GetBestSize();
for (unsigned int i = 0 ; i < m_noItems; i++) for (unsigned int i = 0 ; i < m_noItems; i++)
{ {
GetTextExtent(GetString(i), &eachWidth, &eachHeight, NULL, NULL, &font ); GetTextExtent(GetString(i), &eachWidth, &eachHeight, NULL, NULL, &font );
eachWidth = (int)(eachWidth + RADIO_SIZE); eachWidth = (eachWidth + RADIO_SIZE);
eachHeight = (int)eachHeight; eachHeight = wxMax(eachHeight, bestSizeRadio.y );
if (maxWidth < eachWidth) if (maxWidth < eachWidth)
maxWidth = eachWidth; maxWidth = eachWidth;
if (maxHeight < eachHeight) if (maxHeight < eachHeight)
maxHeight = eachHeight; maxHeight = eachHeight;
} }
totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * maxHeight / 2; // 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); totWidth = GetColumnCount() * (maxWidth + charWidth);
wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ); wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) );
@@ -522,6 +549,8 @@ bool wxRadioBox::SetFont(const wxFont& font)
// dont' update the native control, it has its own small font // dont' update the native control, it has its own small font
// should we iterate over the children ?
return retval; return retval;
} }