]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
11e62fe6 | 2 | // Name: src/gtk/radiobox.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
f96aa4d9 RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
dcf924a3 RR |
12 | |
13 | #if wxUSE_RADIOBOX | |
14 | ||
1e6feb95 VZ |
15 | #include "wx/radiobox.h" |
16 | ||
e4db172a WS |
17 | #ifndef WX_PRECOMP |
18 | #include "wx/log.h" | |
76b49cf4 | 19 | #include "wx/frame.h" |
fdf565fe | 20 | #include "wx/dialog.h" |
e4db172a WS |
21 | #endif |
22 | ||
aa1e6de9 VZ |
23 | #if wxUSE_TOOLTIPS |
24 | #include "wx/tooltip.h" | |
25 | #endif | |
26 | ||
9e691f46 | 27 | #include "wx/gtk/private.h" |
3f26799e RR |
28 | #include <gdk/gdkkeysyms.h> |
29 | ||
c801d85f KB |
30 | #include "wx/gtk/win_gtk.h" |
31 | ||
dc26eeb3 VZ |
32 | //----------------------------------------------------------------------------- |
33 | // wxGTKRadioButtonInfo | |
34 | //----------------------------------------------------------------------------- | |
35 | // structure internally used by wxRadioBox to store its child buttons | |
36 | ||
37 | class wxGTKRadioButtonInfo : public wxObject | |
38 | { | |
39 | public: | |
40 | wxGTKRadioButtonInfo( GtkRadioButton * abutton, const wxRect & arect ) | |
41 | : button( abutton ), rect( arect ) {} | |
42 | ||
43 | GtkRadioButton * button; | |
44 | wxRect rect; | |
45 | }; | |
46 | ||
66bd6b93 RR |
47 | //----------------------------------------------------------------------------- |
48 | // data | |
49 | //----------------------------------------------------------------------------- | |
50 | ||
dc26eeb3 VZ |
51 | #include "wx/listimpl.cpp" |
52 | WX_DEFINE_LIST( wxRadioBoxButtonsInfoList ); | |
53 | ||
d7fa7eaa | 54 | extern bool g_blockEventsOnDrag; |
66bd6b93 | 55 | |
c801d85f | 56 | //----------------------------------------------------------------------------- |
b4071e91 | 57 | // "clicked" |
c801d85f KB |
58 | //----------------------------------------------------------------------------- |
59 | ||
865bb325 | 60 | extern "C" { |
e2762ff0 | 61 | static void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioBox *rb ) |
c801d85f | 62 | { |
acfd422a RR |
63 | if (g_isIdle) wxapp_install_idle_handler(); |
64 | ||
a2053b27 | 65 | if (!rb->m_hasVMT) return; |
907789a0 | 66 | if (g_blockEventsOnDrag) return; |
29006414 | 67 | |
e2762ff0 | 68 | if (!button->active) return; |
29006414 | 69 | |
907789a0 RR |
70 | wxCommandEvent event( wxEVT_COMMAND_RADIOBOX_SELECTED, rb->GetId() ); |
71 | event.SetInt( rb->GetSelection() ); | |
29006414 | 72 | event.SetString( rb->GetStringSelection() ); |
907789a0 RR |
73 | event.SetEventObject( rb ); |
74 | rb->GetEventHandler()->ProcessEvent(event); | |
6de97a3b | 75 | } |
865bb325 | 76 | } |
c801d85f | 77 | |
2e0e025e RR |
78 | //----------------------------------------------------------------------------- |
79 | // "key_press_event" | |
80 | //----------------------------------------------------------------------------- | |
81 | ||
865bb325 | 82 | extern "C" { |
2e0e025e RR |
83 | static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb ) |
84 | { | |
14819684 | 85 | // don't need to install idle handler, its done from "event" signal |
2e0e025e RR |
86 | |
87 | if (!rb->m_hasVMT) return FALSE; | |
88 | if (g_blockEventsOnDrag) return FALSE; | |
89 | ||
8228b893 | 90 | if ( ((gdk_event->keyval == GDK_Tab) || |
5985c07c RR |
91 | (gdk_event->keyval == GDK_ISO_Left_Tab)) && |
92 | rb->GetParent() && (rb->GetParent()->HasFlag( wxTAB_TRAVERSAL)) ) | |
93 | { | |
94 | wxNavigationKeyEvent new_event; | |
95 | new_event.SetEventObject( rb->GetParent() ); | |
96 | // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB | |
97 | new_event.SetDirection( (gdk_event->keyval == GDK_Tab) ); | |
98 | // CTRL-TAB changes the (parent) window, i.e. switch notebook page | |
99 | new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ); | |
100 | new_event.SetCurrentFocus( rb ); | |
101 | return rb->GetParent()->GetEventHandler()->ProcessEvent( new_event ); | |
102 | } | |
103 | ||
2e0e025e RR |
104 | if ((gdk_event->keyval != GDK_Up) && |
105 | (gdk_event->keyval != GDK_Down) && | |
106 | (gdk_event->keyval != GDK_Left) && | |
107 | (gdk_event->keyval != GDK_Right)) | |
108 | { | |
109 | return FALSE; | |
110 | } | |
2da61056 | 111 | |
dc26eeb3 VZ |
112 | wxRadioBoxButtonsInfoList::compatibility_iterator node = rb->m_buttonsInfo.GetFirst(); |
113 | while( node && GTK_WIDGET( node->GetData()->button ) != widget ) | |
114 | { | |
115 | node = node->GetNext(); | |
116 | } | |
2e0e025e RR |
117 | if (!node) |
118 | { | |
119 | return FALSE; | |
120 | } | |
2da61056 | 121 | |
2e0e025e RR |
122 | if ((gdk_event->keyval == GDK_Up) || |
123 | (gdk_event->keyval == GDK_Left)) | |
124 | { | |
dc26eeb3 VZ |
125 | if (node == rb->m_buttonsInfo.GetFirst()) |
126 | node = rb->m_buttonsInfo.GetLast(); | |
2da61056 | 127 | else |
b1d4dd7a | 128 | node = node->GetPrevious(); |
2e0e025e RR |
129 | } |
130 | else | |
131 | { | |
dc26eeb3 VZ |
132 | if (node == rb->m_buttonsInfo.GetLast()) |
133 | node = rb->m_buttonsInfo.GetFirst(); | |
2da61056 | 134 | else |
b1d4dd7a | 135 | node = node->GetNext(); |
2e0e025e | 136 | } |
2da61056 | 137 | |
dc26eeb3 | 138 | GtkWidget *button = (GtkWidget*) node->GetData()->button; |
2da61056 | 139 | |
2e0e025e | 140 | gtk_widget_grab_focus( button ); |
2da61056 | 141 | |
2e0e025e RR |
142 | return TRUE; |
143 | } | |
865bb325 | 144 | } |
2e0e025e | 145 | |
865bb325 | 146 | extern "C" { |
f6bcfd97 BP |
147 | static gint gtk_radiobutton_focus_in( GtkWidget *widget, |
148 | GdkEvent *WXUNUSED(event), | |
149 | wxRadioBox *win ) | |
150 | { | |
151 | if ( win->m_lostFocus ) | |
152 | { | |
153 | // no, we didn't really lose it | |
154 | win->m_lostFocus = FALSE; | |
155 | } | |
156 | else if ( !win->m_hasFocus ) | |
157 | { | |
b4efc9b9 | 158 | win->m_hasFocus = true; |
f6bcfd97 BP |
159 | |
160 | wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); | |
161 | event.SetEventObject( win ); | |
162 | ||
163 | // never stop the signal emission, it seems to break the kbd handling | |
164 | // inside the radiobox | |
165 | (void)win->GetEventHandler()->ProcessEvent( event ); | |
166 | } | |
167 | ||
168 | return FALSE; | |
169 | } | |
865bb325 | 170 | } |
f6bcfd97 | 171 | |
865bb325 | 172 | extern "C" { |
f6bcfd97 BP |
173 | static gint gtk_radiobutton_focus_out( GtkWidget *widget, |
174 | GdkEvent *WXUNUSED(event), | |
175 | wxRadioBox *win ) | |
176 | { | |
cc1fcb95 JS |
177 | // wxASSERT_MSG( win->m_hasFocus, _T("got focus out without any focus in?") ); |
178 | // Replace with a warning, else we dump core a lot! | |
179 | // if (!win->m_hasFocus) | |
180 | // wxLogWarning(_T("Radiobox got focus out without any focus in.") ); | |
f6bcfd97 BP |
181 | |
182 | // we might have lost the focus, but may be not - it may have just gone to | |
183 | // another button in the same radiobox, so we'll check for it in the next | |
b4efc9b9 WS |
184 | // idle iteration (leave m_hasFocus == true for now) |
185 | win->m_lostFocus = true; | |
f6bcfd97 BP |
186 | |
187 | return FALSE; | |
188 | } | |
865bb325 | 189 | } |
f6bcfd97 | 190 | |
dc26eeb3 VZ |
191 | extern "C" { |
192 | static void gtk_radiobutton_size_allocate( GtkWidget *widget, | |
193 | GtkAllocation * alloc, | |
194 | wxRadioBox *win ) | |
195 | { | |
dc26eeb3 VZ |
196 | for ( wxRadioBoxButtonsInfoList::compatibility_iterator node = win->m_buttonsInfo.GetFirst(); |
197 | node; | |
964c139b | 198 | node = node->GetNext()) |
dc26eeb3 | 199 | { |
964c139b | 200 | if (widget == GTK_WIDGET(node->GetData()->button)) |
dc26eeb3 VZ |
201 | { |
202 | const wxPoint origin = win->GetPosition(); | |
203 | wxRect rect = wxRect( alloc->x - origin.x, alloc->y - origin.y, | |
204 | alloc->width, alloc->height ); | |
205 | node->GetData()->rect = rect; | |
206 | break; | |
207 | } | |
208 | } | |
209 | } | |
210 | } | |
211 | ||
212 | ||
b4071e91 RR |
213 | //----------------------------------------------------------------------------- |
214 | // wxRadioBox | |
c801d85f KB |
215 | //----------------------------------------------------------------------------- |
216 | ||
217 | IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl) | |
218 | ||
f6bcfd97 | 219 | void wxRadioBox::Init() |
c801d85f | 220 | { |
b4efc9b9 WS |
221 | m_needParent = true; |
222 | m_acceptsFocus = true; | |
f6bcfd97 BP |
223 | |
224 | m_hasFocus = | |
b4efc9b9 | 225 | m_lostFocus = false; |
6de97a3b | 226 | } |
c801d85f | 227 | |
584ad2a3 MB |
228 | bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, |
229 | const wxString& title, | |
230 | const wxPoint &pos, const wxSize &size, | |
231 | const wxArrayString& choices, int majorDim, | |
232 | long style, const wxValidator& validator, | |
233 | const wxString &name ) | |
234 | { | |
235 | wxCArrayString chs(choices); | |
236 | ||
237 | return Create( parent, id, title, pos, size, chs.GetCount(), | |
238 | chs.GetStrings(), majorDim, style, validator, name ); | |
239 | } | |
240 | ||
debe6624 | 241 | bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, |
907789a0 | 242 | const wxPoint &pos, const wxSize &size, |
29006414 VZ |
243 | int n, const wxString choices[], int majorDim, |
244 | long style, const wxValidator& validator, | |
245 | const wxString &name ) | |
c801d85f | 246 | { |
4dcaf11a RR |
247 | if (!PreCreation( parent, pos, size ) || |
248 | !CreateBase( parent, id, pos, size, style, validator, name )) | |
249 | { | |
223d09f6 | 250 | wxFAIL_MSG( wxT("wxRadioBox creation failed") ); |
b4efc9b9 | 251 | return false; |
4dcaf11a | 252 | } |
6de97a3b | 253 | |
2e1f5012 VZ |
254 | m_widget = GTKCreateFrame(title); |
255 | wxControl::SetLabel(title); | |
29006414 | 256 | |
5eaac5b5 VZ |
257 | // majorDim may be 0 if all trailing parameters were omitted, so don't |
258 | // assert here but just use the correct value for it | |
27c78e45 | 259 | SetMajorDim(majorDim == 0 ? n : majorDim, style); |
29006414 | 260 | |
8017ee9b | 261 | |
aa61d352 VZ |
262 | unsigned int num_of_cols = GetColumnCount(); |
263 | unsigned int num_of_rows = GetRowCount(); | |
11e62fe6 | 264 | |
07014b5a | 265 | GtkRadioButton *rbtn = (GtkRadioButton*) NULL; |
29006414 | 266 | |
8017ee9b | 267 | GtkWidget *table = gtk_table_new( num_of_rows, num_of_cols, FALSE ); |
d504085d RR |
268 | gtk_table_set_col_spacings( GTK_TABLE(table), 1 ); |
269 | gtk_table_set_row_spacings( GTK_TABLE(table), 1 ); | |
8017ee9b RR |
270 | gtk_widget_show( table ); |
271 | gtk_container_add( GTK_CONTAINER(m_widget), table ); | |
11e62fe6 | 272 | |
26333898 | 273 | wxString label; |
d3b4d113 | 274 | GSList *radio_button_group = (GSList *) NULL; |
8ebb2a1d | 275 | for (unsigned int i = 0; i < (unsigned int)n; i++) |
c801d85f | 276 | { |
26333898 | 277 | if ( i != 0 ) |
07014b5a | 278 | radio_button_group = gtk_radio_button_get_group( GTK_RADIO_BUTTON(rbtn) ); |
29006414 | 279 | |
26333898 VZ |
280 | label.Empty(); |
281 | for ( const wxChar *pc = choices[i]; *pc; pc++ ) | |
282 | { | |
223d09f6 | 283 | if ( *pc != wxT('&') ) |
26333898 VZ |
284 | label += *pc; |
285 | } | |
286 | ||
07014b5a VZ |
287 | rbtn = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) ); |
288 | gtk_widget_show( GTK_WIDGET(rbtn) ); | |
29006414 | 289 | |
07014b5a | 290 | g_signal_connect (rbtn, "key_press_event", |
9fa72bd2 | 291 | G_CALLBACK (gtk_radiobox_keypress_callback), this); |
2da61056 | 292 | |
dc26eeb3 | 293 | m_buttonsInfo.Append( new wxGTKRadioButtonInfo( rbtn, wxRect() ) ); |
29006414 | 294 | |
8017ee9b RR |
295 | if (HasFlag(wxRA_SPECIFY_COLS)) |
296 | { | |
297 | int left = i%num_of_cols; | |
298 | int right = (i%num_of_cols) + 1; | |
299 | int top = i/num_of_cols; | |
300 | int bottom = (i/num_of_cols)+1; | |
07014b5a | 301 | gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom, |
11e62fe6 | 302 | GTK_FILL, GTK_FILL, 1, 1 ); |
8017ee9b RR |
303 | } |
304 | else | |
305 | { | |
306 | int left = i/num_of_rows; | |
307 | int right = (i/num_of_rows) + 1; | |
308 | int top = i%num_of_rows; | |
309 | int bottom = (i%num_of_rows)+1; | |
07014b5a | 310 | gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(rbtn), left, right, top, bottom, |
11e62fe6 | 311 | GTK_FILL, GTK_FILL, 1, 1 ); |
8017ee9b RR |
312 | } |
313 | ||
07014b5a | 314 | ConnectWidget( GTK_WIDGET(rbtn) ); |
29006414 | 315 | |
e343da37 | 316 | if (!i) |
07014b5a | 317 | gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(rbtn), TRUE ); |
29006414 | 318 | |
07014b5a | 319 | g_signal_connect (rbtn, "clicked", |
9fa72bd2 | 320 | G_CALLBACK (gtk_radiobutton_clicked_callback), this); |
07014b5a | 321 | g_signal_connect (rbtn, "focus_in_event", |
9fa72bd2 | 322 | G_CALLBACK (gtk_radiobutton_focus_in), this); |
07014b5a | 323 | g_signal_connect (rbtn, "focus_out_event", |
9fa72bd2 | 324 | G_CALLBACK (gtk_radiobutton_focus_out), this); |
dc26eeb3 VZ |
325 | g_signal_connect (rbtn, "size_allocate", |
326 | G_CALLBACK (gtk_radiobutton_size_allocate), this); | |
6de97a3b | 327 | } |
29006414 | 328 | |
db434467 RR |
329 | m_parent->DoAddChild( this ); |
330 | ||
abdeb9e7 | 331 | PostCreation(size); |
29006414 | 332 | |
b4efc9b9 | 333 | return true; |
6de97a3b | 334 | } |
c801d85f | 335 | |
f03fc89f | 336 | wxRadioBox::~wxRadioBox() |
d6d1892b | 337 | { |
dc26eeb3 | 338 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst(); |
907789a0 RR |
339 | while (node) |
340 | { | |
dc26eeb3 | 341 | GtkWidget *button = GTK_WIDGET( node->GetData()->button ); |
907789a0 | 342 | gtk_widget_destroy( button ); |
b1d4dd7a | 343 | node = node->GetNext(); |
907789a0 | 344 | } |
dc26eeb3 | 345 | WX_CLEAR_LIST( wxRadioBoxButtonsInfoList, m_buttonsInfo ); |
d6d1892b RR |
346 | } |
347 | ||
debe6624 | 348 | bool wxRadioBox::Show( bool show ) |
c801d85f | 349 | { |
b4efc9b9 | 350 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 351 | |
f96ac56a RR |
352 | if (!wxControl::Show(show)) |
353 | { | |
354 | // nothing to do | |
b4efc9b9 | 355 | return false; |
f96ac56a | 356 | } |
c801d85f | 357 | |
c4ca49cd | 358 | if ( HasFlag(wxNO_BORDER) ) |
b0351fc9 | 359 | gtk_widget_hide( m_widget ); |
e3e717ec | 360 | |
dc26eeb3 | 361 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst(); |
907789a0 RR |
362 | while (node) |
363 | { | |
dc26eeb3 | 364 | GtkWidget *button = GTK_WIDGET( node->GetData()->button ); |
29006414 | 365 | |
27c78e45 VZ |
366 | if (show) |
367 | gtk_widget_show( button ); | |
368 | else | |
369 | gtk_widget_hide( button ); | |
29006414 | 370 | |
b1d4dd7a | 371 | node = node->GetNext(); |
907789a0 | 372 | } |
c801d85f | 373 | |
b4efc9b9 | 374 | return true; |
6de97a3b | 375 | } |
c801d85f | 376 | |
b292e2f5 RR |
377 | void wxRadioBox::SetFocus() |
378 | { | |
223d09f6 | 379 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 380 | |
dc26eeb3 | 381 | if (m_buttonsInfo.GetCount() == 0) return; |
29006414 | 382 | |
dc26eeb3 | 383 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst(); |
b292e2f5 RR |
384 | while (node) |
385 | { | |
dc26eeb3 | 386 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button ); |
b292e2f5 | 387 | if (button->active) |
29006414 | 388 | { |
b292e2f5 | 389 | gtk_widget_grab_focus( GTK_WIDGET(button) ); |
29006414 VZ |
390 | return; |
391 | } | |
b1d4dd7a | 392 | node = node->GetNext(); |
b292e2f5 | 393 | } |
b292e2f5 RR |
394 | } |
395 | ||
47908e25 | 396 | void wxRadioBox::SetSelection( int n ) |
c801d85f | 397 | { |
223d09f6 | 398 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 399 | |
dc26eeb3 | 400 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( n ); |
29006414 | 401 | |
223d09f6 | 402 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 403 | |
dc26eeb3 | 404 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button ); |
29006414 | 405 | |
72a7edf0 | 406 | GtkDisableEvents(); |
2da61056 | 407 | |
e2762ff0 | 408 | gtk_toggle_button_set_active( button, 1 ); |
2da61056 | 409 | |
72a7edf0 | 410 | GtkEnableEvents(); |
6de97a3b | 411 | } |
c801d85f KB |
412 | |
413 | int wxRadioBox::GetSelection(void) const | |
414 | { | |
789f6795 | 415 | wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") ); |
29006414 | 416 | |
907789a0 | 417 | int count = 0; |
29006414 | 418 | |
dc26eeb3 | 419 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst(); |
907789a0 RR |
420 | while (node) |
421 | { | |
dc26eeb3 | 422 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData()->button ); |
907789a0 RR |
423 | if (button->active) return count; |
424 | count++; | |
b1d4dd7a | 425 | node = node->GetNext(); |
907789a0 | 426 | } |
29006414 | 427 | |
223d09f6 | 428 | wxFAIL_MSG( wxT("wxRadioBox none selected") ); |
29006414 | 429 | |
789f6795 | 430 | return wxNOT_FOUND; |
6de97a3b | 431 | } |
c801d85f | 432 | |
aa61d352 | 433 | wxString wxRadioBox::GetString(unsigned int n) const |
c801d85f | 434 | { |
1a87edf2 | 435 | wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") ); |
29006414 | 436 | |
dc26eeb3 | 437 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( n ); |
29006414 | 438 | |
1a87edf2 | 439 | wxCHECK_MSG( node, wxEmptyString, wxT("radiobox wrong index") ); |
29006414 | 440 | |
dc26eeb3 | 441 | GtkLabel *label = GTK_LABEL(GTK_BIN(node->GetData()->button)->child); |
29006414 | 442 | |
2b5f62a0 | 443 | wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); |
2b5f62a0 VZ |
444 | |
445 | return str; | |
6de97a3b | 446 | } |
c801d85f | 447 | |
d3904ceb | 448 | void wxRadioBox::SetLabel( const wxString& label ) |
c801d85f | 449 | { |
223d09f6 | 450 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 451 | |
b2ff89d6 | 452 | GTKSetLabelForFrame(GTK_FRAME(m_widget), label); |
6de97a3b | 453 | } |
c801d85f | 454 | |
aa61d352 | 455 | void wxRadioBox::SetString(unsigned int item, const wxString& label) |
c801d85f | 456 | { |
223d09f6 | 457 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 458 | |
dc26eeb3 | 459 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item ); |
29006414 | 460 | |
223d09f6 | 461 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 462 | |
dc26eeb3 | 463 | GtkLabel *g_label = GTK_LABEL(GTK_BIN(node->GetData()->button)->child); |
29006414 | 464 | |
a7c12d28 | 465 | gtk_label_set_text( g_label, wxGTK_CONV( label ) ); |
6de97a3b | 466 | } |
c801d85f | 467 | |
f03fc89f | 468 | bool wxRadioBox::Enable( bool enable ) |
c801d85f | 469 | { |
f03fc89f | 470 | if ( !wxControl::Enable( enable ) ) |
b4efc9b9 | 471 | return false; |
29006414 | 472 | |
dc26eeb3 | 473 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst(); |
907789a0 RR |
474 | while (node) |
475 | { | |
dc26eeb3 | 476 | GtkButton *button = GTK_BUTTON( node->GetData()->button ); |
afa7bd1e | 477 | GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child); |
9e691f46 | 478 | |
907789a0 | 479 | gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); |
9e691f46 | 480 | gtk_widget_set_sensitive( GTK_WIDGET(label), enable ); |
b1d4dd7a | 481 | node = node->GetNext(); |
907789a0 | 482 | } |
f03fc89f | 483 | |
b4efc9b9 | 484 | return true; |
6de97a3b | 485 | } |
c801d85f | 486 | |
aa61d352 | 487 | bool wxRadioBox::Enable(unsigned int item, bool enable) |
c801d85f | 488 | { |
1a87edf2 | 489 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 490 | |
dc26eeb3 | 491 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item ); |
29006414 | 492 | |
1a87edf2 | 493 | wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); |
29006414 | 494 | |
dc26eeb3 | 495 | GtkButton *button = GTK_BUTTON( node->GetData()->button ); |
afa7bd1e | 496 | GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child); |
9e691f46 | 497 | |
907789a0 | 498 | gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); |
9e691f46 | 499 | gtk_widget_set_sensitive( GTK_WIDGET(label), enable ); |
1a87edf2 WS |
500 | |
501 | return true; | |
6de97a3b | 502 | } |
c801d85f | 503 | |
aa61d352 | 504 | bool wxRadioBox::IsItemEnabled(unsigned int item) const |
27c78e45 VZ |
505 | { |
506 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); | |
507 | ||
dc26eeb3 | 508 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item ); |
27c78e45 VZ |
509 | |
510 | wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); | |
511 | ||
dc26eeb3 | 512 | GtkButton *button = GTK_BUTTON( node->GetData()->button ); |
27c78e45 VZ |
513 | |
514 | // don't use GTK_WIDGET_IS_SENSITIVE() here, we want to return true even if | |
515 | // the parent radiobox is disabled | |
516 | return GTK_WIDGET_SENSITIVE(GTK_WIDGET(button)); | |
517 | } | |
518 | ||
aa61d352 | 519 | bool wxRadioBox::Show(unsigned int item, bool show) |
c801d85f | 520 | { |
789f6795 | 521 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 522 | |
dc26eeb3 | 523 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item ); |
29006414 | 524 | |
789f6795 | 525 | wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); |
29006414 | 526 | |
dc26eeb3 | 527 | GtkWidget *button = GTK_WIDGET( node->GetData()->button ); |
c801d85f | 528 | |
907789a0 RR |
529 | if (show) |
530 | gtk_widget_show( button ); | |
531 | else | |
532 | gtk_widget_hide( button ); | |
789f6795 WS |
533 | |
534 | return true; | |
6de97a3b | 535 | } |
c801d85f | 536 | |
aa61d352 | 537 | bool wxRadioBox::IsItemShown(unsigned int item) const |
c801d85f | 538 | { |
27c78e45 | 539 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 540 | |
dc26eeb3 | 541 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.Item( item ); |
c801d85f | 542 | |
27c78e45 | 543 | wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); |
29006414 | 544 | |
dc26eeb3 | 545 | GtkButton *button = GTK_BUTTON( node->GetData()->button ); |
29006414 | 546 | |
27c78e45 | 547 | return GTK_WIDGET_VISIBLE(GTK_WIDGET(button)); |
6de97a3b | 548 | } |
c801d85f | 549 | |
aa61d352 | 550 | unsigned int wxRadioBox::GetCount() const |
c801d85f | 551 | { |
dc26eeb3 | 552 | return m_buttonsInfo.GetCount(); |
6de97a3b | 553 | } |
c801d85f | 554 | |
72a7edf0 | 555 | void wxRadioBox::GtkDisableEvents() |
953704c1 | 556 | { |
dc26eeb3 | 557 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst(); |
953704c1 RR |
558 | while (node) |
559 | { | |
dc26eeb3 | 560 | g_signal_handlers_disconnect_by_func (node->GetData()->button, |
9fa72bd2 MR |
561 | (gpointer) gtk_radiobutton_clicked_callback, |
562 | this); | |
953704c1 | 563 | |
b1d4dd7a | 564 | node = node->GetNext(); |
953704c1 RR |
565 | } |
566 | } | |
567 | ||
72a7edf0 | 568 | void wxRadioBox::GtkEnableEvents() |
953704c1 | 569 | { |
dc26eeb3 | 570 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst(); |
953704c1 RR |
571 | while (node) |
572 | { | |
dc26eeb3 | 573 | g_signal_connect (node->GetData()->button, "clicked", |
9fa72bd2 | 574 | G_CALLBACK (gtk_radiobutton_clicked_callback), this); |
953704c1 | 575 | |
b1d4dd7a | 576 | node = node->GetNext(); |
953704c1 RR |
577 | } |
578 | } | |
579 | ||
f40fdaa3 | 580 | void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style) |
868a2826 | 581 | { |
2e1f5012 | 582 | GTKFrameApplyWidgetStyle(GTK_FRAME(m_widget), style); |
81e88f5b | 583 | |
dc26eeb3 | 584 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst(); |
907789a0 RR |
585 | while (node) |
586 | { | |
dc26eeb3 | 587 | GtkWidget *widget = GTK_WIDGET( node->GetData()->button ); |
29006414 | 588 | |
f40fdaa3 | 589 | gtk_widget_modify_style( widget, style ); |
afa7bd1e | 590 | gtk_widget_modify_style(GTK_BIN(widget)->child, style); |
29006414 | 591 | |
b1d4dd7a | 592 | node = node->GetNext(); |
907789a0 | 593 | } |
868a2826 | 594 | } |
b4071e91 | 595 | |
2e1f5012 VZ |
596 | bool wxRadioBox::GTKWidgetNeedsMnemonic() const |
597 | { | |
598 | return true; | |
599 | } | |
600 | ||
601 | void wxRadioBox::GTKWidgetDoSetMnemonic(GtkWidget* w) | |
602 | { | |
603 | GTKFrameSetMnemonicWidget(GTK_FRAME(m_widget), w); | |
604 | } | |
605 | ||
72a7edf0 | 606 | #if wxUSE_TOOLTIPS |
aa1e6de9 | 607 | void wxRadioBox::ApplyToolTip(GtkTooltips * WXUNUSED(tips), const wxChar *tip) |
72a7edf0 | 608 | { |
aa1e6de9 VZ |
609 | // set this tooltip for all radiobuttons which don't have their own tips |
610 | unsigned n = 0; | |
dc26eeb3 | 611 | for ( wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst(); |
aa1e6de9 VZ |
612 | node; |
613 | node = node->GetNext(), n++ ) | |
72a7edf0 | 614 | { |
aa1e6de9 VZ |
615 | if ( !GetItemToolTip(n) ) |
616 | { | |
dc26eeb3 | 617 | wxToolTip::Apply(GTK_WIDGET(node->GetData()->button), |
aa1e6de9 VZ |
618 | wxConvCurrent->cWX2MB(tip)); |
619 | } | |
72a7edf0 RR |
620 | } |
621 | } | |
aa1e6de9 VZ |
622 | |
623 | void wxRadioBox::DoSetItemToolTip(unsigned int n, wxToolTip *tooltip) | |
624 | { | |
625 | wxCharBuffer buf; | |
626 | if ( !tooltip ) | |
627 | tooltip = GetToolTip(); | |
628 | if ( tooltip ) | |
629 | buf = wxGTK_CONV(tooltip->GetTip()); | |
630 | ||
dc26eeb3 | 631 | wxToolTip::Apply(GTK_WIDGET(m_buttonsInfo[n]->button), buf); |
aa1e6de9 VZ |
632 | } |
633 | ||
72a7edf0 RR |
634 | #endif // wxUSE_TOOLTIPS |
635 | ||
ef5c70f9 | 636 | GdkWindow *wxRadioBox::GTKGetWindow(wxArrayGdkWindows& windows) const |
b4071e91 | 637 | { |
ef5c70f9 | 638 | windows.push_back(m_widget->window); |
29006414 | 639 | |
dc26eeb3 | 640 | wxRadioBoxButtonsInfoList::compatibility_iterator node = m_buttonsInfo.GetFirst(); |
907789a0 RR |
641 | while (node) |
642 | { | |
dc26eeb3 | 643 | GtkWidget *button = GTK_WIDGET( node->GetData()->button ); |
29006414 | 644 | |
ef5c70f9 | 645 | windows.push_back(button->window); |
29006414 | 646 | |
b1d4dd7a | 647 | node = node->GetNext(); |
907789a0 | 648 | } |
29006414 | 649 | |
ef5c70f9 | 650 | return NULL; |
b4071e91 | 651 | } |
dcf924a3 | 652 | |
f6bcfd97 BP |
653 | void wxRadioBox::OnInternalIdle() |
654 | { | |
ef5c70f9 VZ |
655 | wxControl::OnInternalIdle(); |
656 | ||
f6bcfd97 BP |
657 | if ( m_lostFocus ) |
658 | { | |
b4efc9b9 WS |
659 | m_hasFocus = false; |
660 | m_lostFocus = false; | |
f6bcfd97 BP |
661 | |
662 | wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() ); | |
663 | event.SetEventObject( this ); | |
664 | ||
665 | (void)GetEventHandler()->ProcessEvent( event ); | |
666 | } | |
667 | } | |
668 | ||
9d522606 RD |
669 | // static |
670 | wxVisualAttributes | |
671 | wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
672 | { | |
673 | wxVisualAttributes attr; | |
bc0eb46c VS |
674 | // NB: we need toplevel window so that GTK+ can find the right style |
675 | GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
9d522606 | 676 | GtkWidget* widget = gtk_radio_button_new_with_label(NULL, ""); |
bc0eb46c | 677 | gtk_container_add(GTK_CONTAINER(wnd), widget); |
9d522606 | 678 | attr = GetDefaultAttributesFromGTKWidget(widget); |
bc0eb46c | 679 | gtk_widget_destroy(wnd); |
9d522606 RD |
680 | return attr; |
681 | } | |
682 | ||
dc26eeb3 VZ |
683 | int wxRadioBox::GetItemFromPoint(const wxPoint& point) const |
684 | { | |
685 | const wxPoint pt = ScreenToClient(point); | |
686 | unsigned n = 0; | |
687 | for ( wxRadioBoxButtonsInfoList::compatibility_iterator | |
688 | node = m_buttonsInfo.GetFirst(); node; node = node->GetNext(), n++ ) | |
689 | { | |
22a35096 | 690 | if ( m_buttonsInfo[n]->rect.Contains(pt) ) |
dc26eeb3 VZ |
691 | return n; |
692 | } | |
693 | ||
694 | return wxNOT_FOUND; | |
695 | } | |
696 | ||
f6bcfd97 | 697 | #endif // wxUSE_RADIOBOX |