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