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