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