]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/combobox.cpp
Convert argv[] to Unicode
[wxWidgets.git] / src / gtk1 / combobox.cpp
CommitLineData
53010e52
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: combobox.cpp
3// Purpose:
4// Author: Robert Roebling
dbf858b5 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
805dd538 7// Licence: wxWindows licence
53010e52
RR
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "combobox.h"
12#endif
13
14#include "wx/combobox.h"
dcf924a3
RR
15
16#if wxUSE_COMBOBOX
17
72a16063 18#include "wx/settings.h"
b62c3631 19#include "wx/intl.h"
53010e52 20
83624f79
RR
21#include "gdk/gdk.h"
22#include "gtk/gtk.h"
23
acfd422a
RR
24//-----------------------------------------------------------------------------
25// idle system
26//-----------------------------------------------------------------------------
27
28extern void wxapp_install_idle_handler();
29extern bool g_isIdle;
30
47908e25
RR
31//-----------------------------------------------------------------------------
32// data
33//-----------------------------------------------------------------------------
34
35extern bool g_blockEventsOnDrag;
36
53010e52 37//-----------------------------------------------------------------------------
e1e955e1 38// "select"
47908e25 39//-----------------------------------------------------------------------------
47908e25 40
8a85884a
VZ
41static void
42gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
53010e52 43{
acfd422a 44 if (g_isIdle) wxapp_install_idle_handler();
8a85884a 45
a2053b27 46 if (!combo->m_hasVMT) return;
acfd422a
RR
47
48 if (g_blockEventsOnDrag) return;
805dd538 49
fd0eed64
RR
50 if (combo->m_alreadySent)
51 {
52 combo->m_alreadySent = FALSE;
53 return;
54 }
47908e25 55
fd0eed64 56 combo->m_alreadySent = TRUE;
805dd538 57
8a85884a 58 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
fd0eed64 59 event.SetInt( combo->GetSelection() );
29006414 60 event.SetString( combo->GetStringSelection() );
8a85884a 61 event.SetEventObject( combo );
ec5d85fb 62
8a85884a 63 combo->GetEventHandler()->ProcessEvent( event );
6de97a3b 64}
47908e25 65
0c77152e
RR
66//-----------------------------------------------------------------------------
67// "changed"
68//-----------------------------------------------------------------------------
69
eeccd5d9 70static void
0c77152e
RR
71gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
72{
acfd422a
RR
73 if (g_isIdle) wxapp_install_idle_handler();
74
a2053b27
RR
75 if (!combo->m_hasVMT) return;
76
8a85884a 77 wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
29006414 78 event.SetString( combo->GetValue() );
0c77152e
RR
79 event.SetEventObject( combo );
80 combo->GetEventHandler()->ProcessEvent( event );
0c77152e
RR
81}
82
e1e955e1
RR
83//-----------------------------------------------------------------------------
84// wxComboBox
53010e52
RR
85//-----------------------------------------------------------------------------
86
87IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl)
88
b4071e91 89BEGIN_EVENT_TABLE(wxComboBox, wxControl)
fd0eed64 90 EVT_SIZE(wxComboBox::OnSize)
8a85884a 91 EVT_CHAR(wxComboBox::OnChar)
b4071e91
RR
92END_EVENT_TABLE()
93
fd0eed64
RR
94bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
95 const wxPoint& pos, const wxSize& size,
96 int n, const wxString choices[],
805dd538
VZ
97 long style, const wxValidator& validator,
98 const wxString& name )
53010e52 99{
fd0eed64
RR
100 m_alreadySent = FALSE;
101 m_needParent = TRUE;
b292e2f5 102 m_acceptsFocus = TRUE;
805dd538 103
fd0eed64 104 PreCreation( parent, id, pos, size, style, name );
805dd538 105
ce4169a4 106#if wxUSE_VALIDATORS
fd0eed64 107 SetValidator( validator );
ce4169a4 108#endif
6de97a3b 109
fd0eed64 110 m_widget = gtk_combo_new();
805dd538 111
8a85884a
VZ
112 // make it more useable
113 gtk_combo_set_use_arrows_always(GTK_COMBO(m_widget), TRUE);
114
fd0eed64 115 wxSize newSize = size;
8a85884a
VZ
116 if (newSize.x == -1)
117 newSize.x = 100;
118 if (newSize.y == -1)
fdd3ed7a 119 newSize.y = 26;
fd0eed64 120 SetSize( newSize.x, newSize.y );
805dd538 121
fd0eed64 122 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 123
fd0eed64
RR
124 for (int i = 0; i < n; i++)
125 {
19da4326
RR
126 /* don't send first event, which GTK sends aways when
127 inserting the first item */
128 m_alreadySent = TRUE;
129
93c5dd39 130 GtkWidget *list_item = gtk_list_item_new_with_label( choices[i].mbc_str() );
805dd538 131
fd0eed64 132 m_clientDataList.Append( (wxObject*)NULL );
f5e27805 133 m_clientObjectList.Append( (wxObject*)NULL );
805dd538 134
fd0eed64 135 gtk_container_add( GTK_CONTAINER(list), list_item );
805dd538 136
805dd538 137 gtk_signal_connect( GTK_OBJECT(list_item), "select",
19da4326
RR
138 GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
139
140 gtk_widget_show( list_item );
fd0eed64 141 }
805dd538 142
f03fc89f 143 m_parent->DoAddChild( this );
805dd538 144
fd0eed64 145 PostCreation();
53010e52 146
fd0eed64 147 ConnectWidget( GTK_COMBO(m_widget)->button );
805dd538 148
fd0eed64 149 if (!value.IsNull()) SetValue( value );
805dd538 150
a260fe6a
RR
151 if (style & wxCB_READONLY)
152 gtk_entry_set_editable( GTK_ENTRY( GTK_COMBO(m_widget)->entry ), FALSE );
153
0c77152e
RR
154 gtk_signal_connect( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed",
155 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
805dd538 156
72a16063 157 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW ) );
fd0eed64 158 SetForegroundColour( parent->GetForegroundColour() );
a7ac4461 159 SetFont( parent->GetFont() );
f96aa4d9 160
fd0eed64 161 Show( TRUE );
805dd538 162
fd0eed64
RR
163 return TRUE;
164}
165
166wxComboBox::~wxComboBox()
167{
7d6d2cd4 168 wxNode *node = m_clientObjectList.First();
fd0eed64
RR
169 while (node)
170 {
171 wxClientData *cd = (wxClientData*)node->Data();
172 if (cd) delete cd;
173 node = node->Next();
174 }
7d6d2cd4
RR
175 m_clientObjectList.Clear();
176
fd0eed64 177 m_clientDataList.Clear();
6de97a3b 178}
53010e52 179
fd0eed64 180void wxComboBox::AppendCommon( const wxString &item )
53010e52 181{
93c5dd39 182 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 183
fd0eed64 184 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 185
93c5dd39 186 GtkWidget *list_item = gtk_list_item_new_with_label( item.mbc_str() );
805dd538 187
ec5d85fb
RR
188 gtk_container_add( GTK_CONTAINER(list), list_item );
189
805dd538 190 gtk_signal_connect( GTK_OBJECT(list_item), "select",
fd0eed64 191 GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
805dd538 192
2b07d713
RR
193 if (GTK_WIDGET_REALIZED(m_widget))
194 {
195 gtk_widget_realize( list_item );
196 gtk_widget_realize( GTK_BIN(list_item)->child );
197
198 if (m_widgetStyle) ApplyWidgetStyle();
199 }
805dd538 200
fd0eed64 201 gtk_widget_show( list_item );
6de97a3b 202}
53010e52
RR
203
204void wxComboBox::Append( const wxString &item )
47908e25 205{
f5e27805
RR
206 m_clientDataList.Append( (wxObject*) NULL );
207 m_clientObjectList.Append( (wxObject*) NULL );
805dd538 208
fd0eed64 209 AppendCommon( item );
6de97a3b 210}
47908e25 211
fd0eed64 212void wxComboBox::Append( const wxString &item, void *clientData )
53010e52 213{
f5e27805
RR
214 m_clientDataList.Append( (wxObject*) clientData );
215 m_clientObjectList.Append( (wxObject*)NULL );
805dd538 216
fd0eed64 217 AppendCommon( item );
6de97a3b 218}
53010e52 219
fd0eed64 220void wxComboBox::Append( const wxString &item, wxClientData *clientData )
53010e52 221{
f5e27805
RR
222 m_clientDataList.Append( (wxObject*) NULL );
223 m_clientObjectList.Append( (wxObject*) clientData );
805dd538 224
fd0eed64
RR
225 AppendCommon( item );
226}
227
228void wxComboBox::SetClientData( int n, void* clientData )
229{
93c5dd39 230 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 231
fd0eed64
RR
232 wxNode *node = m_clientDataList.Nth( n );
233 if (!node) return;
805dd538 234
f5e27805 235 node->SetData( (wxObject*) clientData );
6de97a3b 236}
53010e52 237
fd0eed64 238void* wxComboBox::GetClientData( int n )
53010e52 239{
93c5dd39 240 wxCHECK_MSG( m_widget != NULL, NULL, _T("invalid combobox") );
805dd538 241
fd0eed64
RR
242 wxNode *node = m_clientDataList.Nth( n );
243 if (!node) return NULL;
805dd538 244
f5e27805 245 return node->Data();
fd0eed64
RR
246}
247
248void wxComboBox::SetClientObject( int n, wxClientData* clientData )
249{
93c5dd39 250 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 251
f5e27805 252 wxNode *node = m_clientObjectList.Nth( n );
fd0eed64 253 if (!node) return;
805dd538 254
fd0eed64
RR
255 wxClientData *cd = (wxClientData*) node->Data();
256 if (cd) delete cd;
805dd538 257
fd0eed64 258 node->SetData( (wxObject*) clientData );
6de97a3b 259}
53010e52 260
fd0eed64 261wxClientData* wxComboBox::GetClientObject( int n )
53010e52 262{
93c5dd39 263 wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, _T("invalid combobox") );
805dd538 264
fd0eed64
RR
265 wxNode *node = m_clientDataList.Nth( n );
266 if (!node) return (wxClientData*) NULL;
805dd538 267
fd0eed64
RR
268 return (wxClientData*) node->Data();
269}
270
271void wxComboBox::Clear()
272{
93c5dd39 273 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 274
fd0eed64
RR
275 GtkWidget *list = GTK_COMBO(m_widget)->list;
276 gtk_list_clear_items( GTK_LIST(list), 0, Number() );
805dd538 277
f5e27805 278 wxNode *node = m_clientObjectList.First();
fd0eed64
RR
279 while (node)
280 {
281 wxClientData *cd = (wxClientData*)node->Data();
282 if (cd) delete cd;
283 node = node->Next();
284 }
f5e27805 285 m_clientObjectList.Clear();
805dd538 286
fd0eed64 287 m_clientDataList.Clear();
6de97a3b 288}
53010e52 289
fd0eed64 290void wxComboBox::Delete( int n )
53010e52 291{
93c5dd39 292 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 293
fd0eed64 294 GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list );
805dd538 295
fd0eed64 296 GList *child = g_list_nth( listbox->children, n );
805dd538 297
fd0eed64
RR
298 if (!child)
299 {
93c5dd39 300 wxFAIL_MSG(_T("wrong index"));
fd0eed64
RR
301 return;
302 }
805dd538 303
bbe0af5b 304 GList *list = g_list_append( (GList*) NULL, child->data );
fd0eed64
RR
305 gtk_list_remove_items( listbox, list );
306 g_list_free( list );
805dd538 307
f5e27805
RR
308 wxNode *node = m_clientObjectList.Nth( n );
309 if (node)
fd0eed64
RR
310 {
311 wxClientData *cd = (wxClientData*)node->Data();
312 if (cd) delete cd;
f5e27805
RR
313 m_clientObjectList.DeleteNode( node );
314 }
805dd538 315
f5e27805
RR
316 node = m_clientDataList.Nth( n );
317 if (node)
318 {
fd0eed64
RR
319 m_clientDataList.DeleteNode( node );
320 }
6de97a3b 321}
53010e52 322
fd0eed64 323int wxComboBox::FindString( const wxString &item )
53010e52 324{
93c5dd39 325 wxCHECK_MSG( m_widget != NULL, -1, _T("invalid combobox") );
805dd538 326
fd0eed64 327 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 328
53010e52
RR
329 GList *child = GTK_LIST(list)->children;
330 int count = 0;
331 while (child)
332 {
fd0eed64
RR
333 GtkBin *bin = GTK_BIN( child->data );
334 GtkLabel *label = GTK_LABEL( bin->child );
53b88b54 335 if (item == wxString(label->label,*wxConvCurrent))
7cf8cb48 336 return count;
fd0eed64
RR
337 count++;
338 child = child->next;
339 }
805dd538 340
7cf8cb48 341 return wxNOT_FOUND;
fd0eed64
RR
342}
343
344int wxComboBox::GetSelection() const
345{
93c5dd39 346 wxCHECK_MSG( m_widget != NULL, -1, _T("invalid combobox") );
805dd538 347
fd0eed64 348 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 349
fd0eed64
RR
350 GList *selection = GTK_LIST(list)->selection;
351 if (selection)
352 {
353 GList *child = GTK_LIST(list)->children;
354 int count = 0;
355 while (child)
356 {
357 if (child->data == selection->data) return count;
358 count++;
359 child = child->next;
360 }
6de97a3b 361 }
805dd538 362
93c5dd39 363 wxFAIL_MSG( _T("wxComboBox: no selection") );
805dd538 364
fd0eed64 365 return -1;
6de97a3b 366}
53010e52 367
debe6624 368wxString wxComboBox::GetString( int n ) const
53010e52 369{
93c5dd39 370 wxCHECK_MSG( m_widget != NULL, _T(""), _T("invalid combobox") );
805dd538 371
fd0eed64 372 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 373
7cf8cb48 374 wxString str;
fd0eed64
RR
375 GList *child = g_list_nth( GTK_LIST(list)->children, n );
376 if (child)
377 {
378 GtkBin *bin = GTK_BIN( child->data );
379 GtkLabel *label = GTK_LABEL( bin->child );
53b88b54 380 str = wxString(label->label,*wxConvCurrent);
7cf8cb48
VZ
381 }
382 else
383 {
93c5dd39 384 wxFAIL_MSG( _T("wxComboBox: wrong index") );
fd0eed64 385 }
805dd538 386
7cf8cb48 387 return str;
6de97a3b 388}
53010e52 389
fd0eed64 390wxString wxComboBox::GetStringSelection() const
53010e52 391{
93c5dd39 392 wxCHECK_MSG( m_widget != NULL, _T(""), _T("invalid combobox") );
805dd538 393
fd0eed64 394 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 395
fd0eed64
RR
396 GList *selection = GTK_LIST(list)->selection;
397 if (selection)
398 {
399 GtkBin *bin = GTK_BIN( selection->data );
53b88b54 400 wxString tmp = wxString(GTK_LABEL( bin->child )->label,*wxConvCurrent);
fd0eed64
RR
401 return tmp;
402 }
805dd538 403
93c5dd39 404 wxFAIL_MSG( _T("wxComboBox: no selection") );
805dd538 405
93c5dd39 406 return _T("");
6de97a3b 407}
53010e52 408
fd0eed64 409int wxComboBox::Number() const
53010e52 410{
93c5dd39 411 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid combobox") );
805dd538 412
fd0eed64 413 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 414
fd0eed64
RR
415 GList *child = GTK_LIST(list)->children;
416 int count = 0;
417 while (child) { count++; child = child->next; }
418 return count;
6de97a3b 419}
53010e52 420
debe6624 421void wxComboBox::SetSelection( int n )
53010e52 422{
93c5dd39 423 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 424
953704c1
RR
425 DisableEvents();
426
fd0eed64
RR
427 GtkWidget *list = GTK_COMBO(m_widget)->list;
428 gtk_list_select_item( GTK_LIST(list), n );
953704c1
RR
429
430 EnableEvents();
6de97a3b 431}
53010e52 432
47908e25
RR
433void wxComboBox::SetStringSelection( const wxString &string )
434{
93c5dd39 435 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 436
fd0eed64
RR
437 int res = FindString( string );
438 if (res == -1) return;
439 SetSelection( res );
6de97a3b 440}
47908e25 441
fd0eed64 442wxString wxComboBox::GetValue() const
53010e52 443{
fd0eed64 444 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
53b88b54 445 wxString tmp = wxString(gtk_entry_get_text( GTK_ENTRY(entry) ),*wxConvCurrent);
fd0eed64 446 return tmp;
6de97a3b 447}
53010e52
RR
448
449void wxComboBox::SetValue( const wxString& value )
450{
93c5dd39 451 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 452
fd0eed64 453 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
93c5dd39 454 wxString tmp = _T("");
fd0eed64 455 if (!value.IsNull()) tmp = value;
93c5dd39 456 gtk_entry_set_text( GTK_ENTRY(entry), tmp.mbc_str() );
6de97a3b 457}
53010e52 458
fd0eed64 459void wxComboBox::Copy()
53010e52 460{
93c5dd39 461 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 462
fd0eed64 463 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
d345e841 464#if (GTK_MINOR_VERSION > 0)
fd0eed64 465 gtk_editable_copy_clipboard( GTK_EDITABLE(entry) );
75ed1d15 466#else
fd0eed64 467 gtk_editable_copy_clipboard( GTK_EDITABLE(entry), 0 );
75ed1d15 468#endif
6de97a3b 469}
53010e52 470
fd0eed64 471void wxComboBox::Cut()
53010e52 472{
93c5dd39 473 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 474
fd0eed64 475 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
d345e841 476#if (GTK_MINOR_VERSION > 0)
fd0eed64 477 gtk_editable_cut_clipboard( GTK_EDITABLE(entry) );
75ed1d15 478#else
fd0eed64 479 gtk_editable_cut_clipboard( GTK_EDITABLE(entry), 0 );
75ed1d15 480#endif
6de97a3b 481}
53010e52 482
fd0eed64 483void wxComboBox::Paste()
53010e52 484{
93c5dd39 485 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 486
fd0eed64 487 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
d345e841 488#if (GTK_MINOR_VERSION > 0)
fd0eed64 489 gtk_editable_paste_clipboard( GTK_EDITABLE(entry) );
75ed1d15 490#else
fd0eed64 491 gtk_editable_paste_clipboard( GTK_EDITABLE(entry), 0 );
75ed1d15 492#endif
6de97a3b 493}
53010e52 494
debe6624 495void wxComboBox::SetInsertionPoint( long pos )
53010e52 496{
93c5dd39 497 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 498
fd0eed64 499 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
073c8fe9 500 gtk_entry_set_position( GTK_ENTRY(entry), (int)pos );
6de97a3b 501}
53010e52 502
fd0eed64 503void wxComboBox::SetInsertionPointEnd()
53010e52 504{
93c5dd39 505 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538
VZ
506
507 SetInsertionPoint( -1 );
6de97a3b 508}
53010e52 509
fd0eed64 510long wxComboBox::GetInsertionPoint() const
53010e52 511{
fd0eed64
RR
512 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
513 return (long) GTK_EDITABLE(entry)->current_pos;
6de97a3b 514}
53010e52 515
fd0eed64 516long wxComboBox::GetLastPosition() const
53010e52 517{
fd0eed64
RR
518 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
519 int pos = GTK_ENTRY(entry)->text_length;
520 return (long) pos-1;
6de97a3b 521}
53010e52 522
debe6624 523void wxComboBox::Replace( long from, long to, const wxString& value )
53010e52 524{
93c5dd39
OK
525 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
526 // FIXME: not quite sure how to do this method right in multibyte mode
805dd538 527
fd0eed64
RR
528 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
529 gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
530 if (value.IsNull()) return;
531 gint pos = (gint)to;
93c5dd39 532 gtk_editable_insert_text( GTK_EDITABLE(entry), value.mbc_str(), value.Length(), &pos );
6de97a3b 533}
53010e52 534
debe6624 535void wxComboBox::Remove(long from, long to)
53010e52 536{
93c5dd39 537 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 538
fd0eed64
RR
539 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
540 gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
6de97a3b 541}
53010e52 542
20d10ee1 543void wxComboBox::SetSelection( long from, long to )
53010e52 544{
20d10ee1
VZ
545 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
546 gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to );
6de97a3b 547}
53010e52 548
20d10ee1 549void wxComboBox::SetEditable( bool editable )
53010e52 550{
20d10ee1
VZ
551 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
552 gtk_entry_set_editable( GTK_ENTRY(entry), editable );
b4071e91
RR
553}
554
8a85884a
VZ
555void wxComboBox::OnChar( wxKeyEvent &event )
556{
7cf8cb48 557 if ( event.KeyCode() == WXK_RETURN )
8a85884a 558 {
7cf8cb48 559 wxString value = GetValue();
8a85884a 560
7cf8cb48
VZ
561 if ( Number() == 0 )
562 {
563 // make Enter generate "selected" event if there is only one item
564 // in the combobox - without it, it's impossible to select it at
565 // all!
566 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
567 event.SetInt( 0 );
29006414 568 event.SetString( value );
7cf8cb48
VZ
569 event.SetEventObject( this );
570 GetEventHandler()->ProcessEvent( event );
571 }
572 else
573 {
574 // add the item to the list if it's not there yet
575 if ( FindString(value) == wxNOT_FOUND )
576 {
577 Append(value);
578
579 // and generate the selected event for it
580 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
581 event.SetInt( Number() - 1 );
29006414 582 event.SetString( value );
7cf8cb48
VZ
583 event.SetEventObject( this );
584 GetEventHandler()->ProcessEvent( event );
585 }
586 //else: do nothing, this will open the listbox
587 }
8a85884a 588 }
7cf8cb48
VZ
589
590 event.Skip();
8a85884a
VZ
591}
592
953704c1
RR
593void wxComboBox::DisableEvents()
594{
595 GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
596 GList *child = list->children;
597 while (child)
598 {
599 gtk_signal_disconnect_by_func( GTK_OBJECT(child->data),
600 GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
601
602 child = child->next;
603 }
604}
605
606void wxComboBox::EnableEvents()
607{
608 GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
609 GList *child = list->children;
610 while (child)
611 {
612 gtk_signal_connect( GTK_OBJECT(child->data), "select",
613 GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
614
615 child = child->next;
616 }
617}
618
b4071e91
RR
619void wxComboBox::OnSize( wxSizeEvent &event )
620{
f03fc89f 621 event.Skip();
fdd3ed7a
RR
622
623 return;
805dd538 624
fd0eed64
RR
625 int w = 21;
626 gtk_widget_set_usize( GTK_COMBO(m_widget)->entry, m_width-w-1, m_height );
805dd538 627
fd0eed64
RR
628 gtk_widget_set_uposition( GTK_COMBO(m_widget)->button, m_x+m_width-w, m_y );
629 gtk_widget_set_usize( GTK_COMBO(m_widget)->button, w, m_height );
6de97a3b 630}
53010e52 631
58614078 632void wxComboBox::ApplyWidgetStyle()
868a2826 633{
fd0eed64 634 SetWidgetStyle();
805dd538 635
72a16063 636// gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle );
fd0eed64
RR
637 gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle );
638 gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle );
805dd538 639
fd0eed64
RR
640 GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
641 GList *child = list->children;
642 while (child)
643 {
644 gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
805dd538 645
fd0eed64
RR
646 GtkBin *bin = GTK_BIN(child->data);
647 gtk_widget_set_style( bin->child, m_widgetStyle );
805dd538 648
fd0eed64
RR
649 child = child->next;
650 }
868a2826 651}
b4071e91 652
fd0eed64 653GtkWidget* wxComboBox::GetConnectWidget()
97b3455a 654{
fd0eed64 655 return GTK_COMBO(m_widget)->entry;
97b3455a
RR
656}
657
b4071e91
RR
658bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
659{
fd0eed64
RR
660 return ( (window == GTK_ENTRY( GTK_COMBO(m_widget)->entry )->text_area) ||
661 (window == GTK_COMBO(m_widget)->button->window ) );
b4071e91 662}
ac57418f 663
dcf924a3 664#endif