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