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