/////////////////////////////////////////////////////////////////////////////
-// Name: msw/radiobox.cpp
+// Name: src/msw/radiobox.cpp
// Purpose: wxRadioBox implementation
// Author: Julian Smart
// Modified by:
// headers
// ---------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "radiobox.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
wxUnusedVar(val);
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
- // and now create the buttons
- HWND hwndParent = GetHwndOf(parent);
-
m_radioButtons = new wxSubwindows(n);
m_radioWidth = new int[n];
m_radioHeight = new int[n];
m_radioWidth[i] =
m_radioHeight[i] = wxDefaultCoord;
long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
- if ( i == 0 && style == 0 )
+ if ( i == 0 )
styleBtn |= WS_GROUP;
long newId = NewControlId();
choices[i],
styleBtn,
0, 0, 0, 0, // will be set in SetSize()
- hwndParent,
+ GetHwnd(),
(HMENU)newId,
wxGetInstance(),
NULL);
(void)::CreateWindow(_T("BUTTON"),
wxEmptyString,
WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
- 0, 0, 0, 0, hwndParent,
+ 0, 0, 0, 0, GetHwnd(),
(HMENU)NewControlId(), wxGetInstance(), NULL);
m_radioButtons->SetFont(GetFont());
void wxRadioBox::Command(wxCommandEvent & event)
{
- SetSelection (event.m_commandInt);
+ SetSelection (event.GetInt());
SetFocus();
ProcessCommand(event);
}
void wxRadioBox::SetString(int item, const wxString& label)
{
- wxCHECK_RET( item >= 0 && item < GetCount(), wxT("invalid radiobox index") );
+ wxCHECK_RET( IsValid(item), wxT("invalid radiobox index") );
m_radioWidth[item] =
m_radioHeight[item] = wxDefaultCoord;
::SetWindowText((*m_radioButtons)[item], label.c_str());
+
+ InvalidateBestSize();
}
void wxRadioBox::SetSelection(int N)
{
- wxCHECK_RET( (N >= 0) && (N < GetCount()), wxT("invalid radiobox index") );
+ wxCHECK_RET( IsValid(N), wxT("invalid radiobox index") );
// unselect the old button
if ( m_selectedButton != wxNOT_FOUND )
// Find string for position
wxString wxRadioBox::GetString(int item) const
{
- wxCHECK_MSG( item >= 0 && item < GetCount(), wxEmptyString,
+ wxCHECK_MSG( IsValid(item), wxEmptyString,
wxT("invalid radiobox index") );
return wxGetWindowText((*m_radioButtons)[item]);
}
// Enable a specific button
-void wxRadioBox::Enable(int item, bool enable)
+bool wxRadioBox::Enable(int item, bool enable)
{
- wxCHECK_RET( item >= 0 && item < GetCount(),
+ wxCHECK_MSG( IsValid(item), false,
wxT("invalid item in wxRadioBox::Enable()") );
- ::EnableWindow((*m_radioButtons)[item], enable);
+ BOOL ret = ::EnableWindow((*m_radioButtons)[item], enable);
+
+ return (ret == 0) == enable;
}
// Show a specific button
-void wxRadioBox::Show(int item, bool show)
+bool wxRadioBox::Show(int item, bool show)
{
- wxCHECK_RET( item >= 0 && item < GetCount(),
+ wxCHECK_MSG( IsValid(item), false,
wxT("invalid item in wxRadioBox::Show()") );
- ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE);
+ BOOL ret = ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE);
+
+ bool changed = (ret != 0) == show;
+ if( changed )
+ InvalidateBestSize();
+ return changed;
}
WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons)
int width = GetNumHor() * (sizeBtn.x + cx1) + cx1;
// Add extra space under the label, if it exists.
- if (!wxControl::GetLabel().IsEmpty())
+ if (!wxControl::GetLabel().empty())
height += cy1/2;
// and also wide enough for its label
int widthLabel;
- GetTextExtent(GetTitle(), &widthLabel, NULL);
+ GetTextExtent(GetLabel(), &widthLabel, NULL);
widthLabel += RADIO_SIZE; // FIXME this is bogus too
if ( widthLabel > width )
width = widthLabel;
wxSize wxRadioBox::DoGetBestSize() const
{
- return GetTotalButtonSize(GetMaxButtonSize());
+ wxSize best = GetTotalButtonSize(GetMaxButtonSize());
+ CacheBestSize(best);
+ return best;
}
// Restored old code.
if (y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
yy = currentY;
- int y_offset = yy;
- int x_offset = xx;
+ int y_offset = 0;
+ int x_offset = 0;
int cx1, cy1;
wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());
height = heightOld;
}
- ::MoveWindow(GetHwnd(), xx, yy, width, height, TRUE);
+ DoMoveWindow(xx, yy, width, height);
// Now position all the buttons: the current button will be put at
// wxPoint(x_offset, y_offset) and the new row/column will start at
y_offset += cy1;
// Add extra space under the label, if it exists.
- if (!wxControl::GetLabel().IsEmpty())
+ if (!wxControl::GetLabel().empty())
y_offset += cy1/2;
int startX = x_offset;
}
}
+// ----------------------------------------------------------------------------
+// radio box drawing
+// ----------------------------------------------------------------------------
+
+#ifndef __WXWINCE__
+
+WXHRGN wxRadioBox::MSWGetRegionWithoutChildren()
+{
+ RECT rc;
+ ::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 )
+ {
+ ::GetWindowRect((*m_radioButtons)[i], &rc);
+ AutoHRGN hrgnchild(::CreateRectRgnIndirect(&rc));
+ ::CombineRgn(hrgn, hrgn, hrgnchild, RGN_DIFF);
+ }
+
+ return (WXHRGN)hrgn;
+}
+
+WXLRESULT
+wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
+{
+ // FIXME: Without this, the radiobox corrupts other controls as it moves
+ // in a dynamic layout. Refreshing causes flicker, but it's better than
+ // leaving droppings. Note that for some reason, wxStaticBox doesn't need
+ // this (perhaps because it has no real children?)
+ if ( nMsg == WM_MOVE )
+ {
+ WXLRESULT res = wxControl::MSWWindowProc(nMsg, wParam, lParam);
+ wxRect rect = GetRect();
+ GetParent()->Refresh(true, & rect);
+ return res;
+ }
+
+ return wxStaticBox::MSWWindowProc(nMsg, wParam, lParam);
+}
+
+#endif // __WXWINCE__
+
// ---------------------------------------------------------------------------
// window proc for radio buttons
// ---------------------------------------------------------------------------
if ( processed )
return 0;
-
- break;
}
+ break;
#endif // !__WXWINCE__
}
}
#endif // wxUSE_RADIOBOX
-