]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/radiobox.cpp
Doc/distribution script mods
[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
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
d3b4d113 190 m_majorDim = majorDim;
29006414 191
907789a0 192 GtkRadioButton *m_radio = (GtkRadioButton*) NULL;
29006414 193
26333898 194 wxString label;
d3b4d113
RR
195 GSList *radio_button_group = (GSList *) NULL;
196 for (int i = 0; i < n; i++)
c801d85f 197 {
26333898
VZ
198 if ( i != 0 )
199 radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) );
29006414 200
26333898
VZ
201 label.Empty();
202 for ( const wxChar *pc = choices[i]; *pc; pc++ )
203 {
223d09f6 204 if ( *pc != wxT('&') )
26333898
VZ
205 label += *pc;
206 }
207
208 m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, label.mbc_str() ) );
29006414 209
2e0e025e
RR
210 gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event",
211 GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this );
212
d3b4d113 213 m_boxes.Append( (wxObject*) m_radio );
29006414 214
d3b4d113 215 ConnectWidget( GTK_WIDGET(m_radio) );
29006414 216
d3b4d113 217 if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE );
29006414
VZ
218
219 gtk_signal_connect( GTK_OBJECT(m_radio), "clicked",
354aa1e3 220 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
29006414 221
f6bcfd97
BP
222 gtk_signal_connect( GTK_OBJECT(m_radio), "focus_in_event",
223 GTK_SIGNAL_FUNC(gtk_radiobutton_focus_in), (gpointer)this );
224
225 gtk_signal_connect( GTK_OBJECT(m_radio), "focus_out_event",
226 GTK_SIGNAL_FUNC(gtk_radiobutton_focus_out), (gpointer)this );
227
da048e3d 228 gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow),
e3e717ec 229 GTK_WIDGET(m_radio),
f03fc89f 230 m_x+10, m_y+10+(i*24), 10, 10 );
6de97a3b 231 }
29006414 232
db434467
RR
233 m_parent->DoAddChild( this );
234
235 PostCreation();
7e2b55cd
RR
236
237 ApplyWidgetStyle();
db434467 238
db434467
RR
239 SetLabel( title );
240
241 SetFont( parent->GetFont() );
242
d3b4d113 243 wxSize ls = LayoutItems();
29006414 244
a56fcaaf
RR
245 GtkRequisition req;
246 req.width = 2;
247 req.height = 2;
2afa14f2 248 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) (m_widget, &req );
a56fcaaf
RR
249 if (req.width > ls.x) ls.x = req.width;
250
907789a0 251 wxSize newSize = size;
d3b4d113
RR
252 if (newSize.x == -1) newSize.x = ls.x;
253 if (newSize.y == -1) newSize.y = ls.y;
907789a0 254 SetSize( newSize.x, newSize.y );
29006414 255
907789a0
RR
256 SetBackgroundColour( parent->GetBackgroundColour() );
257 SetForegroundColour( parent->GetForegroundColour() );
f96aa4d9 258
907789a0 259 Show( TRUE );
29006414 260
907789a0 261 return TRUE;
6de97a3b 262}
c801d85f 263
f03fc89f 264wxRadioBox::~wxRadioBox()
d6d1892b 265{
907789a0
RR
266 wxNode *node = m_boxes.First();
267 while (node)
268 {
269 GtkWidget *button = GTK_WIDGET( node->Data() );
270 gtk_widget_destroy( button );
271 node = node->Next();
272 }
d6d1892b
RR
273}
274
54517652 275void wxRadioBox::DoSetSize( int x, int y, int width, int height, int sizeFlags )
3f659fd6 276{
54517652
RR
277 wxWindow::DoSetSize( x, y, width, height, sizeFlags );
278
d3b4d113
RR
279 LayoutItems();
280}
281
282wxSize wxRadioBox::LayoutItems()
283{
bbe0af5b
RR
284 int x = 7;
285 int y = 15;
29006414 286
e3e717ec
VZ
287 if ( m_majorDim == 0 )
288 {
289 // avoid dividing by 0 below
223d09f6 290 wxFAIL_MSG( wxT("dimension of radiobox should not be 0!") );
e3e717ec
VZ
291
292 m_majorDim = 1;
293 }
294
d3b4d113 295 int num_per_major = (m_boxes.GetCount() - 1) / m_majorDim +1;
29006414 296
d3b4d113 297 wxSize res( 0, 0 );
29006414 298
e9158f7d
RR
299 int num_of_cols = 0;
300 int num_of_rows = 0;
301 if (HasFlag(wxRA_SPECIFY_COLS))
d3b4d113 302 {
e9158f7d
RR
303 num_of_cols = m_majorDim;
304 num_of_rows = num_per_major;
305 }
306 else
307 {
308 num_of_cols = num_per_major;
309 num_of_rows = m_majorDim;
310 }
311
312 if ( HasFlag(wxRA_SPECIFY_COLS) ||
313 (HasFlag(wxRA_SPECIFY_ROWS) && (num_of_cols > 1)) )
314 {
315 for (int j = 0; j < num_of_cols; j++)
29006414 316 {
bbe0af5b 317 y = 15;
29006414 318
d3b4d113 319 int max_len = 0;
e9158f7d
RR
320 wxNode *node = m_boxes.Nth( j*num_of_rows );
321 for (int i1 = 0; i1< num_of_rows; i1++)
29006414 322 {
d3b4d113 323 GtkWidget *button = GTK_WIDGET( node->Data() );
165b6ee0
VS
324
325 GtkRequisition req;
326 req.width = 2;
327 req.height = 2;
2afa14f2 328 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
165b6ee0
VS
329 (button, &req );
330
331 if (req.width > max_len) max_len = req.width;
29006414 332
da048e3d 333 gtk_pizza_move( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y );
165b6ee0 334 y += req.height;
29006414
VZ
335
336 node = node->Next();
337 if (!node) break;
338 }
339
340 // we don't know the max_len before
341
e9158f7d
RR
342 node = m_boxes.Nth( j*num_of_rows );
343 for (int i2 = 0; i2< num_of_rows; i2++)
29006414 344 {
d3b4d113 345 GtkWidget *button = GTK_WIDGET( node->Data() );
29006414 346
da048e3d 347 gtk_pizza_resize( GTK_PIZZA(m_parent->m_wxwindow), button, max_len, 20 );
29006414
VZ
348
349 node = node->Next();
350 if (!node) break;
351 }
352
353 if (y > res.y) res.y = y;
354
355 x += max_len + 2;
d3b4d113 356 }
29006414
VZ
357
358 res.x = x+4;
165b6ee0 359 res.y += 4;
e5403d7c 360 }
d3b4d113 361 else
e5403d7c 362 {
d3b4d113
RR
363 int max = 0;
364
365 wxNode *node = m_boxes.First();
366 while (node)
367 {
165b6ee0
VS
368 GtkWidget *button = GTK_WIDGET( node->Data() );
369
370 GtkRequisition req;
371 req.width = 2;
372 req.height = 2;
2afa14f2 373 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
165b6ee0 374 (button, &req );
29006414 375
165b6ee0 376 if (req.width > max) max = req.width;
29006414 377
d3b4d113
RR
378 node = node->Next();
379 }
29006414 380
d3b4d113
RR
381 node = m_boxes.First();
382 while (node)
383 {
384 GtkWidget *button = GTK_WIDGET( node->Data() );
29006414 385
da048e3d 386 gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y, max, 20 );
d3b4d113 387 x += max;
29006414 388
d3b4d113
RR
389 node = node->Next();
390 }
29006414 391 res.x = x+4;
3417c2cd 392 res.y = 40;
e5403d7c 393 }
29006414 394
d3b4d113 395 return res;
3f659fd6
RR
396}
397
debe6624 398bool wxRadioBox::Show( bool show )
c801d85f 399{
223d09f6 400 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") );
29006414 401
f96ac56a
RR
402 if (!wxControl::Show(show))
403 {
404 // nothing to do
405 return FALSE;
406 }
c801d85f 407
ba2a0103 408 if ((m_windowStyle & wxNO_BORDER) != 0)
b0351fc9 409 gtk_widget_hide( m_widget );
e3e717ec 410
907789a0
RR
411 wxNode *node = m_boxes.First();
412 while (node)
413 {
414 GtkWidget *button = GTK_WIDGET( node->Data() );
29006414 415
907789a0 416 if (show) gtk_widget_show( button ); else gtk_widget_hide( button );
29006414 417
907789a0
RR
418 node = node->Next();
419 }
c801d85f 420
907789a0 421 return TRUE;
6de97a3b 422}
c801d85f 423
47908e25 424int wxRadioBox::FindString( const wxString &s ) const
c801d85f 425{
223d09f6 426 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") );
29006414 427
907789a0 428 int count = 0;
29006414 429
907789a0
RR
430 wxNode *node = m_boxes.First();
431 while (node)
432 {
433 GtkButton *button = GTK_BUTTON( node->Data() );
29006414 434
907789a0
RR
435 GtkLabel *label = GTK_LABEL( button->child );
436 if (s == label->label) return count;
437 count++;
29006414 438
907789a0
RR
439 node = node->Next();
440 }
29006414 441
907789a0 442 return -1;
6de97a3b 443}
c801d85f 444
b292e2f5
RR
445void wxRadioBox::SetFocus()
446{
223d09f6 447 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 448
b292e2f5 449 if (m_boxes.GetCount() == 0) return;
29006414 450
b292e2f5
RR
451 wxNode *node = m_boxes.First();
452 while (node)
453 {
454 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
455 if (button->active)
29006414 456 {
b292e2f5 457 gtk_widget_grab_focus( GTK_WIDGET(button) );
29006414
VZ
458 return;
459 }
b292e2f5
RR
460 node = node->Next();
461 }
29006414 462
b292e2f5
RR
463}
464
47908e25 465void wxRadioBox::SetSelection( int n )
c801d85f 466{
223d09f6 467 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 468
907789a0 469 wxNode *node = m_boxes.Nth( n );
29006414 470
223d09f6 471 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 472
907789a0 473 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
29006414 474
72a7edf0 475 GtkDisableEvents();
953704c1 476
907789a0 477 gtk_toggle_button_set_state( button, 1 );
953704c1 478
72a7edf0 479 GtkEnableEvents();
6de97a3b 480}
c801d85f
KB
481
482int wxRadioBox::GetSelection(void) const
483{
223d09f6 484 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") );
29006414 485
907789a0 486 int count = 0;
29006414 487
907789a0
RR
488 wxNode *node = m_boxes.First();
489 while (node)
490 {
491 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
492 if (button->active) return count;
493 count++;
494 node = node->Next();
495 }
29006414 496
223d09f6 497 wxFAIL_MSG( wxT("wxRadioBox none selected") );
29006414 498
907789a0 499 return -1;
6de97a3b 500}
c801d85f 501
47908e25 502wxString wxRadioBox::GetString( int n ) const
c801d85f 503{
223d09f6 504 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") );
29006414 505
907789a0 506 wxNode *node = m_boxes.Nth( n );
29006414 507
223d09f6 508 wxCHECK_MSG( node, wxT(""), wxT("radiobox wrong index") );
29006414 509
907789a0
RR
510 GtkButton *button = GTK_BUTTON( node->Data() );
511 GtkLabel *label = GTK_LABEL( button->child );
29006414 512
907789a0 513 return wxString( label->label );
6de97a3b 514}
c801d85f 515
d3904ceb 516wxString wxRadioBox::GetLabel( int item ) const
c801d85f 517{
223d09f6 518 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") );
29006414 519
907789a0 520 return GetString( item );
6de97a3b 521}
c801d85f 522
d3904ceb 523void wxRadioBox::SetLabel( const wxString& label )
c801d85f 524{
223d09f6 525 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 526
907789a0 527 wxControl::SetLabel( label );
29006414 528
b019151f 529 gtk_frame_set_label( GTK_FRAME(m_widget), wxControl::GetLabel().mbc_str() );
6de97a3b 530}
c801d85f 531
d3904ceb 532void wxRadioBox::SetLabel( int item, const wxString& label )
c801d85f 533{
223d09f6 534 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 535
907789a0 536 wxNode *node = m_boxes.Nth( item );
29006414 537
223d09f6 538 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 539
907789a0
RR
540 GtkButton *button = GTK_BUTTON( node->Data() );
541 GtkLabel *g_label = GTK_LABEL( button->child );
29006414 542
b019151f 543 gtk_label_set( g_label, label.mbc_str() );
6de97a3b 544}
c801d85f 545
debe6624 546void wxRadioBox::SetLabel( int WXUNUSED(item), wxBitmap *WXUNUSED(bitmap) )
c801d85f 547{
223d09f6 548 wxFAIL_MSG(wxT("wxRadioBox::SetLabel not implemented."));
6de97a3b 549}
c801d85f 550
f03fc89f 551bool wxRadioBox::Enable( bool enable )
c801d85f 552{
f03fc89f
VZ
553 if ( !wxControl::Enable( enable ) )
554 return FALSE;
29006414 555
907789a0
RR
556 wxNode *node = m_boxes.First();
557 while (node)
558 {
559 GtkButton *button = GTK_BUTTON( node->Data() );
560 GtkWidget *label = button->child;
561 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
562 gtk_widget_set_sensitive( label, enable );
563 node = node->Next();
564 }
f03fc89f
VZ
565
566 return TRUE;
6de97a3b 567}
c801d85f 568
d3904ceb 569void wxRadioBox::Enable( int item, bool enable )
c801d85f 570{
223d09f6 571 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 572
907789a0 573 wxNode *node = m_boxes.Nth( item );
29006414 574
223d09f6 575 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 576
907789a0
RR
577 GtkButton *button = GTK_BUTTON( node->Data() );
578 GtkWidget *label = button->child;
579 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
580 gtk_widget_set_sensitive( label, enable );
6de97a3b 581}
c801d85f 582
d3904ceb 583void wxRadioBox::Show( int item, bool show )
c801d85f 584{
223d09f6 585 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 586
907789a0 587 wxNode *node = m_boxes.Nth( item );
29006414 588
223d09f6 589 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 590
907789a0 591 GtkWidget *button = GTK_WIDGET( node->Data() );
c801d85f 592
907789a0
RR
593 if (show)
594 gtk_widget_show( button );
595 else
596 gtk_widget_hide( button );
6de97a3b 597}
c801d85f 598
9c884972 599wxString wxRadioBox::GetStringSelection() const
c801d85f 600{
223d09f6 601 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") );
29006414 602
907789a0
RR
603 wxNode *node = m_boxes.First();
604 while (node)
c801d85f 605 {
907789a0
RR
606 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
607 if (button->active)
608 {
609 GtkLabel *label = GTK_LABEL( GTK_BUTTON(button)->child );
610 return label->label;
611 }
612 node = node->Next();
6de97a3b 613 }
29006414 614
223d09f6
KB
615 wxFAIL_MSG( wxT("wxRadioBox none selected") );
616 return wxT("");
6de97a3b 617}
c801d85f 618
907789a0 619bool wxRadioBox::SetStringSelection( const wxString &s )
c801d85f 620{
223d09f6 621 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") );
29006414 622
907789a0
RR
623 int res = FindString( s );
624 if (res == -1) return FALSE;
625 SetSelection( res );
29006414 626
907789a0 627 return TRUE;
6de97a3b 628}
c801d85f 629
9c884972 630int wxRadioBox::Number() const
c801d85f 631{
907789a0 632 return m_boxes.Number();
6de97a3b 633}
c801d85f 634
9c884972 635int wxRadioBox::GetNumberOfRowsOrCols() const
c801d85f 636{
907789a0 637 return 1;
6de97a3b 638}
c801d85f 639
debe6624 640void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) )
c801d85f 641{
223d09f6 642 wxFAIL_MSG(wxT("wxRadioBox::SetNumberOfRowsOrCols not implemented."));
6de97a3b 643}
c801d85f 644
72a7edf0 645void wxRadioBox::GtkDisableEvents()
953704c1
RR
646{
647 wxNode *node = m_boxes.First();
648 while (node)
649 {
650 gtk_signal_disconnect_by_func( GTK_OBJECT(node->Data()),
651 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
652
653 node = node->Next();
654 }
655}
656
72a7edf0 657void wxRadioBox::GtkEnableEvents()
953704c1
RR
658{
659 wxNode *node = m_boxes.First();
660 while (node)
661 {
662 gtk_signal_connect( GTK_OBJECT(node->Data()), "clicked",
663 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
664
665 node = node->Next();
666 }
667}
668
58614078 669void wxRadioBox::ApplyWidgetStyle()
868a2826 670{
907789a0 671 SetWidgetStyle();
29006414 672
907789a0 673 gtk_widget_set_style( m_widget, m_widgetStyle );
29006414 674
907789a0
RR
675 wxNode *node = m_boxes.First();
676 while (node)
677 {
678 GtkWidget *widget = GTK_WIDGET( node->Data() );
679 gtk_widget_set_style( widget, m_widgetStyle );
29006414 680
907789a0
RR
681 GtkButton *button = GTK_BUTTON( node->Data() );
682 gtk_widget_set_style( button->child, m_widgetStyle );
29006414 683
907789a0
RR
684 node = node->Next();
685 }
868a2826 686}
b4071e91 687
72a7edf0
RR
688#if wxUSE_TOOLTIPS
689void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
690{
691 wxNode *node = m_boxes.First();
692 while (node)
693 {
694 GtkWidget *widget = GTK_WIDGET( node->Data() );
695 gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL );
696 node = node->Next();
697 }
698}
699#endif // wxUSE_TOOLTIPS
700
b4071e91
RR
701bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window )
702{
907789a0 703 if (window == m_widget->window) return TRUE;
29006414 704
907789a0
RR
705 wxNode *node = m_boxes.First();
706 while (node)
707 {
708 GtkWidget *button = GTK_WIDGET( node->Data() );
29006414 709
907789a0 710 if (window == button->window) return TRUE;
29006414 711
907789a0
RR
712 node = node->Next();
713 }
29006414 714
907789a0 715 return FALSE;
b4071e91 716}
dcf924a3 717
f6bcfd97
BP
718void wxRadioBox::OnInternalIdle()
719{
720 if ( m_lostFocus )
721 {
722 m_hasFocus = FALSE;
723 m_lostFocus = FALSE;
724
725 wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() );
726 event.SetEventObject( this );
727
728 (void)GetEventHandler()->ProcessEvent( event );
729 }
730}
731
732#endif // wxUSE_RADIOBOX
733