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