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