]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/radiobox.cpp
Fixed a warning....
[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
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 {
126 win->m_hasFocus = TRUE;
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
150 // idle iteration (leave m_hasFocus == TRUE for now)
151 win->m_lostFocus = TRUE;
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{
f6bcfd97
BP
164 m_needParent = TRUE;
165 m_acceptsFocus = TRUE;
166
167 m_hasFocus =
168 m_lostFocus = FALSE;
6de97a3b 169}
c801d85f 170
debe6624 171bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
907789a0 172 const wxPoint &pos, const wxSize &size,
29006414
VZ
173 int n, const wxString choices[], int majorDim,
174 long style, const wxValidator& validator,
175 const wxString &name )
c801d85f 176{
4dcaf11a
RR
177 if (!PreCreation( parent, pos, size ) ||
178 !CreateBase( parent, id, pos, size, style, validator, name ))
179 {
223d09f6 180 wxFAIL_MSG( wxT("wxRadioBox creation failed") );
e2762ff0 181 return FALSE;
4dcaf11a 182 }
6de97a3b 183
fab591c5 184 m_widget = gtk_frame_new( wxGTK_CONV( title ) );
29006414 185
5eaac5b5
VZ
186 // majorDim may be 0 if all trailing parameters were omitted, so don't
187 // assert here but just use the correct value for it
188 m_majorDim = majorDim == 0 ? n : majorDim;
29006414 189
907789a0 190 GtkRadioButton *m_radio = (GtkRadioButton*) NULL;
29006414 191
26333898 192 wxString label;
d3b4d113
RR
193 GSList *radio_button_group = (GSList *) NULL;
194 for (int i = 0; i < n; i++)
c801d85f 195 {
26333898
VZ
196 if ( i != 0 )
197 radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) );
29006414 198
26333898
VZ
199 label.Empty();
200 for ( const wxChar *pc = choices[i]; *pc; pc++ )
201 {
223d09f6 202 if ( *pc != wxT('&') )
26333898
VZ
203 label += *pc;
204 }
205
fab591c5 206 m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) );
29006414 207
2e0e025e
RR
208 gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event",
209 GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this );
2da61056 210
d3b4d113 211 m_boxes.Append( (wxObject*) m_radio );
29006414 212
d3b4d113 213 ConnectWidget( GTK_WIDGET(m_radio) );
29006414 214
d3b4d113 215 if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE );
29006414
VZ
216
217 gtk_signal_connect( GTK_OBJECT(m_radio), "clicked",
354aa1e3 218 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
29006414 219
f6bcfd97
BP
220 gtk_signal_connect( GTK_OBJECT(m_radio), "focus_in_event",
221 GTK_SIGNAL_FUNC(gtk_radiobutton_focus_in), (gpointer)this );
222
223 gtk_signal_connect( GTK_OBJECT(m_radio), "focus_out_event",
224 GTK_SIGNAL_FUNC(gtk_radiobutton_focus_out), (gpointer)this );
225
da048e3d 226 gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow),
e3e717ec 227 GTK_WIDGET(m_radio),
f03fc89f 228 m_x+10, m_y+10+(i*24), 10, 10 );
6de97a3b 229 }
29006414 230
db434467
RR
231 m_parent->DoAddChild( this );
232
233 PostCreation();
e8e24dfa 234 InheritAttributes();
2da61056 235
7e2b55cd 236 ApplyWidgetStyle();
db434467 237
db434467
RR
238 SetLabel( title );
239
240 SetFont( parent->GetFont() );
241
d3b4d113 242 wxSize ls = LayoutItems();
29006414 243
a56fcaaf
RR
244 GtkRequisition req;
245 req.width = 2;
246 req.height = 2;
2afa14f2 247 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) (m_widget, &req );
a56fcaaf 248 if (req.width > ls.x) ls.x = req.width;
2da61056 249
907789a0 250 wxSize newSize = size;
d3b4d113
RR
251 if (newSize.x == -1) newSize.x = ls.x;
252 if (newSize.y == -1) newSize.y = ls.y;
907789a0 253 SetSize( newSize.x, newSize.y );
29006414 254
907789a0 255 Show( TRUE );
29006414 256
907789a0 257 return TRUE;
6de97a3b 258}
c801d85f 259
f03fc89f 260wxRadioBox::~wxRadioBox()
d6d1892b 261{
222ed1d6 262 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
263 while (node)
264 {
b1d4dd7a 265 GtkWidget *button = GTK_WIDGET( node->GetData() );
907789a0 266 gtk_widget_destroy( button );
b1d4dd7a 267 node = node->GetNext();
907789a0 268 }
d6d1892b
RR
269}
270
54517652 271void wxRadioBox::DoSetSize( int x, int y, int width, int height, int sizeFlags )
3f659fd6 272{
54517652 273 wxWindow::DoSetSize( x, y, width, height, sizeFlags );
2da61056 274
d3b4d113
RR
275 LayoutItems();
276}
277
278wxSize wxRadioBox::LayoutItems()
279{
bbe0af5b
RR
280 int x = 7;
281 int y = 15;
29006414 282
e3e717ec
VZ
283 if ( m_majorDim == 0 )
284 {
285 // avoid dividing by 0 below
223d09f6 286 wxFAIL_MSG( wxT("dimension of radiobox should not be 0!") );
e3e717ec
VZ
287
288 m_majorDim = 1;
289 }
290
d3b4d113 291 int num_per_major = (m_boxes.GetCount() - 1) / m_majorDim +1;
29006414 292
d3b4d113 293 wxSize res( 0, 0 );
29006414 294
e9158f7d
RR
295 int num_of_cols = 0;
296 int num_of_rows = 0;
297 if (HasFlag(wxRA_SPECIFY_COLS))
d3b4d113 298 {
e9158f7d
RR
299 num_of_cols = m_majorDim;
300 num_of_rows = num_per_major;
301 }
302 else
303 {
304 num_of_cols = num_per_major;
305 num_of_rows = m_majorDim;
306 }
2da61056 307
e9158f7d
RR
308 if ( HasFlag(wxRA_SPECIFY_COLS) ||
309 (HasFlag(wxRA_SPECIFY_ROWS) && (num_of_cols > 1)) )
310 {
311 for (int j = 0; j < num_of_cols; j++)
29006414 312 {
bbe0af5b 313 y = 15;
29006414 314
d3b4d113 315 int max_len = 0;
222ed1d6 316 wxList::compatibility_iterator node = m_boxes.Item( j*num_of_rows );
e9158f7d 317 for (int i1 = 0; i1< num_of_rows; i1++)
29006414 318 {
b1d4dd7a 319 GtkWidget *button = GTK_WIDGET( node->GetData() );
2da61056 320
165b6ee0
VS
321 GtkRequisition req;
322 req.width = 2;
323 req.height = 2;
2afa14f2 324 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
165b6ee0 325 (button, &req );
2da61056 326
165b6ee0 327 if (req.width > max_len) max_len = req.width;
29006414 328
da048e3d 329 gtk_pizza_move( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y );
165b6ee0 330 y += req.height;
29006414 331
b1d4dd7a 332 node = node->GetNext();
29006414
VZ
333 if (!node) break;
334 }
335
336 // we don't know the max_len before
337
b1d4dd7a 338 node = m_boxes.Item( j*num_of_rows );
e9158f7d 339 for (int i2 = 0; i2< num_of_rows; i2++)
29006414 340 {
b1d4dd7a 341 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 342
da048e3d 343 gtk_pizza_resize( GTK_PIZZA(m_parent->m_wxwindow), button, max_len, 20 );
29006414 344
b1d4dd7a 345 node = node->GetNext();
29006414
VZ
346 if (!node) break;
347 }
348
349 if (y > res.y) res.y = y;
350
351 x += max_len + 2;
d3b4d113 352 }
29006414
VZ
353
354 res.x = x+4;
165b6ee0 355 res.y += 4;
e5403d7c 356 }
d3b4d113 357 else
e5403d7c 358 {
d3b4d113
RR
359 int max = 0;
360
222ed1d6 361 wxList::compatibility_iterator node = m_boxes.GetFirst();
d3b4d113
RR
362 while (node)
363 {
b1d4dd7a 364 GtkWidget *button = GTK_WIDGET( node->GetData() );
165b6ee0
VS
365
366 GtkRequisition req;
367 req.width = 2;
368 req.height = 2;
2afa14f2 369 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
165b6ee0 370 (button, &req );
29006414 371
165b6ee0 372 if (req.width > max) max = req.width;
29006414 373
b1d4dd7a 374 node = node->GetNext();
d3b4d113 375 }
29006414 376
b1d4dd7a 377 node = m_boxes.GetFirst();
d3b4d113
RR
378 while (node)
379 {
b1d4dd7a 380 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 381
da048e3d 382 gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y, max, 20 );
d3b4d113 383 x += max;
29006414 384
b1d4dd7a 385 node = node->GetNext();
d3b4d113 386 }
29006414 387 res.x = x+4;
3417c2cd 388 res.y = 40;
e5403d7c 389 }
29006414 390
d3b4d113 391 return res;
3f659fd6
RR
392}
393
debe6624 394bool wxRadioBox::Show( bool show )
c801d85f 395{
223d09f6 396 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") );
29006414 397
f96ac56a
RR
398 if (!wxControl::Show(show))
399 {
400 // nothing to do
401 return FALSE;
402 }
c801d85f 403
ba2a0103 404 if ((m_windowStyle & wxNO_BORDER) != 0)
b0351fc9 405 gtk_widget_hide( m_widget );
e3e717ec 406
222ed1d6 407 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
408 while (node)
409 {
b1d4dd7a 410 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 411
907789a0 412 if (show) gtk_widget_show( button ); else gtk_widget_hide( button );
29006414 413
b1d4dd7a 414 node = node->GetNext();
907789a0 415 }
c801d85f 416
907789a0 417 return TRUE;
6de97a3b 418}
c801d85f 419
2b5f62a0 420int wxRadioBox::FindString( const wxString &find ) const
c801d85f 421{
223d09f6 422 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") );
29006414 423
907789a0 424 int count = 0;
29006414 425
222ed1d6 426 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
427 while (node)
428 {
b1d4dd7a 429 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
2b5f62a0
VZ
430#ifdef __WXGTK20__
431 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
432#else
433 wxString str( label->label );
434#endif
435 if (find == str)
9e691f46 436 return count;
29006414 437
907789a0 438 count++;
29006414 439
b1d4dd7a 440 node = node->GetNext();
907789a0 441 }
29006414 442
907789a0 443 return -1;
6de97a3b 444}
c801d85f 445
b292e2f5
RR
446void wxRadioBox::SetFocus()
447{
223d09f6 448 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 449
b292e2f5 450 if (m_boxes.GetCount() == 0) return;
29006414 451
222ed1d6 452 wxList::compatibility_iterator node = m_boxes.GetFirst();
b292e2f5
RR
453 while (node)
454 {
b1d4dd7a 455 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
b292e2f5 456 if (button->active)
29006414 457 {
b292e2f5 458 gtk_widget_grab_focus( GTK_WIDGET(button) );
29006414
VZ
459 return;
460 }
b1d4dd7a 461 node = node->GetNext();
b292e2f5 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
222ed1d6 469 wxList::compatibility_iterator node = m_boxes.Item( n );
29006414 470
223d09f6 471 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 472
b1d4dd7a 473 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
29006414 474
72a7edf0 475 GtkDisableEvents();
2da61056 476
e2762ff0 477 gtk_toggle_button_set_active( button, 1 );
2da61056 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
222ed1d6 488 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
489 while (node)
490 {
b1d4dd7a 491 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
907789a0
RR
492 if (button->active) return count;
493 count++;
b1d4dd7a 494 node = node->GetNext();
907789a0 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
222ed1d6 506 wxList::compatibility_iterator node = m_boxes.Item( n );
29006414 507
223d09f6 508 wxCHECK_MSG( node, wxT(""), wxT("radiobox wrong index") );
29006414 509
b1d4dd7a 510 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
29006414 511
2b5f62a0
VZ
512#ifdef __WXGTK20__
513 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
514#else
515 wxString str( label->label );
516#endif
517
518 return str;
6de97a3b 519}
c801d85f 520
d3904ceb 521void wxRadioBox::SetLabel( const wxString& label )
c801d85f 522{
223d09f6 523 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 524
907789a0 525 wxControl::SetLabel( label );
29006414 526
fab591c5 527 gtk_frame_set_label( GTK_FRAME(m_widget), wxGTK_CONV( wxControl::GetLabel() ) );
6de97a3b 528}
c801d85f 529
2da61056 530void wxRadioBox::SetString( int item, const wxString& label )
c801d85f 531{
223d09f6 532 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 533
222ed1d6 534 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 535
223d09f6 536 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 537
b1d4dd7a 538 GtkLabel *g_label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
29006414 539
fab591c5 540 gtk_label_set( g_label, wxGTK_CONV( label ) );
6de97a3b 541}
c801d85f 542
f03fc89f 543bool wxRadioBox::Enable( bool enable )
c801d85f 544{
f03fc89f
VZ
545 if ( !wxControl::Enable( enable ) )
546 return FALSE;
29006414 547
222ed1d6 548 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
549 while (node)
550 {
b1d4dd7a 551 GtkButton *button = GTK_BUTTON( node->GetData() );
9e691f46
VZ
552 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) );
553
907789a0 554 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 555 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
b1d4dd7a 556 node = node->GetNext();
907789a0 557 }
f03fc89f
VZ
558
559 return TRUE;
6de97a3b 560}
c801d85f 561
d3904ceb 562void wxRadioBox::Enable( int item, bool enable )
c801d85f 563{
223d09f6 564 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 565
222ed1d6 566 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 567
223d09f6 568 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 569
b1d4dd7a 570 GtkButton *button = GTK_BUTTON( node->GetData() );
9e691f46
VZ
571 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) );
572
907789a0 573 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 574 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
6de97a3b 575}
c801d85f 576
d3904ceb 577void wxRadioBox::Show( int item, bool show )
c801d85f 578{
223d09f6 579 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 580
222ed1d6 581 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 582
223d09f6 583 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 584
b1d4dd7a 585 GtkWidget *button = GTK_WIDGET( node->GetData() );
c801d85f 586
907789a0
RR
587 if (show)
588 gtk_widget_show( button );
589 else
590 gtk_widget_hide( button );
6de97a3b 591}
c801d85f 592
9c884972 593wxString wxRadioBox::GetStringSelection() const
c801d85f 594{
223d09f6 595 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") );
29006414 596
222ed1d6 597 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0 598 while (node)
c801d85f 599 {
b1d4dd7a 600 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
907789a0
RR
601 if (button->active)
602 {
b1d4dd7a 603 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
9e691f46 604
2b5f62a0
VZ
605#ifdef __WXGTK20__
606 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
607#else
608 wxString str( label->label );
609#endif
610 return str;
907789a0 611 }
b1d4dd7a 612 node = node->GetNext();
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
2da61056 630int wxRadioBox::GetCount() const
c801d85f 631{
b1d4dd7a 632 return m_boxes.GetCount();
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 646{
222ed1d6 647 wxList::compatibility_iterator node = m_boxes.GetFirst();
953704c1
RR
648 while (node)
649 {
b1d4dd7a 650 gtk_signal_disconnect_by_func( GTK_OBJECT(node->GetData()),
953704c1
RR
651 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
652
b1d4dd7a 653 node = node->GetNext();
953704c1
RR
654 }
655}
656
72a7edf0 657void wxRadioBox::GtkEnableEvents()
953704c1 658{
222ed1d6 659 wxList::compatibility_iterator node = m_boxes.GetFirst();
953704c1
RR
660 while (node)
661 {
b1d4dd7a 662 gtk_signal_connect( GTK_OBJECT(node->GetData()), "clicked",
953704c1
RR
663 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
664
b1d4dd7a 665 node = node->GetNext();
953704c1
RR
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
222ed1d6 675 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
676 while (node)
677 {
b1d4dd7a 678 GtkWidget *widget = GTK_WIDGET( node->GetData() );
907789a0 679 gtk_widget_set_style( widget, m_widgetStyle );
29006414 680
b1d4dd7a 681 gtk_widget_set_style( BUTTON_CHILD(node->GetData()), m_widgetStyle );
29006414 682
b1d4dd7a 683 node = node->GetNext();
907789a0 684 }
868a2826 685}
b4071e91 686
72a7edf0
RR
687#if wxUSE_TOOLTIPS
688void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
689{
222ed1d6 690 wxList::compatibility_iterator node = m_boxes.GetFirst();
72a7edf0
RR
691 while (node)
692 {
b1d4dd7a 693 GtkWidget *widget = GTK_WIDGET( node->GetData() );
72a7edf0 694 gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL );
b1d4dd7a 695 node = node->GetNext();
72a7edf0
RR
696 }
697}
698#endif // wxUSE_TOOLTIPS
699
b4071e91
RR
700bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window )
701{
907789a0 702 if (window == m_widget->window) return TRUE;
29006414 703
222ed1d6 704 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
705 while (node)
706 {
b1d4dd7a 707 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 708
907789a0 709 if (window == button->window) return TRUE;
29006414 710
b1d4dd7a 711 node = node->GetNext();
907789a0 712 }
29006414 713
907789a0 714 return FALSE;
b4071e91 715}
dcf924a3 716
f6bcfd97
BP
717void wxRadioBox::OnInternalIdle()
718{
719 if ( m_lostFocus )
720 {
721 m_hasFocus = FALSE;
722 m_lostFocus = FALSE;
723
724 wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() );
725 event.SetEventObject( this );
726
727 (void)GetEventHandler()->ProcessEvent( event );
728 }
d7fa7eaa
RR
729
730 if (g_delayedFocus == this)
731 {
732 if (GTK_WIDGET_REALIZED(m_widget))
733 {
734 g_delayedFocus = NULL;
735 SetFocus();
736 }
737 }
f6bcfd97
BP
738}
739
740#endif // wxUSE_RADIOBOX
741