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