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
*widget
, GdkEventButton
*gdk_event
, wxListBox
*listbox
)
93 if (g_isIdle
) wxapp_install_idle_handler();
95 if (g_blockEventsOnDrag
) return FALSE
;
96 if (g_blockEventsOnScroll
) return FALSE
;
98 if (!listbox
->m_hasVMT
) return FALSE
;
100 if (!g_hasDoubleClicked
) return FALSE
;
102 wxCommandEvent
event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, listbox
->GetId() );
103 event
.SetEventObject( listbox
);
105 wxArrayInt aSelections
;
106 int count
= listbox
->GetSelections(aSelections
);
109 event
.m_commandInt
= aSelections
[0] ;
110 event
.m_clientData
= listbox
->GetClientData( event
.m_commandInt
);
111 wxString
str(listbox
->GetString(event
.m_commandInt
));
112 if (!str
.IsEmpty()) event
.m_commandString
= str
;
116 event
.m_commandInt
= -1 ;
117 event
.m_commandString
.Empty();
120 listbox
->GetEventHandler()->ProcessEvent( event
);
125 //-----------------------------------------------------------------------------
126 // "button_press_event"
127 //-----------------------------------------------------------------------------
130 gtk_listbox_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxListBox
*listbox
)
132 if (g_isIdle
) wxapp_install_idle_handler();
134 if (g_blockEventsOnDrag
) return FALSE
;
135 if (g_blockEventsOnScroll
) return FALSE
;
137 if (!listbox
->m_hasVMT
) return FALSE
;
139 int sel
= listbox
->GetIndex( widget
);
141 #if wxUSE_CHECKLISTBOX
142 if ((listbox
->m_hasCheckBoxes
) && (gdk_event
->x
< 15) && (gdk_event
->type
!= GDK_2BUTTON_PRESS
))
144 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
146 clb
->Check( sel
, !clb
->IsChecked(sel
) );
148 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
149 event
.SetEventObject( listbox
);
151 listbox
->GetEventHandler()->ProcessEvent( event
);
153 #endif // wxUSE_CHECKLISTBOX
155 /* emit wxEVT_COMMAND_LISTBOX_DOUBLECLICKED later */
156 g_hasDoubleClicked
= (gdk_event
->type
== GDK_2BUTTON_PRESS
);
161 //-----------------------------------------------------------------------------
163 //-----------------------------------------------------------------------------
165 #if wxUSE_CHECKLISTBOX
167 gtk_listbox_key_press_callback( GtkWidget
*widget
, GdkEventKey
*gdk_event
, wxListBox
*listbox
)
169 if (g_isIdle
) wxapp_install_idle_handler();
171 if (g_blockEventsOnDrag
) return FALSE
;
173 if (!listbox
->m_hasVMT
) return FALSE
;
175 if (gdk_event
->keyval
!= ' ') return FALSE
;
177 int sel
= listbox
->GetIndex( widget
);
179 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
181 clb
->Check( sel
, !clb
->IsChecked(sel
) );
183 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
184 event
.SetEventObject( listbox
);
186 listbox
->GetEventHandler()->ProcessEvent( event
);
190 #endif // wxUSE_CHECKLISTBOX
192 //-----------------------------------------------------------------------------
193 // "select" and "deselect"
194 //-----------------------------------------------------------------------------
196 static void gtk_listitem_select_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
);
198 static void gtk_listitem_deselect_callback( GtkWidget
*widget
, wxListBox
*listbox
)
200 gtk_listitem_select_callback( widget
, listbox
);
203 static void gtk_listitem_select_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
)
205 if (g_isIdle
) wxapp_install_idle_handler();
207 if (!listbox
->m_hasVMT
) return;
208 if (g_blockEventsOnDrag
) return;
210 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, listbox
->GetId() );
212 wxArrayInt aSelections
;
213 int count
= listbox
->GetSelections(aSelections
);
216 event
.m_commandInt
= aSelections
[0] ;
217 event
.m_clientData
= listbox
->GetClientData( event
.m_commandInt
);
218 wxString
str(listbox
->GetString(event
.m_commandInt
));
219 if (!str
.IsEmpty()) event
.m_commandString
= str
;
223 event
.m_commandInt
= -1 ;
224 event
.m_commandString
.Empty();
227 event
.SetEventObject( listbox
);
229 listbox
->GetEventHandler()->ProcessEvent( event
);
232 //-----------------------------------------------------------------------------
234 //-----------------------------------------------------------------------------
236 IMPLEMENT_DYNAMIC_CLASS(wxListBox
,wxControl
)
238 wxListBox::wxListBox()
240 m_list
= (GtkList
*) NULL
;
241 #if wxUSE_CHECKLISTBOX
242 m_hasCheckBoxes
= FALSE
;
243 #endif // wxUSE_CHECKLISTBOX
246 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
247 const wxPoint
&pos
, const wxSize
&size
,
248 int n
, const wxString choices
[],
249 long style
, const wxValidator
& validator
, const wxString
&name
)
252 m_acceptsFocus
= TRUE
;
254 if (!PreCreation( parent
, pos
, size
) ||
255 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
257 wxFAIL_MSG( _T("wxListBox creation failed") );
261 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
262 if (style
& wxLB_ALWAYS_SB
)
264 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
265 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
269 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
270 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
273 m_list
= GTK_LIST( gtk_list_new() );
275 GtkSelectionMode mode
= GTK_SELECTION_BROWSE
;
276 if (style
& wxLB_MULTIPLE
)
277 mode
= GTK_SELECTION_MULTIPLE
;
278 else if (style
& wxLB_EXTENDED
)
279 mode
= GTK_SELECTION_EXTENDED
;
281 gtk_list_set_selection_mode( GTK_LIST(m_list
), mode
);
283 #ifdef NEW_GTK_SCROLL_CODE
284 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget
), GTK_WIDGET(m_list
) );
286 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_list
) );
289 gtk_widget_show( GTK_WIDGET(m_list
) );
291 wxSize newSize
= size
;
292 if (newSize
.x
== -1) newSize
.x
= 100;
293 if (newSize
.y
== -1) newSize
.y
= 110;
294 SetSize( newSize
.x
, newSize
.y
);
296 for (int i
= 0; i
< n
; i
++)
298 m_clientDataList
.Append( (wxObject
*) NULL
);
299 m_clientObjectList
.Append( (wxObject
*) NULL
);
301 GtkWidget
*list_item
;
303 wxString
str(choices
[i
]);
304 #if wxUSE_CHECKLISTBOX
307 str
.Prepend(CHECKBOX_STRING
);
309 #endif // wxUSE_CHECKLISTBOX
311 list_item
= gtk_list_item_new_with_label( str
.mbc_str() );
313 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
315 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
316 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
318 if (style
& wxLB_MULTIPLE
)
319 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
320 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
322 gtk_signal_connect( GTK_OBJECT(list_item
),
323 "button_press_event",
324 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
327 gtk_signal_connect_after( GTK_OBJECT(list_item
),
328 "button_release_event",
329 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
332 #if wxUSE_CHECKLISTBOX
335 gtk_signal_connect( GTK_OBJECT(list_item
),
337 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
340 #endif // wxUSE_CHECKLISTBOX
342 ConnectWidget( list_item
);
344 gtk_widget_show( list_item
);
347 m_parent
->DoAddChild( this );
351 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW
) );
352 SetForegroundColour( parent
->GetForegroundColour() );
353 SetFont( parent
->GetFont() );
360 wxListBox::~wxListBox()
365 void wxListBox::InsertItems(int nItems
, const wxString items
[], int pos
)
367 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
369 GList
*children
= m_list
->children
;
370 int length
= g_list_length(children
);
371 wxCHECK_RET( pos
<= length
, _T("invalid index in wxListBox::InsertItems") );
373 // VZ: it seems that GTK 1.0.6 doesn't has a function to insert an item
374 // into a listbox at the given position, this is why we first delete
375 // all items after this position, then append these items and then
376 // reappend back the old ones.
378 // first detach the old items
383 // no need to do anything complicated
384 for ( n
= 0; n
< nItems
; n
++ )
392 wxArrayString deletedLabels
;
393 wxArrayPtrVoid deletedData
;
394 wxArrayInt deletedChecks
; // only for check list boxes
396 GList
*child
= g_list_nth( children
, pos
);
397 for ( n
= 0; child
!= NULL
; n
++, child
= child
->next
)
400 GtkBin
*bin
= GTK_BIN( child
->data
);
401 GtkLabel
*label
= GTK_LABEL( bin
->child
);
403 wxString
str(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
404 deletedLabels
.Add(str
);
407 void *clientData
= NULL
;
410 if ( n
< (int)m_clientObjectList
.GetCount() )
411 node
= m_clientObjectList
.Nth( n
);
415 clientData
= node
->GetData();
416 m_clientObjectList
.DeleteNode( node
);
421 if ( n
< (int)m_clientDataList
.GetCount() )
422 node
= m_clientDataList
.Nth( n
);
426 clientData
= node
->GetData();
427 node
= m_clientDataList
.Nth( n
);
431 deletedData
.Add(clientData
);
433 #if wxUSE_CHECKLISTBOX
435 if ( m_hasCheckBoxes
)
437 deletedChecks
.Add(((wxCheckListBox
*)this)->IsChecked(pos
+ n
));
439 #endif // wxUSE_CHECKLISTBOX
442 int nDeletedCount
= n
;
444 gtk_list_clear_items( m_list
, pos
, length
);
446 // now append the new items
447 for ( n
= 0; n
< nItems
; n
++ )
452 // and append the old items too
453 pos
+= nItems
; // now the indices are shifter
454 for ( n
= 0; n
< nDeletedCount
; n
++ )
456 Append(deletedLabels
[n
], deletedData
[n
]);
458 #if wxUSE_CHECKLISTBOX
459 if ( m_hasCheckBoxes
)
461 ((wxCheckListBox
*)this)->Check(pos
+ n
, (bool)deletedChecks
[n
]);
463 #endif // wxUSE_CHECKLISTBOX
467 void wxListBox::AppendCommon( const wxString
&item
)
469 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
471 GtkWidget
*list_item
;
473 wxString
label(item
);
474 #if wxUSE_CHECKLISTBOX
477 label
.Prepend(CHECKBOX_STRING
);
479 #endif // wxUSE_CHECKLISTBOX
481 list_item
= gtk_list_item_new_with_label( label
.mbc_str() );
483 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
485 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
486 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
488 if (HasFlag(wxLB_MULTIPLE
))
489 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
490 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
492 gtk_signal_connect( GTK_OBJECT(list_item
),
493 "button_press_event",
494 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
497 gtk_signal_connect_after( GTK_OBJECT(list_item
),
498 "button_release_event",
499 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
502 #if wxUSE_CHECKLISTBOX
505 gtk_signal_connect( GTK_OBJECT(list_item
),
507 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
510 #endif // wxUSE_CHECKLISTBOX
512 gtk_widget_show( list_item
);
514 ConnectWidget( list_item
);
516 if (GTK_WIDGET_REALIZED(m_widget
))
518 gtk_widget_realize( list_item
);
519 gtk_widget_realize( GTK_BIN(list_item
)->child
);
521 if (m_widgetStyle
) ApplyWidgetStyle();
523 #if wxUSE_DRAG_AND_DROP
524 #ifndef NEW_GTK_DND_CODE
525 if (m_dropTarget
) m_dropTarget
->RegisterWidget( list_item
);
530 if (m_tooltip
) m_tooltip
->Apply( this );
535 void wxListBox::Append( const wxString
&item
)
537 m_clientDataList
.Append( (wxObject
*) NULL
);
538 m_clientObjectList
.Append( (wxObject
*) NULL
);
540 AppendCommon( item
);
543 void wxListBox::Append( const wxString
&item
, void *clientData
)
545 m_clientDataList
.Append( (wxObject
*) clientData
);
546 m_clientObjectList
.Append( (wxObject
*) NULL
);
548 AppendCommon( item
);
551 void wxListBox::Append( const wxString
&item
, wxClientData
*clientData
)
553 m_clientObjectList
.Append( (wxObject
*) clientData
);
554 m_clientDataList
.Append( (wxObject
*) NULL
);
556 AppendCommon( item
);
559 void wxListBox::SetClientData( int n
, void* clientData
)
561 wxCHECK_RET( m_widget
!= NULL
, _T("invalid combobox") );
563 wxNode
*node
= m_clientDataList
.Nth( n
);
566 node
->SetData( (wxObject
*) clientData
);
569 void* wxListBox::GetClientData( int n
)
571 wxCHECK_MSG( m_widget
!= NULL
, NULL
, _T("invalid combobox") );
573 wxNode
*node
= m_clientDataList
.Nth( n
);
574 if (!node
) return NULL
;
579 void wxListBox::SetClientObject( int n
, wxClientData
* clientData
)
581 wxCHECK_RET( m_widget
!= NULL
, _T("invalid combobox") );
583 wxNode
*node
= m_clientObjectList
.Nth( n
);
586 wxClientData
*cd
= (wxClientData
*) node
->Data();
589 node
->SetData( (wxObject
*) clientData
);
592 wxClientData
* wxListBox::GetClientObject( int n
)
594 wxCHECK_MSG( m_widget
!= NULL
, (wxClientData
*)NULL
, _T("invalid combobox") );
596 wxNode
*node
= m_clientObjectList
.Nth( n
);
597 if (!node
) return (wxClientData
*) NULL
;
599 return (wxClientData
*) node
->Data();
602 void wxListBox::Clear()
604 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
606 gtk_list_clear_items( m_list
, 0, Number() );
608 wxNode
*node
= m_clientObjectList
.First();
611 wxClientData
*cd
= (wxClientData
*)node
->Data();
615 m_clientObjectList
.Clear();
617 m_clientDataList
.Clear();
620 void wxListBox::Delete( int n
)
622 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
624 GList
*child
= g_list_nth( m_list
->children
, n
);
626 wxCHECK_RET( child
, _T("wrong listbox index") );
628 GList
*list
= g_list_append( (GList
*) NULL
, child
->data
);
629 gtk_list_remove_items( m_list
, list
);
632 wxNode
*node
= m_clientObjectList
.Nth( n
);
635 wxClientData
*cd
= (wxClientData
*)node
->Data();
637 m_clientObjectList
.DeleteNode( node
);
640 node
= m_clientDataList
.Nth( n
);
643 m_clientDataList
.DeleteNode( node
);
647 void wxListBox::Deselect( int n
)
649 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
653 gtk_list_unselect_item( m_list
, n
);
658 int wxListBox::FindString( const wxString
&item
) const
660 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
662 GList
*child
= m_list
->children
;
666 GtkBin
*bin
= GTK_BIN( child
->data
);
667 GtkLabel
*label
= GTK_LABEL( bin
->child
);
669 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
678 // it's not an error if the string is not found -> no wxCHECK
683 int wxListBox::GetSelection() const
685 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
687 GList
*child
= m_list
->children
;
691 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
) return count
;
698 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
700 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
702 // get the number of selected items first
703 GList
*child
= m_list
->children
;
705 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
)
707 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
716 aSelections
.Alloc(count
); // optimization attempt
718 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
, i
++)
720 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
728 wxString
wxListBox::GetString( int n
) const
730 wxCHECK_MSG( m_list
!= NULL
, _T(""), _T("invalid listbox") );
732 GList
*child
= g_list_nth( m_list
->children
, n
);
735 GtkBin
*bin
= GTK_BIN( child
->data
);
736 GtkLabel
*label
= GTK_LABEL( bin
->child
);
738 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
743 wxFAIL_MSG(_T("wrong listbox index"));
748 wxString
wxListBox::GetStringSelection() const
750 wxCHECK_MSG( m_list
!= NULL
, _T(""), _T("invalid listbox") );
752 GList
*selection
= m_list
->selection
;
755 GtkBin
*bin
= GTK_BIN( selection
->data
);
756 GtkLabel
*label
= GTK_LABEL( bin
->child
);
758 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
763 wxFAIL_MSG(_T("no listbox selection available"));
767 int wxListBox::Number()
769 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
771 GList
*child
= m_list
->children
;
773 while (child
) { count
++; child
= child
->next
; }
777 bool wxListBox::Selected( int n
)
779 wxCHECK_MSG( m_list
!= NULL
, FALSE
, _T("invalid listbox") );
781 GList
*target
= g_list_nth( m_list
->children
, n
);
784 GList
*child
= m_list
->selection
;
787 if (child
->data
== target
->data
) return TRUE
;
791 wxFAIL_MSG(_T("wrong listbox index"));
795 void wxListBox::Set( int WXUNUSED(n
), const wxString
*WXUNUSED(choices
) )
797 wxFAIL_MSG(_T("wxListBox::Set not implemented"));
800 void wxListBox::SetFirstItem( int WXUNUSED(n
) )
802 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
805 void wxListBox::SetFirstItem( const wxString
&WXUNUSED(item
) )
807 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
810 void wxListBox::SetSelection( int n
, bool select
)
812 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
817 gtk_list_select_item( m_list
, n
);
819 gtk_list_unselect_item( m_list
, n
);
824 void wxListBox::SetString( int n
, const wxString
&string
)
826 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
828 GList
*child
= g_list_nth( m_list
->children
, n
);
831 GtkBin
*bin
= GTK_BIN( child
->data
);
832 GtkLabel
*label
= GTK_LABEL( bin
->child
);
835 #if wxUSE_CHECKLISTBOX
837 str
+= CHECKBOX_STRING
;
838 #endif // wxUSE_CHECKLISTBOX
841 gtk_label_set( label
, str
.mbc_str() );
845 wxFAIL_MSG(_T("wrong listbox index"));
849 void wxListBox::SetStringSelection( const wxString
&string
, bool select
)
851 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
853 SetSelection( FindString(string
), select
);
856 int wxListBox::GetIndex( GtkWidget
*item
) const
860 GList
*child
= m_list
->children
;
864 if (GTK_WIDGET(child
->data
) == item
) return count
;
873 void wxListBox::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
875 GList
*child
= m_list
->children
;
878 gtk_tooltips_set_tip( tips
, GTK_WIDGET( child
->data
), wxConvCurrent
->cWX2MB(tip
), (gchar
*) NULL
);
882 #endif // wxUSE_TOOLTIPS
884 #if wxUSE_DRAG_AND_DROP
885 void wxListBox::SetDropTarget( wxDropTarget
*dropTarget
)
887 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
889 #ifndef NEW_GTK_DND_CODE
892 GList
*child
= m_list
->children
;
895 m_dropTarget
->UnregisterWidget( GTK_WIDGET( child
->data
) );
901 wxWindow::SetDropTarget( dropTarget
);
903 #ifndef NEW_GTK_DND_CODE
906 GList
*child
= m_list
->children
;
909 m_dropTarget
->RegisterWidget( GTK_WIDGET( child
->data
) );
917 void wxListBox::DisableEvents()
919 GList
*child
= m_list
->children
;
922 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
923 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
925 if (HasFlag(wxLB_MULTIPLE
))
926 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
927 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
933 void wxListBox::EnableEvents()
935 GList
*child
= m_list
->children
;
938 gtk_signal_connect( GTK_OBJECT(child
->data
), "select",
939 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
941 if (HasFlag(wxLB_MULTIPLE
))
942 gtk_signal_connect( GTK_OBJECT(child
->data
), "deselect",
943 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
949 GtkWidget
*wxListBox::GetConnectWidget()
951 return GTK_WIDGET(m_list
);
954 bool wxListBox::IsOwnGtkWindow( GdkWindow
*window
)
956 if (wxWindow::IsOwnGtkWindow( window
)) return TRUE
;
958 GList
*child
= m_list
->children
;
961 GtkWidget
*bin
= GTK_WIDGET( child
->data
);
962 if (bin
->window
== window
) return TRUE
;
969 void wxListBox::ApplyWidgetStyle()
973 if (m_backgroundColour
.Ok())
975 GdkWindow
*window
= GTK_WIDGET(m_list
)->window
;
978 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
979 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
980 gdk_window_clear( window
);
984 GList
*child
= m_list
->children
;
987 gtk_widget_set_style( GTK_WIDGET(child
->data
), m_widgetStyle
);
989 GtkBin
*bin
= GTK_BIN( child
->data
);
990 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
991 gtk_widget_set_style( label
, m_widgetStyle
);