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