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