]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobut.cpp
Put the call to CheckForKeyDown() back in to ProcessXEvent because key down events...
[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"
dcf924a3
RR
16
17#if wxUSE_RADIOBOX
18
83624f79
RR
19#include "gdk/gdk.h"
20#include "gtk/gtk.h"
c801d85f 21
acfd422a
RR
22//-----------------------------------------------------------------------------
23// idle system
24//-----------------------------------------------------------------------------
25
26extern void wxapp_install_idle_handler();
27extern bool g_isIdle;
28
6de97a3b
RR
29//-----------------------------------------------------------------------------
30// data
31//-----------------------------------------------------------------------------
32
33extern bool g_blockEventsOnDrag;
34
35//-----------------------------------------------------------------------------
bb4549de 36// "clicked"
6de97a3b
RR
37//-----------------------------------------------------------------------------
38
bb4549de
RR
39static
40void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioButton *rb )
6de97a3b 41{
acfd422a
RR
42 if (g_isIdle) wxapp_install_idle_handler();
43
a2053b27 44 if (!rb->m_hasVMT) return;
bb4549de 45
f5d29b39 46 if (g_blockEventsOnDrag) return;
6de97a3b 47
f5d29b39
RR
48 wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId());
49 event.SetInt( rb->GetValue() );
50 event.SetEventObject( rb );
51 rb->GetEventHandler()->ProcessEvent( event );
6de97a3b
RR
52}
53
bb4549de
RR
54//-----------------------------------------------------------------------------
55// wxRadioButton
56//-----------------------------------------------------------------------------
57
58IMPLEMENT_DYNAMIC_CLASS(wxRadioButton,wxControl)
59
6de97a3b
RR
60bool wxRadioButton::Create( wxWindow *parent, wxWindowID id, const wxString& label,
61 const wxPoint& pos, const wxSize& size, long style,
62 const wxValidator& validator, const wxString& name )
63{
b292e2f5 64 m_acceptsFocus = TRUE;
f5d29b39 65 m_needParent = TRUE;
953704c1 66 m_isRadioButton = TRUE;
6de97a3b 67
4dcaf11a
RR
68 if (!PreCreation( parent, pos, size ) ||
69 !CreateBase( parent, id, pos, size, style, validator, name ))
70 {
71 wxFAIL_MSG( _T("wxRadioButton creation failed") );
72 return FALSE;
73 }
953704c1
RR
74
75 if (HasFlag(wxRB_GROUP))
76 {
77 /* start a new group */
78 m_radioButtonGroup = (GSList*) NULL;
79 }
80 else
81 {
82 /* search backward for last group start */
83 wxRadioButton *chief = (wxRadioButton*) NULL;
84 wxWindowList::Node *node = parent->GetChildren().GetLast();
85 while (node)
86 {
87 wxWindow *child = node->GetData();
88 if (child->m_isRadioButton)
89 {
90 chief = (wxRadioButton*) child;
91 if (child->HasFlag(wxRB_GROUP)) break;
92 }
953704c1
RR
93 node = node->GetPrevious();
94 }
0544bc0a
RR
95 if (chief)
96 {
97 /* we are part of the group started by chief */
98 m_radioButtonGroup = gtk_radio_button_group( GTK_RADIO_BUTTON(chief->m_widget) );
99 }
100 else
101 {
102 /* start a new group */
103 m_radioButtonGroup = (GSList*) NULL;
104 }
953704c1
RR
105 }
106
107 m_widget = gtk_radio_button_new_with_label( m_radioButtonGroup, label.mbc_str() );
6de97a3b 108
f5d29b39 109 SetLabel(label);
6de97a3b 110
4dcaf11a 111 wxSize newSize = size;
b019151f 112 if (newSize.x == -1) newSize.x = 22+gdk_string_measure( m_widget->style->font, label.mbc_str() );
f5d29b39
RR
113 if (newSize.y == -1) newSize.y = 26;
114 SetSize( newSize.x, newSize.y );
6de97a3b 115
f5d29b39
RR
116 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
117 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
6de97a3b 118
f03fc89f 119 m_parent->DoAddChild( this );
6ca41e57 120
f5d29b39 121 PostCreation();
6de97a3b 122
f5d29b39
RR
123 SetBackgroundColour( parent->GetBackgroundColour() );
124 SetForegroundColour( parent->GetForegroundColour() );
a7ac4461 125 SetFont( parent->GetFont() );
58614078 126
f5d29b39 127 Show( TRUE );
6de97a3b 128
f5d29b39 129 return TRUE;
6de97a3b
RR
130}
131
132void wxRadioButton::SetLabel( const wxString& label )
133{
b019151f 134 wxCHECK_RET( m_widget != NULL, _T("invalid radiobutton") );
f96aa4d9 135
f5d29b39
RR
136 wxControl::SetLabel( label );
137 GtkButton *bin = GTK_BUTTON( m_widget );
138 GtkLabel *g_label = GTK_LABEL( bin->child );
b019151f 139 gtk_label_set( g_label, GetLabel().mbc_str() );
6de97a3b
RR
140}
141
142void wxRadioButton::SetValue( bool val )
143{
b019151f 144 wxCHECK_RET( m_widget != NULL, _T("invalid radiobutton") );
f96aa4d9 145
953704c1 146 if (val == GetValue())
0659e7ee
RR
147 return;
148
953704c1
RR
149 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
150 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
151
f5d29b39 152 if (val)
953704c1 153 {
f5d29b39 154 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), TRUE );
953704c1 155 }
f5d29b39 156 else
953704c1
RR
157 {
158 // should give an assert
159 }
160
161 gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
162 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
6de97a3b
RR
163}
164
eb082a08 165bool wxRadioButton::GetValue() const
6de97a3b 166{
b019151f 167 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid radiobutton") );
f96aa4d9 168
f5d29b39 169 return GTK_TOGGLE_BUTTON(m_widget)->active;
6de97a3b
RR
170}
171
f03fc89f 172bool wxRadioButton::Enable( bool enable )
d3904ceb 173{
f03fc89f
VZ
174 if ( !wxControl::Enable( enable ) )
175 return FALSE;
f96aa4d9 176
f5d29b39 177 gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
f03fc89f
VZ
178
179 return TRUE;
d3904ceb
RR
180}
181
58614078 182void wxRadioButton::ApplyWidgetStyle()
868a2826 183{
f5d29b39
RR
184 SetWidgetStyle();
185 gtk_widget_set_style( m_widget, m_widgetStyle );
186 gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
f96aa4d9 187}
dcf924a3
RR
188
189#endif