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