-void wxRadioBox::GetSize(int *width, int *height) const
-{
- RECT rect;
- rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
-
- if (m_hWnd)
- wxFindMaxSize(m_hWnd, &rect);
-
- int i;
- for (i = 0; i < m_noItems; i++)
- wxFindMaxSize(m_radioButtons[i], &rect);
-
- *width = rect.right - rect.left;
- *height = rect.bottom - rect.top;
-}
-
-void wxRadioBox::GetPosition(int *x, int *y) const
-{
- wxWindow *parent = GetParent();
- RECT rect = { -1, -1, -1, -1 };
-
- int i;
- for (i = 0; i < m_noItems; i++)
- wxFindMaxSize(m_radioButtons[i], &rect);
-
- if (m_hWnd)
- wxFindMaxSize(m_hWnd, &rect);
-
- // Since we now have the absolute screen coords, if there's a parent we
- // must subtract its top left corner
- POINT point;
- point.x = rect.left;
- point.y = rect.top;
- if (parent)
- {
- ::ScreenToClient((HWND) parent->GetHWND(), &point);
- }
-
- // We may be faking the client origin. So a window that's really at (0, 30)
- // may appear (to wxWin apps) to be at (0, 0).
- if (GetParent())
- {
- wxPoint pt(GetParent()->GetClientAreaOrigin());
- point.x -= pt.x;
- point.y -= pt.y;
- }
-
- *x = point.x;
- *y = point.y;
-}
-
-void wxRadioBox::SetFocus()
-{
- if (m_noItems > 0)
- {
- if (m_selectedButton == -1)
- ::SetFocus((HWND) m_radioButtons[0]);
- else
- ::SetFocus((HWND) m_radioButtons[m_selectedButton]);
- }
-
-}
-
-bool wxRadioBox::Show(bool show)
-{
- if ( !wxControl::Show(show) )
- return FALSE;
-
- int nCmdShow = show ? SW_SHOW : SW_HIDE;
- for ( int i = 0; i < m_noItems; i++ )
- {
- ::ShowWindow((HWND)m_radioButtons[i], nCmdShow);
- }
-
- return TRUE;
-}
-
-// Enable a specific button
-void wxRadioBox::Enable(int item, bool enable)
-{
- wxCHECK_RET( item >= 0 && item < m_noItems,
- wxT("invalid item in wxRadioBox::Enable()") );
-
- ::EnableWindow((HWND) m_radioButtons[item], enable);
-}
-
-// Enable all controls
-bool wxRadioBox::Enable(bool enable)
-{
- if ( !wxControl::Enable(enable) )
- return FALSE;
-
- for (int i = 0; i < m_noItems; i++)
- ::EnableWindow((HWND) m_radioButtons[i], enable);
-
- return TRUE;
-}
-
-// Show a specific button
-void wxRadioBox::Show(int item, bool show)
-{
- wxCHECK_RET( item >= 0 && item < m_noItems,
- wxT("invalid item in wxRadioBox::Show()") );
-
- ::ShowWindow((HWND)m_radioButtons[item], show ? SW_SHOW : SW_HIDE);
-}
-
-bool wxRadioBox::ContainsHWND(WXHWND hWnd) const
-{
- size_t count = GetCount();
- for ( size_t i = 0; i < count; i++ )
- {
- if ( GetRadioButtons()[i] == hWnd )
- return TRUE;
- }
-
- return FALSE;
-}
-
-void wxRadioBox::Command(wxCommandEvent & event)
-{
- SetSelection (event.m_commandInt);
- ProcessCommand (event);
-}
-
-// NB: if this code is changed, wxGetWindowForHWND() which relies on having the
-// radiobox pointer in GWL_USERDATA for radio buttons must be updated too!
-void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
-{
- // No GWL_USERDATA in Win16, so omit this subclassing.
-#ifdef __WIN32__
- HWND hwndBtn = (HWND)hWndBtn;
-
- if ( !s_wndprocRadioBtn )
- s_wndprocRadioBtn = (WXFARPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC);
-
- ::SetWindowLong(hwndBtn, GWL_WNDPROC, (long)wxRadioBtnWndProc);
- ::SetWindowLong(hwndBtn, GWL_USERDATA, (long)this);
-#endif // __WIN32__
-}
-
-void wxRadioBox::SendNotificationEvent()
-{
- wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId);
- event.SetInt( m_selectedButton );
- event.SetString( GetString(m_selectedButton) );
- event.SetEventObject( this );
- ProcessCommand(event);
-}
-
-bool wxRadioBox::SetFont(const wxFont& font)
-{
- if ( !wxControl::SetFont(font) )
- {
- // nothing to do
- return FALSE;
- }
-
- // also set the font of our radio buttons
- WXHFONT hfont = wxFont(font).GetResourceHandle();
- for ( int n = 0; n < m_noItems; n++ )
- {
- HWND hwndBtn = (HWND)m_radioButtons[n];
- ::SendMessage(hwndBtn, WM_SETFONT, (WPARAM)hfont, 0L);
-
- // otherwise the buttons are not redrawn correctly
- ::InvalidateRect(hwndBtn, NULL, FALSE /* don't erase bg */);
- }
-
- return TRUE;
-}
-
-// ----------------------------------------------------------------------------
-// our window proc
-// ----------------------------------------------------------------------------
-
-long wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
-{
- switch ( nMsg )
- {
-#ifdef __WIN32__
- case WM_CTLCOLORSTATIC:
- // set the colour of the radio buttons to be the same as ours
- {
- HDC hdc = (HDC)wParam;
-
- const wxColour& colBack = GetBackgroundColour();
- ::SetBkColor(hdc, wxColourToRGB(colBack));
- ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
-
- wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
-
- return (WXHBRUSH)brush->GetResourceHandle();
- }
-#endif // Win32
-
- // VZ: this code breaks radiobox redrawing under Windows XP, don't use
- // it. If you need to get messages from the static controls,
- // create them as a child of another (non static) window
-#if 0
- // This is required for the radiobox to be sensitive to mouse input,
- // e.g. for Dialog Editor.
- case WM_NCHITTEST:
- {
- int xPos = LOWORD(lParam); // horizontal position of cursor
- int yPos = HIWORD(lParam); // vertical position of cursor
-
- ScreenToClient(&xPos, &yPos);
-
- // Make sure you can drag by the top of the groupbox, but let
- // other (enclosed) controls get mouse events also
- if (yPos < 10)
- return (long)HTCLIENT;
- }
- break;
-#endif // 0
- }
-
- return wxControl::MSWWindowProc(nMsg, wParam, lParam);
-}
-
-WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
-#if wxUSE_CTL3D
- WXUINT message,
- WXWPARAM wParam,
- WXLPARAM lParam
-#else
- WXUINT WXUNUSED(message),
- WXWPARAM WXUNUSED(wParam),
- WXLPARAM WXUNUSED(lParam)
-#endif
- )
-{
-#if wxUSE_CTL3D
- if ( m_useCtl3D )
- {
- HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
- return (WXHBRUSH) hbrush;
- }
-#endif // wxUSE_CTL3D
-
- HDC hdc = (HDC)pDC;
- wxColour colBack = GetBackgroundColour();
-
- if (!IsEnabled())
- colBack = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
-
- ::SetBkColor(hdc, wxColourToRGB(colBack));
- ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
-
- wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
-
- return (WXHBRUSH)brush->GetResourceHandle();
-}
-
-