X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce3ed50dbe32d118321082db84c3a9abb047d5b7..180db9083613b9b6eca8451ee19553c6581f5505:/src/msw/radiobut.cpp diff --git a/src/msw/radiobut.cpp b/src/msw/radiobut.cpp index eb067a09a3..c4453ac9ac 100644 --- a/src/msw/radiobut.cpp +++ b/src/msw/radiobut.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: radiobut.cpp +// Name: msw/radiobut.cpp // Purpose: wxRadioButton // Author: Julian Smart // Modified by: @@ -10,36 +10,36 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "radiobut.h" + #pragma implementation "radiobut.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif +#if wxUSE_RADIOBTN + #ifndef WX_PRECOMP -#include -#include "wx/setup.h" -#include "wx/radiobut.h" -#include "wx/brush.h" + #include "wx/radiobut.h" + #include "wx/settings.h" + #include "wx/brush.h" #endif #include "wx/msw/private.h" -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) // IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton) -#endif -bool wxRadioButton::MSWCommand(WXUINT param, WXWORD id) +bool wxRadioButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { if (param == BN_CLICKED) { wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId); event.SetEventObject( this ); + event.SetInt( GetValue() ); ProcessCommand(event); return TRUE; } @@ -54,7 +54,9 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, const wxString& name) { SetName(name); +#if wxUSE_VALIDATORS SetValidator(validator); +#endif // wxUSE_VALIDATORS if (parent) parent->AddChild(this); @@ -78,7 +80,11 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, groupStyle = WS_GROUP; // long msStyle = groupStyle | RADIO_FLAGS; - long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE ; + long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE /* | WS_CLIPSIBLINGS */; + + if ( m_windowStyle & wxCLIP_SIBLINGS ) + msStyle |= WS_CLIPSIBLINGS; + bool want3D; WXDWORD exStyle = Determine3DEffects(0, &want3D) ; @@ -90,13 +96,13 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, msStyle |= WS_BORDER; */ - m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const char *)label, + m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label, msStyle,0,0,0,0, (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); - wxCHECK_MSG( m_hWnd, FALSE, "Failed to create radiobutton" ); + wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") ); -#if CTL3D +#if wxUSE_CTL3D if (want3D) { Ctl3dSubclassCtl((HWND) m_hWnd); @@ -112,7 +118,7 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, // SetValue(value); // start GRW fix - if (label != "") + if (label != wxT("")) { int label_width, label_height; GetTextExtent(label, &label_width, &label_height, NULL, NULL, & this->GetFont()); @@ -136,13 +142,20 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, SetSize(x, y, width, height); + // for compatibility with wxGTK, the first radio button in a group is + // always checked (this makes sense anyhow as you need to ensure that at + // least one button in the group is checked and this is the simlpest way to + // do it) + if ( m_windowStyle & wxRB_GROUP ) + SetValue(TRUE); + return TRUE; } void wxRadioButton::SetLabel(const wxString& label) { - SetWindowText((HWND) GetHWND(), (const char *)label); + SetWindowText((HWND) GetHWND(), (const wxChar *)label); } void wxRadioButton::SetValue(bool value) @@ -157,39 +170,50 @@ bool wxRadioButton::GetValue(void) const return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L) != 0); } -WXHBRUSH wxRadioButton::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +void wxRadioButton::Command (wxCommandEvent & event) { -#if CTL3D - if ( m_useCtl3D ) - { - HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); - return (WXHBRUSH) hbrush; - } + SetValue ( (event.m_commandInt != 0) ); + ProcessCommand (event); +} + +WXHBRUSH wxRadioButton::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 - if (GetParent()->GetTransparentBackground()) - SetBkMode((HDC) pDC, TRANSPARENT); - else - SetBkMode((HDC) pDC, OPAQUE); + HDC hdc = (HDC)pDC; + if (GetParent()->GetTransparentBackground()) + SetBkMode(hdc, TRANSPARENT); + else + SetBkMode(hdc, OPAQUE); - ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); - ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); + wxColour colBack = GetBackgroundColour(); - wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID); + if (!IsEnabled()) + colBack = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); - // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush - // has a zero usage count. -// backgroundBrush->RealizeResource(); - return (WXHBRUSH) backgroundBrush->GetResourceHandle(); -} + ::SetBkColor(hdc, wxColourToRGB(colBack)); + ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour())); -void wxRadioButton::Command (wxCommandEvent & event) -{ - SetValue ( (event.m_commandInt != 0) ); - ProcessCommand (event); -} + wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID); + return (WXHBRUSH)brush->GetResourceHandle(); +} // Not implemented #if 0 @@ -231,7 +255,7 @@ bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id, wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE ); -#if CTL3D +#if wxUSE_CTL3D if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS)) { Ctl3dSubclassCtl((HWND) GetHWND()); @@ -264,3 +288,5 @@ bool wxBitmapRadioButton::GetValue(void) const } #endif + +#endif // wxUSE_RADIOBTN