]>
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 | ||
c801d85f KB |
17 | #include "wx/dialog.h" |
18 | #include "wx/frame.h" | |
cc1fcb95 | 19 | #include "wx/log.h" |
83624f79 | 20 | |
9e691f46 | 21 | #include "wx/gtk/private.h" |
3f26799e RR |
22 | #include <gdk/gdkkeysyms.h> |
23 | ||
c801d85f KB |
24 | #include "wx/gtk/win_gtk.h" |
25 | ||
acfd422a RR |
26 | //----------------------------------------------------------------------------- |
27 | // idle system | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
30 | extern void wxapp_install_idle_handler(); | |
31 | extern bool g_isIdle; | |
32 | ||
66bd6b93 RR |
33 | //----------------------------------------------------------------------------- |
34 | // data | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
d7fa7eaa RR |
37 | extern bool g_blockEventsOnDrag; |
38 | extern wxWindowGTK *g_delayedFocus; | |
66bd6b93 | 39 | |
c801d85f | 40 | //----------------------------------------------------------------------------- |
b4071e91 | 41 | // "clicked" |
c801d85f KB |
42 | //----------------------------------------------------------------------------- |
43 | ||
865bb325 | 44 | extern "C" { |
e2762ff0 | 45 | static void gtk_radiobutton_clicked_callback( GtkToggleButton *button, wxRadioBox *rb ) |
c801d85f | 46 | { |
acfd422a RR |
47 | if (g_isIdle) wxapp_install_idle_handler(); |
48 | ||
a2053b27 | 49 | if (!rb->m_hasVMT) return; |
907789a0 | 50 | if (g_blockEventsOnDrag) return; |
29006414 | 51 | |
e2762ff0 | 52 | if (!button->active) return; |
29006414 | 53 | |
907789a0 RR |
54 | wxCommandEvent event( wxEVT_COMMAND_RADIOBOX_SELECTED, rb->GetId() ); |
55 | event.SetInt( rb->GetSelection() ); | |
29006414 | 56 | event.SetString( rb->GetStringSelection() ); |
907789a0 RR |
57 | event.SetEventObject( rb ); |
58 | rb->GetEventHandler()->ProcessEvent(event); | |
6de97a3b | 59 | } |
865bb325 | 60 | } |
c801d85f | 61 | |
2e0e025e RR |
62 | //----------------------------------------------------------------------------- |
63 | // "key_press_event" | |
64 | //----------------------------------------------------------------------------- | |
65 | ||
865bb325 | 66 | extern "C" { |
2e0e025e RR |
67 | static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb ) |
68 | { | |
69 | if (g_isIdle) | |
70 | wxapp_install_idle_handler(); | |
71 | ||
72 | if (!rb->m_hasVMT) return FALSE; | |
73 | if (g_blockEventsOnDrag) return FALSE; | |
74 | ||
75 | if ((gdk_event->keyval != GDK_Up) && | |
76 | (gdk_event->keyval != GDK_Down) && | |
77 | (gdk_event->keyval != GDK_Left) && | |
78 | (gdk_event->keyval != GDK_Right)) | |
79 | { | |
80 | return FALSE; | |
81 | } | |
2da61056 | 82 | |
222ed1d6 | 83 | wxList::compatibility_iterator node = rb->m_boxes.Find( (wxObject*) widget ); |
2e0e025e RR |
84 | if (!node) |
85 | { | |
86 | return FALSE; | |
87 | } | |
2da61056 | 88 | |
9fa72bd2 | 89 | g_signal_stop_emission_by_name (widget, "key_press_event"); |
2da61056 | 90 | |
2e0e025e RR |
91 | if ((gdk_event->keyval == GDK_Up) || |
92 | (gdk_event->keyval == GDK_Left)) | |
93 | { | |
b1d4dd7a RL |
94 | if (node == rb->m_boxes.GetFirst()) |
95 | node = rb->m_boxes.GetLast(); | |
2da61056 | 96 | else |
b1d4dd7a | 97 | node = node->GetPrevious(); |
2e0e025e RR |
98 | } |
99 | else | |
100 | { | |
b1d4dd7a RL |
101 | if (node == rb->m_boxes.GetLast()) |
102 | node = rb->m_boxes.GetFirst(); | |
2da61056 | 103 | else |
b1d4dd7a | 104 | node = node->GetNext(); |
2e0e025e | 105 | } |
2da61056 | 106 | |
b1d4dd7a | 107 | GtkWidget *button = (GtkWidget*) node->GetData(); |
2da61056 | 108 | |
2e0e025e | 109 | gtk_widget_grab_focus( button ); |
2da61056 | 110 | |
2e0e025e RR |
111 | return TRUE; |
112 | } | |
865bb325 | 113 | } |
2e0e025e | 114 | |
865bb325 | 115 | extern "C" { |
f6bcfd97 BP |
116 | static gint gtk_radiobutton_focus_in( GtkWidget *widget, |
117 | GdkEvent *WXUNUSED(event), | |
118 | wxRadioBox *win ) | |
119 | { | |
120 | if ( win->m_lostFocus ) | |
121 | { | |
122 | // no, we didn't really lose it | |
123 | win->m_lostFocus = FALSE; | |
124 | } | |
125 | else if ( !win->m_hasFocus ) | |
126 | { | |
b4efc9b9 | 127 | win->m_hasFocus = true; |
f6bcfd97 BP |
128 | |
129 | wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); | |
130 | event.SetEventObject( win ); | |
131 | ||
132 | // never stop the signal emission, it seems to break the kbd handling | |
133 | // inside the radiobox | |
134 | (void)win->GetEventHandler()->ProcessEvent( event ); | |
135 | } | |
136 | ||
137 | return FALSE; | |
138 | } | |
865bb325 | 139 | } |
f6bcfd97 | 140 | |
865bb325 | 141 | extern "C" { |
f6bcfd97 BP |
142 | static gint gtk_radiobutton_focus_out( GtkWidget *widget, |
143 | GdkEvent *WXUNUSED(event), | |
144 | wxRadioBox *win ) | |
145 | { | |
cc1fcb95 JS |
146 | // wxASSERT_MSG( win->m_hasFocus, _T("got focus out without any focus in?") ); |
147 | // Replace with a warning, else we dump core a lot! | |
148 | // if (!win->m_hasFocus) | |
149 | // wxLogWarning(_T("Radiobox got focus out without any focus in.") ); | |
f6bcfd97 BP |
150 | |
151 | // we might have lost the focus, but may be not - it may have just gone to | |
152 | // another button in the same radiobox, so we'll check for it in the next | |
b4efc9b9 WS |
153 | // idle iteration (leave m_hasFocus == true for now) |
154 | win->m_lostFocus = true; | |
f6bcfd97 BP |
155 | |
156 | return FALSE; | |
157 | } | |
865bb325 | 158 | } |
f6bcfd97 | 159 | |
b4071e91 RR |
160 | //----------------------------------------------------------------------------- |
161 | // wxRadioBox | |
c801d85f KB |
162 | //----------------------------------------------------------------------------- |
163 | ||
164 | IMPLEMENT_DYNAMIC_CLASS(wxRadioBox,wxControl) | |
165 | ||
f6bcfd97 | 166 | void wxRadioBox::Init() |
c801d85f | 167 | { |
b4efc9b9 WS |
168 | m_needParent = true; |
169 | m_acceptsFocus = true; | |
f6bcfd97 BP |
170 | |
171 | m_hasFocus = | |
b4efc9b9 | 172 | m_lostFocus = false; |
6de97a3b | 173 | } |
c801d85f | 174 | |
584ad2a3 MB |
175 | bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, |
176 | const wxString& title, | |
177 | const wxPoint &pos, const wxSize &size, | |
178 | const wxArrayString& choices, int majorDim, | |
179 | long style, const wxValidator& validator, | |
180 | const wxString &name ) | |
181 | { | |
182 | wxCArrayString chs(choices); | |
183 | ||
184 | return Create( parent, id, title, pos, size, chs.GetCount(), | |
185 | chs.GetStrings(), majorDim, style, validator, name ); | |
186 | } | |
187 | ||
debe6624 | 188 | bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, |
907789a0 | 189 | const wxPoint &pos, const wxSize &size, |
29006414 VZ |
190 | int n, const wxString choices[], int majorDim, |
191 | long style, const wxValidator& validator, | |
192 | const wxString &name ) | |
c801d85f | 193 | { |
4dcaf11a RR |
194 | if (!PreCreation( parent, pos, size ) || |
195 | !CreateBase( parent, id, pos, size, style, validator, name )) | |
196 | { | |
223d09f6 | 197 | wxFAIL_MSG( wxT("wxRadioBox creation failed") ); |
b4efc9b9 | 198 | return false; |
4dcaf11a | 199 | } |
6de97a3b | 200 | |
b2ff89d6 VZ |
201 | m_widget = gtk_frame_new(NULL); |
202 | SetLabel(title); | |
29006414 | 203 | |
5eaac5b5 VZ |
204 | // majorDim may be 0 if all trailing parameters were omitted, so don't |
205 | // assert here but just use the correct value for it | |
27c78e45 | 206 | SetMajorDim(majorDim == 0 ? n : majorDim, style); |
29006414 | 207 | |
8017ee9b | 208 | |
27c78e45 VZ |
209 | int num_of_cols = GetColumnCount(); |
210 | int num_of_rows = GetRowCount(); | |
11e62fe6 | 211 | |
907789a0 | 212 | GtkRadioButton *m_radio = (GtkRadioButton*) NULL; |
29006414 | 213 | |
8017ee9b | 214 | GtkWidget *table = gtk_table_new( num_of_rows, num_of_cols, FALSE ); |
d504085d RR |
215 | gtk_table_set_col_spacings( GTK_TABLE(table), 1 ); |
216 | gtk_table_set_row_spacings( GTK_TABLE(table), 1 ); | |
8017ee9b RR |
217 | gtk_widget_show( table ); |
218 | gtk_container_add( GTK_CONTAINER(m_widget), table ); | |
11e62fe6 | 219 | |
26333898 | 220 | wxString label; |
d3b4d113 RR |
221 | GSList *radio_button_group = (GSList *) NULL; |
222 | for (int i = 0; i < n; i++) | |
c801d85f | 223 | { |
26333898 VZ |
224 | if ( i != 0 ) |
225 | radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) ); | |
29006414 | 226 | |
26333898 VZ |
227 | label.Empty(); |
228 | for ( const wxChar *pc = choices[i]; *pc; pc++ ) | |
229 | { | |
223d09f6 | 230 | if ( *pc != wxT('&') ) |
26333898 VZ |
231 | label += *pc; |
232 | } | |
233 | ||
fab591c5 | 234 | m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) ); |
8017ee9b | 235 | gtk_widget_show( GTK_WIDGET(m_radio) ); |
29006414 | 236 | |
9fa72bd2 MR |
237 | g_signal_connect (m_radio, "key_press_event", |
238 | G_CALLBACK (gtk_radiobox_keypress_callback), this); | |
2da61056 | 239 | |
d3b4d113 | 240 | m_boxes.Append( (wxObject*) m_radio ); |
29006414 | 241 | |
8017ee9b RR |
242 | if (HasFlag(wxRA_SPECIFY_COLS)) |
243 | { | |
244 | int left = i%num_of_cols; | |
245 | int right = (i%num_of_cols) + 1; | |
246 | int top = i/num_of_cols; | |
247 | int bottom = (i/num_of_cols)+1; | |
11e62fe6 WS |
248 | gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(m_radio), left, right, top, bottom, |
249 | GTK_FILL, GTK_FILL, 1, 1 ); | |
8017ee9b RR |
250 | } |
251 | else | |
252 | { | |
253 | int left = i/num_of_rows; | |
254 | int right = (i/num_of_rows) + 1; | |
255 | int top = i%num_of_rows; | |
256 | int bottom = (i%num_of_rows)+1; | |
11e62fe6 WS |
257 | gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(m_radio), left, right, top, bottom, |
258 | GTK_FILL, GTK_FILL, 1, 1 ); | |
8017ee9b RR |
259 | } |
260 | ||
d3b4d113 | 261 | ConnectWidget( GTK_WIDGET(m_radio) ); |
29006414 | 262 | |
d3b4d113 | 263 | if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); |
29006414 | 264 | |
9fa72bd2 MR |
265 | g_signal_connect (m_radio, "clicked", |
266 | G_CALLBACK (gtk_radiobutton_clicked_callback), this); | |
267 | g_signal_connect (m_radio, "focus_in_event", | |
268 | G_CALLBACK (gtk_radiobutton_focus_in), this); | |
269 | g_signal_connect (m_radio, "focus_out_event", | |
270 | G_CALLBACK (gtk_radiobutton_focus_out), this); | |
6de97a3b | 271 | } |
29006414 | 272 | |
db434467 RR |
273 | m_parent->DoAddChild( this ); |
274 | ||
abdeb9e7 | 275 | PostCreation(size); |
29006414 | 276 | |
b4efc9b9 | 277 | return true; |
6de97a3b | 278 | } |
c801d85f | 279 | |
f03fc89f | 280 | wxRadioBox::~wxRadioBox() |
d6d1892b | 281 | { |
222ed1d6 | 282 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
283 | while (node) |
284 | { | |
b1d4dd7a | 285 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
907789a0 | 286 | gtk_widget_destroy( button ); |
b1d4dd7a | 287 | node = node->GetNext(); |
907789a0 | 288 | } |
d6d1892b RR |
289 | } |
290 | ||
debe6624 | 291 | bool wxRadioBox::Show( bool show ) |
c801d85f | 292 | { |
b4efc9b9 | 293 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 294 | |
f96ac56a RR |
295 | if (!wxControl::Show(show)) |
296 | { | |
297 | // nothing to do | |
b4efc9b9 | 298 | return false; |
f96ac56a | 299 | } |
c801d85f | 300 | |
c4ca49cd | 301 | if ( HasFlag(wxNO_BORDER) ) |
b0351fc9 | 302 | gtk_widget_hide( m_widget ); |
e3e717ec | 303 | |
222ed1d6 | 304 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
305 | while (node) |
306 | { | |
b1d4dd7a | 307 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
29006414 | 308 | |
27c78e45 VZ |
309 | if (show) |
310 | gtk_widget_show( button ); | |
311 | else | |
312 | gtk_widget_hide( button ); | |
29006414 | 313 | |
b1d4dd7a | 314 | node = node->GetNext(); |
907789a0 | 315 | } |
c801d85f | 316 | |
b4efc9b9 | 317 | return true; |
6de97a3b | 318 | } |
c801d85f | 319 | |
b292e2f5 RR |
320 | void wxRadioBox::SetFocus() |
321 | { | |
223d09f6 | 322 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 323 | |
b292e2f5 | 324 | if (m_boxes.GetCount() == 0) return; |
29006414 | 325 | |
222ed1d6 | 326 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
b292e2f5 RR |
327 | while (node) |
328 | { | |
b1d4dd7a | 329 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); |
b292e2f5 | 330 | if (button->active) |
29006414 | 331 | { |
b292e2f5 | 332 | gtk_widget_grab_focus( GTK_WIDGET(button) ); |
29006414 VZ |
333 | return; |
334 | } | |
b1d4dd7a | 335 | node = node->GetNext(); |
b292e2f5 | 336 | } |
b292e2f5 RR |
337 | } |
338 | ||
47908e25 | 339 | void wxRadioBox::SetSelection( int n ) |
c801d85f | 340 | { |
223d09f6 | 341 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 342 | |
222ed1d6 | 343 | wxList::compatibility_iterator node = m_boxes.Item( n ); |
29006414 | 344 | |
223d09f6 | 345 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 346 | |
b1d4dd7a | 347 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); |
29006414 | 348 | |
72a7edf0 | 349 | GtkDisableEvents(); |
2da61056 | 350 | |
e2762ff0 | 351 | gtk_toggle_button_set_active( button, 1 ); |
2da61056 | 352 | |
72a7edf0 | 353 | GtkEnableEvents(); |
6de97a3b | 354 | } |
c801d85f KB |
355 | |
356 | int wxRadioBox::GetSelection(void) const | |
357 | { | |
789f6795 | 358 | wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") ); |
29006414 | 359 | |
907789a0 | 360 | int count = 0; |
29006414 | 361 | |
222ed1d6 | 362 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
363 | while (node) |
364 | { | |
b1d4dd7a | 365 | GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->GetData() ); |
907789a0 RR |
366 | if (button->active) return count; |
367 | count++; | |
b1d4dd7a | 368 | node = node->GetNext(); |
907789a0 | 369 | } |
29006414 | 370 | |
223d09f6 | 371 | wxFAIL_MSG( wxT("wxRadioBox none selected") ); |
29006414 | 372 | |
789f6795 | 373 | return wxNOT_FOUND; |
6de97a3b | 374 | } |
c801d85f | 375 | |
47908e25 | 376 | wxString wxRadioBox::GetString( int n ) const |
c801d85f | 377 | { |
1a87edf2 | 378 | wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid radiobox") ); |
29006414 | 379 | |
222ed1d6 | 380 | wxList::compatibility_iterator node = m_boxes.Item( n ); |
29006414 | 381 | |
1a87edf2 | 382 | wxCHECK_MSG( node, wxEmptyString, wxT("radiobox wrong index") ); |
29006414 | 383 | |
afa7bd1e | 384 | GtkLabel *label = GTK_LABEL(GTK_BIN(node->GetData())->child); |
29006414 | 385 | |
2b5f62a0 | 386 | wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) ); |
2b5f62a0 VZ |
387 | |
388 | return str; | |
6de97a3b | 389 | } |
c801d85f | 390 | |
d3904ceb | 391 | void wxRadioBox::SetLabel( const wxString& label ) |
c801d85f | 392 | { |
223d09f6 | 393 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 394 | |
b2ff89d6 | 395 | GTKSetLabelForFrame(GTK_FRAME(m_widget), label); |
6de97a3b | 396 | } |
c801d85f | 397 | |
2da61056 | 398 | void wxRadioBox::SetString( int item, const wxString& label ) |
c801d85f | 399 | { |
223d09f6 | 400 | wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); |
29006414 | 401 | |
222ed1d6 | 402 | wxList::compatibility_iterator node = m_boxes.Item( item ); |
29006414 | 403 | |
223d09f6 | 404 | wxCHECK_RET( node, wxT("radiobox wrong index") ); |
29006414 | 405 | |
afa7bd1e | 406 | GtkLabel *g_label = GTK_LABEL(GTK_BIN(node->GetData())->child); |
29006414 | 407 | |
fab591c5 | 408 | gtk_label_set( g_label, wxGTK_CONV( label ) ); |
6de97a3b | 409 | } |
c801d85f | 410 | |
f03fc89f | 411 | bool wxRadioBox::Enable( bool enable ) |
c801d85f | 412 | { |
f03fc89f | 413 | if ( !wxControl::Enable( enable ) ) |
b4efc9b9 | 414 | return false; |
29006414 | 415 | |
222ed1d6 | 416 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
417 | while (node) |
418 | { | |
b1d4dd7a | 419 | GtkButton *button = GTK_BUTTON( node->GetData() ); |
afa7bd1e | 420 | GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child); |
9e691f46 | 421 | |
907789a0 | 422 | gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); |
9e691f46 | 423 | gtk_widget_set_sensitive( GTK_WIDGET(label), enable ); |
b1d4dd7a | 424 | node = node->GetNext(); |
907789a0 | 425 | } |
f03fc89f | 426 | |
b4efc9b9 | 427 | return true; |
6de97a3b | 428 | } |
c801d85f | 429 | |
1a87edf2 | 430 | bool wxRadioBox::Enable( int item, bool enable ) |
c801d85f | 431 | { |
1a87edf2 | 432 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 433 | |
222ed1d6 | 434 | wxList::compatibility_iterator node = m_boxes.Item( item ); |
29006414 | 435 | |
1a87edf2 | 436 | wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); |
29006414 | 437 | |
b1d4dd7a | 438 | GtkButton *button = GTK_BUTTON( node->GetData() ); |
afa7bd1e | 439 | GtkLabel *label = GTK_LABEL(GTK_BIN(button)->child); |
9e691f46 | 440 | |
907789a0 | 441 | gtk_widget_set_sensitive( GTK_WIDGET(button), enable ); |
9e691f46 | 442 | gtk_widget_set_sensitive( GTK_WIDGET(label), enable ); |
1a87edf2 WS |
443 | |
444 | return true; | |
6de97a3b | 445 | } |
c801d85f | 446 | |
27c78e45 VZ |
447 | bool wxRadioBox::IsItemEnabled(int item) const |
448 | { | |
449 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); | |
450 | ||
451 | wxList::compatibility_iterator node = m_boxes.Item( item ); | |
452 | ||
453 | wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); | |
454 | ||
455 | GtkButton *button = GTK_BUTTON( node->GetData() ); | |
456 | ||
457 | // don't use GTK_WIDGET_IS_SENSITIVE() here, we want to return true even if | |
458 | // the parent radiobox is disabled | |
459 | return GTK_WIDGET_SENSITIVE(GTK_WIDGET(button)); | |
460 | } | |
461 | ||
789f6795 | 462 | bool wxRadioBox::Show( int item, bool show ) |
c801d85f | 463 | { |
789f6795 | 464 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 465 | |
222ed1d6 | 466 | wxList::compatibility_iterator node = m_boxes.Item( item ); |
29006414 | 467 | |
789f6795 | 468 | wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); |
29006414 | 469 | |
b1d4dd7a | 470 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
c801d85f | 471 | |
907789a0 RR |
472 | if (show) |
473 | gtk_widget_show( button ); | |
474 | else | |
475 | gtk_widget_hide( button ); | |
789f6795 WS |
476 | |
477 | return true; | |
6de97a3b | 478 | } |
c801d85f | 479 | |
27c78e45 | 480 | bool wxRadioBox::IsItemShown(int item) const |
c801d85f | 481 | { |
27c78e45 | 482 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); |
29006414 | 483 | |
27c78e45 | 484 | wxList::compatibility_iterator node = m_boxes.Item( item ); |
c801d85f | 485 | |
27c78e45 | 486 | wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); |
29006414 | 487 | |
27c78e45 | 488 | GtkButton *button = GTK_BUTTON( node->GetData() ); |
29006414 | 489 | |
27c78e45 | 490 | return GTK_WIDGET_VISIBLE(GTK_WIDGET(button)); |
6de97a3b | 491 | } |
c801d85f | 492 | |
2da61056 | 493 | int wxRadioBox::GetCount() const |
c801d85f | 494 | { |
b1d4dd7a | 495 | return m_boxes.GetCount(); |
6de97a3b | 496 | } |
c801d85f | 497 | |
72a7edf0 | 498 | void wxRadioBox::GtkDisableEvents() |
953704c1 | 499 | { |
222ed1d6 | 500 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
953704c1 RR |
501 | while (node) |
502 | { | |
9fa72bd2 MR |
503 | g_signal_handlers_disconnect_by_func (node->GetData(), |
504 | (gpointer) gtk_radiobutton_clicked_callback, | |
505 | this); | |
953704c1 | 506 | |
b1d4dd7a | 507 | node = node->GetNext(); |
953704c1 RR |
508 | } |
509 | } | |
510 | ||
72a7edf0 | 511 | void wxRadioBox::GtkEnableEvents() |
953704c1 | 512 | { |
222ed1d6 | 513 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
953704c1 RR |
514 | while (node) |
515 | { | |
9fa72bd2 MR |
516 | g_signal_connect (node->GetData(), "clicked", |
517 | G_CALLBACK (gtk_radiobutton_clicked_callback), this); | |
953704c1 | 518 | |
b1d4dd7a | 519 | node = node->GetNext(); |
953704c1 RR |
520 | } |
521 | } | |
522 | ||
f40fdaa3 | 523 | void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style) |
868a2826 | 524 | { |
f40fdaa3 | 525 | gtk_widget_modify_style( m_widget, style ); |
81e88f5b | 526 | gtk_widget_modify_style(GTK_FRAME(m_widget)->label_widget, style); |
81e88f5b | 527 | |
222ed1d6 | 528 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
529 | while (node) |
530 | { | |
b1d4dd7a | 531 | GtkWidget *widget = GTK_WIDGET( node->GetData() ); |
29006414 | 532 | |
f40fdaa3 | 533 | gtk_widget_modify_style( widget, style ); |
afa7bd1e | 534 | gtk_widget_modify_style(GTK_BIN(widget)->child, style); |
29006414 | 535 | |
b1d4dd7a | 536 | node = node->GetNext(); |
907789a0 | 537 | } |
868a2826 | 538 | } |
b4071e91 | 539 | |
72a7edf0 RR |
540 | #if wxUSE_TOOLTIPS |
541 | void wxRadioBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip ) | |
542 | { | |
222ed1d6 | 543 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
72a7edf0 RR |
544 | while (node) |
545 | { | |
b1d4dd7a | 546 | GtkWidget *widget = GTK_WIDGET( node->GetData() ); |
72a7edf0 | 547 | gtk_tooltips_set_tip( tips, widget, wxConvCurrent->cWX2MB(tip), (gchar*) NULL ); |
b1d4dd7a | 548 | node = node->GetNext(); |
72a7edf0 RR |
549 | } |
550 | } | |
551 | #endif // wxUSE_TOOLTIPS | |
552 | ||
b4071e91 RR |
553 | bool wxRadioBox::IsOwnGtkWindow( GdkWindow *window ) |
554 | { | |
27c78e45 VZ |
555 | if (window == m_widget->window) |
556 | return true; | |
29006414 | 557 | |
222ed1d6 | 558 | wxList::compatibility_iterator node = m_boxes.GetFirst(); |
907789a0 RR |
559 | while (node) |
560 | { | |
b1d4dd7a | 561 | GtkWidget *button = GTK_WIDGET( node->GetData() ); |
29006414 | 562 | |
27c78e45 VZ |
563 | if (window == button->window) |
564 | return true; | |
29006414 | 565 | |
b1d4dd7a | 566 | node = node->GetNext(); |
907789a0 | 567 | } |
29006414 | 568 | |
b4efc9b9 | 569 | return false; |
b4071e91 | 570 | } |
dcf924a3 | 571 | |
f6bcfd97 BP |
572 | void wxRadioBox::OnInternalIdle() |
573 | { | |
574 | if ( m_lostFocus ) | |
575 | { | |
b4efc9b9 WS |
576 | m_hasFocus = false; |
577 | m_lostFocus = false; | |
f6bcfd97 BP |
578 | |
579 | wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() ); | |
580 | event.SetEventObject( this ); | |
581 | ||
582 | (void)GetEventHandler()->ProcessEvent( event ); | |
583 | } | |
d7fa7eaa RR |
584 | |
585 | if (g_delayedFocus == this) | |
586 | { | |
587 | if (GTK_WIDGET_REALIZED(m_widget)) | |
588 | { | |
589 | g_delayedFocus = NULL; | |
590 | SetFocus(); | |
591 | } | |
592 | } | |
f6bcfd97 BP |
593 | } |
594 | ||
9d522606 RD |
595 | // static |
596 | wxVisualAttributes | |
597 | wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
598 | { | |
599 | wxVisualAttributes attr; | |
bc0eb46c VS |
600 | // NB: we need toplevel window so that GTK+ can find the right style |
601 | GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
9d522606 | 602 | GtkWidget* widget = gtk_radio_button_new_with_label(NULL, ""); |
bc0eb46c | 603 | gtk_container_add(GTK_CONTAINER(wnd), widget); |
9d522606 | 604 | attr = GetDefaultAttributesFromGTKWidget(widget); |
bc0eb46c | 605 | gtk_widget_destroy(wnd); |
9d522606 RD |
606 | return attr; |
607 | } | |
608 | ||
f6bcfd97 | 609 | #endif // wxUSE_RADIOBOX |