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