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