1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "listbox.h"
16 #define gtk_scrolled_window_add_with_viewport gtk_scrolled_window_add_with_vi
17 #define gtk_container_set_focus_vadjustment gtk_container_set_focus_vadjust
18 #define gtk_scrolled_window_get_vadjustment gtk_scrolled_window_get_vadjust
21 #include "wx/listbox.h"
25 #include "wx/dynarray.h"
28 #include "wx/checklst.h"
29 #include "wx/settings.h"
32 #include "wx/tooltip.h"
37 #include <gdk/gdkkeysyms.h>
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 extern void wxapp_install_idle_handler();
46 //-------------------------------------------------------------------------
47 // conditional compilation
48 //-------------------------------------------------------------------------
50 #if (GTK_MINOR_VERSION > 0)
51 #define NEW_GTK_SCROLL_CODE
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 #if wxUSE_CHECKLISTBOX
60 #define CHECKBOX_STRING "[-] "
62 // checklistboxes have "[±] " prepended to their lables, this macro removes it
63 // (NB: 4 below is the length of CHECKBOX_STRING above)
65 // the argument to it is a "const char *" pointer
66 #define GET_REAL_LABEL(label) ((m_hasCheckBoxes)?(label)+4 : (label))
68 #else // !wxUSE_CHECKLISTBOX
70 #define GET_REAL_LABEL(label) (label)
72 #endif // wxUSE_CHECKLISTBOX
74 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
78 extern bool g_blockEventsOnDrag
;
79 extern bool g_blockEventsOnScroll
;
80 extern wxCursor g_globalCursor
;
82 static bool g_hasDoubleClicked
= FALSE
;
84 //-----------------------------------------------------------------------------
85 // idle callback for SetFirstItem
86 //-----------------------------------------------------------------------------
88 struct wxlistbox_idle_struct
95 static gint
wxlistbox_idle_callback( gpointer gdata
)
97 wxlistbox_idle_struct
* data
= (wxlistbox_idle_struct
*) gdata
;
100 gtk_idle_remove( data
->m_tag
);
102 data
->m_listbox
->SetFirstItem( data
->m_item
);
111 //-----------------------------------------------------------------------------
112 // "button_release_event"
113 //-----------------------------------------------------------------------------
115 /* we would normally emit a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event once
116 a GDK_2BUTTON_PRESS occurs, but this has the particular problem of the
117 listbox keeping the focus until it receives a GDK_BUTTON_RELEASE event.
118 this can lead to race conditions so that we emit the dclick event
119 after the GDK_BUTTON_RELEASE event after the GDK_2BUTTON_PRESS event */
122 gtk_listbox_button_release_callback( GtkWidget
* WXUNUSED(widget
),
123 GdkEventButton
* WXUNUSED(gdk_event
),
126 if (g_isIdle
) wxapp_install_idle_handler();
128 if (g_blockEventsOnDrag
) return FALSE
;
129 if (g_blockEventsOnScroll
) return FALSE
;
131 if (!listbox
->m_hasVMT
) return FALSE
;
133 if (!g_hasDoubleClicked
) return FALSE
;
135 wxCommandEvent
event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, listbox
->GetId() );
136 event
.SetEventObject( listbox
);
138 wxArrayInt aSelections
;
139 int n
, count
= listbox
->GetSelections(aSelections
);
143 if ( listbox
->HasClientObjectData() )
144 event
.SetClientObject( listbox
->GetClientObject(n
) );
145 else if ( listbox
->HasClientUntypedData() )
146 event
.SetClientData( listbox
->GetClientData(n
) );
147 event
.SetString( listbox
->GetString(n
) );
154 event
.m_commandInt
= n
;
156 listbox
->GetEventHandler()->ProcessEvent( event
);
161 //-----------------------------------------------------------------------------
162 // "button_press_event"
163 //-----------------------------------------------------------------------------
166 gtk_listbox_button_press_callback( GtkWidget
*widget
,
167 GdkEventButton
*gdk_event
,
170 if (g_isIdle
) wxapp_install_idle_handler();
172 if (g_blockEventsOnDrag
) return FALSE
;
173 if (g_blockEventsOnScroll
) return FALSE
;
175 if (!listbox
->m_hasVMT
) return FALSE
;
177 int sel
= listbox
->GtkGetIndex( widget
);
179 #if wxUSE_CHECKLISTBOX
180 if ((listbox
->m_hasCheckBoxes
) && (gdk_event
->x
< 15) && (gdk_event
->type
!= GDK_2BUTTON_PRESS
))
182 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
184 clb
->Check( sel
, !clb
->IsChecked(sel
) );
186 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
187 event
.SetEventObject( listbox
);
189 listbox
->GetEventHandler()->ProcessEvent( event
);
191 #endif // wxUSE_CHECKLISTBOX
193 /* emit wxEVT_COMMAND_LISTBOX_DOUBLECLICKED later */
194 g_hasDoubleClicked
= (gdk_event
->type
== GDK_2BUTTON_PRESS
);
199 //-----------------------------------------------------------------------------
201 //-----------------------------------------------------------------------------
204 gtk_listbox_key_press_callback( GtkWidget
*widget
, GdkEventKey
*gdk_event
, wxListBox
*listbox
)
207 wxapp_install_idle_handler();
209 if (g_blockEventsOnDrag
)
214 if ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
))
216 wxNavigationKeyEvent new_event
;
217 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
218 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
219 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
220 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
221 new_event
.SetCurrentFocus( listbox
);
222 ret
= listbox
->GetEventHandler()->ProcessEvent( new_event
);
225 if ((gdk_event
->keyval
== GDK_Return
) && (!ret
))
227 // eat return in all modes
231 #if wxUSE_CHECKLISTBOX
232 if ((gdk_event
->keyval
== ' ') && (listbox
->m_hasCheckBoxes
) && (!ret
))
234 int sel
= listbox
->GtkGetIndex( widget
);
236 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
238 clb
->Check( sel
, !clb
->IsChecked(sel
) );
240 wxCommandEvent
new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
241 new_event
.SetEventObject( listbox
);
242 new_event
.SetInt( sel
);
243 ret
= listbox
->GetEventHandler()->ProcessEvent( new_event
);
245 #endif // wxUSE_CHECKLISTBOX
249 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
256 //-----------------------------------------------------------------------------
257 // "select" and "deselect"
258 //-----------------------------------------------------------------------------
260 static void gtk_listitem_select_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
);
262 static void gtk_listitem_deselect_callback( GtkWidget
*widget
, wxListBox
*listbox
)
264 gtk_listitem_select_callback( widget
, listbox
);
267 static void gtk_listitem_select_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
)
269 if (g_isIdle
) wxapp_install_idle_handler();
271 if (!listbox
->m_hasVMT
) return;
272 if (g_blockEventsOnDrag
) return;
274 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, listbox
->GetId() );
275 event
.SetEventObject( listbox
);
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();
442 for ( size_t n
= 0; n
< nItems
; n
++ )
444 GtkAddItem( items
[n
] );
446 m_clientList
.Append((wxObject
*)NULL
);
451 wxNode
*node
= m_clientList
.Nth( pos
);
452 for ( size_t n
= 0; n
< nItems
; n
++ )
454 GtkAddItem( items
[n
], pos
+n
);
456 m_clientList
.Insert( node
, (wxObject
*)NULL
);
460 wxASSERT_MSG( m_clientList
.GetCount() == (size_t)GetCount(),
461 wxT("bug in client data management") );
464 int wxListBox
::DoAppend( const wxString
& item
)
468 // need to determine the index
469 int index
= m_strings
->Add( item
);
471 // only if not at the end anyway
472 if (index
!= GetCount())
474 GtkAddItem( item
, index
);
476 wxNode
*node
= m_clientList
.Nth( index
);
477 m_clientList
.Insert( node
, (wxObject
*)NULL
);
485 m_clientList
.Append((wxObject
*)NULL
);
487 return GetCount() - 1;
490 void wxListBox
::GtkAddItem( const wxString
&item
, int pos
)
492 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
494 GtkWidget
*list_item
;
496 wxString
label(item
);
497 #if wxUSE_CHECKLISTBOX
500 label
.Prepend(CHECKBOX_STRING
);
502 #endif // wxUSE_CHECKLISTBOX
504 list_item
= gtk_list_item_new_with_label( label
.mbc_str() );
506 GList
*gitem_list
= g_list_alloc ();
507 gitem_list
->data
= list_item
;
510 gtk_list_append_items( GTK_LIST (m_list
), gitem_list
);
512 gtk_list_insert_items( GTK_LIST (m_list
), gitem_list
, pos
);
514 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
515 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
517 if (HasFlag(wxLB_MULTIPLE
))
518 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
519 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
521 gtk_signal_connect( GTK_OBJECT(list_item
),
522 "button_press_event",
523 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
526 gtk_signal_connect_after( GTK_OBJECT(list_item
),
527 "button_release_event",
528 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
531 gtk_signal_connect( GTK_OBJECT(list_item
),
533 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
536 ConnectWidget( list_item
);
538 gtk_widget_show( list_item
);
540 if (GTK_WIDGET_REALIZED(m_widget
))
542 gtk_widget_realize( list_item
);
543 gtk_widget_realize( GTK_BIN(list_item
)->child
);
545 // Apply current widget style to the new list_item
548 gtk_widget_set_style( GTK_WIDGET( list_item
), m_widgetStyle
);
549 GtkBin
*bin
= GTK_BIN( list_item
);
550 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
551 gtk_widget_set_style( label
, m_widgetStyle
);
555 if (m_tooltip
) m_tooltip
->Apply( this );
560 void wxListBox
::DoSetItems( const wxArrayString
& items
,
565 DoInsertItems(items
, 0);
569 size_t count
= items
.GetCount();
570 for ( size_t n
= 0; n
< count
; n
++ )
572 SetClientData(n
, clientData
[n
]);
577 // ----------------------------------------------------------------------------
579 // ----------------------------------------------------------------------------
581 void wxListBox
::DoSetItemClientData( int n
, void* clientData
)
583 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid listbox control") );
585 wxNode
*node
= m_clientList
.Nth( n
);
586 wxCHECK_RET( node
, wxT("invalid index in wxListBox::DoSetItemClientData") );
588 node
->SetData( (wxObject
*) clientData
);
591 void* wxListBox
::DoGetItemClientData( int n
) const
593 wxCHECK_MSG( m_widget
!= NULL
, NULL
, wxT("invalid listbox control") );
595 wxNode
*node
= m_clientList
.Nth( n
);
596 wxCHECK_MSG( node
, NULL
, wxT("invalid index in wxListBox::DoGetItemClientData") );
601 void wxListBox
::DoSetItemClientObject( int n
, wxClientData
* clientData
)
603 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid listbox control") );
605 wxNode
*node
= m_clientList
.Nth( n
);
606 wxCHECK_RET( node
, wxT("invalid index in wxListBox::DoSetItemClientObject") );
608 wxClientData
*cd
= (wxClientData
*) node
->Data();
611 node
->SetData( (wxObject
*) clientData
);
614 wxClientData
* wxListBox
::DoGetItemClientObject( int n
) const
616 wxCHECK_MSG( m_widget
!= NULL
, (wxClientData
*) NULL
, wxT("invalid listbox control") );
618 wxNode
*node
= m_clientList
.Nth( n
);
619 wxCHECK_MSG( node
, (wxClientData
*)NULL
,
620 wxT("invalid index in wxListBox::DoGetItemClientObject") );
622 return (wxClientData
*) node
->Data();
625 void wxListBox
::Clear()
627 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
629 gtk_list_clear_items( m_list
, 0, Number() );
631 if ( HasClientObjectData() )
633 // destroy the data (due to Robert's idea of using wxList<wxObject>
634 // and not wxList<wxClientData> we can't just say
635 // m_clientList.DeleteContents(TRUE) - this would crash!
636 wxNode
*node
= m_clientList
.First();
639 delete (wxClientData
*)node
->Data();
643 m_clientList
.Clear();
649 void wxListBox
::Delete( int n
)
651 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
653 GList
*child
= g_list_nth( m_list
->children
, n
);
655 wxCHECK_RET( child
, wxT("wrong listbox index") );
657 GList
*list
= g_list_append( (GList
*) NULL
, child
->data
);
658 gtk_list_remove_items( m_list
, list
);
661 wxNode
*node
= m_clientList
.Nth( n
);
664 if ( m_clientDataItemsType
== ClientData_Object
)
666 wxClientData
*cd
= (wxClientData
*)node
->Data();
670 m_clientList
.DeleteNode( node
);
674 m_strings
->Remove(n
);
677 // ----------------------------------------------------------------------------
678 // string list access
679 // ----------------------------------------------------------------------------
681 void wxListBox
::SetString( int n
, const wxString
&string
)
683 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
685 GList
*child
= g_list_nth( m_list
->children
, n
);
688 GtkBin
*bin
= GTK_BIN( child
->data
);
689 GtkLabel
*label
= GTK_LABEL( bin
->child
);
692 #if wxUSE_CHECKLISTBOX
694 str
+= CHECKBOX_STRING
;
695 #endif // wxUSE_CHECKLISTBOX
698 gtk_label_set( label
, str
.mbc_str() );
702 wxFAIL_MSG(wxT("wrong listbox index"));
706 wxString wxListBox
::GetString( int n
) const
708 wxCHECK_MSG( m_list
!= NULL
, wxT(""), wxT("invalid listbox") );
710 GList
*child
= g_list_nth( m_list
->children
, n
);
713 GtkBin
*bin
= GTK_BIN( child
->data
);
714 GtkLabel
*label
= GTK_LABEL( bin
->child
);
716 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
721 wxFAIL_MSG(wxT("wrong listbox index"));
726 int wxListBox
::GetCount() const
728 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
730 GList
*children
= m_list
->children
;
731 return g_list_length(children
);
734 int wxListBox
::FindString( const wxString
&item
) const
736 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
738 GList
*child
= m_list
->children
;
742 GtkBin
*bin
= GTK_BIN( child
->data
);
743 GtkLabel
*label
= GTK_LABEL( bin
->child
);
745 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
754 // it's not an error if the string is not found -> no wxCHECK
759 // ----------------------------------------------------------------------------
761 // ----------------------------------------------------------------------------
763 int wxListBox
::GetSelection() const
765 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
767 GList
*child
= m_list
->children
;
771 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
) return count
;
778 int wxListBox
::GetSelections( wxArrayInt
& aSelections
) const
780 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
782 // get the number of selected items first
783 GList
*child
= m_list
->children
;
785 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
)
787 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
796 aSelections
.Alloc(count
); // optimization attempt
798 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
, i
++)
800 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
808 bool wxListBox
::IsSelected( int n
) const
810 wxCHECK_MSG( m_list
!= NULL
, FALSE
, wxT("invalid listbox") );
812 GList
*target
= g_list_nth( m_list
->children
, n
);
814 wxCHECK_MSG( target
, FALSE
, wxT("invalid listbox index") );
816 return (GTK_WIDGET(target
->data
)->state
== GTK_STATE_SELECTED
) ;
819 void wxListBox
::SetSelection( int n
, bool select
)
821 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
826 gtk_list_select_item( m_list
, n
);
828 gtk_list_unselect_item( m_list
, n
);
833 void wxListBox
::DoSetFirstItem( int n
)
835 wxCHECK_RET( m_list
, wxT("invalid listbox") );
837 if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_list
))
840 // terribly efficient
841 const gchar
*vadjustment_key
= "gtk-vadjustment";
842 guint vadjustment_key_id
= g_quark_from_static_string (vadjustment_key
);
844 GtkAdjustment
*adjustment
=
845 (GtkAdjustment
*) gtk_object_get_data_by_id (GTK_OBJECT (m_list
), vadjustment_key_id
);
846 wxCHECK_RET( adjustment
, wxT("invalid listbox code") );
848 GList
*target
= g_list_nth( m_list
->children
, n
);
849 wxCHECK_RET( target
, wxT("invalid listbox index") );
851 GtkWidget
*item
= GTK_WIDGET(target
->data
);
852 wxCHECK_RET( item
, wxT("invalid listbox code") );
854 if (item
->allocation
.y
== -1)
856 wxlistbox_idle_struct
* data
= new wxlistbox_idle_struct
;
857 data
->m_listbox
= this;
859 data
->m_tag
= gtk_idle_add_priority( 800, wxlistbox_idle_callback
, (gpointer
) data
);
864 float y
= item
->allocation
.y
;
865 if (y
> adjustment
->upper
- adjustment
->page_size
)
866 y
= adjustment
->upper
- adjustment
->page_size
;
867 gtk_adjustment_set_value( adjustment
, y
);
870 // ----------------------------------------------------------------------------
872 // ----------------------------------------------------------------------------
874 int wxListBox
::GtkGetIndex( 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 void wxListBox
::GtkDisableEvents()
904 GList
*child
= m_list
->children
;
907 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
908 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
910 if (HasFlag(wxLB_MULTIPLE
))
911 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
912 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
918 void wxListBox
::GtkEnableEvents()
920 GList
*child
= m_list
->children
;
923 gtk_signal_connect( GTK_OBJECT(child
->data
), "select",
924 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
926 if (HasFlag(wxLB_MULTIPLE
))
927 gtk_signal_connect( GTK_OBJECT(child
->data
), "deselect",
928 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
934 GtkWidget
*wxListBox
::GetConnectWidget()
936 return GTK_WIDGET(m_list
);
939 bool wxListBox
::IsOwnGtkWindow( GdkWindow
*window
)
941 if (GTK_WIDGET(m_list
)->window
== window
) return TRUE
;
943 GList
*child
= m_list
->children
;
946 GtkWidget
*bin
= GTK_WIDGET( child
->data
);
947 if (bin
->window
== window
) return TRUE
;
954 void wxListBox
::ApplyWidgetStyle()
958 if (m_backgroundColour
.Ok())
960 GdkWindow
*window
= GTK_WIDGET(m_list
)->window
;
963 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
964 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
965 gdk_window_clear( window
);
969 GList
*child
= m_list
->children
;
972 gtk_widget_set_style( GTK_WIDGET(child
->data
), m_widgetStyle
);
974 GtkBin
*bin
= GTK_BIN( child
->data
);
975 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
976 gtk_widget_set_style( label
, m_widgetStyle
);
982 void wxListBox
::OnInternalIdle()
984 wxCursor cursor
= m_cursor
;
985 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
987 if (GTK_WIDGET(m_list
)->window
&& cursor
.Ok())
989 /* I now set the cursor the anew in every OnInternalIdle call
990 as setting the cursor in a parent window also effects the
991 windows above so that checking for the current cursor is
994 gdk_window_set_cursor( GTK_WIDGET(m_list
)->window
, cursor
.GetCursor() );
996 GList
*child
= m_list
->children
;
999 GtkBin
*bin
= GTK_BIN( child
->data
);
1000 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
1005 gdk_window_set_cursor( label
->window
, cursor
.GetCursor() );
1007 child
= child
->next
;
1014 wxSize wxListBox
::DoGetBestSize() const
1016 return wxSize(100, 110);