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