]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/combobox.cpp
Changes corresponding to patch #841324 from Ian Brown:
[wxWidgets.git] / src / gtk1 / combobox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: combobox.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "combobox.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #include "wx/combobox.h"
18
19 #if wxUSE_COMBOBOX
20
21 #include "wx/settings.h"
22 #include "wx/intl.h"
23
24 #include "wx/textctrl.h" // for wxEVT_COMMAND_TEXT_UPDATED
25
26 #include "wx/gtk/private.h"
27
28 //-----------------------------------------------------------------------------
29 // idle system
30 //-----------------------------------------------------------------------------
31
32 extern void wxapp_install_idle_handler();
33 extern bool g_isIdle;
34
35 //-----------------------------------------------------------------------------
36 // data
37 //-----------------------------------------------------------------------------
38
39 extern bool g_blockEventsOnDrag;
40
41 //-----------------------------------------------------------------------------
42 // "select-child" - click/cursor get select-child, changed, select-child
43 //-----------------------------------------------------------------------------
44
45 static void
46 gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(widget), wxComboBox *combo )
47 {
48 if (g_isIdle) wxapp_install_idle_handler();
49
50 if (!combo->m_hasVMT) return;
51
52 if (g_blockEventsOnDrag) return;
53
54 int curSelection = combo->GetSelection();
55
56 if (combo->m_prevSelection != curSelection)
57 {
58 GtkWidget *list = GTK_COMBO(combo->m_widget)->list;
59 gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection );
60 }
61 combo->m_prevSelection = curSelection;
62
63 wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
64 event.SetInt( curSelection );
65 event.SetString( combo->GetStringSelection() );
66 event.SetEventObject( combo );
67
68 combo->GetEventHandler()->ProcessEvent( event );
69 }
70
71 //-----------------------------------------------------------------------------
72 // "changed" - typing and list item matches get changed, select-child
73 // if it doesn't match an item then just get a single changed
74 //-----------------------------------------------------------------------------
75
76 static void
77 gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
78 {
79 if (g_isIdle) wxapp_install_idle_handler();
80
81 if (!combo->m_hasVMT) return;
82
83 wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
84 event.SetString( combo->GetValue() );
85 event.SetEventObject( combo );
86 combo->GetEventHandler()->ProcessEvent( event );
87 }
88
89 static void
90 gtk_dummy_callback(GtkEntry *WXUNUSED(entry), GtkCombo *WXUNUSED(combo))
91 {
92 }
93
94 //-----------------------------------------------------------------------------
95 // wxComboBox
96 //-----------------------------------------------------------------------------
97
98 IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl)
99
100 BEGIN_EVENT_TABLE(wxComboBox, wxControl)
101 EVT_SIZE(wxComboBox::OnSize)
102 EVT_CHAR(wxComboBox::OnChar)
103 END_EVENT_TABLE()
104
105 bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
106 const wxPoint& pos, const wxSize& size,
107 int n, const wxString choices[],
108 long style, const wxValidator& validator,
109 const wxString& name )
110 {
111 m_alreadySent = FALSE;
112 m_needParent = TRUE;
113 m_acceptsFocus = TRUE;
114 m_prevSelection = 0;
115
116 if (!PreCreation( parent, pos, size ) ||
117 !CreateBase( parent, id, pos, size, style, validator, name ))
118 {
119 wxFAIL_MSG( wxT("wxComboBox creation failed") );
120 return FALSE;
121 }
122
123 m_widget = gtk_combo_new();
124 GtkCombo *combo = GTK_COMBO(m_widget);
125
126 // Disable GTK's broken events ...
127 gtk_signal_disconnect( GTK_OBJECT(combo->entry), combo->entry_change_id );
128 // ... and add surogate handler.
129 combo->entry_change_id = gtk_signal_connect (GTK_OBJECT (combo->entry), "changed",
130 (GtkSignalFunc) gtk_dummy_callback, combo);
131
132 // make it more useable
133 gtk_combo_set_use_arrows_always( GTK_COMBO(m_widget), TRUE );
134
135 // and case-sensitive
136 gtk_combo_set_case_sensitive( GTK_COMBO(m_widget), TRUE );
137
138 GtkWidget *list = GTK_COMBO(m_widget)->list;
139
140 #ifndef __WXGTK20__
141 // gtk_list_set_selection_mode( GTK_LIST(list), GTK_SELECTION_MULTIPLE );
142 #endif
143
144 for (int i = 0; i < n; i++)
145 {
146 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( choices[i] ) );
147
148 m_clientDataList.Append( (wxObject*)NULL );
149 m_clientObjectList.Append( (wxObject*)NULL );
150
151 gtk_container_add( GTK_CONTAINER(list), list_item );
152
153 gtk_widget_show( list_item );
154 }
155
156 m_parent->DoAddChild( this );
157
158 m_focusWidget = combo->entry;
159
160 PostCreation();
161
162 ConnectWidget( combo->button );
163
164 // MSW's combo box shows the value and the selection is -1
165 gtk_entry_set_text( GTK_ENTRY(combo->entry), wxGTK_CONV(value) );
166 gtk_list_unselect_all( GTK_LIST(combo->list) );
167
168 if (style & wxCB_READONLY)
169 gtk_entry_set_editable( GTK_ENTRY( combo->entry ), FALSE );
170
171 gtk_signal_connect( GTK_OBJECT(combo->entry), "changed",
172 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
173
174 gtk_signal_connect( GTK_OBJECT(combo->list), "select-child",
175 GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
176
177 wxSize size_best( DoGetBestSize() );
178 wxSize new_size( size );
179 if (new_size.x == -1)
180 new_size.x = size_best.x;
181 if (new_size.y == -1)
182 new_size.y = size_best.y;
183 if (new_size.y > size_best.y)
184 new_size.y = size_best.y;
185 if ((new_size.x != size.x) || (new_size.y != size.y))
186 {
187 SetSize( new_size.x, new_size.y );
188
189 // This is required for tool bar support
190 gtk_widget_set_usize( m_widget, new_size.x, new_size.y );
191 }
192
193 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
194 SetForegroundColour( parent->GetForegroundColour() );
195
196 Show( TRUE );
197
198 return TRUE;
199 }
200
201 wxComboBox::~wxComboBox()
202 {
203 wxList::compatibility_iterator node = m_clientObjectList.GetFirst();
204 while (node)
205 {
206 wxClientData *cd = (wxClientData*)node->GetData();
207 if (cd) delete cd;
208 node = node->GetNext();
209 }
210 m_clientObjectList.Clear();
211
212 m_clientDataList.Clear();
213 }
214
215 void wxComboBox::SetFocus()
216 {
217 if ( m_hasFocus )
218 {
219 // don't do anything if we already have focus
220 return;
221 }
222
223 gtk_widget_grab_focus( m_focusWidget );
224 }
225
226 int wxComboBox::DoAppend( const wxString &item )
227 {
228 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
229
230 DisableEvents();
231
232 GtkWidget *list = GTK_COMBO(m_widget)->list;
233
234 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
235
236 gtk_container_add( GTK_CONTAINER(list), list_item );
237
238 if (GTK_WIDGET_REALIZED(m_widget))
239 {
240 gtk_widget_realize( list_item );
241 gtk_widget_realize( GTK_BIN(list_item)->child );
242
243 if (m_widgetStyle) ApplyWidgetStyle();
244 }
245
246 gtk_widget_show( list_item );
247
248 const int count = GetCount();
249
250 if ( (int)m_clientDataList.GetCount() < count )
251 m_clientDataList.Append( (wxObject*) NULL );
252 if ( (int)m_clientObjectList.GetCount() < count )
253 m_clientObjectList.Append( (wxObject*) NULL );
254
255 EnableEvents();
256
257 return count - 1;
258 }
259
260 int wxComboBox::DoInsert( const wxString &item, int pos )
261 {
262 wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT), -1,
263 wxT("can't insert into sorted list"));
264
265 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
266
267 int count = GetCount();
268 wxCHECK_MSG( (pos >= 0) && (pos <= count), -1, wxT("invalid index") );
269
270 if (pos == count)
271 return Append(item);
272
273 DisableEvents();
274
275 GtkWidget *list = GTK_COMBO(m_widget)->list;
276
277 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
278
279 GList *gitem_list = g_list_alloc ();
280 gitem_list->data = list_item;
281 gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );
282
283 if (GTK_WIDGET_REALIZED(m_widget))
284 {
285 gtk_widget_realize( list_item );
286 gtk_widget_realize( GTK_BIN(list_item)->child );
287
288 if (m_widgetStyle)
289 ApplyWidgetStyle();
290 }
291
292 gtk_widget_show( list_item );
293
294 count = GetCount();
295
296 if ( (int)m_clientDataList.GetCount() < count )
297 m_clientDataList.Insert( pos, (wxObject*) NULL );
298 if ( (int)m_clientObjectList.GetCount() < count )
299 m_clientObjectList.Insert( pos, (wxObject*) NULL );
300
301 EnableEvents();
302
303 return pos;
304 }
305
306 void wxComboBox::DoSetItemClientData( int n, void* clientData )
307 {
308 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
309
310 wxList::compatibility_iterator node = m_clientDataList.Item( n );
311 if (!node) return;
312
313 node->SetData( (wxObject*) clientData );
314 }
315
316 void* wxComboBox::DoGetItemClientData( int n ) const
317 {
318 wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
319
320 wxList::compatibility_iterator node = m_clientDataList.Item( n );
321
322 return node ? node->GetData() : NULL;
323 }
324
325 void wxComboBox::DoSetItemClientObject( int n, wxClientData* clientData )
326 {
327 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
328
329 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
330 if (!node) return;
331
332 wxClientData *cd = (wxClientData*) node->GetData();
333 if (cd) delete cd;
334
335 node->SetData( (wxObject*) clientData );
336 }
337
338 wxClientData* wxComboBox::DoGetItemClientObject( int n ) const
339 {
340 wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") );
341
342 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
343
344 return node ? (wxClientData*) node->GetData() : NULL;
345 }
346
347 void wxComboBox::Clear()
348 {
349 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
350
351 DisableEvents();
352
353 GtkWidget *list = GTK_COMBO(m_widget)->list;
354 gtk_list_clear_items( GTK_LIST(list), 0, GetCount() );
355
356 wxList::compatibility_iterator node = m_clientObjectList.GetFirst();
357 while (node)
358 {
359 wxClientData *cd = (wxClientData*)node->GetData();
360 if (cd) delete cd;
361 node = node->GetNext();
362 }
363 m_clientObjectList.Clear();
364
365 m_clientDataList.Clear();
366
367 EnableEvents();
368 }
369
370 void wxComboBox::Delete( int n )
371 {
372 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
373
374 GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list );
375
376 GList *child = g_list_nth( listbox->children, n );
377
378 if (!child)
379 {
380 wxFAIL_MSG(wxT("wrong index"));
381 return;
382 }
383
384 DisableEvents();
385
386 GList *list = g_list_append( (GList*) NULL, child->data );
387 gtk_list_remove_items( listbox, list );
388 g_list_free( list );
389
390 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
391 if (node)
392 {
393 wxClientData *cd = (wxClientData*)node->GetData();
394 if (cd) delete cd;
395 m_clientObjectList.Erase( node );
396 }
397
398 node = m_clientDataList.Item( n );
399 if (node)
400 m_clientDataList.Erase( node );
401
402 EnableEvents();
403 }
404
405 void wxComboBox::SetString(int n, const wxString &text)
406 {
407 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
408
409 GtkWidget *list = GTK_COMBO(m_widget)->list;
410
411 GList *child = g_list_nth( GTK_LIST(list)->children, n );
412 if (child)
413 {
414 GtkBin *bin = GTK_BIN( child->data );
415 GtkLabel *label = GTK_LABEL( bin->child );
416 gtk_label_set_text(label, wxGTK_CONV(text));
417 }
418 else
419 {
420 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
421 }
422 }
423
424 int wxComboBox::FindString( const wxString &item ) const
425 {
426 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
427
428 GtkWidget *list = GTK_COMBO(m_widget)->list;
429
430 GList *child = GTK_LIST(list)->children;
431 int count = 0;
432 while (child)
433 {
434 GtkBin *bin = GTK_BIN( child->data );
435 GtkLabel *label = GTK_LABEL( bin->child );
436 #ifdef __WXGTK20__
437 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
438 #else
439 wxString str( label->label );
440 #endif
441 if (item == str)
442 return count;
443
444 count++;
445 child = child->next;
446 }
447
448 return wxNOT_FOUND;
449 }
450
451 int wxComboBox::GetSelection() const
452 {
453 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
454
455 GtkWidget *list = GTK_COMBO(m_widget)->list;
456
457 GList *selection = GTK_LIST(list)->selection;
458 if (selection)
459 {
460 GList *child = GTK_LIST(list)->children;
461 int count = 0;
462 while (child)
463 {
464 if (child->data == selection->data) return count;
465 count++;
466 child = child->next;
467 }
468 }
469
470 return -1;
471 }
472
473 wxString wxComboBox::GetString( int n ) const
474 {
475 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") );
476
477 GtkWidget *list = GTK_COMBO(m_widget)->list;
478
479 wxString str;
480 GList *child = g_list_nth( GTK_LIST(list)->children, n );
481 if (child)
482 {
483 GtkBin *bin = GTK_BIN( child->data );
484 GtkLabel *label = GTK_LABEL( bin->child );
485 #ifdef __WXGTK20__
486 str = wxGTK_CONV_BACK( gtk_label_get_text(label) );
487 #else
488 str = wxString( label->label );
489 #endif
490 }
491 else
492 {
493 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
494 }
495
496 return str;
497 }
498
499 wxString wxComboBox::GetStringSelection() const
500 {
501 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") );
502
503 GtkWidget *list = GTK_COMBO(m_widget)->list;
504
505 GList *selection = GTK_LIST(list)->selection;
506 if (selection)
507 {
508 GtkBin *bin = GTK_BIN( selection->data );
509 GtkLabel *label = GTK_LABEL( bin->child );
510 #ifdef __WXGTK20__
511 wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
512 #else
513 wxString tmp( label->label );
514 #endif
515 return tmp;
516 }
517
518 wxFAIL_MSG( wxT("wxComboBox: no selection") );
519
520 return wxT("");
521 }
522
523 int wxComboBox::GetCount() const
524 {
525 wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") );
526
527 GtkWidget *list = GTK_COMBO(m_widget)->list;
528
529 GList *child = GTK_LIST(list)->children;
530 int count = 0;
531 while (child) { count++; child = child->next; }
532 return count;
533 }
534
535 void wxComboBox::SetSelection( int n )
536 {
537 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
538
539 DisableEvents();
540
541 GtkWidget *list = GTK_COMBO(m_widget)->list;
542 gtk_list_unselect_item( GTK_LIST(list), m_prevSelection );
543 gtk_list_select_item( GTK_LIST(list), n );
544 m_prevSelection = n;
545
546 EnableEvents();
547 }
548
549 void wxComboBox::SetStringSelection( const wxString &string )
550 {
551 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
552
553 int res = FindString( string );
554 if (res == -1) return;
555 SetSelection( res );
556 }
557
558 wxString wxComboBox::GetValue() const
559 {
560 GtkEntry *entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
561 wxString tmp( wxGTK_CONV_BACK( gtk_entry_get_text( entry ) ) );
562
563 #if 0
564 for (int i = 0; i < wxStrlen(tmp.c_str()) +1; i++)
565 {
566 wxChar c = tmp[i];
567 printf( "%d ", (int) (c) );
568 }
569 printf( "\n" );
570 #endif
571
572 return tmp;
573 }
574
575 void wxComboBox::SetValue( const wxString& value )
576 {
577 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
578
579 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
580 wxString tmp = wxT("");
581 if (!value.IsNull()) tmp = value;
582 gtk_entry_set_text( GTK_ENTRY(entry), wxGTK_CONV( tmp ) );
583 }
584
585 void wxComboBox::Copy()
586 {
587 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
588
589 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
590 gtk_editable_copy_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG );
591 }
592
593 void wxComboBox::Cut()
594 {
595 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
596
597 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
598 gtk_editable_cut_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG );
599 }
600
601 void wxComboBox::Paste()
602 {
603 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
604
605 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
606 gtk_editable_paste_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG);
607 }
608
609 void wxComboBox::SetInsertionPoint( long pos )
610 {
611 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
612
613 if ( pos == GetLastPosition() )
614 pos = -1;
615
616 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
617 gtk_entry_set_position( GTK_ENTRY(entry), (int)pos );
618 }
619
620 long wxComboBox::GetInsertionPoint() const
621 {
622 return (long) GET_EDITABLE_POS( GTK_COMBO(m_widget)->entry );
623 }
624
625 long wxComboBox::GetLastPosition() const
626 {
627 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
628 int pos = GTK_ENTRY(entry)->text_length;
629 return (long) pos-1;
630 }
631
632 void wxComboBox::Replace( long from, long to, const wxString& value )
633 {
634 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
635
636 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
637 gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
638 if (value.IsNull()) return;
639 gint pos = (gint)to;
640
641 #if wxUSE_UNICODE
642 wxCharBuffer buffer = wxConvUTF8.cWX2MB( value );
643 gtk_editable_insert_text( GTK_EDITABLE(entry), (const char*) buffer, strlen( (const char*) buffer ), &pos );
644 #else
645 gtk_editable_insert_text( GTK_EDITABLE(entry), value.c_str(), value.Length(), &pos );
646 #endif
647 }
648
649 void wxComboBox::SetSelection( long from, long to )
650 {
651 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
652 gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to );
653 }
654
655 void wxComboBox::SetEditable( bool editable )
656 {
657 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
658 gtk_entry_set_editable( GTK_ENTRY(entry), editable );
659 }
660
661 void wxComboBox::OnChar( wxKeyEvent &event )
662 {
663 if ( event.GetKeyCode() == WXK_RETURN )
664 {
665 // GTK automatically selects an item if its in the list
666 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, GetId());
667 event.SetString( GetValue() );
668 event.SetInt( GetSelection() );
669 event.SetEventObject( this );
670
671 if (!GetEventHandler()->ProcessEvent( event ))
672 {
673 // This will invoke the dialog default action, such
674 // as the clicking the default button.
675
676 wxWindow *top_frame = m_parent;
677 while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
678 top_frame = top_frame->GetParent();
679
680 if (top_frame && GTK_IS_WINDOW(top_frame->m_widget))
681 {
682 GtkWindow *window = GTK_WINDOW(top_frame->m_widget);
683
684 if (window->default_widget)
685 gtk_widget_activate (window->default_widget);
686 }
687 }
688
689 // Catch GTK event so that GTK doesn't open the drop
690 // down list upon RETURN.
691 return;
692 }
693
694 event.Skip();
695 }
696
697 void wxComboBox::DisableEvents()
698 {
699 gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget)->list),
700 GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
701 gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget)->entry),
702 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
703 }
704
705 void wxComboBox::EnableEvents()
706 {
707 gtk_signal_connect( GTK_OBJECT(GTK_COMBO(m_widget)->list), "select-child",
708 GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
709 gtk_signal_connect( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed",
710 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
711 }
712
713 void wxComboBox::OnSize( wxSizeEvent &event )
714 {
715 event.Skip();
716
717 #if 0
718 int w = 21;
719 gtk_widget_set_usize( GTK_COMBO(m_widget)->entry, m_width-w-1, m_height );
720
721 gtk_widget_set_uposition( GTK_COMBO(m_widget)->button, m_x+m_width-w, m_y );
722 gtk_widget_set_usize( GTK_COMBO(m_widget)->button, w, m_height );
723 #endif // 0
724 }
725
726 void wxComboBox::ApplyWidgetStyle()
727 {
728 SetWidgetStyle();
729
730 // gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle );
731 gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle );
732 gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle );
733
734 GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
735 GList *child = list->children;
736 while (child)
737 {
738 gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
739
740 GtkBin *bin = GTK_BIN(child->data);
741 gtk_widget_set_style( bin->child, m_widgetStyle );
742
743 child = child->next;
744 }
745 }
746
747 GtkWidget* wxComboBox::GetConnectWidget()
748 {
749 return GTK_COMBO(m_widget)->entry;
750 }
751
752 bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
753 {
754 return ( (window == GTK_ENTRY( GTK_COMBO(m_widget)->entry )->text_area) ||
755 (window == GTK_COMBO(m_widget)->button->window ) );
756 }
757
758 wxSize wxComboBox::DoGetBestSize() const
759 {
760 wxSize ret( wxControl::DoGetBestSize() );
761
762 // we know better our horizontal extent: it depends on the longest string
763 // in the combobox
764 ret.x = 0;
765 if ( m_widget )
766 {
767 int width;
768 size_t count = GetCount();
769 for ( size_t n = 0; n < count; n++ )
770 {
771 GetTextExtent( GetString(n), &width, NULL, NULL, NULL, &m_font );
772 if ( width > ret.x )
773 ret.x = width;
774 }
775 }
776
777 // empty combobox should have some reasonable default size too
778 if ( ret.x < 100 )
779 ret.x = 100;
780 return ret;
781 }
782
783 #endif