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