]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/radiobox.cpp
Rewritten in-place editing for generic wxDataViewCtrl
[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{
dc26eeb3
VZ
196 for ( wxRadioBoxButtonsInfoList::compatibility_iterator node = win->m_buttonsInfo.GetFirst();
197 node;
964c139b 198 node = node->GetNext())
dc26eeb3 199 {
964c139b 200 if (widget == GTK_WIDGET(node->GetData()->button))
dc26eeb3
VZ
201 {
202 const wxPoint origin = win->GetPosition();
203 wxRect rect = wxRect( alloc->x - origin.x, alloc->y - origin.y,
204 alloc->width, alloc->height );
205 node->GetData()->rect = rect;
206 break;
207 }
208 }
209}
210}
211
212
b4071e91
RR
213//-----------------------------------------------------------------------------
214// wxRadioBox
c801d85f
KB
215//-----------------------------------------------------------------------------
216
217IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl)
218
f6bcfd97 219void wxRadioBox::Init()
c801d85f 220{
b4efc9b9 221 m_needParent = true;
f6bcfd97
BP
222
223 m_hasFocus =
b4efc9b9 224 m_lostFocus = false;
6de97a3b 225}
c801d85f 226
584ad2a3
MB
227bool wxRadioBox::Create( wxWindow *parent, wxWindowID id,
228 const wxString& title,
229 const wxPoint &pos, const wxSize &size,
230 const wxArrayString& choices, int majorDim,
231 long style, const wxValidator& validator,
232 const wxString &name )
233{
234 wxCArrayString chs(choices);
235
236 return Create( parent, id, title, pos, size, chs.GetCount(),
237 chs.GetStrings(), majorDim, style, validator, name );
238}
239
debe6624 240bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
907789a0 241 const wxPoint &pos, const wxSize &size,
29006414
VZ
242 int n, const wxString choices[], int majorDim,
243 long style, const wxValidator& validator,
244 const wxString &name )
c801d85f 245{
4dcaf11a
RR
246 if (!PreCreation( parent, pos, size ) ||
247 !CreateBase( parent, id, pos, size, style, validator, name ))
248 {
223d09f6 249 wxFAIL_MSG( wxT("wxRadioBox creation failed") );
b4efc9b9 250 return false;
4dcaf11a 251 }
6de97a3b 252
2e1f5012
VZ
253 m_widget = GTKCreateFrame(title);
254 wxControl::SetLabel(title);
378b042b
VZ
255 if ( HasFlag(wxNO_BORDER) )
256 {
257 // If we don't do this here, the wxNO_BORDER style is ignored in Show()
258 gtk_frame_set_shadow_type(GTK_FRAME(m_widget), GTK_SHADOW_NONE);
259 }
260
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
ef5c70f9 641GdkWindow *wxRadioBox::GTKGetWindow(wxArrayGdkWindows& windows) const
b4071e91 642{
ef5c70f9 643 windows.push_back(m_widget->window);
29006414 644
dc26eeb3 645 wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst();
907789a0
RR
646 while (node)
647 {
dc26eeb3 648 GtkWidget *button = GTK_WIDGET( node->GetData()->button );
29006414 649
ef5c70f9 650 windows.push_back(button->window);
29006414 651
b1d4dd7a 652 node = node->GetNext();
907789a0 653 }
29006414 654
ef5c70f9 655 return NULL;
b4071e91 656}
dcf924a3 657
f6bcfd97
BP
658void wxRadioBox::OnInternalIdle()
659{
ef5c70f9
VZ
660 wxControl::OnInternalIdle();
661
f6bcfd97
BP
662 if ( m_lostFocus )
663 {
b4efc9b9
WS
664 m_hasFocus = false;
665 m_lostFocus = false;
f6bcfd97
BP
666
667 wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() );
668 event.SetEventObject( this );
669
670 (void)GetEventHandler()->ProcessEvent( event );
671 }
672}
673
9d522606
RD
674// static
675wxVisualAttributes
676wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
677{
678 wxVisualAttributes attr;
bc0eb46c
VS
679 // NB: we need toplevel window so that GTK+ can find the right style
680 GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
9d522606 681 GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
bc0eb46c 682 gtk_container_add(GTK_CONTAINER(wnd), widget);
9d522606 683 attr = GetDefaultAttributesFromGTKWidget(widget);
bc0eb46c 684 gtk_widget_destroy(wnd);
9d522606
RD
685 return attr;
686}
687
dc26eeb3
VZ
688int wxRadioBox::GetItemFromPoint(const wxPoint& point) const
689{
690 const wxPoint pt = ScreenToClient(point);
691 unsigned n = 0;
692 for ( wxRadioBoxButtonsInfoList::compatibility_iterator
693 node = m_buttonsInfo.GetFirst(); node; node = node->GetNext(), n++ )
694 {
22a35096 695 if ( m_buttonsInfo[n]->rect.Contains(pt) )
dc26eeb3
VZ
696 return n;
697 }
698
699 return wxNOT_FOUND;
700}
701
f6bcfd97 702#endif // wxUSE_RADIOBOX