1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "listbox.h"
15 #include "wx/listbox.h"
19 #include "wx/dynarray.h"
22 #include "wx/checklst.h"
23 #include "wx/settings.h"
26 #include "wx/tooltip.h"
29 #if wxUSE_DRAG_AND_DROP
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 extern void wxapp_install_idle_handler();
43 //-------------------------------------------------------------------------
44 // conditional compilation
45 //-------------------------------------------------------------------------
47 #if (GTK_MINOR_VERSION > 0)
48 #define NEW_GTK_SCROLL_CODE
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 #if wxUSE_CHECKLISTBOX
57 #define CHECKBOX_STRING "[-] "
59 // checklistboxes have "[±] " prepended to their lables, this macro removes it
60 // (NB: 4 below is the length of CHECKBOX_STRING above)
62 // the argument to it is a "const char *" pointer
63 #define GET_REAL_LABEL(label) ((m_hasCheckBoxes)?(label)+4 : (label))
65 #else // !wxUSE_CHECKLISTBOX
67 #define GET_REAL_LABEL(label) (label)
69 #endif // wxUSE_CHECKLISTBOX
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
75 extern bool g_blockEventsOnDrag
;
76 extern bool g_blockEventsOnScroll
;
78 static bool g_hasDoubleClicked
= FALSE
;
80 //-----------------------------------------------------------------------------
81 // "button_release_event"
82 //-----------------------------------------------------------------------------
84 /* we would normally emit a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event once
85 a GDK_2BUTTON_PRESS occurs, but this has the particular problem of the
86 listbox keeping the focus until it receives a GDK_BUTTON_RELEASE event.
87 this can lead to race conditions so that we emit the dclick event
88 after the GDK_BUTTON_RELEASE event after the GDK_2BUTTON_PRESS event */
91 gtk_listbox_button_release_callback( GtkWidget
* WXUNUSED(widget
),
92 GdkEventButton
* WXUNUSED(gdk_event
),
95 if (g_isIdle
) wxapp_install_idle_handler();
97 if (g_blockEventsOnDrag
) return FALSE
;
98 if (g_blockEventsOnScroll
) return FALSE
;
100 if (!listbox
->m_hasVMT
) return FALSE
;
102 if (!g_hasDoubleClicked
) return FALSE
;
104 wxCommandEvent
event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, listbox
->GetId() );
105 event
.SetEventObject( listbox
);
107 wxArrayInt aSelections
;
108 int count
= listbox
->GetSelections(aSelections
);
111 event
.m_commandInt
= aSelections
[0] ;
112 event
.m_clientData
= listbox
->GetClientData( event
.m_commandInt
);
113 wxString
str(listbox
->GetString(event
.m_commandInt
));
114 if (!str
.IsEmpty()) event
.m_commandString
= str
;
118 event
.m_commandInt
= -1 ;
119 event
.m_commandString
.Empty();
122 listbox
->GetEventHandler()->ProcessEvent( event
);
127 //-----------------------------------------------------------------------------
128 // "button_press_event"
129 //-----------------------------------------------------------------------------
132 gtk_listbox_button_press_callback( GtkWidget
*widget
,
133 GdkEventButton
*gdk_event
,
136 if (g_isIdle
) wxapp_install_idle_handler();
138 if (g_blockEventsOnDrag
) return FALSE
;
139 if (g_blockEventsOnScroll
) return FALSE
;
141 if (!listbox
->m_hasVMT
) return FALSE
;
143 int sel
= listbox
->GetIndex( widget
);
145 #if wxUSE_CHECKLISTBOX
146 if ((listbox
->m_hasCheckBoxes
) && (gdk_event
->x
< 15) && (gdk_event
->type
!= GDK_2BUTTON_PRESS
))
148 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
150 clb
->Check( sel
, !clb
->IsChecked(sel
) );
152 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
153 event
.SetEventObject( listbox
);
155 listbox
->GetEventHandler()->ProcessEvent( event
);
157 #endif // wxUSE_CHECKLISTBOX
159 /* emit wxEVT_COMMAND_LISTBOX_DOUBLECLICKED later */
160 g_hasDoubleClicked
= (gdk_event
->type
== GDK_2BUTTON_PRESS
);
165 //-----------------------------------------------------------------------------
167 //-----------------------------------------------------------------------------
169 #if wxUSE_CHECKLISTBOX
171 gtk_listbox_key_press_callback( GtkWidget
*widget
, GdkEventKey
*gdk_event
, wxListBox
*listbox
)
173 if (g_isIdle
) wxapp_install_idle_handler();
175 if (g_blockEventsOnDrag
) return FALSE
;
177 if (!listbox
->m_hasVMT
) return FALSE
;
179 if (gdk_event
->keyval
!= ' ') return FALSE
;
181 int sel
= listbox
->GetIndex( widget
);
183 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
185 clb
->Check( sel
, !clb
->IsChecked(sel
) );
187 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
188 event
.SetEventObject( listbox
);
190 listbox
->GetEventHandler()->ProcessEvent( event
);
194 #endif // wxUSE_CHECKLISTBOX
196 //-----------------------------------------------------------------------------
197 // "select" and "deselect"
198 //-----------------------------------------------------------------------------
200 static void gtk_listitem_select_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
);
202 static void gtk_listitem_deselect_callback( GtkWidget
*widget
, wxListBox
*listbox
)
204 gtk_listitem_select_callback( widget
, listbox
);
207 static void gtk_listitem_select_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
)
209 if (g_isIdle
) wxapp_install_idle_handler();
211 if (!listbox
->m_hasVMT
) return;
212 if (g_blockEventsOnDrag
) return;
214 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, listbox
->GetId() );
216 wxArrayInt aSelections
;
217 int count
= listbox
->GetSelections(aSelections
);
220 event
.m_commandInt
= aSelections
[0] ;
221 event
.m_clientData
= listbox
->GetClientData( event
.m_commandInt
);
222 wxString
str(listbox
->GetString(event
.m_commandInt
));
223 if (!str
.IsEmpty()) event
.m_commandString
= str
;
227 event
.m_commandInt
= -1 ;
228 event
.m_commandString
.Empty();
231 event
.SetEventObject( listbox
);
233 listbox
->GetEventHandler()->ProcessEvent( event
);
236 //-----------------------------------------------------------------------------
238 //-----------------------------------------------------------------------------
240 IMPLEMENT_DYNAMIC_CLASS(wxListBox
,wxControl
)
242 wxListBox::wxListBox()
244 m_list
= (GtkList
*) NULL
;
245 #if wxUSE_CHECKLISTBOX
246 m_hasCheckBoxes
= FALSE
;
247 #endif // wxUSE_CHECKLISTBOX
250 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
251 const wxPoint
&pos
, const wxSize
&size
,
252 int n
, const wxString choices
[],
253 long style
, const wxValidator
& validator
, const wxString
&name
)
256 m_acceptsFocus
= TRUE
;
258 if (!PreCreation( parent
, pos
, size
) ||
259 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
261 wxFAIL_MSG( _T("wxListBox creation failed") );
265 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
266 if (style
& wxLB_ALWAYS_SB
)
268 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
269 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
273 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
274 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
277 m_list
= GTK_LIST( gtk_list_new() );
279 GtkSelectionMode mode
= GTK_SELECTION_BROWSE
;
280 if (style
& wxLB_MULTIPLE
)
281 mode
= GTK_SELECTION_MULTIPLE
;
282 else if (style
& wxLB_EXTENDED
)
283 mode
= GTK_SELECTION_EXTENDED
;
285 gtk_list_set_selection_mode( GTK_LIST(m_list
), mode
);
287 #ifdef NEW_GTK_SCROLL_CODE
288 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget
), GTK_WIDGET(m_list
) );
290 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_list
) );
293 gtk_widget_show( GTK_WIDGET(m_list
) );
295 wxSize newSize
= size
;
296 if (newSize
.x
== -1) newSize
.x
= 100;
297 if (newSize
.y
== -1) newSize
.y
= 110;
298 SetSize( newSize
.x
, newSize
.y
);
300 for (int i
= 0; i
< n
; i
++)
302 m_clientDataList
.Append( (wxObject
*) NULL
);
303 m_clientObjectList
.Append( (wxObject
*) NULL
);
305 GtkWidget
*list_item
;
307 wxString
str(choices
[i
]);
308 #if wxUSE_CHECKLISTBOX
311 str
.Prepend(CHECKBOX_STRING
);
313 #endif // wxUSE_CHECKLISTBOX
315 list_item
= gtk_list_item_new_with_label( str
.mbc_str() );
317 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
319 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
320 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
322 if (style
& wxLB_MULTIPLE
)
323 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
324 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
326 gtk_signal_connect( GTK_OBJECT(list_item
),
327 "button_press_event",
328 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
331 gtk_signal_connect_after( GTK_OBJECT(list_item
),
332 "button_release_event",
333 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
336 #if wxUSE_CHECKLISTBOX
339 gtk_signal_connect( GTK_OBJECT(list_item
),
341 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
344 #endif // wxUSE_CHECKLISTBOX
346 ConnectWidget( list_item
);
348 gtk_widget_show( list_item
);
351 m_parent
->DoAddChild( this );
355 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW
) );
356 SetForegroundColour( parent
->GetForegroundColour() );
357 SetFont( parent
->GetFont() );
364 wxListBox::~wxListBox()
369 void wxListBox::InsertItems(int nItems
, const wxString items
[], int pos
)
371 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
373 GList
*children
= m_list
->children
;
374 int length
= g_list_length(children
);
375 wxCHECK_RET( pos
<= length
, _T("invalid index in wxListBox::InsertItems") );
377 // VZ: it seems that GTK 1.0.6 doesn't has a function to insert an item
378 // into a listbox at the given position, this is why we first delete
379 // all items after this position, then append these items and then
380 // reappend back the old ones.
382 // first detach the old items
387 // no need to do anything complicated
388 for ( n
= 0; n
< nItems
; n
++ )
396 wxArrayString deletedLabels
;
397 wxArrayPtrVoid deletedData
;
398 wxArrayInt deletedChecks
; // only for check list boxes
400 GList
*child
= g_list_nth( children
, pos
);
401 for ( n
= 0; child
!= NULL
; n
++, child
= child
->next
)
404 GtkBin
*bin
= GTK_BIN( child
->data
);
405 GtkLabel
*label
= GTK_LABEL( bin
->child
);
407 wxString
str(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
408 deletedLabels
.Add(str
);
411 void *clientData
= NULL
;
414 if ( n
< (int)m_clientObjectList
.GetCount() )
415 node
= m_clientObjectList
.Nth( n
);
419 clientData
= node
->GetData();
420 m_clientObjectList
.DeleteNode( node
);
425 if ( n
< (int)m_clientDataList
.GetCount() )
426 node
= m_clientDataList
.Nth( n
);
430 clientData
= node
->GetData();
431 node
= m_clientDataList
.Nth( n
);
435 deletedData
.Add(clientData
);
437 #if wxUSE_CHECKLISTBOX
439 if ( m_hasCheckBoxes
)
441 deletedChecks
.Add(((wxCheckListBox
*)this)->IsChecked(pos
+ n
));
443 #endif // wxUSE_CHECKLISTBOX
446 int nDeletedCount
= n
;
448 gtk_list_clear_items( m_list
, pos
, length
);
450 // now append the new items
451 for ( n
= 0; n
< nItems
; n
++ )
456 // and append the old items too
457 pos
+= nItems
; // now the indices are shifter
458 for ( n
= 0; n
< nDeletedCount
; n
++ )
460 Append(deletedLabels
[n
], deletedData
[n
]);
462 #if wxUSE_CHECKLISTBOX
463 if ( m_hasCheckBoxes
)
465 ((wxCheckListBox
*)this)->Check(pos
+ n
, (bool)deletedChecks
[n
]);
467 #endif // wxUSE_CHECKLISTBOX
471 void wxListBox::AppendCommon( const wxString
&item
)
473 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
475 GtkWidget
*list_item
;
477 wxString
label(item
);
478 #if wxUSE_CHECKLISTBOX
481 label
.Prepend(CHECKBOX_STRING
);
483 #endif // wxUSE_CHECKLISTBOX
485 list_item
= gtk_list_item_new_with_label( label
.mbc_str() );
487 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
489 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
490 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
492 if (HasFlag(wxLB_MULTIPLE
))
493 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
494 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
496 gtk_signal_connect( GTK_OBJECT(list_item
),
497 "button_press_event",
498 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
501 gtk_signal_connect_after( GTK_OBJECT(list_item
),
502 "button_release_event",
503 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
506 #if wxUSE_CHECKLISTBOX
509 gtk_signal_connect( GTK_OBJECT(list_item
),
511 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
514 #endif // wxUSE_CHECKLISTBOX
516 gtk_widget_show( list_item
);
518 ConnectWidget( list_item
);
520 if (GTK_WIDGET_REALIZED(m_widget
))
522 gtk_widget_realize( list_item
);
523 gtk_widget_realize( GTK_BIN(list_item
)->child
);
525 //if (m_widgetStyle) ApplyWidgetStyle();
527 // Apply current widget style to the new list_item
528 gtk_widget_set_style( GTK_WIDGET( list_item
), m_widgetStyle
);
529 GtkBin
*bin
= GTK_BIN( list_item
);
530 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
531 gtk_widget_set_style( label
, m_widgetStyle
);
534 #if wxUSE_DRAG_AND_DROP
535 #ifndef NEW_GTK_DND_CODE
536 if (m_dropTarget
) m_dropTarget
->RegisterWidget( list_item
);
541 if (m_tooltip
) m_tooltip
->Apply( this );
546 void wxListBox::Append( const wxString
&item
)
548 m_clientDataList
.Append( (wxObject
*) NULL
);
549 m_clientObjectList
.Append( (wxObject
*) NULL
);
551 AppendCommon( item
);
554 void wxListBox::Append( const wxString
&item
, void *clientData
)
556 m_clientDataList
.Append( (wxObject
*) clientData
);
557 m_clientObjectList
.Append( (wxObject
*) NULL
);
559 AppendCommon( item
);
562 void wxListBox::Append( const wxString
&item
, wxClientData
*clientData
)
564 m_clientObjectList
.Append( (wxObject
*) clientData
);
565 m_clientDataList
.Append( (wxObject
*) NULL
);
567 AppendCommon( item
);
570 void wxListBox::SetClientData( int n
, void* clientData
)
572 wxCHECK_RET( m_widget
!= NULL
, _T("invalid combobox") );
574 wxNode
*node
= m_clientDataList
.Nth( n
);
577 node
->SetData( (wxObject
*) clientData
);
580 void* wxListBox::GetClientData( int n
)
582 wxCHECK_MSG( m_widget
!= NULL
, NULL
, _T("invalid combobox") );
584 wxNode
*node
= m_clientDataList
.Nth( n
);
585 if (!node
) return NULL
;
590 void wxListBox::SetClientObject( int n
, wxClientData
* clientData
)
592 wxCHECK_RET( m_widget
!= NULL
, _T("invalid combobox") );
594 wxNode
*node
= m_clientObjectList
.Nth( n
);
597 wxClientData
*cd
= (wxClientData
*) node
->Data();
600 node
->SetData( (wxObject
*) clientData
);
603 wxClientData
* wxListBox::GetClientObject( int n
)
605 wxCHECK_MSG( m_widget
!= NULL
, (wxClientData
*)NULL
, _T("invalid combobox") );
607 wxNode
*node
= m_clientObjectList
.Nth( n
);
608 if (!node
) return (wxClientData
*) NULL
;
610 return (wxClientData
*) node
->Data();
613 void wxListBox::Clear()
615 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
617 gtk_list_clear_items( m_list
, 0, Number() );
619 wxNode
*node
= m_clientObjectList
.First();
622 wxClientData
*cd
= (wxClientData
*)node
->Data();
626 m_clientObjectList
.Clear();
628 m_clientDataList
.Clear();
631 void wxListBox::Delete( int n
)
633 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
635 GList
*child
= g_list_nth( m_list
->children
, n
);
637 wxCHECK_RET( child
, _T("wrong listbox index") );
639 GList
*list
= g_list_append( (GList
*) NULL
, child
->data
);
640 gtk_list_remove_items( m_list
, list
);
643 wxNode
*node
= m_clientObjectList
.Nth( n
);
646 wxClientData
*cd
= (wxClientData
*)node
->Data();
648 m_clientObjectList
.DeleteNode( node
);
651 node
= m_clientDataList
.Nth( n
);
654 m_clientDataList
.DeleteNode( node
);
658 void wxListBox::Deselect( int n
)
660 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
664 gtk_list_unselect_item( m_list
, n
);
669 int wxListBox::FindString( const wxString
&item
) const
671 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
673 GList
*child
= m_list
->children
;
677 GtkBin
*bin
= GTK_BIN( child
->data
);
678 GtkLabel
*label
= GTK_LABEL( bin
->child
);
680 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
689 // it's not an error if the string is not found -> no wxCHECK
694 int wxListBox::GetSelection() const
696 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
698 GList
*child
= m_list
->children
;
702 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
) return count
;
709 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
711 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
713 // get the number of selected items first
714 GList
*child
= m_list
->children
;
716 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
)
718 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
727 aSelections
.Alloc(count
); // optimization attempt
729 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
, i
++)
731 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
739 wxString
wxListBox::GetString( int n
) const
741 wxCHECK_MSG( m_list
!= NULL
, _T(""), _T("invalid listbox") );
743 GList
*child
= g_list_nth( m_list
->children
, n
);
746 GtkBin
*bin
= GTK_BIN( child
->data
);
747 GtkLabel
*label
= GTK_LABEL( bin
->child
);
749 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
754 wxFAIL_MSG(_T("wrong listbox index"));
759 wxString
wxListBox::GetStringSelection() const
761 wxCHECK_MSG( m_list
!= NULL
, _T(""), _T("invalid listbox") );
763 GList
*selection
= m_list
->selection
;
766 GtkBin
*bin
= GTK_BIN( selection
->data
);
767 GtkLabel
*label
= GTK_LABEL( bin
->child
);
769 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
774 wxFAIL_MSG(_T("no listbox selection available"));
778 int wxListBox::Number()
780 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
782 GList
*child
= m_list
->children
;
784 while (child
) { count
++; child
= child
->next
; }
788 bool wxListBox::Selected( int n
)
790 wxCHECK_MSG( m_list
!= NULL
, FALSE
, _T("invalid listbox") );
792 GList
*target
= g_list_nth( m_list
->children
, n
);
795 GList
*child
= m_list
->selection
;
798 if (child
->data
== target
->data
) return TRUE
;
802 wxFAIL_MSG(_T("wrong listbox index"));
806 void wxListBox::Set( int WXUNUSED(n
), const wxString
*WXUNUSED(choices
) )
808 wxFAIL_MSG(_T("wxListBox::Set not implemented"));
811 void wxListBox::SetFirstItem( int WXUNUSED(n
) )
813 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
816 void wxListBox::SetFirstItem( const wxString
&WXUNUSED(item
) )
818 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
821 void wxListBox::SetSelection( int n
, bool select
)
823 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
828 gtk_list_select_item( m_list
, n
);
830 gtk_list_unselect_item( m_list
, n
);
835 void wxListBox::SetString( int n
, const wxString
&string
)
837 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
839 GList
*child
= g_list_nth( m_list
->children
, n
);
842 GtkBin
*bin
= GTK_BIN( child
->data
);
843 GtkLabel
*label
= GTK_LABEL( bin
->child
);
846 #if wxUSE_CHECKLISTBOX
848 str
+= CHECKBOX_STRING
;
849 #endif // wxUSE_CHECKLISTBOX
852 gtk_label_set( label
, str
.mbc_str() );
856 wxFAIL_MSG(_T("wrong listbox index"));
860 void wxListBox::SetStringSelection( const wxString
&string
, bool select
)
862 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
864 SetSelection( FindString(string
), select
);
867 int wxListBox::GetIndex( GtkWidget
*item
) const
871 GList
*child
= m_list
->children
;
875 if (GTK_WIDGET(child
->data
) == item
) return count
;
884 void wxListBox::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
886 GList
*child
= m_list
->children
;
889 gtk_tooltips_set_tip( tips
, GTK_WIDGET( child
->data
), wxConvCurrent
->cWX2MB(tip
), (gchar
*) NULL
);
893 #endif // wxUSE_TOOLTIPS
895 #if wxUSE_DRAG_AND_DROP
896 void wxListBox::SetDropTarget( wxDropTarget
*dropTarget
)
898 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
900 #ifndef NEW_GTK_DND_CODE
903 GList
*child
= m_list
->children
;
906 m_dropTarget
->UnregisterWidget( GTK_WIDGET( child
->data
) );
912 wxWindow::SetDropTarget( dropTarget
);
914 #ifndef NEW_GTK_DND_CODE
917 GList
*child
= m_list
->children
;
920 m_dropTarget
->RegisterWidget( GTK_WIDGET( child
->data
) );
928 void wxListBox::DisableEvents()
930 GList
*child
= m_list
->children
;
933 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
934 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
936 if (HasFlag(wxLB_MULTIPLE
))
937 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
938 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
944 void wxListBox::EnableEvents()
946 GList
*child
= m_list
->children
;
949 gtk_signal_connect( GTK_OBJECT(child
->data
), "select",
950 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
952 if (HasFlag(wxLB_MULTIPLE
))
953 gtk_signal_connect( GTK_OBJECT(child
->data
), "deselect",
954 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
960 GtkWidget
*wxListBox::GetConnectWidget()
962 return GTK_WIDGET(m_list
);
965 bool wxListBox::IsOwnGtkWindow( GdkWindow
*window
)
967 if (wxWindow::IsOwnGtkWindow( window
)) return TRUE
;
969 GList
*child
= m_list
->children
;
972 GtkWidget
*bin
= GTK_WIDGET( child
->data
);
973 if (bin
->window
== window
) return TRUE
;
980 void wxListBox::ApplyWidgetStyle()
984 if (m_backgroundColour
.Ok())
986 GdkWindow
*window
= GTK_WIDGET(m_list
)->window
;
989 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
990 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
991 gdk_window_clear( window
);
995 GList
*child
= m_list
->children
;
998 gtk_widget_set_style( GTK_WIDGET(child
->data
), m_widgetStyle
);
1000 GtkBin
*bin
= GTK_BIN( child
->data
);
1001 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
1002 gtk_widget_set_style( label
, m_widgetStyle
);
1004 child
= child
->next
;