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