]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobox.cpp
removed extra membersections (patch 1702329)
[wxWidgets.git] / src / gtk / radiobox.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
11e62fe6 2// Name: src/gtk/radiobox.cpp
c801d85f
KB
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
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
dcf924a3
RR
12
13#if wxUSE_RADIOBOX
14
1e6feb95
VZ
15#include "wx/radiobox.h"
16
e4db172a
WS
17#ifndef WX_PRECOMP
18 #include "wx/log.h"
76b49cf4 19 #include "wx/frame.h"
fdf565fe 20 #include "wx/dialog.h"
e4db172a
WS
21#endif
22
aa1e6de9
VZ
23#if wxUSE_TOOLTIPS
24 #include "wx/tooltip.h"
25#endif
26
9e691f46 27#include "wx/gtk/private.h"
3f26799e
RR
28#include <gdk/gdkkeysyms.h>
29
dc26eeb3
VZ
30//-----------------------------------------------------------------------------
31// wxGTKRadioButtonInfo
32//-----------------------------------------------------------------------------
33// structure internally used by wxRadioBox to store its child buttons
34
35class wxGTKRadioButtonInfo : public wxObject
36{
37public:
38 wxGTKRadioButtonInfo( GtkRadioButton * abutton, const wxRect & arect )
39 : button( abutton ), rect( arect ) {}
40
41 GtkRadioButton * button;
42 wxRect rect;
43};
44
66bd6b93
RR
45//-----------------------------------------------------------------------------
46// data
47//-----------------------------------------------------------------------------
48
dc26eeb3 49#include "wx/listimpl.cpp"
178d7ec2 50WX_DEFINE_LIST( wxRadioBoxButtonsInfoList )
dc26eeb3 51
d7fa7eaa 52extern bool g_blockEventsOnDrag;
66bd6b93 53
c801d85f 54//-----------------------------------------------------------------------------
b4071e91 55// "clicked"
c801d85f
KB
56//-----------------------------------------------------------------------------
57
865bb325 58extern "C" {
e2762ff0 59static void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioBox *rb )
c801d85f 60{
a2053b27 61 if (!rb->m_hasVMT) return;
907789a0 62 if (g_blockEventsOnDrag) return;
29006414 63
e2762ff0 64 if (!button->active) return;
29006414 65
907789a0
RR
66 wxCommandEvent event( wxEVT_COMMAND_RADIOBOX_SELECTED, rb->GetId() );
67 event.SetInt( rb->GetSelection() );
29006414 68 event.SetString( rb->GetStringSelection() );
907789a0
RR
69 event.SetEventObject( rb );
70 rb->GetEventHandler()->ProcessEvent(event);
6de97a3b 71}
865bb325 72}
c801d85f 73
2e0e025e
RR
74//-----------------------------------------------------------------------------
75// "key_press_event"
76//-----------------------------------------------------------------------------
77
865bb325 78extern "C" {
2e0e025e
RR
79static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb )
80{
2e0e025e
RR
81 if (!rb->m_hasVMT) return FALSE;
82 if (g_blockEventsOnDrag) return FALSE;
83
8228b893 84 if ( ((gdk_event->keyval == GDK_Tab) ||
5985c07c
RR
85 (gdk_event->keyval == GDK_ISO_Left_Tab)) &&
86 rb->GetParent() && (rb->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
87 {
88 wxNavigationKeyEvent new_event;
89 new_event.SetEventObject( rb->GetParent() );
90 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
91 new_event.SetDirection( (gdk_event->keyval == GDK_Tab) );
92 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
93 new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
94 new_event.SetCurrentFocus( rb );
95 return rb->GetParent()->GetEventHandler()->ProcessEvent( new_event );
96 }
97
2e0e025e
RR
98 if ((gdk_event->keyval != GDK_Up) &&
99 (gdk_event->keyval != GDK_Down) &&
100 (gdk_event->keyval != GDK_Left) &&
101 (gdk_event->keyval != GDK_Right))
102 {
103 return FALSE;
104 }
2da61056 105
dc26eeb3
VZ
106 wxRadioBoxButtonsInfoList::compatibility_iterator node = rb->m_buttonsInfo.GetFirst();
107 while( node && GTK_WIDGET( node->GetData()->button ) != widget )
108 {
109 node = node->GetNext();
110 }
2e0e025e
RR
111 if (!node)
112 {
113 return FALSE;
114 }
2da61056 115
2e0e025e
RR
116 if ((gdk_event->keyval == GDK_Up) ||
117 (gdk_event->keyval == GDK_Left))
118 {
dc26eeb3
VZ
119 if (node == rb->m_buttonsInfo.GetFirst())
120 node = rb->m_buttonsInfo.GetLast();
2da61056 121 else
b1d4dd7a 122 node = node->GetPrevious();
2e0e025e
RR
123 }
124 else
125 {
dc26eeb3
VZ
126 if (node == rb->m_buttonsInfo.GetLast())
127 node = rb->m_buttonsInfo.GetFirst();
2da61056 128 else
b1d4dd7a 129 node = node->GetNext();
2e0e025e 130 }
2da61056 131
dc26eeb3 132 GtkWidget *button = (GtkWidget*) node->GetData()->button;
2da61056 133
2e0e025e 134 gtk_widget_grab_focus( button );
2da61056 135
2e0e025e
RR
136 return TRUE;
137}
865bb325 138}
2e0e025e 139
865bb325 140extern "C" {
f6bcfd97
BP
141static gint gtk_radiobutton_focus_in( GtkWidget *widget,
142 GdkEvent *WXUNUSED(event),
143 wxRadioBox *win )
144{
145 if ( win->m_lostFocus )
146 {
147 // no, we didn't really lose it
148 win->m_lostFocus = FALSE;
149 }
150 else if ( !win->m_hasFocus )
151 {
b4efc9b9 152 win->m_hasFocus = true;
f6bcfd97
BP
153
154 wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
155 event.SetEventObject( win );
156
157 // never stop the signal emission, it seems to break the kbd handling
158 // inside the radiobox
159 (void)win->GetEventHandler()->ProcessEvent( event );
160 }
161
162 return FALSE;
163}
865bb325 164}
f6bcfd97 165
865bb325 166extern "C" {
f6bcfd97
BP
167static gint gtk_radiobutton_focus_out( GtkWidget *widget,
168 GdkEvent *WXUNUSED(event),
169 wxRadioBox *win )
170{
cc1fcb95
JS
171 // wxASSERT_MSG( win->m_hasFocus, _T("got focus out without any focus in?") );
172 // Replace with a warning, else we dump core a lot!
173 // if (!win->m_hasFocus)
174 // wxLogWarning(_T("Radiobox got focus out without any focus in.") );
f6bcfd97
BP
175
176 // we might have lost the focus, but may be not - it may have just gone to
177 // another button in the same radiobox, so we'll check for it in the next
b4efc9b9
WS
178 // idle iteration (leave m_hasFocus == true for now)
179 win->m_lostFocus = true;
f6bcfd97
BP
180
181 return FALSE;
182}
865bb325 183}
f6bcfd97 184
dc26eeb3
VZ
185extern "C" {
186static void gtk_radiobutton_size_allocate( GtkWidget *widget,
187 GtkAllocation * alloc,
188 wxRadioBox *win )
189{
dc26eeb3
VZ
190 for ( wxRadioBoxButtonsInfoList::compatibility_iterator node = win->m_buttonsInfo.GetFirst();
191 node;
964c139b 192 node = node->GetNext())
dc26eeb3 193 {
964c139b 194 if (widget == GTK_WIDGET(node->GetData()->button))
dc26eeb3
VZ
195 {
196 const wxPoint origin = win->GetPosition();
197 wxRect rect = wxRect( alloc->x - origin.x, alloc->y - origin.y,
198 alloc->width, alloc->height );
199 node->GetData()->rect = rect;
200 break;
201 }
202 }
203}
204}
205
206
b4071e91
RR
207//-----------------------------------------------------------------------------
208// wxRadioBox
c801d85f
KB
209//-----------------------------------------------------------------------------
210
211IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl)
212
f6bcfd97 213void wxRadioBox::Init()
c801d85f 214{
b4efc9b9 215 m_needParent = true;
f6bcfd97
BP
216
217 m_hasFocus =
b4efc9b9 218 m_lostFocus = false;
6de97a3b 219}
c801d85f 220
584ad2a3
MB
221bool wxRadioBox::Create( wxWindow *parent, wxWindowID id,
222 const wxString& title,
223 const wxPoint &pos, const wxSize &size,
224 const wxArrayString& choices, int majorDim,
225 long style, const wxValidator& validator,
226 const wxString &name )
227{
228 wxCArrayString chs(choices);
229
230 return Create( parent, id, title, pos, size, chs.GetCount(),
231 chs.GetStrings(), majorDim, style, validator, name );
232}
233
debe6624 234bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
907789a0 235 const wxPoint &pos, const wxSize &size,
29006414
VZ
236 int n, const wxString choices[], int majorDim,
237 long style, const wxValidator& validator,
238 const wxString &name )
c801d85f 239{
4dcaf11a
RR
240 if (!PreCreation( parent, pos, size ) ||
241 !CreateBase( parent, id, pos, size, style, validator, name ))
242 {
223d09f6 243 wxFAIL_MSG( wxT("wxRadioBox creation failed") );
b4efc9b9 244 return false;
4dcaf11a 245 }
6de97a3b 246
2e1f5012
VZ
247 m_widget = GTKCreateFrame(title);
248 wxControl::SetLabel(title);
378b042b
VZ
249 if ( HasFlag(wxNO_BORDER) )
250 {
251 // If we don't do this here, the wxNO_BORDER style is ignored in Show()
252 gtk_frame_set_shadow_type(GTK_FRAME(m_widget), GTK_SHADOW_NONE);
253 }
254
29006414 255
5eaac5b5
VZ
256 // majorDim may be 0 if all trailing parameters were omitted, so don't
257 // assert here but just use the correct value for it
27c78e45 258 SetMajorDim(majorDim == 0 ? n : majorDim, style);
29006414 259
8017ee9b 260
aa61d352
VZ
261 unsigned int num_of_cols = GetColumnCount();
262 unsigned int num_of_rows = GetRowCount();
11e62fe6 263
07014b5a 264 GtkRadioButton *rbtn = (GtkRadioButton*) NULL;
29006414 265
8017ee9b 266 GtkWidget *table = gtk_table_new( num_of_rows, num_of_cols, FALSE );
d504085d
RR
267 gtk_table_set_col_spacings( GTK_TABLE(table), 1 );
268 gtk_table_set_row_spacings( GTK_TABLE(table), 1 );
8017ee9b
RR
269 gtk_widget_show( table );
270 gtk_container_add( GTK_CONTAINER(m_widget), table );
11e62fe6 271
26333898 272 wxString label;
d3b4d113 273 GSList *radio_button_group = (GSList *) NULL;
8ebb2a1d 274 for (unsigned int i = 0; i < (unsigned int)n; i++)
c801d85f 275 {
26333898 276 if ( i != 0 )
07014b5a 277 radio_button_group = gtk_radio_button_get_group( GTK_RADIO_BUTTON(rbtn) );
29006414 278
26333898
VZ
279 label.Empty();
280 for ( const wxChar *pc = choices[i]; *pc; pc++ )
281 {
223d09f6 282 if ( *pc != wxT('&') )
26333898
VZ
283 label += *pc;
284 }
285
07014b5a
VZ
286 rbtn = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) );
287 gtk_widget_show( GTK_WIDGET(rbtn) );
29006414 288
07014b5a 289 g_signal_connect (rbtn, "key_press_event",
9fa72bd2 290 G_CALLBACK (gtk_radiobox_keypress_callback), this);
2da61056 291
dc26eeb3 292 m_buttonsInfo.Append( new wxGTKRadioButtonInfo( rbtn, wxRect() ) );
29006414 293
8017ee9b
RR
294 if (HasFlag(wxRA_SPECIFY_COLS))
295 {
296 int left = i%num_of_cols;
297 int right = (i%num_of_cols) + 1;
298 int top = i/num_of_cols;
299 int bottom = (i/num_of_cols)+1;
07014b5a 300 gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom,
11e62fe6 301 GTK_FILL, GTK_FILL, 1, 1 );
8017ee9b
RR
302 }
303 else
304 {
305 int left = i/num_of_rows;
306 int right = (i/num_of_rows) + 1;
307 int top = i%num_of_rows;
308 int bottom = (i%num_of_rows)+1;
07014b5a 309 gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom,
11e62fe6 310 GTK_FILL, GTK_FILL, 1, 1 );
8017ee9b
RR
311 }
312
07014b5a 313 ConnectWidget( GTK_WIDGET(rbtn) );
29006414 314
e343da37 315 if (!i)
07014b5a 316 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(rbtn), TRUE );
29006414 317
07014b5a 318 g_signal_connect (rbtn, "clicked",
9fa72bd2 319 G_CALLBACK (gtk_radiobutton_clicked_callback), this);
07014b5a 320 g_signal_connect (rbtn, "focus_in_event",
9fa72bd2 321 G_CALLBACK (gtk_radiobutton_focus_in), this);
07014b5a 322 g_signal_connect (rbtn, "focus_out_event",
9fa72bd2 323 G_CALLBACK (gtk_radiobutton_focus_out), this);
dc26eeb3
VZ
324 g_signal_connect (rbtn, "size_allocate",
325 G_CALLBACK (gtk_radiobutton_size_allocate), this);
6de97a3b 326 }
29006414 327
db434467
RR
328 m_parent->DoAddChild( this );
329
abdeb9e7 330 PostCreation(size);
29006414 331
b4efc9b9 332 return true;
6de97a3b 333}
c801d85f 334
f03fc89f 335wxRadioBox::~wxRadioBox()
d6d1892b 336{
dc26eeb3 337 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
338 while (node)
339 {
dc26eeb3 340 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
907789a0 341 gtk_widget_destroy( button );
b1d4dd7a 342 node = node->GetNext();
907789a0 343 }
dc26eeb3 344 WX_CLEAR_LIST( wxRadioBoxButtonsInfoList, m_buttonsInfo );
d6d1892b
RR
345}
346
debe6624 347bool wxRadioBox::Show( bool show )
c801d85f 348{
b4efc9b9 349 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 350
f96ac56a
RR
351 if (!wxControl::Show(show))
352 {
353 // nothing to do
b4efc9b9 354 return false;
f96ac56a 355 }
c801d85f 356
c4ca49cd 357 if ( HasFlag(wxNO_BORDER) )
b0351fc9 358 gtk_widget_hide( m_widget );
e3e717ec 359
dc26eeb3 360 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
361 while (node)
362 {
dc26eeb3 363 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
29006414 364
27c78e45
VZ
365 if (show)
366 gtk_widget_show( button );
367 else
368 gtk_widget_hide( button );
29006414 369
b1d4dd7a 370 node = node->GetNext();
907789a0 371 }
c801d85f 372
b4efc9b9 373 return true;
6de97a3b 374}
c801d85f 375
b292e2f5
RR
376void wxRadioBox::SetFocus()
377{
223d09f6 378 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 379
dc26eeb3 380 if (m_buttonsInfo.GetCount() == 0) return;
29006414 381
dc26eeb3 382 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
b292e2f5
RR
383 while (node)
384 {
dc26eeb3 385 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button );
b292e2f5 386 if (button->active)
29006414 387 {
b292e2f5 388 gtk_widget_grab_focus( GTK_WIDGET(button) );
29006414
VZ
389 return;
390 }
b1d4dd7a 391 node = node->GetNext();
b292e2f5 392 }
b292e2f5
RR
393}
394
47908e25 395void wxRadioBox::SetSelection( int n )
c801d85f 396{
223d09f6 397 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 398
dc26eeb3 399 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( n );
29006414 400
223d09f6 401 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 402
dc26eeb3 403 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button );
29006414 404
72a7edf0 405 GtkDisableEvents();
2da61056 406
e2762ff0 407 gtk_toggle_button_set_active( button, 1 );
2da61056 408
72a7edf0 409 GtkEnableEvents();
6de97a3b 410}
c801d85f
KB
411
412int wxRadioBox::GetSelection(void) const
413{
789f6795 414 wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") );
29006414 415
907789a0 416 int count = 0;
29006414 417
dc26eeb3 418 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
419 while (node)
420 {
dc26eeb3 421 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button );
907789a0
RR
422 if (button->active) return count;
423 count++;
b1d4dd7a 424 node = node->GetNext();
907789a0 425 }
29006414 426
223d09f6 427 wxFAIL_MSG( wxT("wxRadioBox none selected") );
29006414 428
789f6795 429 return wxNOT_FOUND;
6de97a3b 430}
c801d85f 431
aa61d352 432wxString wxRadioBox::GetString(unsigned int n) const
c801d85f 433{
1a87edf2 434 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") );
29006414 435
dc26eeb3 436 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( n );
29006414 437
1a87edf2 438 wxCHECK_MSG( node, wxEmptyString, wxT("radiobox wrong index") );
29006414 439
dc26eeb3 440 GtkLabel *label = GTK_LABEL(GTK_BIN(node->GetData()->button)->child);
29006414 441
2b5f62a0 442 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
2b5f62a0
VZ
443
444 return str;
6de97a3b 445}
c801d85f 446
d3904ceb 447void wxRadioBox::SetLabel( const wxString& label )
c801d85f 448{
223d09f6 449 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 450
b2ff89d6 451 GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
6de97a3b 452}
c801d85f 453
aa61d352 454void wxRadioBox::SetString(unsigned int item, const wxString& label)
c801d85f 455{
223d09f6 456 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 457
dc26eeb3 458 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 459
223d09f6 460 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 461
dc26eeb3 462 GtkLabel *g_label = GTK_LABEL(GTK_BIN(node->GetData()->button)->child);
29006414 463
a7c12d28 464 gtk_label_set_text( g_label, wxGTK_CONV( label ) );
6de97a3b 465}
c801d85f 466
f03fc89f 467bool wxRadioBox::Enable( bool enable )
c801d85f 468{
f03fc89f 469 if ( !wxControl::Enable( enable ) )
b4efc9b9 470 return false;
29006414 471
dc26eeb3 472 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
473 while (node)
474 {
dc26eeb3 475 GtkButton *button = GTK_BUTTON( node->GetData()->button );
afa7bd1e 476 GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child);
9e691f46 477
907789a0 478 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 479 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
b1d4dd7a 480 node = node->GetNext();
907789a0 481 }
f03fc89f 482
b4efc9b9 483 return true;
6de97a3b 484}
c801d85f 485
aa61d352 486bool wxRadioBox::Enable(unsigned int item, bool enable)
c801d85f 487{
1a87edf2 488 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 489
dc26eeb3 490 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 491
1a87edf2 492 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 493
dc26eeb3 494 GtkButton *button = GTK_BUTTON( node->GetData()->button );
afa7bd1e 495 GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child);
9e691f46 496
907789a0 497 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 498 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
1a87edf2
WS
499
500 return true;
6de97a3b 501}
c801d85f 502
aa61d352 503bool wxRadioBox::IsItemEnabled(unsigned int item) const
27c78e45
VZ
504{
505 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
506
dc26eeb3 507 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
27c78e45
VZ
508
509 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
510
dc26eeb3 511 GtkButton *button = GTK_BUTTON( node->GetData()->button );
27c78e45
VZ
512
513 // don't use GTK_WIDGET_IS_SENSITIVE() here, we want to return true even if
514 // the parent radiobox is disabled
515 return GTK_WIDGET_SENSITIVE(GTK_WIDGET(button));
516}
517
aa61d352 518bool wxRadioBox::Show(unsigned int item, bool show)
c801d85f 519{
789f6795 520 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 521
dc26eeb3 522 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 523
789f6795 524 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 525
dc26eeb3 526 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
c801d85f 527
907789a0
RR
528 if (show)
529 gtk_widget_show( button );
530 else
531 gtk_widget_hide( button );
789f6795
WS
532
533 return true;
6de97a3b 534}
c801d85f 535
aa61d352 536bool wxRadioBox::IsItemShown(unsigned int item) const
c801d85f 537{
27c78e45 538 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 539
dc26eeb3 540 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
c801d85f 541
27c78e45 542 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 543
dc26eeb3 544 GtkButton *button = GTK_BUTTON( node->GetData()->button );
29006414 545
27c78e45 546 return GTK_WIDGET_VISIBLE(GTK_WIDGET(button));
6de97a3b 547}
c801d85f 548
aa61d352 549unsigned int wxRadioBox::GetCount() const
c801d85f 550{
dc26eeb3 551 return m_buttonsInfo.GetCount();
6de97a3b 552}
c801d85f 553
72a7edf0 554void wxRadioBox::GtkDisableEvents()
953704c1 555{
dc26eeb3 556 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
953704c1
RR
557 while (node)
558 {
dc26eeb3 559 g_signal_handlers_disconnect_by_func (node->GetData()->button,
9fa72bd2
MR
560 (gpointer) gtk_radiobutton_clicked_callback,
561 this);
953704c1 562
b1d4dd7a 563 node = node->GetNext();
953704c1
RR
564 }
565}
566
72a7edf0 567void wxRadioBox::GtkEnableEvents()
953704c1 568{
dc26eeb3 569 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
953704c1
RR
570 while (node)
571 {
dc26eeb3 572 g_signal_connect (node->GetData()->button, "clicked",
9fa72bd2 573 G_CALLBACK (gtk_radiobutton_clicked_callback), this);
953704c1 574
b1d4dd7a 575 node = node->GetNext();
953704c1
RR
576 }
577}
578
f40fdaa3 579void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 580{
2e1f5012 581 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget), style);
81e88f5b 582
dc26eeb3 583 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
584 while (node)
585 {
dc26eeb3 586 GtkWidget *widget = GTK_WIDGET( node->GetData()->button );
29006414 587
f40fdaa3 588 gtk_widget_modify_style( widget, style );
afa7bd1e 589 gtk_widget_modify_style(GTK_BIN(widget)->child, style);
29006414 590
b1d4dd7a 591 node = node->GetNext();
907789a0 592 }
868a2826 593}
b4071e91 594
2e1f5012
VZ
595bool wxRadioBox::GTKWidgetNeedsMnemonic() const
596{
597 return true;
598}
599
600void wxRadioBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
601{
602 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget), w);
603}
604
72a7edf0 605#if wxUSE_TOOLTIPS
aa1e6de9 606void wxRadioBox::ApplyToolTip(GtkTooltips * WXUNUSED(tips), const wxChar *tip)
72a7edf0 607{
aa1e6de9
VZ
608 // set this tooltip for all radiobuttons which don't have their own tips
609 unsigned n = 0;
dc26eeb3 610 for ( wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
aa1e6de9
VZ
611 node;
612 node = node->GetNext(), n++ )
72a7edf0 613 {
aa1e6de9
VZ
614 if ( !GetItemToolTip(n) )
615 {
dc26eeb3 616 wxToolTip::Apply(GTK_WIDGET(node->GetData()->button),
aa1e6de9
VZ
617 wxConvCurrent->cWX2MB(tip));
618 }
72a7edf0
RR
619 }
620}
aa1e6de9
VZ
621
622void wxRadioBox::DoSetItemToolTip(unsigned int n, wxToolTip *tooltip)
623{
624 wxCharBuffer buf;
625 if ( !tooltip )
626 tooltip = GetToolTip();
627 if ( tooltip )
628 buf = wxGTK_CONV(tooltip->GetTip());
629
dc26eeb3 630 wxToolTip::Apply(GTK_WIDGET(m_buttonsInfo[n]->button), buf);
aa1e6de9
VZ
631}
632
72a7edf0
RR
633#endif // wxUSE_TOOLTIPS
634
ef5c70f9 635GdkWindow *wxRadioBox::GTKGetWindow(wxArrayGdkWindows& windows) const
b4071e91 636{
ef5c70f9 637 windows.push_back(m_widget->window);
29006414 638
dc26eeb3 639 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
640 while (node)
641 {
dc26eeb3 642 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
29006414 643
ef5c70f9 644 windows.push_back(button->window);
29006414 645
b1d4dd7a 646 node = node->GetNext();
907789a0 647 }
29006414 648
ef5c70f9 649 return NULL;
b4071e91 650}
dcf924a3 651
f6bcfd97
BP
652void wxRadioBox::OnInternalIdle()
653{
ef5c70f9
VZ
654 wxControl::OnInternalIdle();
655
f6bcfd97
BP
656 if ( m_lostFocus )
657 {
b4efc9b9
WS
658 m_hasFocus = false;
659 m_lostFocus = false;
f6bcfd97
BP
660
661 wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() );
662 event.SetEventObject( this );
663
664 (void)GetEventHandler()->ProcessEvent( event );
665 }
666}
667
9d522606
RD
668// static
669wxVisualAttributes
670wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
671{
672 wxVisualAttributes attr;
bc0eb46c
VS
673 // NB: we need toplevel window so that GTK+ can find the right style
674 GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
9d522606 675 GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
bc0eb46c 676 gtk_container_add(GTK_CONTAINER(wnd), widget);
9d522606 677 attr = GetDefaultAttributesFromGTKWidget(widget);
bc0eb46c 678 gtk_widget_destroy(wnd);
9d522606
RD
679 return attr;
680}
681
dc26eeb3
VZ
682int wxRadioBox::GetItemFromPoint(const wxPoint& point) const
683{
684 const wxPoint pt = ScreenToClient(point);
685 unsigned n = 0;
686 for ( wxRadioBoxButtonsInfoList::compatibility_iterator
687 node = m_buttonsInfo.GetFirst(); node; node = node->GetNext(), n++ )
688 {
22a35096 689 if ( m_buttonsInfo[n]->rect.Contains(pt) )
dc26eeb3
VZ
690 return n;
691 }
692
693 return wxNOT_FOUND;
694}
695
f6bcfd97 696#endif // wxUSE_RADIOBOX