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