]>
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 | ||
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 | } |
c801d85f | 63 | |
2e0e025e RR |
64 | //----------------------------------------------------------------------------- |
65 | // "key_press_event" | |
66 | //----------------------------------------------------------------------------- | |
67 | ||
68 | static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb ) | |
69 | { | |
70 | if (g_isIdle) | |
71 | wxapp_install_idle_handler(); | |
72 | ||
73 | if (!rb->m_hasVMT) return FALSE; | |
74 | if (g_blockEventsOnDrag) return FALSE; | |
75 | ||
76 | if ((gdk_event->keyval != GDK_Up) && | |
77 | (gdk_event->keyval != GDK_Down) && | |
78 | (gdk_event->keyval != GDK_Left) && | |
79 | (gdk_event->keyval != GDK_Right)) | |
80 | { | |
81 | return FALSE; | |
82 | } | |
2da61056 | 83 | |
222ed1d6 | 84 | wxList::compatibility_iterator node = rb->m_boxes.Find( (wxObject*) widget ); |
2e0e025e RR |
85 | if (!node) |
86 | { | |
87 | return FALSE; | |
88 | } | |
2da61056 | 89 | |
2e0e025e | 90 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); |
2da61056 | 91 | |
2e0e025e RR |
92 | if ((gdk_event->keyval == GDK_Up) || |
93 | (gdk_event->keyval == GDK_Left)) | |
94 | { | |
b1d4dd7a RL |
95 | if (node == rb->m_boxes.GetFirst()) |
96 | node = rb->m_boxes.GetLast(); | |
2da61056 | 97 | else |
b1d4dd7a | 98 | node = node->GetPrevious(); |
2e0e025e RR |
99 | } |
100 | else | |
101 | { | |
b1d4dd7a RL |
102 | if (node == rb->m_boxes.GetLast()) |
103 | node = rb->m_boxes.GetFirst(); | |
2da61056 | 104 | else |
b1d4dd7a | 105 | node = node->GetNext(); |
2e0e025e | 106 | } |
2da61056 | 107 | |
b1d4dd7a | 108 | GtkWidget *button = (GtkWidget*) node->GetData(); |
2da61056 | 109 | |
2e0e025e | 110 | gtk_widget_grab_focus( button ); |
2da61056 | 111 | |
2e0e025e RR |
112 | return TRUE; |
113 | } | |
114 | ||
f6bcfd97 BP |
115 | static gint gtk_radiobutton_focus_in( GtkWidget *widget, |
116 | GdkEvent *WXUNUSED(event), | |
117 | wxRadioBox *win ) | |
118 | { | |
119 | if ( win->m_lostFocus ) | |
120 | { | |
121 | // no, we didn't really lose it | |
122 | win->m_lostFocus = FALSE; | |
123 | } | |
124 | else if ( !win->m_hasFocus ) | |
125 | { | |
126 | win->m_hasFocus = TRUE; | |
127 | ||
128 | wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); | |
129 | event.SetEventObject( win ); | |
130 | ||
131 | // never stop the signal emission, it seems to break the kbd handling | |
132 | // inside the radiobox | |
133 | (void)win->GetEventHandler()->ProcessEvent( event ); | |
134 | } | |
135 | ||
136 | return FALSE; | |
137 | } | |
138 | ||
139 | static gint gtk_radiobutton_focus_out( GtkWidget *widget, | |
140 | GdkEvent *WXUNUSED(event), | |
141 | wxRadioBox *win ) | |
142 | { | |
cc1fcb95 JS |
143 | // wxASSERT_MSG( win->m_hasFocus, _T("got focus out without any focus in?") ); |
144 | // Replace with a warning, else we dump core a lot! | |
145 | // if (!win->m_hasFocus) | |
146 | // wxLogWarning(_T("Radiobox got focus out without any focus in.") ); | |
f6bcfd97 BP |
147 | |
148 | // we might have lost the focus, but may be not - it may have just gone to | |
149 | // another button in the same radiobox, so we'll check for it in the next | |
150 | // idle iteration (leave m_hasFocus == TRUE for now) | |
151 | win->m_lostFocus = TRUE; | |
152 | ||
153 | return FALSE; | |
154 | } | |
155 | ||
b4071e91 RR |
156 | //----------------------------------------------------------------------------- |
157 | // wxRadioBox | |
c801d85f KB |
158 | //----------------------------------------------------------------------------- |
159 | ||
160 | IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl) | |
161 | ||
f6bcfd97 | 162 | void wxRadioBox::Init() |
c801d85f | 163 | { |
f6bcfd97 BP |
164 | m_needParent = TRUE; |
165 | m_acceptsFocus = TRUE; | |
166 | ||
167 | m_hasFocus = | |
168 | m_lostFocus = FALSE; | |
6de97a3b | 169 | } |
c801d85f | 170 | |
584ad2a3 MB |
171 | bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, |
172 | const wxString& title, | |
173 | const wxPoint &pos, const wxSize &size, | |
174 | const wxArrayString& choices, int majorDim, | |
175 | long style, const wxValidator& validator, | |
176 | const wxString &name ) | |
177 | { | |
178 | wxCArrayString chs(choices); | |
179 | ||
180 | return Create( parent, id, title, pos, size, chs.GetCount(), | |
181 | chs.GetStrings(), majorDim, style, validator, name ); | |
182 | } | |
183 | ||
debe6624 | 184 | bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, |
907789a0 | 185 | const wxPoint &pos, const wxSize &size, |
29006414 VZ |
186 | int n, const wxString choices[], int majorDim, |
187 | long style, const wxValidator& validator, | |
188 | const wxString &name ) | |
c801d85f | 189 | { |
4dcaf11a RR |
190 | if (!PreCreation( parent, pos, size ) || |
191 | !CreateBase( parent, id, pos, size, style, validator, name )) | |
192 | { | |
223d09f6 | 193 | wxFAIL_MSG( wxT("wxRadioBox creation failed") ); |
e2762ff0 | 194 | return FALSE; |
4dcaf11a | 195 | } |
6de97a3b | 196 | |
fab591c5 | 197 | m_widget = gtk_frame_new( wxGTK_CONV( title ) ); |
29006414 | 198 | |
5eaac5b5 VZ |
199 | // majorDim may be 0 if all trailing parameters were omitted, so don't |
200 | // assert here but just use the correct value for it | |
201 | m_majorDim = majorDim == 0 ? n : majorDim; | |
29006414 | 202 | |
907789a0 | 203 | GtkRadioButton *m_radio = (GtkRadioButton*) NULL; |
29006414 | 204 | |
26333898 | 205 | wxString label; |
d3b4d113 RR |
206 | GSList *radio_button_group = (GSList *) NULL; |
207 | for (int i = 0; i < n; i++) | |
c801d85f | 208 | { |
26333898 VZ |
209 | if ( i != 0 ) |
210 | radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) ); | |
29006414 | 211 | |
26333898 VZ |
212 | label.Empty(); |
213 | for ( const wxChar *pc = choices[i]; *pc; pc++ ) | |
214 | { | |
223d09f6 | 215 | if ( *pc != wxT('&') ) |
26333898 VZ |
216 | label += *pc; |
217 | } | |
218 | ||
fab591c5 | 219 | m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) ); |
29006414 | 220 | |
2e0e025e RR |
221 | gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event", |
222 | GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this ); | |
2da61056 | 223 | |
d3b4d113 | 224 | m_boxes.Append( (wxObject*) m_radio ); |
29006414 | 225 | |
d3b4d113 | 226 | ConnectWidget( GTK_WIDGET(m_radio) ); |
29006414 | 227 | |
d3b4d113 | 228 | if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); |
29006414 VZ |
229 | |
230 | gtk_signal_connect( GTK_OBJECT(m_radio), "clicked", | |
354aa1e3 | 231 | GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); |
29006414 | 232 | |
f6bcfd97 BP |
233 | gtk_signal_connect( GTK_OBJECT(m_radio), "focus_in_event", |
234 | GTK_SIGNAL_FUNC(gtk_radiobutton_focus_in), (gpointer)this ); | |
235 | ||
236 | gtk_signal_connect( GTK_OBJECT(m_radio), "focus_out_event", | |
237 | GTK_SIGNAL_FUNC(gtk_radiobutton_focus_out), (gpointer)this ); | |
238 | ||
da048e3d | 239 | gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow), |
e3e717ec | 240 | GTK_WIDGET(m_radio), |
f03fc89f | 241 | m_x+10, m_y+10+(i*24), 10, 10 ); |
6de97a3b | 242 | } |
29006414 | 243 | |
db434467 RR |
244 | m_parent->DoAddChild( this ); |
245 | ||
c4ca49cd VZ |
246 | bool wasShown = IsShown(); |
247 | if ( wasShown ) | |
248 | Hide(); // prevent PostCreation() from showing us | |
db434467 | 249 | |
db434467 RR |
250 | SetLabel( title ); |
251 | ||
abdeb9e7 | 252 | PostCreation(size); |
29006414 | 253 | |
c4ca49cd VZ |
254 | if ( wasShown ) |
255 | Show(); | |
29006414 | 256 | |
907789a0 | 257 | return TRUE; |
6de97a3b | 258 | } |
c801d85f | 259 | |
f03fc89f | 260 | wxRadioBox::~wxRadioBox() |
d6d1892b | 261 | { |
222ed1d6 | 262 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
263 | while (node) |
264 | { | |
b1d4dd7a | 265 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
907789a0 | 266 | gtk_widget_destroy( button ); |
b1d4dd7a | 267 | node = node->GetNext(); |
907789a0 | 268 | } |
d6d1892b RR |
269 | } |
270 | ||
54517652 | 271 | void wxRadioBox::DoSetSize( int x, int y, int width, int height, int sizeFlags ) |
3f659fd6 | 272 | { |
54517652 | 273 | wxWindow::DoSetSize( x, y, width, height, sizeFlags ); |
2da61056 | 274 | |
c4ca49cd | 275 | LayoutItems(false); |
d3b4d113 RR |
276 | } |
277 | ||
c4ca49cd | 278 | wxSize wxRadioBox::DoGetBestSize() const |
d3b4d113 | 279 | { |
c4ca49cd | 280 | wxSize size = LayoutItems(true); |
29006414 | 281 | |
c4ca49cd VZ |
282 | GtkRequisition req; |
283 | req.width = 2; | |
284 | req.height = 2; | |
285 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) (m_widget, &req ); | |
286 | if (req.width > size.x) | |
287 | size.x = req.width; | |
e3e717ec | 288 | |
c4ca49cd VZ |
289 | return size; |
290 | } | |
291 | ||
292 | wxSize wxRadioBox::LayoutItems(bool justCalc) const | |
293 | { | |
294 | wxSize res( 0, 0 ); | |
295 | ||
296 | // avoid dividing by 0 below | |
297 | wxCHECK_MSG( m_majorDim, res, wxT("dimension of radiobox should not be 0!") ); | |
e3e717ec | 298 | |
d3b4d113 | 299 | int num_per_major = (m_boxes.GetCount() - 1) / m_majorDim +1; |
29006414 | 300 | |
c4ca49cd VZ |
301 | int x = 7; |
302 | int y = 15; | |
29006414 | 303 | |
e9158f7d RR |
304 | int num_of_cols = 0; |
305 | int num_of_rows = 0; | |
306 | if (HasFlag(wxRA_SPECIFY_COLS)) | |
d3b4d113 | 307 | { |
e9158f7d RR |
308 | num_of_cols = m_majorDim; |
309 | num_of_rows = num_per_major; | |
310 | } | |
311 | else | |
312 | { | |
313 | num_of_cols = num_per_major; | |
314 | num_of_rows = m_majorDim; | |
315 | } | |
b7b7dedc | 316 | |
ff1c71a2 | 317 | int lineheight = GetCharHeight()+2; |
b7b7dedc | 318 | |
e9158f7d RR |
319 | if ( HasFlag(wxRA_SPECIFY_COLS) || |
320 | (HasFlag(wxRA_SPECIFY_ROWS) && (num_of_cols > 1)) ) | |
321 | { | |
322 | for (int j = 0; j < num_of_cols; j++) | |
29006414 | 323 | { |
b7b7dedc RR |
324 | y = 3; |
325 | y += lineheight; | |
29006414 | 326 | |
d3b4d113 | 327 | int max_len = 0; |
222ed1d6 | 328 | wxList::compatibility_iterator node = m_boxes.Item( j*num_of_rows ); |
e9158f7d | 329 | for (int i1 = 0; i1< num_of_rows; i1++) |
29006414 | 330 | { |
b1d4dd7a | 331 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
2da61056 | 332 | |
165b6ee0 VS |
333 | GtkRequisition req; |
334 | req.width = 2; | |
335 | req.height = 2; | |
2afa14f2 | 336 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request ) |
165b6ee0 | 337 | (button, &req ); |
ff1c71a2 | 338 | |
165b6ee0 | 339 | if (req.width > max_len) max_len = req.width; |
29006414 | 340 | |
c4ca49cd VZ |
341 | if ( !justCalc ) |
342 | gtk_pizza_move( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y ); | |
165b6ee0 | 343 | y += req.height; |
29006414 | 344 | |
b1d4dd7a | 345 | node = node->GetNext(); |
29006414 VZ |
346 | if (!node) break; |
347 | } | |
348 | ||
349 | // we don't know the max_len before | |
350 | ||
b1d4dd7a | 351 | node = m_boxes.Item( j*num_of_rows ); |
e9158f7d | 352 | for (int i2 = 0; i2< num_of_rows; i2++) |
29006414 | 353 | { |
b1d4dd7a | 354 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
29006414 | 355 | |
c4ca49cd VZ |
356 | if ( !justCalc ) |
357 | gtk_pizza_resize( GTK_PIZZA(m_parent->m_wxwindow), button, max_len, lineheight ); | |
29006414 | 358 | |
b1d4dd7a | 359 | node = node->GetNext(); |
29006414 VZ |
360 | if (!node) break; |
361 | } | |
362 | ||
363 | if (y > res.y) res.y = y; | |
364 | ||
365 | x += max_len + 2; | |
d3b4d113 | 366 | } |
29006414 VZ |
367 | |
368 | res.x = x+4; | |
165b6ee0 | 369 | res.y += 4; |
e5403d7c | 370 | } |
d3b4d113 | 371 | else |
e5403d7c | 372 | { |
d3b4d113 RR |
373 | int max = 0; |
374 | ||
222ed1d6 | 375 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
d3b4d113 RR |
376 | while (node) |
377 | { | |
b1d4dd7a | 378 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
165b6ee0 VS |
379 | |
380 | GtkRequisition req; | |
381 | req.width = 2; | |
382 | req.height = 2; | |
2afa14f2 | 383 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(button) )->size_request ) |
165b6ee0 | 384 | (button, &req ); |
29006414 | 385 | |
165b6ee0 | 386 | if (req.width > max) max = req.width; |
29006414 | 387 | |
b1d4dd7a | 388 | node = node->GetNext(); |
d3b4d113 | 389 | } |
29006414 | 390 | |
b1d4dd7a | 391 | node = m_boxes.GetFirst(); |
d3b4d113 RR |
392 | while (node) |
393 | { | |
b1d4dd7a | 394 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
29006414 | 395 | |
c4ca49cd VZ |
396 | if ( !justCalc ) |
397 | gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y, max, lineheight ); | |
d3b4d113 | 398 | x += max; |
29006414 | 399 | |
b1d4dd7a | 400 | node = node->GetNext(); |
d3b4d113 | 401 | } |
29006414 | 402 | res.x = x+4; |
3417c2cd | 403 | res.y = 40; |
e5403d7c | 404 | } |
29006414 | 405 | |
d3b4d113 | 406 | return res; |
3f659fd6 RR |
407 | } |
408 | ||
debe6624 | 409 | bool wxRadioBox::Show( bool show ) |
c801d85f | 410 | { |
223d09f6 | 411 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") ); |
29006414 | 412 | |
f96ac56a RR |
413 | if (!wxControl::Show(show)) |
414 | { | |
415 | // nothing to do | |
416 | return FALSE; | |
417 | } | |
c801d85f | 418 | |
c4ca49cd | 419 | if ( HasFlag(wxNO_BORDER) ) |
b0351fc9 | 420 | gtk_widget_hide( m_widget ); |
e3e717ec | 421 | |
222ed1d6 | 422 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
423 | while (node) |
424 | { | |
b1d4dd7a | 425 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
29006414 | 426 | |
907789a0 | 427 | if (show) gtk_widget_show( button ); else gtk_widget_hide( button ); |
29006414 | 428 | |
b1d4dd7a | 429 | node = node->GetNext(); |
907789a0 | 430 | } |
c801d85f | 431 | |
907789a0 | 432 | return TRUE; |
6de97a3b | 433 | } |
c801d85f | 434 | |
2b5f62a0 | 435 | int wxRadioBox::FindString( const wxString &find ) const |
c801d85f | 436 | { |
223d09f6 | 437 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") ); |
29006414 | 438 | |
907789a0 | 439 | int count = 0; |
29006414 | 440 | |
222ed1d6 | 441 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
442 | while (node) |
443 | { | |
b1d4dd7a | 444 | GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); |
2b5f62a0 VZ |
445 | #ifdef __WXGTK20__ |
446 | wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); | |
447 | #else | |
448 | wxString str( label->label ); | |
449 | #endif | |
450 | if (find == str) | |
9e691f46 | 451 | return count; |
29006414 | 452 | |
907789a0 | 453 | count++; |
29006414 | 454 | |
b1d4dd7a | 455 | node = node->GetNext(); |
907789a0 | 456 | } |
29006414 | 457 | |
907789a0 | 458 | return -1; |
6de97a3b | 459 | } |
c801d85f | 460 | |
b292e2f5 RR |
461 | void wxRadioBox::SetFocus() |
462 | { | |
223d09f6 | 463 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 464 | |
b292e2f5 | 465 | if (m_boxes.GetCount() == 0) return; |
29006414 | 466 | |
222ed1d6 | 467 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
b292e2f5 RR |
468 | while (node) |
469 | { | |
b1d4dd7a | 470 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); |
b292e2f5 | 471 | if (button->active) |
29006414 | 472 | { |
b292e2f5 | 473 | gtk_widget_grab_focus( GTK_WIDGET(button) ); |
29006414 VZ |
474 | return; |
475 | } | |
b1d4dd7a | 476 | node = node->GetNext(); |
b292e2f5 | 477 | } |
b292e2f5 RR |
478 | } |
479 | ||
47908e25 | 480 | void wxRadioBox::SetSelection( int n ) |
c801d85f | 481 | { |
223d09f6 | 482 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 483 | |
222ed1d6 | 484 | wxList::compatibility_iterator node = m_boxes.Item( n ); |
29006414 | 485 | |
223d09f6 | 486 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 487 | |
b1d4dd7a | 488 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); |
29006414 | 489 | |
72a7edf0 | 490 | GtkDisableEvents(); |
2da61056 | 491 | |
e2762ff0 | 492 | gtk_toggle_button_set_active( button, 1 ); |
2da61056 | 493 | |
72a7edf0 | 494 | GtkEnableEvents(); |
6de97a3b | 495 | } |
c801d85f KB |
496 | |
497 | int wxRadioBox::GetSelection(void) const | |
498 | { | |
223d09f6 | 499 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") ); |
29006414 | 500 | |
907789a0 | 501 | int count = 0; |
29006414 | 502 | |
222ed1d6 | 503 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
504 | while (node) |
505 | { | |
b1d4dd7a | 506 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); |
907789a0 RR |
507 | if (button->active) return count; |
508 | count++; | |
b1d4dd7a | 509 | node = node->GetNext(); |
907789a0 | 510 | } |
29006414 | 511 | |
223d09f6 | 512 | wxFAIL_MSG( wxT("wxRadioBox none selected") ); |
29006414 | 513 | |
907789a0 | 514 | return -1; |
6de97a3b | 515 | } |
c801d85f | 516 | |
47908e25 | 517 | wxString wxRadioBox::GetString( int n ) const |
c801d85f | 518 | { |
223d09f6 | 519 | wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") ); |
29006414 | 520 | |
222ed1d6 | 521 | wxList::compatibility_iterator node = m_boxes.Item( n ); |
29006414 | 522 | |
223d09f6 | 523 | wxCHECK_MSG( node, wxT(""), wxT("radiobox wrong index") ); |
29006414 | 524 | |
b1d4dd7a | 525 | GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); |
29006414 | 526 | |
2b5f62a0 VZ |
527 | #ifdef __WXGTK20__ |
528 | wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); | |
529 | #else | |
530 | wxString str( label->label ); | |
531 | #endif | |
532 | ||
533 | return str; | |
6de97a3b | 534 | } |
c801d85f | 535 | |
d3904ceb | 536 | void wxRadioBox::SetLabel( const wxString& label ) |
c801d85f | 537 | { |
223d09f6 | 538 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 539 | |
907789a0 | 540 | wxControl::SetLabel( label ); |
29006414 | 541 | |
fab591c5 | 542 | gtk_frame_set_label( GTK_FRAME(m_widget), wxGTK_CONV( wxControl::GetLabel() ) ); |
6de97a3b | 543 | } |
c801d85f | 544 | |
2da61056 | 545 | void wxRadioBox::SetString( int item, const wxString& label ) |
c801d85f | 546 | { |
223d09f6 | 547 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 548 | |
222ed1d6 | 549 | wxList::compatibility_iterator node = m_boxes.Item( item ); |
29006414 | 550 | |
223d09f6 | 551 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 552 | |
b1d4dd7a | 553 | GtkLabel *g_label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); |
29006414 | 554 | |
fab591c5 | 555 | gtk_label_set( g_label, wxGTK_CONV( label ) ); |
6de97a3b | 556 | } |
c801d85f | 557 | |
f03fc89f | 558 | bool wxRadioBox::Enable( bool enable ) |
c801d85f | 559 | { |
f03fc89f VZ |
560 | if ( !wxControl::Enable( enable ) ) |
561 | return FALSE; | |
29006414 | 562 | |
222ed1d6 | 563 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
564 | while (node) |
565 | { | |
b1d4dd7a | 566 | GtkButton *button = GTK_BUTTON( node->GetData() ); |
9e691f46 VZ |
567 | GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) ); |
568 | ||
907789a0 | 569 | gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); |
9e691f46 | 570 | gtk_widget_set_sensitive( GTK_WIDGET(label), enable ); |
b1d4dd7a | 571 | node = node->GetNext(); |
907789a0 | 572 | } |
f03fc89f VZ |
573 | |
574 | return TRUE; | |
6de97a3b | 575 | } |
c801d85f | 576 | |
d3904ceb | 577 | void wxRadioBox::Enable( int item, bool enable ) |
c801d85f | 578 | { |
223d09f6 | 579 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 580 | |
222ed1d6 | 581 | wxList::compatibility_iterator node = m_boxes.Item( item ); |
29006414 | 582 | |
223d09f6 | 583 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 584 | |
b1d4dd7a | 585 | GtkButton *button = GTK_BUTTON( node->GetData() ); |
9e691f46 VZ |
586 | GtkLabel *label = GTK_LABEL( BUTTON_CHILD(button) ); |
587 | ||
907789a0 | 588 | gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); |
9e691f46 | 589 | gtk_widget_set_sensitive( GTK_WIDGET(label), enable ); |
6de97a3b | 590 | } |
c801d85f | 591 | |
d3904ceb | 592 | void wxRadioBox::Show( int item, bool show ) |
c801d85f | 593 | { |
223d09f6 | 594 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 595 | |
222ed1d6 | 596 | wxList::compatibility_iterator node = m_boxes.Item( item ); |
29006414 | 597 | |
223d09f6 | 598 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 599 | |
b1d4dd7a | 600 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
c801d85f | 601 | |
907789a0 RR |
602 | if (show) |
603 | gtk_widget_show( button ); | |
604 | else | |
605 | gtk_widget_hide( button ); | |
6de97a3b | 606 | } |
c801d85f | 607 | |
9c884972 | 608 | wxString wxRadioBox::GetStringSelection() const |
c801d85f | 609 | { |
223d09f6 | 610 | wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") ); |
29006414 | 611 | |
222ed1d6 | 612 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 | 613 | while (node) |
c801d85f | 614 | { |
b1d4dd7a | 615 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); |
907789a0 RR |
616 | if (button->active) |
617 | { | |
b1d4dd7a | 618 | GtkLabel *label = GTK_LABEL( BUTTON_CHILD(node->GetData()) ); |
9e691f46 | 619 | |
2b5f62a0 VZ |
620 | #ifdef __WXGTK20__ |
621 | wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); | |
622 | #else | |
623 | wxString str( label->label ); | |
624 | #endif | |
625 | return str; | |
907789a0 | 626 | } |
b1d4dd7a | 627 | node = node->GetNext(); |
6de97a3b | 628 | } |
29006414 | 629 | |
223d09f6 KB |
630 | wxFAIL_MSG( wxT("wxRadioBox none selected") ); |
631 | return wxT(""); | |
6de97a3b | 632 | } |
c801d85f | 633 | |
907789a0 | 634 | bool wxRadioBox::SetStringSelection( const wxString &s ) |
c801d85f | 635 | { |
223d09f6 | 636 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") ); |
29006414 | 637 | |
907789a0 RR |
638 | int res = FindString( s ); |
639 | if (res == -1) return FALSE; | |
640 | SetSelection( res ); | |
29006414 | 641 | |
907789a0 | 642 | return TRUE; |
6de97a3b | 643 | } |
c801d85f | 644 | |
2da61056 | 645 | int wxRadioBox::GetCount() const |
c801d85f | 646 | { |
b1d4dd7a | 647 | return m_boxes.GetCount(); |
6de97a3b | 648 | } |
c801d85f | 649 | |
9c884972 | 650 | int wxRadioBox::GetNumberOfRowsOrCols() const |
c801d85f | 651 | { |
907789a0 | 652 | return 1; |
6de97a3b | 653 | } |
c801d85f | 654 | |
debe6624 | 655 | void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) ) |
c801d85f | 656 | { |
223d09f6 | 657 | wxFAIL_MSG(wxT("wxRadioBox::SetNumberOfRowsOrCols not implemented.")); |
6de97a3b | 658 | } |
c801d85f | 659 | |
72a7edf0 | 660 | void wxRadioBox::GtkDisableEvents() |
953704c1 | 661 | { |
222ed1d6 | 662 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
953704c1 RR |
663 | while (node) |
664 | { | |
b1d4dd7a | 665 | gtk_signal_disconnect_by_func( GTK_OBJECT(node->GetData()), |
953704c1 RR |
666 | GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); |
667 | ||
b1d4dd7a | 668 | node = node->GetNext(); |
953704c1 RR |
669 | } |
670 | } | |
671 | ||
72a7edf0 | 672 | void wxRadioBox::GtkEnableEvents() |
953704c1 | 673 | { |
222ed1d6 | 674 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
953704c1 RR |
675 | while (node) |
676 | { | |
b1d4dd7a | 677 | gtk_signal_connect( GTK_OBJECT(node->GetData()), "clicked", |
953704c1 RR |
678 | GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); |
679 | ||
b1d4dd7a | 680 | node = node->GetNext(); |
953704c1 RR |
681 | } |
682 | } | |
683 | ||
58614078 | 684 | void wxRadioBox::ApplyWidgetStyle() |
868a2826 | 685 | { |
907789a0 | 686 | SetWidgetStyle(); |
29006414 | 687 | |
907789a0 | 688 | gtk_widget_set_style( m_widget, m_widgetStyle ); |
29006414 | 689 | |
222ed1d6 | 690 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
691 | while (node) |
692 | { | |
b1d4dd7a | 693 | GtkWidget *widget = GTK_WIDGET( node->GetData() ); |
907789a0 | 694 | gtk_widget_set_style( widget, m_widgetStyle ); |
29006414 | 695 | |
b1d4dd7a | 696 | gtk_widget_set_style( BUTTON_CHILD(node->GetData()), m_widgetStyle ); |
29006414 | 697 | |
b1d4dd7a | 698 | node = node->GetNext(); |
907789a0 | 699 | } |
868a2826 | 700 | } |
b4071e91 | 701 | |
72a7edf0 RR |
702 | #if wxUSE_TOOLTIPS |
703 | void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip ) | |
704 | { | |
222ed1d6 | 705 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
72a7edf0 RR |
706 | while (node) |
707 | { | |
b1d4dd7a | 708 | GtkWidget *widget = GTK_WIDGET( node->GetData() ); |
72a7edf0 | 709 | gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL ); |
b1d4dd7a | 710 | node = node->GetNext(); |
72a7edf0 RR |
711 | } |
712 | } | |
713 | #endif // wxUSE_TOOLTIPS | |
714 | ||
b4071e91 RR |
715 | bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window ) |
716 | { | |
907789a0 | 717 | if (window == m_widget->window) return TRUE; |
29006414 | 718 | |
222ed1d6 | 719 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
720 | while (node) |
721 | { | |
b1d4dd7a | 722 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
29006414 | 723 | |
907789a0 | 724 | if (window == button->window) return TRUE; |
29006414 | 725 | |
b1d4dd7a | 726 | node = node->GetNext(); |
907789a0 | 727 | } |
29006414 | 728 | |
907789a0 | 729 | return FALSE; |
b4071e91 | 730 | } |
dcf924a3 | 731 | |
f6bcfd97 BP |
732 | void wxRadioBox::OnInternalIdle() |
733 | { | |
734 | if ( m_lostFocus ) | |
735 | { | |
736 | m_hasFocus = FALSE; | |
737 | m_lostFocus = FALSE; | |
738 | ||
739 | wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() ); | |
740 | event.SetEventObject( this ); | |
741 | ||
742 | (void)GetEventHandler()->ProcessEvent( event ); | |
743 | } | |
d7fa7eaa RR |
744 | |
745 | if (g_delayedFocus == this) | |
746 | { | |
747 | if (GTK_WIDGET_REALIZED(m_widget)) | |
748 | { | |
749 | g_delayedFocus = NULL; | |
750 | SetFocus(); | |
751 | } | |
752 | } | |
f6bcfd97 BP |
753 | } |
754 | ||
9d522606 RD |
755 | // static |
756 | wxVisualAttributes | |
757 | wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
758 | { | |
759 | wxVisualAttributes attr; | |
760 | GtkWidget* widget = gtk_radio_button_new_with_label(NULL, ""); | |
761 | attr = GetDefaultAttributesFromGTKWidget(widget); | |
762 | gtk_widget_destroy(widget); | |
763 | return attr; | |
764 | } | |
765 | ||
f6bcfd97 BP |
766 | #endif // wxUSE_RADIOBOX |
767 |