]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobox.cpp
Supress SetFocus() warning in wxVListBoxComboPopup
[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 226 m_widget = GTKCreateFrame(title);
9ff9d30c 227 g_object_ref(m_widget);
2e1f5012 228 wxControl::SetLabel(title);
378b042b
VZ
229 if ( HasFlag(wxNO_BORDER) )
230 {
231 // If we don't do this here, the wxNO_BORDER style is ignored in Show()
232 gtk_frame_set_shadow_type(GTK_FRAME(m_widget), GTK_SHADOW_NONE);
233 }
234
29006414 235
5eaac5b5
VZ
236 // majorDim may be 0 if all trailing parameters were omitted, so don't
237 // assert here but just use the correct value for it
27c78e45 238 SetMajorDim(majorDim == 0 ? n : majorDim, style);
29006414 239
8017ee9b 240
aa61d352
VZ
241 unsigned int num_of_cols = GetColumnCount();
242 unsigned int num_of_rows = GetRowCount();
11e62fe6 243
d3b9f782 244 GtkRadioButton *rbtn = NULL;
29006414 245
8017ee9b 246 GtkWidget *table = gtk_table_new( num_of_rows, num_of_cols, FALSE );
d504085d
RR
247 gtk_table_set_col_spacings( GTK_TABLE(table), 1 );
248 gtk_table_set_row_spacings( GTK_TABLE(table), 1 );
8017ee9b
RR
249 gtk_widget_show( table );
250 gtk_container_add( GTK_CONTAINER(m_widget), table );
11e62fe6 251
26333898 252 wxString label;
d3b9f782 253 GSList *radio_button_group = NULL;
8ebb2a1d 254 for (unsigned int i = 0; i < (unsigned int)n; i++)
c801d85f 255 {
26333898 256 if ( i != 0 )
07014b5a 257 radio_button_group = gtk_radio_button_get_group( GTK_RADIO_BUTTON(rbtn) );
29006414 258
26333898 259 label.Empty();
86501081
VS
260 for ( wxString::const_iterator pc = choices[i].begin();
261 pc != choices[i].end(); ++pc )
26333898 262 {
223d09f6 263 if ( *pc != wxT('&') )
26333898
VZ
264 label += *pc;
265 }
266
07014b5a
VZ
267 rbtn = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) );
268 gtk_widget_show( GTK_WIDGET(rbtn) );
29006414 269
07014b5a 270 g_signal_connect (rbtn, "key_press_event",
9fa72bd2 271 G_CALLBACK (gtk_radiobox_keypress_callback), this);
2da61056 272
dc26eeb3 273 m_buttonsInfo.Append( new wxGTKRadioButtonInfo( rbtn, wxRect() ) );
29006414 274
8017ee9b
RR
275 if (HasFlag(wxRA_SPECIFY_COLS))
276 {
277 int left = i%num_of_cols;
278 int right = (i%num_of_cols) + 1;
279 int top = i/num_of_cols;
280 int bottom = (i/num_of_cols)+1;
07014b5a 281 gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom,
11e62fe6 282 GTK_FILL, GTK_FILL, 1, 1 );
8017ee9b
RR
283 }
284 else
285 {
286 int left = i/num_of_rows;
287 int right = (i/num_of_rows) + 1;
288 int top = i%num_of_rows;
289 int bottom = (i%num_of_rows)+1;
07014b5a 290 gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom,
11e62fe6 291 GTK_FILL, GTK_FILL, 1, 1 );
8017ee9b
RR
292 }
293
07014b5a 294 ConnectWidget( GTK_WIDGET(rbtn) );
29006414 295
e343da37 296 if (!i)
07014b5a 297 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(rbtn), TRUE );
29006414 298
07014b5a 299 g_signal_connect (rbtn, "clicked",
9fa72bd2 300 G_CALLBACK (gtk_radiobutton_clicked_callback), this);
07014b5a 301 g_signal_connect (rbtn, "focus_in_event",
9fa72bd2 302 G_CALLBACK (gtk_radiobutton_focus_in), this);
07014b5a 303 g_signal_connect (rbtn, "focus_out_event",
9fa72bd2 304 G_CALLBACK (gtk_radiobutton_focus_out), this);
dc26eeb3
VZ
305 g_signal_connect (rbtn, "size_allocate",
306 G_CALLBACK (gtk_radiobutton_size_allocate), this);
6de97a3b 307 }
29006414 308
db434467
RR
309 m_parent->DoAddChild( this );
310
abdeb9e7 311 PostCreation(size);
29006414 312
b4efc9b9 313 return true;
6de97a3b 314}
c801d85f 315
f03fc89f 316wxRadioBox::~wxRadioBox()
d6d1892b 317{
dc26eeb3 318 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
319 while (node)
320 {
dc26eeb3 321 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
907789a0 322 gtk_widget_destroy( button );
b1d4dd7a 323 node = node->GetNext();
907789a0 324 }
dc26eeb3 325 WX_CLEAR_LIST( wxRadioBoxButtonsInfoList, m_buttonsInfo );
d6d1892b
RR
326}
327
debe6624 328bool wxRadioBox::Show( bool show )
c801d85f 329{
b4efc9b9 330 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 331
f96ac56a
RR
332 if (!wxControl::Show(show))
333 {
334 // nothing to do
b4efc9b9 335 return false;
f96ac56a 336 }
c801d85f 337
c4ca49cd 338 if ( HasFlag(wxNO_BORDER) )
b0351fc9 339 gtk_widget_hide( m_widget );
e3e717ec 340
dc26eeb3 341 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
342 while (node)
343 {
dc26eeb3 344 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
29006414 345
27c78e45
VZ
346 if (show)
347 gtk_widget_show( button );
348 else
349 gtk_widget_hide( button );
29006414 350
b1d4dd7a 351 node = node->GetNext();
907789a0 352 }
c801d85f 353
b4efc9b9 354 return true;
6de97a3b 355}
c801d85f 356
47908e25 357void wxRadioBox::SetSelection( int n )
c801d85f 358{
223d09f6 359 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 360
dc26eeb3 361 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( n );
29006414 362
223d09f6 363 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 364
dc26eeb3 365 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button );
29006414 366
72a7edf0 367 GtkDisableEvents();
2da61056 368
e2762ff0 369 gtk_toggle_button_set_active( button, 1 );
2da61056 370
72a7edf0 371 GtkEnableEvents();
6de97a3b 372}
c801d85f
KB
373
374int wxRadioBox::GetSelection(void) const
375{
789f6795 376 wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") );
29006414 377
907789a0 378 int count = 0;
29006414 379
dc26eeb3 380 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
381 while (node)
382 {
dc26eeb3 383 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button );
907789a0
RR
384 if (button->active) return count;
385 count++;
b1d4dd7a 386 node = node->GetNext();
907789a0 387 }
29006414 388
223d09f6 389 wxFAIL_MSG( wxT("wxRadioBox none selected") );
29006414 390
789f6795 391 return wxNOT_FOUND;
6de97a3b 392}
c801d85f 393
aa61d352 394wxString wxRadioBox::GetString(unsigned int n) const
c801d85f 395{
1a87edf2 396 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") );
29006414 397
dc26eeb3 398 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( n );
29006414 399
1a87edf2 400 wxCHECK_MSG( node, wxEmptyString, wxT("radiobox wrong index") );
29006414 401
dc26eeb3 402 GtkLabel *label = GTK_LABEL(GTK_BIN(node->GetData()->button)->child);
29006414 403
2b5f62a0 404 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
2b5f62a0
VZ
405
406 return str;
6de97a3b 407}
c801d85f 408
d3904ceb 409void wxRadioBox::SetLabel( const wxString& label )
c801d85f 410{
223d09f6 411 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 412
b2ff89d6 413 GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
6de97a3b 414}
c801d85f 415
aa61d352 416void wxRadioBox::SetString(unsigned int item, const wxString& label)
c801d85f 417{
223d09f6 418 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 419
dc26eeb3 420 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 421
223d09f6 422 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 423
dc26eeb3 424 GtkLabel *g_label = GTK_LABEL(GTK_BIN(node->GetData()->button)->child);
29006414 425
a7c12d28 426 gtk_label_set_text( g_label, wxGTK_CONV( label ) );
6de97a3b 427}
c801d85f 428
f03fc89f 429bool wxRadioBox::Enable( bool enable )
c801d85f 430{
f03fc89f 431 if ( !wxControl::Enable( enable ) )
b4efc9b9 432 return false;
29006414 433
dc26eeb3 434 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
435 while (node)
436 {
dc26eeb3 437 GtkButton *button = GTK_BUTTON( node->GetData()->button );
afa7bd1e 438 GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child);
9e691f46 439
907789a0 440 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 441 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
b1d4dd7a 442 node = node->GetNext();
907789a0 443 }
f03fc89f 444
b545684e 445 if (enable)
ad60f9e7 446 GTKFixSensitivity();
ad60f9e7 447
b4efc9b9 448 return true;
6de97a3b 449}
c801d85f 450
aa61d352 451bool wxRadioBox::Enable(unsigned int item, bool enable)
c801d85f 452{
1a87edf2 453 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 454
dc26eeb3 455 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 456
1a87edf2 457 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 458
dc26eeb3 459 GtkButton *button = GTK_BUTTON( node->GetData()->button );
afa7bd1e 460 GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child);
9e691f46 461
907789a0 462 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 463 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
1a87edf2
WS
464
465 return true;
6de97a3b 466}
c801d85f 467
aa61d352 468bool wxRadioBox::IsItemEnabled(unsigned int item) const
27c78e45
VZ
469{
470 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
471
dc26eeb3 472 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
27c78e45
VZ
473
474 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
475
dc26eeb3 476 GtkButton *button = GTK_BUTTON( node->GetData()->button );
27c78e45
VZ
477
478 // don't use GTK_WIDGET_IS_SENSITIVE() here, we want to return true even if
479 // the parent radiobox is disabled
480 return GTK_WIDGET_SENSITIVE(GTK_WIDGET(button));
481}
482
aa61d352 483bool wxRadioBox::Show(unsigned int item, bool show)
c801d85f 484{
789f6795 485 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 486
dc26eeb3 487 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 488
789f6795 489 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 490
dc26eeb3 491 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
c801d85f 492
907789a0
RR
493 if (show)
494 gtk_widget_show( button );
495 else
496 gtk_widget_hide( button );
789f6795
WS
497
498 return true;
6de97a3b 499}
c801d85f 500
aa61d352 501bool wxRadioBox::IsItemShown(unsigned int item) const
c801d85f 502{
27c78e45 503 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 504
dc26eeb3 505 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
c801d85f 506
27c78e45 507 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 508
dc26eeb3 509 GtkButton *button = GTK_BUTTON( node->GetData()->button );
29006414 510
27c78e45 511 return GTK_WIDGET_VISIBLE(GTK_WIDGET(button));
6de97a3b 512}
c801d85f 513
aa61d352 514unsigned int wxRadioBox::GetCount() const
c801d85f 515{
dc26eeb3 516 return m_buttonsInfo.GetCount();
6de97a3b 517}
c801d85f 518
72a7edf0 519void wxRadioBox::GtkDisableEvents()
953704c1 520{
dc26eeb3 521 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
953704c1
RR
522 while (node)
523 {
98264520
PC
524 g_signal_handlers_block_by_func(node->GetData()->button,
525 (gpointer)gtk_radiobutton_clicked_callback, this);
953704c1 526
b1d4dd7a 527 node = node->GetNext();
953704c1
RR
528 }
529}
530
72a7edf0 531void wxRadioBox::GtkEnableEvents()
953704c1 532{
dc26eeb3 533 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
953704c1
RR
534 while (node)
535 {
98264520
PC
536 g_signal_handlers_unblock_by_func(node->GetData()->button,
537 (gpointer)gtk_radiobutton_clicked_callback, this);
953704c1 538
b1d4dd7a 539 node = node->GetNext();
953704c1
RR
540 }
541}
542
f40fdaa3 543void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 544{
2e1f5012 545 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget), style);
81e88f5b 546
dc26eeb3 547 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
548 while (node)
549 {
dc26eeb3 550 GtkWidget *widget = GTK_WIDGET( node->GetData()->button );
29006414 551
f40fdaa3 552 gtk_widget_modify_style( widget, style );
afa7bd1e 553 gtk_widget_modify_style(GTK_BIN(widget)->child, style);
29006414 554
b1d4dd7a 555 node = node->GetNext();
907789a0 556 }
868a2826 557}
b4071e91 558
2e1f5012
VZ
559bool wxRadioBox::GTKWidgetNeedsMnemonic() const
560{
561 return true;
562}
563
564void wxRadioBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
565{
566 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget), w);
567}
568
72a7edf0 569#if wxUSE_TOOLTIPS
7fc8b9a4 570void wxRadioBox::GTKApplyToolTip(GtkTooltips * WXUNUSED(tips), const gchar *tip)
72a7edf0 571{
aa1e6de9
VZ
572 // set this tooltip for all radiobuttons which don't have their own tips
573 unsigned n = 0;
dc26eeb3 574 for ( wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
aa1e6de9
VZ
575 node;
576 node = node->GetNext(), n++ )
72a7edf0 577 {
aa1e6de9
VZ
578 if ( !GetItemToolTip(n) )
579 {
7fc8b9a4 580 wxToolTip::GTKApply(GTK_WIDGET(node->GetData()->button), tip);
aa1e6de9 581 }
72a7edf0
RR
582 }
583}
aa1e6de9
VZ
584
585void wxRadioBox::DoSetItemToolTip(unsigned int n, wxToolTip *tooltip)
586{
587 wxCharBuffer buf;
588 if ( !tooltip )
589 tooltip = GetToolTip();
590 if ( tooltip )
591 buf = wxGTK_CONV(tooltip->GetTip());
592
7fc8b9a4 593 wxToolTip::GTKApply(GTK_WIDGET(m_buttonsInfo[n]->button), buf);
aa1e6de9
VZ
594}
595
72a7edf0
RR
596#endif // wxUSE_TOOLTIPS
597
ef5c70f9 598GdkWindow *wxRadioBox::GTKGetWindow(wxArrayGdkWindows& windows) const
b4071e91 599{
ef5c70f9 600 windows.push_back(m_widget->window);
29006414 601
dc26eeb3 602 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
603 while (node)
604 {
dc26eeb3 605 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
29006414 606
5b88a837
FM
607 // don't put NULL pointers in the 'windows' array!
608 if (button->window)
609 windows.push_back(button->window);
29006414 610
b1d4dd7a 611 node = node->GetNext();
907789a0 612 }
29006414 613
ef5c70f9 614 return NULL;
b4071e91 615}
dcf924a3 616
9d522606
RD
617// static
618wxVisualAttributes
619wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
620{
621 wxVisualAttributes attr;
bc0eb46c
VS
622 // NB: we need toplevel window so that GTK+ can find the right style
623 GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
9d522606 624 GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
bc0eb46c 625 gtk_container_add(GTK_CONTAINER(wnd), widget);
9d522606 626 attr = GetDefaultAttributesFromGTKWidget(widget);
bc0eb46c 627 gtk_widget_destroy(wnd);
9d522606
RD
628 return attr;
629}
630
dc26eeb3
VZ
631int wxRadioBox::GetItemFromPoint(const wxPoint& point) const
632{
633 const wxPoint pt = ScreenToClient(point);
634 unsigned n = 0;
635 for ( wxRadioBoxButtonsInfoList::compatibility_iterator
636 node = m_buttonsInfo.GetFirst(); node; node = node->GetNext(), n++ )
637 {
22a35096 638 if ( m_buttonsInfo[n]->rect.Contains(pt) )
dc26eeb3
VZ
639 return n;
640 }
641
642 return wxNOT_FOUND;
643}
644
f6bcfd97 645#endif // wxUSE_RADIOBOX