]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobut.cpp
(ugh, I need to get a faster computer)
[wxWidgets.git] / src / gtk / radiobut.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobut.cpp
3// Purpose:
4// Author: Robert Roebling
f96aa4d9
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
c801d85f
KB
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "radiobut.h"
13#endif
14
15#include "wx/radiobut.h"
83624f79
RR
16#include "gdk/gdk.h"
17#include "gtk/gtk.h"
c801d85f 18
6de97a3b
RR
19//-----------------------------------------------------------------------------
20// data
21//-----------------------------------------------------------------------------
22
23extern bool g_blockEventsOnDrag;
24
25//-----------------------------------------------------------------------------
bb4549de 26// "clicked"
6de97a3b
RR
27//-----------------------------------------------------------------------------
28
bb4549de
RR
29static
30void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb )
6de97a3b 31{
f5d29b39 32 if (!rb->HasVMT()) return;
bb4549de 33
f5d29b39
RR
34 if (rb->m_blockFirstEvent)
35 {
36 rb->m_blockFirstEvent = FALSE;
37 return;
38 }
bb4549de 39
f5d29b39 40 if (g_blockEventsOnDrag) return;
6de97a3b 41
f5d29b39
RR
42 wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId());
43 event.SetInt( rb->GetValue() );
44 event.SetEventObject( rb );
45 rb->GetEventHandler()->ProcessEvent( event );
6de97a3b
RR
46}
47
bb4549de
RR
48//-----------------------------------------------------------------------------
49// wxRadioButton
50//-----------------------------------------------------------------------------
51
52IMPLEMENT_DYNAMIC_CLASS(wxRadioButton,wxControl)
53
6de97a3b
RR
54bool wxRadioButton::Create( wxWindow *parent, wxWindowID id, const wxString& label,
55 const wxPoint& pos, const wxSize& size, long style,
56 const wxValidator& validator, const wxString& name )
57{
b292e2f5 58 m_acceptsFocus = TRUE;
f5d29b39 59 m_needParent = TRUE;
6de97a3b 60
f5d29b39 61 wxSize newSize = size;
6de97a3b 62
f5d29b39 63 PreCreation( parent, id, pos, newSize, style, name );
6de97a3b 64
f5d29b39 65 SetValidator( validator );
6de97a3b 66
b019151f 67 m_widget = gtk_radio_button_new_with_label( (GSList *) NULL, label.mbc_str() );
6de97a3b 68
f5d29b39
RR
69 m_theOtherRadioButtton =
70 gtk_radio_button_new_with_label(
71 gtk_radio_button_group( GTK_RADIO_BUTTON(m_widget) ),
72 "button2" );
73
74 SetLabel(label);
6de97a3b 75
f5d29b39 76 m_blockFirstEvent = FALSE;
bb4549de 77
b019151f 78 if (newSize.x == -1) newSize.x = 22+gdk_string_measure( m_widget->style->font, label.mbc_str() );
f5d29b39
RR
79 if (newSize.y == -1) newSize.y = 26;
80 SetSize( newSize.x, newSize.y );
6de97a3b 81
f5d29b39
RR
82 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
83 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
6de97a3b 84
f5d29b39 85 m_parent->AddChild( this );
e6b5bded 86
f5d29b39 87 (m_parent->m_insertCallback)( m_parent, this );
6ca41e57 88
f5d29b39 89 PostCreation();
6de97a3b 90
f5d29b39
RR
91 SetBackgroundColour( parent->GetBackgroundColour() );
92 SetForegroundColour( parent->GetForegroundColour() );
a7ac4461 93 SetFont( parent->GetFont() );
58614078 94
f5d29b39 95 Show( TRUE );
6de97a3b 96
f5d29b39 97 return TRUE;
6de97a3b
RR
98}
99
100void wxRadioButton::SetLabel( const wxString& label )
101{
b019151f 102 wxCHECK_RET( m_widget != NULL, _T("invalid radiobutton") );
f96aa4d9 103
f5d29b39
RR
104 wxControl::SetLabel( label );
105 GtkButton *bin = GTK_BUTTON( m_widget );
106 GtkLabel *g_label = GTK_LABEL( bin->child );
b019151f 107 gtk_label_set( g_label, GetLabel().mbc_str() );
6de97a3b
RR
108}
109
110void wxRadioButton::SetValue( bool val )
111{
b019151f 112 wxCHECK_RET( m_widget != NULL, _T("invalid radiobutton") );
f96aa4d9 113
0659e7ee
RR
114 if ( val == GetValue() )
115 return;
116
f5d29b39 117 m_blockFirstEvent = TRUE;
ae0bdb01 118
f5d29b39
RR
119 if (val)
120 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), TRUE );
121 else
122 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_theOtherRadioButtton), TRUE );
6de97a3b
RR
123}
124
125bool wxRadioButton::GetValue(void) const
126{
b019151f 127 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid radiobutton") );
f96aa4d9 128
f5d29b39 129 return GTK_TOGGLE_BUTTON(m_widget)->active;
6de97a3b
RR
130}
131
d3904ceb
RR
132void wxRadioButton::Enable( bool enable )
133{
b019151f 134 wxCHECK_RET( m_widget != NULL, _T("invalid radiobutton") );
f96aa4d9 135
f5d29b39 136 wxControl::Enable( enable );
f96aa4d9 137
f5d29b39 138 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
d3904ceb
RR
139}
140
58614078 141void wxRadioButton::ApplyWidgetStyle()
868a2826 142{
f5d29b39
RR
143 SetWidgetStyle();
144 gtk_widget_set_style( m_widget, m_widgetStyle );
145 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
f96aa4d9 146}