New idle handling. Only that.
[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 // idle system
34 //-----------------------------------------------------------------------------
35
36 extern void wxapp_install_idle_handler();
37 extern bool g_isIdle;
38
39 //-------------------------------------------------------------------------
40 // conditional compilation
41 //-------------------------------------------------------------------------
42
43 #if (GTK_MINOR_VERSION > 0)
44 #define NEW_GTK_SCROLL_CODE
45 #endif
46
47 //-----------------------------------------------------------------------------
48 // private functions
49 //-----------------------------------------------------------------------------
50
51 #define CHECKBOX_STRING "[-] "
52
53 // checklistboxes have "[±] " prepended to their lables, this macro removes it
54 // (NB: 4 below is the length of CHECKBOX_STRING above)
55 //
56 // the argument to it is a "const char *" pointer
57 #define GET_REAL_LABEL(label) ((m_hasCheckBoxes)?(label)+4 : (label))
58
59 //-----------------------------------------------------------------------------
60 // data
61 //-----------------------------------------------------------------------------
62
63 extern bool g_blockEventsOnDrag;
64 extern bool g_blockEventsOnScroll;
65
66 //-----------------------------------------------------------------------------
67 // "button_press_event"
68 //-----------------------------------------------------------------------------
69
70 static gint
71 gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox )
72 {
73 if (g_isIdle) wxapp_install_idle_handler();
74
75 if (g_blockEventsOnDrag) return FALSE;
76 if (g_blockEventsOnScroll) return FALSE;
77
78 if (!listbox->HasVMT()) return FALSE;
79
80 int sel = listbox->GetIndex( widget );
81
82 if ((listbox->m_hasCheckBoxes) && (gdk_event->x < 15) && (gdk_event->type != GDK_2BUTTON_PRESS))
83 {
84 wxCheckListBox *clb = (wxCheckListBox *)listbox;
85
86 clb->Check( sel, !clb->IsChecked(sel) );
87
88 wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() );
89 event.SetEventObject( listbox );
90 event.SetInt( sel );
91 listbox->GetEventHandler()->ProcessEvent( event );
92 }
93
94 if (gdk_event->type == GDK_2BUTTON_PRESS)
95 {
96 wxCommandEvent event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, listbox->GetId() );
97 event.SetEventObject( listbox );
98
99 wxArrayInt aSelections;
100 int count = listbox->GetSelections(aSelections);
101 if ( count > 0 )
102 {
103 event.m_commandInt = aSelections[0] ;
104 event.m_clientData = listbox->GetClientData( event.m_commandInt );
105 wxString str(listbox->GetString(event.m_commandInt));
106 if (!str.IsEmpty()) event.m_commandString = str;
107 }
108 else
109 {
110 event.m_commandInt = -1 ;
111 event.m_commandString.Empty();
112 }
113
114 listbox->GetEventHandler()->ProcessEvent( event );
115
116 }
117
118 return FALSE;
119 }
120
121 //-----------------------------------------------------------------------------
122 // "key_press_event"
123 //-----------------------------------------------------------------------------
124
125 static gint
126 gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox )
127 {
128 if (g_isIdle) wxapp_install_idle_handler();
129
130 if (g_blockEventsOnDrag) return FALSE;
131
132 if (!listbox->HasVMT()) return FALSE;
133
134 if (gdk_event->keyval != ' ') return FALSE;
135
136 int sel = listbox->GetIndex( widget );
137
138 wxCheckListBox *clb = (wxCheckListBox *)listbox;
139
140 clb->Check( sel, !clb->IsChecked(sel) );
141
142 wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() );
143 event.SetEventObject( listbox );
144 event.SetInt( sel );
145 listbox->GetEventHandler()->ProcessEvent( event );
146
147 return FALSE;
148 }
149
150 //-----------------------------------------------------------------------------
151 // "select" and "deselect"
152 //-----------------------------------------------------------------------------
153
154 static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox *listbox )
155 {
156 if (g_isIdle) wxapp_install_idle_handler();
157
158 if (!listbox->HasVMT()) return;
159 if (g_blockEventsOnDrag) return;
160
161 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
162
163 wxArrayInt aSelections;
164 int count = listbox->GetSelections(aSelections);
165 if ( count > 0 )
166 {
167 event.m_commandInt = aSelections[0] ;
168 event.m_clientData = listbox->GetClientData( event.m_commandInt );
169 wxString str(listbox->GetString(event.m_commandInt));
170 if (!str.IsEmpty()) event.m_commandString = str;
171 }
172 else
173 {
174 event.m_commandInt = -1 ;
175 event.m_commandString.Empty();
176 }
177
178 event.SetEventObject( listbox );
179
180 listbox->GetEventHandler()->ProcessEvent( event );
181 }
182
183 //-----------------------------------------------------------------------------
184 // wxListBox
185 //-----------------------------------------------------------------------------
186
187 IMPLEMENT_DYNAMIC_CLASS(wxListBox,wxControl)
188
189 wxListBox::wxListBox()
190 {
191 m_list = (GtkList *) NULL;
192 m_hasCheckBoxes = FALSE;
193 }
194
195 bool wxListBox::Create( wxWindow *parent, wxWindowID id,
196 const wxPoint &pos, const wxSize &size,
197 int n, const wxString choices[],
198 long style, const wxValidator& validator, const wxString &name )
199 {
200 m_needParent = TRUE;
201 m_acceptsFocus = TRUE;
202
203 PreCreation( parent, id, pos, size, style, name );
204
205 SetValidator( validator );
206
207 m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL );
208 if (style & wxLB_ALWAYS_SB)
209 {
210 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget),
211 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
212 }
213 else
214 {
215 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget),
216 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
217 }
218
219 m_list = GTK_LIST( gtk_list_new() );
220
221 GtkSelectionMode mode = GTK_SELECTION_BROWSE;
222 if (style & wxLB_MULTIPLE)
223 mode = GTK_SELECTION_MULTIPLE;
224 else if (style & wxLB_EXTENDED)
225 mode = GTK_SELECTION_EXTENDED;
226
227 gtk_list_set_selection_mode( GTK_LIST(m_list), mode );
228
229 #ifdef NEW_GTK_SCROLL_CODE
230 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), GTK_WIDGET(m_list) );
231 #else
232 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_list) );
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.mbc_str() );
256
257 gtk_container_add( GTK_CONTAINER(m_list), list_item );
258
259 gtk_signal_connect( GTK_OBJECT(list_item), "select",
260 GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
261
262 if (style & wxLB_MULTIPLE)
263 gtk_signal_connect( GTK_OBJECT(list_item), "deselect",
264 GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
265
266 gtk_signal_connect( GTK_OBJECT(list_item),
267 "button_press_event",
268 (GtkSignalFunc)gtk_listbox_button_press_callback,
269 (gpointer) this );
270
271 if (m_hasCheckBoxes)
272 {
273 gtk_signal_connect( GTK_OBJECT(list_item),
274 "key_press_event",
275 (GtkSignalFunc)gtk_listbox_key_press_callback,
276 (gpointer)this );
277 }
278
279 ConnectWidget( list_item );
280
281 gtk_widget_show( list_item );
282 }
283
284 m_parent->AddChild( this );
285
286 (m_parent->m_insertCallback)( m_parent, this );
287
288 PostCreation();
289
290 SetBackgroundColour( parent->GetBackgroundColour() );
291 SetForegroundColour( parent->GetForegroundColour() );
292 SetFont( parent->GetFont() );
293
294 Show( TRUE );
295
296 return TRUE;
297 }
298
299 wxListBox::~wxListBox()
300 {
301 Clear();
302 }
303
304 void wxListBox::InsertItems(int nItems, const wxString items[], int pos)
305 {
306 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
307
308 GList *children = m_list->children;
309 int length = g_list_length(children);
310 wxCHECK_RET( pos <= length, _T("invalid index in wxListBox::InsertItems") );
311
312 // VZ: it seems that GTK 1.0.6 doesn't has a function to insert an item
313 // into a listbox at the given position, this is why we first delete
314 // all items after this position, then append these items and then
315 // reappend back the old ones.
316
317 // first detach the old items
318 int n; // loop var
319
320 if ( pos == length )
321 {
322 // no need to do anything complicated
323 for ( n = 0; n < nItems; n++ )
324 {
325 Append(items[n]);
326 }
327
328 return;
329 }
330
331 wxArrayString deletedLabels;
332 wxArrayPtrVoid deletedData;
333 wxArrayInt deletedChecks; // only for check list boxes
334
335 GList *child = g_list_nth( children, pos );
336 for ( n = 0; child != NULL; n++, child = child->next )
337 {
338 // save label
339 GtkBin *bin = GTK_BIN( child->data );
340 GtkLabel *label = GTK_LABEL( bin->child );
341
342 wxString str(GET_REAL_LABEL(label->label));
343 deletedLabels.Add(str);
344
345 // save data
346 void *clientData = NULL;
347 wxNode *node = NULL;
348
349 if ( n < (int)m_clientObjectList.GetCount() )
350 node = m_clientObjectList.Nth( n );
351
352 if ( node )
353 {
354 clientData = node->GetData();
355 m_clientObjectList.DeleteNode( node );
356 }
357
358 if ( !clientData )
359 {
360 if ( n < (int)m_clientDataList.GetCount() )
361 node = m_clientDataList.Nth( n );
362
363 if ( node )
364 {
365 clientData = node->GetData();
366 node = m_clientDataList.Nth( n );
367 }
368 }
369
370 deletedData.Add(clientData);
371
372 // save check state
373 if ( m_hasCheckBoxes )
374 {
375 deletedChecks.Add(((wxCheckListBox *)this)->IsChecked(pos + n));
376 }
377 }
378
379 int nDeletedCount = n;
380
381 gtk_list_clear_items( m_list, pos, length );
382
383 // now append the new items
384 for ( n = 0; n < nItems; n++ )
385 {
386 Append(items[n]);
387 }
388
389 // and append the old items too
390 pos += nItems; // now the indices are shifter
391 for ( n = 0; n < nDeletedCount; n++ )
392 {
393 Append(deletedLabels[n], deletedData[n]);
394
395 if ( m_hasCheckBoxes )
396 {
397 ((wxCheckListBox *)this)->Check(pos + n, (bool)deletedChecks[n]);
398 }
399 }
400 }
401
402 void wxListBox::AppendCommon( const wxString &item )
403 {
404 wxCHECK_RET( m_list != NULL, _T("invalid listbox") );
405
406 GtkWidget *list_item;
407
408 wxString label(item);
409 if (m_hasCheckBoxes)
410 {
411 label.Prepend(CHECKBOX_STRING);
412 }
413
414 list_item = gtk_list_item_new_with_label( label.mbc_str() );
415
416 gtk_container_add( GTK_CONTAINER(m_list), list_item );
417
418 gtk_signal_connect( GTK_OBJECT(list_item), "select",
419 GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
420
421 if (GetWindowStyleFlag() & wxLB_MULTIPLE)
422 gtk_signal_connect( GTK_OBJECT(list_item), "deselect",
423 GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this );
424
425 gtk_signal_connect( GTK_OBJECT(list_item),
426 "button_press_event",
427 (GtkSignalFunc)gtk_listbox_button_press_callback,
428 (gpointer) this );
429
430 if (m_hasCheckBoxes)
431 {
432 gtk_signal_connect( GTK_OBJECT(list_item),
433 "key_press_event",
434 (GtkSignalFunc)gtk_listbox_key_press_callback,
435 (gpointer)this );
436 }
437
438 gtk_widget_show( list_item );
439
440 ConnectWidget( list_item );
441
442 if (GTK_WIDGET_REALIZED(m_widget))
443 {
444 gtk_widget_realize( list_item );
445 gtk_widget_realize( GTK_BIN(list_item)->child );
446
447 if (m_widgetStyle) ApplyWidgetStyle();
448
449 #if wxUSE_DRAG_AND_DROP
450 #ifndef NEW_GTK_DND_CODE
451 if (m_dropTarget) m_dropTarget->RegisterWidget( list_item );
452 #endif
453 #endif
454
455 #if wxUSE_TOOLTIPS
456 if (m_toolTip) m_toolTip->Apply( this );
457 #endif
458 }
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, _T("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, _T("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, _T("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, _T("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, _T("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, _T("invalid listbox") );
549
550 GList *child = g_list_nth( m_list->children, n );
551
552 wxCHECK_RET( child, _T("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, _T("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, _T("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, _T("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, _T("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, _T(""), _T("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(_T("wrong listbox index"));
666
667 return _T("");
668 }
669
670 wxString wxListBox::GetStringSelection() const
671 {
672 wxCHECK_MSG( m_list != NULL, _T(""), _T("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(_T("no listbox selection available"));
686 return _T("");
687 }
688
689 int wxListBox::Number()
690 {
691 wxCHECK_MSG( m_list != NULL, -1, _T("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, _T("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(_T("wrong listbox index"));
714 return FALSE;
715 }
716
717 void wxListBox::Set( int WXUNUSED(n), const wxString *WXUNUSED(choices) )
718 {
719 wxFAIL_MSG(_T("wxListBox::Set not implemented"));
720 }
721
722 void wxListBox::SetFirstItem( int WXUNUSED(n) )
723 {
724 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
725 }
726
727 void wxListBox::SetFirstItem( const wxString &WXUNUSED(item) )
728 {
729 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
730 }
731
732 void wxListBox::SetSelection( int n, bool select )
733 {
734 wxCHECK_RET( m_list != NULL, _T("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, _T("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.mbc_str() );
758 }
759 else
760 {
761 wxFAIL_MSG(_T("wrong listbox index"));
762 }
763 }
764
765 void wxListBox::SetStringSelection( const wxString &string, bool select )
766 {
767 wxCHECK_RET( m_list != NULL, _T("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 wxChar *tip )
790 {
791 GList *child = m_list->children;
792 while (child)
793 {
794 gtk_tooltips_set_tip( tips, GTK_WIDGET( child->data ), wxConv_local.cWX2MB(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, _T("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 }