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