X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/debe6624c1e9d4bf3243381153d1e173c849bcd8..585266618c27ac77a5e5316c03e06ffc514715c9:/src/msw/radiobut.cpp diff --git a/src/msw/radiobut.cpp b/src/msw/radiobut.cpp index 47783bcd87..a9a7705f60 100644 --- a/src/msw/radiobut.cpp +++ b/src/msw/radiobut.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -24,34 +24,49 @@ #include #include "wx/setup.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) +{ + if (param == BN_CLICKED) + { + wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId); + event.SetEventObject( this ); + event.SetInt( GetValue() ); + ProcessCommand(event); + return TRUE; + } + else return FALSE; +} bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, - const wxString& label, + const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { SetName(name); +#if wxUSE_VALIDATORS SetValidator(validator); +#endif // wxUSE_VALIDATORS if (parent) parent->AddChild(this); - SetBackgroundColour(parent->GetDefaultBackgroundColour()); - SetForegroundColour(parent->GetDefaultForegroundColour()); + SetBackgroundColour(parent->GetBackgroundColour()); + SetForegroundColour(parent->GetForegroundColour()); if ( id == -1 ) - m_windowId = (int)NewControlId(); + m_windowId = (int)NewControlId(); else - m_windowId = id; + m_windowId = id; int x = pos.x; int y = pos.y; @@ -65,29 +80,33 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, groupStyle = WS_GROUP; // long msStyle = groupStyle | RADIO_FLAGS; - long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ; + long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE /* | WS_CLIPSIBLINGS */; bool want3D; WXDWORD exStyle = Determine3DEffects(0, &want3D) ; // Even with extended styles, need to combine with WS_BORDER // for them to look right. - if (want3D && ((m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) || - (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER))) +/* + if ( want3D || wxStyleHasBorder(m_windowStyle) ) 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); -#if CTL3D + + wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") ); + +#if wxUSE_CTL3D if (want3D) { Ctl3dSubclassCtl((HWND) m_hWnd); - m_useCtl3D = TRUE; + m_useCtl3D = TRUE; } #endif - SetFont(* parent->GetFont()); + SetFont(parent->GetFont()); // Subclass again for purposes of dialog editing mode SubclassWin((WXHWND)m_hWnd); @@ -95,10 +114,10 @@ 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, GetFont()); + GetTextExtent(label, &label_width, &label_height, NULL, NULL, & this->GetFont()); if (width < 0) width = (int)(label_width + RADIO_SIZE); if (height<0) @@ -125,7 +144,7 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, void wxRadioButton::SetLabel(const wxString& label) { - SetWindowText((HWND) GetHWND(), (const char *)label); + SetWindowText((HWND) GetHWND(), (const wxChar *)label); } void wxRadioButton::SetValue(bool value) @@ -134,50 +153,54 @@ void wxRadioButton::SetValue(bool value) SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L); } -// Get single selection, for single choice list items +// Get single selection bool wxRadioButton::GetValue(void) const { - return (SendMessage((HWND) GetHWND(), BM_SETCHECK, 0, 0L) != 0); + return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L) != 0); +} + +void wxRadioButton::Command (wxCommandEvent & event) +{ + SetValue ( (event.m_commandInt != 0) ); + ProcessCommand (event); } WXHBRUSH wxRadioButton::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) + WXUINT message, + WXWPARAM wParam, + WXLPARAM lParam) { -#if CTL3D - if ( m_useCtl3D ) - { - HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); - return (WXHBRUSH) hbrush; - } -#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 bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id, - const wxBitmap *bitmap, + const wxBitmap *bitmap, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, @@ -187,13 +210,13 @@ bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id, SetValidator(validator); if (parent) parent->AddChild(this); - SetBackgroundColour(parent->GetDefaultBackgroundColour()); - SetForegroundColour(parent->GetDefaultForegroundColour()); + SetBackgroundColour(parent->GetBackgroundColour()); + SetForegroundColour(parent->GetForegroundColour()); if ( id == -1 ) - m_windowId = (int)NewControlId(); + m_windowId = (int)NewControlId(); else - m_windowId = id; + m_windowId = id; int x = pos.x; int y = pos.y; @@ -211,11 +234,14 @@ bool wxBitmapRadioButton::Create(wxWindow *parent, wxWindowID id, m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle", msStyle,0,0,0,0, (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); -#if CTL3D + + wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE ); + +#if wxUSE_CTL3D if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS)) { Ctl3dSubclassCtl((HWND) GetHWND()); - m_useCtl3D = TRUE; + m_useCtl3D = TRUE; } #endif