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