background colour changes for listbox and combobox
[wxWidgets.git] / src / gtk / listbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: listbox.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation "listbox.h"
13 #endif
14
15 #include "wx/dynarray.h"
16 #include "wx/listbox.h"
17 #include "wx/utils.h"
18 #include "wx/intl.h"
19 #include "wx/checklst.h"
20 #include "wx/settings.h"
21
22 #if wxUSE_TOOLTIPS
23 #include "wx/tooltip.h"
24 #endif
25
26 #if wxUSE_DRAG_AND_DROP
27 #include "wx/dnd.h"
28 #endif
29
30 #include "gdk/gdk.h"
31 #include "gtk/gtk.h"
32
33 //-----------------------------------------------------------------------------
34 // idle system
35 //-----------------------------------------------------------------------------
36
37 extern void wxapp_install_idle_handler();
38 extern bool g_isIdle;
39
40 //-------------------------------------------------------------------------
41 // conditional compilation
42 //-------------------------------------------------------------------------
43
44 #if (GTK_MINOR_VERSION > 0)
45 #define NEW_GTK_SCROLL_CODE
46 #endif
47
48 //-----------------------------------------------------------------------------
49 // private functions
50 //-----------------------------------------------------------------------------
51
52 #define CHECKBOX_STRING "[-] "
53
54 // checklistboxes have "[±] " prepended to their lables, this macro removes it
55 // (NB: 4 below is the length of CHECKBOX_STRING above)
56 //
57 // the argument to it is a "const char *" pointer
58 #define GET_REAL_LABEL(label) ((m_hasCheckBoxes)?(label)+4 : (label))
59
60 //-----------------------------------------------------------------------------
61 // data
62 //-----------------------------------------------------------------------------
63
64 extern bool g_blockEventsOnDrag;
65 extern bool g_blockEventsOnScroll;
66
67 //-----------------------------------------------------------------------------
68 // "button_press_event"
69 //-----------------------------------------------------------------------------
70
71 static gint
72 gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox )
73 {
74 if (g_isIdle) wxapp_install_idle_handler();
75
76 if (g_blockEventsOnDrag) return FALSE;
77 if (g_blockEventsOnScroll) return FALSE;
78
79 if (!listbox->HasVMT()) return FALSE;
80
81 int sel = listbox->GetIndex( widget );
82
83 if ((listbox->m_hasCheckBoxes) && (gdk_event->x < 15) && (gdk_event->type != GDK_2BUTTON_PRESS))
84 {
85 wxCheckListBox *clb = (wxCheckListBox *)listbox;
86
87 clb->Check( sel, !clb->IsChecked(sel) );
88
89 wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() );
90 event.SetEventObject( listbox );
91 event.SetInt( sel );
92 listbox->GetEventHandler()->ProcessEvent( event );
93 }
94
95 if (gdk_event->type == GDK_2BUTTON_PRESS)
96 {
97 wxCommandEvent event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, listbox->GetId() );
98 event.SetEventObject( listbox );
99
100 wxArrayInt aSelections;
101 int count = listbox->GetSelections(aSelections);
102 if ( count > 0 )
103 {
104 event.m_commandInt = aSelections[0] ;
105 event.m_clientData = listbox->GetClientData( event.m_commandInt );
106 wxString str(listbox->GetString(event.m_commandInt));
107 if (!str.IsEmpty()) event.m_commandString = str;
108 }
109 else
110 {
111 event.m_commandInt = -1 ;
112 event.m_commandString.Empty();
113 }
114
115 listbox->GetEventHandler()->ProcessEvent( event );
116
117 }
118
119 return FALSE;
120 }
121
122 //-----------------------------------------------------------------------------
123 // "key_press_event"
124 //-----------------------------------------------------------------------------
125
126 static gint
127 gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox )
128 {
129 if (g_isIdle) wxapp_install_idle_handler();
130
131 if (g_blockEventsOnDrag) return FALSE;
132
133 if (!listbox->HasVMT()) return FALSE;
134
135 if (gdk_event->keyval != ' ') return FALSE;
136
137 int sel = listbox->GetIndex( widget );
138
139 wxCheckListBox *clb = (wxCheckListBox *)listbox;
140
141 clb->Check( sel, !clb->IsChecked(sel) );
142
143 wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() );
144 event.SetEventObject( listbox );
145 event.SetInt( sel );
146 listbox->GetEventHandler()->ProcessEvent( event );
147
148 return FALSE;
149 }
150
151 //-----------------------------------------------------------------------------
152 // "select" and "deselect"
153 //-----------------------------------------------------------------------------
154
155 static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox *listbox )
156 {
157 if (g_isIdle) wxapp_install_idle_handler();
158
159 if (!listbox->HasVMT()) return;
160 if (g_blockEventsOnDrag) return;
161
162 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
163
164 wxArrayInt aSelections;
165 int count = listbox->GetSelections(aSelections);
166 if ( count > 0 )
167 {
168 event.m_commandInt = aSelections[0] ;
169 event.m_clientData = listbox->GetClientData( event.m_commandInt );
170 wxString str(listbox->GetString(event.m_commandInt));
171 if (!str.IsEmpty()) event.m_commandString = str;
172 }
173 else
174 {
175 event.m_commandInt = -1 ;
176 event.m_commandString.Empty();
177 }
178
179 event.SetEventObject( listbox );
180
181 listbox->GetEventHandler()->ProcessEvent( event );
182 }
183
184 //-----------------------------------------------------------------------------
185 // wxListBox
186 //-----------------------------------------------------------------------------
187
188 IMPLEMENT_DYNAMIC_CLASS(wxListBox,wxControl)
189
190 wxListBox::wxListBox()
191 {
192 m_list = (GtkList *) NULL;
193 m_hasCheckBoxes = FALSE;
194 }
195
196 bool wxListBox::Create( wxWindow *parent, wxWindowID id,
197 const wxPoint &pos, const wxSize &size,
198 int n, const wxString choices[],
199 long style, const wxValidator& validator, const wxString &name )
200 {
201 m_needParent = TRUE;
202 m_acceptsFocus = TRUE;
203
204 PreCreation( parent, id, pos, size, style, name );
205
206 SetValidator( validator );
207
208 m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL );
209 if (style & wxLB_ALWAYS_SB)
210 {
211 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget),
212 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
213 }
214 else
215 {
216 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget),
217 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
218 }
219
220 m_list = GTK_LIST( gtk_list_new() );
221
222 GtkSelectionMode mode = GTK_SELECTION_BROWSE;
223 if (style & wxLB_MULTIPLE)
224 mode = GTK_SELECTION_MULTIPLE;
225 else if (style & wxLB_EXTENDED)
226 mode = GTK_SELECTION_EXTENDED;
227
228 gtk_list_set_selection_mode( GTK_LIST(m_list), mode );
229
230 #ifdef NEW_GTK_SCROLL_CODE
231 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), GTK_WIDGET(m_list) );
232 #else
233 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_list) );
234 #endif
235
236 gtk_widget_show( GTK_WIDGET(m_list) );
237
238 wxSize newSize = size;
239 if (newSize.x == -1) newSize.x = 100;
240 if (newSize.y == -1) newSize.y = 110;
241 SetSize( newSize.x, newSize.y );
242
243 for (int i = 0; i < n; i++)
244 {
245 m_clientDataList.Append( (wxObject*) NULL );
246 m_clientObjectList.Append( (wxObject*) NULL );
247
248 GtkWidget *list_item;
249
250 wxString str(choices[i]);
251 if (m_hasCheckBoxes)
252 {
253 str.Prepend(CHECKBOX_STRING);
254 }
255
256 list_item = gtk_list_item_new_with_label( str.mbc_str() );
257
258 gtk_container_add( GTK_CONTAINER(m_list), list_item );
259
260 gtk_signal_connect( GTK_OBJECT(list_item), "select",
261 GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
262
263 if (style & wxLB_MULTIPLE)
264 gtk_signal_connect( GTK_OBJECT(list_item), "deselect",
265 GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
266
267 gtk_signal_connect( GTK_OBJECT(list_item),
268 "button_press_event",
269 (GtkSignalFunc)gtk_listbox_button_press_callback,
270 (gpointer) this );
271
272 if (m_hasCheckBoxes)
273 {
274 gtk_signal_connect( GTK_OBJECT(list_item),
275 "key_press_event",
276 (GtkSignalFunc)gtk_listbox_key_press_callback,
277 (gpointer)this );
278 }
279
280 ConnectWidget( list_item );
281
282 gtk_widget_show( list_item );
283 }
284
285 m_parent->AddChild( this );
286
287 (m_parent->m_insertCallback)( m_parent, this );
288
289 PostCreation();
290
291 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW ) );
292 SetForegroundColour( parent->GetForegroundColour() );
293 SetFont( parent->GetFont() );
294
295 Show( TRUE );
296
297 return TRUE;
298 }
299
300 wxListBox::~wxListBox()
301 {
302 Clear();
303 }
304
305 void wxListBox::InsertItems(int nItems, const wxString items[], int pos)
306 {
307 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
308
309 GList *children = m_list->children;
310 int length = g_list_length(children);
311 wxCHECK_RET( pos <= length, _T("invalid index in wxListBox::InsertItems") );
312
313 // VZ: it seems that GTK 1.0.6 doesn't has a function to insert an item
314 // into a listbox at the given position, this is why we first delete
315 // all items after this position, then append these items and then
316 // reappend back the old ones.
317
318 // first detach the old items
319 int n; // loop var
320
321 if ( pos == length )
322 {
323 // no need to do anything complicated
324 for ( n = 0; n < nItems; n++ )
325 {
326 Append(items[n]);
327 }
328
329 return;
330 }
331
332 wxArrayString deletedLabels;
333 wxArrayPtrVoid deletedData;
334 wxArrayInt deletedChecks; // only for check list boxes
335
336 GList *child = g_list_nth( children, pos );
337 for ( n = 0; child != NULL; n++, child = child->next )
338 {
339 // save label
340 GtkBin *bin = GTK_BIN( child->data );
341 GtkLabel *label = GTK_LABEL( bin->child );
342
343 wxString str(GET_REAL_LABEL(label->label));
344 deletedLabels.Add(str);
345
346 // save data
347 void *clientData = NULL;
348 wxNode *node = NULL;
349
350 if ( n < (int)m_clientObjectList.GetCount() )
351 node = m_clientObjectList.Nth( n );
352
353 if ( node )
354 {
355 clientData = node->GetData();
356 m_clientObjectList.DeleteNode( node );
357 }
358
359 if ( !clientData )
360 {
361 if ( n < (int)m_clientDataList.GetCount() )
362 node = m_clientDataList.Nth( n );
363
364 if ( node )
365 {
366 clientData = node->GetData();
367 node = m_clientDataList.Nth( n );
368 }
369 }
370
371 deletedData.Add(clientData);
372
373 // save check state
374 if ( m_hasCheckBoxes )
375 {
376 deletedChecks.Add(((wxCheckListBox *)this)->IsChecked(pos + n));
377 }
378 }
379
380 int nDeletedCount = n;
381
382 gtk_list_clear_items( m_list, pos, length );
383
384 // now append the new items
385 for ( n = 0; n < nItems; n++ )
386 {
387 Append(items[n]);
388 }
389
390 // and append the old items too
391 pos += nItems; // now the indices are shifter
392 for ( n = 0; n < nDeletedCount; n++ )
393 {
394 Append(deletedLabels[n], deletedData[n]);
395
396 if ( m_hasCheckBoxes )
397 {
398 ((wxCheckListBox *)this)->Check(pos + n, (bool)deletedChecks[n]);
399 }
400 }
401 }
402
403 void wxListBox::AppendCommon( const wxString &item )
404 {
405 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
406
407 GtkWidget *list_item;
408
409 wxString label(item);
410 if (m_hasCheckBoxes)
411 {
412 label.Prepend(CHECKBOX_STRING);
413 }
414
415 list_item = gtk_list_item_new_with_label( label.mbc_str() );
416
417 gtk_container_add( GTK_CONTAINER(m_list), list_item );
418
419 gtk_signal_connect( GTK_OBJECT(list_item), "select",
420 GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
421
422 if (GetWindowStyleFlag() & wxLB_MULTIPLE)
423 gtk_signal_connect( GTK_OBJECT(list_item), "deselect",
424 GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
425
426 gtk_signal_connect( GTK_OBJECT(list_item),
427 "button_press_event",
428 (GtkSignalFunc)gtk_listbox_button_press_callback,
429 (gpointer) this );
430
431 if (m_hasCheckBoxes)
432 {
433 gtk_signal_connect( GTK_OBJECT(list_item),
434 "key_press_event",
435 (GtkSignalFunc)gtk_listbox_key_press_callback,
436 (gpointer)this );
437 }
438
439 gtk_widget_show( list_item );
440
441 ConnectWidget( list_item );
442
443 if (GTK_WIDGET_REALIZED(m_widget))
444 {
445 gtk_widget_realize( list_item );
446 gtk_widget_realize( GTK_BIN(list_item)->child );
447
448 if (m_widgetStyle) ApplyWidgetStyle();
449
450 #if wxUSE_DRAG_AND_DROP
451 #ifndef NEW_GTK_DND_CODE
452 if (m_dropTarget) m_dropTarget->RegisterWidget( list_item );
453 #endif
454 #endif
455
456 #if wxUSE_TOOLTIPS
457 if (m_toolTip) m_toolTip->Apply( this );
458 #endif
459 }
460 }
461
462 void wxListBox::Append( const wxString &item )
463 {
464 m_clientDataList.Append( (wxObject*) NULL );
465 m_clientObjectList.Append( (wxObject*) NULL );
466
467 AppendCommon( item );
468 }
469
470 void wxListBox::Append( const wxString &item, void *clientData )
471 {
472 m_clientDataList.Append( (wxObject*) clientData );
473 m_clientObjectList.Append( (wxObject*) NULL );
474
475 AppendCommon( item );
476 }
477
478 void wxListBox::Append( const wxString &item, wxClientData *clientData )
479 {
480 m_clientObjectList.Append( (wxObject*) clientData );
481 m_clientDataList.Append( (wxObject*) NULL );
482
483 AppendCommon( item );
484 }
485
486 void wxListBox::SetClientData( int n, void* clientData )
487 {
488 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
489
490 wxNode *node = m_clientDataList.Nth( n );
491 if (!node) return;
492
493 node->SetData( (wxObject*) clientData );
494 }
495
496 void* wxListBox::GetClientData( int n )
497 {
498 wxCHECK_MSG( m_widget != NULL, NULL, _T("invalid combobox") );
499
500 wxNode *node = m_clientDataList.Nth( n );
501 if (!node) return NULL;
502
503 return node->Data();
504 }
505
506 void wxListBox::SetClientObject( int n, wxClientData* clientData )
507 {
508 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
509
510 wxNode *node = m_clientObjectList.Nth( n );
511 if (!node) return;
512
513 wxClientData *cd = (wxClientData*) node->Data();
514 if (cd) delete cd;
515
516 node->SetData( (wxObject*) clientData );
517 }
518
519 wxClientData* wxListBox::GetClientObject( int n )
520 {
521 wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, _T("invalid combobox") );
522
523 wxNode *node = m_clientObjectList.Nth( n );
524 if (!node) return (wxClientData*) NULL;
525
526 return (wxClientData*) node->Data();
527 }
528
529 void wxListBox::Clear()
530 {
531 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
532
533 gtk_list_clear_items( m_list, 0, Number() );
534
535 wxNode *node = m_clientObjectList.First();
536 while (node)
537 {
538 wxClientData *cd = (wxClientData*)node->Data();
539 if (cd) delete cd;
540 node = node->Next();
541 }
542 m_clientObjectList.Clear();
543
544 m_clientDataList.Clear();
545 }
546
547 void wxListBox::Delete( int n )
548 {
549 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
550
551 GList *child = g_list_nth( m_list->children, n );
552
553 wxCHECK_RET( child, _T("wrong listbox index") );
554
555 GList *list = g_list_append( (GList*) NULL, child->data );
556 gtk_list_remove_items( m_list, list );
557 g_list_free( list );
558
559 wxNode *node = m_clientObjectList.Nth( n );
560 if (node)
561 {
562 wxClientData *cd = (wxClientData*)node->Data();
563 if (cd) delete cd;
564 m_clientObjectList.DeleteNode( node );
565 }
566
567 node = m_clientDataList.Nth( n );
568 if (node)
569 {
570 m_clientDataList.DeleteNode( node );
571 }
572 }
573
574 void wxListBox::Deselect( int n )
575 {
576 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
577
578 gtk_list_unselect_item( m_list, n );
579 }
580
581 int wxListBox::FindString( const wxString &item ) const
582 {
583 wxCHECK_MSG( m_list != NULL, -1, _T("invalid listbox") );
584
585 GList *child = m_list->children;
586 int count = 0;
587 while (child)
588 {
589 GtkBin *bin = GTK_BIN( child->data );
590 GtkLabel *label = GTK_LABEL( bin->child );
591
592 wxString str = GET_REAL_LABEL(label->label);
593
594 if (str == item)
595 return count;
596
597 count++;
598 child = child->next;
599 }
600
601 // it's not an error if the string is not found -> no wxCHECK
602
603 return -1;
604 }
605
606 int wxListBox::GetSelection() const
607 {
608 wxCHECK_MSG( m_list != NULL, -1, _T("invalid listbox") );
609
610 GList *child = m_list->children;
611 int count = 0;
612 while (child)
613 {
614 if (GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED) return count;
615 count++;
616 child = child->next;
617 }
618 return -1;
619 }
620
621 int wxListBox::GetSelections( wxArrayInt& aSelections ) const
622 {
623 wxCHECK_MSG( m_list != NULL, -1, _T("invalid listbox") );
624
625 // get the number of selected items first
626 GList *child = m_list->children;
627 int count = 0;
628 for (child = m_list->children; child != NULL; child = child->next)
629 {
630 if (GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED)
631 count++;
632 }
633
634 aSelections.Empty();
635
636 if (count > 0)
637 {
638 // now fill the list
639 aSelections.Alloc(count); // optimization attempt
640 int i = 0;
641 for (child = m_list->children; child != NULL; child = child->next, i++)
642 {
643 if (GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED)
644 aSelections.Add(i);
645 }
646 }
647
648 return count;
649 }
650
651 wxString wxListBox::GetString( int n ) const
652 {
653 wxCHECK_MSG( m_list != NULL, _T(""), _T("invalid listbox") );
654
655 GList *child = g_list_nth( m_list->children, n );
656 if (child)
657 {
658 GtkBin *bin = GTK_BIN( child->data );
659 GtkLabel *label = GTK_LABEL( bin->child );
660
661 wxString str = GET_REAL_LABEL(label->label);
662
663 return str;
664 }
665
666 wxFAIL_MSG(_T("wrong listbox index"));
667
668 return _T("");
669 }
670
671 wxString wxListBox::GetStringSelection() const
672 {
673 wxCHECK_MSG( m_list != NULL, _T(""), _T("invalid listbox") );
674
675 GList *selection = m_list->selection;
676 if (selection)
677 {
678 GtkBin *bin = GTK_BIN( selection->data );
679 GtkLabel *label = GTK_LABEL( bin->child );
680
681 wxString str = GET_REAL_LABEL(label->label);
682
683 return str;
684 }
685
686 wxFAIL_MSG(_T("no listbox selection available"));
687 return _T("");
688 }
689
690 int wxListBox::Number()
691 {
692 wxCHECK_MSG( m_list != NULL, -1, _T("invalid listbox") );
693
694 GList *child = m_list->children;
695 int count = 0;
696 while (child) { count++; child = child->next; }
697 return count;
698 }
699
700 bool wxListBox::Selected( int n )
701 {
702 wxCHECK_MSG( m_list != NULL, FALSE, _T("invalid listbox") );
703
704 GList *target = g_list_nth( m_list->children, n );
705 if (target)
706 {
707 GList *child = m_list->selection;
708 while (child)
709 {
710 if (child->data == target->data) return TRUE;
711 child = child->next;
712 }
713 }
714 wxFAIL_MSG(_T("wrong listbox index"));
715 return FALSE;
716 }
717
718 void wxListBox::Set( int WXUNUSED(n), const wxString *WXUNUSED(choices) )
719 {
720 wxFAIL_MSG(_T("wxListBox::Set not implemented"));
721 }
722
723 void wxListBox::SetFirstItem( int WXUNUSED(n) )
724 {
725 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
726 }
727
728 void wxListBox::SetFirstItem( const wxString &WXUNUSED(item) )
729 {
730 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
731 }
732
733 void wxListBox::SetSelection( int n, bool select )
734 {
735 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
736
737 if (select)
738 gtk_list_select_item( m_list, n );
739 else
740 gtk_list_unselect_item( m_list, n );
741 }
742
743 void wxListBox::SetString( int n, const wxString &string )
744 {
745 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
746
747 GList *child = g_list_nth( m_list->children, n );
748 if (child)
749 {
750 GtkBin *bin = GTK_BIN( child->data );
751 GtkLabel *label = GTK_LABEL( bin->child );
752
753 wxString str;
754 if (m_hasCheckBoxes)
755 str += CHECKBOX_STRING;
756 str += string;
757
758 gtk_label_set( label, str.mbc_str() );
759 }
760 else
761 {
762 wxFAIL_MSG(_T("wrong listbox index"));
763 }
764 }
765
766 void wxListBox::SetStringSelection( const wxString &string, bool select )
767 {
768 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
769
770 SetSelection( FindString(string), select );
771 }
772
773 int wxListBox::GetIndex( GtkWidget *item ) const
774 {
775 if (item)
776 {
777 GList *child = m_list->children;
778 int count = 0;
779 while (child)
780 {
781 if (GTK_WIDGET(child->data) == item) return count;
782 count++;
783 child = child->next;
784 }
785 }
786 return -1;
787 }
788
789 #if wxUSE_TOOLTIPS
790 void wxListBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
791 {
792 GList *child = m_list->children;
793 while (child)
794 {
795 gtk_tooltips_set_tip( tips, GTK_WIDGET( child->data ), wxConv_local.cWX2MB(tip), (gchar*) NULL );
796 child = child->next;
797 }
798 }
799 #endif // wxUSE_TOOLTIPS
800
801 #if wxUSE_DRAG_AND_DROP
802 void wxListBox::SetDropTarget( wxDropTarget *dropTarget )
803 {
804 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
805
806 #ifndef NEW_GTK_DND_CODE
807 if (m_dropTarget)
808 {
809 GList *child = m_list->children;
810 while (child)
811 {
812 m_dropTarget->UnregisterWidget( GTK_WIDGET( child->data ) );
813 child = child->next;
814 }
815 }
816 #endif
817
818 wxWindow::SetDropTarget( dropTarget );
819
820 #ifndef NEW_GTK_DND_CODE
821 if (m_dropTarget)
822 {
823 GList *child = m_list->children;
824 while (child)
825 {
826 m_dropTarget->RegisterWidget( GTK_WIDGET( child->data ) );
827 child = child->next;
828 }
829 }
830 #endif
831 }
832 #endif
833
834 GtkWidget *wxListBox::GetConnectWidget()
835 {
836 return GTK_WIDGET(m_list);
837 }
838
839 bool wxListBox::IsOwnGtkWindow( GdkWindow *window )
840 {
841 if (wxWindow::IsOwnGtkWindow( window )) return TRUE;
842
843 GList *child = m_list->children;
844 while (child)
845 {
846 GtkWidget *bin = GTK_WIDGET( child->data );
847 if (bin->window == window) return TRUE;
848 child = child->next;
849 }
850
851 return FALSE;
852 }
853
854 void wxListBox::ApplyWidgetStyle()
855 {
856 SetWidgetStyle();
857
858 if (m_backgroundColour.Ok())
859 {
860 GdkWindow *window = GTK_WIDGET(m_list)->window;
861 m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
862 gdk_window_set_background( window, m_backgroundColour.GetColor() );
863 gdk_window_clear( window );
864 }
865
866 GList *child = m_list->children;
867 while (child)
868 {
869 gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
870
871 GtkBin *bin = GTK_BIN( child->data );
872 GtkWidget *label = GTK_WIDGET( bin->child );
873 gtk_widget_set_style( label, m_widgetStyle );
874
875 child = child->next;
876 }
877 }