]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobox.cpp
Update OpenVMS compile support
[wxWidgets.git] / src / gtk / radiobox.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
11e62fe6 2// Name: src/gtk/radiobox.cpp
c801d85f
KB
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/radiobox.h"
16
e4db172a
WS
17#ifndef WX_PRECOMP
18 #include "wx/log.h"
76b49cf4 19 #include "wx/frame.h"
fdf565fe 20 #include "wx/dialog.h"
e4db172a
WS
21#endif
22
aa1e6de9
VZ
23#if wxUSE_TOOLTIPS
24 #include "wx/tooltip.h"
25#endif
26
9e691f46 27#include "wx/gtk/private.h"
3f26799e
RR
28#include <gdk/gdkkeysyms.h>
29
dc26eeb3
VZ
30//-----------------------------------------------------------------------------
31// wxGTKRadioButtonInfo
32//-----------------------------------------------------------------------------
33// structure internally used by wxRadioBox to store its child buttons
34
35class wxGTKRadioButtonInfo : public wxObject
36{
37public:
38 wxGTKRadioButtonInfo( GtkRadioButton * abutton, const wxRect & arect )
39 : button( abutton ), rect( arect ) {}
40
41 GtkRadioButton * button;
42 wxRect rect;
43};
44
66bd6b93
RR
45//-----------------------------------------------------------------------------
46// data
47//-----------------------------------------------------------------------------
48
dc26eeb3 49#include "wx/listimpl.cpp"
178d7ec2 50WX_DEFINE_LIST( wxRadioBoxButtonsInfoList )
dc26eeb3 51
d7fa7eaa 52extern bool g_blockEventsOnDrag;
66bd6b93 53
c801d85f 54//-----------------------------------------------------------------------------
b4071e91 55// "clicked"
c801d85f
KB
56//-----------------------------------------------------------------------------
57
865bb325 58extern "C" {
e2762ff0 59static void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioBox *rb )
c801d85f 60{
a2053b27 61 if (!rb->m_hasVMT) return;
907789a0 62 if (g_blockEventsOnDrag) return;
29006414 63
e2762ff0 64 if (!button->active) return;
29006414 65
907789a0
RR
66 wxCommandEvent event( wxEVT_COMMAND_RADIOBOX_SELECTED, rb->GetId() );
67 event.SetInt( rb->GetSelection() );
29006414 68 event.SetString( rb->GetStringSelection() );
907789a0 69 event.SetEventObject( rb );
937013e0 70 rb->HandleWindowEvent(event);
6de97a3b 71}
865bb325 72}
c801d85f 73
2e0e025e
RR
74//-----------------------------------------------------------------------------
75// "key_press_event"
76//-----------------------------------------------------------------------------
77
865bb325 78extern "C" {
2e0e025e
RR
79static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb )
80{
2e0e025e
RR
81 if (!rb->m_hasVMT) return FALSE;
82 if (g_blockEventsOnDrag) return FALSE;
83
8228b893 84 if ( ((gdk_event->keyval == GDK_Tab) ||
5985c07c
RR
85 (gdk_event->keyval == GDK_ISO_Left_Tab)) &&
86 rb->GetParent() && (rb->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
87 {
88 wxNavigationKeyEvent new_event;
89 new_event.SetEventObject( rb->GetParent() );
90 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
91 new_event.SetDirection( (gdk_event->keyval == GDK_Tab) );
92 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
93 new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
94 new_event.SetCurrentFocus( rb );
937013e0 95 return rb->GetParent()->HandleWindowEvent(new_event);
5985c07c
RR
96 }
97
2e0e025e
RR
98 if ((gdk_event->keyval != GDK_Up) &&
99 (gdk_event->keyval != GDK_Down) &&
100 (gdk_event->keyval != GDK_Left) &&
101 (gdk_event->keyval != GDK_Right))
102 {
103 return FALSE;
104 }
2da61056 105
dc26eeb3
VZ
106 wxRadioBoxButtonsInfoList::compatibility_iterator node = rb->m_buttonsInfo.GetFirst();
107 while( node && GTK_WIDGET( node->GetData()->button ) != widget )
108 {
109 node = node->GetNext();
110 }
2e0e025e
RR
111 if (!node)
112 {
113 return FALSE;
114 }
2da61056 115
2e0e025e
RR
116 if ((gdk_event->keyval == GDK_Up) ||
117 (gdk_event->keyval == GDK_Left))
118 {
dc26eeb3
VZ
119 if (node == rb->m_buttonsInfo.GetFirst())
120 node = rb->m_buttonsInfo.GetLast();
2da61056 121 else
b1d4dd7a 122 node = node->GetPrevious();
2e0e025e
RR
123 }
124 else
125 {
dc26eeb3
VZ
126 if (node == rb->m_buttonsInfo.GetLast())
127 node = rb->m_buttonsInfo.GetFirst();
2da61056 128 else
b1d4dd7a 129 node = node->GetNext();
2e0e025e 130 }
2da61056 131
dc26eeb3 132 GtkWidget *button = (GtkWidget*) node->GetData()->button;
2da61056 133
2e0e025e 134 gtk_widget_grab_focus( button );
2da61056 135
2e0e025e
RR
136 return TRUE;
137}
865bb325 138}
2e0e025e 139
865bb325 140extern "C" {
bd2e08d0
VS
141static gint gtk_radiobutton_focus_out( GtkWidget * WXUNUSED(widget),
142 GdkEventFocus *WXUNUSED(event),
143 wxRadioBox *win )
f6bcfd97 144{
bd2e08d0
VS
145 // NB: This control is composed of several GtkRadioButton widgets and
146 // when focus changes from one of them to another in the same
147 // wxRadioBox, we get a focus-out event followed by focus-in for
148 // another GtkRadioButton owned by the same control. We don't want
149 // to generate two spurious wxEVT_SET_FOCUS events in this case,
150 // so we defer sending wx events until idle time.
151 win->GTKHandleFocusOut();
f6bcfd97 152
bd2e08d0
VS
153 // never stop the signal emission, it seems to break the kbd handling
154 // inside the radiobox
f6bcfd97
BP
155 return FALSE;
156}
865bb325 157}
f6bcfd97 158
865bb325 159extern "C" {
bd2e08d0
VS
160static gint gtk_radiobutton_focus_in( GtkWidget * WXUNUSED(widget),
161 GdkEventFocus *WXUNUSED(event),
162 wxRadioBox *win )
f6bcfd97 163{
bd2e08d0 164 win->GTKHandleFocusIn();
f6bcfd97 165
bd2e08d0
VS
166 // never stop the signal emission, it seems to break the kbd handling
167 // inside the radiobox
f6bcfd97
BP
168 return FALSE;
169}
865bb325 170}
f6bcfd97 171
dc26eeb3
VZ
172extern "C" {
173static void gtk_radiobutton_size_allocate( GtkWidget *widget,
174 GtkAllocation * alloc,
175 wxRadioBox *win )
176{
dc26eeb3
VZ
177 for ( wxRadioBoxButtonsInfoList::compatibility_iterator node = win->m_buttonsInfo.GetFirst();
178 node;
964c139b 179 node = node->GetNext())
dc26eeb3 180 {
964c139b 181 if (widget == GTK_WIDGET(node->GetData()->button))
dc26eeb3
VZ
182 {
183 const wxPoint origin = win->GetPosition();
184 wxRect rect = wxRect( alloc->x - origin.x, alloc->y - origin.y,
185 alloc->width, alloc->height );
186 node->GetData()->rect = rect;
187 break;
188 }
189 }
190}
191}
192
193
b4071e91
RR
194//-----------------------------------------------------------------------------
195// wxRadioBox
c801d85f
KB
196//-----------------------------------------------------------------------------
197
198IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl)
199
584ad2a3
MB
200bool wxRadioBox::Create( wxWindow *parent, wxWindowID id,
201 const wxString& title,
202 const wxPoint &pos, const wxSize &size,
203 const wxArrayString& choices, int majorDim,
204 long style, const wxValidator& validator,
205 const wxString &name )
206{
207 wxCArrayString chs(choices);
208
209 return Create( parent, id, title, pos, size, chs.GetCount(),
210 chs.GetStrings(), majorDim, style, validator, name );
211}
212
debe6624 213bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
907789a0 214 const wxPoint &pos, const wxSize &size,
29006414
VZ
215 int n, const wxString choices[], int majorDim,
216 long style, const wxValidator& validator,
217 const wxString &name )
c801d85f 218{
4dcaf11a
RR
219 if (!PreCreation( parent, pos, size ) ||
220 !CreateBase( parent, id, pos, size, style, validator, name ))
221 {
223d09f6 222 wxFAIL_MSG( wxT("wxRadioBox creation failed") );
b4efc9b9 223 return false;
4dcaf11a 224 }
6de97a3b 225
2e1f5012
VZ
226 m_widget = GTKCreateFrame(title);
227 wxControl::SetLabel(title);
378b042b
VZ
228 if ( HasFlag(wxNO_BORDER) )
229 {
230 // If we don't do this here, the wxNO_BORDER style is ignored in Show()
231 gtk_frame_set_shadow_type(GTK_FRAME(m_widget), GTK_SHADOW_NONE);
232 }
233
29006414 234
5eaac5b5
VZ
235 // majorDim may be 0 if all trailing parameters were omitted, so don't
236 // assert here but just use the correct value for it
27c78e45 237 SetMajorDim(majorDim == 0 ? n : majorDim, style);
29006414 238
8017ee9b 239
aa61d352
VZ
240 unsigned int num_of_cols = GetColumnCount();
241 unsigned int num_of_rows = GetRowCount();
11e62fe6 242
07014b5a 243 GtkRadioButton *rbtn = (GtkRadioButton*) NULL;
29006414 244
8017ee9b 245 GtkWidget *table = gtk_table_new( num_of_rows, num_of_cols, FALSE );
d504085d
RR
246 gtk_table_set_col_spacings( GTK_TABLE(table), 1 );
247 gtk_table_set_row_spacings( GTK_TABLE(table), 1 );
8017ee9b
RR
248 gtk_widget_show( table );
249 gtk_container_add( GTK_CONTAINER(m_widget), table );
11e62fe6 250
26333898 251 wxString label;
d3b4d113 252 GSList *radio_button_group = (GSList *) NULL;
8ebb2a1d 253 for (unsigned int i = 0; i < (unsigned int)n; i++)
c801d85f 254 {
26333898 255 if ( i != 0 )
07014b5a 256 radio_button_group = gtk_radio_button_get_group( GTK_RADIO_BUTTON(rbtn) );
29006414 257
26333898 258 label.Empty();
86501081
VS
259 for ( wxString::const_iterator pc = choices[i].begin();
260 pc != choices[i].end(); ++pc )
26333898 261 {
223d09f6 262 if ( *pc != wxT('&') )
26333898
VZ
263 label += *pc;
264 }
265
07014b5a
VZ
266 rbtn = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) );
267 gtk_widget_show( GTK_WIDGET(rbtn) );
29006414 268
07014b5a 269 g_signal_connect (rbtn, "key_press_event",
9fa72bd2 270 G_CALLBACK (gtk_radiobox_keypress_callback), this);
2da61056 271
dc26eeb3 272 m_buttonsInfo.Append( new wxGTKRadioButtonInfo( rbtn, wxRect() ) );
29006414 273
8017ee9b
RR
274 if (HasFlag(wxRA_SPECIFY_COLS))
275 {
276 int left = i%num_of_cols;
277 int right = (i%num_of_cols) + 1;
278 int top = i/num_of_cols;
279 int bottom = (i/num_of_cols)+1;
07014b5a 280 gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom,
11e62fe6 281 GTK_FILL, GTK_FILL, 1, 1 );
8017ee9b
RR
282 }
283 else
284 {
285 int left = i/num_of_rows;
286 int right = (i/num_of_rows) + 1;
287 int top = i%num_of_rows;
288 int bottom = (i%num_of_rows)+1;
07014b5a 289 gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom,
11e62fe6 290 GTK_FILL, GTK_FILL, 1, 1 );
8017ee9b
RR
291 }
292
07014b5a 293 ConnectWidget( GTK_WIDGET(rbtn) );
29006414 294
e343da37 295 if (!i)
07014b5a 296 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(rbtn), TRUE );
29006414 297
07014b5a 298 g_signal_connect (rbtn, "clicked",
9fa72bd2 299 G_CALLBACK (gtk_radiobutton_clicked_callback), this);
07014b5a 300 g_signal_connect (rbtn, "focus_in_event",
9fa72bd2 301 G_CALLBACK (gtk_radiobutton_focus_in), this);
07014b5a 302 g_signal_connect (rbtn, "focus_out_event",
9fa72bd2 303 G_CALLBACK (gtk_radiobutton_focus_out), this);
dc26eeb3
VZ
304 g_signal_connect (rbtn, "size_allocate",
305 G_CALLBACK (gtk_radiobutton_size_allocate), this);
6de97a3b 306 }
29006414 307
db434467
RR
308 m_parent->DoAddChild( this );
309
abdeb9e7 310 PostCreation(size);
29006414 311
b4efc9b9 312 return true;
6de97a3b 313}
c801d85f 314
f03fc89f 315wxRadioBox::~wxRadioBox()
d6d1892b 316{
dc26eeb3 317 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
318 while (node)
319 {
dc26eeb3 320 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
907789a0 321 gtk_widget_destroy( button );
b1d4dd7a 322 node = node->GetNext();
907789a0 323 }
dc26eeb3 324 WX_CLEAR_LIST( wxRadioBoxButtonsInfoList, m_buttonsInfo );
d6d1892b
RR
325}
326
debe6624 327bool wxRadioBox::Show( bool show )
c801d85f 328{
b4efc9b9 329 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 330
f96ac56a
RR
331 if (!wxControl::Show(show))
332 {
333 // nothing to do
b4efc9b9 334 return false;
f96ac56a 335 }
c801d85f 336
c4ca49cd 337 if ( HasFlag(wxNO_BORDER) )
b0351fc9 338 gtk_widget_hide( m_widget );
e3e717ec 339
dc26eeb3 340 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
341 while (node)
342 {
dc26eeb3 343 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
29006414 344
27c78e45
VZ
345 if (show)
346 gtk_widget_show( button );
347 else
348 gtk_widget_hide( button );
29006414 349
b1d4dd7a 350 node = node->GetNext();
907789a0 351 }
c801d85f 352
b4efc9b9 353 return true;
6de97a3b 354}
c801d85f 355
47908e25 356void wxRadioBox::SetSelection( int n )
c801d85f 357{
223d09f6 358 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 359
dc26eeb3 360 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( n );
29006414 361
223d09f6 362 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 363
dc26eeb3 364 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button );
29006414 365
72a7edf0 366 GtkDisableEvents();
2da61056 367
e2762ff0 368 gtk_toggle_button_set_active( button, 1 );
2da61056 369
72a7edf0 370 GtkEnableEvents();
6de97a3b 371}
c801d85f
KB
372
373int wxRadioBox::GetSelection(void) const
374{
789f6795 375 wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") );
29006414 376
907789a0 377 int count = 0;
29006414 378
dc26eeb3 379 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
380 while (node)
381 {
dc26eeb3 382 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button );
907789a0
RR
383 if (button->active) return count;
384 count++;
b1d4dd7a 385 node = node->GetNext();
907789a0 386 }
29006414 387
223d09f6 388 wxFAIL_MSG( wxT("wxRadioBox none selected") );
29006414 389
789f6795 390 return wxNOT_FOUND;
6de97a3b 391}
c801d85f 392
aa61d352 393wxString wxRadioBox::GetString(unsigned int n) const
c801d85f 394{
1a87edf2 395 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") );
29006414 396
dc26eeb3 397 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( n );
29006414 398
1a87edf2 399 wxCHECK_MSG( node, wxEmptyString, wxT("radiobox wrong index") );
29006414 400
dc26eeb3 401 GtkLabel *label = GTK_LABEL(GTK_BIN(node->GetData()->button)->child);
29006414 402
2b5f62a0 403 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
2b5f62a0
VZ
404
405 return str;
6de97a3b 406}
c801d85f 407
d3904ceb 408void wxRadioBox::SetLabel( const wxString& label )
c801d85f 409{
223d09f6 410 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 411
b2ff89d6 412 GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
6de97a3b 413}
c801d85f 414
aa61d352 415void wxRadioBox::SetString(unsigned int item, const wxString& label)
c801d85f 416{
223d09f6 417 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 418
dc26eeb3 419 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 420
223d09f6 421 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 422
dc26eeb3 423 GtkLabel *g_label = GTK_LABEL(GTK_BIN(node->GetData()->button)->child);
29006414 424
a7c12d28 425 gtk_label_set_text( g_label, wxGTK_CONV( label ) );
6de97a3b 426}
c801d85f 427
f03fc89f 428bool wxRadioBox::Enable( bool enable )
c801d85f 429{
f03fc89f 430 if ( !wxControl::Enable( enable ) )
b4efc9b9 431 return false;
29006414 432
dc26eeb3 433 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
434 while (node)
435 {
dc26eeb3 436 GtkButton *button = GTK_BUTTON( node->GetData()->button );
afa7bd1e 437 GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child);
9e691f46 438
907789a0 439 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 440 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
b1d4dd7a 441 node = node->GetNext();
907789a0 442 }
f03fc89f 443
b4efc9b9 444 return true;
6de97a3b 445}
c801d85f 446
aa61d352 447bool wxRadioBox::Enable(unsigned int item, bool enable)
c801d85f 448{
1a87edf2 449 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 450
dc26eeb3 451 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 452
1a87edf2 453 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 454
dc26eeb3 455 GtkButton *button = GTK_BUTTON( node->GetData()->button );
afa7bd1e 456 GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child);
9e691f46 457
907789a0 458 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 459 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
1a87edf2
WS
460
461 return true;
6de97a3b 462}
c801d85f 463
aa61d352 464bool wxRadioBox::IsItemEnabled(unsigned int item) const
27c78e45
VZ
465{
466 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
467
dc26eeb3 468 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
27c78e45
VZ
469
470 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
471
dc26eeb3 472 GtkButton *button = GTK_BUTTON( node->GetData()->button );
27c78e45
VZ
473
474 // don't use GTK_WIDGET_IS_SENSITIVE() here, we want to return true even if
475 // the parent radiobox is disabled
476 return GTK_WIDGET_SENSITIVE(GTK_WIDGET(button));
477}
478
aa61d352 479bool wxRadioBox::Show(unsigned int item, bool show)
c801d85f 480{
789f6795 481 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 482
dc26eeb3 483 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 484
789f6795 485 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 486
dc26eeb3 487 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
c801d85f 488
907789a0
RR
489 if (show)
490 gtk_widget_show( button );
491 else
492 gtk_widget_hide( button );
789f6795
WS
493
494 return true;
6de97a3b 495}
c801d85f 496
aa61d352 497bool wxRadioBox::IsItemShown(unsigned int item) const
c801d85f 498{
27c78e45 499 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 500
dc26eeb3 501 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
c801d85f 502
27c78e45 503 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 504
dc26eeb3 505 GtkButton *button = GTK_BUTTON( node->GetData()->button );
29006414 506
27c78e45 507 return GTK_WIDGET_VISIBLE(GTK_WIDGET(button));
6de97a3b 508}
c801d85f 509
aa61d352 510unsigned int wxRadioBox::GetCount() const
c801d85f 511{
dc26eeb3 512 return m_buttonsInfo.GetCount();
6de97a3b 513}
c801d85f 514
72a7edf0 515void wxRadioBox::GtkDisableEvents()
953704c1 516{
dc26eeb3 517 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
953704c1
RR
518 while (node)
519 {
98264520
PC
520 g_signal_handlers_block_by_func(node->GetData()->button,
521 (gpointer)gtk_radiobutton_clicked_callback, this);
953704c1 522
b1d4dd7a 523 node = node->GetNext();
953704c1
RR
524 }
525}
526
72a7edf0 527void wxRadioBox::GtkEnableEvents()
953704c1 528{
dc26eeb3 529 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
953704c1
RR
530 while (node)
531 {
98264520
PC
532 g_signal_handlers_unblock_by_func(node->GetData()->button,
533 (gpointer)gtk_radiobutton_clicked_callback, this);
953704c1 534
b1d4dd7a 535 node = node->GetNext();
953704c1
RR
536 }
537}
538
f40fdaa3 539void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 540{
2e1f5012 541 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget), style);
81e88f5b 542
dc26eeb3 543 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
544 while (node)
545 {
dc26eeb3 546 GtkWidget *widget = GTK_WIDGET( node->GetData()->button );
29006414 547
f40fdaa3 548 gtk_widget_modify_style( widget, style );
afa7bd1e 549 gtk_widget_modify_style(GTK_BIN(widget)->child, style);
29006414 550
b1d4dd7a 551 node = node->GetNext();
907789a0 552 }
868a2826 553}
b4071e91 554
2e1f5012
VZ
555bool wxRadioBox::GTKWidgetNeedsMnemonic() const
556{
557 return true;
558}
559
560void wxRadioBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
561{
562 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget), w);
563}
564
72a7edf0 565#if wxUSE_TOOLTIPS
6e5f6c7c 566void wxRadioBox::ApplyToolTip(GtkTooltips * WXUNUSED(tips), const gchar *tip)
72a7edf0 567{
aa1e6de9
VZ
568 // set this tooltip for all radiobuttons which don't have their own tips
569 unsigned n = 0;
dc26eeb3 570 for ( wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
aa1e6de9
VZ
571 node;
572 node = node->GetNext(), n++ )
72a7edf0 573 {
aa1e6de9
VZ
574 if ( !GetItemToolTip(n) )
575 {
6e5f6c7c 576 wxToolTip::Apply(GTK_WIDGET(node->GetData()->button), tip);
aa1e6de9 577 }
72a7edf0
RR
578 }
579}
aa1e6de9
VZ
580
581void wxRadioBox::DoSetItemToolTip(unsigned int n, wxToolTip *tooltip)
582{
583 wxCharBuffer buf;
584 if ( !tooltip )
585 tooltip = GetToolTip();
586 if ( tooltip )
587 buf = wxGTK_CONV(tooltip->GetTip());
588
dc26eeb3 589 wxToolTip::Apply(GTK_WIDGET(m_buttonsInfo[n]->button), buf);
aa1e6de9
VZ
590}
591
72a7edf0
RR
592#endif // wxUSE_TOOLTIPS
593
ef5c70f9 594GdkWindow *wxRadioBox::GTKGetWindow(wxArrayGdkWindows& windows) const
b4071e91 595{
ef5c70f9 596 windows.push_back(m_widget->window);
29006414 597
dc26eeb3 598 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
599 while (node)
600 {
dc26eeb3 601 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
29006414 602
ef5c70f9 603 windows.push_back(button->window);
29006414 604
b1d4dd7a 605 node = node->GetNext();
907789a0 606 }
29006414 607
ef5c70f9 608 return NULL;
b4071e91 609}
dcf924a3 610
9d522606
RD
611// static
612wxVisualAttributes
613wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
614{
615 wxVisualAttributes attr;
bc0eb46c
VS
616 // NB: we need toplevel window so that GTK+ can find the right style
617 GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
9d522606 618 GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
bc0eb46c 619 gtk_container_add(GTK_CONTAINER(wnd), widget);
9d522606 620 attr = GetDefaultAttributesFromGTKWidget(widget);
bc0eb46c 621 gtk_widget_destroy(wnd);
9d522606
RD
622 return attr;
623}
624
dc26eeb3
VZ
625int wxRadioBox::GetItemFromPoint(const wxPoint& point) const
626{
627 const wxPoint pt = ScreenToClient(point);
628 unsigned n = 0;
629 for ( wxRadioBoxButtonsInfoList::compatibility_iterator
630 node = m_buttonsInfo.GetFirst(); node; node = node->GetNext(), n++ )
631 {
22a35096 632 if ( m_buttonsInfo[n]->rect.Contains(pt) )
dc26eeb3
VZ
633 return n;
634 }
635
636 return wxNOT_FOUND;
637}
638
f6bcfd97 639#endif // wxUSE_RADIOBOX