]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/radiobut.cpp
-somewhat more elegant method, supporting the src subdir (-Markus)
[wxWidgets.git] / src / gtk1 / radiobut.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: radiobut.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id:
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11
12 #ifdef __GNUG__
13 #pragma implementation "radiobut.h"
14 #endif
15
16 #include "wx/radiobut.h"
17
18 //-----------------------------------------------------------------------------
19 // data
20 //-----------------------------------------------------------------------------
21
22 extern bool g_blockEventsOnDrag;
23
24 //-----------------------------------------------------------------------------
25 // wxRadioButton
26 //-----------------------------------------------------------------------------
27
28 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton,wxControl)
29
30 static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb )
31 {
32 if (!rb->HasVMT()) return;
33 if (g_blockEventsOnDrag) return;
34
35 wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId());
36 event.SetInt( rb->GetValue() );
37 event.SetEventObject( rb );
38 rb->GetEventHandler()->ProcessEvent( event );
39 }
40
41 bool wxRadioButton::Create( wxWindow *parent, wxWindowID id, const wxString& label,
42 const wxPoint& pos, const wxSize& size, long style,
43 const wxValidator& validator, const wxString& name )
44 {
45 m_needParent = TRUE;
46
47 wxSize newSize = size;
48
49 PreCreation( parent, id, pos, newSize, style, name );
50
51 SetValidator( validator );
52
53 m_widget = gtk_radio_button_new_with_label( NULL, label );
54
55 SetLabel(label);
56
57 if (newSize.x == -1) newSize.x = 22+gdk_string_measure( m_widget->style->font, label );
58 if (newSize.y == -1) newSize.y = 26;
59 SetSize( newSize.x, newSize.y );
60
61 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
62 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
63
64 PostCreation();
65
66 Show( TRUE );
67
68 return TRUE;
69 }
70
71 void wxRadioButton::SetLabel( const wxString& label )
72 {
73 wxControl::SetLabel( label );
74 GtkButton *bin = GTK_BUTTON( m_widget );
75 GtkLabel *g_label = GTK_LABEL( bin->child );
76 gtk_label_set( g_label, GetLabel() );
77 }
78
79 void wxRadioButton::SetValue( bool val )
80 {
81 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), val );
82 }
83
84 bool wxRadioButton::GetValue(void) const
85 {
86 return GTK_TOGGLE_BUTTON(m_widget)->active;
87 }
88
89