]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: radiobox.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
11 | #pragma implementation "radiobox.h" | |
12 | #endif | |
13 | ||
14 | // For compilers that support precompilation, includes "wx.h". | |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #if wxUSE_RADIOBOX | |
18 | ||
19 | #include "wx/radiobox.h" | |
20 | ||
21 | #include "wx/dialog.h" | |
22 | #include "wx/frame.h" | |
23 | #include "wx/log.h" | |
24 | ||
25 | #include "wx/gtk/private.h" | |
26 | #include <gdk/gdkkeysyms.h> | |
27 | ||
28 | #include "wx/gtk/win_gtk.h" | |
29 | ||
30 | //----------------------------------------------------------------------------- | |
31 | // idle system | |
32 | //----------------------------------------------------------------------------- | |
33 | ||
34 | extern void wxapp_install_idle_handler(); | |
35 | extern bool g_isIdle; | |
36 | ||
37 | //----------------------------------------------------------------------------- | |
38 | // data | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
41 | extern bool g_blockEventsOnDrag; | |
42 | extern wxWindowGTK *g_delayedFocus; | |
43 | ||
44 | //----------------------------------------------------------------------------- | |
45 | // "clicked" | |
46 | //----------------------------------------------------------------------------- | |
47 | ||
48 | static void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioBox *rb ) | |
49 | { | |
50 | if (g_isIdle) wxapp_install_idle_handler(); | |
51 | ||
52 | if (!rb->m_hasVMT) return; | |
53 | if (g_blockEventsOnDrag) return; | |
54 | ||
55 | if (!button->active) return; | |
56 | ||
57 | wxCommandEvent event( wxEVT_COMMAND_RADIOBOX_SELECTED, rb->GetId() ); | |
58 | event.SetInt( rb->GetSelection() ); | |
59 | event.SetString( rb->GetStringSelection() ); | |
60 | event.SetEventObject( rb ); | |
61 | rb->GetEventHandler()->ProcessEvent(event); | |
62 | } | |
63 | ||
64 | //----------------------------------------------------------------------------- | |
65 | // "key_press_event" | |
66 | //----------------------------------------------------------------------------- | |
67 | ||
68 | static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb ) | |
69 | { | |
70 | if (g_isIdle) | |
71 | wxapp_install_idle_handler(); | |
72 | ||
73 | if (!rb->m_hasVMT) return FALSE; | |
74 | if (g_blockEventsOnDrag) return FALSE; | |
75 | ||
76 | if ((gdk_event->keyval != GDK_Up) && | |
77 | (gdk_event->keyval != GDK_Down) && | |
78 | (gdk_event->keyval != GDK_Left) && | |
79 | (gdk_event->keyval != GDK_Right)) | |
80 | { | |
81 | return FALSE; | |
82 | } | |
83 | ||
84 | wxList::compatibility_iterator node = rb->m_boxes.Find( (wxObject*) widget ); | |
85 | if (!node) | |
86 | { | |
87 | return FALSE; | |
88 | } | |
89 | ||
90 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); | |
91 | ||
92 | if ((gdk_event->keyval == GDK_Up) || | |
93 | (gdk_event->keyval == GDK_Left)) | |
94 | { | |
95 | if (node == rb->m_boxes.GetFirst()) | |
96 | node = rb->m_boxes.GetLast(); | |
97 | else | |
98 | node = node->GetPrevious(); | |
99 | } | |
100 | else | |
101 | { | |
102 | if (node == rb->m_boxes.GetLast()) | |
103 | node = rb->m_boxes.GetFirst(); | |
104 | else | |
105 | node = node->GetNext(); | |
106 | } | |
107 | ||
108 | GtkWidget *button = (GtkWidget*) node->GetData(); | |
109 | ||
110 | gtk_widget_grab_focus( button ); | |
111 | ||
112 | return TRUE; | |
113 | } | |
114 | ||
115 | static gint gtk_radiobutton_focus_in( GtkWidget *widget, | |
116 | GdkEvent *WXUNUSED(event), | |
117 | wxRadioBox *win ) | |
118 | { | |
119 | if ( win->m_lostFocus ) | |
120 | { | |
121 | // no, we didn't really lose it | |
122 | win->m_lostFocus = FALSE; | |
123 | } | |
124 | else if ( !win->m_hasFocus ) | |
125 | { | |
126 | win->m_hasFocus = TRUE; | |
127 | ||
128 | wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); | |
129 | event.SetEventObject( win ); | |
130 | ||
131 | // never stop the signal emission, it seems to break the kbd handling | |
132 | // inside the radiobox | |
133 | (void)win->GetEventHandler()->ProcessEvent( event ); | |
134 | } | |
135 | ||
136 | return FALSE; | |
137 | } | |
138 | ||
139 | static gint gtk_radiobutton_focus_out( GtkWidget *widget, | |
140 | GdkEvent *WXUNUSED(event), | |
141 | wxRadioBox *win ) | |
142 | { | |
143 | // wxASSERT_MSG( win->m_hasFocus, _T("got focus out without any focus in?") ); | |
144 | // Replace with a warning, else we dump core a lot! | |
145 | // if (!win->m_hasFocus) | |
146 | // wxLogWarning(_T("Radiobox got focus out without any focus in.") ); | |
147 | ||
148 | // we might have lost the focus, but may be not - it may have just gone to | |
149 | // another button in the same radiobox, so we'll check for it in the next | |
150 | // idle iteration (leave m_hasFocus == TRUE for now) | |
151 | win->m_lostFocus = TRUE; | |
152 | ||
153 | return FALSE; | |
154 | } | |
155 | ||
156 | //----------------------------------------------------------------------------- | |
157 | // wxRadioBox | |
158 | //----------------------------------------------------------------------------- | |
159 | ||
160 | IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl) | |
161 | ||
162 | void wxRadioBox::Init() | |
163 | { | |
164 | m_needParent = TRUE; | |
165 | m_acceptsFocus = TRUE; | |
166 | ||
167 | m_hasFocus = | |
168 | m_lostFocus = FALSE; | |
169 | } | |
170 | ||
171 | bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, | |
172 | const wxString& title, | |
173 | const wxPoint &pos, const wxSize &size, | |
174 | const wxArrayString& choices, int majorDim, | |
175 | long style, const wxValidator& validator, | |
176 | const wxString &name ) | |
177 | { | |
178 | wxCArrayString chs(choices); | |
179 | ||
180 | return Create( parent, id, title, pos, size, chs.GetCount(), | |
181 | chs.GetStrings(), majorDim, style, validator, name ); | |
182 | } | |
183 | ||
184 | bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, | |
185 | const wxPoint &pos, const wxSize &size, | |
186 | int n, const wxString choices[], int majorDim, | |
187 | long style, const wxValidator& validator, | |
188 | const wxString &name ) | |
189 | { | |
190 | if (!PreCreation( parent, pos, size ) || | |
191 | !CreateBase( parent, id, pos, size, style, validator, name )) | |
192 | { | |
193 | wxFAIL_MSG( wxT("wxRadioBox creation failed") ); | |
194 | return FALSE; | |
195 | } | |
196 | ||
197 | m_widget = gtk_frame_new( wxGTK_CONV( title ) ); | |
198 | ||
199 | // majorDim may be 0 if all trailing parameters were omitted, so don't | |
200 | // assert here but just use the correct value for it | |
201 | m_majorDim = majorDim == 0 ? n : majorDim; | |
202 | ||
203 | GtkRadioButton *m_radio = (GtkRadioButton*) NULL; | |
204 | ||
205 | wxString label; | |
206 | GSList *radio_button_group = (GSList *) NULL; | |
207 | for (int i = 0; i < n; i++) | |
208 | { | |
209 | if ( i != 0 ) | |
210 | radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) ); | |
211 | ||
212 | label.Empty(); | |
213 | for ( const wxChar *pc = choices[i]; *pc; pc++ ) | |
214 | { | |
215 | if ( *pc != wxT('&') ) | |
216 | label += *pc; | |
217 | } | |
218 | ||
219 | m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) ); | |
220 | ||
221 | gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event", | |
222 | GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this ); | |
223 | ||
224 | m_boxes.Append( (wxObject*) m_radio ); | |
225 | ||
226 | ConnectWidget( GTK_WIDGET(m_radio) ); | |
227 | ||
228 | if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); | |
229 | ||
230 | gtk_signal_connect( GTK_OBJECT(m_radio), "clicked", | |
231 | GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); | |
232 | ||
233 | gtk_signal_connect( GTK_OBJECT(m_radio), "focus_in_event", | |
234 | GTK_SIGNAL_FUNC(gtk_radiobutton_focus_in), (gpointer)this ); | |
235 | ||
236 | gtk_signal_connect( GTK_OBJECT(m_radio), "focus_out_event", | |
237 | GTK_SIGNAL_FUNC(gtk_radiobutton_focus_out), (gpointer)this ); | |
238 | ||
239 | gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow), | |
240 | GTK_WIDGET(m_radio), | |
241 | m_x+10, m_y+10+(i*24), 10, 10 ); | |
242 | } | |
243 | ||
244 | m_parent->DoAddChild( this ); | |
245 | ||
246 | bool wasShown = IsShown(); | |
247 | if ( wasShown ) | |
248 | Hide(); // prevent PostCreation() from showing us | |
249 | ||
250 | SetLabel( title ); | |
251 | ||
252 | PostCreation(size); | |
253 | ||
254 | if ( wasShown ) | |
255 | Show(); | |
256 | ||
257 | return TRUE; | |
258 | } | |
259 | ||
260 | wxRadioBox::~wxRadioBox() | |
261 | { | |
262 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
263 | while (node) | |
264 | { | |
265 | GtkWidget *button = GTK_WIDGET( node->GetData() ); | |
266 | gtk_widget_destroy( button ); | |
267 | node = node->GetNext(); | |
268 | } | |
269 | } | |
270 | ||
271 | void wxRadioBox::DoSetSize( int x, int y, int width, int height, int sizeFlags ) | |
272 | { | |
273 | wxWindow::DoSetSize( x, y, width, height, sizeFlags ); | |
274 | ||
275 | LayoutItems(false); | |
276 | } | |
277 | ||
278 | wxSize wxRadioBox::DoGetBestSize() const | |
279 | { | |
280 | wxSize size = LayoutItems(true); | |
281 | ||
282 | GtkRequisition req; | |
283 | req.width = 2; | |
284 | req.height = 2; | |
285 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) (m_widget, &req ); | |
286 | if (req.width > size.x) | |
287 | size.x = req.width; | |
288 | ||
289 | CacheBestSize(size); | |
290 | return size; | |
291 | } | |
292 | ||
293 | wxSize wxRadioBox::LayoutItems(bool justCalc) const | |
294 | { | |
295 | wxSize res( 0, 0 ); | |
296 | ||
297 | // avoid dividing by 0 below | |
298 | wxCHECK_MSG( m_majorDim, res, wxT("dimension of radiobox should not be 0!") ); | |
299 | ||
300 | int num_per_major = (m_boxes.GetCount() - 1) / m_majorDim +1; | |
301 | ||
302 | int x = 7; | |
303 | int y = 15; | |
304 | ||
305 | int num_of_cols = 0; | |
306 | int num_of_rows = 0; | |
307 | if (HasFlag(wxRA_SPECIFY_COLS)) | |
308 | { | |
309 | num_of_cols = m_majorDim; | |
310 | num_of_rows = num_per_major; | |
311 | } | |
312 | else | |
313 | { | |
314 | num_of_cols = num_per_major; | |
315 | num_of_rows = m_majorDim; | |
316 | } | |
317 | ||
318 | int lineheight = GetCharHeight()+2; | |
319 | ||
320 | if ( HasFlag(wxRA_SPECIFY_COLS) || | |
321 | (HasFlag(wxRA_SPECIFY_ROWS) && (num_of_cols > 1)) ) | |
322 | { | |
323 | for (int j = 0; j < num_of_cols; j++) | |
324 | { | |
325 | y = 3; | |
326 | y += lineheight; | |
327 | ||
328 | int max_len = 0; | |
329 | wxList::compatibility_iterator node = m_boxes.Item( j*num_of_rows ); | |
330 | for (int i1 = 0; i1< num_of_rows; i1++) | |
331 | { | |
332 | GtkWidget *button = GTK_WIDGET( node->GetData() ); | |
333 | ||
334 | GtkRequisition req; | |
335 | req.width = 2; | |
336 | req.height = 2; | |
337 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request ) | |
338 | (button, &req ); | |
339 | ||
340 | if (req.width > max_len) max_len = req.width; | |
341 | ||
342 | if ( !justCalc ) | |
343 | gtk_pizza_move( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y ); | |
344 | y += req.height; | |
345 | ||
346 | node = node->GetNext(); | |
347 | if (!node) break; | |
348 | } | |
349 | ||
350 | // we don't know the max_len before | |
351 | ||
352 | node = m_boxes.Item( j*num_of_rows ); | |
353 | for (int i2 = 0; i2< num_of_rows; i2++) | |
354 | { | |
355 | GtkWidget *button = GTK_WIDGET( node->GetData() ); | |
356 | ||
357 | if ( !justCalc ) | |
358 | gtk_pizza_resize( GTK_PIZZA(m_parent->m_wxwindow), button, max_len, lineheight ); | |
359 | ||
360 | node = node->GetNext(); | |
361 | if (!node) break; | |
362 | } | |
363 | ||
364 | if (y > res.y) res.y = y; | |
365 | ||
366 | x += max_len + 2; | |
367 | } | |
368 | ||
369 | res.x = x+4; | |
370 | res.y += 4; | |
371 | } | |
372 | else | |
373 | { | |
374 | int max = 0; | |
375 | ||
376 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
377 | while (node) | |
378 | { | |
379 | GtkWidget *button = GTK_WIDGET( node->GetData() ); | |
380 | ||
381 | GtkRequisition req; | |
382 | req.width = 2; | |
383 | req.height = 2; | |
384 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request ) | |
385 | (button, &req ); | |
386 | ||
387 | if (req.width > max) max = req.width; | |
388 | ||
389 | node = node->GetNext(); | |
390 | } | |
391 | ||
392 | node = m_boxes.GetFirst(); | |
393 | while (node) | |
394 | { | |
395 | GtkWidget *button = GTK_WIDGET( node->GetData() ); | |
396 | ||
397 | if ( !justCalc ) | |
398 | gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y, max, lineheight ); | |
399 | x += max; | |
400 | ||
401 | node = node->GetNext(); | |
402 | } | |
403 | res.x = x+4; | |
404 | res.y = 40; | |
405 | } | |
406 | ||
407 | return res; | |
408 | } | |
409 | ||
410 | bool wxRadioBox::Show( bool show ) | |
411 | { | |
412 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") ); | |
413 | ||
414 | if (!wxControl::Show(show)) | |
415 | { | |
416 | // nothing to do | |
417 | return FALSE; | |
418 | } | |
419 | ||
420 | if ( HasFlag(wxNO_BORDER) ) | |
421 | gtk_widget_hide( m_widget ); | |
422 | ||
423 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
424 | while (node) | |
425 | { | |
426 | GtkWidget *button = GTK_WIDGET( node->GetData() ); | |
427 | ||
428 | if (show) gtk_widget_show( button ); else gtk_widget_hide( button ); | |
429 | ||
430 | node = node->GetNext(); | |
431 | } | |
432 | ||
433 | return TRUE; | |
434 | } | |
435 | ||
436 | int wxRadioBox::FindString( const wxString &find ) const | |
437 | { | |
438 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") ); | |
439 | ||
440 | int count = 0; | |
441 | ||
442 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
443 | while (node) | |
444 | { | |
445 | GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); | |
446 | #ifdef __WXGTK20__ | |
447 | wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); | |
448 | #else | |
449 | wxString str( label->label ); | |
450 | #endif | |
451 | if (find == str) | |
452 | return count; | |
453 | ||
454 | count++; | |
455 | ||
456 | node = node->GetNext(); | |
457 | } | |
458 | ||
459 | return -1; | |
460 | } | |
461 | ||
462 | void wxRadioBox::SetFocus() | |
463 | { | |
464 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); | |
465 | ||
466 | if (m_boxes.GetCount() == 0) return; | |
467 | ||
468 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
469 | while (node) | |
470 | { | |
471 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); | |
472 | if (button->active) | |
473 | { | |
474 | gtk_widget_grab_focus( GTK_WIDGET(button) ); | |
475 | return; | |
476 | } | |
477 | node = node->GetNext(); | |
478 | } | |
479 | } | |
480 | ||
481 | void wxRadioBox::SetSelection( int n ) | |
482 | { | |
483 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); | |
484 | ||
485 | wxList::compatibility_iterator node = m_boxes.Item( n ); | |
486 | ||
487 | wxCHECK_RET( node, wxT("radiobox wrong index") ); | |
488 | ||
489 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); | |
490 | ||
491 | GtkDisableEvents(); | |
492 | ||
493 | gtk_toggle_button_set_active( button, 1 ); | |
494 | ||
495 | GtkEnableEvents(); | |
496 | } | |
497 | ||
498 | int wxRadioBox::GetSelection(void) const | |
499 | { | |
500 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") ); | |
501 | ||
502 | int count = 0; | |
503 | ||
504 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
505 | while (node) | |
506 | { | |
507 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); | |
508 | if (button->active) return count; | |
509 | count++; | |
510 | node = node->GetNext(); | |
511 | } | |
512 | ||
513 | wxFAIL_MSG( wxT("wxRadioBox none selected") ); | |
514 | ||
515 | return -1; | |
516 | } | |
517 | ||
518 | wxString wxRadioBox::GetString( int n ) const | |
519 | { | |
520 | wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") ); | |
521 | ||
522 | wxList::compatibility_iterator node = m_boxes.Item( n ); | |
523 | ||
524 | wxCHECK_MSG( node, wxT(""), wxT("radiobox wrong index") ); | |
525 | ||
526 | GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); | |
527 | ||
528 | #ifdef __WXGTK20__ | |
529 | wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); | |
530 | #else | |
531 | wxString str( label->label ); | |
532 | #endif | |
533 | ||
534 | return str; | |
535 | } | |
536 | ||
537 | void wxRadioBox::SetLabel( const wxString& label ) | |
538 | { | |
539 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); | |
540 | ||
541 | wxControl::SetLabel( label ); | |
542 | ||
543 | gtk_frame_set_label( GTK_FRAME(m_widget), wxGTK_CONV( wxControl::GetLabel() ) ); | |
544 | } | |
545 | ||
546 | void wxRadioBox::SetString( int item, const wxString& label ) | |
547 | { | |
548 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); | |
549 | ||
550 | wxList::compatibility_iterator node = m_boxes.Item( item ); | |
551 | ||
552 | wxCHECK_RET( node, wxT("radiobox wrong index") ); | |
553 | ||
554 | GtkLabel *g_label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); | |
555 | ||
556 | gtk_label_set( g_label, wxGTK_CONV( label ) ); | |
557 | } | |
558 | ||
559 | bool wxRadioBox::Enable( bool enable ) | |
560 | { | |
561 | if ( !wxControl::Enable( enable ) ) | |
562 | return FALSE; | |
563 | ||
564 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
565 | while (node) | |
566 | { | |
567 | GtkButton *button = GTK_BUTTON( node->GetData() ); | |
568 | GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) ); | |
569 | ||
570 | gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); | |
571 | gtk_widget_set_sensitive( GTK_WIDGET(label), enable ); | |
572 | node = node->GetNext(); | |
573 | } | |
574 | ||
575 | return TRUE; | |
576 | } | |
577 | ||
578 | void wxRadioBox::Enable( int item, bool enable ) | |
579 | { | |
580 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); | |
581 | ||
582 | wxList::compatibility_iterator node = m_boxes.Item( item ); | |
583 | ||
584 | wxCHECK_RET( node, wxT("radiobox wrong index") ); | |
585 | ||
586 | GtkButton *button = GTK_BUTTON( node->GetData() ); | |
587 | GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) ); | |
588 | ||
589 | gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); | |
590 | gtk_widget_set_sensitive( GTK_WIDGET(label), enable ); | |
591 | } | |
592 | ||
593 | void wxRadioBox::Show( int item, bool show ) | |
594 | { | |
595 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); | |
596 | ||
597 | wxList::compatibility_iterator node = m_boxes.Item( item ); | |
598 | ||
599 | wxCHECK_RET( node, wxT("radiobox wrong index") ); | |
600 | ||
601 | GtkWidget *button = GTK_WIDGET( node->GetData() ); | |
602 | ||
603 | if (show) | |
604 | gtk_widget_show( button ); | |
605 | else | |
606 | gtk_widget_hide( button ); | |
607 | } | |
608 | ||
609 | wxString wxRadioBox::GetStringSelection() const | |
610 | { | |
611 | wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") ); | |
612 | ||
613 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
614 | while (node) | |
615 | { | |
616 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); | |
617 | if (button->active) | |
618 | { | |
619 | GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); | |
620 | ||
621 | #ifdef __WXGTK20__ | |
622 | wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); | |
623 | #else | |
624 | wxString str( label->label ); | |
625 | #endif | |
626 | return str; | |
627 | } | |
628 | node = node->GetNext(); | |
629 | } | |
630 | ||
631 | wxFAIL_MSG( wxT("wxRadioBox none selected") ); | |
632 | return wxT(""); | |
633 | } | |
634 | ||
635 | bool wxRadioBox::SetStringSelection( const wxString &s ) | |
636 | { | |
637 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") ); | |
638 | ||
639 | int res = FindString( s ); | |
640 | if (res == -1) return FALSE; | |
641 | SetSelection( res ); | |
642 | ||
643 | return TRUE; | |
644 | } | |
645 | ||
646 | int wxRadioBox::GetCount() const | |
647 | { | |
648 | return m_boxes.GetCount(); | |
649 | } | |
650 | ||
651 | int wxRadioBox::GetNumberOfRowsOrCols() const | |
652 | { | |
653 | return 1; | |
654 | } | |
655 | ||
656 | void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) ) | |
657 | { | |
658 | wxFAIL_MSG(wxT("wxRadioBox::SetNumberOfRowsOrCols not implemented.")); | |
659 | } | |
660 | ||
661 | void wxRadioBox::GtkDisableEvents() | |
662 | { | |
663 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
664 | while (node) | |
665 | { | |
666 | gtk_signal_disconnect_by_func( GTK_OBJECT(node->GetData()), | |
667 | GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); | |
668 | ||
669 | node = node->GetNext(); | |
670 | } | |
671 | } | |
672 | ||
673 | void wxRadioBox::GtkEnableEvents() | |
674 | { | |
675 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
676 | while (node) | |
677 | { | |
678 | gtk_signal_connect( GTK_OBJECT(node->GetData()), "clicked", | |
679 | GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); | |
680 | ||
681 | node = node->GetNext(); | |
682 | } | |
683 | } | |
684 | ||
685 | void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style) | |
686 | { | |
687 | gtk_widget_modify_style( m_widget, style ); | |
688 | ||
689 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
690 | while (node) | |
691 | { | |
692 | GtkWidget *widget = GTK_WIDGET( node->GetData() ); | |
693 | ||
694 | gtk_widget_modify_style( widget, style ); | |
695 | gtk_widget_modify_style( BUTTON_CHILD(node->GetData()), style ); | |
696 | ||
697 | node = node->GetNext(); | |
698 | } | |
699 | } | |
700 | ||
701 | #if wxUSE_TOOLTIPS | |
702 | void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip ) | |
703 | { | |
704 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
705 | while (node) | |
706 | { | |
707 | GtkWidget *widget = GTK_WIDGET( node->GetData() ); | |
708 | gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL ); | |
709 | node = node->GetNext(); | |
710 | } | |
711 | } | |
712 | #endif // wxUSE_TOOLTIPS | |
713 | ||
714 | bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window ) | |
715 | { | |
716 | if (window == m_widget->window) return TRUE; | |
717 | ||
718 | wxList::compatibility_iterator node = m_boxes.GetFirst(); | |
719 | while (node) | |
720 | { | |
721 | GtkWidget *button = GTK_WIDGET( node->GetData() ); | |
722 | ||
723 | if (window == button->window) return TRUE; | |
724 | ||
725 | node = node->GetNext(); | |
726 | } | |
727 | ||
728 | return FALSE; | |
729 | } | |
730 | ||
731 | void wxRadioBox::OnInternalIdle() | |
732 | { | |
733 | if ( m_lostFocus ) | |
734 | { | |
735 | m_hasFocus = FALSE; | |
736 | m_lostFocus = FALSE; | |
737 | ||
738 | wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() ); | |
739 | event.SetEventObject( this ); | |
740 | ||
741 | (void)GetEventHandler()->ProcessEvent( event ); | |
742 | } | |
743 | ||
744 | if (g_delayedFocus == this) | |
745 | { | |
746 | if (GTK_WIDGET_REALIZED(m_widget)) | |
747 | { | |
748 | g_delayedFocus = NULL; | |
749 | SetFocus(); | |
750 | } | |
751 | } | |
752 | } | |
753 | ||
754 | // static | |
755 | wxVisualAttributes | |
756 | wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
757 | { | |
758 | wxVisualAttributes attr; | |
759 | GtkWidget* widget = gtk_radio_button_new_with_label(NULL, ""); | |
760 | attr = GetDefaultAttributesFromGTKWidget(widget); | |
761 | gtk_widget_destroy(widget); | |
762 | return attr; | |
763 | } | |
764 | ||
765 | #endif // wxUSE_RADIOBOX | |
766 |