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 n
, count
= listbox
->GetSelections(aSelections
);
222 event
.m_clientData
= listbox
->m_clientData
.Item(n
);
223 event
.m_commandString
= listbox
->GetString(n
);
230 event
.m_commandInt
= n
;
232 event
.SetEventObject( listbox
);
234 listbox
->GetEventHandler()->ProcessEvent( event
);
237 //-----------------------------------------------------------------------------
239 //-----------------------------------------------------------------------------
241 IMPLEMENT_DYNAMIC_CLASS(wxListBox
,wxControl
)
243 // ----------------------------------------------------------------------------
245 // ----------------------------------------------------------------------------
247 wxListBox::wxListBox()
249 m_list
= (GtkList
*) NULL
;
250 #if wxUSE_CHECKLISTBOX
251 m_hasCheckBoxes
= FALSE
;
252 #endif // wxUSE_CHECKLISTBOX
255 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
256 const wxPoint
&pos
, const wxSize
&size
,
257 int n
, const wxString choices
[],
258 long style
, const wxValidator
& validator
,
259 const wxString
&name
)
262 m_acceptsFocus
= TRUE
;
264 if (!PreCreation( parent
, pos
, size
) ||
265 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
267 wxFAIL_MSG( wxT("wxListBox creation failed") );
271 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
272 if (style
& wxLB_ALWAYS_SB
)
274 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
275 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
279 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
280 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
283 m_list
= GTK_LIST( gtk_list_new() );
285 GtkSelectionMode mode
= GTK_SELECTION_BROWSE
;
286 if (style
& wxLB_MULTIPLE
)
287 mode
= GTK_SELECTION_MULTIPLE
;
288 else if (style
& wxLB_EXTENDED
)
289 mode
= GTK_SELECTION_EXTENDED
;
291 gtk_list_set_selection_mode( GTK_LIST(m_list
), mode
);
293 #ifdef NEW_GTK_SCROLL_CODE
294 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget
), GTK_WIDGET(m_list
) );
296 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_list
) );
299 /* make list scroll when moving the focus down using cursor keys */
300 gtk_container_set_focus_vadjustment(
301 GTK_CONTAINER(m_list
),
302 gtk_scrolled_window_get_vadjustment(
303 GTK_SCROLLED_WINDOW(m_widget
)));
305 gtk_widget_show( GTK_WIDGET(m_list
) );
307 wxSize newSize
= size
;
308 if (newSize
.x
== -1) newSize
.x
= 100;
309 if (newSize
.y
== -1) newSize
.y
= 110;
310 SetSize( newSize
.x
, newSize
.y
);
312 if ( style
& wxLB_SORT
)
314 // this will change DoAppend() behaviour
315 m_strings
= new wxSortedArrayString
;
318 for (int i
= 0; i
< n
; i
++)
320 m_clientData
.Append((wxObject
*)NULL
);
322 DoAppend(choices
[i
]);
325 wxString
str(choices
[i
]);
327 #if wxUSE_CHECKLISTBOX
330 str
.Prepend(CHECKBOX_STRING
);
332 #endif // wxUSE_CHECKLISTBOX
334 GtkWidget
*list_item
= gtk_list_item_new_with_label( str
.mbc_str() );
336 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
338 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
339 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
341 if (style
& wxLB_MULTIPLE
)
342 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
343 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
345 gtk_signal_connect( GTK_OBJECT(list_item
),
346 "button_press_event",
347 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
350 gtk_signal_connect_after( GTK_OBJECT(list_item
),
351 "button_release_event",
352 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
355 #if wxUSE_CHECKLISTBOX
358 gtk_signal_connect( GTK_OBJECT(list_item
),
360 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
363 #endif // wxUSE_CHECKLISTBOX
365 ConnectWidget( list_item
);
367 gtk_widget_show( list_item
);
371 m_parent
->DoAddChild( this );
375 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW
) );
376 SetForegroundColour( parent
->GetForegroundColour() );
377 SetFont( parent
->GetFont() );
384 wxListBox::~wxListBox()
389 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
391 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
393 // code elsewhere supposes we have as many items in m_clientData as items
395 wxASSERT_MSG( m_clientData
.GetCount() == (size_t)GetCount(),
396 wxT("bug in client data management") );
398 GList
*children
= m_list
->children
;
399 int length
= g_list_length(children
);
400 wxCHECK_RET( pos
<= length
, wxT("invalid index in wxListBox::InsertItems") );
402 // VZ: it seems that GTK 1.0.6 doesn't has a function to insert an item
403 // into a listbox at the given position, this is why we first delete
404 // all items after this position, then append these items and then
405 // reappend back the old ones.
407 // VZ: notice that InsertItems knows nothing about sorting, so calling it
408 // from outside (and not from our own Append) is likely to break
411 size_t nItems
= items
.GetCount();
413 size_t n
; // loop var
415 // optimise for this trivial case
418 // no need to do anything complicated
419 for ( n
= 0; n
< nItems
; n
++ )
421 AppendWithoutSorting(items
[n
]);
423 m_clientData
.Append((wxObject
*)NULL
);
426 wxASSERT_MSG( m_clientData
.GetCount() == (size_t)GetCount(),
427 wxT("bug in client data management") );
432 // remove the old items
433 wxArrayString deletedLabels
;
434 wxArrayPtrVoid deletedData
;
435 #if wxUSE_CHECKLISTBOX
436 wxArrayInt deletedChecks
;
439 GList
*child
= g_list_nth( children
, pos
);
440 for ( n
= 0; child
!= NULL
; n
++, child
= child
->next
)
443 GtkBin
*bin
= GTK_BIN( child
->data
);
444 GtkLabel
*label
= GTK_LABEL( bin
->child
);
446 wxString
str(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
447 deletedLabels
.Add(str
);
450 deletedData
.Add(m_clientData
.Item(n
));
452 #if wxUSE_CHECKLISTBOX
454 if ( m_hasCheckBoxes
)
456 deletedChecks
.Add(((wxCheckListBox
*)this)->IsChecked(pos
+ n
));
458 #endif // wxUSE_CHECKLISTBOX
461 // don't delete contents, the data will be reappended soon
462 m_clientData
.Clear();
464 size_t nDeletedCount
= n
;
466 gtk_list_clear_items( m_list
, pos
, length
);
468 // now append the new items
469 for ( n
= 0; n
< nItems
; n
++ )
471 AppendWithoutSorting(items
[n
]);
473 m_clientData
.Append((wxObject
*)NULL
);
476 // and append the old items too
477 pos
+= nItems
; // now the indices are shifter
478 for ( n
= 0; n
< nDeletedCount
; n
++ )
480 AppendWithoutSorting(deletedLabels
[n
]);
482 m_clientData
.Append((wxObject
*)NULL
);
484 if ( m_clientDataItemsType
== ClientData_Object
)
485 SetClientObject(n
, (wxClientData
*)deletedData
[n
]);
486 else if ( m_clientDataItemsType
== ClientData_Void
)
487 SetClientData(n
, deletedData
[n
]);
489 #if wxUSE_CHECKLISTBOX
490 if ( m_hasCheckBoxes
)
492 ((wxCheckListBox
*)this)->Check(pos
+ n
, (bool)deletedChecks
[n
]);
494 #endif // wxUSE_CHECKLISTBOX
497 wxASSERT_MSG( m_clientData
.GetCount() == (size_t)GetCount(),
498 wxT("bug in client data management") );
501 int wxListBox::DoAppend( const wxString
& item
)
506 // need to determine the index
507 index
= m_strings
->Add(item
);
509 InsertItems(1, &item
, index
);
513 // not sorted, just append
514 AppendWithoutSorting(item
);
516 m_clientData
.Append((wxObject
*)NULL
);
518 index
= GetCount() - 1;
524 void wxListBox::AppendWithoutSorting( const wxString
&item
)
526 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
528 GtkWidget
*list_item
;
530 wxString
label(item
);
531 #if wxUSE_CHECKLISTBOX
534 label
.Prepend(CHECKBOX_STRING
);
536 #endif // wxUSE_CHECKLISTBOX
538 list_item
= gtk_list_item_new_with_label( label
.mbc_str() );
540 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
542 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
543 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
545 if (HasFlag(wxLB_MULTIPLE
))
546 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
547 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
549 gtk_signal_connect( GTK_OBJECT(list_item
),
550 "button_press_event",
551 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
554 gtk_signal_connect_after( GTK_OBJECT(list_item
),
555 "button_release_event",
556 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
559 #if wxUSE_CHECKLISTBOX
562 gtk_signal_connect( GTK_OBJECT(list_item
),
564 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
567 #endif // wxUSE_CHECKLISTBOX
569 gtk_widget_show( list_item
);
571 ConnectWidget( list_item
);
573 if (GTK_WIDGET_REALIZED(m_widget
))
575 gtk_widget_realize( list_item
);
576 gtk_widget_realize( GTK_BIN(list_item
)->child
);
578 //if (m_widgetStyle) ApplyWidgetStyle();
580 // Apply current widget style to the new list_item
581 gtk_widget_set_style( GTK_WIDGET( list_item
), m_widgetStyle
);
582 GtkBin
*bin
= GTK_BIN( list_item
);
583 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
584 gtk_widget_set_style( label
, m_widgetStyle
);
587 #if wxUSE_DRAG_AND_DROP
588 #ifndef NEW_GTK_DND_CODE
589 if (m_dropTarget
) m_dropTarget
->RegisterWidget( list_item
);
594 if (m_tooltip
) m_tooltip
->Apply( this );
599 void wxListBox::DoSetItems( const wxArrayString
& items
,
604 DoInsertItems(items
, 0);
608 size_t count
= items
.GetCount();
609 for ( size_t n
= 0; n
< count
; n
++ )
611 SetClientData(n
, clientData
[n
]);
616 // ----------------------------------------------------------------------------
618 // ----------------------------------------------------------------------------
620 void wxListBox::DoSetClientData( int n
, void* clientData
)
622 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid listbox control") );
624 wxNode
*node
= m_clientData
.Nth( n
);
625 wxCHECK_RET( node
, wxT("invalid index in wxListBox::DoSetClientData") );
627 node
->SetData( (wxObject
*) clientData
);
630 void* wxListBox::DoGetClientData( int n
) const
632 wxCHECK_MSG( m_widget
!= NULL
, NULL
, wxT("invalid listbox control") );
634 wxNode
*node
= m_clientData
.Nth( n
);
635 wxCHECK_MSG( node
, NULL
, wxT("invalid index in wxListBox::DoGetClientData") );
640 void wxListBox::DoSetClientObject( int n
, wxClientData
* clientData
)
642 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid listbox control") );
644 wxNode
*node
= m_clientData
.Nth( n
);
645 wxCHECK_RET( node
, wxT("invalid index in wxListBox::DoSetClientObject") );
647 wxClientData
*cd
= (wxClientData
*) node
->Data();
650 node
->SetData( (wxObject
*) clientData
);
653 wxClientData
* wxListBox::DoGetClientObject( int n
) const
655 wxCHECK_MSG( m_widget
!= NULL
, (wxClientData
*) NULL
, wxT("invalid listbox control") );
657 wxNode
*node
= m_clientData
.Nth( n
);
658 wxCHECK_MSG( node
, (wxClientData
*)NULL
,
659 wxT("invalid index in wxListBox::DoGetClientObject") );
661 return (wxClientData
*) node
->Data();
664 void wxListBox::Clear()
666 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
668 gtk_list_clear_items( m_list
, 0, Number() );
670 if ( m_clientDataItemsType
== ClientData_Object
)
671 m_clientData
.DeleteContents(TRUE
);
672 m_clientData
.Clear();
678 void wxListBox::Delete( int n
)
680 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
682 GList
*child
= g_list_nth( m_list
->children
, n
);
684 wxCHECK_RET( child
, wxT("wrong listbox index") );
686 GList
*list
= g_list_append( (GList
*) NULL
, child
->data
);
687 gtk_list_remove_items( m_list
, list
);
690 wxNode
*node
= m_clientData
.Nth( n
);
693 if ( m_clientDataItemsType
== ClientData_Object
)
695 wxClientData
*cd
= (wxClientData
*)node
->Data();
699 m_clientData
.DeleteNode( node
);
703 m_strings
->Remove(n
);
706 // ----------------------------------------------------------------------------
707 // string list access
708 // ----------------------------------------------------------------------------
710 void wxListBox::SetString( int n
, const wxString
&string
)
712 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
714 GList
*child
= g_list_nth( m_list
->children
, n
);
717 GtkBin
*bin
= GTK_BIN( child
->data
);
718 GtkLabel
*label
= GTK_LABEL( bin
->child
);
721 #if wxUSE_CHECKLISTBOX
723 str
+= CHECKBOX_STRING
;
724 #endif // wxUSE_CHECKLISTBOX
727 gtk_label_set( label
, str
.mbc_str() );
731 wxFAIL_MSG(wxT("wrong listbox index"));
735 wxString
wxListBox::GetString( int n
) const
737 wxCHECK_MSG( m_list
!= NULL
, wxT(""), wxT("invalid listbox") );
739 GList
*child
= g_list_nth( m_list
->children
, n
);
742 GtkBin
*bin
= GTK_BIN( child
->data
);
743 GtkLabel
*label
= GTK_LABEL( bin
->child
);
745 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
750 wxFAIL_MSG(wxT("wrong listbox index"));
755 int wxListBox::GetCount() const
757 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
759 GList
*child
= m_list
->children
;
770 int wxListBox::FindString( const wxString
&item
) const
772 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
774 GList
*child
= m_list
->children
;
778 GtkBin
*bin
= GTK_BIN( child
->data
);
779 GtkLabel
*label
= GTK_LABEL( bin
->child
);
781 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
790 // it's not an error if the string is not found -> no wxCHECK
795 // ----------------------------------------------------------------------------
797 // ----------------------------------------------------------------------------
799 int wxListBox::GetSelection() const
801 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
803 GList
*child
= m_list
->children
;
807 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
) return count
;
814 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
816 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
818 // get the number of selected items first
819 GList
*child
= m_list
->children
;
821 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
)
823 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
832 aSelections
.Alloc(count
); // optimization attempt
834 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
, i
++)
836 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
844 bool wxListBox::IsSelected( int n
) const
846 wxCHECK_MSG( m_list
!= NULL
, FALSE
, wxT("invalid listbox") );
848 GList
*target
= g_list_nth( m_list
->children
, n
);
851 GList
*child
= m_list
->selection
;
854 if (child
->data
== target
->data
) return TRUE
;
859 wxFAIL_MSG(wxT("wrong listbox index"));
864 void wxListBox::SetSelection( int n
, bool select
)
866 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
871 gtk_list_select_item( m_list
, n
);
873 gtk_list_unselect_item( m_list
, n
);
878 void wxListBox::DoSetFirstItem( int WXUNUSED(n
) )
880 wxFAIL_MSG(wxT("wxListBox::SetFirstItem not implemented"));
883 // ----------------------------------------------------------------------------
885 // ----------------------------------------------------------------------------
887 int wxListBox::GetIndex( GtkWidget
*item
) const
891 GList
*child
= m_list
->children
;
895 if (GTK_WIDGET(child
->data
) == item
) return count
;
904 void wxListBox::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
906 GList
*child
= m_list
->children
;
909 gtk_tooltips_set_tip( tips
, GTK_WIDGET( child
->data
), wxConvCurrent
->cWX2MB(tip
), (gchar
*) NULL
);
913 #endif // wxUSE_TOOLTIPS
915 #if wxUSE_DRAG_AND_DROP
916 void wxListBox::SetDropTarget( wxDropTarget
*dropTarget
)
918 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
920 #ifndef NEW_GTK_DND_CODE
923 GList
*child
= m_list
->children
;
926 m_dropTarget
->UnregisterWidget( GTK_WIDGET( child
->data
) );
932 wxWindow::SetDropTarget( dropTarget
);
934 #ifndef NEW_GTK_DND_CODE
937 GList
*child
= m_list
->children
;
940 m_dropTarget
->RegisterWidget( GTK_WIDGET( child
->data
) );
948 void wxListBox::DisableEvents()
950 GList
*child
= m_list
->children
;
953 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
954 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
956 if (HasFlag(wxLB_MULTIPLE
))
957 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
958 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
964 void wxListBox::EnableEvents()
966 GList
*child
= m_list
->children
;
969 gtk_signal_connect( GTK_OBJECT(child
->data
), "select",
970 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
972 if (HasFlag(wxLB_MULTIPLE
))
973 gtk_signal_connect( GTK_OBJECT(child
->data
), "deselect",
974 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
980 GtkWidget
*wxListBox::GetConnectWidget()
982 return GTK_WIDGET(m_list
);
985 bool wxListBox::IsOwnGtkWindow( GdkWindow
*window
)
987 if (wxWindow::IsOwnGtkWindow( window
)) return TRUE
;
989 GList
*child
= m_list
->children
;
992 GtkWidget
*bin
= GTK_WIDGET( child
->data
);
993 if (bin
->window
== window
) return TRUE
;
1000 void wxListBox::ApplyWidgetStyle()
1004 if (m_backgroundColour
.Ok())
1006 GdkWindow
*window
= GTK_WIDGET(m_list
)->window
;
1009 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
1010 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
1011 gdk_window_clear( window
);
1015 GList
*child
= m_list
->children
;
1018 gtk_widget_set_style( GTK_WIDGET(child
->data
), m_widgetStyle
);
1020 GtkBin
*bin
= GTK_BIN( child
->data
);
1021 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
1022 gtk_widget_set_style( label
, m_widgetStyle
);
1024 child
= child
->next
;
1028 void wxListBox::OnInternalIdle()
1030 wxCursor cursor
= m_cursor
;
1031 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
1033 if (GTK_WIDGET(m_list
)->window
&& cursor
.Ok())
1035 /* I now set the cursor the anew in every OnInternalIdle call
1036 as setting the cursor in a parent window also effects the
1037 windows above so that checking for the current cursor is
1040 gdk_window_set_cursor( GTK_WIDGET(m_list
)->window
, cursor
.GetCursor() );
1042 GList
*child
= m_list
->children
;
1045 GtkBin
*bin
= GTK_BIN( child
->data
);
1046 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
1051 gdk_window_set_cursor( label
->window
, cursor
.GetCursor() );
1053 child
= child
->next
;