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