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( wxT("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 /* make list scroll when moving the focus down using cursor keys */
295 gtk_container_set_focus_vadjustment(
296 GTK_CONTAINER(m_list
),
297 gtk_scrolled_window_get_vadjustment(
298 GTK_SCROLLED_WINDOW(m_widget
)));
300 gtk_widget_show( GTK_WIDGET(m_list
) );
302 wxSize newSize
= size
;
303 if (newSize
.x
== -1) newSize
.x
= 100;
304 if (newSize
.y
== -1) newSize
.y
= 110;
305 SetSize( newSize
.x
, newSize
.y
);
307 for (int i
= 0; i
< n
; i
++)
309 m_clientDataList
.Append( (wxObject
*) NULL
);
310 m_clientObjectList
.Append( (wxObject
*) NULL
);
312 GtkWidget
*list_item
;
314 wxString
str(choices
[i
]);
315 #if wxUSE_CHECKLISTBOX
318 str
.Prepend(CHECKBOX_STRING
);
320 #endif // wxUSE_CHECKLISTBOX
322 list_item
= gtk_list_item_new_with_label( str
.mbc_str() );
324 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
326 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
327 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
329 if (style
& wxLB_MULTIPLE
)
330 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
331 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
333 gtk_signal_connect( GTK_OBJECT(list_item
),
334 "button_press_event",
335 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
338 gtk_signal_connect_after( GTK_OBJECT(list_item
),
339 "button_release_event",
340 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
343 #if wxUSE_CHECKLISTBOX
346 gtk_signal_connect( GTK_OBJECT(list_item
),
348 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
351 #endif // wxUSE_CHECKLISTBOX
353 ConnectWidget( list_item
);
355 gtk_widget_show( list_item
);
358 m_parent
->DoAddChild( this );
362 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW
) );
363 SetForegroundColour( parent
->GetForegroundColour() );
364 SetFont( parent
->GetFont() );
371 wxListBox::~wxListBox()
376 void wxListBox::InsertItems(int nItems
, const wxString items
[], int pos
)
378 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
380 GList
*children
= m_list
->children
;
381 int length
= g_list_length(children
);
382 wxCHECK_RET( pos
<= length
, wxT("invalid index in wxListBox::InsertItems") );
384 // VZ: it seems that GTK 1.0.6 doesn't has a function to insert an item
385 // into a listbox at the given position, this is why we first delete
386 // all items after this position, then append these items and then
387 // reappend back the old ones.
389 // first detach the old items
394 // no need to do anything complicated
395 for ( n
= 0; n
< nItems
; n
++ )
403 wxArrayString deletedLabels
;
404 wxArrayPtrVoid deletedData
;
405 wxArrayInt deletedChecks
; // only for check list boxes
407 GList
*child
= g_list_nth( children
, pos
);
408 for ( n
= 0; child
!= NULL
; n
++, child
= child
->next
)
411 GtkBin
*bin
= GTK_BIN( child
->data
);
412 GtkLabel
*label
= GTK_LABEL( bin
->child
);
414 wxString
str(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
415 deletedLabels
.Add(str
);
418 void *clientData
= NULL
;
421 if ( n
< (int)m_clientObjectList
.GetCount() )
422 node
= m_clientObjectList
.Nth( n
);
426 clientData
= node
->GetData();
427 m_clientObjectList
.DeleteNode( node
);
432 if ( n
< (int)m_clientDataList
.GetCount() )
433 node
= m_clientDataList
.Nth( n
);
437 clientData
= node
->GetData();
438 node
= m_clientDataList
.Nth( n
);
442 deletedData
.Add(clientData
);
444 #if wxUSE_CHECKLISTBOX
446 if ( m_hasCheckBoxes
)
448 deletedChecks
.Add(((wxCheckListBox
*)this)->IsChecked(pos
+ n
));
450 #endif // wxUSE_CHECKLISTBOX
453 int nDeletedCount
= n
;
455 gtk_list_clear_items( m_list
, pos
, length
);
457 // now append the new items
458 for ( n
= 0; n
< nItems
; n
++ )
463 // and append the old items too
464 pos
+= nItems
; // now the indices are shifter
465 for ( n
= 0; n
< nDeletedCount
; n
++ )
467 Append(deletedLabels
[n
], deletedData
[n
]);
469 #if wxUSE_CHECKLISTBOX
470 if ( m_hasCheckBoxes
)
472 ((wxCheckListBox
*)this)->Check(pos
+ n
, (bool)deletedChecks
[n
]);
474 #endif // wxUSE_CHECKLISTBOX
478 void wxListBox::AppendCommon( const wxString
&item
)
480 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
482 GtkWidget
*list_item
;
484 wxString
label(item
);
485 #if wxUSE_CHECKLISTBOX
488 label
.Prepend(CHECKBOX_STRING
);
490 #endif // wxUSE_CHECKLISTBOX
492 list_item
= gtk_list_item_new_with_label( label
.mbc_str() );
494 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
496 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
497 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
499 if (HasFlag(wxLB_MULTIPLE
))
500 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
501 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
503 gtk_signal_connect( GTK_OBJECT(list_item
),
504 "button_press_event",
505 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
508 gtk_signal_connect_after( GTK_OBJECT(list_item
),
509 "button_release_event",
510 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
513 #if wxUSE_CHECKLISTBOX
516 gtk_signal_connect( GTK_OBJECT(list_item
),
518 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
521 #endif // wxUSE_CHECKLISTBOX
523 gtk_widget_show( list_item
);
525 ConnectWidget( list_item
);
527 if (GTK_WIDGET_REALIZED(m_widget
))
529 gtk_widget_realize( list_item
);
530 gtk_widget_realize( GTK_BIN(list_item
)->child
);
532 //if (m_widgetStyle) ApplyWidgetStyle();
534 // Apply current widget style to the new list_item
535 gtk_widget_set_style( GTK_WIDGET( list_item
), m_widgetStyle
);
536 GtkBin
*bin
= GTK_BIN( list_item
);
537 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
538 gtk_widget_set_style( label
, m_widgetStyle
);
541 #if wxUSE_DRAG_AND_DROP
542 #ifndef NEW_GTK_DND_CODE
543 if (m_dropTarget
) m_dropTarget
->RegisterWidget( list_item
);
548 if (m_tooltip
) m_tooltip
->Apply( this );
553 void wxListBox::Append( const wxString
&item
)
555 m_clientDataList
.Append( (wxObject
*) NULL
);
556 m_clientObjectList
.Append( (wxObject
*) NULL
);
558 AppendCommon( item
);
561 void wxListBox::Append( const wxString
&item
, void *clientData
)
563 m_clientDataList
.Append( (wxObject
*) clientData
);
564 m_clientObjectList
.Append( (wxObject
*) NULL
);
566 AppendCommon( item
);
569 void wxListBox::Append( const wxString
&item
, wxClientData
*clientData
)
571 m_clientObjectList
.Append( (wxObject
*) clientData
);
572 m_clientDataList
.Append( (wxObject
*) NULL
);
574 AppendCommon( item
);
577 void wxListBox::SetClientData( int n
, void* clientData
)
579 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid combobox") );
581 wxNode
*node
= m_clientDataList
.Nth( n
);
584 node
->SetData( (wxObject
*) clientData
);
587 void* wxListBox::GetClientData( int n
)
589 wxCHECK_MSG( m_widget
!= NULL
, NULL
, wxT("invalid combobox") );
591 wxNode
*node
= m_clientDataList
.Nth( n
);
592 if (!node
) return NULL
;
597 void wxListBox::SetClientObject( int n
, wxClientData
* clientData
)
599 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid combobox") );
601 wxNode
*node
= m_clientObjectList
.Nth( n
);
604 wxClientData
*cd
= (wxClientData
*) node
->Data();
607 node
->SetData( (wxObject
*) clientData
);
610 wxClientData
* wxListBox::GetClientObject( int n
)
612 wxCHECK_MSG( m_widget
!= NULL
, (wxClientData
*)NULL
, wxT("invalid combobox") );
614 wxNode
*node
= m_clientObjectList
.Nth( n
);
615 if (!node
) return (wxClientData
*) NULL
;
617 return (wxClientData
*) node
->Data();
620 void wxListBox::Clear()
622 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
624 gtk_list_clear_items( m_list
, 0, Number() );
626 wxNode
*node
= m_clientObjectList
.First();
629 wxClientData
*cd
= (wxClientData
*)node
->Data();
633 m_clientObjectList
.Clear();
635 m_clientDataList
.Clear();
638 void wxListBox::Delete( int n
)
640 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
642 GList
*child
= g_list_nth( m_list
->children
, n
);
644 wxCHECK_RET( child
, wxT("wrong listbox index") );
646 GList
*list
= g_list_append( (GList
*) NULL
, child
->data
);
647 gtk_list_remove_items( m_list
, list
);
650 wxNode
*node
= m_clientObjectList
.Nth( n
);
653 wxClientData
*cd
= (wxClientData
*)node
->Data();
655 m_clientObjectList
.DeleteNode( node
);
658 node
= m_clientDataList
.Nth( n
);
661 m_clientDataList
.DeleteNode( node
);
665 void wxListBox::Deselect( int n
)
667 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
671 gtk_list_unselect_item( m_list
, n
);
676 int wxListBox::FindString( const wxString
&item
) const
678 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
680 GList
*child
= m_list
->children
;
684 GtkBin
*bin
= GTK_BIN( child
->data
);
685 GtkLabel
*label
= GTK_LABEL( bin
->child
);
687 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
696 // it's not an error if the string is not found -> no wxCHECK
701 int wxListBox::GetSelection() const
703 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
705 GList
*child
= m_list
->children
;
709 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
) return count
;
716 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
718 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
720 // get the number of selected items first
721 GList
*child
= m_list
->children
;
723 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
)
725 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
734 aSelections
.Alloc(count
); // optimization attempt
736 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
, i
++)
738 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
746 wxString
wxListBox::GetString( int n
) const
748 wxCHECK_MSG( m_list
!= NULL
, wxT(""), wxT("invalid listbox") );
750 GList
*child
= g_list_nth( m_list
->children
, n
);
753 GtkBin
*bin
= GTK_BIN( child
->data
);
754 GtkLabel
*label
= GTK_LABEL( bin
->child
);
756 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
761 wxFAIL_MSG(wxT("wrong listbox index"));
766 wxString
wxListBox::GetStringSelection() const
768 wxCHECK_MSG( m_list
!= NULL
, wxT(""), wxT("invalid listbox") );
770 GList
*selection
= m_list
->selection
;
773 GtkBin
*bin
= GTK_BIN( selection
->data
);
774 GtkLabel
*label
= GTK_LABEL( bin
->child
);
776 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
781 wxFAIL_MSG(wxT("no listbox selection available"));
785 int wxListBox::Number()
787 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
789 GList
*child
= m_list
->children
;
791 while (child
) { count
++; child
= child
->next
; }
795 bool wxListBox::Selected( int n
)
797 wxCHECK_MSG( m_list
!= NULL
, FALSE
, wxT("invalid listbox") );
799 GList
*target
= g_list_nth( m_list
->children
, n
);
802 GList
*child
= m_list
->selection
;
805 if (child
->data
== target
->data
) return TRUE
;
809 wxFAIL_MSG(wxT("wrong listbox index"));
813 void wxListBox::Set( int WXUNUSED(n
), const wxString
*WXUNUSED(choices
) )
815 wxFAIL_MSG(wxT("wxListBox::Set not implemented"));
818 void wxListBox::SetFirstItem( int WXUNUSED(n
) )
820 wxFAIL_MSG(wxT("wxListBox::SetFirstItem not implemented"));
823 void wxListBox::SetFirstItem( const wxString
&WXUNUSED(item
) )
825 wxFAIL_MSG(wxT("wxListBox::SetFirstItem not implemented"));
828 void wxListBox::SetSelection( int n
, bool select
)
830 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
835 gtk_list_select_item( m_list
, n
);
837 gtk_list_unselect_item( m_list
, n
);
842 void wxListBox::SetString( int n
, const wxString
&string
)
844 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
846 GList
*child
= g_list_nth( m_list
->children
, n
);
849 GtkBin
*bin
= GTK_BIN( child
->data
);
850 GtkLabel
*label
= GTK_LABEL( bin
->child
);
853 #if wxUSE_CHECKLISTBOX
855 str
+= CHECKBOX_STRING
;
856 #endif // wxUSE_CHECKLISTBOX
859 gtk_label_set( label
, str
.mbc_str() );
863 wxFAIL_MSG(wxT("wrong listbox index"));
867 void wxListBox::SetStringSelection( const wxString
&string
, bool select
)
869 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
871 SetSelection( FindString(string
), select
);
874 int wxListBox::GetIndex( GtkWidget
*item
) const
878 GList
*child
= m_list
->children
;
882 if (GTK_WIDGET(child
->data
) == item
) return count
;
891 void wxListBox::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
893 GList
*child
= m_list
->children
;
896 gtk_tooltips_set_tip( tips
, GTK_WIDGET( child
->data
), wxConvCurrent
->cWX2MB(tip
), (gchar
*) NULL
);
900 #endif // wxUSE_TOOLTIPS
902 #if wxUSE_DRAG_AND_DROP
903 void wxListBox::SetDropTarget( wxDropTarget
*dropTarget
)
905 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
907 #ifndef NEW_GTK_DND_CODE
910 GList
*child
= m_list
->children
;
913 m_dropTarget
->UnregisterWidget( GTK_WIDGET( child
->data
) );
919 wxWindow::SetDropTarget( dropTarget
);
921 #ifndef NEW_GTK_DND_CODE
924 GList
*child
= m_list
->children
;
927 m_dropTarget
->RegisterWidget( GTK_WIDGET( child
->data
) );
935 void wxListBox::DisableEvents()
937 GList
*child
= m_list
->children
;
940 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
941 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
943 if (HasFlag(wxLB_MULTIPLE
))
944 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
945 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
951 void wxListBox::EnableEvents()
953 GList
*child
= m_list
->children
;
956 gtk_signal_connect( GTK_OBJECT(child
->data
), "select",
957 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
959 if (HasFlag(wxLB_MULTIPLE
))
960 gtk_signal_connect( GTK_OBJECT(child
->data
), "deselect",
961 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
967 GtkWidget
*wxListBox::GetConnectWidget()
969 return GTK_WIDGET(m_list
);
972 bool wxListBox::IsOwnGtkWindow( GdkWindow
*window
)
974 if (wxWindow::IsOwnGtkWindow( window
)) return TRUE
;
976 GList
*child
= m_list
->children
;
979 GtkWidget
*bin
= GTK_WIDGET( child
->data
);
980 if (bin
->window
== window
) return TRUE
;
987 void wxListBox::ApplyWidgetStyle()
991 if (m_backgroundColour
.Ok())
993 GdkWindow
*window
= GTK_WIDGET(m_list
)->window
;
996 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
997 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
998 gdk_window_clear( window
);
1002 GList
*child
= m_list
->children
;
1005 gtk_widget_set_style( GTK_WIDGET(child
->data
), m_widgetStyle
);
1007 GtkBin
*bin
= GTK_BIN( child
->data
);
1008 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
1009 gtk_widget_set_style( label
, m_widgetStyle
);
1011 child
= child
->next
;
1015 void wxListBox::OnInternalIdle()
1017 wxCursor cursor
= m_cursor
;
1018 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
1020 if (GTK_WIDGET(m_list
)->window
&& cursor
.Ok())
1022 /* I now set the cursor the anew in every OnInternalIdle call
1023 as setting the cursor in a parent window also effects the
1024 windows above so that checking for the current cursor is
1027 gdk_window_set_cursor( GTK_WIDGET(m_list
)->window
, cursor
.GetCursor() );
1029 GList
*child
= m_list
->children
;
1032 GtkBin
*bin
= GTK_BIN( child
->data
);
1033 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
1038 gdk_window_set_cursor( label
->window
, cursor
.GetCursor() );
1040 child
= child
->next
;