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