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