]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/combobox.cpp
BC++ compialtion fix (?)
[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
d984207c
RR
104 wxSize newSize( size );
105 if (newSize.x == -1)
106 newSize.x = 80;
107 if (newSize.y == -1)
108 newSize.y = 26;
109 if (newSize.y > 30)
110 newSize.y = 30;
111
112 if (!PreCreation( parent, pos, newSize ) ||
4dcaf11a
RR
113 !CreateBase( parent, id, pos, size, style, validator, name ))
114 {
223d09f6 115 wxFAIL_MSG( wxT("wxComboBox creation failed") );
4dcaf11a
RR
116 return FALSE;
117 }
6de97a3b 118
fd0eed64 119 m_widget = gtk_combo_new();
805dd538 120
8a85884a
VZ
121 // make it more useable
122 gtk_combo_set_use_arrows_always(GTK_COMBO(m_widget), TRUE);
123
fd0eed64 124 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 125
fd0eed64
RR
126 for (int i = 0; i < n; i++)
127 {
19da4326
RR
128 /* don't send first event, which GTK sends aways when
129 inserting the first item */
130 m_alreadySent = TRUE;
31528cd3 131
93c5dd39 132 GtkWidget *list_item = gtk_list_item_new_with_label( choices[i].mbc_str() );
805dd538 133
fd0eed64 134 m_clientDataList.Append( (wxObject*)NULL );
f5e27805 135 m_clientObjectList.Append( (wxObject*)NULL );
805dd538 136
fd0eed64 137 gtk_container_add( GTK_CONTAINER(list), list_item );
805dd538 138
805dd538 139 gtk_signal_connect( GTK_OBJECT(list_item), "select",
19da4326
RR
140 GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
141
142 gtk_widget_show( list_item );
fd0eed64 143 }
805dd538 144
f03fc89f 145 m_parent->DoAddChild( this );
805dd538 146
fd0eed64 147 PostCreation();
53010e52 148
fd0eed64 149 ConnectWidget( GTK_COMBO(m_widget)->button );
805dd538 150
fd0eed64 151 if (!value.IsNull()) SetValue( value );
805dd538 152
a260fe6a
RR
153 if (style & wxCB_READONLY)
154 gtk_entry_set_editable( GTK_ENTRY( GTK_COMBO(m_widget)->entry ), FALSE );
155
0c77152e
RR
156 gtk_signal_connect( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed",
157 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
805dd538 158
72a16063 159 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW ) );
fd0eed64 160 SetForegroundColour( parent->GetForegroundColour() );
a7ac4461 161 SetFont( parent->GetFont() );
f96aa4d9 162
fd0eed64 163 Show( TRUE );
805dd538 164
fd0eed64
RR
165 return TRUE;
166}
167
168wxComboBox::~wxComboBox()
169{
7d6d2cd4 170 wxNode *node = m_clientObjectList.First();
fd0eed64
RR
171 while (node)
172 {
173 wxClientData *cd = (wxClientData*)node->Data();
174 if (cd) delete cd;
175 node = node->Next();
176 }
7d6d2cd4
RR
177 m_clientObjectList.Clear();
178
fd0eed64 179 m_clientDataList.Clear();
6de97a3b 180}
53010e52 181
fd0eed64 182void wxComboBox::AppendCommon( const wxString &item )
53010e52 183{
223d09f6 184 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
805dd538 185
fd0eed64 186 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 187
93c5dd39 188 GtkWidget *list_item = gtk_list_item_new_with_label( item.mbc_str() );
805dd538 189
ec5d85fb
RR
190 gtk_container_add( GTK_CONTAINER(list), list_item );
191
805dd538 192 gtk_signal_connect( GTK_OBJECT(list_item), "select",
fd0eed64 193 GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
805dd538 194
2b07d713
RR
195 if (GTK_WIDGET_REALIZED(m_widget))
196 {
197 gtk_widget_realize( list_item );
198 gtk_widget_realize( GTK_BIN(list_item)->child );
199
200 if (m_widgetStyle) ApplyWidgetStyle();
201 }
805dd538 202
fd0eed64 203 gtk_widget_show( list_item );
6de97a3b 204}
53010e52
RR
205
206void wxComboBox::Append( const wxString &item )
47908e25 207{
f5e27805
RR
208 m_clientDataList.Append( (wxObject*) NULL );
209 m_clientObjectList.Append( (wxObject*) NULL );
805dd538 210
fd0eed64 211 AppendCommon( item );
6de97a3b 212}
47908e25 213
fd0eed64 214void wxComboBox::Append( const wxString &item, void *clientData )
53010e52 215{
f5e27805
RR
216 m_clientDataList.Append( (wxObject*) clientData );
217 m_clientObjectList.Append( (wxObject*)NULL );
805dd538 218
fd0eed64 219 AppendCommon( item );
6de97a3b 220}
53010e52 221
fd0eed64 222void wxComboBox::Append( const wxString &item, wxClientData *clientData )
53010e52 223{
f5e27805
RR
224 m_clientDataList.Append( (wxObject*) NULL );
225 m_clientObjectList.Append( (wxObject*) clientData );
805dd538 226
fd0eed64
RR
227 AppendCommon( item );
228}
229
230void wxComboBox::SetClientData( int n, void* clientData )
231{
223d09f6 232 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
805dd538 233
fd0eed64
RR
234 wxNode *node = m_clientDataList.Nth( n );
235 if (!node) return;
805dd538 236
f5e27805 237 node->SetData( (wxObject*) clientData );
6de97a3b 238}
53010e52 239
fd0eed64 240void* wxComboBox::GetClientData( int n )
53010e52 241{
223d09f6 242 wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
805dd538 243
fd0eed64
RR
244 wxNode *node = m_clientDataList.Nth( n );
245 if (!node) return NULL;
805dd538 246
f5e27805 247 return node->Data();
fd0eed64
RR
248}
249
250void wxComboBox::SetClientObject( int n, wxClientData* clientData )
251{
223d09f6 252 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
805dd538 253
f5e27805 254 wxNode *node = m_clientObjectList.Nth( n );
fd0eed64 255 if (!node) return;
805dd538 256
fd0eed64
RR
257 wxClientData *cd = (wxClientData*) node->Data();
258 if (cd) delete cd;
805dd538 259
fd0eed64 260 node->SetData( (wxObject*) clientData );
6de97a3b 261}
53010e52 262
fd0eed64 263wxClientData* wxComboBox::GetClientObject( int n )
53010e52 264{
223d09f6 265 wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") );
805dd538 266
fd0eed64
RR
267 wxNode *node = m_clientDataList.Nth( n );
268 if (!node) return (wxClientData*) NULL;
805dd538 269
fd0eed64
RR
270 return (wxClientData*) node->Data();
271}
272
273void wxComboBox::Clear()
274{
223d09f6 275 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
805dd538 276
fd0eed64
RR
277 GtkWidget *list = GTK_COMBO(m_widget)->list;
278 gtk_list_clear_items( GTK_LIST(list), 0, Number() );
805dd538 279
f5e27805 280 wxNode *node = m_clientObjectList.First();
fd0eed64
RR
281 while (node)
282 {
283 wxClientData *cd = (wxClientData*)node->Data();
284 if (cd) delete cd;
285 node = node->Next();
286 }
f5e27805 287 m_clientObjectList.Clear();
805dd538 288
fd0eed64 289 m_clientDataList.Clear();
6de97a3b 290}
53010e52 291
fd0eed64 292void wxComboBox::Delete( int n )
53010e52 293{
223d09f6 294 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
805dd538 295
fd0eed64 296 GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list );
805dd538 297
fd0eed64 298 GList *child = g_list_nth( listbox->children, n );
805dd538 299
fd0eed64
RR
300 if (!child)
301 {
223d09f6 302 wxFAIL_MSG(wxT("wrong index"));
fd0eed64
RR
303 return;
304 }
805dd538 305
bbe0af5b 306 GList *list = g_list_append( (GList*) NULL, child->data );
fd0eed64
RR
307 gtk_list_remove_items( listbox, list );
308 g_list_free( list );
805dd538 309
f5e27805
RR
310 wxNode *node = m_clientObjectList.Nth( n );
311 if (node)
fd0eed64
RR
312 {
313 wxClientData *cd = (wxClientData*)node->Data();
314 if (cd) delete cd;
f5e27805
RR
315 m_clientObjectList.DeleteNode( node );
316 }
805dd538 317
f5e27805
RR
318 node = m_clientDataList.Nth( n );
319 if (node)
320 {
fd0eed64
RR
321 m_clientDataList.DeleteNode( node );
322 }
6de97a3b 323}
53010e52 324
fd0eed64 325int wxComboBox::FindString( const wxString &item )
53010e52 326{
223d09f6 327 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
805dd538 328
fd0eed64 329 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 330
53010e52
RR
331 GList *child = GTK_LIST(list)->children;
332 int count = 0;
333 while (child)
334 {
fd0eed64
RR
335 GtkBin *bin = GTK_BIN( child->data );
336 GtkLabel *label = GTK_LABEL( bin->child );
53b88b54 337 if (item == wxString(label->label,*wxConvCurrent))
7cf8cb48 338 return count;
fd0eed64
RR
339 count++;
340 child = child->next;
341 }
805dd538 342
7cf8cb48 343 return wxNOT_FOUND;
fd0eed64
RR
344}
345
346int wxComboBox::GetSelection() const
347{
223d09f6 348 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
805dd538 349
fd0eed64 350 GtkWidget *list = GTK_COMBO(m_widget)->list;
805dd538 351
fd0eed64
RR
352 GList *selection = GTK_LIST(list)->selection;
353 if (selection)
354 {
355 GList *child = GTK_LIST(list)->children;
356 int count = 0;
357 while (child)
358 {
359 if (child->data == selection->data) return count;
360 count++;
361 child = child->next;
362 }
6de97a3b 363 }
805dd538 364
fd0eed64 365 return -1;
6de97a3b 366}
53010e52 367
debe6624 368wxString wxComboBox::GetString( int n ) const
53010e52 369{
223d09f6 370 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("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 {
223d09f6 384 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
fd0eed64 385 }
805dd538 386
7cf8cb48 387 return str;
6de97a3b 388}
53010e52 389
fd0eed64 390wxString wxComboBox::GetStringSelection() const
53010e52 391{
223d09f6 392 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("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
223d09f6 404 wxFAIL_MSG( wxT("wxComboBox: no selection") );
805dd538 405
223d09f6 406 return wxT("");
6de97a3b 407}
53010e52 408
fd0eed64 409int wxComboBox::Number() const
53010e52 410{
223d09f6 411 wxCHECK_MSG( m_widget != NULL, 0, wxT("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{
223d09f6 423 wxCHECK_RET( m_widget != NULL, wxT("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{
223d09f6 435 wxCHECK_RET( m_widget != NULL, wxT("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{
223d09f6 451 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
805dd538 452
fd0eed64 453 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
223d09f6 454 wxString tmp = wxT("");
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{
223d09f6 461 wxCHECK_RET( m_widget != NULL, wxT("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{
223d09f6 473 wxCHECK_RET( m_widget != NULL, wxT("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{
223d09f6 485 wxCHECK_RET( m_widget != NULL, wxT("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{
223d09f6 497 wxCHECK_RET( m_widget != NULL, wxT("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{
223d09f6 505 wxCHECK_RET( m_widget != NULL, wxT("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{
223d09f6 525 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
93c5dd39 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{
223d09f6 537 wxCHECK_RET( m_widget != NULL, wxT("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 {
31528cd3 599 gtk_signal_disconnect_by_func( GTK_OBJECT(child->data),
953704c1
RR
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();
31528cd3 622
b02da6b1 623#if 0
fd0eed64
RR
624 int w = 21;
625 gtk_widget_set_usize( GTK_COMBO(m_widget)->entry, m_width-w-1, m_height );
805dd538 626
fd0eed64
RR
627 gtk_widget_set_uposition( GTK_COMBO(m_widget)->button, m_x+m_width-w, m_y );
628 gtk_widget_set_usize( GTK_COMBO(m_widget)->button, w, m_height );
b02da6b1 629#endif // 0
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
f68586e5
VZ
664wxSize wxComboBox::DoGetBestSize() const
665{
666 return wxSize(100, 26);
667}
668
dcf924a3 669#endif