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