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