]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobut.cpp
More clean-up
[wxWidgets.git] / src / gtk / radiobut.cpp
CommitLineData
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
21extern bool g_blockEventsOnDrag;
22
23//-----------------------------------------------------------------------------
bb4549de 24// "clicked"
6de97a3b
RR
25//-----------------------------------------------------------------------------
26
bb4549de
RR
27static
28void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb )
6de97a3b
RR
29{
30 if (!rb->HasVMT()) return;
bb4549de
RR
31
32 if (rb->m_blockFirstEvent)
33 {
34 rb->m_blockFirstEvent = FALSE;
35 return;
36 }
37
6de97a3b
RR
38 if (g_blockEventsOnDrag) return;
39
40 wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId());
41 event.SetInt( rb->GetValue() );
42 event.SetEventObject( rb );
43 rb->GetEventHandler()->ProcessEvent( event );
44}
45
bb4549de
RR
46//-----------------------------------------------------------------------------
47// wxRadioButton
48//-----------------------------------------------------------------------------
49
50IMPLEMENT_DYNAMIC_CLASS(wxRadioButton,wxControl)
51
6de97a3b
RR
52bool 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{
56 m_needParent = TRUE;
57
58 wxSize newSize = size;
59
60 PreCreation( parent, id, pos, newSize, style, name );
61
62 SetValidator( validator );
63
c67daf87 64 m_widget = gtk_radio_button_new_with_label( (GSList *) NULL, label );
6de97a3b
RR
65
66 SetLabel(label);
67
bb4549de
RR
68 m_blockFirstEvent = FALSE;
69
6de97a3b
RR
70 if (newSize.x == -1) newSize.x = 22+gdk_string_measure( m_widget->style->font, label );
71 if (newSize.y == -1) newSize.y = 26;
72 SetSize( newSize.x, newSize.y );
73
74 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
75 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
76
e6b5bded
RR
77 m_parent->AddChild( this );
78
79 (m_parent->m_insertCallback)( m_parent, this );
6ca41e57 80
6de97a3b
RR
81 PostCreation();
82
58614078
RR
83 SetBackgroundColour( parent->GetBackgroundColour() );
84 SetForegroundColour( parent->GetForegroundColour() );
85
6de97a3b
RR
86 Show( TRUE );
87
88 return TRUE;
89}
90
91void wxRadioButton::SetLabel( const wxString& label )
92{
f96aa4d9
RR
93 wxCHECK_RET( m_widget != NULL, "invalid radiobutton" );
94
6de97a3b
RR
95 wxControl::SetLabel( label );
96 GtkButton *bin = GTK_BUTTON( m_widget );
97 GtkLabel *g_label = GTK_LABEL( bin->child );
98 gtk_label_set( g_label, GetLabel() );
99}
100
101void wxRadioButton::SetValue( bool val )
102{
f96aa4d9
RR
103 wxCHECK_RET( m_widget != NULL, "invalid radiobutton" );
104
bb4549de 105 m_blockFirstEvent = TRUE;
ae0bdb01
RR
106
107 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), val );
6de97a3b
RR
108}
109
110bool wxRadioButton::GetValue(void) const
111{
f96aa4d9
RR
112 wxCHECK_MSG( m_widget != NULL, FALSE, "invalid radiobutton" );
113
6de97a3b
RR
114 return GTK_TOGGLE_BUTTON(m_widget)->active;
115}
116
d3904ceb
RR
117void wxRadioButton::Enable( bool enable )
118{
f96aa4d9
RR
119 wxCHECK_RET( m_widget != NULL, "invalid radiobutton" );
120
d3904ceb 121 wxControl::Enable( enable );
f96aa4d9
RR
122
123 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
d3904ceb
RR
124}
125
58614078 126void wxRadioButton::ApplyWidgetStyle()
868a2826 127{
58614078
RR
128 SetWidgetStyle();
129 gtk_widget_set_style( m_widget, m_widgetStyle );
a81258be 130 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
f96aa4d9
RR
131}
132
6de97a3b 133