]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobut.cpp
Tinderbox build fix.
[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
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
dcf924a3
RR
12
13#if wxUSE_RADIOBOX
14
1e6feb95
VZ
15#include "wx/radiobut.h"
16
9e691f46 17#include "wx/gtk/private.h"
c801d85f 18
6de97a3b
RR
19//-----------------------------------------------------------------------------
20// data
21//-----------------------------------------------------------------------------
22
d7fa7eaa 23extern bool g_blockEventsOnDrag;
6de97a3b
RR
24
25//-----------------------------------------------------------------------------
bb4549de 26// "clicked"
6de97a3b
RR
27//-----------------------------------------------------------------------------
28
865bb325 29extern "C" {
b2ff89d6 30static
e2762ff0 31void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioButton *rb )
6de97a3b 32{
acfd422a
RR
33 if (g_isIdle) wxapp_install_idle_handler();
34
a2053b27 35 if (!rb->m_hasVMT) return;
b2ff89d6 36
f5d29b39 37 if (g_blockEventsOnDrag) return;
b2ff89d6 38
e2762ff0 39 if (!button->active) return;
b2ff89d6 40
9864c56d 41 if (rb->m_blockEvent) return;
b2ff89d6 42
f5d29b39
RR
43 wxCommandEvent event( wxEVT_COMMAND_RADIOBUTTON_SELECTED, rb->GetId());
44 event.SetInt( rb->GetValue() );
45 event.SetEventObject( rb );
46 rb->GetEventHandler()->ProcessEvent( event );
6de97a3b 47}
865bb325 48}
6de97a3b 49
bb4549de
RR
50//-----------------------------------------------------------------------------
51// wxRadioButton
52//-----------------------------------------------------------------------------
53
54IMPLEMENT_DYNAMIC_CLASS(wxRadioButton,wxControl)
b2ff89d6 55
2b4f3c9f
VZ
56bool wxRadioButton::Create( wxWindow *parent,
57 wxWindowID id,
58 const wxString& label,
59 const wxPoint& pos,
60 const wxSize& size,
61 long style,
62 const wxValidator& validator,
63 const wxString& name )
6de97a3b 64{
b292e2f5 65 m_acceptsFocus = TRUE;
f5d29b39 66 m_needParent = TRUE;
b2ff89d6 67
9864c56d 68 m_blockEvent = FALSE;
6de97a3b 69
4dcaf11a
RR
70 if (!PreCreation( parent, pos, size ) ||
71 !CreateBase( parent, id, pos, size, style, validator, name ))
72 {
223d09f6 73 wxFAIL_MSG( wxT("wxRadioButton creation failed") );
9864c56d 74 return FALSE;
4dcaf11a 75 }
953704c1 76
739b7529
DS
77 GSList* radioButtonGroup = NULL;
78 if (!HasFlag(wxRB_GROUP))
953704c1 79 {
9864c56d 80 // search backward for last group start
953704c1 81 wxRadioButton *chief = (wxRadioButton*) NULL;
222ed1d6 82 wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast();
953704c1 83 while (node)
e2762ff0
RR
84 {
85 wxWindow *child = node->GetData();
2b4f3c9f 86 if (child->IsRadioButton())
e2762ff0
RR
87 {
88 chief = (wxRadioButton*) child;
2b4f3c9f
VZ
89 if (child->HasFlag(wxRB_GROUP))
90 break;
e2762ff0
RR
91 }
92 node = node->GetPrevious();
953704c1 93 }
e2762ff0
RR
94 if (chief)
95 {
9864c56d 96 // we are part of the group started by chief
78e017d8 97 radioButtonGroup = gtk_radio_button_get_group( GTK_RADIO_BUTTON(chief->m_widget) );
e2762ff0 98 }
953704c1
RR
99 }
100
739b7529 101 m_widget = gtk_radio_button_new_with_label( radioButtonGroup, wxGTK_CONV( label ) );
b2ff89d6 102
f5d29b39 103 SetLabel(label);
6de97a3b 104
9fa72bd2
MR
105 g_signal_connect (m_widget, "clicked",
106 G_CALLBACK (gtk_radiobutton_clicked_callback), this);
b2ff89d6 107
f03fc89f 108 m_parent->DoAddChild( this );
b2ff89d6 109
abdeb9e7 110 PostCreation(size);
6de97a3b 111
f5d29b39 112 return TRUE;
6de97a3b
RR
113}
114
115void wxRadioButton::SetLabel( const wxString& label )
116{
223d09f6 117 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobutton") );
b2ff89d6 118
afa7bd1e 119 GTKSetLabelForLabel(GTK_LABEL(GTK_BIN(m_widget)->child), label);
6de97a3b
RR
120}
121
122void wxRadioButton::SetValue( bool val )
123{
223d09f6 124 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobutton") );
f6bcfd97 125
953704c1 126 if (val == GetValue())
0659e7ee
RR
127 return;
128
9864c56d 129 m_blockEvent = TRUE;
953704c1 130
f5d29b39 131 if (val)
953704c1 132 {
e2762ff0 133 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(m_widget), TRUE );
953704c1 134 }
f5d29b39 135 else
953704c1
RR
136 {
137 // should give an assert
f6bcfd97
BP
138 // RL - No it shouldn't. A wxGenericValidator might try to set it
139 // as FALSE. Failing silently is probably TRTTD here.
953704c1 140 }
f6bcfd97 141
9864c56d 142 m_blockEvent = FALSE;
6de97a3b
RR
143}
144
eb082a08 145bool wxRadioButton::GetValue() const
6de97a3b 146{
223d09f6 147 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobutton") );
b2ff89d6 148
f5d29b39 149 return GTK_TOGGLE_BUTTON(m_widget)->active;
6de97a3b
RR
150}
151
f03fc89f 152bool wxRadioButton::Enable( bool enable )
d3904ceb 153{
f03fc89f
VZ
154 if ( !wxControl::Enable( enable ) )
155 return FALSE;
b2ff89d6 156
afa7bd1e 157 gtk_widget_set_sensitive(GTK_BIN(m_widget)->child, enable);
f03fc89f
VZ
158
159 return TRUE;
d3904ceb
RR
160}
161
f40fdaa3 162void wxRadioButton::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 163{
f40fdaa3 164 gtk_widget_modify_style(m_widget, style);
afa7bd1e 165 gtk_widget_modify_style(GTK_BIN(m_widget)->child, style);
f96aa4d9 166}
dcf924a3 167
ef5c70f9
VZ
168GdkWindow *
169wxRadioButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
2f073eb2 170{
ef5c70f9 171 return GTK_BUTTON(m_widget)->event_window;
2f073eb2
RR
172}
173
db434467
RR
174wxSize wxRadioButton::DoGetBestSize() const
175{
176 return wxControl::DoGetBestSize();
177}
178
9d522606
RD
179// static
180wxVisualAttributes
181wxRadioButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
182{
183 wxVisualAttributes attr;
bc0eb46c
VS
184 // NB: we need toplevel window so that GTK+ can find the right style
185 GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
9d522606 186 GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
bc0eb46c 187 gtk_container_add(GTK_CONTAINER(wnd), widget);
9d522606 188 attr = GetDefaultAttributesFromGTKWidget(widget);
bc0eb46c 189 gtk_widget_destroy(wnd);
9d522606
RD
190 return attr;
191}
192
193
dcf924a3 194#endif