]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: radiobut.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
f96aa4d9 RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
c801d85f KB |
7 | // Licence: wxWindows licence |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "radiobut.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/radiobut.h" | |
16 | ||
6de97a3b RR |
17 | //----------------------------------------------------------------------------- |
18 | // data | |
19 | //----------------------------------------------------------------------------- | |
20 | ||
21 | extern bool g_blockEventsOnDrag; | |
22 | ||
23 | //----------------------------------------------------------------------------- | |
bb4549de | 24 | // "clicked" |
6de97a3b RR |
25 | //----------------------------------------------------------------------------- |
26 | ||
bb4549de RR |
27 | static |
28 | void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb ) | |
6de97a3b | 29 | { |
f5d29b39 | 30 | if (!rb->HasVMT()) return; |
bb4549de | 31 | |
f5d29b39 RR |
32 | if (rb->m_blockFirstEvent) |
33 | { | |
34 | rb->m_blockFirstEvent = FALSE; | |
35 | return; | |
36 | } | |
bb4549de | 37 | |
f5d29b39 | 38 | if (g_blockEventsOnDrag) return; |
6de97a3b | 39 | |
f5d29b39 RR |
40 | wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId()); |
41 | event.SetInt( rb->GetValue() ); | |
42 | event.SetEventObject( rb ); | |
43 | rb->GetEventHandler()->ProcessEvent( event ); | |
6de97a3b RR |
44 | } |
45 | ||
bb4549de RR |
46 | //----------------------------------------------------------------------------- |
47 | // wxRadioButton | |
48 | //----------------------------------------------------------------------------- | |
49 | ||
50 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton,wxControl) | |
51 | ||
6de97a3b RR |
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 | { | |
b292e2f5 | 56 | m_acceptsFocus = TRUE; |
f5d29b39 | 57 | m_needParent = TRUE; |
6de97a3b | 58 | |
f5d29b39 | 59 | wxSize newSize = size; |
6de97a3b | 60 | |
f5d29b39 | 61 | PreCreation( parent, id, pos, newSize, style, name ); |
6de97a3b | 62 | |
f5d29b39 | 63 | SetValidator( validator ); |
6de97a3b | 64 | |
f5d29b39 | 65 | m_widget = gtk_radio_button_new_with_label( (GSList *) NULL, label ); |
6de97a3b | 66 | |
f5d29b39 RR |
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); | |
6de97a3b | 73 | |
f5d29b39 | 74 | m_blockFirstEvent = FALSE; |
bb4549de | 75 | |
f5d29b39 RR |
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 ); | |
6de97a3b | 79 | |
f5d29b39 RR |
80 | gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", |
81 | GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); | |
6de97a3b | 82 | |
f5d29b39 | 83 | m_parent->AddChild( this ); |
e6b5bded | 84 | |
f5d29b39 | 85 | (m_parent->m_insertCallback)( m_parent, this ); |
6ca41e57 | 86 | |
f5d29b39 | 87 | PostCreation(); |
6de97a3b | 88 | |
f5d29b39 RR |
89 | SetBackgroundColour( parent->GetBackgroundColour() ); |
90 | SetForegroundColour( parent->GetForegroundColour() ); | |
58614078 | 91 | |
f5d29b39 | 92 | Show( TRUE ); |
6de97a3b | 93 | |
f5d29b39 | 94 | return TRUE; |
6de97a3b RR |
95 | } |
96 | ||
97 | void wxRadioButton::SetLabel( const wxString& label ) | |
98 | { | |
f5d29b39 | 99 | wxCHECK_RET( m_widget != NULL, "invalid radiobutton" ); |
f96aa4d9 | 100 | |
f5d29b39 RR |
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() ); | |
6de97a3b RR |
105 | } |
106 | ||
107 | void wxRadioButton::SetValue( bool val ) | |
108 | { | |
f5d29b39 | 109 | wxCHECK_RET( m_widget != NULL, "invalid radiobutton" ); |
f96aa4d9 | 110 | |
f5d29b39 | 111 | m_blockFirstEvent = TRUE; |
ae0bdb01 | 112 | |
f5d29b39 RR |
113 | if (val) |
114 | gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), TRUE ); | |
115 | else | |
116 | gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_theOtherRadioButtton), TRUE ); | |
6de97a3b RR |
117 | } |
118 | ||
119 | bool wxRadioButton::GetValue(void) const | |
120 | { | |
f5d29b39 | 121 | wxCHECK_MSG( m_widget != NULL, FALSE, "invalid radiobutton" ); |
f96aa4d9 | 122 | |
f5d29b39 | 123 | return GTK_TOGGLE_BUTTON(m_widget)->active; |
6de97a3b RR |
124 | } |
125 | ||
d3904ceb RR |
126 | void wxRadioButton::Enable( bool enable ) |
127 | { | |
f5d29b39 | 128 | wxCHECK_RET( m_widget != NULL, "invalid radiobutton" ); |
f96aa4d9 | 129 | |
f5d29b39 | 130 | wxControl::Enable( enable ); |
f96aa4d9 | 131 | |
f5d29b39 | 132 | gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable ); |
d3904ceb RR |
133 | } |
134 | ||
58614078 | 135 | void wxRadioButton::ApplyWidgetStyle() |
868a2826 | 136 | { |
f5d29b39 RR |
137 | SetWidgetStyle(); |
138 | gtk_widget_set_style( m_widget, m_widgetStyle ); | |
139 | gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle ); | |
f96aa4d9 RR |
140 | } |
141 | ||
6de97a3b | 142 |