added radio button (which doesn't work yet)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8314 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-09-09 22:39:59 +00:00
parent a02336b2bb
commit bc2dad04e7
10 changed files with 313 additions and 29 deletions

View File

@@ -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

View File

@@ -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_

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 <zeitlin@dptmaths.ens-cachan.fr>
// 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_

View File

@@ -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

View File

@@ -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

125
src/univ/radiobut.cpp Normal file
View File

@@ -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

View File

@@ -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,7 +497,7 @@ wxColour wxGTKColourScheme::Get(wxGTKColourScheme::StdColour col) const
#if wxUSE_CHECKBOX
wxBitmap wxGTKColourScheme::Get(wxCheckBox::State state,
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
// ============================================================================

View File

@@ -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,7 +574,7 @@ static char *pressed_unchecked_xpm[] = {
"hhhhhhhhhhhhh"
};
wxBitmap wxWin32ColourScheme::Get(wxCheckBox::State state,
wxBitmap wxWin32ColourScheme::GetCheckBitmap(wxCheckBox::State state,
wxCheckBox::Status status)
{
char **xpm;
@@ -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
// ============================================================================