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