]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/radiobox.cpp
Updates for doc/view from Morgan Hua
[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
65571936 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 {
b4efc9b9 126 win->m_hasFocus = true;
f6bcfd97
BP
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
b4efc9b9
WS
150 // idle iteration (leave m_hasFocus == true for now)
151 win->m_lostFocus = true;
f6bcfd97
BP
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{
b4efc9b9
WS
164 m_needParent = true;
165 m_acceptsFocus = true;
f6bcfd97
BP
166
167 m_hasFocus =
b4efc9b9 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") );
b4efc9b9 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
db434467
RR
250 SetLabel( title );
251
abdeb9e7 252 PostCreation(size);
29006414 253
c4ca49cd
VZ
254 if ( wasShown )
255 Show();
29006414 256
b4efc9b9 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
c4ca49cd 275 LayoutItems(false);
d3b4d113
RR
276}
277
c4ca49cd 278wxSize wxRadioBox::DoGetBestSize() const
d3b4d113 279{
c4ca49cd 280 wxSize size = LayoutItems(true);
29006414 281
c4ca49cd
VZ
282 GtkRequisition req;
283 req.width = 2;
284 req.height = 2;
285 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) (m_widget, &req );
286 if (req.width > size.x)
287 size.x = req.width;
e3e717ec 288
9f884528 289 CacheBestSize(size);
c4ca49cd
VZ
290 return size;
291}
292
293wxSize wxRadioBox::LayoutItems(bool justCalc) const
294{
295 wxSize res( 0, 0 );
296
297 // avoid dividing by 0 below
298 wxCHECK_MSG( m_majorDim, res, wxT("dimension of radiobox should not be 0!") );
e3e717ec 299
d3b4d113 300 int num_per_major = (m_boxes.GetCount() - 1) / m_majorDim +1;
29006414 301
c4ca49cd
VZ
302 int x = 7;
303 int y = 15;
29006414 304
e9158f7d
RR
305 int num_of_cols = 0;
306 int num_of_rows = 0;
307 if (HasFlag(wxRA_SPECIFY_COLS))
d3b4d113 308 {
e9158f7d
RR
309 num_of_cols = m_majorDim;
310 num_of_rows = num_per_major;
311 }
312 else
313 {
314 num_of_cols = num_per_major;
315 num_of_rows = m_majorDim;
316 }
b4efc9b9 317
ff1c71a2 318 int lineheight = GetCharHeight()+2;
b4efc9b9 319
e9158f7d
RR
320 if ( HasFlag(wxRA_SPECIFY_COLS) ||
321 (HasFlag(wxRA_SPECIFY_ROWS) && (num_of_cols > 1)) )
322 {
323 for (int j = 0; j < num_of_cols; j++)
29006414 324 {
b7b7dedc
RR
325 y = 3;
326 y += lineheight;
29006414 327
d3b4d113 328 int max_len = 0;
222ed1d6 329 wxList::compatibility_iterator node = m_boxes.Item( j*num_of_rows );
e9158f7d 330 for (int i1 = 0; i1< num_of_rows; i1++)
29006414 331 {
b1d4dd7a 332 GtkWidget *button = GTK_WIDGET( node->GetData() );
2da61056 333
165b6ee0
VS
334 GtkRequisition req;
335 req.width = 2;
336 req.height = 2;
2afa14f2 337 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
165b6ee0 338 (button, &req );
b4efc9b9 339
165b6ee0 340 if (req.width > max_len) max_len = req.width;
29006414 341
c4ca49cd
VZ
342 if ( !justCalc )
343 gtk_pizza_move( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y );
165b6ee0 344 y += req.height;
29006414 345
b1d4dd7a 346 node = node->GetNext();
29006414
VZ
347 if (!node) break;
348 }
349
350 // we don't know the max_len before
351
b1d4dd7a 352 node = m_boxes.Item( j*num_of_rows );
e9158f7d 353 for (int i2 = 0; i2< num_of_rows; i2++)
29006414 354 {
b1d4dd7a 355 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 356
c4ca49cd
VZ
357 if ( !justCalc )
358 gtk_pizza_resize( GTK_PIZZA(m_parent->m_wxwindow), button, max_len, lineheight );
29006414 359
b1d4dd7a 360 node = node->GetNext();
29006414
VZ
361 if (!node) break;
362 }
363
364 if (y > res.y) res.y = y;
365
366 x += max_len + 2;
d3b4d113 367 }
29006414
VZ
368
369 res.x = x+4;
165b6ee0 370 res.y += 4;
e5403d7c 371 }
d3b4d113 372 else
e5403d7c 373 {
d3b4d113
RR
374 int max = 0;
375
222ed1d6 376 wxList::compatibility_iterator node = m_boxes.GetFirst();
d3b4d113
RR
377 while (node)
378 {
b1d4dd7a 379 GtkWidget *button = GTK_WIDGET( node->GetData() );
165b6ee0
VS
380
381 GtkRequisition req;
382 req.width = 2;
383 req.height = 2;
2afa14f2 384 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request )
165b6ee0 385 (button, &req );
29006414 386
165b6ee0 387 if (req.width > max) max = req.width;
29006414 388
b1d4dd7a 389 node = node->GetNext();
d3b4d113 390 }
29006414 391
b1d4dd7a 392 node = m_boxes.GetFirst();
d3b4d113
RR
393 while (node)
394 {
b1d4dd7a 395 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 396
c4ca49cd
VZ
397 if ( !justCalc )
398 gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y, max, lineheight );
d3b4d113 399 x += max;
29006414 400
b1d4dd7a 401 node = node->GetNext();
d3b4d113 402 }
29006414 403 res.x = x+4;
3417c2cd 404 res.y = 40;
e5403d7c 405 }
29006414 406
d3b4d113 407 return res;
3f659fd6
RR
408}
409
debe6624 410bool wxRadioBox::Show( bool show )
c801d85f 411{
b4efc9b9 412 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 413
f96ac56a
RR
414 if (!wxControl::Show(show))
415 {
416 // nothing to do
b4efc9b9 417 return false;
f96ac56a 418 }
c801d85f 419
c4ca49cd 420 if ( HasFlag(wxNO_BORDER) )
b0351fc9 421 gtk_widget_hide( m_widget );
e3e717ec 422
222ed1d6 423 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
424 while (node)
425 {
b1d4dd7a 426 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 427
907789a0 428 if (show) gtk_widget_show( button ); else gtk_widget_hide( button );
29006414 429
b1d4dd7a 430 node = node->GetNext();
907789a0 431 }
c801d85f 432
b4efc9b9 433 return true;
6de97a3b 434}
c801d85f 435
2b5f62a0 436int wxRadioBox::FindString( const wxString &find ) const
c801d85f 437{
789f6795 438 wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") );
29006414 439
907789a0 440 int count = 0;
29006414 441
222ed1d6 442 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
443 while (node)
444 {
b1d4dd7a 445 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
2b5f62a0
VZ
446#ifdef __WXGTK20__
447 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
448#else
449 wxString str( label->label );
450#endif
451 if (find == str)
9e691f46 452 return count;
29006414 453
907789a0 454 count++;
29006414 455
b1d4dd7a 456 node = node->GetNext();
907789a0 457 }
29006414 458
789f6795 459 return wxNOT_FOUND;
6de97a3b 460}
c801d85f 461
b292e2f5
RR
462void wxRadioBox::SetFocus()
463{
223d09f6 464 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 465
b292e2f5 466 if (m_boxes.GetCount() == 0) return;
29006414 467
222ed1d6 468 wxList::compatibility_iterator node = m_boxes.GetFirst();
b292e2f5
RR
469 while (node)
470 {
b1d4dd7a 471 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
b292e2f5 472 if (button->active)
29006414 473 {
b292e2f5 474 gtk_widget_grab_focus( GTK_WIDGET(button) );
29006414
VZ
475 return;
476 }
b1d4dd7a 477 node = node->GetNext();
b292e2f5 478 }
b292e2f5
RR
479}
480
47908e25 481void wxRadioBox::SetSelection( int n )
c801d85f 482{
223d09f6 483 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 484
222ed1d6 485 wxList::compatibility_iterator node = m_boxes.Item( n );
29006414 486
223d09f6 487 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 488
b1d4dd7a 489 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
29006414 490
72a7edf0 491 GtkDisableEvents();
2da61056 492
e2762ff0 493 gtk_toggle_button_set_active( button, 1 );
2da61056 494
72a7edf0 495 GtkEnableEvents();
6de97a3b 496}
c801d85f
KB
497
498int wxRadioBox::GetSelection(void) const
499{
789f6795 500 wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") );
29006414 501
907789a0 502 int count = 0;
29006414 503
222ed1d6 504 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
505 while (node)
506 {
b1d4dd7a 507 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
907789a0
RR
508 if (button->active) return count;
509 count++;
b1d4dd7a 510 node = node->GetNext();
907789a0 511 }
29006414 512
223d09f6 513 wxFAIL_MSG( wxT("wxRadioBox none selected") );
29006414 514
789f6795 515 return wxNOT_FOUND;
6de97a3b 516}
c801d85f 517
47908e25 518wxString wxRadioBox::GetString( int n ) const
c801d85f 519{
1a87edf2 520 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") );
29006414 521
222ed1d6 522 wxList::compatibility_iterator node = m_boxes.Item( n );
29006414 523
1a87edf2 524 wxCHECK_MSG( node, wxEmptyString, wxT("radiobox wrong index") );
29006414 525
b1d4dd7a 526 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
29006414 527
2b5f62a0
VZ
528#ifdef __WXGTK20__
529 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
530#else
531 wxString str( label->label );
532#endif
533
534 return str;
6de97a3b 535}
c801d85f 536
d3904ceb 537void wxRadioBox::SetLabel( const wxString& label )
c801d85f 538{
223d09f6 539 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 540
907789a0 541 wxControl::SetLabel( label );
29006414 542
fab591c5 543 gtk_frame_set_label( GTK_FRAME(m_widget), wxGTK_CONV( wxControl::GetLabel() ) );
6de97a3b 544}
c801d85f 545
2da61056 546void wxRadioBox::SetString( int item, const wxString& label )
c801d85f 547{
223d09f6 548 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 549
222ed1d6 550 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 551
223d09f6 552 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 553
b1d4dd7a 554 GtkLabel *g_label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
29006414 555
fab591c5 556 gtk_label_set( g_label, wxGTK_CONV( label ) );
6de97a3b 557}
c801d85f 558
f03fc89f 559bool wxRadioBox::Enable( bool enable )
c801d85f 560{
f03fc89f 561 if ( !wxControl::Enable( enable ) )
b4efc9b9 562 return false;
29006414 563
222ed1d6 564 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
565 while (node)
566 {
b1d4dd7a 567 GtkButton *button = GTK_BUTTON( node->GetData() );
9e691f46
VZ
568 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) );
569
907789a0 570 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 571 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
b1d4dd7a 572 node = node->GetNext();
907789a0 573 }
f03fc89f 574
b4efc9b9 575 return true;
6de97a3b 576}
c801d85f 577
1a87edf2 578bool wxRadioBox::Enable( int item, bool enable )
c801d85f 579{
1a87edf2 580 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 581
222ed1d6 582 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 583
1a87edf2 584 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 585
b1d4dd7a 586 GtkButton *button = GTK_BUTTON( node->GetData() );
9e691f46
VZ
587 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) );
588
907789a0 589 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 590 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
1a87edf2
WS
591
592 return true;
6de97a3b 593}
c801d85f 594
789f6795 595bool wxRadioBox::Show( int item, bool show )
c801d85f 596{
789f6795 597 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 598
222ed1d6 599 wxList::compatibility_iterator node = m_boxes.Item( item );
29006414 600
789f6795 601 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 602
b1d4dd7a 603 GtkWidget *button = GTK_WIDGET( node->GetData() );
c801d85f 604
907789a0
RR
605 if (show)
606 gtk_widget_show( button );
607 else
608 gtk_widget_hide( button );
789f6795
WS
609
610 return true;
6de97a3b 611}
c801d85f 612
9c884972 613wxString wxRadioBox::GetStringSelection() const
c801d85f 614{
1a87edf2 615 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") );
29006414 616
222ed1d6 617 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0 618 while (node)
c801d85f 619 {
b1d4dd7a 620 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() );
907789a0
RR
621 if (button->active)
622 {
b1d4dd7a 623 GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) );
9e691f46 624
2b5f62a0
VZ
625#ifdef __WXGTK20__
626 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
627#else
628 wxString str( label->label );
629#endif
630 return str;
907789a0 631 }
b1d4dd7a 632 node = node->GetNext();
6de97a3b 633 }
29006414 634
223d09f6 635 wxFAIL_MSG( wxT("wxRadioBox none selected") );
1a87edf2 636 return wxEmptyString;
6de97a3b 637}
c801d85f 638
907789a0 639bool wxRadioBox::SetStringSelection( const wxString &s )
c801d85f 640{
b4efc9b9 641 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 642
907789a0 643 int res = FindString( s );
789f6795 644 if (res == wxNOT_FOUND) return false;
907789a0 645 SetSelection( res );
29006414 646
b4efc9b9 647 return true;
6de97a3b 648}
c801d85f 649
2da61056 650int wxRadioBox::GetCount() const
c801d85f 651{
b1d4dd7a 652 return m_boxes.GetCount();
6de97a3b 653}
c801d85f 654
72a7edf0 655void wxRadioBox::GtkDisableEvents()
953704c1 656{
222ed1d6 657 wxList::compatibility_iterator node = m_boxes.GetFirst();
953704c1
RR
658 while (node)
659 {
b1d4dd7a 660 gtk_signal_disconnect_by_func( GTK_OBJECT(node->GetData()),
953704c1
RR
661 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
662
b1d4dd7a 663 node = node->GetNext();
953704c1
RR
664 }
665}
666
72a7edf0 667void wxRadioBox::GtkEnableEvents()
953704c1 668{
222ed1d6 669 wxList::compatibility_iterator node = m_boxes.GetFirst();
953704c1
RR
670 while (node)
671 {
b1d4dd7a 672 gtk_signal_connect( GTK_OBJECT(node->GetData()), "clicked",
953704c1
RR
673 GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
674
b1d4dd7a 675 node = node->GetNext();
953704c1
RR
676 }
677}
678
f40fdaa3 679void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 680{
f40fdaa3 681 gtk_widget_modify_style( m_widget, style );
29006414 682
81e88f5b
RR
683#ifdef __WXGTK20__
684 gtk_widget_modify_style(GTK_FRAME(m_widget)->label_widget, style);
685#endif
686
222ed1d6 687 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
688 while (node)
689 {
b1d4dd7a 690 GtkWidget *widget = GTK_WIDGET( node->GetData() );
29006414 691
f40fdaa3
VS
692 gtk_widget_modify_style( widget, style );
693 gtk_widget_modify_style( BUTTON_CHILD(node->GetData()), style );
29006414 694
b1d4dd7a 695 node = node->GetNext();
907789a0 696 }
868a2826 697}
b4071e91 698
72a7edf0
RR
699#if wxUSE_TOOLTIPS
700void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
701{
222ed1d6 702 wxList::compatibility_iterator node = m_boxes.GetFirst();
72a7edf0
RR
703 while (node)
704 {
b1d4dd7a 705 GtkWidget *widget = GTK_WIDGET( node->GetData() );
72a7edf0 706 gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL );
b1d4dd7a 707 node = node->GetNext();
72a7edf0
RR
708 }
709}
710#endif // wxUSE_TOOLTIPS
711
b4071e91
RR
712bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window )
713{
b4efc9b9 714 if (window == m_widget->window) return true;
29006414 715
222ed1d6 716 wxList::compatibility_iterator node = m_boxes.GetFirst();
907789a0
RR
717 while (node)
718 {
b1d4dd7a 719 GtkWidget *button = GTK_WIDGET( node->GetData() );
29006414 720
b4efc9b9 721 if (window == button->window) return true;
29006414 722
b1d4dd7a 723 node = node->GetNext();
907789a0 724 }
29006414 725
b4efc9b9 726 return false;
b4071e91 727}
dcf924a3 728
f6bcfd97
BP
729void wxRadioBox::OnInternalIdle()
730{
731 if ( m_lostFocus )
732 {
b4efc9b9
WS
733 m_hasFocus = false;
734 m_lostFocus = false;
f6bcfd97
BP
735
736 wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() );
737 event.SetEventObject( this );
738
739 (void)GetEventHandler()->ProcessEvent( event );
740 }
d7fa7eaa
RR
741
742 if (g_delayedFocus == this)
743 {
744 if (GTK_WIDGET_REALIZED(m_widget))
745 {
746 g_delayedFocus = NULL;
747 SetFocus();
748 }
749 }
f6bcfd97
BP
750}
751
9d522606
RD
752// static
753wxVisualAttributes
754wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
755{
756 wxVisualAttributes attr;
bc0eb46c
VS
757 // NB: we need toplevel window so that GTK+ can find the right style
758 GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
9d522606 759 GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
bc0eb46c 760 gtk_container_add(GTK_CONTAINER(wnd), widget);
9d522606 761 attr = GetDefaultAttributesFromGTKWidget(widget);
bc0eb46c 762 gtk_widget_destroy(wnd);
9d522606
RD
763 return attr;
764}
765
b4efc9b9
WS
766#if WXWIN_COMPATIBILITY_2_2
767
768int wxRadioBox::Number() const
769{
770 return GetCount();
771}
772
773wxString wxRadioBox::GetLabel(int n) const
774{
775 return GetString(n);
776}
777
778void wxRadioBox::SetLabel( int item, const wxString& label )
779{
780 SetString(item, label);
781}
782
783#endif // WXWIN_COMPATIBILITY_2_2
784
f6bcfd97
BP
785#endif // wxUSE_RADIOBOX
786