]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/radiobut.cpp
Added zillions of #if wxUSE_XXX
[wxWidgets.git] / src / gtk1 / 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 #if wxUSE_RADIOBOX
18
19 #include "gdk/gdk.h"
20 #include "gtk/gtk.h"
21
22 //-----------------------------------------------------------------------------
23 // idle system
24 //-----------------------------------------------------------------------------
25
26 extern void wxapp_install_idle_handler();
27 extern bool g_isIdle;
28
29 //-----------------------------------------------------------------------------
30 // data
31 //-----------------------------------------------------------------------------
32
33 extern bool g_blockEventsOnDrag;
34
35 //-----------------------------------------------------------------------------
36 // "clicked"
37 //-----------------------------------------------------------------------------
38
39 static
40 void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb )
41 {
42 if (g_isIdle) wxapp_install_idle_handler();
43
44 if (!rb->m_hasVMT) return;
45
46 if (rb->m_blockFirstEvent)
47 {
48 rb->m_blockFirstEvent = FALSE;
49 return;
50 }
51
52 if (g_blockEventsOnDrag) return;
53
54 wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId());
55 event.SetInt( rb->GetValue() );
56 event.SetEventObject( rb );
57 rb->GetEventHandler()->ProcessEvent( event );
58 }
59
60 //-----------------------------------------------------------------------------
61 // wxRadioButton
62 //-----------------------------------------------------------------------------
63
64 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton,wxControl)
65
66 bool wxRadioButton::Create( wxWindow *parent, wxWindowID id, const wxString& label,
67 const wxPoint& pos, const wxSize& size, long style,
68 const wxValidator& validator, const wxString& name )
69 {
70 m_acceptsFocus = TRUE;
71 m_needParent = TRUE;
72
73 wxSize newSize = size;
74
75 PreCreation( parent, id, pos, newSize, style, name );
76
77 SetValidator( validator );
78
79 m_widget = gtk_radio_button_new_with_label( (GSList *) NULL, label.mbc_str() );
80
81 m_theOtherRadioButtton =
82 gtk_radio_button_new_with_label(
83 gtk_radio_button_group( GTK_RADIO_BUTTON(m_widget) ),
84 "button2" );
85
86 SetLabel(label);
87
88 m_blockFirstEvent = FALSE;
89
90 if (newSize.x == -1) newSize.x = 22+gdk_string_measure( m_widget->style->font, label.mbc_str() );
91 if (newSize.y == -1) newSize.y = 26;
92 SetSize( newSize.x, newSize.y );
93
94 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
95 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
96
97 m_parent->DoAddChild( this );
98
99 PostCreation();
100
101 SetBackgroundColour( parent->GetBackgroundColour() );
102 SetForegroundColour( parent->GetForegroundColour() );
103 SetFont( parent->GetFont() );
104
105 Show( TRUE );
106
107 return TRUE;
108 }
109
110 void wxRadioButton::SetLabel( const wxString& label )
111 {
112 wxCHECK_RET( m_widget != NULL, _T("invalid radiobutton") );
113
114 wxControl::SetLabel( label );
115 GtkButton *bin = GTK_BUTTON( m_widget );
116 GtkLabel *g_label = GTK_LABEL( bin->child );
117 gtk_label_set( g_label, GetLabel().mbc_str() );
118 }
119
120 void wxRadioButton::SetValue( bool val )
121 {
122 wxCHECK_RET( m_widget != NULL, _T("invalid radiobutton") );
123
124 if ( val == GetValue() )
125 return;
126
127 m_blockFirstEvent = TRUE;
128
129 if (val)
130 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), TRUE );
131 else
132 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_theOtherRadioButtton), TRUE );
133 }
134
135 bool wxRadioButton::GetValue() const
136 {
137 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid radiobutton") );
138
139 return GTK_TOGGLE_BUTTON(m_widget)->active;
140 }
141
142 bool wxRadioButton::Enable( bool enable )
143 {
144 if ( !wxControl::Enable( enable ) )
145 return FALSE;
146
147 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
148
149 return TRUE;
150 }
151
152 void wxRadioButton::ApplyWidgetStyle()
153 {
154 SetWidgetStyle();
155 gtk_widget_set_style( m_widget, m_widgetStyle );
156 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
157 }
158
159 #endif