Handle client data correctly.
[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 InheritAttributes();
162
163 ConnectWidget( combo->button );
164
165 // MSW's combo box shows the value and the selection is -1
166 gtk_entry_set_text( GTK_ENTRY(combo->entry), wxGTK_CONV(value) );
167 gtk_list_unselect_all( GTK_LIST(combo->list) );
168
169 if (style & wxCB_READONLY)
170 gtk_entry_set_editable( GTK_ENTRY( combo->entry ), FALSE );
171
172 gtk_signal_connect( GTK_OBJECT(combo->entry), "changed",
173 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
174
175 gtk_signal_connect( GTK_OBJECT(combo->list), "select-child",
176 GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
177
178 wxSize size_best( DoGetBestSize() );
179 wxSize new_size( size );
180 if (new_size.x == -1)
181 new_size.x = size_best.x;
182 if (new_size.y == -1)
183 new_size.y = size_best.y;
184 if (new_size.y > size_best.y)
185 new_size.y = size_best.y;
186 if ((new_size.x != size.x) || (new_size.y != size.y))
187 {
188 SetSize( new_size.x, new_size.y );
189
190 // This is required for tool bar support
191 gtk_widget_set_usize( m_widget, new_size.x, new_size.y );
192 }
193
194 Show( TRUE );
195
196 return TRUE;
197 }
198
199 wxComboBox::~wxComboBox()
200 {
201 wxList::compatibility_iterator node = m_clientObjectList.GetFirst();
202 while (node)
203 {
204 wxClientData *cd = (wxClientData*)node->GetData();
205 if (cd) delete cd;
206 node = node->GetNext();
207 }
208 m_clientObjectList.Clear();
209
210 m_clientDataList.Clear();
211 }
212
213 void wxComboBox::SetFocus()
214 {
215 if ( m_hasFocus )
216 {
217 // don't do anything if we already have focus
218 return;
219 }
220
221 gtk_widget_grab_focus( m_focusWidget );
222 }
223
224 int wxComboBox::DoAppend( const wxString &item )
225 {
226 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
227
228 DisableEvents();
229
230 GtkWidget *list = GTK_COMBO(m_widget)->list;
231
232 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
233
234 gtk_container_add( GTK_CONTAINER(list), list_item );
235
236 if (GTK_WIDGET_REALIZED(m_widget))
237 {
238 gtk_widget_realize( list_item );
239 gtk_widget_realize( GTK_BIN(list_item)->child );
240
241 if (m_widgetStyle) ApplyWidgetStyle();
242 }
243
244 gtk_widget_show( list_item );
245
246 const int count = GetCount();
247
248 if ( (int)m_clientDataList.GetCount() < count )
249 m_clientDataList.Append( (wxObject*) NULL );
250 if ( (int)m_clientObjectList.GetCount() < count )
251 m_clientObjectList.Append( (wxObject*) NULL );
252
253 EnableEvents();
254
255 return count - 1;
256 }
257
258 int wxComboBox::DoInsert( const wxString &item, int pos )
259 {
260 wxCHECK_MSG( !(GetWindowStyle() & wxCB_SORT), -1,
261 wxT("can't insert into sorted list"));
262
263 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
264
265 int count = GetCount();
266 wxCHECK_MSG( (pos >= 0) && (pos <= count), -1, wxT("invalid index") );
267
268 if (pos == count)
269 return Append(item);
270
271 DisableEvents();
272
273 GtkWidget *list = GTK_COMBO(m_widget)->list;
274
275 GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
276
277 GList *gitem_list = g_list_alloc ();
278 gitem_list->data = list_item;
279 gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );
280
281 if (GTK_WIDGET_REALIZED(m_widget))
282 {
283 gtk_widget_realize( list_item );
284 gtk_widget_realize( GTK_BIN(list_item)->child );
285
286 if (m_widgetStyle)
287 ApplyWidgetStyle();
288 }
289
290 gtk_widget_show( list_item );
291
292 count = GetCount();
293
294 if ( (int)m_clientDataList.GetCount() < count )
295 m_clientDataList.Insert( pos, (wxObject*) NULL );
296 if ( (int)m_clientObjectList.GetCount() < count )
297 m_clientObjectList.Insert( pos, (wxObject*) NULL );
298
299 EnableEvents();
300
301 return pos;
302 }
303
304 void wxComboBox::DoSetItemClientData( int n, void* clientData )
305 {
306 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
307
308 wxList::compatibility_iterator node = m_clientDataList.Item( n );
309 if (!node) return;
310
311 node->SetData( (wxObject*) clientData );
312 }
313
314 void* wxComboBox::DoGetItemClientData( int n ) const
315 {
316 wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
317
318 wxList::compatibility_iterator node = m_clientDataList.Item( n );
319
320 return node ? node->GetData() : NULL;
321 }
322
323 void wxComboBox::DoSetItemClientObject( int n, wxClientData* clientData )
324 {
325 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
326
327 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
328 if (!node) return;
329
330 // wxItemContainer already deletes data for us
331
332 node->SetData( (wxObject*) clientData );
333 }
334
335 wxClientData* wxComboBox::DoGetItemClientObject( int n ) const
336 {
337 wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") );
338
339 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
340
341 return node ? (wxClientData*) node->GetData() : NULL;
342 }
343
344 void wxComboBox::Clear()
345 {
346 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
347
348 DisableEvents();
349
350 GtkWidget *list = GTK_COMBO(m_widget)->list;
351 gtk_list_clear_items( GTK_LIST(list), 0, GetCount() );
352
353 wxList::compatibility_iterator node = m_clientObjectList.GetFirst();
354 while (node)
355 {
356 wxClientData *cd = (wxClientData*)node->GetData();
357 if (cd) delete cd;
358 node = node->GetNext();
359 }
360 m_clientObjectList.Clear();
361
362 m_clientDataList.Clear();
363
364 EnableEvents();
365 }
366
367 void wxComboBox::Delete( int n )
368 {
369 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
370
371 GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list );
372
373 GList *child = g_list_nth( listbox->children, n );
374
375 if (!child)
376 {
377 wxFAIL_MSG(wxT("wrong index"));
378 return;
379 }
380
381 DisableEvents();
382
383 GList *list = g_list_append( (GList*) NULL, child->data );
384 gtk_list_remove_items( listbox, list );
385 g_list_free( list );
386
387 wxList::compatibility_iterator node = m_clientObjectList.Item( n );
388 if (node)
389 {
390 wxClientData *cd = (wxClientData*)node->GetData();
391 if (cd) delete cd;
392 m_clientObjectList.Erase( node );
393 }
394
395 node = m_clientDataList.Item( n );
396 if (node)
397 m_clientDataList.Erase( node );
398
399 EnableEvents();
400 }
401
402 void wxComboBox::SetString(int n, const wxString &text)
403 {
404 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
405
406 GtkWidget *list = GTK_COMBO(m_widget)->list;
407
408 GList *child = g_list_nth( GTK_LIST(list)->children, n );
409 if (child)
410 {
411 GtkBin *bin = GTK_BIN( child->data );
412 GtkLabel *label = GTK_LABEL( bin->child );
413 gtk_label_set_text(label, wxGTK_CONV(text));
414 }
415 else
416 {
417 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
418 }
419 }
420
421 int wxComboBox::FindString( const wxString &item ) const
422 {
423 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
424
425 GtkWidget *list = GTK_COMBO(m_widget)->list;
426
427 GList *child = GTK_LIST(list)->children;
428 int count = 0;
429 while (child)
430 {
431 GtkBin *bin = GTK_BIN( child->data );
432 GtkLabel *label = GTK_LABEL( bin->child );
433 #ifdef __WXGTK20__
434 wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
435 #else
436 wxString str( label->label );
437 #endif
438 if (item == str)
439 return count;
440
441 count++;
442 child = child->next;
443 }
444
445 return wxNOT_FOUND;
446 }
447
448 int wxComboBox::GetSelection() const
449 {
450 wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
451
452 GtkWidget *list = GTK_COMBO(m_widget)->list;
453
454 GList *selection = GTK_LIST(list)->selection;
455 if (selection)
456 {
457 GList *child = GTK_LIST(list)->children;
458 int count = 0;
459 while (child)
460 {
461 if (child->data == selection->data) return count;
462 count++;
463 child = child->next;
464 }
465 }
466
467 return -1;
468 }
469
470 wxString wxComboBox::GetString( int n ) const
471 {
472 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") );
473
474 GtkWidget *list = GTK_COMBO(m_widget)->list;
475
476 wxString str;
477 GList *child = g_list_nth( GTK_LIST(list)->children, n );
478 if (child)
479 {
480 GtkBin *bin = GTK_BIN( child->data );
481 GtkLabel *label = GTK_LABEL( bin->child );
482 #ifdef __WXGTK20__
483 str = wxGTK_CONV_BACK( gtk_label_get_text(label) );
484 #else
485 str = wxString( label->label );
486 #endif
487 }
488 else
489 {
490 wxFAIL_MSG( wxT("wxComboBox: wrong index") );
491 }
492
493 return str;
494 }
495
496 wxString wxComboBox::GetStringSelection() const
497 {
498 wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") );
499
500 GtkWidget *list = GTK_COMBO(m_widget)->list;
501
502 GList *selection = GTK_LIST(list)->selection;
503 if (selection)
504 {
505 GtkBin *bin = GTK_BIN( selection->data );
506 GtkLabel *label = GTK_LABEL( bin->child );
507 #ifdef __WXGTK20__
508 wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
509 #else
510 wxString tmp( label->label );
511 #endif
512 return tmp;
513 }
514
515 wxFAIL_MSG( wxT("wxComboBox: no selection") );
516
517 return wxT("");
518 }
519
520 int wxComboBox::GetCount() const
521 {
522 wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") );
523
524 GtkWidget *list = GTK_COMBO(m_widget)->list;
525
526 GList *child = GTK_LIST(list)->children;
527 int count = 0;
528 while (child) { count++; child = child->next; }
529 return count;
530 }
531
532 void wxComboBox::SetSelection( int n )
533 {
534 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
535
536 DisableEvents();
537
538 GtkWidget *list = GTK_COMBO(m_widget)->list;
539 gtk_list_unselect_item( GTK_LIST(list), m_prevSelection );
540 gtk_list_select_item( GTK_LIST(list), n );
541 m_prevSelection = n;
542
543 EnableEvents();
544 }
545
546 void wxComboBox::SetStringSelection( const wxString &string )
547 {
548 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
549
550 int res = FindString( string );
551 if (res == -1) return;
552 SetSelection( res );
553 }
554
555 wxString wxComboBox::GetValue() const
556 {
557 GtkEntry *entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
558 wxString tmp( wxGTK_CONV_BACK( gtk_entry_get_text( entry ) ) );
559
560 #if 0
561 for (int i = 0; i < wxStrlen(tmp.c_str()) +1; i++)
562 {
563 wxChar c = tmp[i];
564 printf( "%d ", (int) (c) );
565 }
566 printf( "\n" );
567 #endif
568
569 return tmp;
570 }
571
572 void wxComboBox::SetValue( const wxString& value )
573 {
574 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
575
576 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
577 wxString tmp = wxT("");
578 if (!value.IsNull()) tmp = value;
579 gtk_entry_set_text( GTK_ENTRY(entry), wxGTK_CONV( tmp ) );
580 }
581
582 void wxComboBox::Copy()
583 {
584 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
585
586 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
587 gtk_editable_copy_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG );
588 }
589
590 void wxComboBox::Cut()
591 {
592 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
593
594 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
595 gtk_editable_cut_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG );
596 }
597
598 void wxComboBox::Paste()
599 {
600 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
601
602 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
603 gtk_editable_paste_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG);
604 }
605
606 void wxComboBox::SetInsertionPoint( long pos )
607 {
608 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
609
610 if ( pos == GetLastPosition() )
611 pos = -1;
612
613 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
614 gtk_entry_set_position( GTK_ENTRY(entry), (int)pos );
615 }
616
617 long wxComboBox::GetInsertionPoint() const
618 {
619 return (long) GET_EDITABLE_POS( GTK_COMBO(m_widget)->entry );
620 }
621
622 long wxComboBox::GetLastPosition() const
623 {
624 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
625 int pos = GTK_ENTRY(entry)->text_length;
626 return (long) pos-1;
627 }
628
629 void wxComboBox::Replace( long from, long to, const wxString& value )
630 {
631 wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
632
633 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
634 gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
635 if (value.IsNull()) return;
636 gint pos = (gint)to;
637
638 #if wxUSE_UNICODE
639 wxCharBuffer buffer = wxConvUTF8.cWX2MB( value );
640 gtk_editable_insert_text( GTK_EDITABLE(entry), (const char*) buffer, strlen( (const char*) buffer ), &pos );
641 #else
642 gtk_editable_insert_text( GTK_EDITABLE(entry), value.c_str(), value.Length(), &pos );
643 #endif
644 }
645
646 void wxComboBox::SetSelection( long from, long to )
647 {
648 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
649 gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to );
650 }
651
652 void wxComboBox::SetEditable( bool editable )
653 {
654 GtkWidget *entry = GTK_COMBO(m_widget)->entry;
655 gtk_entry_set_editable( GTK_ENTRY(entry), editable );
656 }
657
658 void wxComboBox::OnChar( wxKeyEvent &event )
659 {
660 if ( event.GetKeyCode() == WXK_RETURN )
661 {
662 // GTK automatically selects an item if its in the list
663 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, GetId());
664 event.SetString( GetValue() );
665 event.SetInt( GetSelection() );
666 event.SetEventObject( this );
667
668 if (!GetEventHandler()->ProcessEvent( event ))
669 {
670 // This will invoke the dialog default action, such
671 // as the clicking the default button.
672
673 wxWindow *top_frame = m_parent;
674 while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
675 top_frame = top_frame->GetParent();
676
677 if (top_frame && GTK_IS_WINDOW(top_frame->m_widget))
678 {
679 GtkWindow *window = GTK_WINDOW(top_frame->m_widget);
680
681 if (window->default_widget)
682 gtk_widget_activate (window->default_widget);
683 }
684 }
685
686 // Catch GTK event so that GTK doesn't open the drop
687 // down list upon RETURN.
688 return;
689 }
690
691 event.Skip();
692 }
693
694 void wxComboBox::DisableEvents()
695 {
696 gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget)->list),
697 GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
698 gtk_signal_disconnect_by_func( GTK_OBJECT(GTK_COMBO(m_widget)->entry),
699 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
700 }
701
702 void wxComboBox::EnableEvents()
703 {
704 gtk_signal_connect( GTK_OBJECT(GTK_COMBO(m_widget)->list), "select-child",
705 GTK_SIGNAL_FUNC(gtk_combo_select_child_callback), (gpointer)this );
706 gtk_signal_connect( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed",
707 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this );
708 }
709
710 void wxComboBox::OnSize( wxSizeEvent &event )
711 {
712 event.Skip();
713
714 #if 0
715 int w = 21;
716 gtk_widget_set_usize( GTK_COMBO(m_widget)->entry, m_width-w-1, m_height );
717
718 gtk_widget_set_uposition( GTK_COMBO(m_widget)->button, m_x+m_width-w, m_y );
719 gtk_widget_set_usize( GTK_COMBO(m_widget)->button, w, m_height );
720 #endif // 0
721 }
722
723 void wxComboBox::ApplyWidgetStyle()
724 {
725 SetWidgetStyle();
726
727 // gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle );
728 gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle );
729 gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle );
730
731 GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
732 GList *child = list->children;
733 while (child)
734 {
735 gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
736
737 GtkBin *bin = GTK_BIN(child->data);
738 gtk_widget_set_style( bin->child, m_widgetStyle );
739
740 child = child->next;
741 }
742 }
743
744 GtkWidget* wxComboBox::GetConnectWidget()
745 {
746 return GTK_COMBO(m_widget)->entry;
747 }
748
749 bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
750 {
751 return ( (window == GTK_ENTRY( GTK_COMBO(m_widget)->entry )->text_area) ||
752 (window == GTK_COMBO(m_widget)->button->window ) );
753 }
754
755 wxSize wxComboBox::DoGetBestSize() const
756 {
757 wxSize ret( wxControl::DoGetBestSize() );
758
759 // we know better our horizontal extent: it depends on the longest string
760 // in the combobox
761 ret.x = 0;
762 if ( m_widget )
763 {
764 int width;
765 size_t count = GetCount();
766 for ( size_t n = 0; n < count; n++ )
767 {
768 GetTextExtent( GetString(n), &width, NULL, NULL, NULL, &m_font );
769 if ( width > ret.x )
770 ret.x = width;
771 }
772 }
773
774 // empty combobox should have some reasonable default size too
775 if ( ret.x < 100 )
776 ret.x = 100;
777 return ret;
778 }
779
780 #endif