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