]>
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 | ||
14 | #include "wx/radiobox.h" | |
dcf924a3 RR |
15 | |
16 | #if wxUSE_RADIOBOX | |
17 | ||
c801d85f KB |
18 | #include "wx/dialog.h" |
19 | #include "wx/frame.h" | |
83624f79 | 20 | |
3f26799e RR |
21 | #include <gdk/gdk.h> |
22 | #include <gtk/gtk.h> | |
23 | #include <gdk/gdkkeysyms.h> | |
24 | ||
c801d85f KB |
25 | #include "wx/gtk/win_gtk.h" |
26 | ||
acfd422a RR |
27 | //----------------------------------------------------------------------------- |
28 | // idle system | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | extern void wxapp_install_idle_handler(); | |
32 | extern bool g_isIdle; | |
33 | ||
66bd6b93 RR |
34 | //----------------------------------------------------------------------------- |
35 | // data | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
69ffe1d2 | 38 | extern bool g_blockEventsOnDrag; |
66bd6b93 | 39 | |
c801d85f | 40 | //----------------------------------------------------------------------------- |
b4071e91 | 41 | // "clicked" |
c801d85f KB |
42 | //----------------------------------------------------------------------------- |
43 | ||
66bd6b93 | 44 | static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRadioBox *rb ) |
c801d85f | 45 | { |
acfd422a RR |
46 | if (g_isIdle) wxapp_install_idle_handler(); |
47 | ||
a2053b27 | 48 | if (!rb->m_hasVMT) return; |
907789a0 | 49 | if (g_blockEventsOnDrag) return; |
29006414 | 50 | |
907789a0 RR |
51 | if (rb->m_alreadySent) |
52 | { | |
53 | rb->m_alreadySent = FALSE; | |
54 | return; | |
55 | } | |
47908e25 | 56 | |
907789a0 | 57 | rb->m_alreadySent = TRUE; |
29006414 | 58 | |
907789a0 RR |
59 | wxCommandEvent event( wxEVT_COMMAND_RADIOBOX_SELECTED, rb->GetId() ); |
60 | event.SetInt( rb->GetSelection() ); | |
29006414 | 61 | event.SetString( rb->GetStringSelection() ); |
907789a0 RR |
62 | event.SetEventObject( rb ); |
63 | rb->GetEventHandler()->ProcessEvent(event); | |
6de97a3b | 64 | } |
c801d85f | 65 | |
2e0e025e RR |
66 | //----------------------------------------------------------------------------- |
67 | // "key_press_event" | |
68 | //----------------------------------------------------------------------------- | |
69 | ||
70 | static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb ) | |
71 | { | |
72 | if (g_isIdle) | |
73 | wxapp_install_idle_handler(); | |
74 | ||
75 | if (!rb->m_hasVMT) return FALSE; | |
76 | if (g_blockEventsOnDrag) return FALSE; | |
77 | ||
78 | if ((gdk_event->keyval != GDK_Up) && | |
79 | (gdk_event->keyval != GDK_Down) && | |
80 | (gdk_event->keyval != GDK_Left) && | |
81 | (gdk_event->keyval != GDK_Right)) | |
82 | { | |
83 | return FALSE; | |
84 | } | |
85 | ||
86 | wxNode *node = rb->m_boxes.Find( (wxObject*) widget ); | |
87 | if (!node) | |
88 | { | |
89 | return FALSE; | |
90 | } | |
91 | ||
92 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); | |
93 | ||
94 | if ((gdk_event->keyval == GDK_Up) || | |
95 | (gdk_event->keyval == GDK_Left)) | |
96 | { | |
97 | if (node == rb->m_boxes.First()) | |
98 | node = rb->m_boxes.Last(); | |
99 | else | |
100 | node = node->Previous(); | |
101 | } | |
102 | else | |
103 | { | |
104 | if (node == rb->m_boxes.Last()) | |
105 | node = rb->m_boxes.First(); | |
106 | else | |
107 | node = node->Next(); | |
108 | } | |
109 | ||
110 | GtkWidget *button = (GtkWidget*) node->Data(); | |
111 | ||
112 | gtk_widget_grab_focus( button ); | |
113 | ||
114 | return TRUE; | |
115 | } | |
116 | ||
b4071e91 RR |
117 | //----------------------------------------------------------------------------- |
118 | // wxRadioBox | |
c801d85f KB |
119 | //----------------------------------------------------------------------------- |
120 | ||
121 | IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl) | |
122 | ||
f03fc89f | 123 | wxRadioBox::wxRadioBox() |
c801d85f | 124 | { |
6de97a3b | 125 | } |
c801d85f | 126 | |
debe6624 | 127 | bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, |
907789a0 | 128 | const wxPoint &pos, const wxSize &size, |
29006414 VZ |
129 | int n, const wxString choices[], int majorDim, |
130 | long style, const wxValidator& validator, | |
131 | const wxString &name ) | |
c801d85f | 132 | { |
907789a0 RR |
133 | m_alreadySent = FALSE; |
134 | m_needParent = TRUE; | |
b292e2f5 | 135 | m_acceptsFocus = TRUE; |
29006414 | 136 | |
4dcaf11a RR |
137 | if (!PreCreation( parent, pos, size ) || |
138 | !CreateBase( parent, id, pos, size, style, validator, name )) | |
139 | { | |
223d09f6 | 140 | wxFAIL_MSG( wxT("wxRadioBox creation failed") ); |
4dcaf11a RR |
141 | return FALSE; |
142 | } | |
6de97a3b | 143 | |
b019151f | 144 | m_widget = gtk_frame_new( title.mbc_str() ); |
29006414 | 145 | |
d3b4d113 | 146 | m_majorDim = majorDim; |
29006414 | 147 | |
907789a0 | 148 | GtkRadioButton *m_radio = (GtkRadioButton*) NULL; |
29006414 | 149 | |
26333898 | 150 | wxString label; |
d3b4d113 RR |
151 | GSList *radio_button_group = (GSList *) NULL; |
152 | for (int i = 0; i < n; i++) | |
c801d85f | 153 | { |
26333898 VZ |
154 | if ( i != 0 ) |
155 | radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) ); | |
29006414 | 156 | |
26333898 VZ |
157 | label.Empty(); |
158 | for ( const wxChar *pc = choices[i]; *pc; pc++ ) | |
159 | { | |
223d09f6 | 160 | if ( *pc != wxT('&') ) |
26333898 VZ |
161 | label += *pc; |
162 | } | |
163 | ||
164 | m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, label.mbc_str() ) ); | |
29006414 | 165 | |
2e0e025e RR |
166 | gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event", |
167 | GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this ); | |
168 | ||
d3b4d113 | 169 | m_boxes.Append( (wxObject*) m_radio ); |
29006414 | 170 | |
d3b4d113 | 171 | ConnectWidget( GTK_WIDGET(m_radio) ); |
29006414 | 172 | |
d3b4d113 | 173 | if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); |
29006414 VZ |
174 | |
175 | gtk_signal_connect( GTK_OBJECT(m_radio), "clicked", | |
354aa1e3 | 176 | GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); |
29006414 | 177 | |
da048e3d | 178 | gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow), |
e3e717ec | 179 | GTK_WIDGET(m_radio), |
f03fc89f | 180 | m_x+10, m_y+10+(i*24), 10, 10 ); |
6de97a3b | 181 | } |
29006414 | 182 | |
db434467 RR |
183 | m_parent->DoAddChild( this ); |
184 | ||
185 | PostCreation(); | |
7e2b55cd RR |
186 | |
187 | ApplyWidgetStyle(); | |
db434467 | 188 | |
db434467 RR |
189 | SetLabel( title ); |
190 | ||
191 | SetFont( parent->GetFont() ); | |
192 | ||
d3b4d113 | 193 | wxSize ls = LayoutItems(); |
29006414 | 194 | |
907789a0 | 195 | wxSize newSize = size; |
d3b4d113 RR |
196 | if (newSize.x == -1) newSize.x = ls.x; |
197 | if (newSize.y == -1) newSize.y = ls.y; | |
907789a0 | 198 | SetSize( newSize.x, newSize.y ); |
29006414 | 199 | |
907789a0 RR |
200 | SetBackgroundColour( parent->GetBackgroundColour() ); |
201 | SetForegroundColour( parent->GetForegroundColour() ); | |
f96aa4d9 | 202 | |
907789a0 | 203 | Show( TRUE ); |
29006414 | 204 | |
907789a0 | 205 | return TRUE; |
6de97a3b | 206 | } |
c801d85f | 207 | |
f03fc89f | 208 | wxRadioBox::~wxRadioBox() |
d6d1892b | 209 | { |
907789a0 RR |
210 | wxNode *node = m_boxes.First(); |
211 | while (node) | |
212 | { | |
213 | GtkWidget *button = GTK_WIDGET( node->Data() ); | |
214 | gtk_widget_destroy( button ); | |
215 | node = node->Next(); | |
216 | } | |
d6d1892b RR |
217 | } |
218 | ||
54517652 | 219 | void wxRadioBox::DoSetSize( int x, int y, int width, int height, int sizeFlags ) |
3f659fd6 | 220 | { |
54517652 RR |
221 | wxWindow::DoSetSize( x, y, width, height, sizeFlags ); |
222 | ||
d3b4d113 RR |
223 | LayoutItems(); |
224 | } | |
225 | ||
226 | wxSize wxRadioBox::LayoutItems() | |
227 | { | |
bbe0af5b RR |
228 | int x = 7; |
229 | int y = 15; | |
29006414 | 230 | |
e3e717ec VZ |
231 | if ( m_majorDim == 0 ) |
232 | { | |
233 | // avoid dividing by 0 below | |
223d09f6 | 234 | wxFAIL_MSG( wxT("dimension of radiobox should not be 0!") ); |
e3e717ec VZ |
235 | |
236 | m_majorDim = 1; | |
237 | } | |
238 | ||
d3b4d113 | 239 | int num_per_major = (m_boxes.GetCount() - 1) / m_majorDim +1; |
29006414 | 240 | |
d3b4d113 | 241 | wxSize res( 0, 0 ); |
29006414 | 242 | |
e9158f7d RR |
243 | int num_of_cols = 0; |
244 | int num_of_rows = 0; | |
245 | if (HasFlag(wxRA_SPECIFY_COLS)) | |
d3b4d113 | 246 | { |
e9158f7d RR |
247 | num_of_cols = m_majorDim; |
248 | num_of_rows = num_per_major; | |
249 | } | |
250 | else | |
251 | { | |
252 | num_of_cols = num_per_major; | |
253 | num_of_rows = m_majorDim; | |
254 | } | |
255 | ||
256 | if ( HasFlag(wxRA_SPECIFY_COLS) || | |
257 | (HasFlag(wxRA_SPECIFY_ROWS) && (num_of_cols > 1)) ) | |
258 | { | |
259 | for (int j = 0; j < num_of_cols; j++) | |
29006414 | 260 | { |
bbe0af5b | 261 | y = 15; |
29006414 | 262 | |
d3b4d113 | 263 | int max_len = 0; |
e9158f7d RR |
264 | wxNode *node = m_boxes.Nth( j*num_of_rows ); |
265 | for (int i1 = 0; i1< num_of_rows; i1++) | |
29006414 | 266 | { |
d3b4d113 | 267 | GtkWidget *button = GTK_WIDGET( node->Data() ); |
165b6ee0 VS |
268 | |
269 | GtkRequisition req; | |
270 | req.width = 2; | |
271 | req.height = 2; | |
272 | (* GTK_WIDGET_CLASS( GTK_OBJECT(button)->klass )->size_request ) | |
273 | (button, &req ); | |
274 | ||
275 | if (req.width > max_len) max_len = req.width; | |
29006414 | 276 | |
da048e3d | 277 | gtk_pizza_move( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y ); |
165b6ee0 | 278 | y += req.height; |
29006414 VZ |
279 | |
280 | node = node->Next(); | |
281 | if (!node) break; | |
282 | } | |
283 | ||
284 | // we don't know the max_len before | |
285 | ||
e9158f7d RR |
286 | node = m_boxes.Nth( j*num_of_rows ); |
287 | for (int i2 = 0; i2< num_of_rows; i2++) | |
29006414 | 288 | { |
d3b4d113 | 289 | GtkWidget *button = GTK_WIDGET( node->Data() ); |
29006414 | 290 | |
da048e3d | 291 | gtk_pizza_resize( GTK_PIZZA(m_parent->m_wxwindow), button, max_len, 20 ); |
29006414 VZ |
292 | |
293 | node = node->Next(); | |
294 | if (!node) break; | |
295 | } | |
296 | ||
297 | if (y > res.y) res.y = y; | |
298 | ||
299 | x += max_len + 2; | |
d3b4d113 | 300 | } |
29006414 VZ |
301 | |
302 | res.x = x+4; | |
165b6ee0 | 303 | res.y += 4; |
e5403d7c | 304 | } |
d3b4d113 | 305 | else |
e5403d7c | 306 | { |
d3b4d113 RR |
307 | int max = 0; |
308 | ||
309 | wxNode *node = m_boxes.First(); | |
310 | while (node) | |
311 | { | |
165b6ee0 VS |
312 | GtkWidget *button = GTK_WIDGET( node->Data() ); |
313 | ||
314 | GtkRequisition req; | |
315 | req.width = 2; | |
316 | req.height = 2; | |
317 | (* GTK_WIDGET_CLASS( GTK_OBJECT(button)->klass )->size_request ) | |
318 | (button, &req ); | |
29006414 | 319 | |
165b6ee0 | 320 | if (req.width > max) max = req.width; |
29006414 | 321 | |
d3b4d113 RR |
322 | node = node->Next(); |
323 | } | |
29006414 | 324 | |
d3b4d113 RR |
325 | node = m_boxes.First(); |
326 | while (node) | |
327 | { | |
328 | GtkWidget *button = GTK_WIDGET( node->Data() ); | |
29006414 | 329 | |
da048e3d | 330 | gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), button, m_x+x, m_y+y, max, 20 ); |
d3b4d113 | 331 | x += max; |
29006414 | 332 | |
d3b4d113 RR |
333 | node = node->Next(); |
334 | } | |
29006414 | 335 | res.x = x+4; |
3417c2cd | 336 | res.y = 40; |
e5403d7c | 337 | } |
29006414 | 338 | |
d3b4d113 | 339 | return res; |
3f659fd6 RR |
340 | } |
341 | ||
debe6624 | 342 | bool wxRadioBox::Show( bool show ) |
c801d85f | 343 | { |
223d09f6 | 344 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") ); |
29006414 | 345 | |
f96ac56a RR |
346 | if (!wxControl::Show(show)) |
347 | { | |
348 | // nothing to do | |
349 | return FALSE; | |
350 | } | |
c801d85f | 351 | |
ba2a0103 | 352 | if ((m_windowStyle & wxNO_BORDER) != 0) |
b0351fc9 | 353 | gtk_widget_hide( m_widget ); |
e3e717ec | 354 | |
907789a0 RR |
355 | wxNode *node = m_boxes.First(); |
356 | while (node) | |
357 | { | |
358 | GtkWidget *button = GTK_WIDGET( node->Data() ); | |
29006414 | 359 | |
907789a0 | 360 | if (show) gtk_widget_show( button ); else gtk_widget_hide( button ); |
29006414 | 361 | |
907789a0 RR |
362 | node = node->Next(); |
363 | } | |
c801d85f | 364 | |
907789a0 | 365 | return TRUE; |
6de97a3b | 366 | } |
c801d85f | 367 | |
47908e25 | 368 | int wxRadioBox::FindString( const wxString &s ) const |
c801d85f | 369 | { |
223d09f6 | 370 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") ); |
29006414 | 371 | |
907789a0 | 372 | int count = 0; |
29006414 | 373 | |
907789a0 RR |
374 | wxNode *node = m_boxes.First(); |
375 | while (node) | |
376 | { | |
377 | GtkButton *button = GTK_BUTTON( node->Data() ); | |
29006414 | 378 | |
907789a0 RR |
379 | GtkLabel *label = GTK_LABEL( button->child ); |
380 | if (s == label->label) return count; | |
381 | count++; | |
29006414 | 382 | |
907789a0 RR |
383 | node = node->Next(); |
384 | } | |
29006414 | 385 | |
907789a0 | 386 | return -1; |
6de97a3b | 387 | } |
c801d85f | 388 | |
b292e2f5 RR |
389 | void wxRadioBox::SetFocus() |
390 | { | |
223d09f6 | 391 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 392 | |
b292e2f5 | 393 | if (m_boxes.GetCount() == 0) return; |
29006414 | 394 | |
b292e2f5 RR |
395 | wxNode *node = m_boxes.First(); |
396 | while (node) | |
397 | { | |
398 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() ); | |
399 | if (button->active) | |
29006414 | 400 | { |
b292e2f5 | 401 | gtk_widget_grab_focus( GTK_WIDGET(button) ); |
29006414 VZ |
402 | return; |
403 | } | |
b292e2f5 RR |
404 | node = node->Next(); |
405 | } | |
29006414 | 406 | |
b292e2f5 RR |
407 | } |
408 | ||
47908e25 | 409 | void wxRadioBox::SetSelection( int n ) |
c801d85f | 410 | { |
223d09f6 | 411 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 412 | |
907789a0 | 413 | wxNode *node = m_boxes.Nth( n ); |
29006414 | 414 | |
223d09f6 | 415 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 416 | |
907789a0 | 417 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() ); |
29006414 | 418 | |
72a7edf0 | 419 | GtkDisableEvents(); |
953704c1 | 420 | |
907789a0 | 421 | gtk_toggle_button_set_state( button, 1 ); |
953704c1 | 422 | |
72a7edf0 | 423 | GtkEnableEvents(); |
6de97a3b | 424 | } |
c801d85f KB |
425 | |
426 | int wxRadioBox::GetSelection(void) const | |
427 | { | |
223d09f6 | 428 | wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") ); |
29006414 | 429 | |
907789a0 | 430 | int count = 0; |
29006414 | 431 | |
907789a0 RR |
432 | wxNode *node = m_boxes.First(); |
433 | while (node) | |
434 | { | |
435 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() ); | |
436 | if (button->active) return count; | |
437 | count++; | |
438 | node = node->Next(); | |
439 | } | |
29006414 | 440 | |
223d09f6 | 441 | wxFAIL_MSG( wxT("wxRadioBox none selected") ); |
29006414 | 442 | |
907789a0 | 443 | return -1; |
6de97a3b | 444 | } |
c801d85f | 445 | |
47908e25 | 446 | wxString wxRadioBox::GetString( int n ) const |
c801d85f | 447 | { |
223d09f6 | 448 | wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") ); |
29006414 | 449 | |
907789a0 | 450 | wxNode *node = m_boxes.Nth( n ); |
29006414 | 451 | |
223d09f6 | 452 | wxCHECK_MSG( node, wxT(""), wxT("radiobox wrong index") ); |
29006414 | 453 | |
907789a0 RR |
454 | GtkButton *button = GTK_BUTTON( node->Data() ); |
455 | GtkLabel *label = GTK_LABEL( button->child ); | |
29006414 | 456 | |
907789a0 | 457 | return wxString( label->label ); |
6de97a3b | 458 | } |
c801d85f | 459 | |
d3904ceb | 460 | wxString wxRadioBox::GetLabel( int item ) const |
c801d85f | 461 | { |
223d09f6 | 462 | wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") ); |
29006414 | 463 | |
907789a0 | 464 | return GetString( item ); |
6de97a3b | 465 | } |
c801d85f | 466 | |
d3904ceb | 467 | void wxRadioBox::SetLabel( const wxString& label ) |
c801d85f | 468 | { |
223d09f6 | 469 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 470 | |
907789a0 | 471 | wxControl::SetLabel( label ); |
29006414 | 472 | |
b019151f | 473 | gtk_frame_set_label( GTK_FRAME(m_widget), wxControl::GetLabel().mbc_str() ); |
6de97a3b | 474 | } |
c801d85f | 475 | |
d3904ceb | 476 | void wxRadioBox::SetLabel( int item, const wxString& label ) |
c801d85f | 477 | { |
223d09f6 | 478 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 479 | |
907789a0 | 480 | wxNode *node = m_boxes.Nth( item ); |
29006414 | 481 | |
223d09f6 | 482 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 483 | |
907789a0 RR |
484 | GtkButton *button = GTK_BUTTON( node->Data() ); |
485 | GtkLabel *g_label = GTK_LABEL( button->child ); | |
29006414 | 486 | |
b019151f | 487 | gtk_label_set( g_label, label.mbc_str() ); |
6de97a3b | 488 | } |
c801d85f | 489 | |
debe6624 | 490 | void wxRadioBox::SetLabel( int WXUNUSED(item), wxBitmap *WXUNUSED(bitmap) ) |
c801d85f | 491 | { |
223d09f6 | 492 | wxFAIL_MSG(wxT("wxRadioBox::SetLabel not implemented.")); |
6de97a3b | 493 | } |
c801d85f | 494 | |
f03fc89f | 495 | bool wxRadioBox::Enable( bool enable ) |
c801d85f | 496 | { |
f03fc89f VZ |
497 | if ( !wxControl::Enable( enable ) ) |
498 | return FALSE; | |
29006414 | 499 | |
907789a0 RR |
500 | wxNode *node = m_boxes.First(); |
501 | while (node) | |
502 | { | |
503 | GtkButton *button = GTK_BUTTON( node->Data() ); | |
504 | GtkWidget *label = button->child; | |
505 | gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); | |
506 | gtk_widget_set_sensitive( label, enable ); | |
507 | node = node->Next(); | |
508 | } | |
f03fc89f VZ |
509 | |
510 | return TRUE; | |
6de97a3b | 511 | } |
c801d85f | 512 | |
d3904ceb | 513 | void wxRadioBox::Enable( int item, bool enable ) |
c801d85f | 514 | { |
223d09f6 | 515 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 516 | |
907789a0 | 517 | wxNode *node = m_boxes.Nth( item ); |
29006414 | 518 | |
223d09f6 | 519 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 520 | |
907789a0 RR |
521 | GtkButton *button = GTK_BUTTON( node->Data() ); |
522 | GtkWidget *label = button->child; | |
523 | gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); | |
524 | gtk_widget_set_sensitive( label, enable ); | |
6de97a3b | 525 | } |
c801d85f | 526 | |
d3904ceb | 527 | void wxRadioBox::Show( int item, bool show ) |
c801d85f | 528 | { |
223d09f6 | 529 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 530 | |
907789a0 | 531 | wxNode *node = m_boxes.Nth( item ); |
29006414 | 532 | |
223d09f6 | 533 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 534 | |
907789a0 | 535 | GtkWidget *button = GTK_WIDGET( node->Data() ); |
c801d85f | 536 | |
907789a0 RR |
537 | if (show) |
538 | gtk_widget_show( button ); | |
539 | else | |
540 | gtk_widget_hide( button ); | |
6de97a3b | 541 | } |
c801d85f | 542 | |
9c884972 | 543 | wxString wxRadioBox::GetStringSelection() const |
c801d85f | 544 | { |
223d09f6 | 545 | wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid radiobox") ); |
29006414 | 546 | |
907789a0 RR |
547 | wxNode *node = m_boxes.First(); |
548 | while (node) | |
c801d85f | 549 | { |
907789a0 RR |
550 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() ); |
551 | if (button->active) | |
552 | { | |
553 | GtkLabel *label = GTK_LABEL( GTK_BUTTON(button)->child ); | |
554 | return label->label; | |
555 | } | |
556 | node = node->Next(); | |
6de97a3b | 557 | } |
29006414 | 558 | |
223d09f6 KB |
559 | wxFAIL_MSG( wxT("wxRadioBox none selected") ); |
560 | return wxT(""); | |
6de97a3b | 561 | } |
c801d85f | 562 | |
907789a0 | 563 | bool wxRadioBox::SetStringSelection( const wxString &s ) |
c801d85f | 564 | { |
223d09f6 | 565 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid radiobox") ); |
29006414 | 566 | |
907789a0 RR |
567 | int res = FindString( s ); |
568 | if (res == -1) return FALSE; | |
569 | SetSelection( res ); | |
29006414 | 570 | |
907789a0 | 571 | return TRUE; |
6de97a3b | 572 | } |
c801d85f | 573 | |
9c884972 | 574 | int wxRadioBox::Number() const |
c801d85f | 575 | { |
907789a0 | 576 | return m_boxes.Number(); |
6de97a3b | 577 | } |
c801d85f | 578 | |
9c884972 | 579 | int wxRadioBox::GetNumberOfRowsOrCols() const |
c801d85f | 580 | { |
907789a0 | 581 | return 1; |
6de97a3b | 582 | } |
c801d85f | 583 | |
debe6624 | 584 | void wxRadioBox::SetNumberOfRowsOrCols( int WXUNUSED(n) ) |
c801d85f | 585 | { |
223d09f6 | 586 | wxFAIL_MSG(wxT("wxRadioBox::SetNumberOfRowsOrCols not implemented.")); |
6de97a3b | 587 | } |
c801d85f | 588 | |
72a7edf0 | 589 | void wxRadioBox::GtkDisableEvents() |
953704c1 RR |
590 | { |
591 | wxNode *node = m_boxes.First(); | |
592 | while (node) | |
593 | { | |
594 | gtk_signal_disconnect_by_func( GTK_OBJECT(node->Data()), | |
595 | GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); | |
596 | ||
597 | node = node->Next(); | |
598 | } | |
599 | } | |
600 | ||
72a7edf0 | 601 | void wxRadioBox::GtkEnableEvents() |
953704c1 RR |
602 | { |
603 | wxNode *node = m_boxes.First(); | |
604 | while (node) | |
605 | { | |
606 | gtk_signal_connect( GTK_OBJECT(node->Data()), "clicked", | |
607 | GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); | |
608 | ||
609 | node = node->Next(); | |
610 | } | |
611 | } | |
612 | ||
58614078 | 613 | void wxRadioBox::ApplyWidgetStyle() |
868a2826 | 614 | { |
907789a0 | 615 | SetWidgetStyle(); |
29006414 | 616 | |
907789a0 | 617 | gtk_widget_set_style( m_widget, m_widgetStyle ); |
29006414 | 618 | |
907789a0 RR |
619 | wxNode *node = m_boxes.First(); |
620 | while (node) | |
621 | { | |
622 | GtkWidget *widget = GTK_WIDGET( node->Data() ); | |
623 | gtk_widget_set_style( widget, m_widgetStyle ); | |
29006414 | 624 | |
907789a0 RR |
625 | GtkButton *button = GTK_BUTTON( node->Data() ); |
626 | gtk_widget_set_style( button->child, m_widgetStyle ); | |
29006414 | 627 | |
907789a0 RR |
628 | node = node->Next(); |
629 | } | |
868a2826 | 630 | } |
b4071e91 | 631 | |
72a7edf0 RR |
632 | #if wxUSE_TOOLTIPS |
633 | void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip ) | |
634 | { | |
635 | wxNode *node = m_boxes.First(); | |
636 | while (node) | |
637 | { | |
638 | GtkWidget *widget = GTK_WIDGET( node->Data() ); | |
639 | gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL ); | |
640 | node = node->Next(); | |
641 | } | |
642 | } | |
643 | #endif // wxUSE_TOOLTIPS | |
644 | ||
b4071e91 RR |
645 | bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window ) |
646 | { | |
907789a0 | 647 | if (window == m_widget->window) return TRUE; |
29006414 | 648 | |
907789a0 RR |
649 | wxNode *node = m_boxes.First(); |
650 | while (node) | |
651 | { | |
652 | GtkWidget *button = GTK_WIDGET( node->Data() ); | |
29006414 | 653 | |
907789a0 | 654 | if (window == button->window) return TRUE; |
29006414 | 655 | |
907789a0 RR |
656 | node = node->Next(); |
657 | } | |
29006414 | 658 | |
907789a0 | 659 | return FALSE; |
b4071e91 | 660 | } |
dcf924a3 RR |
661 | |
662 | #endif |