]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/radiobox.cpp
fixed loop deleting the old filters in SetWildcard() after last commit
[wxWidgets.git] / src / gtk1 / radiobox.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobox.cpp
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 10#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
c801d85f
KB
11#pragma implementation "radiobox.h"
12#endif
13
14f355c2
VS
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
dcf924a3
RR
16
17#if wxUSE_RADIOBOX
18
1e6feb95
VZ
19#include "wx/radiobox.h"
20
c801d85f
KB
21#include "wx/dialog.h"
22#include "wx/frame.h"
cc1fcb95 23#include "wx/log.h"
83624f79 24
9e691f46 25#include "wx/gtk/private.h"
3f26799e
RR
26#include <gdk/gdkkeysyms.h>
27
c801d85f
KB
28#include "wx/gtk/win_gtk.h"
29
acfd422a
RR
30//-----------------------------------------------------------------------------
31// idle system
32//-----------------------------------------------------------------------------
33
34extern void wxapp_install_idle_handler();
35extern bool g_isIdle;
36
66bd6b93
RR
37//-----------------------------------------------------------------------------
38// data
39//-----------------------------------------------------------------------------
40
d7fa7eaa
RR
41extern bool g_blockEventsOnDrag;
42extern wxWindowGTK *g_delayedFocus;
66bd6b93 43
c801d85f 44//-----------------------------------------------------------------------------
b4071e91 45// "clicked"
c801d85f
KB
46//-----------------------------------------------------------------------------
47
e2762ff0 48static void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioBox *rb )
c801d85f 49{
acfd422a
RR
50 if (g_isIdle) wxapp_install_idle_handler();
51
a2053b27 52 if (!rb->m_hasVMT) return;
907789a0 53 if (g_blockEventsOnDrag) return;
29006414 54
e2762ff0 55 if (!button->active) return;
29006414 56
907789a0
RR
57 wxCommandEvent event( wxEVT_COMMAND_RADIOBOX_SELECTED, rb->GetId() );
58 event.SetInt( rb->GetSelection() );
29006414 59 event.SetString( rb->GetStringSelection() );
907789a0
RR
60 event.SetEventObject( rb );
61 rb->GetEventHandler()->ProcessEvent(event);
6de97a3b 62}
c801d85f 63
2e0e025e
RR
64//-----------------------------------------------------------------------------
65// "key_press_event"
66//-----------------------------------------------------------------------------
67
68static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb )
69{
70 if (g_isIdle)
71 wxapp_install_idle_handler();
72
73 if (!rb->m_hasVMT) return FALSE;
74 if (g_blockEventsOnDrag) return FALSE;
75
76 if ((gdk_event->keyval != GDK_Up) &&
77 (gdk_event->keyval != GDK_Down) &&
78 (gdk_event->keyval != GDK_Left) &&
79 (gdk_event->keyval != GDK_Right))
80 {
81 return FALSE;
82 }
2da61056 83
222ed1d6 84 wxList::compatibility_iterator node = rb->m_boxes.Find( (wxObject*) widget );
2e0e025e
RR
85 if (!node)
86 {
87 return FALSE;
88 }
2da61056 89
2e0e025e 90 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
2da61056 91
2e0e025e
RR
92 if ((gdk_event->keyval == GDK_Up) ||
93 (gdk_event->keyval == GDK_Left))
94 {
b1d4dd7a
RL
95 if (node == rb->m_boxes.GetFirst())
96 node = rb->m_boxes.GetLast();
2da61056 97 else
b1d4dd7a 98 node = node->GetPrevious();
2e0e025e
RR
99 }
100 else
101 {
b1d4dd7a
RL
102 if (node == rb->m_boxes.GetLast())
103 node = rb->m_boxes.GetFirst();
2da61056 104 else
b1d4dd7a 105 node = node->GetNext();
2e0e025e 106 }
2da61056 107
b1d4dd7a 108 GtkWidget *button = (GtkWidget*) node->GetData();
2da61056 109
2e0e025e 110 gtk_widget_grab_focus( button );
2da61056 111
2e0e025e
RR
112 return TRUE;
113}
114
f6bcfd97
BP
115static gint gtk_radiobutton_focus_in( GtkWidget *widget,
116 GdkEvent *WXUNUSED(event),
117 wxRadioBox *win )
118{
119 if ( win->m_lostFocus )
120 {
121 // no, we didn't really lose it
122 win->m_lostFocus = FALSE;
123 }
124 else if ( !win->m_hasFocus )
125 {
b4efc9b9 126 win->m_hasFocus = true;
f6bcfd97
BP
127
128 wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
129 event.SetEventObject( win );
130
131 // never stop the signal emission, it seems to break the kbd handling
132 // inside the radiobox
133 (void)win->GetEventHandler()->ProcessEvent( event );
134 }
135
136 return FALSE;
137}
138
139static gint gtk_radiobutton_focus_out( GtkWidget *widget,
140 GdkEvent *WXUNUSED(event),
141 wxRadioBox *win )
142{
cc1fcb95
JS
143 // wxASSERT_MSG( win->m_hasFocus, _T("got focus out without any focus in?") );
144 // Replace with a warning, else we dump core a lot!
145 // if (!win->m_hasFocus)
146 // wxLogWarning(_T("Radiobox got focus out without any focus in.") );
f6bcfd97
BP
147
148 // we might have lost the focus, but may be not - it may have just gone to
149 // another button in the same radiobox, so we'll check for it in the next
b4efc9b9
WS
150 // idle iteration (leave m_hasFocus == true for now)
151 win->m_lostFocus = true;
f6bcfd97
BP
152
153 return FALSE;
154}
155
b4071e91
RR
156//-----------------------------------------------------------------------------
157// wxRadioBox
c801d85f
KB
158//-----------------------------------------------------------------------------
159
160IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl)
161
f6bcfd97 162void wxRadioBox::Init()
c801d85f 163{
b4efc9b9
WS
164 m_needParent = true;
165 m_acceptsFocus = true;
f6bcfd97
BP
166
167 m_hasFocus =
b4efc9b9 168 m_lostFocus = false;
6de97a3b 169}
c801d85f 170
584ad2a3
MB
171bool wxRadioBox::Create( wxWindow *parent, wxWindowID id,
172 const wxString& title,
173 const wxPoint &pos, const wxSize &size,
174 const wxArrayString& choices, int majorDim,
175 long style, const wxValidator& validator,
176 const wxString &name )
177{
178 wxCArrayString chs(choices);
179
180 return Create( parent, id, title, pos, size, chs.GetCount(),
181 chs.GetStrings(), majorDim, style, validator, name );
182}
183
debe6624 184bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
907789a0 185 const wxPoint &pos, const wxSize &size,
29006414
VZ
186 int n, const wxString choices[], int majorDim,
187 long style, const wxValidator& validator,
188 const wxString &name )
c801d85f 189{
4dcaf11a
RR
190 if (!PreCreation( parent, pos, size ) ||
191 !CreateBase( parent, id, pos, size, style, validator, name ))
192 {
223d09f6 193 wxFAIL_MSG( wxT("wxRadioBox creation failed") );
b4efc9b9 194 return false;
4dcaf11a 195 }
6de97a3b 196
fab591c5 197 m_widget = gtk_frame_new( wxGTK_CONV( title ) );
29006414 198
5eaac5b5
VZ
199 // majorDim may be 0 if all trailing parameters were omitted, so don't
200 // assert here but just use the correct value for it
201 m_majorDim = majorDim == 0 ? n : majorDim;
29006414 202
8017ee9b
RR
203 int num_per_major = (n - 1) / m_majorDim +1;
204
205 int num_of_cols = 0;
206 int num_of_rows = 0;
207 if (HasFlag(wxRA_SPECIFY_COLS))
208 {
209 num_of_cols = m_majorDim;
210 num_of_rows = num_per_major;
211 }
212 else
213 {
214 num_of_cols = num_per_major;
215 num_of_rows = m_majorDim;
216 }
217
907789a0 218 GtkRadioButton *m_radio = (GtkRadioButton*) NULL;
29006414 219
8017ee9b 220 GtkWidget *table = gtk_table_new( num_of_rows, num_of_cols, FALSE );
d504085d
RR
221 gtk_table_set_col_spacings( GTK_TABLE(table), 1 );
222 gtk_table_set_row_spacings( GTK_TABLE(table), 1 );
8017ee9b
RR
223 gtk_widget_show( table );
224 gtk_container_add( GTK_CONTAINER(m_widget), table );
225
26333898 226 wxString label;
d3b4d113
RR
227 GSList *radio_button_group = (GSList *) NULL;
228 for (int i = 0; i < n; i++)
c801d85f 229 {
26333898
VZ
230 if ( i != 0 )
231 radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) );
29006414 232
26333898
VZ
233 label.Empty();
234 for ( const wxChar *pc = choices[i]; *pc; pc++ )
235 {
223d09f6 236 if ( *pc != wxT('&') )
26333898
VZ
237 label += *pc;
238 }
239
fab591c5 240 m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) );
8017ee9b 241 gtk_widget_show( GTK_WIDGET(m_radio) );
29006414 242
2e0e025e
RR
243 gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event",
244 GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this );
2da61056 245
d3b4d113 246 m_boxes.Append( (wxObject*) m_radio );
29006414 247
8017ee9b
RR
248 if (HasFlag(wxRA_SPECIFY_COLS))
249 {
250 int left = i%num_of_cols;
251 int right = (i%num_of_cols) + 1;
252 int top = i/num_of_cols;
253 int bottom = (i/num_of_cols)+1;
d504085d
RR
254 gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(m_radio), left, right, top, bottom,
255 GTK_FILL, GTK_FILL, 1, 1 );
8017ee9b
RR
256 }
257 else
258 {
259 int left = i/num_of_rows;
260 int right = (i/num_of_rows) + 1;
261 int top = i%num_of_rows;
262 int bottom = (i%num_of_rows)+1;
d504085d
RR
263 gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(m_radio), left, right, top, bottom,
264 GTK_FILL, GTK_FILL, 1, 1 );
8017ee9b
RR
265 }
266
d3b4d113 267 ConnectWidget( GTK_WIDGET(m_radio) );
29006414 268
d3b4d113 269 if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE );
29006414
VZ
270
271 gtk_signal_connect( GTK_OBJECT(m_radio), "clicked",
354aa1e3 272 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
29006414 273
f6bcfd97
BP
274 gtk_signal_connect( GTK_OBJECT(m_radio), "focus_in_event",
275 GTK_SIGNAL_FUNC(gtk_radiobutton_focus_in), (gpointer)this );
276
277 gtk_signal_connect( GTK_OBJECT(m_radio), "focus_out_event",
278 GTK_SIGNAL_FUNC(gtk_radiobutton_focus_out), (gpointer)this );
6de97a3b 279 }
29006414 280
db434467
RR
281 m_parent->DoAddChild( this );
282
db434467
RR
283 SetLabel( title );
284
abdeb9e7 285 PostCreation(size);
29006414 286
b4efc9b9 287 return true;
6de97a3b 288}
c801d85f 289
f03fc89f 290wxRadioBox::~wxRadioBox()
d6d1892b 291{
222ed1d6 292 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
293 while (node)
294 {
b1d4dd7a 295 GtkWidget *button = GTK_WIDGET( node->GetData() );
907789a0 296 gtk_widget_destroy( button );
b1d4dd7a 297 node = node->GetNext();
907789a0 298 }
d6d1892b
RR
299}
300
debe6624 301bool wxRadioBox::Show( bool show )
c801d85f 302{
b4efc9b9 303 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 304
f96ac56a
RR
305 if (!wxControl::Show(show))
306 {
307 // nothing to do
b4efc9b9 308 return false;
f96ac56a 309 }
c801d85f 310
c4ca49cd 311 if ( HasFlag(wxNO_BORDER) )
b0351fc9 312 gtk_widget_hide( m_widget );
e3e717ec 313
222ed1d6 314 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
315 while (node)
316 {
b1d4dd7a 317 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 318
907789a0 319 if (show) gtk_widget_show( button ); else gtk_widget_hide( button );
29006414 320
b1d4dd7a 321 node = node->GetNext();
907789a0 322 }
c801d85f 323
b4efc9b9 324 return true;
6de97a3b 325}
c801d85f 326
2b5f62a0 327int wxRadioBox::FindString( const wxString &find ) const
c801d85f 328{
789f6795 329 wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") );
29006414 330
907789a0 331 int count = 0;
29006414 332
222ed1d6 333 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
334 while (node)
335 {
b1d4dd7a 336 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
2b5f62a0
VZ
337#ifdef __WXGTK20__
338 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
339#else
340 wxString str( label->label );
341#endif
342 if (find == str)
9e691f46 343 return count;
29006414 344
907789a0 345 count++;
29006414 346
b1d4dd7a 347 node = node->GetNext();
907789a0 348 }
29006414 349
789f6795 350 return wxNOT_FOUND;
6de97a3b 351}
c801d85f 352
b292e2f5
RR
353void wxRadioBox::SetFocus()
354{
223d09f6 355 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 356
b292e2f5 357 if (m_boxes.GetCount() == 0) return;
29006414 358
222ed1d6 359 wxList::compatibility_iterator node = m_boxes.GetFirst();
b292e2f5
RR
360 while (node)
361 {
b1d4dd7a 362 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
b292e2f5 363 if (button->active)
29006414 364 {
b292e2f5 365 gtk_widget_grab_focus( GTK_WIDGET(button) );
29006414
VZ
366 return;
367 }
b1d4dd7a 368 node = node->GetNext();
b292e2f5 369 }
b292e2f5
RR
370}
371
47908e25 372void wxRadioBox::SetSelection( int n )
c801d85f 373{
223d09f6 374 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 375
222ed1d6 376 wxList::compatibility_iterator node = m_boxes.Item( n );
29006414 377
223d09f6 378 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 379
b1d4dd7a 380 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
29006414 381
72a7edf0 382 GtkDisableEvents();
2da61056 383
e2762ff0 384 gtk_toggle_button_set_active( button, 1 );
2da61056 385
72a7edf0 386 GtkEnableEvents();
6de97a3b 387}
c801d85f
KB
388
389int wxRadioBox::GetSelection(void) const
390{
789f6795 391 wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") );
29006414 392
907789a0 393 int count = 0;
29006414 394
222ed1d6 395 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
396 while (node)
397 {
b1d4dd7a 398 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
907789a0
RR
399 if (button->active) return count;
400 count++;
b1d4dd7a 401 node = node->GetNext();
907789a0 402 }
29006414 403
223d09f6 404 wxFAIL_MSG( wxT("wxRadioBox none selected") );
29006414 405
789f6795 406 return wxNOT_FOUND;
6de97a3b 407}
c801d85f 408
47908e25 409wxString wxRadioBox::GetString( int n ) const
c801d85f 410{
1a87edf2 411 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") );
29006414 412
222ed1d6 413 wxList::compatibility_iterator node = m_boxes.Item( n );
29006414 414
1a87edf2 415 wxCHECK_MSG( node, wxEmptyString, wxT("radiobox wrong index") );
29006414 416
b1d4dd7a 417 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
29006414 418
2b5f62a0
VZ
419#ifdef __WXGTK20__
420 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
421#else
422 wxString str( label->label );
423#endif
424
425 return str;
6de97a3b 426}
c801d85f 427
d3904ceb 428void wxRadioBox::SetLabel( const wxString& label )
c801d85f 429{
223d09f6 430 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 431
907789a0 432 wxControl::SetLabel( label );
29006414 433
fab591c5 434 gtk_frame_set_label( GTK_FRAME(m_widget), wxGTK_CONV( wxControl::GetLabel() ) );
6de97a3b 435}
c801d85f 436
2da61056 437void wxRadioBox::SetString( int item, const wxString& label )
c801d85f 438{
223d09f6 439 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 440
222ed1d6 441 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 442
223d09f6 443 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 444
b1d4dd7a 445 GtkLabel *g_label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
29006414 446
fab591c5 447 gtk_label_set( g_label, wxGTK_CONV( label ) );
6de97a3b 448}
c801d85f 449
f03fc89f 450bool wxRadioBox::Enable( bool enable )
c801d85f 451{
f03fc89f 452 if ( !wxControl::Enable( enable ) )
b4efc9b9 453 return false;
29006414 454
222ed1d6 455 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
456 while (node)
457 {
b1d4dd7a 458 GtkButton *button = GTK_BUTTON( node->GetData() );
9e691f46
VZ
459 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) );
460
907789a0 461 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 462 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
b1d4dd7a 463 node = node->GetNext();
907789a0 464 }
f03fc89f 465
b4efc9b9 466 return true;
6de97a3b 467}
c801d85f 468
1a87edf2 469bool wxRadioBox::Enable( int item, bool enable )
c801d85f 470{
1a87edf2 471 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 472
222ed1d6 473 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 474
1a87edf2 475 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 476
b1d4dd7a 477 GtkButton *button = GTK_BUTTON( node->GetData() );
9e691f46
VZ
478 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) );
479
907789a0 480 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 481 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
1a87edf2
WS
482
483 return true;
6de97a3b 484}
c801d85f 485
789f6795 486bool wxRadioBox::Show( int item, bool show )
c801d85f 487{
789f6795 488 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 489
222ed1d6 490 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 491
789f6795 492 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 493
b1d4dd7a 494 GtkWidget *button = GTK_WIDGET( node->GetData() );
c801d85f 495
907789a0
RR
496 if (show)
497 gtk_widget_show( button );
498 else
499 gtk_widget_hide( button );
789f6795
WS
500
501 return true;
6de97a3b 502}
c801d85f 503
9c884972 504wxString wxRadioBox::GetStringSelection() const
c801d85f 505{
1a87edf2 506 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") );
29006414 507
222ed1d6 508 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0 509 while (node)
c801d85f 510 {
b1d4dd7a 511 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
907789a0
RR
512 if (button->active)
513 {
b1d4dd7a 514 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
9e691f46 515
2b5f62a0
VZ
516#ifdef __WXGTK20__
517 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
518#else
519 wxString str( label->label );
520#endif
521 return str;
907789a0 522 }
b1d4dd7a 523 node = node->GetNext();
6de97a3b 524 }
29006414 525
223d09f6 526 wxFAIL_MSG( wxT("wxRadioBox none selected") );
1a87edf2 527 return wxEmptyString;
6de97a3b 528}
c801d85f 529
907789a0 530bool wxRadioBox::SetStringSelection( const wxString &s )
c801d85f 531{
b4efc9b9 532 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 533
907789a0 534 int res = FindString( s );
789f6795 535 if (res == wxNOT_FOUND) return false;
907789a0 536 SetSelection( res );
29006414 537
b4efc9b9 538 return true;
6de97a3b 539}
c801d85f 540
2da61056 541int wxRadioBox::GetCount() const
c801d85f 542{
b1d4dd7a 543 return m_boxes.GetCount();
6de97a3b 544}
c801d85f 545
72a7edf0 546void wxRadioBox::GtkDisableEvents()
953704c1 547{
222ed1d6 548 wxList::compatibility_iterator node = m_boxes.GetFirst();
953704c1
RR
549 while (node)
550 {
b1d4dd7a 551 gtk_signal_disconnect_by_func( GTK_OBJECT(node->GetData()),
953704c1
RR
552 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
553
b1d4dd7a 554 node = node->GetNext();
953704c1
RR
555 }
556}
557
72a7edf0 558void wxRadioBox::GtkEnableEvents()
953704c1 559{
222ed1d6 560 wxList::compatibility_iterator node = m_boxes.GetFirst();
953704c1
RR
561 while (node)
562 {
b1d4dd7a 563 gtk_signal_connect( GTK_OBJECT(node->GetData()), "clicked",
953704c1
RR
564 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
565
b1d4dd7a 566 node = node->GetNext();
953704c1
RR
567 }
568}
569
f40fdaa3 570void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 571{
f40fdaa3 572 gtk_widget_modify_style( m_widget, style );
29006414 573
81e88f5b
RR
574#ifdef __WXGTK20__
575 gtk_widget_modify_style(GTK_FRAME(m_widget)->label_widget, style);
576#endif
577
222ed1d6 578 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
579 while (node)
580 {
b1d4dd7a 581 GtkWidget *widget = GTK_WIDGET( node->GetData() );
29006414 582
f40fdaa3
VS
583 gtk_widget_modify_style( widget, style );
584 gtk_widget_modify_style( BUTTON_CHILD(node->GetData()), style );
29006414 585
b1d4dd7a 586 node = node->GetNext();
907789a0 587 }
868a2826 588}
b4071e91 589
72a7edf0
RR
590#if wxUSE_TOOLTIPS
591void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
592{
222ed1d6 593 wxList::compatibility_iterator node = m_boxes.GetFirst();
72a7edf0
RR
594 while (node)
595 {
b1d4dd7a 596 GtkWidget *widget = GTK_WIDGET( node->GetData() );
72a7edf0 597 gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL );
b1d4dd7a 598 node = node->GetNext();
72a7edf0
RR
599 }
600}
601#endif // wxUSE_TOOLTIPS
602
b4071e91
RR
603bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window )
604{
b4efc9b9 605 if (window == m_widget->window) return true;
29006414 606
222ed1d6 607 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
608 while (node)
609 {
b1d4dd7a 610 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 611
b4efc9b9 612 if (window == button->window) return true;
29006414 613
b1d4dd7a 614 node = node->GetNext();
907789a0 615 }
29006414 616
b4efc9b9 617 return false;
b4071e91 618}
dcf924a3 619
f6bcfd97
BP
620void wxRadioBox::OnInternalIdle()
621{
622 if ( m_lostFocus )
623 {
b4efc9b9
WS
624 m_hasFocus = false;
625 m_lostFocus = false;
f6bcfd97
BP
626
627 wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() );
628 event.SetEventObject( this );
629
630 (void)GetEventHandler()->ProcessEvent( event );
631 }
d7fa7eaa
RR
632
633 if (g_delayedFocus == this)
634 {
635 if (GTK_WIDGET_REALIZED(m_widget))
636 {
637 g_delayedFocus = NULL;
638 SetFocus();
639 }
640 }
f6bcfd97
BP
641}
642
9d522606
RD
643// static
644wxVisualAttributes
645wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
646{
647 wxVisualAttributes attr;
bc0eb46c
VS
648 // NB: we need toplevel window so that GTK+ can find the right style
649 GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
9d522606 650 GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
bc0eb46c 651 gtk_container_add(GTK_CONTAINER(wnd), widget);
9d522606 652 attr = GetDefaultAttributesFromGTKWidget(widget);
bc0eb46c 653 gtk_widget_destroy(wnd);
9d522606
RD
654 return attr;
655}
656
b4efc9b9
WS
657#if WXWIN_COMPATIBILITY_2_2
658
659int wxRadioBox::Number() const
660{
661 return GetCount();
662}
663
664wxString wxRadioBox::GetLabel(int n) const
665{
666 return GetString(n);
667}
668
669void wxRadioBox::SetLabel( int item, const wxString& label )
670{
671 SetString(item, label);
672}
673
674#endif // WXWIN_COMPATIBILITY_2_2
675
f6bcfd97
BP
676#endif // wxUSE_RADIOBOX
677