Small modifications to Vadims changes
[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->m_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->m_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->m_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->DoAddChild( this );
286
287 PostCreation();
288
289 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW ) );
290 SetForegroundColour( parent->GetForegroundColour() );
291 SetFont( parent->GetFont() );
292
293 Show( TRUE );
294
295 return TRUE;
296 }
297
298 wxListBox::~wxListBox()
299 {
300 Clear();
301 }
302
303 void wxListBox::InsertItems(int nItems, const wxString items[], int pos)
304 {
305 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
306
307 GList *children = m_list->children;
308 int length = g_list_length(children);
309 wxCHECK_RET( pos <= length, _T("invalid index in wxListBox::InsertItems") );
310
311 // VZ: it seems that GTK 1.0.6 doesn't has a function to insert an item
312 // into a listbox at the given position, this is why we first delete
313 // all items after this position, then append these items and then
314 // reappend back the old ones.
315
316 // first detach the old items
317 int n; // loop var
318
319 if ( pos == length )
320 {
321 // no need to do anything complicated
322 for ( n = 0; n < nItems; n++ )
323 {
324 Append(items[n]);
325 }
326
327 return;
328 }
329
330 wxArrayString deletedLabels;
331 wxArrayPtrVoid deletedData;
332 wxArrayInt deletedChecks; // only for check list boxes
333
334 GList *child = g_list_nth( children, pos );
335 for ( n = 0; child != NULL; n++, child = child->next )
336 {
337 // save label
338 GtkBin *bin = GTK_BIN( child->data );
339 GtkLabel *label = GTK_LABEL( bin->child );
340
341 wxString str(GET_REAL_LABEL(label->label));
342 deletedLabels.Add(str);
343
344 // save data
345 void *clientData = NULL;
346 wxNode *node = NULL;
347
348 if ( n < (int)m_clientObjectList.GetCount() )
349 node = m_clientObjectList.Nth( n );
350
351 if ( node )
352 {
353 clientData = node->GetData();
354 m_clientObjectList.DeleteNode( node );
355 }
356
357 if ( !clientData )
358 {
359 if ( n < (int)m_clientDataList.GetCount() )
360 node = m_clientDataList.Nth( n );
361
362 if ( node )
363 {
364 clientData = node->GetData();
365 node = m_clientDataList.Nth( n );
366 }
367 }
368
369 deletedData.Add(clientData);
370
371 // save check state
372 if ( m_hasCheckBoxes )
373 {
374 deletedChecks.Add(((wxCheckListBox *)this)->IsChecked(pos + n));
375 }
376 }
377
378 int nDeletedCount = n;
379
380 gtk_list_clear_items( m_list, pos, length );
381
382 // now append the new items
383 for ( n = 0; n < nItems; n++ )
384 {
385 Append(items[n]);
386 }
387
388 // and append the old items too
389 pos += nItems; // now the indices are shifter
390 for ( n = 0; n < nDeletedCount; n++ )
391 {
392 Append(deletedLabels[n], deletedData[n]);
393
394 if ( m_hasCheckBoxes )
395 {
396 ((wxCheckListBox *)this)->Check(pos + n, (bool)deletedChecks[n]);
397 }
398 }
399 }
400
401 void wxListBox::AppendCommon( const wxString &item )
402 {
403 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
404
405 GtkWidget *list_item;
406
407 wxString label(item);
408 if (m_hasCheckBoxes)
409 {
410 label.Prepend(CHECKBOX_STRING);
411 }
412
413 list_item = gtk_list_item_new_with_label( label.mbc_str() );
414
415 gtk_container_add( GTK_CONTAINER(m_list), list_item );
416
417 gtk_signal_connect( GTK_OBJECT(list_item), "select",
418 GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
419
420 if (HasFlag(wxLB_MULTIPLE))
421 gtk_signal_connect( GTK_OBJECT(list_item), "deselect",
422 GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
423
424 gtk_signal_connect( GTK_OBJECT(list_item),
425 "button_press_event",
426 (GtkSignalFunc)gtk_listbox_button_press_callback,
427 (gpointer) this );
428
429 if (m_hasCheckBoxes)
430 {
431 gtk_signal_connect( GTK_OBJECT(list_item),
432 "key_press_event",
433 (GtkSignalFunc)gtk_listbox_key_press_callback,
434 (gpointer)this );
435 }
436
437 gtk_widget_show( list_item );
438
439 ConnectWidget( list_item );
440
441 if (GTK_WIDGET_REALIZED(m_widget))
442 {
443 gtk_widget_realize( list_item );
444 gtk_widget_realize( GTK_BIN(list_item)->child );
445
446 if (m_widgetStyle) ApplyWidgetStyle();
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
460 void wxListBox::Append( const wxString &item )
461 {
462 m_clientDataList.Append( (wxObject*) NULL );
463 m_clientObjectList.Append( (wxObject*) NULL );
464
465 AppendCommon( item );
466 }
467
468 void wxListBox::Append( const wxString &item, void *clientData )
469 {
470 m_clientDataList.Append( (wxObject*) clientData );
471 m_clientObjectList.Append( (wxObject*) NULL );
472
473 AppendCommon( item );
474 }
475
476 void wxListBox::Append( const wxString &item, wxClientData *clientData )
477 {
478 m_clientObjectList.Append( (wxObject*) clientData );
479 m_clientDataList.Append( (wxObject*) NULL );
480
481 AppendCommon( item );
482 }
483
484 void wxListBox::SetClientData( int n, void* clientData )
485 {
486 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
487
488 wxNode *node = m_clientDataList.Nth( n );
489 if (!node) return;
490
491 node->SetData( (wxObject*) clientData );
492 }
493
494 void* wxListBox::GetClientData( int n )
495 {
496 wxCHECK_MSG( m_widget != NULL, NULL, _T("invalid combobox") );
497
498 wxNode *node = m_clientDataList.Nth( n );
499 if (!node) return NULL;
500
501 return node->Data();
502 }
503
504 void wxListBox::SetClientObject( int n, wxClientData* clientData )
505 {
506 wxCHECK_RET( m_widget != NULL, _T("invalid combobox") );
507
508 wxNode *node = m_clientObjectList.Nth( n );
509 if (!node) return;
510
511 wxClientData *cd = (wxClientData*) node->Data();
512 if (cd) delete cd;
513
514 node->SetData( (wxObject*) clientData );
515 }
516
517 wxClientData* wxListBox::GetClientObject( int n )
518 {
519 wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, _T("invalid combobox") );
520
521 wxNode *node = m_clientObjectList.Nth( n );
522 if (!node) return (wxClientData*) NULL;
523
524 return (wxClientData*) node->Data();
525 }
526
527 void wxListBox::Clear()
528 {
529 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
530
531 gtk_list_clear_items( m_list, 0, Number() );
532
533 wxNode *node = m_clientObjectList.First();
534 while (node)
535 {
536 wxClientData *cd = (wxClientData*)node->Data();
537 if (cd) delete cd;
538 node = node->Next();
539 }
540 m_clientObjectList.Clear();
541
542 m_clientDataList.Clear();
543 }
544
545 void wxListBox::Delete( int n )
546 {
547 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
548
549 GList *child = g_list_nth( m_list->children, n );
550
551 wxCHECK_RET( child, _T("wrong listbox index") );
552
553 GList *list = g_list_append( (GList*) NULL, child->data );
554 gtk_list_remove_items( m_list, list );
555 g_list_free( list );
556
557 wxNode *node = m_clientObjectList.Nth( n );
558 if (node)
559 {
560 wxClientData *cd = (wxClientData*)node->Data();
561 if (cd) delete cd;
562 m_clientObjectList.DeleteNode( node );
563 }
564
565 node = m_clientDataList.Nth( n );
566 if (node)
567 {
568 m_clientDataList.DeleteNode( node );
569 }
570 }
571
572 void wxListBox::Deselect( int n )
573 {
574 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
575
576 gtk_list_unselect_item( m_list, n );
577 }
578
579 int wxListBox::FindString( const wxString &item ) const
580 {
581 wxCHECK_MSG( m_list != NULL, -1, _T("invalid listbox") );
582
583 GList *child = m_list->children;
584 int count = 0;
585 while (child)
586 {
587 GtkBin *bin = GTK_BIN( child->data );
588 GtkLabel *label = GTK_LABEL( bin->child );
589
590 wxString str = GET_REAL_LABEL(label->label);
591
592 if (str == item)
593 return count;
594
595 count++;
596 child = child->next;
597 }
598
599 // it's not an error if the string is not found -> no wxCHECK
600
601 return -1;
602 }
603
604 int wxListBox::GetSelection() const
605 {
606 wxCHECK_MSG( m_list != NULL, -1, _T("invalid listbox") );
607
608 GList *child = m_list->children;
609 int count = 0;
610 while (child)
611 {
612 if (GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED) return count;
613 count++;
614 child = child->next;
615 }
616 return -1;
617 }
618
619 int wxListBox::GetSelections( wxArrayInt& aSelections ) const
620 {
621 wxCHECK_MSG( m_list != NULL, -1, _T("invalid listbox") );
622
623 // get the number of selected items first
624 GList *child = m_list->children;
625 int count = 0;
626 for (child = m_list->children; child != NULL; child = child->next)
627 {
628 if (GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED)
629 count++;
630 }
631
632 aSelections.Empty();
633
634 if (count > 0)
635 {
636 // now fill the list
637 aSelections.Alloc(count); // optimization attempt
638 int i = 0;
639 for (child = m_list->children; child != NULL; child = child->next, i++)
640 {
641 if (GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED)
642 aSelections.Add(i);
643 }
644 }
645
646 return count;
647 }
648
649 wxString wxListBox::GetString( int n ) const
650 {
651 wxCHECK_MSG( m_list != NULL, _T(""), _T("invalid listbox") );
652
653 GList *child = g_list_nth( m_list->children, n );
654 if (child)
655 {
656 GtkBin *bin = GTK_BIN( child->data );
657 GtkLabel *label = GTK_LABEL( bin->child );
658
659 wxString str = GET_REAL_LABEL(label->label);
660
661 return str;
662 }
663
664 wxFAIL_MSG(_T("wrong listbox index"));
665
666 return _T("");
667 }
668
669 wxString wxListBox::GetStringSelection() const
670 {
671 wxCHECK_MSG( m_list != NULL, _T(""), _T("invalid listbox") );
672
673 GList *selection = m_list->selection;
674 if (selection)
675 {
676 GtkBin *bin = GTK_BIN( selection->data );
677 GtkLabel *label = GTK_LABEL( bin->child );
678
679 wxString str = GET_REAL_LABEL(label->label);
680
681 return str;
682 }
683
684 wxFAIL_MSG(_T("no listbox selection available"));
685 return _T("");
686 }
687
688 int wxListBox::Number()
689 {
690 wxCHECK_MSG( m_list != NULL, -1, _T("invalid listbox") );
691
692 GList *child = m_list->children;
693 int count = 0;
694 while (child) { count++; child = child->next; }
695 return count;
696 }
697
698 bool wxListBox::Selected( int n )
699 {
700 wxCHECK_MSG( m_list != NULL, FALSE, _T("invalid listbox") );
701
702 GList *target = g_list_nth( m_list->children, n );
703 if (target)
704 {
705 GList *child = m_list->selection;
706 while (child)
707 {
708 if (child->data == target->data) return TRUE;
709 child = child->next;
710 }
711 }
712 wxFAIL_MSG(_T("wrong listbox index"));
713 return FALSE;
714 }
715
716 void wxListBox::Set( int WXUNUSED(n), const wxString *WXUNUSED(choices) )
717 {
718 wxFAIL_MSG(_T("wxListBox::Set not implemented"));
719 }
720
721 void wxListBox::SetFirstItem( int WXUNUSED(n) )
722 {
723 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
724 }
725
726 void wxListBox::SetFirstItem( const wxString &WXUNUSED(item) )
727 {
728 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
729 }
730
731 void wxListBox::SetSelection( int n, bool select )
732 {
733 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
734
735 if (select)
736 gtk_list_select_item( m_list, n );
737 else
738 gtk_list_unselect_item( m_list, n );
739 }
740
741 void wxListBox::SetString( int n, const wxString &string )
742 {
743 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
744
745 GList *child = g_list_nth( m_list->children, n );
746 if (child)
747 {
748 GtkBin *bin = GTK_BIN( child->data );
749 GtkLabel *label = GTK_LABEL( bin->child );
750
751 wxString str;
752 if (m_hasCheckBoxes)
753 str += CHECKBOX_STRING;
754 str += string;
755
756 gtk_label_set( label, str.mbc_str() );
757 }
758 else
759 {
760 wxFAIL_MSG(_T("wrong listbox index"));
761 }
762 }
763
764 void wxListBox::SetStringSelection( const wxString &string, bool select )
765 {
766 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
767
768 SetSelection( FindString(string), select );
769 }
770
771 int wxListBox::GetIndex( GtkWidget *item ) const
772 {
773 if (item)
774 {
775 GList *child = m_list->children;
776 int count = 0;
777 while (child)
778 {
779 if (GTK_WIDGET(child->data) == item) return count;
780 count++;
781 child = child->next;
782 }
783 }
784 return -1;
785 }
786
787 #if wxUSE_TOOLTIPS
788 void wxListBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
789 {
790 GList *child = m_list->children;
791 while (child)
792 {
793 gtk_tooltips_set_tip( tips, GTK_WIDGET( child->data ), wxConv_local.cWX2MB(tip), (gchar*) NULL );
794 child = child->next;
795 }
796 }
797 #endif // wxUSE_TOOLTIPS
798
799 #if wxUSE_DRAG_AND_DROP
800 void wxListBox::SetDropTarget( wxDropTarget *dropTarget )
801 {
802 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
803
804 #ifndef NEW_GTK_DND_CODE
805 if (m_dropTarget)
806 {
807 GList *child = m_list->children;
808 while (child)
809 {
810 m_dropTarget->UnregisterWidget( GTK_WIDGET( child->data ) );
811 child = child->next;
812 }
813 }
814 #endif
815
816 wxWindow::SetDropTarget( dropTarget );
817
818 #ifndef NEW_GTK_DND_CODE
819 if (m_dropTarget)
820 {
821 GList *child = m_list->children;
822 while (child)
823 {
824 m_dropTarget->RegisterWidget( GTK_WIDGET( child->data ) );
825 child = child->next;
826 }
827 }
828 #endif
829 }
830 #endif
831
832 GtkWidget *wxListBox::GetConnectWidget()
833 {
834 return GTK_WIDGET(m_list);
835 }
836
837 bool wxListBox::IsOwnGtkWindow( GdkWindow *window )
838 {
839 if (wxWindow::IsOwnGtkWindow( window )) return TRUE;
840
841 GList *child = m_list->children;
842 while (child)
843 {
844 GtkWidget *bin = GTK_WIDGET( child->data );
845 if (bin->window == window) return TRUE;
846 child = child->next;
847 }
848
849 return FALSE;
850 }
851
852 void wxListBox::ApplyWidgetStyle()
853 {
854 SetWidgetStyle();
855
856 if (m_backgroundColour.Ok())
857 {
858 GdkWindow *window = GTK_WIDGET(m_list)->window;
859 if ( window )
860 {
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
867 GList *child = m_list->children;
868 while (child)
869 {
870 gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
871
872 GtkBin *bin = GTK_BIN( child->data );
873 GtkWidget *label = GTK_WIDGET( bin->child );
874 gtk_widget_set_style( label, m_widgetStyle );
875
876 child = child->next;
877 }
878 }