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