1
/////////////////////////////////////////////////////////////////////////////
4
// Author: Robert Roebling
5
// Id: $Id: combobox.cpp,v 1.131.2.2 2006/03/17 16:00:51 RR Exp $
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();
84
// reset the selection flag to value meaning that it is hidden
85
g_SelectionBeforePopup = wxID_NONE;
87
if (g_SelectionBeforePopup != curSelection)
89
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
90
event.SetInt( curSelection );
91
event.SetString( combo->GetStringSelection() );
92
event.SetEventObject( combo );
93
combo->GetEventHandler()->ProcessEvent( event );
95
// for consistency with the other ports, send TEXT event
96
wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
97
event2.SetString( combo->GetStringSelection() );
98
event2.SetEventObject( combo );
99
combo->GetEventHandler()->ProcessEvent( event2 );
107
gtk_popup_show_callback(GtkCombo *WXUNUSED(gtk_combo), wxComboBox *combo)
109
// store the combobox selection value before the popup is shown
110
g_SelectionBeforePopup = combo->GetCurrentSelection();
114
//-----------------------------------------------------------------------------
115
// "select-child" - click/cursor get select-child, changed, select-child
116
//-----------------------------------------------------------------------------
120
gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(widget), wxComboBox *combo )
122
if (g_isIdle) wxapp_install_idle_handler();
124
if (!combo->m_hasVMT) return;
126
if (g_blockEventsOnDrag) return;
128
int curSelection = combo->GetCurrentSelection();
130
if (combo->m_prevSelection == curSelection) return;
132
GtkWidget *list = GTK_COMBO(combo->m_widget)->list;
133
gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection );
135
combo->m_prevSelection = curSelection;
137
// Quickly set the value of the combo box
138
// as GTK+ does that only AFTER the event
140
gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(combo->GetHandle())->entry),
141
GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)combo );
142
combo->SetValue( combo->GetStringSelection() );
143
gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(combo->GetHandle())->entry), "changed",
144
GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)combo );
146
// throw a SELECTED event only if the combobox popup is hidden (wxID_NONE)
147
// because when combobox popup is shown, gtk_combo_select_child_callback is
148
// called each times the mouse is over an item with a pressed button so a lot
149
// of SELECTED event could be generated if the user keep the mouse button down
150
// and select other items ...
151
if (g_SelectionBeforePopup == wxID_NONE)
153
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
154
event.SetInt( curSelection );
155
event.SetString( combo->GetStringSelection() );
156
event.SetEventObject( combo );
157
combo->GetEventHandler()->ProcessEvent( event );
159
// for consistency with the other ports, don't generate text update
160
// events while the user is browsing the combobox neither
161
wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
162
event2.SetString( combo->GetValue() );
163
event2.SetEventObject( combo );
164
combo->GetEventHandler()->ProcessEvent( event2 );
169
//-----------------------------------------------------------------------------
171
//-----------------------------------------------------------------------------
173
IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl)
175
BEGIN_EVENT_TABLE(wxComboBox, wxControl)
176
EVT_SIZE(wxComboBox::OnSize)
177
EVT_CHAR(wxComboBox::OnChar)
179
EVT_MENU(wxID_CUT, wxComboBox::OnCut)
180
EVT_MENU(wxID_COPY, wxComboBox::OnCopy)
181
EVT_MENU(wxID_PASTE, wxComboBox::OnPaste)
182
EVT_MENU(wxID_UNDO, wxComboBox::OnUndo)
183
EVT_MENU(wxID_REDO, wxComboBox::OnRedo)
184
EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete)
185
EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll)
187
EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut)
188
EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy)
189
EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste)
190
EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo)
191
EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo)
192
EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete)
193
EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll)
196
bool wxComboBox::Create( wxWindow *parent, wxWindowID id,
197
const wxString& value,
198
const wxPoint& pos, const wxSize& size,
199
const wxArrayString& choices,
200
long style, const wxValidator& validator,
201
const wxString& name )
203
wxCArrayString chs(choices);
205
return Create( parent, id, value, pos, size, chs.GetCount(),
206
chs.GetStrings(), style, validator, name );
209
bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
210
const wxPoint& pos, const wxSize& size,
211
int n, const wxString choices[],
212
long style, const wxValidator& validator,
213
const wxString& name )
215
m_ignoreNextUpdate = false;
217
m_acceptsFocus = true;
220
if (!PreCreation( parent, pos, size ) ||
221
!CreateBase( parent, id, pos, size, style, validator, name ))
223
wxFAIL_MSG( wxT("wxComboBox creation failed") );
227
m_widget = gtk_combo_new();
228
GtkCombo *combo = GTK_COMBO(m_widget);
230
// Disable GTK's broken events ...
231
gtk_signal_disconnect( GTK_OBJECT(combo->entry), combo->entry_change_id );
232
// ... and add surogate handler.
233
combo->entry_change_id = gtk_signal_connect (GTK_OBJECT (combo->entry), "changed",
234
(GtkSignalFunc) gtk_dummy_callback, combo);
236
// make it more useable
237
gtk_combo_set_use_arrows_always( GTK_COMBO(m_widget), TRUE );
239
// and case-sensitive
240
gtk_combo_set_case_sensitive( GTK_COMBO(m_widget), TRUE );
243
if (style & wxNO_BORDER)
244
g_object_set( GTK_ENTRY( combo->entry ), "has-frame", FALSE, NULL );
247
GtkWidget *list = GTK_COMBO(m_widget)->list;
250
// gtk_list_set_selection_mode( GTK_LIST(list), GTK_SELECTION_MULTIPLE );
253
for (int i = 0; i < n; i++)
255
GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( choices[i] ) );
257
m_clientDataList.Append( (wxObject*)NULL );
258
m_clientObjectList.Append( (wxObject*)NULL );
260
gtk_container_add( GTK_CONTAINER(list), list_item );
262
gtk_widget_show( list_item );
265
m_parent->DoAddChild( this );
267
m_focusWidget = combo->entry;
271
ConnectWidget( combo->button );
273
// MSW's combo box shows the value and the selection is -1
274
gtk_entry_set_text( GTK_ENTRY(combo->entry), wxGTK_CONV(value) );
275
gtk_list_unselect_all( GTK_LIST(combo->list) );
277
if (style & wxCB_READONLY)
278
gtk_entry_set_editable( GTK_ENTRY( combo->entry ), FALSE );
280
// "show" and "hide" events are generated when user click on the combobox button which popups a list
281
// this list is the "popwin" gtk widget
282
gtk_signal_connect( GTK_OBJECT(GTK_COMBO(combo)->popwin), "hide",
283
GTK_SIGNAL_FUNC(gtk_popup_hide_callback), (gpointer)this );
284
gtk_signal_connect( GTK_OBJECT(GTK_COMBO(combo)->popwin), "show",
285
GTK_SIGNAL_FUNC(gtk_popup_show_callback), (gpointer)this );
287
gtk_signal_connect_after( GTK_OBJECT(combo->entry), "changed",
288
GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
290
gtk_signal_connect_after( GTK_OBJECT(combo->list), "select-child",
291
GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
293
SetBestSize(size); // need this too because this is a wxControlWithItems
295
// This is required for tool bar support
296
// wxSize setsize = GetSize();
297
// gtk_widget_set_usize( m_widget, setsize.x, setsize.y );
302
wxComboBox::~wxComboBox()
304
wxList::compatibility_iterator node = m_clientObjectList.GetFirst();
307
wxClientData *cd = (wxClientData*)node->GetData();
309
node = node->GetNext();
311
m_clientObjectList.Clear();
313
m_clientDataList.Clear();
316
void wxComboBox::SetFocus()
320
// don't do anything if we already have focus
324
gtk_widget_grab_focus( m_focusWidget );
327
int wxComboBox::DoAppend( const wxString &item )
329
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
333
GtkWidget *list = GTK_COMBO(m_widget)->list;
335
GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
337
gtk_container_add( GTK_CONTAINER(list), list_item );
339
if (GTK_WIDGET_REALIZED(m_widget))
341
gtk_widget_realize( list_item );
342
gtk_widget_realize( GTK_BIN(list_item)->child );
345
// Apply current widget style to the new list_item
346
GtkRcStyle *style = CreateWidgetStyle();
349
gtk_widget_modify_style( GTK_WIDGET( list_item ), style );
350
GtkBin *bin = GTK_BIN( list_item );
351
GtkWidget *label = GTK_WIDGET( bin->child );
352
gtk_widget_modify_style( label, style );
353
gtk_rc_style_unref( style );
356
gtk_widget_show( list_item );
358
const int count = GetCount();
360
if ( (int)m_clientDataList.GetCount() < count )
361
m_clientDataList.Append( (wxObject*) NULL );
362
if ( (int)m_clientObjectList.GetCount() < count )
363
m_clientObjectList.Append( (wxObject*) NULL );
367
InvalidateBestSize();
372
int wxComboBox::DoInsert( const wxString &item, int pos )
374
wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT), -1,
375
wxT("can't insert into sorted list"));
377
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
379
int count = GetCount();
380
wxCHECK_MSG( (pos >= 0) && (pos <= count), -1, wxT("invalid index") );
387
GtkWidget *list = GTK_COMBO(m_widget)->list;
389
GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
391
GList *gitem_list = g_list_alloc ();
392
gitem_list->data = list_item;
393
gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );
395
if (GTK_WIDGET_REALIZED(m_widget))
397
gtk_widget_realize( list_item );
398
gtk_widget_realize( GTK_BIN(list_item)->child );
403
gtk_widget_show( list_item );
407
if ( (int)m_clientDataList.GetCount() < count )
408
m_clientDataList.Insert( pos, (wxObject*) NULL );
409
if ( (int)m_clientObjectList.GetCount() < count )
410
m_clientObjectList.Insert( pos, (wxObject*) NULL );
414
InvalidateBestSize();
419
void wxComboBox::DoSetItemClientData( int n, void* clientData )
421
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
423
wxList::compatibility_iterator node = m_clientDataList.Item( n );
426
node->SetData( (wxObject*) clientData );
429
void* wxComboBox::DoGetItemClientData( int n ) const
431
wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
433
wxList::compatibility_iterator node = m_clientDataList.Item( n );
435
return node ? node->GetData() : NULL;
438
void wxComboBox::DoSetItemClientObject( int n, wxClientData* clientData )
440
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
442
wxList::compatibility_iterator node = m_clientObjectList.Item( n );
445
// wxItemContainer already deletes data for us
447
node->SetData( (wxObject*) clientData );
450
wxClientData* wxComboBox::DoGetItemClientObject( int n ) const
452
wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") );
454
wxList::compatibility_iterator node = m_clientObjectList.Item( n );
456
return node ? (wxClientData*) node->GetData() : NULL;
459
void wxComboBox::Clear()
461
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
465
GtkWidget *list = GTK_COMBO(m_widget)->list;
466
gtk_list_clear_items( GTK_LIST(list), 0, GetCount() );
468
wxList::compatibility_iterator node = m_clientObjectList.GetFirst();
471
wxClientData *cd = (wxClientData*)node->GetData();
473
node = node->GetNext();
475
m_clientObjectList.Clear();
477
m_clientDataList.Clear();
481
InvalidateBestSize();
484
void wxComboBox::Delete( int n )
486
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
488
GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list );
490
GList *child = g_list_nth( listbox->children, n );
494
wxFAIL_MSG(wxT("wrong index"));
500
GList *list = g_list_append( (GList*) NULL, child->data );
501
gtk_list_remove_items( listbox, list );
504
wxList::compatibility_iterator node = m_clientObjectList.Item( n );
507
wxClientData *cd = (wxClientData*)node->GetData();
509
m_clientObjectList.Erase( node );
512
node = m_clientDataList.Item( n );
514
m_clientDataList.Erase( node );
518
InvalidateBestSize();
521
void wxComboBox::SetString(int n, const wxString &text)
523
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
525
GtkWidget *list = GTK_COMBO(m_widget)->list;
527
GList *child = g_list_nth( GTK_LIST(list)->children, n );
530
GtkBin *bin = GTK_BIN( child->data );
531
GtkLabel *label = GTK_LABEL( bin->child );
532
gtk_label_set_text(label, wxGTK_CONV(text));
536
wxFAIL_MSG( wxT("wxComboBox: wrong index") );
539
InvalidateBestSize();
542
int wxComboBox::FindString( const wxString &item ) const
544
wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid combobox") );
546
GtkWidget *list = GTK_COMBO(m_widget)->list;
548
GList *child = GTK_LIST(list)->children;
552
GtkBin *bin = GTK_BIN( child->data );
553
GtkLabel *label = GTK_LABEL( bin->child );
555
wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
557
wxString str( label->label );
569
int wxComboBox::GetSelection() const
571
// if the popup is currently opened, use the selection as it had been
572
// before it dropped down
573
return g_SelectionBeforePopup == wxID_NONE ? GetCurrentSelection()
574
: g_SelectionBeforePopup;
577
int wxComboBox::GetCurrentSelection() const
579
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
581
GtkWidget *list = GTK_COMBO(m_widget)->list;
583
GList *selection = GTK_LIST(list)->selection;
586
GList *child = GTK_LIST(list)->children;
590
if (child->data == selection->data) return count;
599
wxString wxComboBox::GetString( int n ) const
601
wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid combobox") );
603
GtkWidget *list = GTK_COMBO(m_widget)->list;
606
GList *child = g_list_nth( GTK_LIST(list)->children, n );
609
GtkBin *bin = GTK_BIN( child->data );
610
GtkLabel *label = GTK_LABEL( bin->child );
612
str = wxGTK_CONV_BACK( gtk_label_get_text(label) );
614
str = wxString( label->label );
619
wxFAIL_MSG( wxT("wxComboBox: wrong index") );
625
wxString wxComboBox::GetStringSelection() const
627
wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid combobox") );
629
GtkWidget *list = GTK_COMBO(m_widget)->list;
631
GList *selection = GTK_LIST(list)->selection;
634
GtkBin *bin = GTK_BIN( selection->data );
635
GtkLabel *label = GTK_LABEL( bin->child );
637
wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
639
wxString tmp( label->label );
644
wxFAIL_MSG( wxT("wxComboBox: no selection") );
646
return wxEmptyString;
649
int wxComboBox::GetCount() const
651
wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") );
653
GtkWidget *list = GTK_COMBO(m_widget)->list;
655
GList *child = GTK_LIST(list)->children;
657
while (child) { count++; child = child->next; }
661
void wxComboBox::SetSelection( int n )
663
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
667
GtkWidget *list = GTK_COMBO(m_widget)->list;
668
gtk_list_unselect_item( GTK_LIST(list), m_prevSelection );
669
gtk_list_select_item( GTK_LIST(list), n );
675
wxString wxComboBox::GetValue() const
677
GtkEntry *entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
678
wxString tmp( wxGTK_CONV_BACK( gtk_entry_get_text( entry ) ) );
681
for (int i = 0; i < wxStrlen(tmp.c_str()) +1; i++)
684
printf( "%d ", (int) (c) );
692
void wxComboBox::SetValue( const wxString& value )
694
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
696
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
698
if (!value.IsNull()) tmp = value;
699
gtk_entry_set_text( GTK_ENTRY(entry), wxGTK_CONV( tmp ) );
701
InvalidateBestSize();
704
void wxComboBox::Copy()
706
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
708
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
709
gtk_editable_copy_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG );
712
void wxComboBox::Cut()
714
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
716
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
717
gtk_editable_cut_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG );
720
void wxComboBox::Paste()
722
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
724
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
725
gtk_editable_paste_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG);
728
void wxComboBox::Undo()
733
void wxComboBox::Redo()
738
void wxComboBox::SelectAll()
740
SetSelection(0, GetLastPosition());
743
bool wxComboBox::CanUndo() const
749
bool wxComboBox::CanRedo() const
755
bool wxComboBox::HasSelection() const
758
GetSelection(&from, &to);
762
bool wxComboBox::CanCopy() const
764
// Can copy if there's a selection
765
return HasSelection();
768
bool wxComboBox::CanCut() const
770
return CanCopy() && IsEditable();
773
bool wxComboBox::CanPaste() const
775
// TODO: check for text on the clipboard
776
return IsEditable() ;
779
bool wxComboBox::IsEditable() const
781
return !HasFlag(wxCB_READONLY);
785
void wxComboBox::SetInsertionPoint( long pos )
787
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
789
if ( pos == GetLastPosition() )
792
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
793
gtk_entry_set_position( GTK_ENTRY(entry), (int)pos );
796
long wxComboBox::GetInsertionPoint() const
798
return (long) GET_EDITABLE_POS( GTK_COMBO(m_widget)->entry );
801
wxTextPos wxComboBox::GetLastPosition() const
803
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
804
int pos = GTK_ENTRY(entry)->text_length;
808
void wxComboBox::Replace( long from, long to, const wxString& value )
810
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
812
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
813
gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
814
if (value.IsNull()) return;
818
wxCharBuffer buffer = wxConvUTF8.cWX2MB( value );
819
gtk_editable_insert_text( GTK_EDITABLE(entry), (const char*) buffer, strlen( (const char*) buffer ), &pos );
821
gtk_editable_insert_text( GTK_EDITABLE(entry), value.c_str(), value.Length(), &pos );
825
void wxComboBox::SetSelection( long from, long to )
827
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
828
gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to );
831
void wxComboBox::GetSelection( long* from, long* to ) const
835
GtkEditable *editable = GTK_EDITABLE(GTK_COMBO(m_widget)->entry);
838
gtk_editable_get_selection_bounds(editable, & start, & end);
842
*from = (long) editable->selection_start_pos;
843
*to = (long) editable->selection_end_pos;
848
void wxComboBox::SetEditable( bool editable )
850
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
851
gtk_entry_set_editable( GTK_ENTRY(entry), editable );
854
void wxComboBox::OnChar( wxKeyEvent &event )
856
if ( event.GetKeyCode() == WXK_RETURN )
858
// GTK automatically selects an item if its in the list
859
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, GetId());
860
event.SetString( GetValue() );
861
event.SetInt( GetSelection() );
862
event.SetEventObject( this );
864
if (!GetEventHandler()->ProcessEvent( event ))
866
// This will invoke the dialog default action, such
867
// as the clicking the default button.
869
wxWindow *top_frame = m_parent;
870
while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
871
top_frame = top_frame->GetParent();
873
if (top_frame && GTK_IS_WINDOW(top_frame->m_widget))
875
GtkWindow *window = GTK_WINDOW(top_frame->m_widget);
877
if (window->default_widget)
878
gtk_widget_activate (window->default_widget);
882
// Catch GTK event so that GTK doesn't open the drop
883
// down list upon RETURN.
890
void wxComboBox::DisableEvents()
892
gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget)->list),
893
GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
894
gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget)->entry),
895
GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
898
void wxComboBox::EnableEvents()
900
gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(m_widget)->list), "select-child",
901
GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
902
gtk_signal_connect_after( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed",
903
GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
906
void wxComboBox::OnSize( wxSizeEvent &event )
908
// NB: In some situations (e.g. on non-first page of a wizard, if the
909
// size used is default size), GtkCombo widget is resized correctly,
910
// but it's look is not updated, it's rendered as if it was much wider.
911
// No other widgets are affected, so it looks like a bug in GTK+.
912
// Manually requesting resize calculation (as gtk_pizza_set_size does)
914
if (GTK_WIDGET_VISIBLE(m_widget))
915
gtk_widget_queue_resize(m_widget);
920
void wxComboBox::DoApplyWidgetStyle(GtkRcStyle *style)
922
// gtk_widget_modify_style( GTK_COMBO(m_widget)->button, syle );
924
gtk_widget_modify_style( GTK_COMBO(m_widget)->entry, style );
925
gtk_widget_modify_style( GTK_COMBO(m_widget)->list, style );
927
GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
928
GList *child = list->children;
931
gtk_widget_modify_style( GTK_WIDGET(child->data), style );
933
GtkBin *bin = GTK_BIN(child->data);
934
gtk_widget_modify_style( bin->child, style );
940
GtkWidget* wxComboBox::GetConnectWidget()
942
return GTK_COMBO(m_widget)->entry;
945
bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
947
return ( (window == GTK_ENTRY( GTK_COMBO(m_widget)->entry )->text_area) ||
948
(window == GTK_COMBO(m_widget)->button->window ) );
951
wxSize wxComboBox::DoGetBestSize() const
953
wxSize ret( wxControl::DoGetBestSize() );
955
// we know better our horizontal extent: it depends on the longest string
960
size_t count = GetCount();
961
for ( size_t n = 0; n < count; n++ )
963
GetTextExtent( GetString(n), &width, NULL, NULL, NULL );
969
// empty combobox should have some reasonable default size too
979
wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
981
return GetDefaultAttributesFromGTKWidget(gtk_combo_new, true);
984
// ----------------------------------------------------------------------------
985
// standard event handling
986
// ----------------------------------------------------------------------------
988
void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event))
993
void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event))
998
void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event))
1003
void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event))
1008
void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event))
1013
void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event))
1016
GetSelection(& from, & to);
1017
if (from != -1 && to != -1)
1021
void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event))
1023
SetSelection(-1, -1);
1026
void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event)
1028
event.Enable( CanCut() );
1031
void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event)
1033
event.Enable( CanCopy() );
1036
void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event)
1038
event.Enable( CanPaste() );
1041
void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event)
1043
event.Enable( CanUndo() );
1046
void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event)
1048
event.Enable( CanRedo() );
1051
void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event)
1053
event.Enable(HasSelection() && IsEditable()) ;
1056
void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
1058
event.Enable(GetLastPosition() > 0);