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