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