#if wxUSE_RADIOBOX
+#include "wx/radiobox.h"
+
#ifndef WX_PRECOMP
#include "wx/bitmap.h"
#include "wx/brush.h"
- #include "wx/radiobox.h"
#include "wx/settings.h"
#include "wx/log.h"
#endif
#include "wx/msw/subwin.h"
#if wxUSE_TOOLTIPS
- #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
- #include <commctrl.h>
- #endif
#include "wx/tooltip.h"
#endif // wxUSE_TOOLTIPS
long newId = NewControlId();
HWND hwndBtn = ::CreateWindow(_T("BUTTON"),
- choices[i],
+ choices[i].wx_str(),
styleBtn,
0, 0, 0, 0, // will be set in SetSize()
GetHwndOf(parent),
SetSize(pos.x, pos.y, size.x, size.y);
// Now that we have items determine what is the best size and set it.
- SetBestSize(size);
+ SetInitialSize(size);
return true;
}
// events generation
// ----------------------------------------------------------------------------
-bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id)
+bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id_)
{
+ const int id = (signed short)id_;
+
if ( cmd == BN_CLICKED )
{
if (id == GetId())
int selectedButton = wxNOT_FOUND;
- int count = GetCount();
- for ( int i = 0; i < count; i++ )
+ const unsigned int count = GetCount();
+ for ( unsigned int i = 0; i < count; i++ )
{
- if ( id == wxGetWindowId((*m_radioButtons)[i]) )
+ const HWND hwndBtn = (*m_radioButtons)[i];
+ if ( id == wxGetWindowId(hwndBtn) )
{
- selectedButton = i;
+ // we can get BN_CLICKED for a button which just became focused
+ // but it may not be checked, in which case we shouldn't
+ // generate a radiobox selection changed event for it
+ if ( ::SendMessage(hwndBtn, BM_GETCHECK, 0, 0) == BST_CHECKED )
+ selectedButton = i;
break;
}
{
wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId);
event.SetInt( m_selectedButton );
- event.SetString( GetString(m_selectedButton) );
+ event.SetString(GetString(m_selectedButton));
event.SetEventObject( this );
ProcessCommand(event);
}
// simple accessors
// ----------------------------------------------------------------------------
-int wxRadioBox::GetCount() const
+unsigned int wxRadioBox::GetCount() const
{
- return m_radioButtons->GetCount();
+ return m_radioButtons ? m_radioButtons->GetCount() : 0u;
}
-void wxRadioBox::SetString(int item, const wxString& label)
+void wxRadioBox::SetString(unsigned int item, const wxString& label)
{
wxCHECK_RET( IsValid(item), wxT("invalid radiobox index") );
}
// Find string for position
-wxString wxRadioBox::GetString(int item) const
+wxString wxRadioBox::GetString(unsigned int item) const
{
wxCHECK_MSG( IsValid(item), wxEmptyString,
wxT("invalid radiobox index") );
}
// Enable a specific button
-bool wxRadioBox::Enable(int item, bool enable)
+bool wxRadioBox::Enable(unsigned int item, bool enable)
{
wxCHECK_MSG( IsValid(item), false,
wxT("invalid item in wxRadioBox::Enable()") );
return (ret == 0) != enable;
}
-bool wxRadioBox::IsItemEnabled(int item) const
+bool wxRadioBox::IsItemEnabled(unsigned int item) const
{
wxCHECK_MSG( IsValid(item), false,
wxT("invalid item in wxRadioBox::IsItemEnabled()") );
}
// Show a specific button
-bool wxRadioBox::Show(int item, bool show)
+bool wxRadioBox::Show(unsigned int item, bool show)
{
wxCHECK_MSG( IsValid(item), false,
wxT("invalid item in wxRadioBox::Show()") );
return changed;
}
-bool wxRadioBox::IsItemShown(int item) const
+bool wxRadioBox::IsItemShown(unsigned int item) const
{
wxCHECK_MSG( IsValid(item), false,
wxT("invalid item in wxRadioBox::IsItemShown()") );
GWL_STYLE) & WS_VISIBLE) != 0;
}
+#if wxUSE_TOOLTIPS
+
+bool wxRadioBox::HasToolTips() const
+{
+ return wxStaticBox::HasToolTips() || wxRadioBoxBase::HasItemToolTips();
+}
+
+void wxRadioBox::DoSetItemToolTip(unsigned int item, wxToolTip *tooltip)
+{
+ // we have already checked for the item to be valid in wxRadioBoxBase
+ const HWND hwndRbtn = (*m_radioButtons)[item];
+ if ( tooltip != NULL )
+ tooltip->Add(hwndRbtn);
+ else // unset the tooltip
+ wxToolTip::Remove(hwndRbtn);
+}
+
+#endif // wxUSE_TOOLTIPS
+
WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons)
// ----------------------------------------------------------------------------
// calculate the max button size
int widthMax = 0,
heightMax = 0;
- const int count = GetCount();
- for ( int i = 0 ; i < count; i++ )
+ const unsigned int count = GetCount();
+ for ( unsigned int i = 0 ; i < count; i++ )
{
int width, height;
if ( m_radioWidth[i] < 0 )
// and also wide enough for its label
int widthLabel;
- GetTextExtent(GetLabel(), &widthLabel, NULL);
+ GetTextExtent(GetLabelText(), &widthLabel, NULL);
widthLabel += RADIO_SIZE; // FIXME this is bogus too
if ( widthLabel > width )
width = widthLabel;
wxSize wxRadioBox::DoGetBestSize() const
{
+ if ( !m_radioButtons )
+ {
+ // if we're not fully initialized yet, we can't meaningfully compute
+ // our best size, we'll do it later
+ return wxSize(1, 1);
+ }
+
wxSize best = GetTotalButtonSize(GetMaxButtonSize());
CacheBestSize(best);
return best;
int startX = x_offset;
int startY = y_offset;
- const int count = GetCount();
- for ( int i = 0; i < count; i++ )
+ 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
{
// 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;
+ unsigned int n = i + 1;
isLastInTheRow = ((n % GetMajorDim()) == 0) || (n == count);
}
else // wxRA_SPECIFY_ROWS
}
}
+int wxRadioBox::GetItemFromPoint(const wxPoint& pt) const
+{
+ const unsigned int count = GetCount();
+ for ( unsigned int i = 0; i < count; i++ )
+ {
+ RECT rect = wxGetWindowRect((*m_radioButtons)[i]);
+
+ if ( rect.left <= pt.x && pt.x < rect.right &&
+ rect.top <= pt.y && pt.y < rect.bottom )
+ {
+ return i;
+ }
+ }
+
+ return wxNOT_FOUND;
+}
+
// ----------------------------------------------------------------------------
// radio box drawing
// ----------------------------------------------------------------------------
::GetWindowRect(GetHwnd(), &rc);
HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1);
- const size_t count = GetCount();
- for ( size_t i = 0; i < count; ++i )
+ const unsigned int count = GetCount();
+ for ( unsigned int i = 0; i < count; ++i )
{
// don't clip out hidden children
if ( !IsItemShown(i) )
return lDlgCode | DLGC_WANTARROWS;
}
-#if wxUSE_TOOLTIPS
- case WM_NOTIFY:
- {
- NMHDR* hdr = (NMHDR *)lParam;
- if ( hdr->code == TTN_NEEDTEXT )
- {
- wxRadioBox *
- radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
-
- wxCHECK_MSG( radiobox, 0,
- wxT("radio button without radio box?") );
-
- wxToolTip *tooltip = radiobox->GetToolTip();
- if ( tooltip )
- {
- TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
- ttt->lpszText = (wxChar *)tooltip->GetTip().c_str();
- }
-
- // processed
- return 0;
- }
- }
- break;
-#endif // wxUSE_TOOLTIPS
-
case WM_KEYDOWN:
{
wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);