]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/radiobox.cpp
Fixed update rectangle passed to WinInvalidateRect in wxWindowOS2::Refresh().
[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();
2da61056 234
7e2b55cd 235 ApplyWidgetStyle();
db434467 236
db434467
RR
237 SetLabel( title );
238
239 SetFont( parent->GetFont() );
240
d3b4d113 241 wxSize ls = LayoutItems();
29006414 242
a56fcaaf
RR
243 GtkRequisition req;
244 req.width = 2;
245 req.height = 2;
2afa14f2 246 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) (m_widget, &req );
a56fcaaf 247 if (req.width > ls.x) ls.x = req.width;
2da61056 248
907789a0 249 wxSize newSize = size;
d3b4d113
RR
250 if (newSize.x == -1) newSize.x = ls.x;
251 if (newSize.y == -1) newSize.y = ls.y;
907789a0 252 SetSize( newSize.x, newSize.y );
29006414 253
907789a0
RR
254 SetBackgroundColour( parent->GetBackgroundColour() );
255 SetForegroundColour( parent->GetForegroundColour() );
f96aa4d9 256
907789a0 257 Show( TRUE );
29006414 258
907789a0 259 return TRUE;
6de97a3b 260}
c801d85f 261
f03fc89f 262wxRadioBox::~wxRadioBox()
d6d1892b 263{
222ed1d6 264 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
265 while (node)
266 {
b1d4dd7a 267 GtkWidget *button = GTK_WIDGET( node->GetData() );
907789a0 268 gtk_widget_destroy( button );
b1d4dd7a 269 node = node->GetNext();
907789a0 270 }
d6d1892b
RR
271}
272
54517652 273void wxRadioBox::DoSetSize( int x, int y, int width, int height, int sizeFlags )
3f659fd6 274{
54517652 275 wxWindow::DoSetSize( x, y, width, height, sizeFlags );
2da61056 276
d3b4d113
RR
277 LayoutItems();
278}
279
280wxSize wxRadioBox::LayoutItems()
281{
bbe0af5b
RR
282 int x = 7;
283 int y = 15;
29006414 284
e3e717ec
VZ
285 if ( m_majorDim == 0 )
286 {
287 // avoid dividing by 0 below
223d09f6 288 wxFAIL_MSG( wxT("dimension of radiobox should not be 0!") );
e3e717ec
VZ
289
290 m_majorDim = 1;
291 }
292
d3b4d113 293 int num_per_major = (m_boxes.GetCount() - 1) / m_majorDim +1;
29006414 294
d3b4d113 295 wxSize res( 0, 0 );
29006414 296
e9158f7d
RR
297 int num_of_cols = 0;
298 int num_of_rows = 0;
299 if (HasFlag(wxRA_SPECIFY_COLS))
d3b4d113 300 {
e9158f7d
RR
301 num_of_cols = m_majorDim;
302 num_of_rows = num_per_major;
303 }
304 else
305 {
306 num_of_cols = num_per_major;
307 num_of_rows = m_majorDim;
308 }
2da61056 309
e9158f7d
RR
310 if ( HasFlag(wxRA_SPECIFY_COLS) ||
311 (HasFlag(wxRA_SPECIFY_ROWS) && (num_of_cols > 1)) )
312 {
313 for (int j = 0; j < num_of_cols; j++)
29006414 314 {
bbe0af5b 315 y = 15;
29006414 316
d3b4d113 317 int max_len = 0;
222ed1d6 318 wxList::compatibility_iterator node = m_boxes.Item( j*num_of_rows );
e9158f7d 319 for (int i1 = 0; i1< num_of_rows; i1++)
29006414 320 {
b1d4dd7a 321 GtkWidget *button = GTK_WIDGET( node->GetData() );
2da61056 322
165b6ee0
VS
323 GtkRequisition req;
324 req.width = 2;
325 req.height = 2;
2afa14f2 326 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
165b6ee0 327 (button, &req );
2da61056 328
165b6ee0 329 if (req.width > max_len) max_len = req.width;
29006414 330
da048e3d 331 gtk_pizza_move( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y );
165b6ee0 332 y += req.height;
29006414 333
b1d4dd7a 334 node = node->GetNext();
29006414
VZ
335 if (!node) break;
336 }
337
338 // we don't know the max_len before
339
b1d4dd7a 340 node = m_boxes.Item( j*num_of_rows );
e9158f7d 341 for (int i2 = 0; i2< num_of_rows; i2++)
29006414 342 {
b1d4dd7a 343 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 344
da048e3d 345 gtk_pizza_resize( GTK_PIZZA(m_parent->m_wxwindow), button, max_len, 20 );
29006414 346
b1d4dd7a 347 node = node->GetNext();
29006414
VZ
348 if (!node) break;
349 }
350
351 if (y > res.y) res.y = y;
352
353 x += max_len + 2;
d3b4d113 354 }
29006414
VZ
355
356 res.x = x+4;
165b6ee0 357 res.y += 4;
e5403d7c 358 }
d3b4d113 359 else
e5403d7c 360 {
d3b4d113
RR
361 int max = 0;
362
222ed1d6 363 wxList::compatibility_iterator node = m_boxes.GetFirst();
d3b4d113
RR
364 while (node)
365 {
b1d4dd7a 366 GtkWidget *button = GTK_WIDGET( node->GetData() );
165b6ee0
VS
367
368 GtkRequisition req;
369 req.width = 2;
370 req.height = 2;
2afa14f2 371 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
165b6ee0 372 (button, &req );
29006414 373
165b6ee0 374 if (req.width > max) max = req.width;
29006414 375
b1d4dd7a 376 node = node->GetNext();
d3b4d113 377 }
29006414 378
b1d4dd7a 379 node = m_boxes.GetFirst();
d3b4d113
RR
380 while (node)
381 {
b1d4dd7a 382 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 383
da048e3d 384 gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y, max, 20 );
d3b4d113 385 x += max;
29006414 386
b1d4dd7a 387 node = node->GetNext();
d3b4d113 388 }
29006414 389 res.x = x+4;
3417c2cd 390 res.y = 40;
e5403d7c 391 }
29006414 392
d3b4d113 393 return res;
3f659fd6
RR
394}
395
debe6624 396bool wxRadioBox::Show( bool show )
c801d85f 397{
223d09f6 398 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") );
29006414 399
f96ac56a
RR
400 if (!wxControl::Show(show))
401 {
402 // nothing to do
403 return FALSE;
404 }
c801d85f 405
ba2a0103 406 if ((m_windowStyle & wxNO_BORDER) != 0)
b0351fc9 407 gtk_widget_hide( m_widget );
e3e717ec 408
222ed1d6 409 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
410 while (node)
411 {
b1d4dd7a 412 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 413
907789a0 414 if (show) gtk_widget_show( button ); else gtk_widget_hide( button );
29006414 415
b1d4dd7a 416 node = node->GetNext();
907789a0 417 }
c801d85f 418
907789a0 419 return TRUE;
6de97a3b 420}
c801d85f 421
2b5f62a0 422int wxRadioBox::FindString( const wxString &find ) const
c801d85f 423{
223d09f6 424 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") );
29006414 425
907789a0 426 int count = 0;
29006414 427
222ed1d6 428 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
429 while (node)
430 {
b1d4dd7a 431 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
2b5f62a0
VZ
432#ifdef __WXGTK20__
433 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
434#else
435 wxString str( label->label );
436#endif
437 if (find == str)
9e691f46 438 return count;
29006414 439
907789a0 440 count++;
29006414 441
b1d4dd7a 442 node = node->GetNext();
907789a0 443 }
29006414 444
907789a0 445 return -1;
6de97a3b 446}
c801d85f 447
b292e2f5
RR
448void wxRadioBox::SetFocus()
449{
223d09f6 450 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 451
b292e2f5 452 if (m_boxes.GetCount() == 0) return;
29006414 453
222ed1d6 454 wxList::compatibility_iterator node = m_boxes.GetFirst();
b292e2f5
RR
455 while (node)
456 {
b1d4dd7a 457 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
b292e2f5 458 if (button->active)
29006414 459 {
b292e2f5 460 gtk_widget_grab_focus( GTK_WIDGET(button) );
29006414
VZ
461 return;
462 }
b1d4dd7a 463 node = node->GetNext();
b292e2f5 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
222ed1d6 471 wxList::compatibility_iterator node = m_boxes.Item( n );
29006414 472
223d09f6 473 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 474
b1d4dd7a 475 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
29006414 476
72a7edf0 477 GtkDisableEvents();
2da61056 478
e2762ff0 479 gtk_toggle_button_set_active( button, 1 );
2da61056 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
222ed1d6 490 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
491 while (node)
492 {
b1d4dd7a 493 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
907789a0
RR
494 if (button->active) return count;
495 count++;
b1d4dd7a 496 node = node->GetNext();
907789a0 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
222ed1d6 508 wxList::compatibility_iterator node = m_boxes.Item( n );
29006414 509
223d09f6 510 wxCHECK_MSG( node, wxT(""), wxT("radiobox wrong index") );
29006414 511
b1d4dd7a 512 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
29006414 513
2b5f62a0
VZ
514#ifdef __WXGTK20__
515 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
516#else
517 wxString str( label->label );
518#endif
519
520 return str;
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
fab591c5 529 gtk_frame_set_label( GTK_FRAME(m_widget), wxGTK_CONV( wxControl::GetLabel() ) );
6de97a3b 530}
c801d85f 531
2da61056 532void wxRadioBox::SetString( int item, const wxString& label )
c801d85f 533{
223d09f6 534 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 535
222ed1d6 536 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 537
223d09f6 538 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 539
b1d4dd7a 540 GtkLabel *g_label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
29006414 541
fab591c5 542 gtk_label_set( g_label, wxGTK_CONV( label ) );
6de97a3b 543}
c801d85f 544
f03fc89f 545bool wxRadioBox::Enable( bool enable )
c801d85f 546{
f03fc89f
VZ
547 if ( !wxControl::Enable( enable ) )
548 return FALSE;
29006414 549
222ed1d6 550 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
551 while (node)
552 {
b1d4dd7a 553 GtkButton *button = GTK_BUTTON( node->GetData() );
9e691f46
VZ
554 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) );
555
907789a0 556 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 557 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
b1d4dd7a 558 node = node->GetNext();
907789a0 559 }
f03fc89f
VZ
560
561 return TRUE;
6de97a3b 562}
c801d85f 563
d3904ceb 564void wxRadioBox::Enable( int item, bool enable )
c801d85f 565{
223d09f6 566 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 567
222ed1d6 568 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 569
223d09f6 570 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 571
b1d4dd7a 572 GtkButton *button = GTK_BUTTON( node->GetData() );
9e691f46
VZ
573 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) );
574
907789a0 575 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 576 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
6de97a3b 577}
c801d85f 578
d3904ceb 579void wxRadioBox::Show( int item, bool show )
c801d85f 580{
223d09f6 581 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 582
222ed1d6 583 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 584
223d09f6 585 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 586
b1d4dd7a 587 GtkWidget *button = GTK_WIDGET( node->GetData() );
c801d85f 588
907789a0
RR
589 if (show)
590 gtk_widget_show( button );
591 else
592 gtk_widget_hide( button );
6de97a3b 593}
c801d85f 594
9c884972 595wxString wxRadioBox::GetStringSelection() const
c801d85f 596{
223d09f6 597 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") );
29006414 598
222ed1d6 599 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0 600 while (node)
c801d85f 601 {
b1d4dd7a 602 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
907789a0
RR
603 if (button->active)
604 {
b1d4dd7a 605 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
9e691f46 606
2b5f62a0
VZ
607#ifdef __WXGTK20__
608 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
609#else
610 wxString str( label->label );
611#endif
612 return str;
907789a0 613 }
b1d4dd7a 614 node = node->GetNext();
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
2da61056 632int wxRadioBox::GetCount() const
c801d85f 633{
b1d4dd7a 634 return m_boxes.GetCount();
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 648{
222ed1d6 649 wxList::compatibility_iterator node = m_boxes.GetFirst();
953704c1
RR
650 while (node)
651 {
b1d4dd7a 652 gtk_signal_disconnect_by_func( GTK_OBJECT(node->GetData()),
953704c1
RR
653 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
654
b1d4dd7a 655 node = node->GetNext();
953704c1
RR
656 }
657}
658
72a7edf0 659void wxRadioBox::GtkEnableEvents()
953704c1 660{
222ed1d6 661 wxList::compatibility_iterator node = m_boxes.GetFirst();
953704c1
RR
662 while (node)
663 {
b1d4dd7a 664 gtk_signal_connect( GTK_OBJECT(node->GetData()), "clicked",
953704c1
RR
665 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
666
b1d4dd7a 667 node = node->GetNext();
953704c1
RR
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
222ed1d6 677 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
678 while (node)
679 {
b1d4dd7a 680 GtkWidget *widget = GTK_WIDGET( node->GetData() );
907789a0 681 gtk_widget_set_style( widget, m_widgetStyle );
29006414 682
b1d4dd7a 683 gtk_widget_set_style( BUTTON_CHILD(node->GetData()), m_widgetStyle );
29006414 684
b1d4dd7a 685 node = node->GetNext();
907789a0 686 }
868a2826 687}
b4071e91 688
72a7edf0
RR
689#if wxUSE_TOOLTIPS
690void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
691{
222ed1d6 692 wxList::compatibility_iterator node = m_boxes.GetFirst();
72a7edf0
RR
693 while (node)
694 {
b1d4dd7a 695 GtkWidget *widget = GTK_WIDGET( node->GetData() );
72a7edf0 696 gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL );
b1d4dd7a 697 node = node->GetNext();
72a7edf0
RR
698 }
699}
700#endif // wxUSE_TOOLTIPS
701
b4071e91
RR
702bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window )
703{
907789a0 704 if (window == m_widget->window) return TRUE;
29006414 705
222ed1d6 706 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
707 while (node)
708 {
b1d4dd7a 709 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 710
907789a0 711 if (window == button->window) return TRUE;
29006414 712
b1d4dd7a 713 node = node->GetNext();
907789a0 714 }
29006414 715
907789a0 716 return FALSE;
b4071e91 717}
dcf924a3 718
f6bcfd97
BP
719void wxRadioBox::OnInternalIdle()
720{
721 if ( m_lostFocus )
722 {
723 m_hasFocus = FALSE;
724 m_lostFocus = FALSE;
725
726 wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() );
727 event.SetEventObject( this );
728
729 (void)GetEventHandler()->ProcessEvent( event );
730 }
d7fa7eaa
RR
731
732 if (g_delayedFocus == this)
733 {
734 if (GTK_WIDGET_REALIZED(m_widget))
735 {
736 g_delayedFocus = NULL;
737 SetFocus();
738 }
739 }
f6bcfd97
BP
740}
741
742#endif // wxUSE_RADIOBOX
743