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