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