]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobox.cpp
non-pch build fix, indentation and whitespace cleanup
[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{
f6bcfd97 215 m_hasFocus =
b4efc9b9 216 m_lostFocus = false;
6de97a3b 217}
c801d85f 218
584ad2a3
MB
219bool wxRadioBox::Create( wxWindow *parent, wxWindowID id,
220 const wxString& title,
221 const wxPoint &pos, const wxSize &size,
222 const wxArrayString& choices, int majorDim,
223 long style, const wxValidator& validator,
224 const wxString &name )
225{
226 wxCArrayString chs(choices);
227
228 return Create( parent, id, title, pos, size, chs.GetCount(),
229 chs.GetStrings(), majorDim, style, validator, name );
230}
231
debe6624 232bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
907789a0 233 const wxPoint &pos, const wxSize &size,
29006414
VZ
234 int n, const wxString choices[], int majorDim,
235 long style, const wxValidator& validator,
236 const wxString &name )
c801d85f 237{
4dcaf11a
RR
238 if (!PreCreation( parent, pos, size ) ||
239 !CreateBase( parent, id, pos, size, style, validator, name ))
240 {
223d09f6 241 wxFAIL_MSG( wxT("wxRadioBox creation failed") );
b4efc9b9 242 return false;
4dcaf11a 243 }
6de97a3b 244
2e1f5012
VZ
245 m_widget = GTKCreateFrame(title);
246 wxControl::SetLabel(title);
378b042b
VZ
247 if ( HasFlag(wxNO_BORDER) )
248 {
249 // If we don't do this here, the wxNO_BORDER style is ignored in Show()
250 gtk_frame_set_shadow_type(GTK_FRAME(m_widget), GTK_SHADOW_NONE);
251 }
252
29006414 253
5eaac5b5
VZ
254 // majorDim may be 0 if all trailing parameters were omitted, so don't
255 // assert here but just use the correct value for it
27c78e45 256 SetMajorDim(majorDim == 0 ? n : majorDim, style);
29006414 257
8017ee9b 258
aa61d352
VZ
259 unsigned int num_of_cols = GetColumnCount();
260 unsigned int num_of_rows = GetRowCount();
11e62fe6 261
07014b5a 262 GtkRadioButton *rbtn = (GtkRadioButton*) NULL;
29006414 263
8017ee9b 264 GtkWidget *table = gtk_table_new( num_of_rows, num_of_cols, FALSE );
d504085d
RR
265 gtk_table_set_col_spacings( GTK_TABLE(table), 1 );
266 gtk_table_set_row_spacings( GTK_TABLE(table), 1 );
8017ee9b
RR
267 gtk_widget_show( table );
268 gtk_container_add( GTK_CONTAINER(m_widget), table );
11e62fe6 269
26333898 270 wxString label;
d3b4d113 271 GSList *radio_button_group = (GSList *) NULL;
8ebb2a1d 272 for (unsigned int i = 0; i < (unsigned int)n; i++)
c801d85f 273 {
26333898 274 if ( i != 0 )
07014b5a 275 radio_button_group = gtk_radio_button_get_group( GTK_RADIO_BUTTON(rbtn) );
29006414 276
26333898 277 label.Empty();
86501081
VS
278 for ( wxString::const_iterator pc = choices[i].begin();
279 pc != choices[i].end(); ++pc )
26333898 280 {
223d09f6 281 if ( *pc != wxT('&') )
26333898
VZ
282 label += *pc;
283 }
284
07014b5a
VZ
285 rbtn = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) );
286 gtk_widget_show( GTK_WIDGET(rbtn) );
29006414 287
07014b5a 288 g_signal_connect (rbtn, "key_press_event",
9fa72bd2 289 G_CALLBACK (gtk_radiobox_keypress_callback), this);
2da61056 290
dc26eeb3 291 m_buttonsInfo.Append( new wxGTKRadioButtonInfo( rbtn, wxRect() ) );
29006414 292
8017ee9b
RR
293 if (HasFlag(wxRA_SPECIFY_COLS))
294 {
295 int left = i%num_of_cols;
296 int right = (i%num_of_cols) + 1;
297 int top = i/num_of_cols;
298 int bottom = (i/num_of_cols)+1;
07014b5a 299 gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom,
11e62fe6 300 GTK_FILL, GTK_FILL, 1, 1 );
8017ee9b
RR
301 }
302 else
303 {
304 int left = i/num_of_rows;
305 int right = (i/num_of_rows) + 1;
306 int top = i%num_of_rows;
307 int bottom = (i%num_of_rows)+1;
07014b5a 308 gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom,
11e62fe6 309 GTK_FILL, GTK_FILL, 1, 1 );
8017ee9b
RR
310 }
311
07014b5a 312 ConnectWidget( GTK_WIDGET(rbtn) );
29006414 313
e343da37 314 if (!i)
07014b5a 315 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(rbtn), TRUE );
29006414 316
07014b5a 317 g_signal_connect (rbtn, "clicked",
9fa72bd2 318 G_CALLBACK (gtk_radiobutton_clicked_callback), this);
07014b5a 319 g_signal_connect (rbtn, "focus_in_event",
9fa72bd2 320 G_CALLBACK (gtk_radiobutton_focus_in), this);
07014b5a 321 g_signal_connect (rbtn, "focus_out_event",
9fa72bd2 322 G_CALLBACK (gtk_radiobutton_focus_out), this);
dc26eeb3
VZ
323 g_signal_connect (rbtn, "size_allocate",
324 G_CALLBACK (gtk_radiobutton_size_allocate), this);
6de97a3b 325 }
29006414 326
db434467
RR
327 m_parent->DoAddChild( this );
328
abdeb9e7 329 PostCreation(size);
29006414 330
b4efc9b9 331 return true;
6de97a3b 332}
c801d85f 333
f03fc89f 334wxRadioBox::~wxRadioBox()
d6d1892b 335{
dc26eeb3 336 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
337 while (node)
338 {
dc26eeb3 339 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
907789a0 340 gtk_widget_destroy( button );
b1d4dd7a 341 node = node->GetNext();
907789a0 342 }
dc26eeb3 343 WX_CLEAR_LIST( wxRadioBoxButtonsInfoList, m_buttonsInfo );
d6d1892b
RR
344}
345
debe6624 346bool wxRadioBox::Show( bool show )
c801d85f 347{
b4efc9b9 348 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 349
f96ac56a
RR
350 if (!wxControl::Show(show))
351 {
352 // nothing to do
b4efc9b9 353 return false;
f96ac56a 354 }
c801d85f 355
c4ca49cd 356 if ( HasFlag(wxNO_BORDER) )
b0351fc9 357 gtk_widget_hide( m_widget );
e3e717ec 358
dc26eeb3 359 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
360 while (node)
361 {
dc26eeb3 362 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
29006414 363
27c78e45
VZ
364 if (show)
365 gtk_widget_show( button );
366 else
367 gtk_widget_hide( button );
29006414 368
b1d4dd7a 369 node = node->GetNext();
907789a0 370 }
c801d85f 371
b4efc9b9 372 return true;
6de97a3b 373}
c801d85f 374
b292e2f5
RR
375void wxRadioBox::SetFocus()
376{
223d09f6 377 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 378
dc26eeb3 379 if (m_buttonsInfo.GetCount() == 0) return;
29006414 380
dc26eeb3 381 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
b292e2f5
RR
382 while (node)
383 {
dc26eeb3 384 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button );
b292e2f5 385 if (button->active)
29006414 386 {
b292e2f5 387 gtk_widget_grab_focus( GTK_WIDGET(button) );
29006414
VZ
388 return;
389 }
b1d4dd7a 390 node = node->GetNext();
b292e2f5 391 }
b292e2f5
RR
392}
393
47908e25 394void wxRadioBox::SetSelection( int n )
c801d85f 395{
223d09f6 396 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 397
dc26eeb3 398 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( n );
29006414 399
223d09f6 400 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 401
dc26eeb3 402 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button );
29006414 403
72a7edf0 404 GtkDisableEvents();
2da61056 405
e2762ff0 406 gtk_toggle_button_set_active( button, 1 );
2da61056 407
72a7edf0 408 GtkEnableEvents();
6de97a3b 409}
c801d85f
KB
410
411int wxRadioBox::GetSelection(void) const
412{
789f6795 413 wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") );
29006414 414
907789a0 415 int count = 0;
29006414 416
dc26eeb3 417 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
418 while (node)
419 {
dc26eeb3 420 GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button );
907789a0
RR
421 if (button->active) return count;
422 count++;
b1d4dd7a 423 node = node->GetNext();
907789a0 424 }
29006414 425
223d09f6 426 wxFAIL_MSG( wxT("wxRadioBox none selected") );
29006414 427
789f6795 428 return wxNOT_FOUND;
6de97a3b 429}
c801d85f 430
aa61d352 431wxString wxRadioBox::GetString(unsigned int n) const
c801d85f 432{
1a87edf2 433 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") );
29006414 434
dc26eeb3 435 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( n );
29006414 436
1a87edf2 437 wxCHECK_MSG( node, wxEmptyString, wxT("radiobox wrong index") );
29006414 438
dc26eeb3 439 GtkLabel *label = GTK_LABEL(GTK_BIN(node->GetData()->button)->child);
29006414 440
2b5f62a0 441 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
2b5f62a0
VZ
442
443 return str;
6de97a3b 444}
c801d85f 445
d3904ceb 446void wxRadioBox::SetLabel( const wxString& label )
c801d85f 447{
223d09f6 448 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 449
b2ff89d6 450 GTKSetLabelForFrame(GTK_FRAME(m_widget), label);
6de97a3b 451}
c801d85f 452
aa61d352 453void wxRadioBox::SetString(unsigned int item, const wxString& label)
c801d85f 454{
223d09f6 455 wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") );
29006414 456
dc26eeb3 457 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 458
223d09f6 459 wxCHECK_RET( node, wxT("radiobox wrong index") );
29006414 460
dc26eeb3 461 GtkLabel *g_label = GTK_LABEL(GTK_BIN(node->GetData()->button)->child);
29006414 462
a7c12d28 463 gtk_label_set_text( g_label, wxGTK_CONV( label ) );
6de97a3b 464}
c801d85f 465
f03fc89f 466bool wxRadioBox::Enable( bool enable )
c801d85f 467{
f03fc89f 468 if ( !wxControl::Enable( enable ) )
b4efc9b9 469 return false;
29006414 470
dc26eeb3 471 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
472 while (node)
473 {
dc26eeb3 474 GtkButton *button = GTK_BUTTON( node->GetData()->button );
afa7bd1e 475 GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child);
9e691f46 476
907789a0 477 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 478 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
b1d4dd7a 479 node = node->GetNext();
907789a0 480 }
f03fc89f 481
b4efc9b9 482 return true;
6de97a3b 483}
c801d85f 484
aa61d352 485bool wxRadioBox::Enable(unsigned int item, bool enable)
c801d85f 486{
1a87edf2 487 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 488
dc26eeb3 489 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 490
1a87edf2 491 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 492
dc26eeb3 493 GtkButton *button = GTK_BUTTON( node->GetData()->button );
afa7bd1e 494 GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child);
9e691f46 495
907789a0 496 gtk_widget_set_sensitive( GTK_WIDGET(button), enable );
9e691f46 497 gtk_widget_set_sensitive( GTK_WIDGET(label), enable );
1a87edf2
WS
498
499 return true;
6de97a3b 500}
c801d85f 501
aa61d352 502bool wxRadioBox::IsItemEnabled(unsigned int item) const
27c78e45
VZ
503{
504 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
505
dc26eeb3 506 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
27c78e45
VZ
507
508 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
509
dc26eeb3 510 GtkButton *button = GTK_BUTTON( node->GetData()->button );
27c78e45
VZ
511
512 // don't use GTK_WIDGET_IS_SENSITIVE() here, we want to return true even if
513 // the parent radiobox is disabled
514 return GTK_WIDGET_SENSITIVE(GTK_WIDGET(button));
515}
516
aa61d352 517bool wxRadioBox::Show(unsigned int item, bool show)
c801d85f 518{
789f6795 519 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 520
dc26eeb3 521 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
29006414 522
789f6795 523 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 524
dc26eeb3 525 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
c801d85f 526
907789a0
RR
527 if (show)
528 gtk_widget_show( button );
529 else
530 gtk_widget_hide( button );
789f6795
WS
531
532 return true;
6de97a3b 533}
c801d85f 534
aa61d352 535bool wxRadioBox::IsItemShown(unsigned int item) const
c801d85f 536{
27c78e45 537 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") );
29006414 538
dc26eeb3 539 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item );
c801d85f 540
27c78e45 541 wxCHECK_MSG( node, false, wxT("radiobox wrong index") );
29006414 542
dc26eeb3 543 GtkButton *button = GTK_BUTTON( node->GetData()->button );
29006414 544
27c78e45 545 return GTK_WIDGET_VISIBLE(GTK_WIDGET(button));
6de97a3b 546}
c801d85f 547
aa61d352 548unsigned int wxRadioBox::GetCount() const
c801d85f 549{
dc26eeb3 550 return m_buttonsInfo.GetCount();
6de97a3b 551}
c801d85f 552
72a7edf0 553void wxRadioBox::GtkDisableEvents()
953704c1 554{
dc26eeb3 555 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
953704c1
RR
556 while (node)
557 {
98264520
PC
558 g_signal_handlers_block_by_func(node->GetData()->button,
559 (gpointer)gtk_radiobutton_clicked_callback, this);
953704c1 560
b1d4dd7a 561 node = node->GetNext();
953704c1
RR
562 }
563}
564
72a7edf0 565void wxRadioBox::GtkEnableEvents()
953704c1 566{
dc26eeb3 567 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
953704c1
RR
568 while (node)
569 {
98264520
PC
570 g_signal_handlers_unblock_by_func(node->GetData()->button,
571 (gpointer)gtk_radiobutton_clicked_callback, this);
953704c1 572
b1d4dd7a 573 node = node->GetNext();
953704c1
RR
574 }
575}
576
f40fdaa3 577void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style)
868a2826 578{
2e1f5012 579 GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget), style);
81e88f5b 580
dc26eeb3 581 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
582 while (node)
583 {
dc26eeb3 584 GtkWidget *widget = GTK_WIDGET( node->GetData()->button );
29006414 585
f40fdaa3 586 gtk_widget_modify_style( widget, style );
afa7bd1e 587 gtk_widget_modify_style(GTK_BIN(widget)->child, style);
29006414 588
b1d4dd7a 589 node = node->GetNext();
907789a0 590 }
868a2826 591}
b4071e91 592
2e1f5012
VZ
593bool wxRadioBox::GTKWidgetNeedsMnemonic() const
594{
595 return true;
596}
597
598void wxRadioBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
599{
600 GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget), w);
601}
602
72a7edf0 603#if wxUSE_TOOLTIPS
6e5f6c7c 604void wxRadioBox::ApplyToolTip(GtkTooltips * WXUNUSED(tips), const gchar *tip)
72a7edf0 605{
aa1e6de9
VZ
606 // set this tooltip for all radiobuttons which don't have their own tips
607 unsigned n = 0;
dc26eeb3 608 for ( wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
aa1e6de9
VZ
609 node;
610 node = node->GetNext(), n++ )
72a7edf0 611 {
aa1e6de9
VZ
612 if ( !GetItemToolTip(n) )
613 {
6e5f6c7c 614 wxToolTip::Apply(GTK_WIDGET(node->GetData()->button), tip);
aa1e6de9 615 }
72a7edf0
RR
616 }
617}
aa1e6de9
VZ
618
619void wxRadioBox::DoSetItemToolTip(unsigned int n, wxToolTip *tooltip)
620{
621 wxCharBuffer buf;
622 if ( !tooltip )
623 tooltip = GetToolTip();
624 if ( tooltip )
625 buf = wxGTK_CONV(tooltip->GetTip());
626
dc26eeb3 627 wxToolTip::Apply(GTK_WIDGET(m_buttonsInfo[n]->button), buf);
aa1e6de9
VZ
628}
629
72a7edf0
RR
630#endif // wxUSE_TOOLTIPS
631
ef5c70f9 632GdkWindow *wxRadioBox::GTKGetWindow(wxArrayGdkWindows& windows) const
b4071e91 633{
ef5c70f9 634 windows.push_back(m_widget->window);
29006414 635
dc26eeb3 636 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
637 while (node)
638 {
dc26eeb3 639 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
29006414 640
ef5c70f9 641 windows.push_back(button->window);
29006414 642
b1d4dd7a 643 node = node->GetNext();
907789a0 644 }
29006414 645
ef5c70f9 646 return NULL;
b4071e91 647}
dcf924a3 648
f6bcfd97
BP
649void wxRadioBox::OnInternalIdle()
650{
ef5c70f9
VZ
651 wxControl::OnInternalIdle();
652
f6bcfd97
BP
653 if ( m_lostFocus )
654 {
b4efc9b9
WS
655 m_hasFocus = false;
656 m_lostFocus = false;
f6bcfd97
BP
657
658 wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() );
659 event.SetEventObject( this );
660
661 (void)GetEventHandler()->ProcessEvent( event );
662 }
663}
664
9d522606
RD
665// static
666wxVisualAttributes
667wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
668{
669 wxVisualAttributes attr;
bc0eb46c
VS
670 // NB: we need toplevel window so that GTK+ can find the right style
671 GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
9d522606 672 GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
bc0eb46c 673 gtk_container_add(GTK_CONTAINER(wnd), widget);
9d522606 674 attr = GetDefaultAttributesFromGTKWidget(widget);
bc0eb46c 675 gtk_widget_destroy(wnd);
9d522606
RD
676 return attr;
677}
678
dc26eeb3
VZ
679int wxRadioBox::GetItemFromPoint(const wxPoint& point) const
680{
681 const wxPoint pt = ScreenToClient(point);
682 unsigned n = 0;
683 for ( wxRadioBoxButtonsInfoList::compatibility_iterator
684 node = m_buttonsInfo.GetFirst(); node; node = node->GetNext(), n++ )
685 {
22a35096 686 if ( m_buttonsInfo[n]->rect.Contains(pt) )
dc26eeb3
VZ
687 return n;
688 }
689
690 return wxNOT_FOUND;
691}
692
f6bcfd97 693#endif // wxUSE_RADIOBOX