]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/combobox.cpp
wxMotif fixes and common fixes for socket compilation
[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 );
31528cd3 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 73 if (g_isIdle) wxapp_install_idle_handler();
31528cd3 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;
31528cd3 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
fd0eed64 363 return -1;
6de97a3b 364}
53010e52 365
debe6624 366wxString wxComboBox::GetString( int n ) const
53010e52 367{
93c5dd39 368 wxCHECK_MSG( m_widget != NULL, _T(""), _T("invalid combobox") );
805dd538 369
fd0eed64 370 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 371
7cf8cb48 372 wxString str;
fd0eed64
RR
373 GList *child = g_list_nth( GTK_LIST(list)->children, n );
374 if (child)
375 {
376 GtkBin *bin = GTK_BIN( child->data );
377 GtkLabel *label = GTK_LABEL( bin->child );
53b88b54 378 str = wxString(label->label,*wxConvCurrent);
7cf8cb48
VZ
379 }
380 else
381 {
93c5dd39 382 wxFAIL_MSG( _T("wxComboBox: wrong index") );
fd0eed64 383 }
805dd538 384
7cf8cb48 385 return str;
6de97a3b 386}
53010e52 387
fd0eed64 388wxString wxComboBox::GetStringSelection() const
53010e52 389{
93c5dd39 390 wxCHECK_MSG( m_widget != NULL, _T(""), _T("invalid combobox") );
805dd538 391
fd0eed64 392 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 393
fd0eed64
RR
394 GList *selection = GTK_LIST(list)->selection;
395 if (selection)
396 {
397 GtkBin *bin = GTK_BIN( selection->data );
53b88b54 398 wxString tmp = wxString(GTK_LABEL( bin->child )->label,*wxConvCurrent);
fd0eed64
RR
399 return tmp;
400 }
805dd538 401
93c5dd39 402 wxFAIL_MSG( _T("wxComboBox: no selection") );
805dd538 403
93c5dd39 404 return _T("");
6de97a3b 405}
53010e52 406
fd0eed64 407int wxComboBox::Number() const
53010e52 408{
93c5dd39 409 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid combobox") );
805dd538 410
fd0eed64 411 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 412
fd0eed64
RR
413 GList *child = GTK_LIST(list)->children;
414 int count = 0;
415 while (child) { count++; child = child->next; }
416 return count;
6de97a3b 417}
53010e52 418
debe6624 419void wxComboBox::SetSelection( int n )
53010e52 420{
93c5dd39 421 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 422
953704c1
RR
423 DisableEvents();
424
fd0eed64
RR
425 GtkWidget *list = GTK_COMBO(m_widget)->list;
426 gtk_list_select_item( GTK_LIST(list), n );
953704c1
RR
427
428 EnableEvents();
6de97a3b 429}
53010e52 430
47908e25
RR
431void wxComboBox::SetStringSelection( const wxString &string )
432{
93c5dd39 433 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 434
fd0eed64
RR
435 int res = FindString( string );
436 if (res == -1) return;
437 SetSelection( res );
6de97a3b 438}
47908e25 439
fd0eed64 440wxString wxComboBox::GetValue() const
53010e52 441{
fd0eed64 442 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
53b88b54 443 wxString tmp = wxString(gtk_entry_get_text( GTK_ENTRY(entry) ),*wxConvCurrent);
fd0eed64 444 return tmp;
6de97a3b 445}
53010e52
RR
446
447void wxComboBox::SetValue( const wxString& value )
448{
93c5dd39 449 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 450
fd0eed64 451 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
93c5dd39 452 wxString tmp = _T("");
fd0eed64 453 if (!value.IsNull()) tmp = value;
93c5dd39 454 gtk_entry_set_text( GTK_ENTRY(entry), tmp.mbc_str() );
6de97a3b 455}
53010e52 456
fd0eed64 457void wxComboBox::Copy()
53010e52 458{
93c5dd39 459 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 460
fd0eed64 461 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
d345e841 462#if (GTK_MINOR_VERSION > 0)
fd0eed64 463 gtk_editable_copy_clipboard( GTK_EDITABLE(entry) );
75ed1d15 464#else
fd0eed64 465 gtk_editable_copy_clipboard( GTK_EDITABLE(entry), 0 );
75ed1d15 466#endif
6de97a3b 467}
53010e52 468
fd0eed64 469void wxComboBox::Cut()
53010e52 470{
93c5dd39 471 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 472
fd0eed64 473 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
d345e841 474#if (GTK_MINOR_VERSION > 0)
fd0eed64 475 gtk_editable_cut_clipboard( GTK_EDITABLE(entry) );
75ed1d15 476#else
fd0eed64 477 gtk_editable_cut_clipboard( GTK_EDITABLE(entry), 0 );
75ed1d15 478#endif
6de97a3b 479}
53010e52 480
fd0eed64 481void wxComboBox::Paste()
53010e52 482{
93c5dd39 483 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 484
fd0eed64 485 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
d345e841 486#if (GTK_MINOR_VERSION > 0)
fd0eed64 487 gtk_editable_paste_clipboard( GTK_EDITABLE(entry) );
75ed1d15 488#else
fd0eed64 489 gtk_editable_paste_clipboard( GTK_EDITABLE(entry), 0 );
75ed1d15 490#endif
6de97a3b 491}
53010e52 492
debe6624 493void wxComboBox::SetInsertionPoint( long pos )
53010e52 494{
93c5dd39 495 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 496
fd0eed64 497 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
073c8fe9 498 gtk_entry_set_position( GTK_ENTRY(entry), (int)pos );
6de97a3b 499}
53010e52 500
fd0eed64 501void wxComboBox::SetInsertionPointEnd()
53010e52 502{
93c5dd39 503 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538
VZ
504
505 SetInsertionPoint( -1 );
6de97a3b 506}
53010e52 507
fd0eed64 508long wxComboBox::GetInsertionPoint() const
53010e52 509{
fd0eed64
RR
510 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
511 return (long) GTK_EDITABLE(entry)->current_pos;
6de97a3b 512}
53010e52 513
fd0eed64 514long wxComboBox::GetLastPosition() const
53010e52 515{
fd0eed64
RR
516 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
517 int pos = GTK_ENTRY(entry)->text_length;
518 return (long) pos-1;
6de97a3b 519}
53010e52 520
debe6624 521void wxComboBox::Replace( long from, long to, const wxString& value )
53010e52 522{
93c5dd39
OK
523 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
524 // FIXME: not quite sure how to do this method right in multibyte mode
805dd538 525
fd0eed64
RR
526 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
527 gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
528 if (value.IsNull()) return;
529 gint pos = (gint)to;
93c5dd39 530 gtk_editable_insert_text( GTK_EDITABLE(entry), value.mbc_str(), value.Length(), &pos );
6de97a3b 531}
53010e52 532
debe6624 533void wxComboBox::Remove(long from, long to)
53010e52 534{
93c5dd39 535 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
805dd538 536
fd0eed64
RR
537 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
538 gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
6de97a3b 539}
53010e52 540
20d10ee1 541void wxComboBox::SetSelection( long from, long to )
53010e52 542{
20d10ee1
VZ
543 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
544 gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to );
6de97a3b 545}
53010e52 546
20d10ee1 547void wxComboBox::SetEditable( bool editable )
53010e52 548{
20d10ee1
VZ
549 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
550 gtk_entry_set_editable( GTK_ENTRY(entry), editable );
b4071e91
RR
551}
552
8a85884a
VZ
553void wxComboBox::OnChar( wxKeyEvent &event )
554{
7cf8cb48 555 if ( event.KeyCode() == WXK_RETURN )
8a85884a 556 {
7cf8cb48 557 wxString value = GetValue();
8a85884a 558
7cf8cb48
VZ
559 if ( Number() == 0 )
560 {
561 // make Enter generate "selected" event if there is only one item
562 // in the combobox - without it, it's impossible to select it at
563 // all!
564 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
565 event.SetInt( 0 );
29006414 566 event.SetString( value );
7cf8cb48
VZ
567 event.SetEventObject( this );
568 GetEventHandler()->ProcessEvent( event );
569 }
570 else
571 {
572 // add the item to the list if it's not there yet
573 if ( FindString(value) == wxNOT_FOUND )
574 {
575 Append(value);
576
577 // and generate the selected event for it
578 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
579 event.SetInt( Number() - 1 );
29006414 580 event.SetString( value );
7cf8cb48
VZ
581 event.SetEventObject( this );
582 GetEventHandler()->ProcessEvent( event );
583 }
584 //else: do nothing, this will open the listbox
585 }
8a85884a 586 }
7cf8cb48
VZ
587
588 event.Skip();
8a85884a
VZ
589}
590
953704c1
RR
591void wxComboBox::DisableEvents()
592{
593 GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
594 GList *child = list->children;
595 while (child)
596 {
31528cd3 597 gtk_signal_disconnect_by_func( GTK_OBJECT(child->data),
953704c1
RR
598 GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
599
600 child = child->next;
601 }
602}
603
604void wxComboBox::EnableEvents()
605{
606 GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
607 GList *child = list->children;
608 while (child)
609 {
610 gtk_signal_connect( GTK_OBJECT(child->data), "select",
611 GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
612
613 child = child->next;
614 }
615}
616
b4071e91
RR
617void wxComboBox::OnSize( wxSizeEvent &event )
618{
f03fc89f 619 event.Skip();
31528cd3 620
fdd3ed7a 621 return;
805dd538 622
fd0eed64
RR
623 int w = 21;
624 gtk_widget_set_usize( GTK_COMBO(m_widget)->entry, m_width-w-1, m_height );
805dd538 625
fd0eed64
RR
626 gtk_widget_set_uposition( GTK_COMBO(m_widget)->button, m_x+m_width-w, m_y );
627 gtk_widget_set_usize( GTK_COMBO(m_widget)->button, w, m_height );
6de97a3b 628}
53010e52 629
58614078 630void wxComboBox::ApplyWidgetStyle()
868a2826 631{
fd0eed64 632 SetWidgetStyle();
805dd538 633
72a16063 634// gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle );
fd0eed64
RR
635 gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle );
636 gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle );
805dd538 637
fd0eed64
RR
638 GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
639 GList *child = list->children;
640 while (child)
641 {
642 gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
805dd538 643
fd0eed64
RR
644 GtkBin *bin = GTK_BIN(child->data);
645 gtk_widget_set_style( bin->child, m_widgetStyle );
805dd538 646
fd0eed64
RR
647 child = child->next;
648 }
868a2826 649}
b4071e91 650
fd0eed64 651GtkWidget* wxComboBox::GetConnectWidget()
97b3455a 652{
fd0eed64 653 return GTK_COMBO(m_widget)->entry;
97b3455a
RR
654}
655
b4071e91
RR
656bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
657{
fd0eed64
RR
658 return ( (window == GTK_ENTRY( GTK_COMBO(m_widget)->entry )->text_area) ||
659 (window == GTK_COMBO(m_widget)->button->window ) );
b4071e91 660}
ac57418f 661
dcf924a3 662#endif