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"
31 #include <gdk/gdkkeysyms.h>
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 extern void wxapp_install_idle_handler();
40 //-------------------------------------------------------------------------
41 // conditional compilation
42 //-------------------------------------------------------------------------
44 #if (GTK_MINOR_VERSION > 0)
45 #define NEW_GTK_SCROLL_CODE
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 #if wxUSE_CHECKLISTBOX
54 #define CHECKBOX_STRING "[-] "
56 // checklistboxes have "[±] " prepended to their lables, this macro removes it
57 // (NB: 4 below is the length of CHECKBOX_STRING above)
59 // the argument to it is a "const char *" pointer
60 #define GET_REAL_LABEL(label) ((m_hasCheckBoxes)?(label)+4 : (label))
62 #else // !wxUSE_CHECKLISTBOX
64 #define GET_REAL_LABEL(label) (label)
66 #endif // wxUSE_CHECKLISTBOX
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
72 extern bool g_blockEventsOnDrag
;
73 extern bool g_blockEventsOnScroll
;
74 extern wxCursor g_globalCursor
;
76 static bool g_hasDoubleClicked
= FALSE
;
78 //-----------------------------------------------------------------------------
79 // idle callback for SetFirstItem
80 //-----------------------------------------------------------------------------
82 struct wxlistbox_idle_struct
89 static gint
wxlistbox_idle_callback( gpointer gdata
)
91 wxlistbox_idle_struct
* data
= (wxlistbox_idle_struct
*) gdata
;
94 gtk_idle_remove( data
->m_tag
);
96 data
->m_listbox
->SetFirstItem( data
->m_item
);
105 //-----------------------------------------------------------------------------
106 // "button_release_event"
107 //-----------------------------------------------------------------------------
109 /* we would normally emit a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event once
110 a GDK_2BUTTON_PRESS occurs, but this has the particular problem of the
111 listbox keeping the focus until it receives a GDK_BUTTON_RELEASE event.
112 this can lead to race conditions so that we emit the dclick event
113 after the GDK_BUTTON_RELEASE event after the GDK_2BUTTON_PRESS event */
116 gtk_listbox_button_release_callback( GtkWidget
* WXUNUSED(widget
),
117 GdkEventButton
* WXUNUSED(gdk_event
),
120 if (g_isIdle
) wxapp_install_idle_handler();
122 if (g_blockEventsOnDrag
) return FALSE
;
123 if (g_blockEventsOnScroll
) return FALSE
;
125 if (!listbox
->m_hasVMT
) return FALSE
;
127 if (!g_hasDoubleClicked
) return FALSE
;
129 wxCommandEvent
event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, listbox
->GetId() );
130 event
.SetEventObject( listbox
);
132 wxArrayInt aSelections
;
133 int n
, count
= listbox
->GetSelections(aSelections
);
137 if ( listbox
->HasClientObjectData() )
138 event
.SetClientObject( listbox
->GetClientObject(n
) );
139 else if ( listbox
->HasClientUntypedData() )
140 event
.SetClientData( listbox
->GetClientData(n
) );
141 event
.SetString( listbox
->GetString(n
) );
148 event
.m_commandInt
= n
;
150 listbox
->GetEventHandler()->ProcessEvent( event
);
155 //-----------------------------------------------------------------------------
156 // "button_press_event"
157 //-----------------------------------------------------------------------------
160 gtk_listbox_button_press_callback( GtkWidget
*widget
,
161 GdkEventButton
*gdk_event
,
164 if (g_isIdle
) wxapp_install_idle_handler();
166 if (g_blockEventsOnDrag
) return FALSE
;
167 if (g_blockEventsOnScroll
) return FALSE
;
169 if (!listbox
->m_hasVMT
) return FALSE
;
171 int sel
= listbox
->GtkGetIndex( widget
);
173 #if wxUSE_CHECKLISTBOX
174 if ((listbox
->m_hasCheckBoxes
) && (gdk_event
->x
< 15) && (gdk_event
->type
!= GDK_2BUTTON_PRESS
))
176 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
178 clb
->Check( sel
, !clb
->IsChecked(sel
) );
180 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
181 event
.SetEventObject( listbox
);
183 listbox
->GetEventHandler()->ProcessEvent( event
);
185 #endif // wxUSE_CHECKLISTBOX
187 /* emit wxEVT_COMMAND_LISTBOX_DOUBLECLICKED later */
188 g_hasDoubleClicked
= (gdk_event
->type
== GDK_2BUTTON_PRESS
);
193 //-----------------------------------------------------------------------------
195 //-----------------------------------------------------------------------------
198 gtk_listbox_key_press_callback( GtkWidget
*widget
, GdkEventKey
*gdk_event
, wxListBox
*listbox
)
201 wxapp_install_idle_handler();
203 if (g_blockEventsOnDrag
)
208 if ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
))
210 wxNavigationKeyEvent new_event
;
211 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
212 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
213 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
214 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
215 new_event
.SetCurrentFocus( listbox
);
216 ret
= listbox
->GetEventHandler()->ProcessEvent( new_event
);
219 if ((gdk_event
->keyval
== GDK_Return
) && (!ret
))
221 // eat return in all modes
225 #if wxUSE_CHECKLISTBOX
226 if ((gdk_event
->keyval
== ' ') && (listbox
->m_hasCheckBoxes
) && (!ret
))
228 int sel
= listbox
->GtkGetIndex( widget
);
230 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
232 clb
->Check( sel
, !clb
->IsChecked(sel
) );
234 wxCommandEvent
new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
235 new_event
.SetEventObject( listbox
);
236 new_event
.SetInt( sel
);
237 ret
= listbox
->GetEventHandler()->ProcessEvent( new_event
);
239 #endif // wxUSE_CHECKLISTBOX
243 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
250 //-----------------------------------------------------------------------------
251 // "select" and "deselect"
252 //-----------------------------------------------------------------------------
254 static void gtk_listitem_select_cb( GtkWidget
*widget
, wxListBox
*listbox
, bool is_selection
);
256 static void gtk_listitem_select_callback( GtkWidget
*widget
, wxListBox
*listbox
)
258 gtk_listitem_select_cb( widget
, listbox
, TRUE
);
261 static void gtk_listitem_deselect_callback( GtkWidget
*widget
, wxListBox
*listbox
)
263 gtk_listitem_select_cb( widget
, listbox
, FALSE
);
266 static void gtk_listitem_select_cb( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
, bool is_selection
)
268 if (g_isIdle
) wxapp_install_idle_handler();
270 if (!listbox
->m_hasVMT
) return;
271 if (g_blockEventsOnDrag
) return;
273 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, listbox
->GetId() );
274 event
.SetEventObject( listbox
);
275 event
.SetExtraLong( (long) is_selection
);
277 wxArrayInt aSelections
;
278 int n
, count
= listbox
->GetSelections(aSelections
);
282 if ( listbox
->HasClientObjectData() )
283 event
.SetClientObject( listbox
->GetClientObject(n
) );
284 else if ( listbox
->HasClientUntypedData() )
285 event
.SetClientData( listbox
->GetClientData(n
) );
286 event
.SetString( listbox
->GetString(n
) );
293 event
.m_commandInt
= n
;
295 listbox
->GetEventHandler()->AddPendingEvent( event
);
296 // listbox->GetEventHandler()->ProcessEvent( event );
299 //-----------------------------------------------------------------------------
301 //-----------------------------------------------------------------------------
303 IMPLEMENT_DYNAMIC_CLASS(wxListBox
,wxControl
)
305 // ----------------------------------------------------------------------------
307 // ----------------------------------------------------------------------------
309 wxListBox::wxListBox()
311 m_list
= (GtkList
*) NULL
;
312 #if wxUSE_CHECKLISTBOX
313 m_hasCheckBoxes
= FALSE
;
314 #endif // wxUSE_CHECKLISTBOX
317 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
318 const wxPoint
&pos
, const wxSize
&size
,
319 int n
, const wxString choices
[],
320 long style
, const wxValidator
& validator
,
321 const wxString
&name
)
324 m_acceptsFocus
= TRUE
;
326 if (!PreCreation( parent
, pos
, size
) ||
327 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
329 wxFAIL_MSG( wxT("wxListBox creation failed") );
333 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
334 if (style
& wxLB_ALWAYS_SB
)
336 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
337 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
341 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
342 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
345 m_list
= GTK_LIST( gtk_list_new() );
347 GtkSelectionMode mode
;
348 if (style
& wxLB_MULTIPLE
)
350 mode
= GTK_SELECTION_MULTIPLE
;
352 else if (style
& wxLB_EXTENDED
)
354 mode
= GTK_SELECTION_EXTENDED
;
358 // if style was 0 set single mode
359 m_windowStyle
|= wxLB_SINGLE
;
360 mode
= GTK_SELECTION_BROWSE
;
363 gtk_list_set_selection_mode( GTK_LIST(m_list
), mode
);
365 #ifdef NEW_GTK_SCROLL_CODE
366 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget
), GTK_WIDGET(m_list
) );
368 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_list
) );
371 /* make list scroll when moving the focus down using cursor keys */
372 gtk_container_set_focus_vadjustment(
373 GTK_CONTAINER(m_list
),
374 gtk_scrolled_window_get_vadjustment(
375 GTK_SCROLLED_WINDOW(m_widget
)));
377 gtk_widget_show( GTK_WIDGET(m_list
) );
379 SetSizeOrDefault( size
);
381 if ( style
& wxLB_SORT
)
383 // this will change DoAppend() behaviour
384 m_strings
= new wxSortedArrayString
;
388 m_strings
= (wxSortedArrayString
*)NULL
;
391 for (int i
= 0; i
< n
; i
++)
394 DoAppend(choices
[i
]);
397 m_parent
->DoAddChild( this );
401 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
402 SetForegroundColour( parent
->GetForegroundColour() );
403 SetFont( parent
->GetFont() );
410 wxListBox::~wxListBox()
420 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
422 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
424 // VZ: notice that InsertItems knows nothing about sorting, so calling it
425 // from outside (and not from our own Append) is likely to break
428 // code elsewhere supposes we have as many items in m_clientList as items
430 wxASSERT_MSG( m_clientList
.GetCount() == (size_t)GetCount(),
431 wxT("bug in client data management") );
433 GList
*children
= m_list
->children
;
434 int length
= g_list_length(children
);
436 wxCHECK_RET( pos
<= length
, wxT("invalid index in wxListBox::InsertItems") );
438 size_t nItems
= items
.GetCount();
443 for (size_t n
= 0; n
< nItems
; n
++)
445 index
= m_strings
->Add( items
[n
] );
447 if (index
!= GetCount())
449 GtkAddItem( items
[n
], index
);
450 wxNode
*node
= m_clientList
.Nth( index
);
451 m_clientList
.Insert( node
, (wxObject
*) NULL
);
455 GtkAddItem( items
[n
] );
456 m_clientList
.Append( (wxObject
*) NULL
);
464 for ( size_t n
= 0; n
< nItems
; n
++ )
466 GtkAddItem( items
[n
] );
468 m_clientList
.Append((wxObject
*)NULL
);
473 wxNode
*node
= m_clientList
.Nth( pos
);
474 for ( size_t n
= 0; n
< nItems
; n
++ )
476 GtkAddItem( items
[n
], pos
+n
);
478 m_clientList
.Insert( node
, (wxObject
*)NULL
);
483 wxASSERT_MSG( m_clientList
.GetCount() == (size_t)GetCount(),
484 wxT("bug in client data management") );
487 int wxListBox::DoAppend( const wxString
& item
)
491 // need to determine the index
492 int index
= m_strings
->Add( item
);
494 // only if not at the end anyway
495 if (index
!= GetCount())
497 GtkAddItem( item
, index
);
499 wxNode
*node
= m_clientList
.Nth( index
);
500 m_clientList
.Insert( node
, (wxObject
*)NULL
);
508 m_clientList
.Append((wxObject
*)NULL
);
510 return GetCount() - 1;
513 void wxListBox::GtkAddItem( const wxString
&item
, int pos
)
515 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
517 GtkWidget
*list_item
;
519 wxString
label(item
);
520 #if wxUSE_CHECKLISTBOX
523 label
.Prepend(CHECKBOX_STRING
);
525 #endif // wxUSE_CHECKLISTBOX
527 list_item
= gtk_list_item_new_with_label( label
.mbc_str() );
529 GList
*gitem_list
= g_list_alloc ();
530 gitem_list
->data
= list_item
;
533 gtk_list_append_items( GTK_LIST (m_list
), gitem_list
);
535 gtk_list_insert_items( GTK_LIST (m_list
), gitem_list
, pos
);
537 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
538 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
540 if (HasFlag(wxLB_MULTIPLE
))
541 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
542 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
544 gtk_signal_connect( GTK_OBJECT(list_item
),
545 "button_press_event",
546 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
549 gtk_signal_connect_after( GTK_OBJECT(list_item
),
550 "button_release_event",
551 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
554 gtk_signal_connect( GTK_OBJECT(list_item
),
556 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
559 ConnectWidget( list_item
);
561 gtk_widget_show( list_item
);
563 if (GTK_WIDGET_REALIZED(m_widget
))
565 gtk_widget_realize( list_item
);
566 gtk_widget_realize( GTK_BIN(list_item
)->child
);
568 // Apply current widget style to the new list_item
571 gtk_widget_set_style( GTK_WIDGET( list_item
), m_widgetStyle
);
572 GtkBin
*bin
= GTK_BIN( list_item
);
573 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
574 gtk_widget_set_style( label
, m_widgetStyle
);
578 if (m_tooltip
) m_tooltip
->Apply( this );
583 void wxListBox::DoSetItems( const wxArrayString
& items
,
588 DoInsertItems(items
, 0);
592 size_t count
= items
.GetCount();
593 for ( size_t n
= 0; n
< count
; n
++ )
595 SetClientData(n
, clientData
[n
]);
600 // ----------------------------------------------------------------------------
602 // ----------------------------------------------------------------------------
604 void wxListBox::DoSetItemClientData( int n
, void* clientData
)
606 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid listbox control") );
608 wxNode
*node
= m_clientList
.Nth( n
);
609 wxCHECK_RET( node
, wxT("invalid index in wxListBox::DoSetItemClientData") );
611 node
->SetData( (wxObject
*) clientData
);
614 void* wxListBox::DoGetItemClientData( int n
) const
616 wxCHECK_MSG( m_widget
!= NULL
, NULL
, wxT("invalid listbox control") );
618 wxNode
*node
= m_clientList
.Nth( n
);
619 wxCHECK_MSG( node
, NULL
, wxT("invalid index in wxListBox::DoGetItemClientData") );
624 void wxListBox::DoSetItemClientObject( int n
, wxClientData
* clientData
)
626 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid listbox control") );
628 wxNode
*node
= m_clientList
.Nth( n
);
629 wxCHECK_RET( node
, wxT("invalid index in wxListBox::DoSetItemClientObject") );
631 wxClientData
*cd
= (wxClientData
*) node
->Data();
634 node
->SetData( (wxObject
*) clientData
);
637 wxClientData
* wxListBox::DoGetItemClientObject( int n
) const
639 wxCHECK_MSG( m_widget
!= NULL
, (wxClientData
*) NULL
, wxT("invalid listbox control") );
641 wxNode
*node
= m_clientList
.Nth( n
);
642 wxCHECK_MSG( node
, (wxClientData
*)NULL
,
643 wxT("invalid index in wxListBox::DoGetItemClientObject") );
645 return (wxClientData
*) node
->Data();
648 void wxListBox::Clear()
650 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
652 gtk_list_clear_items( m_list
, 0, Number() );
654 if ( HasClientObjectData() )
656 // destroy the data (due to Robert's idea of using wxList<wxObject>
657 // and not wxList<wxClientData> we can't just say
658 // m_clientList.DeleteContents(TRUE) - this would crash!
659 wxNode
*node
= m_clientList
.First();
662 delete (wxClientData
*)node
->Data();
666 m_clientList
.Clear();
672 void wxListBox::Delete( int n
)
674 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
676 GList
*child
= g_list_nth( m_list
->children
, n
);
678 wxCHECK_RET( child
, wxT("wrong listbox index") );
680 GList
*list
= g_list_append( (GList
*) NULL
, child
->data
);
681 gtk_list_remove_items( m_list
, list
);
684 wxNode
*node
= m_clientList
.Nth( n
);
687 if ( m_clientDataItemsType
== ClientData_Object
)
689 wxClientData
*cd
= (wxClientData
*)node
->Data();
693 m_clientList
.DeleteNode( node
);
697 m_strings
->Remove(n
);
700 // ----------------------------------------------------------------------------
701 // string list access
702 // ----------------------------------------------------------------------------
704 void wxListBox::SetString( int n
, const wxString
&string
)
706 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
708 GList
*child
= g_list_nth( m_list
->children
, n
);
711 GtkBin
*bin
= GTK_BIN( child
->data
);
712 GtkLabel
*label
= GTK_LABEL( bin
->child
);
715 #if wxUSE_CHECKLISTBOX
717 str
+= CHECKBOX_STRING
;
718 #endif // wxUSE_CHECKLISTBOX
721 gtk_label_set( label
, str
.mbc_str() );
725 wxFAIL_MSG(wxT("wrong listbox index"));
729 wxString
wxListBox::GetString( int n
) const
731 wxCHECK_MSG( m_list
!= NULL
, wxT(""), wxT("invalid listbox") );
733 GList
*child
= g_list_nth( m_list
->children
, n
);
736 GtkBin
*bin
= GTK_BIN( child
->data
);
737 GtkLabel
*label
= GTK_LABEL( bin
->child
);
739 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
744 wxFAIL_MSG(wxT("wrong listbox index"));
749 int wxListBox::GetCount() const
751 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
753 GList
*children
= m_list
->children
;
754 return g_list_length(children
);
757 int wxListBox::FindString( const wxString
&item
) const
759 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
761 GList
*child
= m_list
->children
;
765 GtkBin
*bin
= GTK_BIN( child
->data
);
766 GtkLabel
*label
= GTK_LABEL( bin
->child
);
768 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
777 // it's not an error if the string is not found -> no wxCHECK
782 // ----------------------------------------------------------------------------
784 // ----------------------------------------------------------------------------
786 int wxListBox::GetSelection() const
788 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
790 GList
*child
= m_list
->children
;
794 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
) return count
;
801 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
803 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
805 // get the number of selected items first
806 GList
*child
= m_list
->children
;
808 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
)
810 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
819 aSelections
.Alloc(count
); // optimization attempt
821 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
, i
++)
823 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
831 bool wxListBox::IsSelected( int n
) const
833 wxCHECK_MSG( m_list
!= NULL
, FALSE
, wxT("invalid listbox") );
835 GList
*target
= g_list_nth( m_list
->children
, n
);
837 wxCHECK_MSG( target
, FALSE
, wxT("invalid listbox index") );
839 return (GTK_WIDGET(target
->data
)->state
== GTK_STATE_SELECTED
) ;
842 void wxListBox::SetSelection( int n
, bool select
)
844 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
849 gtk_list_select_item( m_list
, n
);
851 gtk_list_unselect_item( m_list
, n
);
856 void wxListBox::DoSetFirstItem( int n
)
858 wxCHECK_RET( m_list
, wxT("invalid listbox") );
860 if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_list
))
863 // terribly efficient
864 const gchar
*vadjustment_key
= "gtk-vadjustment";
865 guint vadjustment_key_id
= g_quark_from_static_string (vadjustment_key
);
867 GtkAdjustment
*adjustment
=
868 (GtkAdjustment
*) gtk_object_get_data_by_id (GTK_OBJECT (m_list
), vadjustment_key_id
);
869 wxCHECK_RET( adjustment
, wxT("invalid listbox code") );
871 GList
*target
= g_list_nth( m_list
->children
, n
);
872 wxCHECK_RET( target
, wxT("invalid listbox index") );
874 GtkWidget
*item
= GTK_WIDGET(target
->data
);
875 wxCHECK_RET( item
, wxT("invalid listbox code") );
877 if (item
->allocation
.y
== -1)
879 wxlistbox_idle_struct
* data
= new wxlistbox_idle_struct
;
880 data
->m_listbox
= this;
882 data
->m_tag
= gtk_idle_add_priority( 800, wxlistbox_idle_callback
, (gpointer
) data
);
887 float y
= item
->allocation
.y
;
888 if (y
> adjustment
->upper
- adjustment
->page_size
)
889 y
= adjustment
->upper
- adjustment
->page_size
;
890 gtk_adjustment_set_value( adjustment
, y
);
893 // ----------------------------------------------------------------------------
895 // ----------------------------------------------------------------------------
897 int wxListBox::GtkGetIndex( GtkWidget
*item
) const
901 GList
*child
= m_list
->children
;
905 if (GTK_WIDGET(child
->data
) == item
) return count
;
914 void wxListBox::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
916 GList
*child
= m_list
->children
;
919 gtk_tooltips_set_tip( tips
, GTK_WIDGET( child
->data
), wxConvCurrent
->cWX2MB(tip
), (gchar
*) NULL
);
923 #endif // wxUSE_TOOLTIPS
925 void wxListBox::GtkDisableEvents()
927 GList
*child
= m_list
->children
;
930 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
931 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
933 if (HasFlag(wxLB_MULTIPLE
))
934 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
935 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
941 void wxListBox::GtkEnableEvents()
943 GList
*child
= m_list
->children
;
946 gtk_signal_connect( GTK_OBJECT(child
->data
), "select",
947 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
949 if (HasFlag(wxLB_MULTIPLE
))
950 gtk_signal_connect( GTK_OBJECT(child
->data
), "deselect",
951 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
957 GtkWidget
*wxListBox::GetConnectWidget()
959 return GTK_WIDGET(m_list
);
962 bool wxListBox::IsOwnGtkWindow( GdkWindow
*window
)
964 if (GTK_WIDGET(m_list
)->window
== window
) return TRUE
;
966 GList
*child
= m_list
->children
;
969 GtkWidget
*bin
= GTK_WIDGET( child
->data
);
970 if (bin
->window
== window
) return TRUE
;
977 void wxListBox::ApplyWidgetStyle()
981 if (m_backgroundColour
.Ok())
983 GdkWindow
*window
= GTK_WIDGET(m_list
)->window
;
986 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
987 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
988 gdk_window_clear( window
);
992 GList
*child
= m_list
->children
;
995 gtk_widget_set_style( GTK_WIDGET(child
->data
), m_widgetStyle
);
997 GtkBin
*bin
= GTK_BIN( child
->data
);
998 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
999 gtk_widget_set_style( label
, m_widgetStyle
);
1001 child
= child
->next
;
1005 void wxListBox::OnInternalIdle()
1007 wxCursor cursor
= m_cursor
;
1008 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
1010 if (GTK_WIDGET(m_list
)->window
&& cursor
.Ok())
1012 /* I now set the cursor the anew in every OnInternalIdle call
1013 as setting the cursor in a parent window also effects the
1014 windows above so that checking for the current cursor is
1017 gdk_window_set_cursor( GTK_WIDGET(m_list
)->window
, cursor
.GetCursor() );
1019 GList
*child
= m_list
->children
;
1022 GtkBin
*bin
= GTK_BIN( child
->data
);
1023 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
1028 gdk_window_set_cursor( label
->window
, cursor
.GetCursor() );
1030 child
= child
->next
;
1037 wxSize
wxListBox::DoGetBestSize() const
1039 return wxSize(100, 110);