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