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
;
77 extern wxCursor g_globalCursor
;
79 static bool g_hasDoubleClicked
= FALSE
;
81 //-----------------------------------------------------------------------------
82 // "button_release_event"
83 //-----------------------------------------------------------------------------
85 /* we would normally emit a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event once
86 a GDK_2BUTTON_PRESS occurs, but this has the particular problem of the
87 listbox keeping the focus until it receives a GDK_BUTTON_RELEASE event.
88 this can lead to race conditions so that we emit the dclick event
89 after the GDK_BUTTON_RELEASE event after the GDK_2BUTTON_PRESS event */
92 gtk_listbox_button_release_callback( GtkWidget
* WXUNUSED(widget
),
93 GdkEventButton
* WXUNUSED(gdk_event
),
96 if (g_isIdle
) wxapp_install_idle_handler();
98 if (g_blockEventsOnDrag
) return FALSE
;
99 if (g_blockEventsOnScroll
) return FALSE
;
101 if (!listbox
->m_hasVMT
) return FALSE
;
103 if (!g_hasDoubleClicked
) return FALSE
;
105 wxCommandEvent
event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, listbox
->GetId() );
106 event
.SetEventObject( listbox
);
108 wxArrayInt aSelections
;
109 int count
= listbox
->GetSelections(aSelections
);
112 event
.m_commandInt
= aSelections
[0] ;
113 event
.m_clientData
= listbox
->GetClientData( event
.m_commandInt
);
114 wxString
str(listbox
->GetString(event
.m_commandInt
));
115 if (!str
.IsEmpty()) event
.m_commandString
= str
;
119 event
.m_commandInt
= -1 ;
120 event
.m_commandString
.Empty();
123 listbox
->GetEventHandler()->ProcessEvent( event
);
128 //-----------------------------------------------------------------------------
129 // "button_press_event"
130 //-----------------------------------------------------------------------------
133 gtk_listbox_button_press_callback( GtkWidget
*widget
,
134 GdkEventButton
*gdk_event
,
137 if (g_isIdle
) wxapp_install_idle_handler();
139 if (g_blockEventsOnDrag
) return FALSE
;
140 if (g_blockEventsOnScroll
) return FALSE
;
142 if (!listbox
->m_hasVMT
) return FALSE
;
144 int sel
= listbox
->GetIndex( widget
);
146 #if wxUSE_CHECKLISTBOX
147 if ((listbox
->m_hasCheckBoxes
) && (gdk_event
->x
< 15) && (gdk_event
->type
!= GDK_2BUTTON_PRESS
))
149 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
151 clb
->Check( sel
, !clb
->IsChecked(sel
) );
153 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
154 event
.SetEventObject( listbox
);
156 listbox
->GetEventHandler()->ProcessEvent( event
);
158 #endif // wxUSE_CHECKLISTBOX
160 /* emit wxEVT_COMMAND_LISTBOX_DOUBLECLICKED later */
161 g_hasDoubleClicked
= (gdk_event
->type
== GDK_2BUTTON_PRESS
);
166 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
170 #if wxUSE_CHECKLISTBOX
172 gtk_listbox_key_press_callback( GtkWidget
*widget
, GdkEventKey
*gdk_event
, wxListBox
*listbox
)
174 if (g_isIdle
) wxapp_install_idle_handler();
176 if (g_blockEventsOnDrag
) return FALSE
;
178 if (!listbox
->m_hasVMT
) return FALSE
;
180 if (gdk_event
->keyval
!= ' ') return FALSE
;
182 int sel
= listbox
->GetIndex( widget
);
184 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
186 clb
->Check( sel
, !clb
->IsChecked(sel
) );
188 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
189 event
.SetEventObject( listbox
);
191 listbox
->GetEventHandler()->ProcessEvent( event
);
195 #endif // wxUSE_CHECKLISTBOX
197 //-----------------------------------------------------------------------------
198 // "select" and "deselect"
199 //-----------------------------------------------------------------------------
201 static void gtk_listitem_select_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
);
203 static void gtk_listitem_deselect_callback( GtkWidget
*widget
, wxListBox
*listbox
)
205 gtk_listitem_select_callback( widget
, listbox
);
208 static void gtk_listitem_select_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
)
210 if (g_isIdle
) wxapp_install_idle_handler();
212 if (!listbox
->m_hasVMT
) return;
213 if (g_blockEventsOnDrag
) return;
215 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, listbox
->GetId() );
217 wxArrayInt aSelections
;
218 int count
= listbox
->GetSelections(aSelections
);
221 event
.m_commandInt
= aSelections
[0] ;
222 event
.m_clientData
= listbox
->GetClientData( event
.m_commandInt
);
223 wxString
str(listbox
->GetString(event
.m_commandInt
));
224 if (!str
.IsEmpty()) event
.m_commandString
= str
;
228 event
.m_commandInt
= -1 ;
229 event
.m_commandString
.Empty();
232 event
.SetEventObject( listbox
);
234 listbox
->GetEventHandler()->ProcessEvent( event
);
237 //-----------------------------------------------------------------------------
239 //-----------------------------------------------------------------------------
241 IMPLEMENT_DYNAMIC_CLASS(wxListBox
,wxControl
)
243 wxListBox::wxListBox()
245 m_list
= (GtkList
*) NULL
;
246 #if wxUSE_CHECKLISTBOX
247 m_hasCheckBoxes
= FALSE
;
248 #endif // wxUSE_CHECKLISTBOX
251 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
252 const wxPoint
&pos
, const wxSize
&size
,
253 int n
, const wxString choices
[],
254 long style
, const wxValidator
& validator
, const wxString
&name
)
257 m_acceptsFocus
= TRUE
;
259 if (!PreCreation( parent
, pos
, size
) ||
260 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
262 wxFAIL_MSG( T("wxListBox creation failed") );
266 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
267 if (style
& wxLB_ALWAYS_SB
)
269 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
270 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
274 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
275 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
278 m_list
= GTK_LIST( gtk_list_new() );
280 GtkSelectionMode mode
= GTK_SELECTION_BROWSE
;
281 if (style
& wxLB_MULTIPLE
)
282 mode
= GTK_SELECTION_MULTIPLE
;
283 else if (style
& wxLB_EXTENDED
)
284 mode
= GTK_SELECTION_EXTENDED
;
286 gtk_list_set_selection_mode( GTK_LIST(m_list
), mode
);
288 #ifdef NEW_GTK_SCROLL_CODE
289 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget
), GTK_WIDGET(m_list
) );
291 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_list
) );
294 gtk_widget_show( GTK_WIDGET(m_list
) );
296 wxSize newSize
= size
;
297 if (newSize
.x
== -1) newSize
.x
= 100;
298 if (newSize
.y
== -1) newSize
.y
= 110;
299 SetSize( newSize
.x
, newSize
.y
);
301 for (int i
= 0; i
< n
; i
++)
303 m_clientDataList
.Append( (wxObject
*) NULL
);
304 m_clientObjectList
.Append( (wxObject
*) NULL
);
306 GtkWidget
*list_item
;
308 wxString
str(choices
[i
]);
309 #if wxUSE_CHECKLISTBOX
312 str
.Prepend(CHECKBOX_STRING
);
314 #endif // wxUSE_CHECKLISTBOX
316 list_item
= gtk_list_item_new_with_label( str
.mbc_str() );
318 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
320 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
321 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
323 if (style
& wxLB_MULTIPLE
)
324 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
325 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
327 gtk_signal_connect( GTK_OBJECT(list_item
),
328 "button_press_event",
329 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
332 gtk_signal_connect_after( GTK_OBJECT(list_item
),
333 "button_release_event",
334 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
337 #if wxUSE_CHECKLISTBOX
340 gtk_signal_connect( GTK_OBJECT(list_item
),
342 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
345 #endif // wxUSE_CHECKLISTBOX
347 ConnectWidget( list_item
);
349 gtk_widget_show( list_item
);
352 m_parent
->DoAddChild( this );
356 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW
) );
357 SetForegroundColour( parent
->GetForegroundColour() );
358 SetFont( parent
->GetFont() );
365 wxListBox::~wxListBox()
370 void wxListBox::InsertItems(int nItems
, const wxString items
[], int pos
)
372 wxCHECK_RET( m_list
!= NULL
, T("invalid listbox") );
374 GList
*children
= m_list
->children
;
375 int length
= g_list_length(children
);
376 wxCHECK_RET( pos
<= length
, T("invalid index in wxListBox::InsertItems") );
378 // VZ: it seems that GTK 1.0.6 doesn't has a function to insert an item
379 // into a listbox at the given position, this is why we first delete
380 // all items after this position, then append these items and then
381 // reappend back the old ones.
383 // first detach the old items
388 // no need to do anything complicated
389 for ( n
= 0; n
< nItems
; n
++ )
397 wxArrayString deletedLabels
;
398 wxArrayPtrVoid deletedData
;
399 wxArrayInt deletedChecks
; // only for check list boxes
401 GList
*child
= g_list_nth( children
, pos
);
402 for ( n
= 0; child
!= NULL
; n
++, child
= child
->next
)
405 GtkBin
*bin
= GTK_BIN( child
->data
);
406 GtkLabel
*label
= GTK_LABEL( bin
->child
);
408 wxString
str(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
409 deletedLabels
.Add(str
);
412 void *clientData
= NULL
;
415 if ( n
< (int)m_clientObjectList
.GetCount() )
416 node
= m_clientObjectList
.Nth( n
);
420 clientData
= node
->GetData();
421 m_clientObjectList
.DeleteNode( node
);
426 if ( n
< (int)m_clientDataList
.GetCount() )
427 node
= m_clientDataList
.Nth( n
);
431 clientData
= node
->GetData();
432 node
= m_clientDataList
.Nth( n
);
436 deletedData
.Add(clientData
);
438 #if wxUSE_CHECKLISTBOX
440 if ( m_hasCheckBoxes
)
442 deletedChecks
.Add(((wxCheckListBox
*)this)->IsChecked(pos
+ n
));
444 #endif // wxUSE_CHECKLISTBOX
447 int nDeletedCount
= n
;
449 gtk_list_clear_items( m_list
, pos
, length
);
451 // now append the new items
452 for ( n
= 0; n
< nItems
; n
++ )
457 // and append the old items too
458 pos
+= nItems
; // now the indices are shifter
459 for ( n
= 0; n
< nDeletedCount
; n
++ )
461 Append(deletedLabels
[n
], deletedData
[n
]);
463 #if wxUSE_CHECKLISTBOX
464 if ( m_hasCheckBoxes
)
466 ((wxCheckListBox
*)this)->Check(pos
+ n
, (bool)deletedChecks
[n
]);
468 #endif // wxUSE_CHECKLISTBOX
472 void wxListBox::AppendCommon( const wxString
&item
)
474 wxCHECK_RET( m_list
!= NULL
, T("invalid listbox") );
476 GtkWidget
*list_item
;
478 wxString
label(item
);
479 #if wxUSE_CHECKLISTBOX
482 label
.Prepend(CHECKBOX_STRING
);
484 #endif // wxUSE_CHECKLISTBOX
486 list_item
= gtk_list_item_new_with_label( label
.mbc_str() );
488 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
490 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
491 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
493 if (HasFlag(wxLB_MULTIPLE
))
494 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
495 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
497 gtk_signal_connect( GTK_OBJECT(list_item
),
498 "button_press_event",
499 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
502 gtk_signal_connect_after( GTK_OBJECT(list_item
),
503 "button_release_event",
504 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
507 #if wxUSE_CHECKLISTBOX
510 gtk_signal_connect( GTK_OBJECT(list_item
),
512 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
515 #endif // wxUSE_CHECKLISTBOX
517 gtk_widget_show( list_item
);
519 ConnectWidget( list_item
);
521 if (GTK_WIDGET_REALIZED(m_widget
))
523 gtk_widget_realize( list_item
);
524 gtk_widget_realize( GTK_BIN(list_item
)->child
);
526 //if (m_widgetStyle) ApplyWidgetStyle();
528 // Apply current widget style to the new list_item
529 gtk_widget_set_style( GTK_WIDGET( list_item
), m_widgetStyle
);
530 GtkBin
*bin
= GTK_BIN( list_item
);
531 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
532 gtk_widget_set_style( label
, m_widgetStyle
);
535 #if wxUSE_DRAG_AND_DROP
536 #ifndef NEW_GTK_DND_CODE
537 if (m_dropTarget
) m_dropTarget
->RegisterWidget( list_item
);
542 if (m_tooltip
) m_tooltip
->Apply( this );
547 void wxListBox::Append( const wxString
&item
)
549 m_clientDataList
.Append( (wxObject
*) NULL
);
550 m_clientObjectList
.Append( (wxObject
*) NULL
);
552 AppendCommon( item
);
555 void wxListBox::Append( const wxString
&item
, void *clientData
)
557 m_clientDataList
.Append( (wxObject
*) clientData
);
558 m_clientObjectList
.Append( (wxObject
*) NULL
);
560 AppendCommon( item
);
563 void wxListBox::Append( const wxString
&item
, wxClientData
*clientData
)
565 m_clientObjectList
.Append( (wxObject
*) clientData
);
566 m_clientDataList
.Append( (wxObject
*) NULL
);
568 AppendCommon( item
);
571 void wxListBox::SetClientData( int n
, void* clientData
)
573 wxCHECK_RET( m_widget
!= NULL
, T("invalid combobox") );
575 wxNode
*node
= m_clientDataList
.Nth( n
);
578 node
->SetData( (wxObject
*) clientData
);
581 void* wxListBox::GetClientData( int n
)
583 wxCHECK_MSG( m_widget
!= NULL
, NULL
, T("invalid combobox") );
585 wxNode
*node
= m_clientDataList
.Nth( n
);
586 if (!node
) return NULL
;
591 void wxListBox::SetClientObject( int n
, wxClientData
* clientData
)
593 wxCHECK_RET( m_widget
!= NULL
, T("invalid combobox") );
595 wxNode
*node
= m_clientObjectList
.Nth( n
);
598 wxClientData
*cd
= (wxClientData
*) node
->Data();
601 node
->SetData( (wxObject
*) clientData
);
604 wxClientData
* wxListBox::GetClientObject( int n
)
606 wxCHECK_MSG( m_widget
!= NULL
, (wxClientData
*)NULL
, T("invalid combobox") );
608 wxNode
*node
= m_clientObjectList
.Nth( n
);
609 if (!node
) return (wxClientData
*) NULL
;
611 return (wxClientData
*) node
->Data();
614 void wxListBox::Clear()
616 wxCHECK_RET( m_list
!= NULL
, T("invalid listbox") );
618 gtk_list_clear_items( m_list
, 0, Number() );
620 wxNode
*node
= m_clientObjectList
.First();
623 wxClientData
*cd
= (wxClientData
*)node
->Data();
627 m_clientObjectList
.Clear();
629 m_clientDataList
.Clear();
632 void wxListBox::Delete( int n
)
634 wxCHECK_RET( m_list
!= NULL
, T("invalid listbox") );
636 GList
*child
= g_list_nth( m_list
->children
, n
);
638 wxCHECK_RET( child
, T("wrong listbox index") );
640 GList
*list
= g_list_append( (GList
*) NULL
, child
->data
);
641 gtk_list_remove_items( m_list
, list
);
644 wxNode
*node
= m_clientObjectList
.Nth( n
);
647 wxClientData
*cd
= (wxClientData
*)node
->Data();
649 m_clientObjectList
.DeleteNode( node
);
652 node
= m_clientDataList
.Nth( n
);
655 m_clientDataList
.DeleteNode( node
);
659 void wxListBox::Deselect( int n
)
661 wxCHECK_RET( m_list
!= NULL
, T("invalid listbox") );
665 gtk_list_unselect_item( m_list
, n
);
670 int wxListBox::FindString( const wxString
&item
) const
672 wxCHECK_MSG( m_list
!= NULL
, -1, T("invalid listbox") );
674 GList
*child
= m_list
->children
;
678 GtkBin
*bin
= GTK_BIN( child
->data
);
679 GtkLabel
*label
= GTK_LABEL( bin
->child
);
681 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
690 // it's not an error if the string is not found -> no wxCHECK
695 int wxListBox::GetSelection() const
697 wxCHECK_MSG( m_list
!= NULL
, -1, T("invalid listbox") );
699 GList
*child
= m_list
->children
;
703 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
) return count
;
710 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
712 wxCHECK_MSG( m_list
!= NULL
, -1, T("invalid listbox") );
714 // get the number of selected items first
715 GList
*child
= m_list
->children
;
717 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
)
719 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
728 aSelections
.Alloc(count
); // optimization attempt
730 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
, i
++)
732 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
740 wxString
wxListBox::GetString( int n
) const
742 wxCHECK_MSG( m_list
!= NULL
, T(""), T("invalid listbox") );
744 GList
*child
= g_list_nth( m_list
->children
, n
);
747 GtkBin
*bin
= GTK_BIN( child
->data
);
748 GtkLabel
*label
= GTK_LABEL( bin
->child
);
750 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
755 wxFAIL_MSG(T("wrong listbox index"));
760 wxString
wxListBox::GetStringSelection() const
762 wxCHECK_MSG( m_list
!= NULL
, T(""), T("invalid listbox") );
764 GList
*selection
= m_list
->selection
;
767 GtkBin
*bin
= GTK_BIN( selection
->data
);
768 GtkLabel
*label
= GTK_LABEL( bin
->child
);
770 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
775 wxFAIL_MSG(T("no listbox selection available"));
779 int wxListBox::Number()
781 wxCHECK_MSG( m_list
!= NULL
, -1, T("invalid listbox") );
783 GList
*child
= m_list
->children
;
785 while (child
) { count
++; child
= child
->next
; }
789 bool wxListBox::Selected( int n
)
791 wxCHECK_MSG( m_list
!= NULL
, FALSE
, T("invalid listbox") );
793 GList
*target
= g_list_nth( m_list
->children
, n
);
796 GList
*child
= m_list
->selection
;
799 if (child
->data
== target
->data
) return TRUE
;
803 wxFAIL_MSG(T("wrong listbox index"));
807 void wxListBox::Set( int WXUNUSED(n
), const wxString
*WXUNUSED(choices
) )
809 wxFAIL_MSG(T("wxListBox::Set not implemented"));
812 void wxListBox::SetFirstItem( int WXUNUSED(n
) )
814 wxFAIL_MSG(T("wxListBox::SetFirstItem not implemented"));
817 void wxListBox::SetFirstItem( const wxString
&WXUNUSED(item
) )
819 wxFAIL_MSG(T("wxListBox::SetFirstItem not implemented"));
822 void wxListBox::SetSelection( int n
, bool select
)
824 wxCHECK_RET( m_list
!= NULL
, T("invalid listbox") );
829 gtk_list_select_item( m_list
, n
);
831 gtk_list_unselect_item( m_list
, n
);
836 void wxListBox::SetString( int n
, const wxString
&string
)
838 wxCHECK_RET( m_list
!= NULL
, T("invalid listbox") );
840 GList
*child
= g_list_nth( m_list
->children
, n
);
843 GtkBin
*bin
= GTK_BIN( child
->data
);
844 GtkLabel
*label
= GTK_LABEL( bin
->child
);
847 #if wxUSE_CHECKLISTBOX
849 str
+= CHECKBOX_STRING
;
850 #endif // wxUSE_CHECKLISTBOX
853 gtk_label_set( label
, str
.mbc_str() );
857 wxFAIL_MSG(T("wrong listbox index"));
861 void wxListBox::SetStringSelection( const wxString
&string
, bool select
)
863 wxCHECK_RET( m_list
!= NULL
, T("invalid listbox") );
865 SetSelection( FindString(string
), select
);
868 int wxListBox::GetIndex( GtkWidget
*item
) const
872 GList
*child
= m_list
->children
;
876 if (GTK_WIDGET(child
->data
) == item
) return count
;
885 void wxListBox::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
887 GList
*child
= m_list
->children
;
890 gtk_tooltips_set_tip( tips
, GTK_WIDGET( child
->data
), wxConvCurrent
->cWX2MB(tip
), (gchar
*) NULL
);
894 #endif // wxUSE_TOOLTIPS
896 #if wxUSE_DRAG_AND_DROP
897 void wxListBox::SetDropTarget( wxDropTarget
*dropTarget
)
899 wxCHECK_RET( m_list
!= NULL
, T("invalid listbox") );
901 #ifndef NEW_GTK_DND_CODE
904 GList
*child
= m_list
->children
;
907 m_dropTarget
->UnregisterWidget( GTK_WIDGET( child
->data
) );
913 wxWindow::SetDropTarget( dropTarget
);
915 #ifndef NEW_GTK_DND_CODE
918 GList
*child
= m_list
->children
;
921 m_dropTarget
->RegisterWidget( GTK_WIDGET( child
->data
) );
929 void wxListBox::DisableEvents()
931 GList
*child
= m_list
->children
;
934 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
935 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
937 if (HasFlag(wxLB_MULTIPLE
))
938 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
939 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
945 void wxListBox::EnableEvents()
947 GList
*child
= m_list
->children
;
950 gtk_signal_connect( GTK_OBJECT(child
->data
), "select",
951 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
953 if (HasFlag(wxLB_MULTIPLE
))
954 gtk_signal_connect( GTK_OBJECT(child
->data
), "deselect",
955 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
961 GtkWidget
*wxListBox::GetConnectWidget()
963 return GTK_WIDGET(m_list
);
966 bool wxListBox::IsOwnGtkWindow( GdkWindow
*window
)
968 if (wxWindow::IsOwnGtkWindow( window
)) return TRUE
;
970 GList
*child
= m_list
->children
;
973 GtkWidget
*bin
= GTK_WIDGET( child
->data
);
974 if (bin
->window
== window
) return TRUE
;
981 void wxListBox::ApplyWidgetStyle()
985 if (m_backgroundColour
.Ok())
987 GdkWindow
*window
= GTK_WIDGET(m_list
)->window
;
990 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
991 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
992 gdk_window_clear( window
);
996 GList
*child
= m_list
->children
;
999 gtk_widget_set_style( GTK_WIDGET(child
->data
), m_widgetStyle
);
1001 GtkBin
*bin
= GTK_BIN( child
->data
);
1002 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
1003 gtk_widget_set_style( label
, m_widgetStyle
);
1005 child
= child
->next
;
1009 void wxListBox::OnInternalIdle()
1011 wxCursor cursor
= m_cursor
;
1012 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
1014 if (GTK_WIDGET(m_list
)->window
&& cursor
.Ok())
1016 /* I now set the cursor the anew in every OnInternalIdle call
1017 as setting the cursor in a parent window also effects the
1018 windows above so that checking for the current cursor is
1021 gdk_window_set_cursor( GTK_WIDGET(m_list
)->window
, cursor
.GetCursor() );
1023 GList
*child
= m_list
->children
;
1026 GtkBin
*bin
= GTK_BIN( child
->data
);
1027 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
1032 gdk_window_set_cursor( label
->window
, cursor
.GetCursor() );
1034 child
= child
->next
;