]>
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 | ||
c801d85f KB |
17 | #include "wx/dialog.h" |
18 | #include "wx/frame.h" | |
cc1fcb95 | 19 | #include "wx/log.h" |
83624f79 | 20 | |
9e691f46 | 21 | #include "wx/gtk/private.h" |
3f26799e RR |
22 | #include <gdk/gdkkeysyms.h> |
23 | ||
c801d85f KB |
24 | #include "wx/gtk/win_gtk.h" |
25 | ||
acfd422a RR |
26 | //----------------------------------------------------------------------------- |
27 | // idle system | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
30 | extern void wxapp_install_idle_handler(); | |
31 | extern bool g_isIdle; | |
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 | ||
5985c07c RR |
75 | if ( ((gdk_event->keyval == GDK_Tab) || |
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 | |
222ed1d6 | 97 | wxList::compatibility_iterator node = rb->m_boxes.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 | { | |
b1d4dd7a RL |
108 | if (node == rb->m_boxes.GetFirst()) |
109 | node = rb->m_boxes.GetLast(); | |
2da61056 | 110 | else |
b1d4dd7a | 111 | node = node->GetPrevious(); |
2e0e025e RR |
112 | } |
113 | else | |
114 | { | |
b1d4dd7a RL |
115 | if (node == rb->m_boxes.GetLast()) |
116 | node = rb->m_boxes.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 | |
b2ff89d6 VZ |
215 | m_widget = gtk_frame_new(NULL); |
216 | 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 | |
27c78e45 VZ |
223 | int num_of_cols = GetColumnCount(); |
224 | int num_of_rows = GetRowCount(); | |
11e62fe6 | 225 | |
907789a0 | 226 | GtkRadioButton *m_radio = (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 RR |
235 | GSList *radio_button_group = (GSList *) NULL; |
236 | for (int i = 0; i < n; i++) | |
c801d85f | 237 | { |
26333898 | 238 | if ( i != 0 ) |
78e017d8 | 239 | radio_button_group = gtk_radio_button_get_group( GTK_RADIO_BUTTON(m_radio) ); |
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 | ||
fab591c5 | 248 | m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) ); |
8017ee9b | 249 | gtk_widget_show( GTK_WIDGET(m_radio) ); |
29006414 | 250 | |
9fa72bd2 MR |
251 | g_signal_connect (m_radio, "key_press_event", |
252 | G_CALLBACK (gtk_radiobox_keypress_callback), this); | |
2da61056 | 253 | |
d3b4d113 | 254 | m_boxes.Append( (wxObject*) m_radio ); |
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; | |
11e62fe6 WS |
262 | gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(m_radio), left, right, top, bottom, |
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; | |
11e62fe6 WS |
271 | gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(m_radio), left, right, top, bottom, |
272 | GTK_FILL, GTK_FILL, 1, 1 ); | |
8017ee9b RR |
273 | } |
274 | ||
d3b4d113 | 275 | ConnectWidget( GTK_WIDGET(m_radio) ); |
29006414 | 276 | |
e343da37 MR |
277 | if (!i) |
278 | gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(m_radio), TRUE ); | |
29006414 | 279 | |
9fa72bd2 MR |
280 | g_signal_connect (m_radio, "clicked", |
281 | G_CALLBACK (gtk_radiobutton_clicked_callback), this); | |
282 | g_signal_connect (m_radio, "focus_in_event", | |
283 | G_CALLBACK (gtk_radiobutton_focus_in), this); | |
284 | g_signal_connect (m_radio, "focus_out_event", | |
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 | { |
222ed1d6 | 297 | wxList::compatibility_iterator node = m_boxes.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 | |
222ed1d6 | 319 | wxList::compatibility_iterator node = m_boxes.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 | |
b292e2f5 | 339 | if (m_boxes.GetCount() == 0) return; |
29006414 | 340 | |
222ed1d6 | 341 | wxList::compatibility_iterator node = m_boxes.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 | |
222ed1d6 | 358 | wxList::compatibility_iterator node = m_boxes.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 | |
222ed1d6 | 377 | wxList::compatibility_iterator node = m_boxes.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 | |
47908e25 | 391 | wxString wxRadioBox::GetString( int n ) const |
c801d85f | 392 | { |
1a87edf2 | 393 | wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") ); |
29006414 | 394 | |
222ed1d6 | 395 | wxList::compatibility_iterator node = m_boxes.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 | |
2da61056 | 413 | void wxRadioBox::SetString( int item, const wxString& label ) |
c801d85f | 414 | { |
223d09f6 | 415 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 416 | |
222ed1d6 | 417 | wxList::compatibility_iterator node = m_boxes.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 | |
222ed1d6 | 431 | wxList::compatibility_iterator node = m_boxes.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 | |
1a87edf2 | 445 | bool wxRadioBox::Enable( int item, bool enable ) |
c801d85f | 446 | { |
1a87edf2 | 447 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 448 | |
222ed1d6 | 449 | wxList::compatibility_iterator node = m_boxes.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 | |
27c78e45 VZ |
462 | bool wxRadioBox::IsItemEnabled(int item) const |
463 | { | |
464 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); | |
465 | ||
466 | wxList::compatibility_iterator node = m_boxes.Item( item ); | |
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 | ||
789f6795 | 477 | bool wxRadioBox::Show( int item, bool show ) |
c801d85f | 478 | { |
789f6795 | 479 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 480 | |
222ed1d6 | 481 | wxList::compatibility_iterator node = m_boxes.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 | |
27c78e45 | 495 | bool wxRadioBox::IsItemShown(int item) const |
c801d85f | 496 | { |
27c78e45 | 497 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 498 | |
27c78e45 | 499 | wxList::compatibility_iterator node = m_boxes.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 | |
2da61056 | 508 | int wxRadioBox::GetCount() const |
c801d85f | 509 | { |
b1d4dd7a | 510 | return m_boxes.GetCount(); |
6de97a3b | 511 | } |
c801d85f | 512 | |
72a7edf0 | 513 | void wxRadioBox::GtkDisableEvents() |
953704c1 | 514 | { |
222ed1d6 | 515 | wxList::compatibility_iterator node = m_boxes.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 | { |
222ed1d6 | 528 | wxList::compatibility_iterator node = m_boxes.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 | { |
f40fdaa3 | 540 | gtk_widget_modify_style( m_widget, style ); |
81e88f5b | 541 | gtk_widget_modify_style(GTK_FRAME(m_widget)->label_widget, style); |
81e88f5b | 542 | |
222ed1d6 | 543 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
544 | while (node) |
545 | { | |
b1d4dd7a | 546 | GtkWidget *widget = GTK_WIDGET( node->GetData() ); |
29006414 | 547 | |
f40fdaa3 | 548 | gtk_widget_modify_style( widget, style ); |
afa7bd1e | 549 | gtk_widget_modify_style(GTK_BIN(widget)->child, style); |
29006414 | 550 | |
b1d4dd7a | 551 | node = node->GetNext(); |
907789a0 | 552 | } |
868a2826 | 553 | } |
b4071e91 | 554 | |
72a7edf0 RR |
555 | #if wxUSE_TOOLTIPS |
556 | void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip ) | |
557 | { | |
222ed1d6 | 558 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
72a7edf0 RR |
559 | while (node) |
560 | { | |
b1d4dd7a | 561 | GtkWidget *widget = GTK_WIDGET( node->GetData() ); |
72a7edf0 | 562 | gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL ); |
b1d4dd7a | 563 | node = node->GetNext(); |
72a7edf0 RR |
564 | } |
565 | } | |
566 | #endif // wxUSE_TOOLTIPS | |
567 | ||
b4071e91 RR |
568 | bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window ) |
569 | { | |
27c78e45 VZ |
570 | if (window == m_widget->window) |
571 | return true; | |
29006414 | 572 | |
222ed1d6 | 573 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
574 | while (node) |
575 | { | |
b1d4dd7a | 576 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
29006414 | 577 | |
27c78e45 VZ |
578 | if (window == button->window) |
579 | return true; | |
29006414 | 580 | |
b1d4dd7a | 581 | node = node->GetNext(); |
907789a0 | 582 | } |
29006414 | 583 | |
b4efc9b9 | 584 | return false; |
b4071e91 | 585 | } |
dcf924a3 | 586 | |
f6bcfd97 BP |
587 | void wxRadioBox::OnInternalIdle() |
588 | { | |
589 | if ( m_lostFocus ) | |
590 | { | |
b4efc9b9 WS |
591 | m_hasFocus = false; |
592 | m_lostFocus = false; | |
f6bcfd97 BP |
593 | |
594 | wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() ); | |
595 | event.SetEventObject( this ); | |
596 | ||
597 | (void)GetEventHandler()->ProcessEvent( event ); | |
598 | } | |
d7fa7eaa RR |
599 | |
600 | if (g_delayedFocus == this) | |
601 | { | |
602 | if (GTK_WIDGET_REALIZED(m_widget)) | |
603 | { | |
604 | g_delayedFocus = NULL; | |
605 | SetFocus(); | |
606 | } | |
607 | } | |
f6bcfd97 BP |
608 | } |
609 | ||
9d522606 RD |
610 | // static |
611 | wxVisualAttributes | |
612 | wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
613 | { | |
614 | wxVisualAttributes attr; | |
bc0eb46c VS |
615 | // NB: we need toplevel window so that GTK+ can find the right style |
616 | GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
9d522606 | 617 | GtkWidget* widget = gtk_radio_button_new_with_label(NULL, ""); |
bc0eb46c | 618 | gtk_container_add(GTK_CONTAINER(wnd), widget); |
9d522606 | 619 | attr = GetDefaultAttributesFromGTKWidget(widget); |
bc0eb46c | 620 | gtk_widget_destroy(wnd); |
9d522606 RD |
621 | return attr; |
622 | } | |
623 | ||
f6bcfd97 | 624 | #endif // wxUSE_RADIOBOX |