+#if wxUSE_CTL3D
+ if ( m_useCtl3D )
+ {
+ HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
+ return (WXHBRUSH) hbrush;
+ }
+#endif // wxUSE_CTL3D
+
+ HDC hdc = (HDC)pDC;
+ if (GetParent()->GetTransparentBackground())
+ SetBkMode(hdc, TRANSPARENT);
+ else
+ SetBkMode(hdc, OPAQUE);
+
+ wxColour colBack = GetBackgroundColour();
+
+ if (!IsEnabled())
+ colBack = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
+
+ ::SetBkColor(hdc, wxColourToRGB(colBack));
+ ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
+
+ wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
+
+ return (WXHBRUSH)brush->GetResourceHandle();
+}
+
+
+// ---------------------------------------------------------------------------
+// window proc for radio buttons
+// ---------------------------------------------------------------------------
+
+#ifdef __WIN32__
+
+LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ switch ( message )
+ {
+ case WM_GETDLGCODE:
+ // we must tell IsDialogMessage()/our kbd processing code that we
+ // want to process arrows ourselves because neither of them is
+ // smart enough to handle arrows properly for us
+ {
+ long lDlgCode = ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd,
+ message, wParam, lParam);
+
+ return lDlgCode | DLGC_WANTARROWS;
+ }
+
+#if wxUSE_TOOLTIPS
+ case WM_NOTIFY:
+ {
+ NMHDR* hdr = (NMHDR *)lParam;
+ if ( (int)hdr->code == TTN_NEEDTEXT )
+ {
+ wxRadioBox *radiobox = (wxRadioBox *)
+ ::GetWindowLong(hwnd, GWL_USERDATA);
+
+ 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 *)
+ ::GetWindowLong(hwnd, GWL_USERDATA);
+
+ wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
+
+ bool processed = TRUE;
+
+ bool horz = (radiobox->GetWindowStyle() & wxRA_SPECIFY_COLS) != 0;
+ int num = radiobox->Number(),
+ rows = radiobox->GetNumVer(),
+ cols = radiobox->GetNumHor();
+
+ int selOld = radiobox->GetSelection();
+ int selNew = selOld;
+
+ // wrapping will be handled below for the cases when we
+ // add/substract more than 1 but here otherwise as it's simpler
+ switch ( wParam )
+ {
+ case VK_UP:
+ if ( horz )
+ selNew -= cols;
+ else
+ {
+ if ( selNew )
+ selNew--;
+ else
+ selNew = num - 1;
+ }
+ break;
+
+ case VK_LEFT:
+ if ( horz )
+ {
+ if ( selNew )
+ selNew--;
+ else
+ selNew = num - 1;
+ }
+ else
+ selNew -= rows;
+ break;
+
+ case VK_DOWN:
+ if ( horz )
+ selNew += cols;
+ else
+ {
+ if ( ++selNew == num )
+ selNew = 0;
+ }
+ break;
+
+ case VK_RIGHT:
+ if ( horz )
+ {
+ if ( ++selNew == num )
+ selNew = 0;
+ }
+ else
+ selNew += rows;
+ break;
+
+ default:
+ processed = FALSE;
+ }
+
+ if ( processed )
+ {
+ // ensure that selNew is in range [0..num)
+ if ( selNew >= num )
+ {
+ selNew -= num;
+
+ int dim = horz ? cols : rows;
+ selNew += dim - 1;
+ selNew %= dim;
+ }
+ else if ( selNew < 0 )
+ {
+ selNew += num;
+
+ int dim = horz ? cols : rows;
+ if ( selNew % dim == 0 )
+ {
+ selNew -= dim - 1;
+ }
+ else
+ {
+ selNew++;
+ }
+ }
+
+ if ( selNew != selOld )
+ {
+ radiobox->SetSelection(selNew);
+
+ // emulate the button click
+ radiobox->SendNotificationEvent();
+
+ return 0;
+ }
+ }
+ }
+ break;
+
+#ifdef __WIN32__
+ case WM_HELP:
+ {
+ wxRadioBox *radiobox = (wxRadioBox *)
+ ::GetWindowLong(hwnd, GWL_USERDATA);
+
+ wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
+
+ bool processed = TRUE;
+
+ HELPINFO* info = (HELPINFO*) lParam;
+ // Don't yet process menu help events, just windows
+ if (info->iContextType == HELPINFO_WINDOW)
+ {
+ wxWindow* subjectOfHelp = radiobox;
+ bool eventProcessed = FALSE;
+ while (subjectOfHelp && !eventProcessed)
+ {
+ wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), wxPoint(info->MousePos.x, info->MousePos.y) ) ; // info->iCtrlId);
+ helpEvent.SetEventObject(radiobox);
+ eventProcessed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
+
+ // Go up the window hierarchy until the event is handled (or not)
+ subjectOfHelp = subjectOfHelp->GetParent();
+ }
+ processed = eventProcessed;
+ }
+ else if (info->iContextType == HELPINFO_MENUITEM)
+ {
+ wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
+ helpEvent.SetEventObject(radiobox);
+ processed = radiobox->GetEventHandler()->ProcessEvent(helpEvent);
+ }
+ else processed = FALSE;
+
+ if (processed)
+ return 0;
+
+ break;
+ }
+#endif
+ }
+
+ return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, message, wParam, lParam);