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