]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/radiobut.cpp
1 - fixed listbox.cpp to work with events with m_commandString member as wxString...
[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 #include "gdk/gdk.h"
17 #include "gtk/gtk.h"
18
19 //-----------------------------------------------------------------------------
20 // data
21 //-----------------------------------------------------------------------------
22
23 extern bool g_blockEventsOnDrag;
24
25 //-----------------------------------------------------------------------------
26 // "clicked"
27 //-----------------------------------------------------------------------------
28
29 static
30 void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb )
31 {
32 if (!rb->HasVMT()) return;
33
34 if (rb->m_blockFirstEvent)
35 {
36 rb->m_blockFirstEvent = FALSE;
37 return;
38 }
39
40 if (g_blockEventsOnDrag) return;
41
42 wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId());
43 event.SetInt( rb->GetValue() );
44 event.SetEventObject( rb );
45 rb->GetEventHandler()->ProcessEvent( event );
46 }
47
48 //-----------------------------------------------------------------------------
49 // wxRadioButton
50 //-----------------------------------------------------------------------------
51
52 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton,wxControl)
53
54 bool 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 {
58 m_acceptsFocus = TRUE;
59 m_needParent = TRUE;
60
61 wxSize newSize = size;
62
63 PreCreation( parent, id, pos, newSize, style, name );
64
65 SetValidator( validator );
66
67 m_widget = gtk_radio_button_new_with_label( (GSList *) NULL, label );
68
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);
75
76 m_blockFirstEvent = FALSE;
77
78 if (newSize.x == -1) newSize.x = 22+gdk_string_measure( m_widget->style->font, label );
79 if (newSize.y == -1) newSize.y = 26;
80 SetSize( newSize.x, newSize.y );
81
82 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
83 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
84
85 m_parent->AddChild( this );
86
87 (m_parent->m_insertCallback)( m_parent, this );
88
89 PostCreation();
90
91 SetBackgroundColour( parent->GetBackgroundColour() );
92 SetForegroundColour( parent->GetForegroundColour() );
93 SetFont( parent->GetFont() );
94
95 Show( TRUE );
96
97 return TRUE;
98 }
99
100 void wxRadioButton::SetLabel( const wxString& label )
101 {
102 wxCHECK_RET( m_widget != NULL, "invalid radiobutton" );
103
104 wxControl::SetLabel( label );
105 GtkButton *bin = GTK_BUTTON( m_widget );
106 GtkLabel *g_label = GTK_LABEL( bin->child );
107 gtk_label_set( g_label, GetLabel() );
108 }
109
110 void wxRadioButton::SetValue( bool val )
111 {
112 wxCHECK_RET( m_widget != NULL, "invalid radiobutton" );
113
114 if ( val == GetValue() )
115 return;
116
117 m_blockFirstEvent = TRUE;
118
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 );
123 }
124
125 bool wxRadioButton::GetValue(void) const
126 {
127 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid radiobutton" );
128
129 return GTK_TOGGLE_BUTTON(m_widget)->active;
130 }
131
132 void wxRadioButton::Enable( bool enable )
133 {
134 wxCHECK_RET( m_widget != NULL, "invalid radiobutton" );
135
136 wxControl::Enable( enable );
137
138 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
139 }
140
141 void wxRadioButton::ApplyWidgetStyle()
142 {
143 SetWidgetStyle();
144 gtk_widget_set_style( m_widget, m_widgetStyle );
145 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
146 }
147
148