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_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
);
256 static void gtk_listitem_deselect_callback( GtkWidget
*widget
, wxListBox
*listbox
)
258 gtk_listitem_select_callback( widget
, listbox
);
261 static void gtk_listitem_select_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
)
263 if (g_isIdle
) wxapp_install_idle_handler();
265 if (!listbox
->m_hasVMT
) return;
266 if (g_blockEventsOnDrag
) return;
268 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, listbox
->GetId() );
269 event
.SetEventObject( listbox
);
271 wxArrayInt aSelections
;
272 int n
, count
= listbox
->GetSelections(aSelections
);
276 if ( listbox
->HasClientObjectData() )
277 event
.SetClientObject( listbox
->GetClientObject(n
) );
278 else if ( listbox
->HasClientUntypedData() )
279 event
.SetClientData( listbox
->GetClientData(n
) );
280 event
.SetString( listbox
->GetString(n
) );
287 event
.m_commandInt
= n
;
289 listbox
->GetEventHandler()->AddPendingEvent( event
);
290 // listbox->GetEventHandler()->ProcessEvent( event );
293 //-----------------------------------------------------------------------------
295 //-----------------------------------------------------------------------------
297 IMPLEMENT_DYNAMIC_CLASS(wxListBox
,wxControl
)
299 // ----------------------------------------------------------------------------
301 // ----------------------------------------------------------------------------
303 wxListBox::wxListBox()
305 m_list
= (GtkList
*) NULL
;
306 #if wxUSE_CHECKLISTBOX
307 m_hasCheckBoxes
= FALSE
;
308 #endif // wxUSE_CHECKLISTBOX
311 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
312 const wxPoint
&pos
, const wxSize
&size
,
313 int n
, const wxString choices
[],
314 long style
, const wxValidator
& validator
,
315 const wxString
&name
)
318 m_acceptsFocus
= TRUE
;
320 if (!PreCreation( parent
, pos
, size
) ||
321 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
323 wxFAIL_MSG( wxT("wxListBox creation failed") );
327 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
328 if (style
& wxLB_ALWAYS_SB
)
330 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
331 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
335 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
336 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
339 m_list
= GTK_LIST( gtk_list_new() );
341 GtkSelectionMode mode
;
342 if (style
& wxLB_MULTIPLE
)
344 mode
= GTK_SELECTION_MULTIPLE
;
346 else if (style
& wxLB_EXTENDED
)
348 mode
= GTK_SELECTION_EXTENDED
;
352 // if style was 0 set single mode
353 m_windowStyle
|= wxLB_SINGLE
;
354 mode
= GTK_SELECTION_BROWSE
;
357 gtk_list_set_selection_mode( GTK_LIST(m_list
), mode
);
359 #ifdef NEW_GTK_SCROLL_CODE
360 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget
), GTK_WIDGET(m_list
) );
362 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_list
) );
365 /* make list scroll when moving the focus down using cursor keys */
366 gtk_container_set_focus_vadjustment(
367 GTK_CONTAINER(m_list
),
368 gtk_scrolled_window_get_vadjustment(
369 GTK_SCROLLED_WINDOW(m_widget
)));
371 gtk_widget_show( GTK_WIDGET(m_list
) );
373 SetSizeOrDefault( size
);
375 if ( style
& wxLB_SORT
)
377 // this will change DoAppend() behaviour
378 m_strings
= new wxSortedArrayString
;
382 m_strings
= (wxSortedArrayString
*)NULL
;
385 for (int i
= 0; i
< n
; i
++)
388 DoAppend(choices
[i
]);
391 m_parent
->DoAddChild( this );
395 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
396 SetForegroundColour( parent
->GetForegroundColour() );
397 SetFont( parent
->GetFont() );
404 wxListBox::~wxListBox()
414 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
416 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
418 // VZ: notice that InsertItems knows nothing about sorting, so calling it
419 // from outside (and not from our own Append) is likely to break
422 // code elsewhere supposes we have as many items in m_clientList as items
424 wxASSERT_MSG( m_clientList
.GetCount() == (size_t)GetCount(),
425 wxT("bug in client data management") );
427 GList
*children
= m_list
->children
;
428 int length
= g_list_length(children
);
430 wxCHECK_RET( pos
<= length
, wxT("invalid index in wxListBox::InsertItems") );
432 size_t nItems
= items
.GetCount();
436 for ( size_t n
= 0; n
< nItems
; n
++ )
438 GtkAddItem( items
[n
] );
440 m_clientList
.Append((wxObject
*)NULL
);
445 wxNode
*node
= m_clientList
.Nth( pos
);
446 for ( size_t n
= 0; n
< nItems
; n
++ )
448 GtkAddItem( items
[n
], pos
+n
);
450 m_clientList
.Insert( node
, (wxObject
*)NULL
);
454 wxASSERT_MSG( m_clientList
.GetCount() == (size_t)GetCount(),
455 wxT("bug in client data management") );
458 int wxListBox::DoAppend( const wxString
& item
)
462 // need to determine the index
463 int index
= m_strings
->Add( item
);
465 // only if not at the end anyway
466 if (index
!= GetCount())
468 GtkAddItem( item
, index
);
470 wxNode
*node
= m_clientList
.Nth( index
);
471 m_clientList
.Insert( node
, (wxObject
*)NULL
);
479 m_clientList
.Append((wxObject
*)NULL
);
481 return GetCount() - 1;
484 void wxListBox::GtkAddItem( const wxString
&item
, int pos
)
486 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
488 GtkWidget
*list_item
;
490 wxString
label(item
);
491 #if wxUSE_CHECKLISTBOX
494 label
.Prepend(CHECKBOX_STRING
);
496 #endif // wxUSE_CHECKLISTBOX
498 list_item
= gtk_list_item_new_with_label( label
.mbc_str() );
500 GList
*gitem_list
= g_list_alloc ();
501 gitem_list
->data
= list_item
;
504 gtk_list_append_items( GTK_LIST (m_list
), gitem_list
);
506 gtk_list_insert_items( GTK_LIST (m_list
), gitem_list
, pos
);
508 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
509 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
511 if (HasFlag(wxLB_MULTIPLE
))
512 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
513 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
515 gtk_signal_connect( GTK_OBJECT(list_item
),
516 "button_press_event",
517 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
520 gtk_signal_connect_after( GTK_OBJECT(list_item
),
521 "button_release_event",
522 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
525 gtk_signal_connect( GTK_OBJECT(list_item
),
527 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
530 ConnectWidget( list_item
);
532 gtk_widget_show( list_item
);
534 if (GTK_WIDGET_REALIZED(m_widget
))
536 gtk_widget_realize( list_item
);
537 gtk_widget_realize( GTK_BIN(list_item
)->child
);
539 // Apply current widget style to the new list_item
542 gtk_widget_set_style( GTK_WIDGET( list_item
), m_widgetStyle
);
543 GtkBin
*bin
= GTK_BIN( list_item
);
544 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
545 gtk_widget_set_style( label
, m_widgetStyle
);
549 if (m_tooltip
) m_tooltip
->Apply( this );
554 void wxListBox::DoSetItems( const wxArrayString
& items
,
559 DoInsertItems(items
, 0);
563 size_t count
= items
.GetCount();
564 for ( size_t n
= 0; n
< count
; n
++ )
566 SetClientData(n
, clientData
[n
]);
571 // ----------------------------------------------------------------------------
573 // ----------------------------------------------------------------------------
575 void wxListBox::DoSetItemClientData( int n
, void* clientData
)
577 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid listbox control") );
579 wxNode
*node
= m_clientList
.Nth( n
);
580 wxCHECK_RET( node
, wxT("invalid index in wxListBox::DoSetItemClientData") );
582 node
->SetData( (wxObject
*) clientData
);
585 void* wxListBox::DoGetItemClientData( int n
) const
587 wxCHECK_MSG( m_widget
!= NULL
, NULL
, wxT("invalid listbox control") );
589 wxNode
*node
= m_clientList
.Nth( n
);
590 wxCHECK_MSG( node
, NULL
, wxT("invalid index in wxListBox::DoGetItemClientData") );
595 void wxListBox::DoSetItemClientObject( int n
, wxClientData
* clientData
)
597 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid listbox control") );
599 wxNode
*node
= m_clientList
.Nth( n
);
600 wxCHECK_RET( node
, wxT("invalid index in wxListBox::DoSetItemClientObject") );
602 wxClientData
*cd
= (wxClientData
*) node
->Data();
605 node
->SetData( (wxObject
*) clientData
);
608 wxClientData
* wxListBox::DoGetItemClientObject( int n
) const
610 wxCHECK_MSG( m_widget
!= NULL
, (wxClientData
*) NULL
, wxT("invalid listbox control") );
612 wxNode
*node
= m_clientList
.Nth( n
);
613 wxCHECK_MSG( node
, (wxClientData
*)NULL
,
614 wxT("invalid index in wxListBox::DoGetItemClientObject") );
616 return (wxClientData
*) node
->Data();
619 void wxListBox::Clear()
621 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
623 gtk_list_clear_items( m_list
, 0, Number() );
625 if ( HasClientObjectData() )
627 // destroy the data (due to Robert's idea of using wxList<wxObject>
628 // and not wxList<wxClientData> we can't just say
629 // m_clientList.DeleteContents(TRUE) - this would crash!
630 wxNode
*node
= m_clientList
.First();
633 delete (wxClientData
*)node
->Data();
637 m_clientList
.Clear();
643 void wxListBox::Delete( int n
)
645 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
647 GList
*child
= g_list_nth( m_list
->children
, n
);
649 wxCHECK_RET( child
, wxT("wrong listbox index") );
651 GList
*list
= g_list_append( (GList
*) NULL
, child
->data
);
652 gtk_list_remove_items( m_list
, list
);
655 wxNode
*node
= m_clientList
.Nth( n
);
658 if ( m_clientDataItemsType
== ClientData_Object
)
660 wxClientData
*cd
= (wxClientData
*)node
->Data();
664 m_clientList
.DeleteNode( node
);
668 m_strings
->Remove(n
);
671 // ----------------------------------------------------------------------------
672 // string list access
673 // ----------------------------------------------------------------------------
675 void wxListBox::SetString( int n
, const wxString
&string
)
677 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
679 GList
*child
= g_list_nth( m_list
->children
, n
);
682 GtkBin
*bin
= GTK_BIN( child
->data
);
683 GtkLabel
*label
= GTK_LABEL( bin
->child
);
686 #if wxUSE_CHECKLISTBOX
688 str
+= CHECKBOX_STRING
;
689 #endif // wxUSE_CHECKLISTBOX
692 gtk_label_set( label
, str
.mbc_str() );
696 wxFAIL_MSG(wxT("wrong listbox index"));
700 wxString
wxListBox::GetString( int n
) const
702 wxCHECK_MSG( m_list
!= NULL
, wxT(""), wxT("invalid listbox") );
704 GList
*child
= g_list_nth( m_list
->children
, n
);
707 GtkBin
*bin
= GTK_BIN( child
->data
);
708 GtkLabel
*label
= GTK_LABEL( bin
->child
);
710 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
715 wxFAIL_MSG(wxT("wrong listbox index"));
720 int wxListBox::GetCount() const
722 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
724 GList
*children
= m_list
->children
;
725 return g_list_length(children
);
728 int wxListBox::FindString( const wxString
&item
) const
730 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
732 GList
*child
= m_list
->children
;
736 GtkBin
*bin
= GTK_BIN( child
->data
);
737 GtkLabel
*label
= GTK_LABEL( bin
->child
);
739 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
748 // it's not an error if the string is not found -> no wxCHECK
753 // ----------------------------------------------------------------------------
755 // ----------------------------------------------------------------------------
757 int wxListBox::GetSelection() const
759 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
761 GList
*child
= m_list
->children
;
765 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
) return count
;
772 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
774 wxCHECK_MSG( m_list
!= NULL
, -1, wxT("invalid listbox") );
776 // get the number of selected items first
777 GList
*child
= m_list
->children
;
779 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
)
781 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
790 aSelections
.Alloc(count
); // optimization attempt
792 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
, i
++)
794 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
802 bool wxListBox::IsSelected( int n
) const
804 wxCHECK_MSG( m_list
!= NULL
, FALSE
, wxT("invalid listbox") );
806 GList
*target
= g_list_nth( m_list
->children
, n
);
808 wxCHECK_MSG( target
, FALSE
, wxT("invalid listbox index") );
810 return (GTK_WIDGET(target
->data
)->state
== GTK_STATE_SELECTED
) ;
813 void wxListBox::SetSelection( int n
, bool select
)
815 wxCHECK_RET( m_list
!= NULL
, wxT("invalid listbox") );
820 gtk_list_select_item( m_list
, n
);
822 gtk_list_unselect_item( m_list
, n
);
827 void wxListBox::DoSetFirstItem( int n
)
829 wxCHECK_RET( m_list
, wxT("invalid listbox") );
831 if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_list
))
834 // terribly efficient
835 const gchar
*vadjustment_key
= "gtk-vadjustment";
836 guint vadjustment_key_id
= g_quark_from_static_string (vadjustment_key
);
838 GtkAdjustment
*adjustment
=
839 (GtkAdjustment
*) gtk_object_get_data_by_id (GTK_OBJECT (m_list
), vadjustment_key_id
);
840 wxCHECK_RET( adjustment
, wxT("invalid listbox code") );
842 GList
*target
= g_list_nth( m_list
->children
, n
);
843 wxCHECK_RET( target
, wxT("invalid listbox index") );
845 GtkWidget
*item
= GTK_WIDGET(target
->data
);
846 wxCHECK_RET( item
, wxT("invalid listbox code") );
848 if (item
->allocation
.y
== -1)
850 wxlistbox_idle_struct
* data
= new wxlistbox_idle_struct
;
851 data
->m_listbox
= this;
853 data
->m_tag
= gtk_idle_add_priority( 800, wxlistbox_idle_callback
, (gpointer
) data
);
858 float y
= item
->allocation
.y
;
859 if (y
> adjustment
->upper
- adjustment
->page_size
)
860 y
= adjustment
->upper
- adjustment
->page_size
;
861 gtk_adjustment_set_value( adjustment
, y
);
864 // ----------------------------------------------------------------------------
866 // ----------------------------------------------------------------------------
868 int wxListBox::GtkGetIndex( GtkWidget
*item
) const
872 GList
*child
= m_list
->children
;
876 if (GTK_WIDGET(child
->data
) == item
) return count
;
885 void wxListBox::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
887 GList
*child
= m_list
->children
;
890 gtk_tooltips_set_tip( tips
, GTK_WIDGET( child
->data
), wxConvCurrent
->cWX2MB(tip
), (gchar
*) NULL
);
894 #endif // wxUSE_TOOLTIPS
896 void wxListBox::GtkDisableEvents()
898 GList
*child
= m_list
->children
;
901 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
902 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
904 if (HasFlag(wxLB_MULTIPLE
))
905 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
906 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
912 void wxListBox::GtkEnableEvents()
914 GList
*child
= m_list
->children
;
917 gtk_signal_connect( GTK_OBJECT(child
->data
), "select",
918 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
920 if (HasFlag(wxLB_MULTIPLE
))
921 gtk_signal_connect( GTK_OBJECT(child
->data
), "deselect",
922 GTK_SIGNAL_FUNC(gtk_listitem_deselect_callback
), (gpointer
)this );
928 GtkWidget
*wxListBox::GetConnectWidget()
930 return GTK_WIDGET(m_list
);
933 bool wxListBox::IsOwnGtkWindow( GdkWindow
*window
)
935 if (GTK_WIDGET(m_list
)->window
== window
) return TRUE
;
937 GList
*child
= m_list
->children
;
940 GtkWidget
*bin
= GTK_WIDGET( child
->data
);
941 if (bin
->window
== window
) return TRUE
;
948 void wxListBox::ApplyWidgetStyle()
952 if (m_backgroundColour
.Ok())
954 GdkWindow
*window
= GTK_WIDGET(m_list
)->window
;
957 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
958 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
959 gdk_window_clear( window
);
963 GList
*child
= m_list
->children
;
966 gtk_widget_set_style( GTK_WIDGET(child
->data
), m_widgetStyle
);
968 GtkBin
*bin
= GTK_BIN( child
->data
);
969 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
970 gtk_widget_set_style( label
, m_widgetStyle
);
976 void wxListBox::OnInternalIdle()
978 wxCursor cursor
= m_cursor
;
979 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
981 if (GTK_WIDGET(m_list
)->window
&& cursor
.Ok())
983 /* I now set the cursor the anew in every OnInternalIdle call
984 as setting the cursor in a parent window also effects the
985 windows above so that checking for the current cursor is
988 gdk_window_set_cursor( GTK_WIDGET(m_list
)->window
, cursor
.GetCursor() );
990 GList
*child
= m_list
->children
;
993 GtkBin
*bin
= GTK_BIN( child
->data
);
994 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
999 gdk_window_set_cursor( label
->window
, cursor
.GetCursor() );
1001 child
= child
->next
;
1008 wxSize
wxListBox::DoGetBestSize() const
1010 return wxSize(100, 110);