Make use of GTK 2.4 GtkComboBox if it is available,
[wxWidgets.git] / src / gtk / combobox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/combobox.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #include "wx/combobox.h"
14
15 #if wxUSE_COMBOBOX
16
17 #include "wx/settings.h"
18 #include "wx/arrstr.h"
19 #include "wx/intl.h"
20
21 #include "wx/textctrl.h" // for wxEVT_COMMAND_TEXT_UPDATED
22
23 #include "wx/gtk/private.h"
24
25 //-----------------------------------------------------------------------------
26 // idle system
27 //-----------------------------------------------------------------------------
28
29 extern void wxapp_install_idle_handler();
30 extern bool g_isIdle;
31
32 //-----------------------------------------------------------------------------
33 // data
34 //-----------------------------------------------------------------------------
35
36 extern bool g_blockEventsOnDrag;
37 static int g_SelectionBeforePopup = wxID_NONE; // this means the popup is hidden
38
39 //-----------------------------------------------------------------------------
40 // "changed" - typing and list item matches get changed, select-child
41 // if it doesn't match an item then just get a single changed
42 //-----------------------------------------------------------------------------
43
44 extern "C" {
45 static void
46 gtkcombo_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
47 {
48 if (g_isIdle) wxapp_install_idle_handler();
49
50 if (combo->m_ignoreNextUpdate)
51 {
52 combo->m_ignoreNextUpdate = false;
53 return;
54 }
55
56 if (!combo->m_hasVMT) return;
57
58 wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
59 event.SetString( combo->GetValue() );
60 event.SetEventObject( combo );
61 combo->GetEventHandler()->ProcessEvent( event );
62 }
63 }
64
65 extern "C" {
66 static void
67 gtkcombo_dummy_callback(GtkEntry *WXUNUSED(entry), GtkCombo *WXUNUSED(combo))
68 {
69 }
70 }
71
72 extern "C" {
73 static void
74 gtkcombo_popup_hide_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo)
75 {
76 // when the popup is hidden, throw a SELECTED event only if the combobox
77 // selection changed.
78 const int curSelection = combo->GetCurrentSelection();
79
80 const bool hasChanged = curSelection != g_SelectionBeforePopup;
81
82 // reset the selection flag to value meaning that it is hidden and do it
83 // now, before generating the events, so that GetSelection() returns the
84 // new value from the event handler
85 g_SelectionBeforePopup = wxID_NONE;
86
87 if ( hasChanged )
88 {
89 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
90 event.SetInt( curSelection );
91 event.SetString( combo->GetStringSelection() );
92 event.SetEventObject( combo );
93 combo->GetEventHandler()->ProcessEvent( event );
94
95 // for consistency with the other ports, send TEXT event
96 wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
97 event2.SetString( combo->GetStringSelection() );
98 event2.SetEventObject( combo );
99 combo->GetEventHandler()->ProcessEvent( event2 );
100 }
101 }
102 }
103
104 extern "C" {
105 static void
106 gtkcombo_popup_show_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo)
107 {
108 // store the combobox selection value before the popup is shown
109 g_SelectionBeforePopup = combo->GetCurrentSelection();
110 }
111 }
112
113 //-----------------------------------------------------------------------------
114 // "select-child" - click/cursor get select-child, changed, select-child
115 //-----------------------------------------------------------------------------
116
117 extern "C" {
118 static void
119 gtkcombo_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(widget), wxComboBox *combo )
120 {
121 if (g_isIdle) wxapp_install_idle_handler();
122
123 if (!combo->m_hasVMT) return;
124
125 if (g_blockEventsOnDrag) return;
126
127 int curSelection = combo->GetCurrentSelection();
128
129 if (combo->m_prevSelection == curSelection) return;
130
131 GtkWidget *list = GTK_COMBO(combo->m_widget)->list;
132 gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection );
133
134 combo->m_prevSelection = curSelection;
135
136 // Quickly set the value of the combo box
137 // as GTK+ does that only AFTER the event
138 // is sent.
139 g_signal_handlers_disconnect_by_func (GTK_COMBO (combo->GetHandle())->entry,
140 (gpointer) gtkcombo_text_changed_callback,
141 combo);
142 combo->SetValue( combo->GetStringSelection() );
143 g_signal_connect_after (GTK_COMBO (combo->GetHandle())->entry, "changed",
144 G_CALLBACK (gtkcombo_text_changed_callback), combo);
145
146 // throw a SELECTED event only if the combobox popup is hidden (wxID_NONE)
147 // because when combobox popup is shown, gtkcombo_combo_select_child_callback is
148 // called each times the mouse is over an item with a pressed button so a lot
149 // of SELECTED event could be generated if the user keep the mouse button down
150 // and select other items ...
151 if (g_SelectionBeforePopup == wxID_NONE)
152 {
153 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
154 event.SetInt( curSelection );
155 event.SetString( combo->GetStringSelection() );
156 event.SetEventObject( combo );
157 combo->GetEventHandler()->ProcessEvent( event );
158
159 // for consistency with the other ports, don't generate text update
160 // events while the user is browsing the combobox neither
161 wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
162 event2.SetString( combo->GetValue() );
163 event2.SetEventObject( combo );
164 combo->GetEventHandler()->ProcessEvent( event2 );
165 }
166 }
167 }
168
169 #ifdef __WXGTK24__
170 extern "C" {
171 static void
172 gtkcombobox_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
173 {
174 if (g_isIdle) wxapp_install_idle_handler();
175
176 if (!combo->m_hasVMT) return;
177
178 wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
179 event.SetString( combo->GetValue() );
180 event.SetEventObject( combo );
181 combo->GetEventHandler()->ProcessEvent( event );
182 }
183 }
184
185 extern "C" {
186 static void
187 gtkcombobox_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
188 {
189 if (g_isIdle) wxapp_install_idle_handler();
190
191 if (!combo->m_hasVMT) return;
192
193 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
194 event.SetInt( combo->GetSelection() );
195 event.SetString( combo->GetStringSelection() );
196 event.SetEventObject( combo );
197 combo->GetEventHandler()->ProcessEvent( event );
198 }
199 }
200 #endif
201
202 //-----------------------------------------------------------------------------
203 // wxComboBox
204 //-----------------------------------------------------------------------------
205
206 IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl)
207
208 BEGIN_EVENT_TABLE(wxComboBox, wxControl)
209 EVT_SIZE(wxComboBox::OnSize)
210 EVT_CHAR(wxComboBox::OnChar)
211
212 EVT_MENU(wxID_CUT, wxComboBox::OnCut)
213 EVT_MENU(wxID_COPY, wxComboBox::OnCopy)
214 EVT_MENU(wxID_PASTE, wxComboBox::OnPaste)
215 EVT_MENU(wxID_UNDO, wxComboBox::OnUndo)
216 EVT_MENU(wxID_REDO, wxComboBox::OnRedo)
217 EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete)
218 EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll)
219
220 EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut)
221 EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy)
222 EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste)
223 EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo)
224 EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo)
225 EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete)
226 EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll)
227 END_EVENT_TABLE()
228
229 bool wxComboBox::Create( wxWindow *parent, wxWindowID id,
230 const wxString& value,
231 const wxPoint& pos, const wxSize& size,
232 const wxArrayString& choices,
233 long style, const wxValidator& validator,
234 const wxString& name )
235 {
236 wxCArrayString chs(choices);
237
238 return Create( parent, id, value, pos, size, chs.GetCount(),
239 chs.GetStrings(), style, validator, name );
240 }
241
242 bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
243 const wxPoint& pos, const wxSize& size,
244 int n, const wxString choices[],
245 long style, const wxValidator& validator,
246 const wxString& name )
247 {
248 m_ignoreNextUpdate = false;
249 m_needParent = true;
250 m_acceptsFocus = true;
251 m_prevSelection = 0;
252
253 if (!PreCreation( parent, pos, size ) ||
254 !CreateBase( parent, id, pos, size, style, validator, name ))
255 {
256 wxFAIL_MSG( wxT("wxComboBox creation failed") );
257 return false;
258 }
259
260 #ifdef __WXGTK24__
261 if (!gtk_check_version(2,4,0))
262 {
263 m_widget = gtk_combo_box_entry_new_text();
264 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
265
266 gtk_entry_set_editable( GTK_ENTRY( GTK_BIN(m_widget)->child ), TRUE );
267
268 for (int i = 0; i < n; i++)
269 {
270 gtk_combo_box_append_text( combobox, wxGTK_CONV( choices[i] ) );
271
272 m_clientDataList.Append( (wxObject*)NULL );
273 m_clientObjectList.Append( (wxObject*)NULL );
274 }
275 }
276 else
277 #endif
278 {
279 m_widget = gtk_combo_new();
280 GtkCombo* combo = GTK_COMBO(m_widget);
281
282 // Disable GTK's broken events ...
283 g_signal_handler_disconnect (combo->entry, combo->entry_change_id);
284 // ... and add surrogate handler.
285 combo->entry_change_id = g_signal_connect (combo->entry, "changed",
286 G_CALLBACK (gtkcombo_dummy_callback),
287 combo);
288
289 // make it more useable
290 gtk_combo_set_use_arrows_always( GTK_COMBO(m_widget), TRUE );
291
292 // and case-sensitive
293 gtk_combo_set_case_sensitive( GTK_COMBO(m_widget), TRUE );
294
295 if (style & wxNO_BORDER)
296 g_object_set( GTK_ENTRY( combo->entry ), "has-frame", FALSE, NULL );
297
298 GtkWidget *list = combo->list;
299
300 for (int i = 0; i < n; i++)
301 {
302 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( choices[i] ) );
303
304 m_clientDataList.Append( (wxObject*)NULL );
305 m_clientObjectList.Append( (wxObject*)NULL );
306
307 gtk_container_add( GTK_CONTAINER(list), list_item );
308
309 gtk_widget_show( list_item );
310 }
311 }
312
313
314 m_parent->DoAddChild( this );
315
316 GtkEntry *entry = NULL;
317 #ifdef __WXGTK24__
318 if (!gtk_check_version(2,4,0))
319 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
320 else
321 #endif
322 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
323
324 m_focusWidget = GTK_WIDGET( entry );
325
326 PostCreation(size);
327
328 #ifdef __WXGTK24__
329 if (!gtk_check_version(2,4,0))
330 ConnectWidget( m_widget );
331 else
332 #endif
333 ConnectWidget( GTK_COMBO(m_widget)->button );
334
335 #ifdef __WXGTK24__
336 if (!gtk_check_version(2,4,0))
337 {
338 gtk_entry_set_text( entry, wxGTK_CONV(value) );
339
340 if (style & wxCB_READONLY)
341 gtk_entry_set_editable( entry, FALSE );
342
343 g_signal_connect_after (entry, "changed",
344 G_CALLBACK (gtkcombobox_text_changed_callback), this);
345
346 g_signal_connect_after (m_widget, "changed",
347 G_CALLBACK (gtkcombobox_changed_callback), this);
348 }
349 else
350 #endif
351 {
352 GtkCombo *combo = GTK_COMBO(m_widget);
353 // MSW's combo box shows the value and the selection is -1
354 gtk_entry_set_text( entry, wxGTK_CONV(value) );
355 gtk_list_unselect_all( GTK_LIST(combo->list) );
356
357 if (style & wxCB_READONLY)
358 gtk_entry_set_editable( entry, FALSE );
359
360 // "show" and "hide" events are generated when user click on the combobox button which popups a list
361 // this list is the "popwin" gtk widget
362 g_signal_connect (GTK_COMBO(combo)->popwin, "hide",
363 G_CALLBACK (gtkcombo_popup_hide_callback), this);
364 g_signal_connect (GTK_COMBO(combo)->popwin, "show",
365 G_CALLBACK (gtkcombo_popup_show_callback), this);
366 g_signal_connect_after (combo->list, "select-child",
367 G_CALLBACK (gtkcombo_combo_select_child_callback),
368 this);
369 g_signal_connect_after (entry, "changed",
370 G_CALLBACK (gtkcombo_text_changed_callback), this);
371
372 // This is required for tool bar support
373 // Doesn't currently work
374 // wxSize setsize = GetSize();
375 // gtk_widget_set_size_request( m_widget, setsize.x, setsize.y );
376 }
377
378 SetBestSize(size); // need this too because this is a wxControlWithItems
379
380
381 return true;
382 }
383
384 wxComboBox::~wxComboBox()
385 {
386 wxList::compatibility_iterator node = m_clientObjectList.GetFirst();
387 while (node)
388 {
389 wxClientData *cd = (wxClientData*)node->GetData();
390 if (cd) delete cd;
391 node = node->GetNext();
392 }
393 m_clientObjectList.Clear();
394
395 m_clientDataList.Clear();
396 }
397
398 void wxComboBox::SetFocus()
399 {
400 if ( m_hasFocus )
401 {
402 // don't do anything if we already have focus
403 return;
404 }
405
406 gtk_widget_grab_focus( m_focusWidget );
407 }
408
409 int wxComboBox::DoAppend( const wxString &item )
410 {
411 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
412
413 #ifdef __WXGTK24__
414 if (!gtk_check_version(2,4,0))
415 {
416 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
417 gtk_combo_box_append_text( combobox, wxGTK_CONV( item ) );
418 }
419 else
420 #endif
421 {
422 DisableEvents();
423
424 GtkWidget *list = GTK_COMBO(m_widget)->list;
425 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
426
427 gtk_container_add( GTK_CONTAINER(list), list_item );
428
429 if (GTK_WIDGET_REALIZED(m_widget))
430 {
431 gtk_widget_realize( list_item );
432 gtk_widget_realize( GTK_BIN(list_item)->child );
433 }
434
435 // Apply current widget style to the new list_item
436 GtkRcStyle *style = CreateWidgetStyle();
437 if (style)
438 {
439 gtk_widget_modify_style( GTK_WIDGET( list_item ), style );
440 GtkBin *bin = GTK_BIN( list_item );
441 GtkWidget *label = GTK_WIDGET( bin->child );
442 gtk_widget_modify_style( label, style );
443 gtk_rc_style_unref( style );
444 }
445
446 gtk_widget_show( list_item );
447
448 EnableEvents();
449 }
450
451 const int count = GetCount();
452
453 if ( (int)m_clientDataList.GetCount() < count )
454 m_clientDataList.Append( (wxObject*) NULL );
455 if ( (int)m_clientObjectList.GetCount() < count )
456 m_clientObjectList.Append( (wxObject*) NULL );
457
458 InvalidateBestSize();
459
460 return count - 1;
461 }
462
463 int wxComboBox::DoInsert( const wxString &item, int pos )
464 {
465 wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT), -1,
466 wxT("can't insert into sorted list"));
467
468 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
469
470 int count = GetCount();
471 wxCHECK_MSG( (pos >= 0) && (pos <= count), -1, wxT("invalid index") );
472
473 if (pos == count)
474 return Append(item);
475
476 #ifdef __WXGTK24__
477 if (!gtk_check_version(2,4,0))
478 {
479 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
480 gtk_combo_box_insert_text( combobox, pos, wxGTK_CONV( item ) );
481 }
482 else
483 #endif
484 {
485 DisableEvents();
486
487 GtkWidget *list = GTK_COMBO(m_widget)->list;
488 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
489
490 GList *gitem_list = g_list_alloc ();
491 gitem_list->data = list_item;
492 gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );
493
494 if (GTK_WIDGET_REALIZED(m_widget))
495 {
496 gtk_widget_realize( list_item );
497 gtk_widget_realize( GTK_BIN(list_item)->child );
498
499 ApplyWidgetStyle();
500 }
501
502 gtk_widget_show( list_item );
503
504 EnableEvents();
505 }
506
507 count = GetCount();
508
509 if ( (int)m_clientDataList.GetCount() < count )
510 m_clientDataList.Insert( pos, (wxObject*) NULL );
511 if ( (int)m_clientObjectList.GetCount() < count )
512 m_clientObjectList.Insert( pos, (wxObject*) NULL );
513
514 InvalidateBestSize();
515
516 return pos;
517 }
518
519 void wxComboBox::DoSetItemClientData( int n, void* clientData )
520 {
521 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
522
523 wxList::compatibility_iterator node = m_clientDataList.Item( n );
524 if (!node) return;
525
526 node->SetData( (wxObject*) clientData );
527 }
528
529 void* wxComboBox::DoGetItemClientData( int n ) const
530 {
531 wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
532
533 wxList::compatibility_iterator node = m_clientDataList.Item( n );
534
535 return node ? node->GetData() : NULL;
536 }
537
538 void wxComboBox::DoSetItemClientObject( int n, wxClientData* clientData )
539 {
540 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
541
542 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
543 if (!node) return;
544
545 // wxItemContainer already deletes data for us
546
547 node->SetData( (wxObject*) clientData );
548 }
549
550 wxClientData* wxComboBox::DoGetItemClientObject( int n ) const
551 {
552 wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") );
553
554 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
555
556 return node ? (wxClientData*) node->GetData() : NULL;
557 }
558
559 void wxComboBox::Clear()
560 {
561 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
562
563 DisableEvents();
564
565 #ifdef __WXGTK24__
566 if (!gtk_check_version(2,4,0))
567 {
568 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
569 int i;
570 for (i = 0; i++; i < GetCount())
571 gtk_combo_box_remove_text( combobox, 0 );
572 }
573 else
574 #endif
575 {
576 GtkWidget *list = GTK_COMBO(m_widget)->list;
577 gtk_list_clear_items( GTK_LIST(list), 0, GetCount() );
578 }
579
580 wxList::compatibility_iterator node = m_clientObjectList.GetFirst();
581 while (node)
582 {
583 wxClientData *cd = (wxClientData*)node->GetData();
584 if (cd) delete cd;
585 node = node->GetNext();
586 }
587 m_clientObjectList.Clear();
588
589 m_clientDataList.Clear();
590
591 EnableEvents();
592
593 InvalidateBestSize();
594 }
595
596 void wxComboBox::Delete( int n )
597 {
598 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
599
600 #ifdef __WXGTK24__
601 if (!gtk_check_version(2,4,0))
602 {
603 wxCHECK_RET( (n >= 0) && (n <= GetCount()), wxT("invalid index") );
604
605 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
606 gtk_combo_box_remove_text( combobox, n );
607 }
608 else
609 #endif
610 {
611 GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list );
612
613 GList *child = g_list_nth( listbox->children, n );
614
615 if (!child)
616 {
617 wxFAIL_MSG(wxT("wrong index"));
618 return;
619 }
620
621 DisableEvents();
622
623 GList *list = g_list_append( (GList*) NULL, child->data );
624 gtk_list_remove_items( listbox, list );
625 g_list_free( list );
626
627 EnableEvents();
628 }
629
630 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
631 if (node)
632 {
633 wxClientData *cd = (wxClientData*)node->GetData();
634 if (cd) delete cd;
635 m_clientObjectList.Erase( node );
636 }
637
638 node = m_clientDataList.Item( n );
639 if (node)
640 m_clientDataList.Erase( node );
641
642 InvalidateBestSize();
643 }
644
645 void wxComboBox::SetString(int n, const wxString &text)
646 {
647 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
648
649 #ifdef __WXGTK24__
650 if (!gtk_check_version(2,4,0))
651 {
652 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
653 wxCHECK_RET( (n >= 0) && (n <= GetCount()), wxT("invalid index") );
654
655 GtkTreeModel *model = gtk_combo_box_get_model( combobox );
656 GtkTreeIter iter;
657 if (gtk_tree_model_iter_nth_child (model, &iter, NULL, n))
658 {
659 GValue value = { 0, };
660 g_value_init( &value, G_TYPE_STRING );
661 g_value_set_string( &value, wxGTK_CONV( text ) );
662 gtk_list_store_set_value( GTK_LIST_STORE(model), &iter, 0, &value );
663 g_value_unset( &value );
664 }
665 }
666 else
667 #endif
668 {
669 GtkWidget *list = GTK_COMBO(m_widget)->list;
670
671 GList *child = g_list_nth( GTK_LIST(list)->children, n );
672 if (child)
673 {
674 GtkBin *bin = GTK_BIN( child->data );
675 GtkLabel *label = GTK_LABEL( bin->child );
676 gtk_label_set_text(label, wxGTK_CONV(text));
677 }
678 else
679 {
680 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
681 }
682 }
683
684 InvalidateBestSize();
685 }
686
687 int wxComboBox::FindString( const wxString &item, bool bCase ) const
688 {
689 wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid combobox") );
690
691 #ifdef __WXGTK24__
692 if (!gtk_check_version(2,4,0))
693 {
694 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
695 GtkTreeModel* model = gtk_combo_box_get_model( combobox );
696 GtkTreeIter iter;
697 gtk_tree_model_get_iter_first( model, &iter );
698 if (!gtk_list_store_iter_is_valid(GTK_LIST_STORE(model), &iter ))
699 return -1;
700 int count = 0;
701 do
702 {
703 GValue value = { 0, };
704 gtk_tree_model_get_value( model, &iter, 0, &value );
705 wxString str = wxGTK_CONV_BACK( g_value_get_string( &value ) );
706 g_value_unset( &value );
707
708 if (item.IsSameAs( str, bCase ) )
709 return count;
710
711 count++;
712
713 } while (gtk_tree_model_iter_next( model, &iter ));
714 }
715 else
716 #endif
717 {
718 GtkWidget *list = GTK_COMBO(m_widget)->list;
719
720 GList *child = GTK_LIST(list)->children;
721 int count = 0;
722 while (child)
723 {
724 GtkBin *bin = GTK_BIN( child->data );
725 GtkLabel *label = GTK_LABEL( bin->child );
726 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
727
728 if (item.IsSameAs( str , bCase ) )
729 return count;
730
731 count++;
732 child = child->next;
733 }
734 }
735
736 return wxNOT_FOUND;
737 }
738
739 int wxComboBox::GetSelection() const
740 {
741 #ifdef __WXGTK24__
742 if (!gtk_check_version(2,4,0))
743 {
744 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
745 return gtk_combo_box_get_active( combobox );
746 }
747 else
748 #endif
749 // if the popup is currently opened, use the selection as it had been
750 // before it dropped down
751 return g_SelectionBeforePopup == wxID_NONE ? GetCurrentSelection()
752 : g_SelectionBeforePopup;
753 }
754
755 int wxComboBox::GetCurrentSelection() const
756 {
757 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
758
759 #ifdef __WXGTK24__
760 if (!gtk_check_version(2,4,0))
761 {
762 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
763 return gtk_combo_box_get_active( combobox );
764 }
765 else
766 #endif
767 {
768 GtkWidget *list = GTK_COMBO(m_widget)->list;
769
770 GList *selection = GTK_LIST(list)->selection;
771 if (selection)
772 {
773 GList *child = GTK_LIST(list)->children;
774 int count = 0;
775 while (child)
776 {
777 if (child->data == selection->data) return count;
778 count++;
779 child = child->next;
780 }
781 }
782 }
783
784 return -1;
785 }
786
787 wxString wxComboBox::GetString( int n ) const
788 {
789 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid combobox") );
790
791 wxString str;
792
793 #ifdef __WXGTK24__
794 if (!gtk_check_version(2,4,0))
795 {
796 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
797 GtkTreeModel *model = gtk_combo_box_get_model( combobox );
798 GtkTreeIter iter;
799 if (gtk_tree_model_iter_nth_child (model, &iter, NULL, n))
800 {
801 GValue value = { 0, };
802 gtk_tree_model_get_value( model, &iter, 0, &value );
803 wxString tmp = wxGTK_CONV_BACK( g_value_get_string( &value ) );
804 g_value_unset( &value );
805 return tmp;
806 }
807 }
808 else
809 #endif
810 {
811 GtkWidget *list = GTK_COMBO(m_widget)->list;
812
813 GList *child = g_list_nth( GTK_LIST(list)->children, n );
814 if (child)
815 {
816 GtkBin *bin = GTK_BIN( child->data );
817 GtkLabel *label = GTK_LABEL( bin->child );
818 str = wxGTK_CONV_BACK( gtk_label_get_text(label) );
819 }
820 else
821 {
822 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
823 }
824 }
825
826 return str;
827 }
828
829 wxString wxComboBox::GetStringSelection() const
830 {
831 wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid combobox") );
832
833 #ifdef __WXGTK24__
834 if (!gtk_check_version(2,4,0))
835 {
836 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
837 int sel = gtk_combo_box_get_active( combobox );
838 if (sel == -1)
839 return wxEmptyString;
840 return GetString( sel );
841 }
842 else
843 #endif
844 {
845 GtkWidget *list = GTK_COMBO(m_widget)->list;
846
847 GList *selection = GTK_LIST(list)->selection;
848 if (selection)
849 {
850 GtkBin *bin = GTK_BIN( selection->data );
851 GtkLabel *label = GTK_LABEL( bin->child );
852 wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
853 return tmp;
854 }
855
856 wxFAIL_MSG( wxT("wxComboBox: no selection") );
857 }
858
859 return wxEmptyString;
860 }
861
862 int wxComboBox::GetCount() const
863 {
864 wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") );
865
866 #ifdef __WXGTK24__
867 if (!gtk_check_version(2,4,0))
868 {
869 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
870 GtkTreeModel* model = gtk_combo_box_get_model( combobox );
871 GtkTreeIter iter;
872 gtk_tree_model_get_iter_first( model, &iter );
873 if (!gtk_list_store_iter_is_valid(GTK_LIST_STORE(model), &iter ))
874 return 0;
875 int ret = 1;
876 while (gtk_tree_model_iter_next( model, &iter ))
877 ret++;
878 return ret;
879 }
880 else
881 #endif
882 {
883 GtkWidget *list = GTK_COMBO(m_widget)->list;
884
885 GList *child = GTK_LIST(list)->children;
886 int count = 0;
887 while (child) { count++; child = child->next; }
888 return count;
889 }
890
891 return 0;
892 }
893
894 void wxComboBox::SetSelection( int n )
895 {
896 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
897
898 DisableEvents();
899
900 #ifdef __WXGTK24__
901 if (!gtk_check_version(2,4,0))
902 {
903 GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
904 gtk_combo_box_set_active( combobox, n );
905 }
906 else
907 #endif
908 {
909 GtkWidget *list = GTK_COMBO(m_widget)->list;
910 gtk_list_unselect_item( GTK_LIST(list), m_prevSelection );
911 gtk_list_select_item( GTK_LIST(list), n );
912 m_prevSelection = n;
913 }
914
915 EnableEvents();
916 }
917
918 wxString wxComboBox::GetValue() const
919 {
920 GtkEntry *entry = NULL;
921 #ifdef __WXGTK24__
922 if (!gtk_check_version(2,4,0))
923 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
924 else
925 #endif
926 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
927
928 wxString tmp( wxGTK_CONV_BACK( gtk_entry_get_text( entry ) ) );
929
930 #if 0
931 for (int i = 0; i < wxStrlen(tmp.c_str()) +1; i++)
932 {
933 wxChar c = tmp[i];
934 printf( "%d ", (int) (c) );
935 }
936 printf( "\n" );
937 #endif
938
939 return tmp;
940 }
941
942 void wxComboBox::SetValue( const wxString& value )
943 {
944 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
945
946 GtkEntry *entry = NULL;
947 #ifdef __WXGTK24__
948 if (!gtk_check_version(2,4,0))
949 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
950 else
951 #endif
952 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
953
954 wxString tmp;
955 if (!value.IsNull()) tmp = value;
956 gtk_entry_set_text( entry, wxGTK_CONV( tmp ) );
957
958 InvalidateBestSize();
959 }
960
961 void wxComboBox::Copy()
962 {
963 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
964
965 GtkEntry *entry = NULL;
966 #ifdef __WXGTK24__
967 if (!gtk_check_version(2,4,0))
968 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
969 else
970 #endif
971 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
972
973 gtk_editable_copy_clipboard(GTK_EDITABLE(entry));
974 }
975
976 void wxComboBox::Cut()
977 {
978 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
979
980 GtkEntry *entry = NULL;
981 #ifdef __WXGTK24__
982 if (!gtk_check_version(2,4,0))
983 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
984 else
985 #endif
986 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
987
988 gtk_editable_cut_clipboard(GTK_EDITABLE(entry));
989 }
990
991 void wxComboBox::Paste()
992 {
993 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
994
995 GtkEntry *entry = NULL;
996 #ifdef __WXGTK24__
997 if (!gtk_check_version(2,4,0))
998 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
999 else
1000 #endif
1001 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
1002
1003 gtk_editable_paste_clipboard(GTK_EDITABLE(entry));
1004 }
1005
1006 void wxComboBox::Undo()
1007 {
1008 // TODO
1009 }
1010
1011 void wxComboBox::Redo()
1012 {
1013 // TODO
1014 }
1015
1016 void wxComboBox::SelectAll()
1017 {
1018 SetSelection(0, GetLastPosition());
1019 }
1020
1021 bool wxComboBox::CanUndo() const
1022 {
1023 // TODO
1024 return false;
1025 }
1026
1027 bool wxComboBox::CanRedo() const
1028 {
1029 // TODO
1030 return false;
1031 }
1032
1033 bool wxComboBox::HasSelection() const
1034 {
1035 long from, to;
1036 GetSelection(&from, &to);
1037 return from != to;
1038 }
1039
1040 bool wxComboBox::CanCopy() const
1041 {
1042 // Can copy if there's a selection
1043 return HasSelection();
1044 }
1045
1046 bool wxComboBox::CanCut() const
1047 {
1048 return CanCopy() && IsEditable();
1049 }
1050
1051 bool wxComboBox::CanPaste() const
1052 {
1053 // TODO: check for text on the clipboard
1054 return IsEditable() ;
1055 }
1056
1057 bool wxComboBox::IsEditable() const
1058 {
1059 return !HasFlag(wxCB_READONLY);
1060 }
1061
1062
1063 void wxComboBox::SetInsertionPoint( long pos )
1064 {
1065 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
1066
1067 if ( pos == GetLastPosition() )
1068 pos = -1;
1069
1070 GtkEntry *entry = NULL;
1071 #ifdef __WXGTK24__
1072 if (!gtk_check_version(2,4,0))
1073 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
1074 else
1075 #endif
1076 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
1077
1078 gtk_entry_set_position( entry, (int)pos );
1079 }
1080
1081 long wxComboBox::GetInsertionPoint() const
1082 {
1083 GtkEntry *entry = NULL;
1084 #ifdef __WXGTK24__
1085 if (!gtk_check_version(2,4,0))
1086 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
1087 else
1088 #endif
1089 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
1090
1091 return (long) gtk_editable_get_position(GTK_EDITABLE(entry));
1092 }
1093
1094 wxTextPos wxComboBox::GetLastPosition() const
1095 {
1096 GtkEntry *entry = NULL;
1097 #ifdef __WXGTK24__
1098 if (!gtk_check_version(2,4,0))
1099 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
1100 else
1101 #endif
1102 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
1103
1104 int pos = entry->text_length;
1105 return (long) pos-1;
1106 }
1107
1108 void wxComboBox::Replace( long from, long to, const wxString& value )
1109 {
1110 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
1111
1112 GtkEntry *entry = NULL;
1113 #ifdef __WXGTK24__
1114 if (!gtk_check_version(2,4,0))
1115 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
1116 else
1117 #endif
1118 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
1119
1120 gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
1121 if (value.IsNull()) return;
1122 gint pos = (gint)to;
1123
1124 #if wxUSE_UNICODE
1125 wxCharBuffer buffer = wxConvUTF8.cWX2MB( value );
1126 gtk_editable_insert_text( GTK_EDITABLE(entry), (const char*) buffer, strlen( (const char*) buffer ), &pos );
1127 #else
1128 gtk_editable_insert_text( GTK_EDITABLE(entry), value.c_str(), value.Length(), &pos );
1129 #endif
1130 }
1131
1132 void wxComboBox::SetSelection( long from, long to )
1133 {
1134 GtkEntry *entry = NULL;
1135 #ifdef __WXGTK24__
1136 if (!gtk_check_version(2,4,0))
1137 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
1138 else
1139 #endif
1140 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
1141
1142 gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to );
1143 }
1144
1145 void wxComboBox::GetSelection( long* from, long* to ) const
1146 {
1147 GtkEntry *entry = NULL;
1148 #ifdef __WXGTK24__
1149 if (!gtk_check_version(2,4,0))
1150 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
1151 else
1152 #endif
1153 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
1154
1155 if (IsEditable())
1156 {
1157 GtkEditable *editable = GTK_EDITABLE(entry);
1158 gint start, end;
1159 gtk_editable_get_selection_bounds(editable, & start, & end);
1160 *from = start;
1161 *to = end;
1162 }
1163 }
1164
1165 void wxComboBox::SetEditable( bool editable )
1166 {
1167 GtkEntry *entry = NULL;
1168 #ifdef __WXGTK24__
1169 if (!gtk_check_version(2,4,0))
1170 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
1171 else
1172 #endif
1173 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
1174
1175 gtk_entry_set_editable( GTK_ENTRY(entry), editable );
1176 }
1177
1178 void wxComboBox::OnChar( wxKeyEvent &event )
1179 {
1180 if ( event.GetKeyCode() == WXK_RETURN )
1181 {
1182 // GTK automatically selects an item if its in the list
1183 wxCommandEvent eventEnter(wxEVT_COMMAND_TEXT_ENTER, GetId());
1184 eventEnter.SetString( GetValue() );
1185 eventEnter.SetInt( GetSelection() );
1186 eventEnter.SetEventObject( this );
1187
1188 if (!GetEventHandler()->ProcessEvent( eventEnter ))
1189 {
1190 // This will invoke the dialog default action, such
1191 // as the clicking the default button.
1192
1193 wxWindow *top_frame = m_parent;
1194 while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
1195 top_frame = top_frame->GetParent();
1196
1197 if (top_frame && GTK_IS_WINDOW(top_frame->m_widget))
1198 {
1199 GtkWindow *window = GTK_WINDOW(top_frame->m_widget);
1200
1201 if (window->default_widget)
1202 gtk_widget_activate (window->default_widget);
1203 }
1204 }
1205
1206 // Catch GTK event so that GTK doesn't open the drop
1207 // down list upon RETURN.
1208 return;
1209 }
1210
1211 event.Skip();
1212 }
1213
1214 void wxComboBox::DisableEvents()
1215 {
1216 #ifdef __WXGTK24__
1217 if (!gtk_check_version(2,4,0))
1218 {
1219 g_signal_handlers_disconnect_by_func (GTK_BIN(m_widget)->child,
1220 (gpointer)gtkcombobox_text_changed_callback, this);
1221
1222 g_signal_handlers_disconnect_by_func (m_widget,
1223 (gpointer)gtkcombobox_changed_callback, this);
1224 }
1225 else
1226 #endif
1227 {
1228 g_signal_handlers_disconnect_by_func (GTK_COMBO(m_widget)->list,
1229 (gpointer) gtkcombo_combo_select_child_callback, this);
1230
1231 g_signal_handlers_disconnect_by_func (GTK_COMBO(m_widget)->entry,
1232 (gpointer) gtkcombo_text_changed_callback, this);
1233 }
1234 }
1235
1236 void wxComboBox::EnableEvents()
1237 {
1238 #ifdef __WXGTK24__
1239 if (!gtk_check_version(2,4,0))
1240 {
1241 g_signal_connect_after (GTK_BIN(m_widget)->child, "changed",
1242 G_CALLBACK (gtkcombobox_text_changed_callback), this);
1243
1244 g_signal_connect_after (m_widget, "changed",
1245 G_CALLBACK (gtkcombobox_changed_callback), this);
1246 }
1247 else
1248 #endif
1249 {
1250 g_signal_connect_after (GTK_COMBO(m_widget)->list, "select-child",
1251 G_CALLBACK (gtkcombo_combo_select_child_callback),
1252 this);
1253 g_signal_connect_after (GTK_COMBO(m_widget)->entry, "changed",
1254 G_CALLBACK (gtkcombo_text_changed_callback),
1255 this );
1256 }
1257 }
1258
1259 void wxComboBox::OnSize( wxSizeEvent &event )
1260 {
1261 #ifdef __WXGTK24__
1262 if (!gtk_check_version(2,4,0))
1263 {
1264 // Do nothing
1265 }
1266 else
1267 #endif
1268 {
1269 // NB: In some situations (e.g. on non-first page of a wizard, if the
1270 // size used is default size), GtkCombo widget is resized correctly,
1271 // but it's look is not updated, it's rendered as if it was much wider.
1272 // No other widgets are affected, so it looks like a bug in GTK+.
1273 // Manually requesting resize calculation (as gtk_pizza_set_size does)
1274 // fixes it.
1275 if (GTK_WIDGET_VISIBLE(m_widget))
1276 gtk_widget_queue_resize(m_widget);
1277 }
1278
1279 event.Skip();
1280 }
1281
1282 void wxComboBox::DoApplyWidgetStyle(GtkRcStyle *style)
1283 {
1284 #ifdef __WXGTK24__
1285 if (!gtk_check_version(2,4,0))
1286 {
1287 // Do nothing
1288 }
1289 else
1290 #endif
1291 {
1292 // gtk_widget_modify_style( GTK_COMBO(m_widget)->button, syle );
1293
1294 gtk_widget_modify_style( GTK_COMBO(m_widget)->entry, style );
1295 gtk_widget_modify_style( GTK_COMBO(m_widget)->list, style );
1296
1297 GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
1298 GList *child = list->children;
1299 while (child)
1300 {
1301 gtk_widget_modify_style( GTK_WIDGET(child->data), style );
1302
1303 GtkBin *bin = GTK_BIN(child->data);
1304 gtk_widget_modify_style( bin->child, style );
1305
1306 child = child->next;
1307 }
1308 }
1309 }
1310
1311 GtkWidget* wxComboBox::GetConnectWidget()
1312 {
1313 GtkEntry *entry = NULL;
1314 #ifdef __WXGTK24__
1315 if (!gtk_check_version(2,4,0))
1316 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
1317 else
1318 #endif
1319 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
1320
1321 return GTK_WIDGET( entry );
1322 }
1323
1324 bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
1325 {
1326 GtkEntry *entry = NULL;
1327 #ifdef __WXGTK24__
1328 if (!gtk_check_version(2,4,0))
1329 {
1330 entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
1331 return (window == entry->text_area);
1332 }
1333 else
1334 #endif
1335 {
1336 entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
1337 return ( (window == entry->text_area) ||
1338 (window == GTK_COMBO(m_widget)->button->window ) );
1339 }
1340 }
1341
1342 wxSize wxComboBox::DoGetBestSize() const
1343 {
1344 wxSize ret( wxControl::DoGetBestSize() );
1345
1346 // we know better our horizontal extent: it depends on the longest string
1347 // in the combobox
1348 if ( m_widget )
1349 {
1350 int width;
1351 size_t count = GetCount();
1352 for ( size_t n = 0; n < count; n++ )
1353 {
1354 GetTextExtent( GetString(n), &width, NULL, NULL, NULL );
1355 if ( width > ret.x )
1356 ret.x = width;
1357 }
1358 }
1359
1360 // empty combobox should have some reasonable default size too
1361 if ( ret.x < 100 )
1362 ret.x = 100;
1363
1364 CacheBestSize(ret);
1365 return ret;
1366 }
1367
1368 // static
1369 wxVisualAttributes
1370 wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
1371 {
1372 #ifdef __WXGTK24__
1373 if (!gtk_check_version(2,4,0))
1374 return GetDefaultAttributesFromGTKWidget(gtk_combo_box_entry_new, true);
1375 else
1376 #endif
1377 return GetDefaultAttributesFromGTKWidget(gtk_combo_new, true);
1378 }
1379
1380 // ----------------------------------------------------------------------------
1381 // standard event handling
1382 // ----------------------------------------------------------------------------
1383
1384 void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event))
1385 {
1386 Cut();
1387 }
1388
1389 void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event))
1390 {
1391 Copy();
1392 }
1393
1394 void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event))
1395 {
1396 Paste();
1397 }
1398
1399 void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event))
1400 {
1401 Undo();
1402 }
1403
1404 void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event))
1405 {
1406 Redo();
1407 }
1408
1409 void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event))
1410 {
1411 long from, to;
1412 GetSelection(& from, & to);
1413 if (from != -1 && to != -1)
1414 Remove(from, to);
1415 }
1416
1417 void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event))
1418 {
1419 SetSelection(-1, -1);
1420 }
1421
1422 void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event)
1423 {
1424 event.Enable( CanCut() );
1425 }
1426
1427 void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event)
1428 {
1429 event.Enable( CanCopy() );
1430 }
1431
1432 void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event)
1433 {
1434 event.Enable( CanPaste() );
1435 }
1436
1437 void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event)
1438 {
1439 event.Enable( CanUndo() );
1440 }
1441
1442 void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event)
1443 {
1444 event.Enable( CanRedo() );
1445 }
1446
1447 void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event)
1448 {
1449 event.Enable(HasSelection() && IsEditable()) ;
1450 }
1451
1452 void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
1453 {
1454 event.Enable(GetLastPosition() > 0);
1455 }
1456
1457 #endif