]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobox.cpp
Give wxCollapsiblePane's pane a name for easier debugging
[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{
ad60f9e7
JS
431 bool isEnabled = IsEnabled();
432
f03fc89f 433 if ( !wxControl::Enable( enable ) )
b4efc9b9 434 return false;
29006414 435
dc26eeb3 436 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
437 while (node)
438 {
dc26eeb3 439 GtkButton *button = GTK_BUTTON( node->GetData()->button );
afa7bd1e 440 GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child);
9e691f46 441
907789a0 442 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 443 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
b1d4dd7a 444 node = node->GetNext();
907789a0 445 }
f03fc89f 446
ad60f9e7
JS
447 if (!isEnabled && enable)
448 {
449 GTKFixSensitivity();
450 }
451
b4efc9b9 452 return true;
6de97a3b 453}
c801d85f 454
aa61d352 455bool wxRadioBox::Enable(unsigned int item, bool enable)
c801d85f 456{
1a87edf2 457 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 458
dc26eeb3 459 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 460
1a87edf2 461 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 462
dc26eeb3 463 GtkButton *button = GTK_BUTTON( node->GetData()->button );
afa7bd1e 464 GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child);
9e691f46 465
907789a0 466 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 467 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
1a87edf2
WS
468
469 return true;
6de97a3b 470}
c801d85f 471
aa61d352 472bool wxRadioBox::IsItemEnabled(unsigned int item) const
27c78e45
VZ
473{
474 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
475
dc26eeb3 476 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
27c78e45
VZ
477
478 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
479
dc26eeb3 480 GtkButton *button = GTK_BUTTON( node->GetData()->button );
27c78e45
VZ
481
482 // don't use GTK_WIDGET_IS_SENSITIVE() here, we want to return true even if
483 // the parent radiobox is disabled
484 return GTK_WIDGET_SENSITIVE(GTK_WIDGET(button));
485}
486
aa61d352 487bool wxRadioBox::Show(unsigned int item, bool show)
c801d85f 488{
789f6795 489 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 490
dc26eeb3 491 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 492
789f6795 493 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 494
dc26eeb3 495 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
c801d85f 496
907789a0
RR
497 if (show)
498 gtk_widget_show( button );
499 else
500 gtk_widget_hide( button );
789f6795
WS
501
502 return true;
6de97a3b 503}
c801d85f 504
aa61d352 505bool wxRadioBox::IsItemShown(unsigned int item) const
c801d85f 506{
27c78e45 507 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 508
dc26eeb3 509 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
c801d85f 510
27c78e45 511 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 512
dc26eeb3 513 GtkButton *button = GTK_BUTTON( node->GetData()->button );
29006414 514
27c78e45 515 return GTK_WIDGET_VISIBLE(GTK_WIDGET(button));
6de97a3b 516}
c801d85f 517
aa61d352 518unsigned int wxRadioBox::GetCount() const
c801d85f 519{
dc26eeb3 520 return m_buttonsInfo.GetCount();
6de97a3b 521}
c801d85f 522
72a7edf0 523void wxRadioBox::GtkDisableEvents()
953704c1 524{
dc26eeb3 525 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
953704c1
RR
526 while (node)
527 {
98264520
PC
528 g_signal_handlers_block_by_func(node->GetData()->button,
529 (gpointer)gtk_radiobutton_clicked_callback, this);
953704c1 530
b1d4dd7a 531 node = node->GetNext();
953704c1
RR
532 }
533}
534
72a7edf0 535void wxRadioBox::GtkEnableEvents()
953704c1 536{
dc26eeb3 537 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
953704c1
RR
538 while (node)
539 {
98264520
PC
540 g_signal_handlers_unblock_by_func(node->GetData()->button,
541 (gpointer)gtk_radiobutton_clicked_callback, this);
953704c1 542
b1d4dd7a 543 node = node->GetNext();
953704c1
RR
544 }
545}
546
f40fdaa3 547void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 548{
2e1f5012 549 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget), style);
81e88f5b 550
dc26eeb3 551 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
552 while (node)
553 {
dc26eeb3 554 GtkWidget *widget = GTK_WIDGET( node->GetData()->button );
29006414 555
f40fdaa3 556 gtk_widget_modify_style( widget, style );
afa7bd1e 557 gtk_widget_modify_style(GTK_BIN(widget)->child, style);
29006414 558
b1d4dd7a 559 node = node->GetNext();
907789a0 560 }
868a2826 561}
b4071e91 562
2e1f5012
VZ
563bool wxRadioBox::GTKWidgetNeedsMnemonic() const
564{
565 return true;
566}
567
568void wxRadioBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
569{
570 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget), w);
571}
572
72a7edf0 573#if wxUSE_TOOLTIPS
6e5f6c7c 574void wxRadioBox::ApplyToolTip(GtkTooltips * WXUNUSED(tips), const gchar *tip)
72a7edf0 575{
aa1e6de9
VZ
576 // set this tooltip for all radiobuttons which don't have their own tips
577 unsigned n = 0;
dc26eeb3 578 for ( wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
aa1e6de9
VZ
579 node;
580 node = node->GetNext(), n++ )
72a7edf0 581 {
aa1e6de9
VZ
582 if ( !GetItemToolTip(n) )
583 {
6e5f6c7c 584 wxToolTip::Apply(GTK_WIDGET(node->GetData()->button), tip);
aa1e6de9 585 }
72a7edf0
RR
586 }
587}
aa1e6de9
VZ
588
589void wxRadioBox::DoSetItemToolTip(unsigned int n, wxToolTip *tooltip)
590{
591 wxCharBuffer buf;
592 if ( !tooltip )
593 tooltip = GetToolTip();
594 if ( tooltip )
595 buf = wxGTK_CONV(tooltip->GetTip());
596
dc26eeb3 597 wxToolTip::Apply(GTK_WIDGET(m_buttonsInfo[n]->button), buf);
aa1e6de9
VZ
598}
599
72a7edf0
RR
600#endif // wxUSE_TOOLTIPS
601
ef5c70f9 602GdkWindow *wxRadioBox::GTKGetWindow(wxArrayGdkWindows& windows) const
b4071e91 603{
ef5c70f9 604 windows.push_back(m_widget->window);
29006414 605
dc26eeb3 606 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
607 while (node)
608 {
dc26eeb3 609 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
29006414 610
ef5c70f9 611 windows.push_back(button->window);
29006414 612
b1d4dd7a 613 node = node->GetNext();
907789a0 614 }
29006414 615
ef5c70f9 616 return NULL;
b4071e91 617}
dcf924a3 618
9d522606
RD
619// static
620wxVisualAttributes
621wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
622{
623 wxVisualAttributes attr;
bc0eb46c
VS
624 // NB: we need toplevel window so that GTK+ can find the right style
625 GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
9d522606 626 GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
bc0eb46c 627 gtk_container_add(GTK_CONTAINER(wnd), widget);
9d522606 628 attr = GetDefaultAttributesFromGTKWidget(widget);
bc0eb46c 629 gtk_widget_destroy(wnd);
9d522606
RD
630 return attr;
631}
632
dc26eeb3
VZ
633int wxRadioBox::GetItemFromPoint(const wxPoint& point) const
634{
635 const wxPoint pt = ScreenToClient(point);
636 unsigned n = 0;
637 for ( wxRadioBoxButtonsInfoList::compatibility_iterator
638 node = m_buttonsInfo.GetFirst(); node; node = node->GetNext(), n++ )
639 {
22a35096 640 if ( m_buttonsInfo[n]->rect.Contains(pt) )
dc26eeb3
VZ
641 return n;
642 }
643
644 return wxNOT_FOUND;
645}
646
f6bcfd97 647#endif // wxUSE_RADIOBOX