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