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