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 = -2; // -2 <=> the popup is hidden
42 //-----------------------------------------------------------------------------
43 // "changed" - typing and list item matches get changed, select-child
44 // if it doesn't match an item then just get a single changed
45 //-----------------------------------------------------------------------------
49 gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
51 if (g_isIdle) wxapp_install_idle_handler();
53 if (combo->m_ignoreNextUpdate)
55 combo->m_ignoreNextUpdate = false;
59 if (!combo->m_hasVMT) return;
61 wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
62 event.SetString( combo->GetValue() );
63 event.SetEventObject( combo );
64 combo->GetEventHandler()->ProcessEvent( event );
70 gtk_dummy_callback(GtkEntry *WXUNUSED(entry), GtkCombo *WXUNUSED(combo))
77 gtk_popup_hide_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo)
79 // when the popup is hidden, throw a SELECTED event only if the combobox
81 int curSelection = combo->GetSelection();
82 if (g_SelectionBeforePopup != curSelection)
84 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
85 event.SetInt( curSelection );
86 event.SetString( combo->GetStringSelection() );
87 event.SetEventObject( combo );
88 combo->GetEventHandler()->ProcessEvent( event );
91 // reset the selection flag to an identifiable value (-2 = hidden)
92 g_SelectionBeforePopup = -2;
98 gtk_popup_show_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo)
100 // store the combobox selection value before the popup is shown
101 // if there is no selection, combo->GetSelection() returns -1
102 g_SelectionBeforePopup = combo->GetSelection();
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->GetSelection();
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 (-2)
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 == -2)
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 );
152 // Now send the event ourselves
153 wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
154 event2.SetString( combo->GetValue() );
155 event2.SetEventObject( combo );
156 combo->GetEventHandler()->ProcessEvent( event2 );
160 //-----------------------------------------------------------------------------
162 //-----------------------------------------------------------------------------
164 IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl)
166 BEGIN_EVENT_TABLE(wxComboBox, wxControl)
167 EVT_SIZE(wxComboBox::OnSize)
168 EVT_CHAR(wxComboBox::OnChar)
170 EVT_MENU(wxID_CUT, wxComboBox::OnCut)
171 EVT_MENU(wxID_COPY, wxComboBox::OnCopy)
172 EVT_MENU(wxID_PASTE, wxComboBox::OnPaste)
173 EVT_MENU(wxID_UNDO, wxComboBox::OnUndo)
174 EVT_MENU(wxID_REDO, wxComboBox::OnRedo)
175 EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete)
176 EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll)
178 EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut)
179 EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy)
180 EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste)
181 EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo)
182 EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo)
183 EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete)
184 EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll)
187 bool wxComboBox::Create( wxWindow *parent, wxWindowID id,
188 const wxString& value,
189 const wxPoint& pos, const wxSize& size,
190 const wxArrayString& choices,
191 long style, const wxValidator& validator,
192 const wxString& name )
194 wxCArrayString chs(choices);
196 return Create( parent, id, value, pos, size, chs.GetCount(),
197 chs.GetStrings(), style, validator, name );
200 bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
201 const wxPoint& pos, const wxSize& size,
202 int n, const wxString choices[],
203 long style, const wxValidator& validator,
204 const wxString& name )
206 m_ignoreNextUpdate = false;
208 m_acceptsFocus = true;
211 if (!PreCreation( parent, pos, size ) ||
212 !CreateBase( parent, id, pos, size, style, validator, name ))
214 wxFAIL_MSG( wxT("wxComboBox creation failed") );
218 m_widget = gtk_combo_new();
219 GtkCombo *combo = GTK_COMBO(m_widget);
221 // Disable GTK's broken events ...
222 gtk_signal_disconnect( GTK_OBJECT(combo->entry), combo->entry_change_id );
223 // ... and add surogate handler.
224 combo->entry_change_id = gtk_signal_connect (GTK_OBJECT (combo->entry), "changed",
225 (GtkSignalFunc) gtk_dummy_callback, combo);
227 // make it more useable
228 gtk_combo_set_use_arrows_always( GTK_COMBO(m_widget), TRUE );
230 // and case-sensitive
231 gtk_combo_set_case_sensitive( GTK_COMBO(m_widget), TRUE );
234 if (style & wxNO_BORDER)
235 g_object_set( GTK_ENTRY( combo->entry ), "has-frame", FALSE, NULL );
238 GtkWidget *list = GTK_COMBO(m_widget)->list;
241 // gtk_list_set_selection_mode( GTK_LIST(list), GTK_SELECTION_MULTIPLE );
244 for (int i = 0; i < n; i++)
246 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( choices[i] ) );
248 m_clientDataList.Append( (wxObject*)NULL );
249 m_clientObjectList.Append( (wxObject*)NULL );
251 gtk_container_add( GTK_CONTAINER(list), list_item );
253 gtk_widget_show( list_item );
256 m_parent->DoAddChild( this );
258 m_focusWidget = combo->entry;
262 ConnectWidget( combo->button );
264 // MSW's combo box shows the value and the selection is -1
265 gtk_entry_set_text( GTK_ENTRY(combo->entry), wxGTK_CONV(value) );
266 gtk_list_unselect_all( GTK_LIST(combo->list) );
268 if (style & wxCB_READONLY)
269 gtk_entry_set_editable( GTK_ENTRY( combo->entry ), FALSE );
271 // "show" and "hide" events are generated when user click on the combobox button which popups a list
272 // this list is the "popwin" gtk widget
273 gtk_signal_connect( GTK_OBJECT(GTK_COMBO(combo)->popwin), "hide",
274 GTK_SIGNAL_FUNC(gtk_popup_hide_callback), (gpointer)this );
275 gtk_signal_connect( GTK_OBJECT(GTK_COMBO(combo)->popwin), "show",
276 GTK_SIGNAL_FUNC(gtk_popup_show_callback), (gpointer)this );
278 gtk_signal_connect_after( GTK_OBJECT(combo->entry), "changed",
279 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
281 gtk_signal_connect_after( GTK_OBJECT(combo->list), "select-child",
282 GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
284 SetBestSize(size); // need this too because this is a wxControlWithItems
286 // This is required for tool bar support
287 // wxSize setsize = GetSize();
288 // gtk_widget_set_usize( m_widget, setsize.x, setsize.y );
293 wxComboBox::~wxComboBox()
295 wxList::compatibility_iterator node = m_clientObjectList.GetFirst();
298 wxClientData *cd = (wxClientData*)node->GetData();
300 node = node->GetNext();
302 m_clientObjectList.Clear();
304 m_clientDataList.Clear();
307 void wxComboBox::SetFocus()
311 // don't do anything if we already have focus
315 gtk_widget_grab_focus( m_focusWidget );
318 int wxComboBox::DoAppend( const wxString &item )
320 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
324 GtkWidget *list = GTK_COMBO(m_widget)->list;
326 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
328 gtk_container_add( GTK_CONTAINER(list), list_item );
330 if (GTK_WIDGET_REALIZED(m_widget))
332 gtk_widget_realize( list_item );
333 gtk_widget_realize( GTK_BIN(list_item)->child );
336 // Apply current widget style to the new list_item
337 GtkRcStyle *style = CreateWidgetStyle();
340 gtk_widget_modify_style( GTK_WIDGET( list_item ), style );
341 GtkBin *bin = GTK_BIN( list_item );
342 GtkWidget *label = GTK_WIDGET( bin->child );
343 gtk_widget_modify_style( label, style );
344 gtk_rc_style_unref( style );
347 gtk_widget_show( list_item );
349 const int count = GetCount();
351 if ( (int)m_clientDataList.GetCount() < count )
352 m_clientDataList.Append( (wxObject*) NULL );
353 if ( (int)m_clientObjectList.GetCount() < count )
354 m_clientObjectList.Append( (wxObject*) NULL );
358 InvalidateBestSize();
363 int wxComboBox::DoInsert( const wxString &item, int pos )
365 wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT), -1,
366 wxT("can't insert into sorted list"));
368 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
370 int count = GetCount();
371 wxCHECK_MSG( (pos >= 0) && (pos <= count), -1, wxT("invalid index") );
378 GtkWidget *list = GTK_COMBO(m_widget)->list;
380 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
382 GList *gitem_list = g_list_alloc ();
383 gitem_list->data = list_item;
384 gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );
386 if (GTK_WIDGET_REALIZED(m_widget))
388 gtk_widget_realize( list_item );
389 gtk_widget_realize( GTK_BIN(list_item)->child );
394 gtk_widget_show( list_item );
398 if ( (int)m_clientDataList.GetCount() < count )
399 m_clientDataList.Insert( pos, (wxObject*) NULL );
400 if ( (int)m_clientObjectList.GetCount() < count )
401 m_clientObjectList.Insert( pos, (wxObject*) NULL );
405 InvalidateBestSize();
410 void wxComboBox::DoSetItemClientData( int n, void* clientData )
412 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
414 wxList::compatibility_iterator node = m_clientDataList.Item( n );
417 node->SetData( (wxObject*) clientData );
420 void* wxComboBox::DoGetItemClientData( int n ) const
422 wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
424 wxList::compatibility_iterator node = m_clientDataList.Item( n );
426 return node ? node->GetData() : NULL;
429 void wxComboBox::DoSetItemClientObject( int n, wxClientData* clientData )
431 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
433 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
436 // wxItemContainer already deletes data for us
438 node->SetData( (wxObject*) clientData );
441 wxClientData* wxComboBox::DoGetItemClientObject( int n ) const
443 wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") );
445 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
447 return node ? (wxClientData*) node->GetData() : NULL;
450 void wxComboBox::Clear()
452 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
456 GtkWidget *list = GTK_COMBO(m_widget)->list;
457 gtk_list_clear_items( GTK_LIST(list), 0, GetCount() );
459 wxList::compatibility_iterator node = m_clientObjectList.GetFirst();
462 wxClientData *cd = (wxClientData*)node->GetData();
464 node = node->GetNext();
466 m_clientObjectList.Clear();
468 m_clientDataList.Clear();
472 InvalidateBestSize();
475 void wxComboBox::Delete( int n )
477 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
479 GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list );
481 GList *child = g_list_nth( listbox->children, n );
485 wxFAIL_MSG(wxT("wrong index"));
491 GList *list = g_list_append( (GList*) NULL, child->data );
492 gtk_list_remove_items( listbox, list );
495 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
498 wxClientData *cd = (wxClientData*)node->GetData();
500 m_clientObjectList.Erase( node );
503 node = m_clientDataList.Item( n );
505 m_clientDataList.Erase( node );
509 InvalidateBestSize();
512 void wxComboBox::SetString(int n, const wxString &text)
514 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
516 GtkWidget *list = GTK_COMBO(m_widget)->list;
518 GList *child = g_list_nth( GTK_LIST(list)->children, n );
521 GtkBin *bin = GTK_BIN( child->data );
522 GtkLabel *label = GTK_LABEL( bin->child );
523 gtk_label_set_text(label, wxGTK_CONV(text));
527 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
530 InvalidateBestSize();
533 int wxComboBox::FindString( const wxString &item ) const
535 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
537 GtkWidget *list = GTK_COMBO(m_widget)->list;
539 GList *child = GTK_LIST(list)->children;
543 GtkBin *bin = GTK_BIN( child->data );
544 GtkLabel *label = GTK_LABEL( bin->child );
546 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
548 wxString str( label->label );
560 int wxComboBox::GetSelection() const
562 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
564 GtkWidget *list = GTK_COMBO(m_widget)->list;
566 GList *selection = GTK_LIST(list)->selection;
569 GList *child = GTK_LIST(list)->children;
573 if (child->data == selection->data) return count;
582 wxString wxComboBox::GetString( int n ) const
584 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") );
586 GtkWidget *list = GTK_COMBO(m_widget)->list;
589 GList *child = g_list_nth( GTK_LIST(list)->children, n );
592 GtkBin *bin = GTK_BIN( child->data );
593 GtkLabel *label = GTK_LABEL( bin->child );
595 str = wxGTK_CONV_BACK( gtk_label_get_text(label) );
597 str = wxString( label->label );
602 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
608 wxString wxComboBox::GetStringSelection() const
610 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") );
612 GtkWidget *list = GTK_COMBO(m_widget)->list;
614 GList *selection = GTK_LIST(list)->selection;
617 GtkBin *bin = GTK_BIN( selection->data );
618 GtkLabel *label = GTK_LABEL( bin->child );
620 wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
622 wxString tmp( label->label );
627 wxFAIL_MSG( wxT("wxComboBox: no selection") );
632 int wxComboBox::GetCount() const
634 wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") );
636 GtkWidget *list = GTK_COMBO(m_widget)->list;
638 GList *child = GTK_LIST(list)->children;
640 while (child) { count++; child = child->next; }
644 void wxComboBox::SetSelection( int n )
646 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
650 GtkWidget *list = GTK_COMBO(m_widget)->list;
651 gtk_list_unselect_item( GTK_LIST(list), m_prevSelection );
652 gtk_list_select_item( GTK_LIST(list), n );
658 wxString wxComboBox::GetValue() const
660 GtkEntry *entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
661 wxString tmp( wxGTK_CONV_BACK( gtk_entry_get_text( entry ) ) );
664 for (int i = 0; i < wxStrlen(tmp.c_str()) +1; i++)
667 printf( "%d ", (int) (c) );
675 void wxComboBox::SetValue( const wxString& value )
677 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
679 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
680 wxString tmp = wxT("");
681 if (!value.IsNull()) tmp = value;
682 gtk_entry_set_text( GTK_ENTRY(entry), wxGTK_CONV( tmp ) );
684 InvalidateBestSize();
687 void wxComboBox::Copy()
689 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
691 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
692 gtk_editable_copy_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG );
695 void wxComboBox::Cut()
697 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
699 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
700 gtk_editable_cut_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG );
703 void wxComboBox::Paste()
705 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
707 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
708 gtk_editable_paste_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG);
711 void wxComboBox::Undo()
716 void wxComboBox::Redo()
721 void wxComboBox::SelectAll()
723 SetSelection(0, GetLastPosition());
726 bool wxComboBox::CanUndo() const
732 bool wxComboBox::CanRedo() const
738 bool wxComboBox::HasSelection() const
741 GetSelection(&from, &to);
745 bool wxComboBox::CanCopy() const
747 // Can copy if there's a selection
748 return HasSelection();
751 bool wxComboBox::CanCut() const
753 return CanCopy() && IsEditable();
756 bool wxComboBox::CanPaste() const
758 // TODO: check for text on the clipboard
759 return IsEditable() ;
762 bool wxComboBox::IsEditable() const
764 return !HasFlag(wxCB_READONLY);
768 void wxComboBox::SetInsertionPoint( long pos )
770 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
772 if ( pos == GetLastPosition() )
775 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
776 gtk_entry_set_position( GTK_ENTRY(entry), (int)pos );
779 long wxComboBox::GetInsertionPoint() const
781 return (long) GET_EDITABLE_POS( GTK_COMBO(m_widget)->entry );
784 wxTextPos wxComboBox::GetLastPosition() const
786 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
787 int pos = GTK_ENTRY(entry)->text_length;
791 void wxComboBox::Replace( long from, long to, const wxString& value )
793 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
795 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
796 gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
797 if (value.IsNull()) return;
801 wxCharBuffer buffer = wxConvUTF8.cWX2MB( value );
802 gtk_editable_insert_text( GTK_EDITABLE(entry), (const char*) buffer, strlen( (const char*) buffer ), &pos );
804 gtk_editable_insert_text( GTK_EDITABLE(entry), value.c_str(), value.Length(), &pos );
808 void wxComboBox::SetSelection( long from, long to )
810 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
811 gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to );
814 void wxComboBox::GetSelection( long* from, long* to ) const
818 GtkEditable *editable = GTK_EDITABLE(GTK_COMBO(m_widget)->entry);
821 gtk_editable_get_selection_bounds(editable, & start, & end);
825 *from = (long) editable->selection_start_pos;
826 *to = (long) editable->selection_end_pos;
831 void wxComboBox::SetEditable( bool editable )
833 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
834 gtk_entry_set_editable( GTK_ENTRY(entry), editable );
837 void wxComboBox::OnChar( wxKeyEvent &event )
839 if ( event.GetKeyCode() == WXK_RETURN )
841 // GTK automatically selects an item if its in the list
842 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, GetId());
843 event.SetString( GetValue() );
844 event.SetInt( GetSelection() );
845 event.SetEventObject( this );
847 if (!GetEventHandler()->ProcessEvent( event ))
849 // This will invoke the dialog default action, such
850 // as the clicking the default button.
852 wxWindow *top_frame = m_parent;
853 while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
854 top_frame = top_frame->GetParent();
856 if (top_frame && GTK_IS_WINDOW(top_frame->m_widget))
858 GtkWindow *window = GTK_WINDOW(top_frame->m_widget);
860 if (window->default_widget)
861 gtk_widget_activate (window->default_widget);
865 // Catch GTK event so that GTK doesn't open the drop
866 // down list upon RETURN.
873 void wxComboBox::DisableEvents()
875 gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget)->list),
876 GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
877 gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget)->entry),
878 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
881 void wxComboBox::EnableEvents()
883 gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(m_widget)->list), "select-child",
884 GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
885 gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed",
886 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
889 void wxComboBox::OnSize( wxSizeEvent &event )
891 // NB: In some situations (e.g. on non-first page of a wizard, if the
892 // size used is default size), GtkCombo widget is resized correctly,
893 // but it's look is not updated, it's rendered as if it was much wider.
894 // No other widgets are affected, so it looks like a bug in GTK+.
895 // Manually requesting resize calculation (as gtk_pizza_set_size does)
897 if (GTK_WIDGET_VISIBLE(m_widget))
898 gtk_widget_queue_resize(m_widget);
903 void wxComboBox::DoApplyWidgetStyle(GtkRcStyle *style)
905 // gtk_widget_modify_style( GTK_COMBO(m_widget)->button, syle );
907 gtk_widget_modify_style( GTK_COMBO(m_widget)->entry, style );
908 gtk_widget_modify_style( GTK_COMBO(m_widget)->list, style );
910 GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
911 GList *child = list->children;
914 gtk_widget_modify_style( GTK_WIDGET(child->data), style );
916 GtkBin *bin = GTK_BIN(child->data);
917 gtk_widget_modify_style( bin->child, style );
923 GtkWidget* wxComboBox::GetConnectWidget()
925 return GTK_COMBO(m_widget)->entry;
928 bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
930 return ( (window == GTK_ENTRY( GTK_COMBO(m_widget)->entry )->text_area) ||
931 (window == GTK_COMBO(m_widget)->button->window ) );
934 wxSize wxComboBox::DoGetBestSize() const
936 wxSize ret( wxControl::DoGetBestSize() );
938 // we know better our horizontal extent: it depends on the longest string
943 size_t count = GetCount();
944 for ( size_t n = 0; n < count; n++ )
946 GetTextExtent( GetString(n), &width, NULL, NULL, NULL );
952 // empty combobox should have some reasonable default size too
962 wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
964 return GetDefaultAttributesFromGTKWidget(gtk_combo_new, true);
967 // ----------------------------------------------------------------------------
968 // standard event handling
969 // ----------------------------------------------------------------------------
971 void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event))
976 void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event))
981 void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event))
986 void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event))
991 void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event))
996 void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event))
999 GetSelection(& from, & to);
1000 if (from != -1 && to != -1)
1004 void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event))
1006 SetSelection(-1, -1);
1009 void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event)
1011 event.Enable( CanCut() );
1014 void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event)
1016 event.Enable( CanCopy() );
1019 void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event)
1021 event.Enable( CanPaste() );
1024 void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event)
1026 event.Enable( CanUndo() );
1029 void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event)
1031 event.Enable( CanRedo() );
1034 void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event)
1036 event.Enable(HasSelection() && IsEditable()) ;
1039 void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
1041 event.Enable(GetLastPosition() > 0);