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