1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  11 #pragma implementation "combobox.h" 
  14 // For compilers that support precompilation, includes "wx.h". 
  15 #include "wx/wxprec.h" 
  17 #include "wx/combobox.h" 
  21 #include "wx/settings.h" 
  22 #include "wx/arrstr.h" 
  25 #include "wx/textctrl.h"    // for wxEVT_COMMAND_TEXT_UPDATED 
  27 #include "wx/gtk/private.h" 
  29 //----------------------------------------------------------------------------- 
  31 //----------------------------------------------------------------------------- 
  33 extern void wxapp_install_idle_handler(); 
  36 //----------------------------------------------------------------------------- 
  38 //----------------------------------------------------------------------------- 
  40 extern bool   g_blockEventsOnDrag
; 
  41 static int    g_SelectionBeforePopup 
= wxID_NONE
; // this means the popup is hidden 
  43 //----------------------------------------------------------------------------- 
  44 //  "changed" - typing and list item matches get changed, select-child 
  45 //              if it doesn't match an item then just get a single changed 
  46 //----------------------------------------------------------------------------- 
  50 gtk_text_changed_callback( GtkWidget 
*WXUNUSED(widget
), wxComboBox 
*combo 
) 
  52     if (g_isIdle
) wxapp_install_idle_handler(); 
  54     if (combo
->m_ignoreNextUpdate
) 
  56         combo
->m_ignoreNextUpdate 
= false; 
  60     if (!combo
->m_hasVMT
) return; 
  62     wxCommandEvent 
event( wxEVT_COMMAND_TEXT_UPDATED
, combo
->GetId() ); 
  63     event
.SetString( combo
->GetValue() ); 
  64     event
.SetEventObject( combo 
); 
  65     combo
->GetEventHandler()->ProcessEvent( event 
); 
  71 gtk_dummy_callback(GtkEntry 
*WXUNUSED(entry
), GtkCombo 
*WXUNUSED(combo
)) 
  78 gtk_popup_hide_callback(GtkCombo 
*WXUNUSED(gtk_combo
), wxComboBox 
*combo
) 
  80     // when the popup is hidden, throw a SELECTED event only if the combobox 
  82     int curSelection 
= combo
->GetCurrentSelection(); 
  83     if (g_SelectionBeforePopup 
!= curSelection
) 
  85         wxCommandEvent 
event( wxEVT_COMMAND_COMBOBOX_SELECTED
, combo
->GetId() ); 
  86         event
.SetInt( curSelection 
); 
  87         event
.SetString( combo
->GetStringSelection() ); 
  88         event
.SetEventObject( combo 
); 
  89         combo
->GetEventHandler()->ProcessEvent( event 
); 
  92     // reset the selection flag to value meaning that it is hidden 
  93     g_SelectionBeforePopup 
= wxID_NONE
; 
  99 gtk_popup_show_callback(GtkCombo 
*WXUNUSED(gtk_combo
), wxComboBox 
*combo
) 
 101     // store the combobox selection value before the popup is shown 
 102     g_SelectionBeforePopup 
= combo
->GetCurrentSelection(); 
 106 //----------------------------------------------------------------------------- 
 107 // "select-child" - click/cursor get select-child, changed, select-child 
 108 //----------------------------------------------------------------------------- 
 112 gtk_combo_select_child_callback( GtkList 
*WXUNUSED(list
), GtkWidget 
*WXUNUSED(widget
), wxComboBox 
*combo 
) 
 114     if (g_isIdle
) wxapp_install_idle_handler(); 
 116     if (!combo
->m_hasVMT
) return; 
 118     if (g_blockEventsOnDrag
) return; 
 120     int curSelection 
= combo
->GetCurrentSelection(); 
 122     if (combo
->m_prevSelection 
== curSelection
) return; 
 124     GtkWidget 
*list 
= GTK_COMBO(combo
->m_widget
)->list
; 
 125     gtk_list_unselect_item( GTK_LIST(list
), combo
->m_prevSelection 
); 
 127     combo
->m_prevSelection 
= curSelection
; 
 129     // Quickly set the value of the combo box 
 130     // as GTK+ does that only AFTER the event 
 132     gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(combo
->GetHandle())->entry
), 
 133       GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)combo 
); 
 134     combo
->SetValue( combo
->GetStringSelection() ); 
 135     gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(combo
->GetHandle())->entry
), "changed", 
 136       GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)combo 
); 
 138     // throw a SELECTED event only if the combobox popup is hidden (wxID_NONE) 
 139     // because when combobox popup is shown, gtk_combo_select_child_callback is 
 140     // called each times the mouse is over an item with a pressed button so a lot 
 141     // of SELECTED event could be generated if the user keep the mouse button down 
 142     // and select other items ... 
 143     if (g_SelectionBeforePopup 
== wxID_NONE
) 
 145         wxCommandEvent 
event( wxEVT_COMMAND_COMBOBOX_SELECTED
, combo
->GetId() ); 
 146         event
.SetInt( curSelection 
); 
 147         event
.SetString( combo
->GetStringSelection() ); 
 148         event
.SetEventObject( combo 
); 
 149         combo
->GetEventHandler()->ProcessEvent( event 
); 
 151         // for consistencu with the other ports, don't generate text update 
 152         // events while the user is browsing the combobox neither 
 153         wxCommandEvent 
event2( wxEVT_COMMAND_TEXT_UPDATED
, combo
->GetId() ); 
 154         event2
.SetString( combo
->GetValue() ); 
 155         event2
.SetEventObject( combo 
); 
 156         combo
->GetEventHandler()->ProcessEvent( event2 
); 
 161 //----------------------------------------------------------------------------- 
 163 //----------------------------------------------------------------------------- 
 165 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
,wxControl
) 
 167 BEGIN_EVENT_TABLE(wxComboBox
, wxControl
) 
 168     EVT_SIZE(wxComboBox::OnSize
) 
 169     EVT_CHAR(wxComboBox::OnChar
) 
 171     EVT_MENU(wxID_CUT
, wxComboBox::OnCut
) 
 172     EVT_MENU(wxID_COPY
, wxComboBox::OnCopy
) 
 173     EVT_MENU(wxID_PASTE
, wxComboBox::OnPaste
) 
 174     EVT_MENU(wxID_UNDO
, wxComboBox::OnUndo
) 
 175     EVT_MENU(wxID_REDO
, wxComboBox::OnRedo
) 
 176     EVT_MENU(wxID_CLEAR
, wxComboBox::OnDelete
) 
 177     EVT_MENU(wxID_SELECTALL
, wxComboBox::OnSelectAll
) 
 179     EVT_UPDATE_UI(wxID_CUT
, wxComboBox::OnUpdateCut
) 
 180     EVT_UPDATE_UI(wxID_COPY
, wxComboBox::OnUpdateCopy
) 
 181     EVT_UPDATE_UI(wxID_PASTE
, wxComboBox::OnUpdatePaste
) 
 182     EVT_UPDATE_UI(wxID_UNDO
, wxComboBox::OnUpdateUndo
) 
 183     EVT_UPDATE_UI(wxID_REDO
, wxComboBox::OnUpdateRedo
) 
 184     EVT_UPDATE_UI(wxID_CLEAR
, wxComboBox::OnUpdateDelete
) 
 185     EVT_UPDATE_UI(wxID_SELECTALL
, wxComboBox::OnUpdateSelectAll
) 
 188 bool wxComboBox::Create( wxWindow 
*parent
, wxWindowID id
, 
 189                          const wxString
& value
, 
 190                          const wxPoint
& pos
, const wxSize
& size
, 
 191                          const wxArrayString
& choices
, 
 192                          long style
, const wxValidator
& validator
, 
 193                          const wxString
& name 
) 
 195     wxCArrayString 
chs(choices
); 
 197     return Create( parent
, id
, value
, pos
, size
, chs
.GetCount(), 
 198                    chs
.GetStrings(), style
, validator
, name 
); 
 201 bool wxComboBox::Create( wxWindow 
*parent
, wxWindowID id
, const wxString
& value
, 
 202                          const wxPoint
& pos
, const wxSize
& size
, 
 203                          int n
, const wxString choices
[], 
 204                          long style
, const wxValidator
& validator
, 
 205                          const wxString
& name 
) 
 207     m_ignoreNextUpdate 
= false; 
 209     m_acceptsFocus 
= true; 
 212     if (!PreCreation( parent
, pos
, size 
) || 
 213         !CreateBase( parent
, id
, pos
, size
, style
, validator
, name 
)) 
 215         wxFAIL_MSG( wxT("wxComboBox creation failed") ); 
 219     m_widget 
= gtk_combo_new(); 
 220     GtkCombo 
*combo 
= GTK_COMBO(m_widget
); 
 222     // Disable GTK's broken events ... 
 223     gtk_signal_disconnect( GTK_OBJECT(combo
->entry
), combo
->entry_change_id 
); 
 224     // ... and add surogate handler. 
 225     combo
->entry_change_id 
= gtk_signal_connect (GTK_OBJECT (combo
->entry
), "changed", 
 226                   (GtkSignalFunc
) gtk_dummy_callback
, combo
); 
 228     // make it more useable 
 229     gtk_combo_set_use_arrows_always( GTK_COMBO(m_widget
), TRUE 
); 
 231     // and case-sensitive 
 232     gtk_combo_set_case_sensitive( GTK_COMBO(m_widget
), TRUE 
); 
 235     if (style 
& wxNO_BORDER
) 
 236         g_object_set( GTK_ENTRY( combo
->entry 
), "has-frame", FALSE
, NULL 
); 
 239     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 242     // gtk_list_set_selection_mode( GTK_LIST(list), GTK_SELECTION_MULTIPLE ); 
 245     for (int i 
= 0; i 
< n
; i
++) 
 247         GtkWidget 
*list_item 
= gtk_list_item_new_with_label( wxGTK_CONV( choices
[i
] ) ); 
 249         m_clientDataList
.Append( (wxObject
*)NULL 
); 
 250         m_clientObjectList
.Append( (wxObject
*)NULL 
); 
 252         gtk_container_add( GTK_CONTAINER(list
), list_item 
); 
 254         gtk_widget_show( list_item 
); 
 257     m_parent
->DoAddChild( this ); 
 259     m_focusWidget 
= combo
->entry
; 
 263     ConnectWidget( combo
->button 
); 
 265     // MSW's combo box shows the value and the selection is -1 
 266     gtk_entry_set_text( GTK_ENTRY(combo
->entry
), wxGTK_CONV(value
) ); 
 267     gtk_list_unselect_all( GTK_LIST(combo
->list
) ); 
 269     if (style 
& wxCB_READONLY
) 
 270         gtk_entry_set_editable( GTK_ENTRY( combo
->entry 
), FALSE 
); 
 272     // "show" and "hide" events are generated when user click on the combobox button which popups a list 
 273     // this list is the "popwin" gtk widget 
 274     gtk_signal_connect( GTK_OBJECT(GTK_COMBO(combo
)->popwin
), "hide", 
 275                         GTK_SIGNAL_FUNC(gtk_popup_hide_callback
), (gpointer
)this ); 
 276     gtk_signal_connect( GTK_OBJECT(GTK_COMBO(combo
)->popwin
), "show", 
 277                         GTK_SIGNAL_FUNC(gtk_popup_show_callback
), (gpointer
)this ); 
 279     gtk_signal_connect_after( GTK_OBJECT(combo
->entry
), "changed", 
 280       GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this ); 
 282     gtk_signal_connect_after( GTK_OBJECT(combo
->list
), "select-child", 
 283       GTK_SIGNAL_FUNC(gtk_combo_select_child_callback
), (gpointer
)this ); 
 285     SetBestSize(size
); // need this too because this is a wxControlWithItems 
 287     // This is required for tool bar support 
 288 //    wxSize setsize = GetSize(); 
 289 //    gtk_widget_set_usize( m_widget, setsize.x, setsize.y ); 
 294 wxComboBox::~wxComboBox() 
 296     wxList::compatibility_iterator node 
= m_clientObjectList
.GetFirst(); 
 299         wxClientData 
*cd 
= (wxClientData
*)node
->GetData(); 
 301         node 
= node
->GetNext(); 
 303     m_clientObjectList
.Clear(); 
 305     m_clientDataList
.Clear(); 
 308 void wxComboBox::SetFocus() 
 312         // don't do anything if we already have focus 
 316     gtk_widget_grab_focus( m_focusWidget 
); 
 319 int wxComboBox::DoAppend( const wxString 
&item 
) 
 321     wxCHECK_MSG( m_widget 
!= NULL
, -1, wxT("invalid combobox") ); 
 325     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 327     GtkWidget 
*list_item 
= gtk_list_item_new_with_label( wxGTK_CONV( item 
) ); 
 329     gtk_container_add( GTK_CONTAINER(list
), list_item 
); 
 331     if (GTK_WIDGET_REALIZED(m_widget
)) 
 333         gtk_widget_realize( list_item 
); 
 334         gtk_widget_realize( GTK_BIN(list_item
)->child 
); 
 337     // Apply current widget style to the new list_item 
 338     GtkRcStyle 
*style 
= CreateWidgetStyle(); 
 341         gtk_widget_modify_style( GTK_WIDGET( list_item 
), style 
); 
 342         GtkBin 
*bin 
= GTK_BIN( list_item 
); 
 343         GtkWidget 
*label 
= GTK_WIDGET( bin
->child 
); 
 344         gtk_widget_modify_style( label
, style 
); 
 345         gtk_rc_style_unref( style 
); 
 348     gtk_widget_show( list_item 
); 
 350     const int count 
= GetCount(); 
 352     if ( (int)m_clientDataList
.GetCount() < count 
) 
 353         m_clientDataList
.Append( (wxObject
*) NULL 
); 
 354     if ( (int)m_clientObjectList
.GetCount() < count 
) 
 355         m_clientObjectList
.Append( (wxObject
*) NULL 
); 
 359     InvalidateBestSize(); 
 364 int wxComboBox::DoInsert( const wxString 
&item
, int pos 
) 
 366     wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT
), -1, 
 367                     wxT("can't insert into sorted list")); 
 369     wxCHECK_MSG( m_widget 
!= NULL
, -1, wxT("invalid combobox") ); 
 371     int count 
= GetCount(); 
 372     wxCHECK_MSG( (pos 
>= 0) && (pos 
<= count
), -1, wxT("invalid index") ); 
 379     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 381     GtkWidget 
*list_item 
= gtk_list_item_new_with_label( wxGTK_CONV( item 
) ); 
 383     GList 
*gitem_list 
= g_list_alloc (); 
 384     gitem_list
->data 
= list_item
; 
 385     gtk_list_insert_items( GTK_LIST (list
), gitem_list
, pos 
); 
 387     if (GTK_WIDGET_REALIZED(m_widget
)) 
 389         gtk_widget_realize( list_item 
); 
 390         gtk_widget_realize( GTK_BIN(list_item
)->child 
); 
 395     gtk_widget_show( list_item 
); 
 399     if ( (int)m_clientDataList
.GetCount() < count 
) 
 400         m_clientDataList
.Insert( pos
, (wxObject
*) NULL 
); 
 401     if ( (int)m_clientObjectList
.GetCount() < count 
) 
 402         m_clientObjectList
.Insert( pos
, (wxObject
*) NULL 
); 
 406     InvalidateBestSize(); 
 411 void wxComboBox::DoSetItemClientData( int n
, void* clientData 
) 
 413     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 415     wxList::compatibility_iterator node 
= m_clientDataList
.Item( n 
); 
 418     node
->SetData( (wxObject
*) clientData 
); 
 421 void* wxComboBox::DoGetItemClientData( int n 
) const 
 423     wxCHECK_MSG( m_widget 
!= NULL
, NULL
, wxT("invalid combobox") ); 
 425     wxList::compatibility_iterator node 
= m_clientDataList
.Item( n 
); 
 427     return node 
? node
->GetData() : NULL
; 
 430 void wxComboBox::DoSetItemClientObject( int n
, wxClientData
* clientData 
) 
 432     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 434     wxList::compatibility_iterator node 
= m_clientObjectList
.Item( n 
); 
 437     // wxItemContainer already deletes data for us 
 439     node
->SetData( (wxObject
*) clientData 
); 
 442 wxClientData
* wxComboBox::DoGetItemClientObject( int n 
) const 
 444     wxCHECK_MSG( m_widget 
!= NULL
, (wxClientData
*)NULL
, wxT("invalid combobox") ); 
 446     wxList::compatibility_iterator node 
= m_clientObjectList
.Item( n 
); 
 448     return node 
? (wxClientData
*) node
->GetData() : NULL
; 
 451 void wxComboBox::Clear() 
 453     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 457     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 458     gtk_list_clear_items( GTK_LIST(list
), 0, GetCount() ); 
 460     wxList::compatibility_iterator node 
= m_clientObjectList
.GetFirst(); 
 463         wxClientData 
*cd 
= (wxClientData
*)node
->GetData(); 
 465         node 
= node
->GetNext(); 
 467     m_clientObjectList
.Clear(); 
 469     m_clientDataList
.Clear(); 
 473     InvalidateBestSize(); 
 476 void wxComboBox::Delete( int n 
) 
 478     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 480     GtkList 
*listbox 
= GTK_LIST( GTK_COMBO(m_widget
)->list 
); 
 482     GList 
*child 
= g_list_nth( listbox
->children
, n 
); 
 486         wxFAIL_MSG(wxT("wrong index")); 
 492     GList 
*list 
= g_list_append( (GList
*) NULL
, child
->data 
); 
 493     gtk_list_remove_items( listbox
, list 
); 
 496     wxList::compatibility_iterator node 
= m_clientObjectList
.Item( n 
); 
 499         wxClientData 
*cd 
= (wxClientData
*)node
->GetData(); 
 501         m_clientObjectList
.Erase( node 
); 
 504     node 
= m_clientDataList
.Item( n 
); 
 506         m_clientDataList
.Erase( node 
); 
 510     InvalidateBestSize(); 
 513 void wxComboBox::SetString(int n
, const wxString 
&text
) 
 515     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 517     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 519     GList 
*child 
= g_list_nth( GTK_LIST(list
)->children
, n 
); 
 522         GtkBin 
*bin 
= GTK_BIN( child
->data 
); 
 523         GtkLabel 
*label 
= GTK_LABEL( bin
->child 
); 
 524         gtk_label_set_text(label
, wxGTK_CONV(text
)); 
 528         wxFAIL_MSG( wxT("wxComboBox: wrong index") ); 
 531     InvalidateBestSize(); 
 534 int wxComboBox::FindString( const wxString 
&item 
) const 
 536     wxCHECK_MSG( m_widget 
!= NULL
, wxNOT_FOUND
, wxT("invalid combobox") ); 
 538     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 540     GList 
*child 
= GTK_LIST(list
)->children
; 
 544         GtkBin 
*bin 
= GTK_BIN( child
->data 
); 
 545         GtkLabel 
*label 
= GTK_LABEL( bin
->child 
); 
 547         wxString 
str( wxGTK_CONV_BACK( gtk_label_get_text(label
) ) ); 
 549         wxString 
str( label
->label 
); 
 561 int wxComboBox::GetSelection() const 
 563     // if the popup is currently opened, use the selection as it had been 
 564     // before it dropped down 
 565     return g_SelectionBeforePopup 
== wxID_NONE 
? GetCurrentSelection() 
 566                                                : g_SelectionBeforePopup
; 
 569 int wxComboBox::GetCurrentSelection() const 
 571     wxCHECK_MSG( m_widget 
!= NULL
, -1, wxT("invalid combobox") ); 
 573     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 575     GList 
*selection 
= GTK_LIST(list
)->selection
; 
 578         GList 
*child 
= GTK_LIST(list
)->children
; 
 582             if (child
->data 
== selection
->data
) return count
; 
 591 wxString 
wxComboBox::GetString( int n 
) const 
 593     wxCHECK_MSG( m_widget 
!= NULL
, wxEmptyString
, wxT("invalid combobox") ); 
 595     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 598     GList 
*child 
= g_list_nth( GTK_LIST(list
)->children
, n 
); 
 601         GtkBin 
*bin 
= GTK_BIN( child
->data 
); 
 602         GtkLabel 
*label 
= GTK_LABEL( bin
->child 
); 
 604         str 
= wxGTK_CONV_BACK( gtk_label_get_text(label
) ); 
 606         str 
= wxString( label
->label 
); 
 611         wxFAIL_MSG( wxT("wxComboBox: wrong index") ); 
 617 wxString 
wxComboBox::GetStringSelection() const 
 619     wxCHECK_MSG( m_widget 
!= NULL
, wxEmptyString
, wxT("invalid combobox") ); 
 621     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 623     GList 
*selection 
= GTK_LIST(list
)->selection
; 
 626         GtkBin 
*bin 
= GTK_BIN( selection
->data 
); 
 627         GtkLabel 
*label 
= GTK_LABEL( bin
->child 
); 
 629         wxString 
tmp( wxGTK_CONV_BACK( gtk_label_get_text(label
) ) ); 
 631         wxString 
tmp( label
->label 
); 
 636     wxFAIL_MSG( wxT("wxComboBox: no selection") ); 
 638     return wxEmptyString
; 
 641 int wxComboBox::GetCount() const 
 643     wxCHECK_MSG( m_widget 
!= NULL
, 0, wxT("invalid combobox") ); 
 645     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 647     GList 
*child 
= GTK_LIST(list
)->children
; 
 649     while (child
) { count
++; child 
= child
->next
; } 
 653 void wxComboBox::SetSelection( int n 
) 
 655     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 659     GtkWidget 
*list 
= GTK_COMBO(m_widget
)->list
; 
 660     gtk_list_unselect_item( GTK_LIST(list
), m_prevSelection 
); 
 661     gtk_list_select_item( GTK_LIST(list
), n 
); 
 667 wxString 
wxComboBox::GetValue() const 
 669     GtkEntry 
*entry 
= GTK_ENTRY( GTK_COMBO(m_widget
)->entry 
); 
 670     wxString 
tmp( wxGTK_CONV_BACK( gtk_entry_get_text( entry 
) ) ); 
 673     for (int i 
= 0; i 
< wxStrlen(tmp
.c_str()) +1; i
++) 
 676         printf( "%d ", (int) (c
) ); 
 684 void wxComboBox::SetValue( const wxString
& value 
) 
 686     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 688     GtkWidget 
*entry 
= GTK_COMBO(m_widget
)->entry
; 
 690     if (!value
.IsNull()) tmp 
= value
; 
 691     gtk_entry_set_text( GTK_ENTRY(entry
), wxGTK_CONV( tmp 
) ); 
 693     InvalidateBestSize(); 
 696 void wxComboBox::Copy() 
 698     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 700     GtkWidget 
*entry 
= GTK_COMBO(m_widget
)->entry
; 
 701     gtk_editable_copy_clipboard( GTK_EDITABLE(entry
) DUMMY_CLIPBOARD_ARG 
); 
 704 void wxComboBox::Cut() 
 706     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 708     GtkWidget 
*entry 
= GTK_COMBO(m_widget
)->entry
; 
 709     gtk_editable_cut_clipboard( GTK_EDITABLE(entry
) DUMMY_CLIPBOARD_ARG 
); 
 712 void wxComboBox::Paste() 
 714     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 716     GtkWidget 
*entry 
= GTK_COMBO(m_widget
)->entry
; 
 717     gtk_editable_paste_clipboard( GTK_EDITABLE(entry
) DUMMY_CLIPBOARD_ARG
); 
 720 void wxComboBox::Undo() 
 725 void wxComboBox::Redo() 
 730 void wxComboBox::SelectAll() 
 732     SetSelection(0, GetLastPosition()); 
 735 bool wxComboBox::CanUndo() const 
 741 bool wxComboBox::CanRedo() const 
 747 bool wxComboBox::HasSelection() const 
 750     GetSelection(&from
, &to
); 
 754 bool wxComboBox::CanCopy() const 
 756     // Can copy if there's a selection 
 757     return HasSelection(); 
 760 bool wxComboBox::CanCut() const 
 762     return CanCopy() && IsEditable(); 
 765 bool wxComboBox::CanPaste() const 
 767     // TODO: check for text on the clipboard 
 768     return IsEditable() ; 
 771 bool wxComboBox::IsEditable() const 
 773     return !HasFlag(wxCB_READONLY
); 
 777 void wxComboBox::SetInsertionPoint( long pos 
) 
 779     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 781     if ( pos 
== GetLastPosition() ) 
 784     GtkWidget 
*entry 
= GTK_COMBO(m_widget
)->entry
; 
 785     gtk_entry_set_position( GTK_ENTRY(entry
), (int)pos 
); 
 788 long wxComboBox::GetInsertionPoint() const 
 790     return (long) GET_EDITABLE_POS( GTK_COMBO(m_widget
)->entry 
); 
 793 wxTextPos 
wxComboBox::GetLastPosition() const 
 795     GtkWidget 
*entry 
= GTK_COMBO(m_widget
)->entry
; 
 796     int pos 
= GTK_ENTRY(entry
)->text_length
; 
 800 void wxComboBox::Replace( long from
, long to
, const wxString
& value 
) 
 802     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid combobox") ); 
 804     GtkWidget 
*entry 
= GTK_COMBO(m_widget
)->entry
; 
 805     gtk_editable_delete_text( GTK_EDITABLE(entry
), (gint
)from
, (gint
)to 
); 
 806     if (value
.IsNull()) return; 
 810     wxCharBuffer buffer 
= wxConvUTF8
.cWX2MB( value 
); 
 811     gtk_editable_insert_text( GTK_EDITABLE(entry
), (const char*) buffer
, strlen( (const char*) buffer 
), &pos 
); 
 813     gtk_editable_insert_text( GTK_EDITABLE(entry
), value
.c_str(), value
.Length(), &pos 
); 
 817 void wxComboBox::SetSelection( long from
, long to 
) 
 819     GtkWidget 
*entry 
= GTK_COMBO(m_widget
)->entry
; 
 820     gtk_editable_select_region( GTK_EDITABLE(entry
), (gint
)from
, (gint
)to 
); 
 823 void wxComboBox::GetSelection( long* from
, long* to 
) const 
 827         GtkEditable 
*editable 
= GTK_EDITABLE(GTK_COMBO(m_widget
)->entry
); 
 830         gtk_editable_get_selection_bounds(editable
, & start
, & end
); 
 834         *from 
= (long) editable
->selection_start_pos
; 
 835         *to 
= (long) editable
->selection_end_pos
; 
 840 void wxComboBox::SetEditable( bool editable 
) 
 842     GtkWidget 
*entry 
= GTK_COMBO(m_widget
)->entry
; 
 843     gtk_entry_set_editable( GTK_ENTRY(entry
), editable 
); 
 846 void wxComboBox::OnChar( wxKeyEvent 
&event 
) 
 848     if ( event
.GetKeyCode() == WXK_RETURN 
) 
 850         // GTK automatically selects an item if its in the list 
 851         wxCommandEvent 
event(wxEVT_COMMAND_TEXT_ENTER
, GetId()); 
 852         event
.SetString( GetValue() ); 
 853         event
.SetInt( GetSelection() ); 
 854         event
.SetEventObject( this ); 
 856         if (!GetEventHandler()->ProcessEvent( event 
)) 
 858             // This will invoke the dialog default action, such 
 859             // as the clicking the default button. 
 861             wxWindow 
*top_frame 
= m_parent
; 
 862             while (top_frame
->GetParent() && !(top_frame
->IsTopLevel())) 
 863                 top_frame 
= top_frame
->GetParent(); 
 865             if (top_frame 
&& GTK_IS_WINDOW(top_frame
->m_widget
)) 
 867                 GtkWindow 
*window 
= GTK_WINDOW(top_frame
->m_widget
); 
 869                 if (window
->default_widget
) 
 870                         gtk_widget_activate (window
->default_widget
); 
 874         // Catch GTK event so that GTK doesn't open the drop 
 875         // down list upon RETURN. 
 882 void wxComboBox::DisableEvents() 
 884     gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget
)->list
), 
 885       GTK_SIGNAL_FUNC(gtk_combo_select_child_callback
), (gpointer
)this ); 
 886     gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget
)->entry
), 
 887       GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this ); 
 890 void wxComboBox::EnableEvents() 
 892     gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(m_widget
)->list
), "select-child", 
 893       GTK_SIGNAL_FUNC(gtk_combo_select_child_callback
), (gpointer
)this ); 
 894     gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(m_widget
)->entry
), "changed", 
 895       GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this ); 
 898 void wxComboBox::OnSize( wxSizeEvent 
&event 
) 
 900     // NB: In some situations (e.g. on non-first page of a wizard, if the 
 901     //     size used is default size), GtkCombo widget is resized correctly, 
 902     //     but it's look is not updated, it's rendered as if it was much wider. 
 903     //     No other widgets are affected, so it looks like a bug in GTK+. 
 904     //     Manually requesting resize calculation (as gtk_pizza_set_size does) 
 906     if (GTK_WIDGET_VISIBLE(m_widget
)) 
 907         gtk_widget_queue_resize(m_widget
); 
 912 void wxComboBox::DoApplyWidgetStyle(GtkRcStyle 
*style
) 
 914 //    gtk_widget_modify_style( GTK_COMBO(m_widget)->button, syle ); 
 916     gtk_widget_modify_style( GTK_COMBO(m_widget
)->entry
, style 
); 
 917     gtk_widget_modify_style( GTK_COMBO(m_widget
)->list
, style 
); 
 919     GtkList 
*list 
= GTK_LIST( GTK_COMBO(m_widget
)->list 
); 
 920     GList 
*child 
= list
->children
; 
 923         gtk_widget_modify_style( GTK_WIDGET(child
->data
), style 
); 
 925         GtkBin 
*bin 
= GTK_BIN(child
->data
); 
 926         gtk_widget_modify_style( bin
->child
, style 
); 
 932 GtkWidget
* wxComboBox::GetConnectWidget() 
 934     return GTK_COMBO(m_widget
)->entry
; 
 937 bool wxComboBox::IsOwnGtkWindow( GdkWindow 
*window 
) 
 939     return ( (window 
== GTK_ENTRY( GTK_COMBO(m_widget
)->entry 
)->text_area
) || 
 940              (window 
== GTK_COMBO(m_widget
)->button
->window 
) ); 
 943 wxSize 
wxComboBox::DoGetBestSize() const 
 945     wxSize 
ret( wxControl::DoGetBestSize() ); 
 947     // we know better our horizontal extent: it depends on the longest string 
 952         size_t count 
= GetCount(); 
 953         for ( size_t n 
= 0; n 
< count
; n
++ ) 
 955             GetTextExtent( GetString(n
), &width
, NULL
, NULL
, NULL 
); 
 961     // empty combobox should have some reasonable default size too 
 971 wxComboBox::GetClassDefaultAttributes(wxWindowVariant 
WXUNUSED(variant
)) 
 973     return GetDefaultAttributesFromGTKWidget(gtk_combo_new
, true); 
 976 // ---------------------------------------------------------------------------- 
 977 // standard event handling 
 978 // ---------------------------------------------------------------------------- 
 980 void wxComboBox::OnCut(wxCommandEvent
& WXUNUSED(event
)) 
 985 void wxComboBox::OnCopy(wxCommandEvent
& WXUNUSED(event
)) 
 990 void wxComboBox::OnPaste(wxCommandEvent
& WXUNUSED(event
)) 
 995 void wxComboBox::OnUndo(wxCommandEvent
& WXUNUSED(event
)) 
1000 void wxComboBox::OnRedo(wxCommandEvent
& WXUNUSED(event
)) 
1005 void wxComboBox::OnDelete(wxCommandEvent
& WXUNUSED(event
)) 
1008     GetSelection(& from
, & to
); 
1009     if (from 
!= -1 && to 
!= -1) 
1013 void wxComboBox::OnSelectAll(wxCommandEvent
& WXUNUSED(event
)) 
1015     SetSelection(-1, -1); 
1018 void wxComboBox::OnUpdateCut(wxUpdateUIEvent
& event
) 
1020     event
.Enable( CanCut() ); 
1023 void wxComboBox::OnUpdateCopy(wxUpdateUIEvent
& event
) 
1025     event
.Enable( CanCopy() ); 
1028 void wxComboBox::OnUpdatePaste(wxUpdateUIEvent
& event
) 
1030     event
.Enable( CanPaste() ); 
1033 void wxComboBox::OnUpdateUndo(wxUpdateUIEvent
& event
) 
1035     event
.Enable( CanUndo() ); 
1038 void wxComboBox::OnUpdateRedo(wxUpdateUIEvent
& event
) 
1040     event
.Enable( CanRedo() ); 
1043 void wxComboBox::OnUpdateDelete(wxUpdateUIEvent
& event
) 
1045     event
.Enable(HasSelection() && IsEditable()) ; 
1048 void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent
& event
) 
1050     event
.Enable(GetLastPosition() > 0);