]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobox.cpp
added missing menu.cpp
[wxWidgets.git] / src / gtk / 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
29006414 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
c801d85f
KB
10#ifdef __GNUG__
11#pragma implementation "radiobox.h"
12#endif
13
1e6feb95 14#include "wx/defs.h"
dcf924a3
RR
15
16#if wxUSE_RADIOBOX
17
1e6feb95
VZ
18#include "wx/radiobox.h"
19
c801d85f
KB
20#include "wx/dialog.h"
21#include "wx/frame.h"
cc1fcb95 22#include "wx/log.h"
83624f79 23
3f26799e
RR
24#include <gdk/gdk.h>
25#include <gtk/gtk.h>
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
69ffe1d2 41extern bool g_blockEventsOnDrag;
66bd6b93 42
c801d85f 43//-----------------------------------------------------------------------------
b4071e91 44// "clicked"
c801d85f
KB
45//-----------------------------------------------------------------------------
46
66bd6b93 47static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioBox *rb )
c801d85f 48{
acfd422a
RR
49 if (g_isIdle) wxapp_install_idle_handler();
50
a2053b27 51 if (!rb->m_hasVMT) return;
907789a0 52 if (g_blockEventsOnDrag) return;
29006414 53
907789a0
RR
54 if (rb->m_alreadySent)
55 {
56 rb->m_alreadySent = FALSE;
57 return;
58 }
47908e25 59
907789a0 60 rb->m_alreadySent = TRUE;
29006414 61
907789a0
RR
62 wxCommandEvent event( wxEVT_COMMAND_RADIOBOX_SELECTED, rb->GetId() );
63 event.SetInt( rb->GetSelection() );
29006414 64 event.SetString( rb->GetStringSelection() );
907789a0
RR
65 event.SetEventObject( rb );
66 rb->GetEventHandler()->ProcessEvent(event);
6de97a3b 67}
c801d85f 68
2e0e025e
RR
69//-----------------------------------------------------------------------------
70// "key_press_event"
71//-----------------------------------------------------------------------------
72
73static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb )
74{
75 if (g_isIdle)
76 wxapp_install_idle_handler();
77
78 if (!rb->m_hasVMT) return FALSE;
79 if (g_blockEventsOnDrag) return FALSE;
80
81 if ((gdk_event->keyval != GDK_Up) &&
82 (gdk_event->keyval != GDK_Down) &&
83 (gdk_event->keyval != GDK_Left) &&
84 (gdk_event->keyval != GDK_Right))
85 {
86 return FALSE;
87 }
88
89 wxNode *node = rb->m_boxes.Find( (wxObject*) widget );
90 if (!node)
91 {
92 return FALSE;
93 }
94
95 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
96
97 if ((gdk_event->keyval == GDK_Up) ||
98 (gdk_event->keyval == GDK_Left))
99 {
100 if (node == rb->m_boxes.First())
101 node = rb->m_boxes.Last();
102 else
103 node = node->Previous();
104 }
105 else
106 {
107 if (node == rb->m_boxes.Last())
108 node = rb->m_boxes.First();
109 else
110 node = node->Next();
111 }
112
113 GtkWidget *button = (GtkWidget*) node->Data();
114
115 gtk_widget_grab_focus( button );
116
117 return TRUE;
118}
119
f6bcfd97
BP
120static gint gtk_radiobutton_focus_in( GtkWidget *widget,
121 GdkEvent *WXUNUSED(event),
122 wxRadioBox *win )
123{
124 if ( win->m_lostFocus )
125 {
126 // no, we didn't really lose it
127 win->m_lostFocus = FALSE;
128 }
129 else if ( !win->m_hasFocus )
130 {
131 win->m_hasFocus = TRUE;
132
133 wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
134 event.SetEventObject( win );
135
136 // never stop the signal emission, it seems to break the kbd handling
137 // inside the radiobox
138 (void)win->GetEventHandler()->ProcessEvent( event );
139 }
140
141 return FALSE;
142}
143
144static gint gtk_radiobutton_focus_out( GtkWidget *widget,
145 GdkEvent *WXUNUSED(event),
146 wxRadioBox *win )
147{
cc1fcb95
JS
148 // wxASSERT_MSG( win->m_hasFocus, _T("got focus out without any focus in?") );
149 // Replace with a warning, else we dump core a lot!
150 // if (!win->m_hasFocus)
151 // wxLogWarning(_T("Radiobox got focus out without any focus in.") );
f6bcfd97
BP
152
153 // we might have lost the focus, but may be not - it may have just gone to
154 // another button in the same radiobox, so we'll check for it in the next
155 // idle iteration (leave m_hasFocus == TRUE for now)
156 win->m_lostFocus = TRUE;
157
158 return FALSE;
159}
160
b4071e91
RR
161//-----------------------------------------------------------------------------
162// wxRadioBox
c801d85f
KB
163//-----------------------------------------------------------------------------
164
165IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl)
166
f6bcfd97 167void wxRadioBox::Init()
c801d85f 168{
f6bcfd97
BP
169 m_alreadySent = FALSE;
170 m_needParent = TRUE;
171 m_acceptsFocus = TRUE;
172
173 m_hasFocus =
174 m_lostFocus = FALSE;
6de97a3b 175}
c801d85f 176
debe6624 177bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
907789a0 178 const wxPoint &pos, const wxSize &size,
29006414
VZ
179 int n, const wxString choices[], int majorDim,
180 long style, const wxValidator& validator,
181 const wxString &name )
c801d85f 182{
4dcaf11a
RR
183 if (!PreCreation( parent, pos, size ) ||
184 !CreateBase( parent, id, pos, size, style, validator, name ))
185 {
223d09f6 186 wxFAIL_MSG( wxT("wxRadioBox creation failed") );
4dcaf11a
RR
187 return FALSE;
188 }
6de97a3b 189
b019151f 190 m_widget = gtk_frame_new( title.mbc_str() );
29006414 191
5eaac5b5
VZ
192 // majorDim may be 0 if all trailing parameters were omitted, so don't
193 // assert here but just use the correct value for it
194 m_majorDim = majorDim == 0 ? n : majorDim;
29006414 195
907789a0 196 GtkRadioButton *m_radio = (GtkRadioButton*) NULL;
29006414 197
26333898 198 wxString label;
d3b4d113
RR
199 GSList *radio_button_group = (GSList *) NULL;
200 for (int i = 0; i < n; i++)
c801d85f 201 {
26333898
VZ
202 if ( i != 0 )
203 radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) );
29006414 204
26333898
VZ
205 label.Empty();
206 for ( const wxChar *pc = choices[i]; *pc; pc++ )
207 {
223d09f6 208 if ( *pc != wxT('&') )
26333898
VZ
209 label += *pc;
210 }
211
212 m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, label.mbc_str() ) );
29006414 213
2e0e025e
RR
214 gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event",
215 GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this );
216
d3b4d113 217 m_boxes.Append( (wxObject*) m_radio );
29006414 218
d3b4d113 219 ConnectWidget( GTK_WIDGET(m_radio) );
29006414 220
d3b4d113 221 if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE );
29006414
VZ
222
223 gtk_signal_connect( GTK_OBJECT(m_radio), "clicked",
354aa1e3 224 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
29006414 225
f6bcfd97
BP
226 gtk_signal_connect( GTK_OBJECT(m_radio), "focus_in_event",
227 GTK_SIGNAL_FUNC(gtk_radiobutton_focus_in), (gpointer)this );
228
229 gtk_signal_connect( GTK_OBJECT(m_radio), "focus_out_event",
230 GTK_SIGNAL_FUNC(gtk_radiobutton_focus_out), (gpointer)this );
231
da048e3d 232 gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow),
e3e717ec 233 GTK_WIDGET(m_radio),
f03fc89f 234 m_x+10, m_y+10+(i*24), 10, 10 );
6de97a3b 235 }
29006414 236
db434467
RR
237 m_parent->DoAddChild( this );
238
239 PostCreation();
7e2b55cd
RR
240
241 ApplyWidgetStyle();
db434467 242
db434467
RR
243 SetLabel( title );
244
245 SetFont( parent->GetFont() );
246
d3b4d113 247 wxSize ls = LayoutItems();
29006414 248
a56fcaaf
RR
249 GtkRequisition req;
250 req.width = 2;
251 req.height = 2;
2afa14f2 252 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) (m_widget, &req );
a56fcaaf
RR
253 if (req.width > ls.x) ls.x = req.width;
254
907789a0 255 wxSize newSize = size;
d3b4d113
RR
256 if (newSize.x == -1) newSize.x = ls.x;
257 if (newSize.y == -1) newSize.y = ls.y;
907789a0 258 SetSize( newSize.x, newSize.y );
29006414 259
907789a0
RR
260 SetBackgroundColour( parent->GetBackgroundColour() );
261 SetForegroundColour( parent->GetForegroundColour() );
f96aa4d9 262
907789a0 263 Show( TRUE );
29006414 264
907789a0 265 return TRUE;
6de97a3b 266}
c801d85f 267
f03fc89f 268wxRadioBox::~wxRadioBox()
d6d1892b 269{
907789a0
RR
270 wxNode *node = m_boxes.First();
271 while (node)
272 {
273 GtkWidget *button = GTK_WIDGET( node->Data() );
274 gtk_widget_destroy( button );
275 node = node->Next();
276 }
d6d1892b
RR
277}
278
54517652 279void wxRadioBox::DoSetSize( int x, int y, int width, int height, int sizeFlags )
3f659fd6 280{
54517652
RR
281 wxWindow::DoSetSize( x, y, width, height, sizeFlags );
282
d3b4d113
RR
283 LayoutItems();
284}
285
286wxSize wxRadioBox::LayoutItems()
287{
bbe0af5b
RR
288 int x = 7;
289 int y = 15;
29006414 290
e3e717ec
VZ
291 if ( m_majorDim == 0 )
292 {
293 // avoid dividing by 0 below
223d09f6 294 wxFAIL_MSG( wxT("dimension of radiobox should not be 0!") );
e3e717ec
VZ
295
296 m_majorDim = 1;
297 }
298
d3b4d113 299 int num_per_major = (m_boxes.GetCount() - 1) / m_majorDim +1;
29006414 300
d3b4d113 301 wxSize res( 0, 0 );
29006414 302
e9158f7d
RR
303 int num_of_cols = 0;
304 int num_of_rows = 0;
305 if (HasFlag(wxRA_SPECIFY_COLS))
d3b4d113 306 {
e9158f7d
RR
307 num_of_cols = m_majorDim;
308 num_of_rows = num_per_major;
309 }
310 else
311 {
312 num_of_cols = num_per_major;
313 num_of_rows = m_majorDim;
314 }
315
316 if ( HasFlag(wxRA_SPECIFY_COLS) ||
317 (HasFlag(wxRA_SPECIFY_ROWS) && (num_of_cols > 1)) )
318 {
319 for (int j = 0; j < num_of_cols; j++)
29006414 320 {
bbe0af5b 321 y = 15;
29006414 322
d3b4d113 323 int max_len = 0;
e9158f7d
RR
324 wxNode *node = m_boxes.Nth( j*num_of_rows );
325 for (int i1 = 0; i1< num_of_rows; i1++)
29006414 326 {
d3b4d113 327 GtkWidget *button = GTK_WIDGET( node->Data() );
165b6ee0
VS
328
329 GtkRequisition req;
330 req.width = 2;
331 req.height = 2;
2afa14f2 332 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
165b6ee0
VS
333 (button, &req );
334
335 if (req.width > max_len) max_len = req.width;
29006414 336
da048e3d 337 gtk_pizza_move( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y );
165b6ee0 338 y += req.height;
29006414
VZ
339
340 node = node->Next();
341 if (!node) break;
342 }
343
344 // we don't know the max_len before
345
e9158f7d
RR
346 node = m_boxes.Nth( j*num_of_rows );
347 for (int i2 = 0; i2< num_of_rows; i2++)
29006414 348 {
d3b4d113 349 GtkWidget *button = GTK_WIDGET( node->Data() );
29006414 350
da048e3d 351 gtk_pizza_resize( GTK_PIZZA(m_parent->m_wxwindow), button, max_len, 20 );
29006414
VZ
352
353 node = node->Next();
354 if (!node) break;
355 }
356
357 if (y > res.y) res.y = y;
358
359 x += max_len + 2;
d3b4d113 360 }
29006414
VZ
361
362 res.x = x+4;
165b6ee0 363 res.y += 4;
e5403d7c 364 }
d3b4d113 365 else
e5403d7c 366 {
d3b4d113
RR
367 int max = 0;
368
369 wxNode *node = m_boxes.First();
370 while (node)
371 {
165b6ee0
VS
372 GtkWidget *button = GTK_WIDGET( node->Data() );
373
374 GtkRequisition req;
375 req.width = 2;
376 req.height = 2;
2afa14f2 377 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
165b6ee0 378 (button, &req );
29006414 379
165b6ee0 380 if (req.width > max) max = req.width;
29006414 381
d3b4d113
RR
382 node = node->Next();
383 }
29006414 384
d3b4d113
RR
385 node = m_boxes.First();
386 while (node)
387 {
388 GtkWidget *button = GTK_WIDGET( node->Data() );
29006414 389
da048e3d 390 gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y, max, 20 );
d3b4d113 391 x += max;
29006414 392
d3b4d113
RR
393 node = node->Next();
394 }
29006414 395 res.x = x+4;
3417c2cd 396 res.y = 40;
e5403d7c 397 }
29006414 398
d3b4d113 399 return res;
3f659fd6
RR
400}
401
debe6624 402bool wxRadioBox::Show( bool show )
c801d85f 403{
223d09f6 404 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") );
29006414 405
f96ac56a
RR
406 if (!wxControl::Show(show))
407 {
408 // nothing to do
409 return FALSE;
410 }
c801d85f 411
ba2a0103 412 if ((m_windowStyle & wxNO_BORDER) != 0)
b0351fc9 413 gtk_widget_hide( m_widget );
e3e717ec 414
907789a0
RR
415 wxNode *node = m_boxes.First();
416 while (node)
417 {
418 GtkWidget *button = GTK_WIDGET( node->Data() );
29006414 419
907789a0 420 if (show) gtk_widget_show( button ); else gtk_widget_hide( button );
29006414 421
907789a0
RR
422 node = node->Next();
423 }
c801d85f 424
907789a0 425 return TRUE;
6de97a3b 426}
c801d85f 427
47908e25 428int wxRadioBox::FindString( const wxString &s ) const
c801d85f 429{
223d09f6 430 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") );
29006414 431
907789a0 432 int count = 0;
29006414 433
907789a0
RR
434 wxNode *node = m_boxes.First();
435 while (node)
436 {
437 GtkButton *button = GTK_BUTTON( node->Data() );
29006414 438
907789a0
RR
439 GtkLabel *label = GTK_LABEL( button->child );
440 if (s == label->label) return count;
441 count++;
29006414 442
907789a0
RR
443 node = node->Next();
444 }
29006414 445
907789a0 446 return -1;
6de97a3b 447}
c801d85f 448
b292e2f5
RR
449void wxRadioBox::SetFocus()
450{
223d09f6 451 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 452
b292e2f5 453 if (m_boxes.GetCount() == 0) return;
29006414 454
b292e2f5
RR
455 wxNode *node = m_boxes.First();
456 while (node)
457 {
458 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
459 if (button->active)
29006414 460 {
b292e2f5 461 gtk_widget_grab_focus( GTK_WIDGET(button) );
29006414
VZ
462 return;
463 }
b292e2f5
RR
464 node = node->Next();
465 }
29006414 466
b292e2f5
RR
467}
468
47908e25 469void wxRadioBox::SetSelection( int n )
c801d85f 470{
223d09f6 471 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 472
907789a0 473 wxNode *node = m_boxes.Nth( n );
29006414 474
223d09f6 475 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 476
907789a0 477 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
29006414 478
72a7edf0 479 GtkDisableEvents();
953704c1 480
907789a0 481 gtk_toggle_button_set_state( button, 1 );
953704c1 482
72a7edf0 483 GtkEnableEvents();
6de97a3b 484}
c801d85f
KB
485
486int wxRadioBox::GetSelection(void) const
487{
223d09f6 488 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") );
29006414 489
907789a0 490 int count = 0;
29006414 491
907789a0
RR
492 wxNode *node = m_boxes.First();
493 while (node)
494 {
495 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
496 if (button->active) return count;
497 count++;
498 node = node->Next();
499 }
29006414 500
223d09f6 501 wxFAIL_MSG( wxT("wxRadioBox none selected") );
29006414 502
907789a0 503 return -1;
6de97a3b 504}
c801d85f 505
47908e25 506wxString wxRadioBox::GetString( int n ) const
c801d85f 507{
223d09f6 508 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") );
29006414 509
907789a0 510 wxNode *node = m_boxes.Nth( n );
29006414 511
223d09f6 512 wxCHECK_MSG( node, wxT(""), wxT("radiobox wrong index") );
29006414 513
907789a0
RR
514 GtkButton *button = GTK_BUTTON( node->Data() );
515 GtkLabel *label = GTK_LABEL( button->child );
29006414 516
907789a0 517 return wxString( label->label );
6de97a3b 518}
c801d85f 519
d3904ceb 520wxString wxRadioBox::GetLabel( int item ) const
c801d85f 521{
223d09f6 522 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") );
29006414 523
907789a0 524 return GetString( item );
6de97a3b 525}
c801d85f 526
d3904ceb 527void wxRadioBox::SetLabel( const wxString& label )
c801d85f 528{
223d09f6 529 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 530
907789a0 531 wxControl::SetLabel( label );
29006414 532
b019151f 533 gtk_frame_set_label( GTK_FRAME(m_widget), wxControl::GetLabel().mbc_str() );
6de97a3b 534}
c801d85f 535
d3904ceb 536void wxRadioBox::SetLabel( int item, const wxString& label )
c801d85f 537{
223d09f6 538 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 539
907789a0 540 wxNode *node = m_boxes.Nth( item );
29006414 541
223d09f6 542 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 543
907789a0
RR
544 GtkButton *button = GTK_BUTTON( node->Data() );
545 GtkLabel *g_label = GTK_LABEL( button->child );
29006414 546
b019151f 547 gtk_label_set( g_label, label.mbc_str() );
6de97a3b 548}
c801d85f 549
debe6624 550void wxRadioBox::SetLabel( int WXUNUSED(item), wxBitmap *WXUNUSED(bitmap) )
c801d85f 551{
223d09f6 552 wxFAIL_MSG(wxT("wxRadioBox::SetLabel not implemented."));
6de97a3b 553}
c801d85f 554
f03fc89f 555bool wxRadioBox::Enable( bool enable )
c801d85f 556{
f03fc89f
VZ
557 if ( !wxControl::Enable( enable ) )
558 return FALSE;
29006414 559
907789a0
RR
560 wxNode *node = m_boxes.First();
561 while (node)
562 {
563 GtkButton *button = GTK_BUTTON( node->Data() );
564 GtkWidget *label = button->child;
565 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
566 gtk_widget_set_sensitive( label, enable );
567 node = node->Next();
568 }
f03fc89f
VZ
569
570 return TRUE;
6de97a3b 571}
c801d85f 572
d3904ceb 573void wxRadioBox::Enable( int item, bool enable )
c801d85f 574{
223d09f6 575 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 576
907789a0 577 wxNode *node = m_boxes.Nth( item );
29006414 578
223d09f6 579 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 580
907789a0
RR
581 GtkButton *button = GTK_BUTTON( node->Data() );
582 GtkWidget *label = button->child;
583 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
584 gtk_widget_set_sensitive( label, enable );
6de97a3b 585}
c801d85f 586
d3904ceb 587void wxRadioBox::Show( int item, bool show )
c801d85f 588{
223d09f6 589 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 590
907789a0 591 wxNode *node = m_boxes.Nth( item );
29006414 592
223d09f6 593 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 594
907789a0 595 GtkWidget *button = GTK_WIDGET( node->Data() );
c801d85f 596
907789a0
RR
597 if (show)
598 gtk_widget_show( button );
599 else
600 gtk_widget_hide( button );
6de97a3b 601}
c801d85f 602
9c884972 603wxString wxRadioBox::GetStringSelection() const
c801d85f 604{
223d09f6 605 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") );
29006414 606
907789a0
RR
607 wxNode *node = m_boxes.First();
608 while (node)
c801d85f 609 {
907789a0
RR
610 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
611 if (button->active)
612 {
613 GtkLabel *label = GTK_LABEL( GTK_BUTTON(button)->child );
614 return label->label;
615 }
616 node = node->Next();
6de97a3b 617 }
29006414 618
223d09f6
KB
619 wxFAIL_MSG( wxT("wxRadioBox none selected") );
620 return wxT("");
6de97a3b 621}
c801d85f 622
907789a0 623bool wxRadioBox::SetStringSelection( const wxString &s )
c801d85f 624{
223d09f6 625 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") );
29006414 626
907789a0
RR
627 int res = FindString( s );
628 if (res == -1) return FALSE;
629 SetSelection( res );
29006414 630
907789a0 631 return TRUE;
6de97a3b 632}
c801d85f 633
9c884972 634int wxRadioBox::Number() const
c801d85f 635{
907789a0 636 return m_boxes.Number();
6de97a3b 637}
c801d85f 638
9c884972 639int wxRadioBox::GetNumberOfRowsOrCols() const
c801d85f 640{
907789a0 641 return 1;
6de97a3b 642}
c801d85f 643
debe6624 644void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) )
c801d85f 645{
223d09f6 646 wxFAIL_MSG(wxT("wxRadioBox::SetNumberOfRowsOrCols not implemented."));
6de97a3b 647}
c801d85f 648
72a7edf0 649void wxRadioBox::GtkDisableEvents()
953704c1
RR
650{
651 wxNode *node = m_boxes.First();
652 while (node)
653 {
654 gtk_signal_disconnect_by_func( GTK_OBJECT(node->Data()),
655 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
656
657 node = node->Next();
658 }
659}
660
72a7edf0 661void wxRadioBox::GtkEnableEvents()
953704c1
RR
662{
663 wxNode *node = m_boxes.First();
664 while (node)
665 {
666 gtk_signal_connect( GTK_OBJECT(node->Data()), "clicked",
667 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
668
669 node = node->Next();
670 }
671}
672
58614078 673void wxRadioBox::ApplyWidgetStyle()
868a2826 674{
907789a0 675 SetWidgetStyle();
29006414 676
907789a0 677 gtk_widget_set_style( m_widget, m_widgetStyle );
29006414 678
907789a0
RR
679 wxNode *node = m_boxes.First();
680 while (node)
681 {
682 GtkWidget *widget = GTK_WIDGET( node->Data() );
683 gtk_widget_set_style( widget, m_widgetStyle );
29006414 684
907789a0
RR
685 GtkButton *button = GTK_BUTTON( node->Data() );
686 gtk_widget_set_style( button->child, m_widgetStyle );
29006414 687
907789a0
RR
688 node = node->Next();
689 }
868a2826 690}
b4071e91 691
72a7edf0
RR
692#if wxUSE_TOOLTIPS
693void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
694{
695 wxNode *node = m_boxes.First();
696 while (node)
697 {
698 GtkWidget *widget = GTK_WIDGET( node->Data() );
699 gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL );
700 node = node->Next();
701 }
702}
703#endif // wxUSE_TOOLTIPS
704
b4071e91
RR
705bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window )
706{
907789a0 707 if (window == m_widget->window) return TRUE;
29006414 708
907789a0
RR
709 wxNode *node = m_boxes.First();
710 while (node)
711 {
712 GtkWidget *button = GTK_WIDGET( node->Data() );
29006414 713
907789a0 714 if (window == button->window) return TRUE;
29006414 715
907789a0
RR
716 node = node->Next();
717 }
29006414 718
907789a0 719 return FALSE;
b4071e91 720}
dcf924a3 721
f6bcfd97
BP
722void wxRadioBox::OnInternalIdle()
723{
724 if ( m_lostFocus )
725 {
726 m_hasFocus = FALSE;
727 m_lostFocus = FALSE;
728
729 wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() );
730 event.SetEventObject( this );
731
732 (void)GetEventHandler()->ProcessEvent( event );
733 }
734}
735
736#endif // wxUSE_RADIOBOX
737