diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h index 010b3c384e..9f779319ae 100644 --- a/include/wx/chkconf.h +++ b/include/wx/chkconf.h @@ -57,6 +57,17 @@ # endif #endif /* controls */ +#if wxUSE_RADIOBTN +# if defined(__WXUNIVERSAL__) && !wxUSE_CHECKBOX +# ifdef wxABORT_ON_CONFIG_ERROR +# error "wxUSE_RADIOBTN requires wxUSE_CHECKBOX in wxUniversal" +# else +# undef wxUSE_CHECKBOX +# define wxUSE_CHECKBOX 1 +# endif +# endif +#endif /* wxUSE_RADIOBTN */ + #if wxUSE_STOPWATCH # if !wxUSE_LONGLONG # ifdef wxABORT_ON_CONFIG_ERROR diff --git a/include/wx/radiobut.h b/include/wx/radiobut.h index 01023e4c17..a5ea84812d 100644 --- a/include/wx/radiobut.h +++ b/include/wx/radiobut.h @@ -1,21 +1,53 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/radiobut.h +// Purpose: wxRadioButton declaration +// Author: Vadim Zeitlin +// Modified by: +// Created: 07.09.00 +// RCS-ID: $Id$ +// Copyright: (c) wxWindows team +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + #ifndef _WX_RADIOBUT_H_BASE_ #define _WX_RADIOBUT_H_BASE_ -#if defined(__WXMSW__) -#include "wx/msw/radiobut.h" +#if wxUSE_RADIOBTN + +/* + There is no wxRadioButtonBase class as wxRadioButton interface is the same + as of wxCheckBox(Base), but under some platforms wxRadioButton really + derives from wxCheckBox and on the others it doesn't. + + The pseudo-declaration of wxRadioButtonBase would look like this: + + class wxRadioButtonBase : public ... + { + public: + virtual void SetValue(bool value); + virtual bool GetValue() const; + }; + */ + +#if defined(__WXUNIVERSAL__) + #include "wx/univ/radiobut.h" +#elif defined(__WXMSW__) + #include "wx/msw/radiobut.h" #elif defined(__WXMOTIF__) -#include "wx/motif/radiobut.h" + #include "wx/motif/radiobut.h" #elif defined(__WXGTK__) -#include "wx/gtk/radiobut.h" + #include "wx/gtk/radiobut.h" #elif defined(__WXQT__) -#include "wx/qt/radiobut.h" + #include "wx/qt/radiobut.h" #elif defined(__WXMAC__) -#include "wx/mac/radiobut.h" + #include "wx/mac/radiobut.h" #elif defined(__WXPM__) -#include "wx/os2/radiobut.h" + #include "wx/os2/radiobut.h" #elif defined(__WXSTUBS__) -#include "wx/stubs/radiobut.h" + #include "wx/stubs/radiobut.h" #endif +#endif // wxUSE_RADIOBTN + #endif // _WX_RADIOBUT_H_BASE_ diff --git a/include/wx/univ/checkbox.h b/include/wx/univ/checkbox.h index 525e7b0b31..53599acd78 100644 --- a/include/wx/univ/checkbox.h +++ b/include/wx/univ/checkbox.h @@ -83,13 +83,12 @@ public: // set/get the bitmaps to use for the checkbox indicator void SetBitmap(const wxBitmap& bmp, State state, Status status); - wxBitmap GetBitmap(State state, Status status) const; + virtual wxBitmap GetBitmap(State state, Status status) const; // wxCheckBox actions void Toggle(); virtual void Press(); virtual void Release(); - virtual void Click(); virtual void ChangeValue(bool value); // overridden base class virtuals @@ -108,6 +107,14 @@ protected: // common part of all ctors void Init(); + // send command event notifying about the checkbox state change + void SendEvent(); + + // directly access the bitmaps array without trying to find a valid bitmap + // to use as GetBitmap() does + wxBitmap DoGetBitmap(State state, Status status) const + { return m_bitmaps[state][status]; } + private: // the current check status Status m_status; diff --git a/include/wx/univ/colschem.h b/include/wx/univ/colschem.h index be2caf76d3..6cdb5629b1 100644 --- a/include/wx/univ/colschem.h +++ b/include/wx/univ/colschem.h @@ -64,10 +64,15 @@ public: // get a standard colour virtual wxColour Get(StdColour col) const = 0; -#if wxUSE_CHECKBOX // get a standard bitmap - virtual wxBitmap Get(wxCheckBox::State state, wxCheckBox::Status status) = 0; +#if wxUSE_CHECKBOX + virtual wxBitmap GetCheckBitmap(wxCheckBox::State state, + wxCheckBox::Status status) = 0; #endif // wxUSE_CHECKBOX +#if wxUSE_RADIOBTN + virtual wxBitmap GetRadioBitmap(wxCheckBox::State state, + wxCheckBox::Status status) = 0; +#endif // wxUSE_RADIOBTN // get the background colour for the given window virtual wxColour GetBackground(wxWindow *win) const = 0; diff --git a/include/wx/univ/radiobut.h b/include/wx/univ/radiobut.h new file mode 100644 index 0000000000..d2186a3ff6 --- /dev/null +++ b/include/wx/univ/radiobut.h @@ -0,0 +1,69 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/univ/radiobut.h +// Purpose: wxRadioButton declaration +// Author: Vadim Zeitlin +// Modified by: +// Created: 10.09.00 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Vadim Zeitlin +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_UNIV_RADIOBUT_H_ +#define _WX_UNIV_RADIOBUT_H_ + +#ifdef __GNUG__ + #pragma interface "univradiobut.h" +#endif + +// ---------------------------------------------------------------------------- +// wxRadioButton +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxRadioButton : public wxCheckBox +{ +public: + // constructors + wxRadioButton() { Init(); } + + wxRadioButton(wxWindow *parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxCheckBoxNameStr) + { + Init(); + + Create(parent, id, label, pos, size, style, validator, name); + } + + bool Create(wxWindow *parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxCheckBoxNameStr); + + // override some base class methods + virtual void ChangeValue(bool value); + virtual wxBitmap GetBitmap(State state, Status status) const; + +protected: + // the radio button can only be cleared using this method, not + // ChangeValue() above - and it is protected as it can only be called by + // another radiobutton + void ClearValue(); + + // send event about radio button selection + void SendEvent(); + +private: + DECLARE_DYNAMIC_CLASS(wxRadioButton) +}; + +#endif // _WX_UNIV_RADIOBUT_H_ diff --git a/include/wx/univ/setup.h b/include/wx/univ/setup.h index 1b5cea6a6f..a5f6ecbd45 100644 --- a/include/wx/univ/setup.h +++ b/include/wx/univ/setup.h @@ -77,7 +77,7 @@ #define wxUSE_LISTBOX 1 #define wxUSE_LISTCTRL 0 #define wxUSE_RADIOBOX 0 -#define wxUSE_RADIOBTN 0 +#define wxUSE_RADIOBTN 1 #define wxUSE_SASH 0 #define wxUSE_SCROLLBAR 1 #define wxUSE_SLIDER 0 diff --git a/src/univ/checkbox.cpp b/src/univ/checkbox.cpp index 44349b2cec..737c197c7b 100644 --- a/src/univ/checkbox.cpp +++ b/src/univ/checkbox.cpp @@ -102,15 +102,20 @@ void wxCheckBox::SetValue(bool value) wxBitmap wxCheckBox::GetBitmap(State state, Status status) const { - wxBitmap bmp = m_bitmaps[state][m_status]; + wxBitmap bmp = m_bitmaps[state][status]; if ( !bmp.Ok() ) - bmp = m_bitmaps[State_Normal][m_status]; + bmp = m_bitmaps[State_Normal][status]; if ( !bmp.Ok() ) - bmp = wxTheme::Get()->GetColourScheme()->Get(state, m_status); + bmp = wxTheme::Get()->GetColourScheme()->GetCheckBitmap(state, status); return bmp; } +void wxCheckBox::SetBitmap(const wxBitmap& bmp, State state, Status status) +{ + m_bitmaps[state][status] = bmp; +} + // ---------------------------------------------------------------------------- // drawing // ---------------------------------------------------------------------------- @@ -199,10 +204,10 @@ void wxCheckBox::ChangeValue(bool value) { SetValue(value); - Click(); + SendEvent(); } -void wxCheckBox::Click() +void wxCheckBox::SendEvent() { wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, GetId()); InitCommandEvent(event); @@ -239,10 +244,6 @@ bool wxCheckBox::PerformAction(const wxControlAction& action, return TRUE; } -#endif // wxUSE_CHECKBOX - -#if wxUSE_CHECKBOX || wxUSE_RADIOBTN - // ---------------------------------------------------------------------------- // wxStdCheckboxInputHandler // ---------------------------------------------------------------------------- @@ -264,4 +265,4 @@ bool wxStdCheckboxInputHandler::HandleMouseMove(wxControl *control, return wxStdButtonInputHandler::HandleMouseMove(control, event); } -#endif // wxUSE_RADIOBTN || wxUSE_CHECKBOX +#endif // wxUSE_CHECKBOX diff --git a/src/univ/radiobut.cpp b/src/univ/radiobut.cpp new file mode 100644 index 0000000000..800e86fb0a --- /dev/null +++ b/src/univ/radiobut.cpp @@ -0,0 +1,125 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: univ/radiobut.cpp +// Purpose: wxRadioButton implementation +// Author: Vadim Zeitlin +// Modified by: +// Created: 10.09.00 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Vadim Zeitlin +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "univradiobut.h" +#endif + +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_RADIOBTN + +#ifndef WX_PRECOMP + #include "wx/dcclient.h" + #include "wx/radiobut.h" + #include "wx/validate.h" +#endif + +#include "wx/univ/theme.h" +#include "wx/univ/renderer.h" +#include "wx/univ/inphand.h" +#include "wx/univ/colschem.h" + +// ============================================================================ +// implementation +// ============================================================================ + +IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) + +// ---------------------------------------------------------------------------- +// wxRadioButton +// ---------------------------------------------------------------------------- + +bool wxRadioButton::Create(wxWindow *parent, + wxWindowID id, + const wxString &label, + const wxPoint &pos, + const wxSize &size, + long style, + const wxValidator& validator, + const wxString &name) +{ + if ( !wxCheckBox::Create(parent, id, label, pos, size, style, + wxDefaultValidator, name) ) + { + return FALSE; + } + + return TRUE; +} + +// ---------------------------------------------------------------------------- +// radio button methods +// ---------------------------------------------------------------------------- + +void wxRadioButton::ChangeValue(bool value) +{ + if ( !IsChecked() && value ) + { + // TODO clear all all others in our group! + + SetValue(TRUE); + + SendEvent(); + } + //else: either nothign chanegd or an attempt was made to clear a checked + // radio button which can't be done +} + +void wxRadioButton::ClearValue() +{ + if ( IsChecked() ) + { + SetValue(FALSE); + } +} + +void wxRadioButton::SendEvent() +{ + wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, GetId()); + InitCommandEvent(event); + event.SetInt(IsChecked()); + Command(event); +} + +// ---------------------------------------------------------------------------- +// indicator bitmaps +// ---------------------------------------------------------------------------- + +wxBitmap wxRadioButton::GetBitmap(State state, Status status) const +{ + // radio buttons don't have "undetermined" status + wxASSERT_MSG( status == Status_Checked || status == Status_Unchecked, + _T("invalid status for a radio button") ); + + wxBitmap bmp = DoGetBitmap(state, status); + if ( !bmp.Ok() ) + bmp = DoGetBitmap(State_Normal, status); + if ( !bmp.Ok() ) + bmp = wxTheme::Get()->GetColourScheme()->GetRadioBitmap(state, status); + + return bmp; +} + +#endif // wxUSE_RADIOBTN + diff --git a/src/univ/themes/gtk.cpp b/src/univ/themes/gtk.cpp index dde1eb783c..a71eb790df 100644 --- a/src/univ/themes/gtk.cpp +++ b/src/univ/themes/gtk.cpp @@ -304,10 +304,17 @@ class wxGTKColourScheme : public wxColourScheme public: virtual wxColour Get(StdColour col) const; virtual wxColour GetBackground(wxWindow *win) const; + #if wxUSE_CHECKBOX - virtual wxBitmap Get(wxCheckBox::State state, wxCheckBox::Status status); + virtual wxBitmap GetCheckBitmap(wxCheckBox::State state, + wxCheckBox::Status status); #endif // wxUSE_CHECKBOX +#if wxUSE_RADIOBTN + virtual wxBitmap GetRadioBitmap(wxCheckBox::State state, + wxCheckBox::Status status); +#endif // wxUSE_RADIOBTN + private: // the checkbox bitmaps: first row is for the normal, second for the // pressed state and the columns are for checked and unchecked status @@ -490,8 +497,8 @@ wxColour wxGTKColourScheme::Get(wxGTKColourScheme::StdColour col) const #if wxUSE_CHECKBOX -wxBitmap wxGTKColourScheme::Get(wxCheckBox::State state, - wxCheckBox::Status status) +wxBitmap wxGTKColourScheme::GetCheckBitmap(wxCheckBox::State state, + wxCheckBox::Status status) { if ( !m_bitmapsCheckbox[0][0].Ok() ) { @@ -533,6 +540,16 @@ wxBitmap wxGTKColourScheme::Get(wxCheckBox::State state, #endif // wxUSE_CHECKBOX +#if wxUSE_RADIOBTN + +wxBitmap wxGTKColourScheme::GetRadioBitmap(wxCheckBox::State state, + wxCheckBox::Status status) +{ + return GetCheckBitmap(state, status); +} + +#endif // wxUSE_RADIOBTN + // ============================================================================ // wxGTKRenderer // ============================================================================ diff --git a/src/univ/themes/win32.cpp b/src/univ/themes/win32.cpp index c332fc7b65..d38950e203 100644 --- a/src/univ/themes/win32.cpp +++ b/src/univ/themes/win32.cpp @@ -285,9 +285,16 @@ class wxWin32ColourScheme : public wxColourScheme public: virtual wxColour Get(StdColour col) const; virtual wxColour GetBackground(wxWindow *win) const; + #if wxUSE_CHECKBOX - virtual wxBitmap Get(wxCheckBox::State state, wxCheckBox::Status status); + virtual wxBitmap GetCheckBitmap(wxCheckBox::State state, + wxCheckBox::Status status); #endif // wxUSE_CHECKBOX + +#if wxUSE_RADIOBTN + virtual wxBitmap GetRadioBitmap(wxCheckBox::State state, + wxCheckBox::Status status); +#endif // wxUSE_RADIOBTN }; // ---------------------------------------------------------------------------- @@ -567,8 +574,8 @@ static char *pressed_unchecked_xpm[] = { "hhhhhhhhhhhhh" }; -wxBitmap wxWin32ColourScheme::Get(wxCheckBox::State state, - wxCheckBox::Status status) +wxBitmap wxWin32ColourScheme::GetCheckBitmap(wxCheckBox::State state, + wxCheckBox::Status status) { char **xpm; if ( status == wxCheckBox::Status_Checked ) @@ -587,6 +594,16 @@ wxBitmap wxWin32ColourScheme::Get(wxCheckBox::State state, #endif // wxUSE_CHECKBOX +#if wxUSE_RADIOBTN + +wxBitmap wxWin32ColourScheme::GetRadioBitmap(wxCheckBox::State state, + wxCheckBox::Status status) +{ + return GetCheckBitmap(state, status); +} + +#endif // wxUSE_RADIOBTN + // ============================================================================ // wxWin32Renderer // ============================================================================