#include "wx/tooltip.h"
#endif
-#if wxUSE_DRAG_AND_DROP
-#include "wx/dnd.h"
-#endif
-
-#include "gdk/gdk.h"
-#include "gtk/gtk.h"
+# include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
//-----------------------------------------------------------------------------
// idle system
// "key_press_event"
//-----------------------------------------------------------------------------
-#if wxUSE_CHECKLISTBOX
static gint
gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox )
{
- if (g_isIdle) wxapp_install_idle_handler();
+ if (g_isIdle)
+ wxapp_install_idle_handler();
- if (g_blockEventsOnDrag) return FALSE;
+ if (g_blockEventsOnDrag)
+ return FALSE;
- if (!listbox->m_hasVMT) return FALSE;
+ bool ret = FALSE;
- if (gdk_event->keyval != ' ') return FALSE;
+ if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab))
+ {
+ wxNavigationKeyEvent new_event;
+ /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
+ new_event.SetDirection( (gdk_event->keyval == GDK_Tab) );
+ /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
+ new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
+ new_event.SetCurrentFocus( listbox );
+ ret = listbox->GetEventHandler()->ProcessEvent( new_event );
+ }
- int sel = listbox->GtkGetIndex( widget );
+#if wxUSE_CHECKLISTBOX
+ if ((gdk_event->keyval == ' ') && (listbox->m_hasCheckBoxes) && (!ret))
+ {
+ int sel = listbox->GtkGetIndex( widget );
- wxCheckListBox *clb = (wxCheckListBox *)listbox;
+ wxCheckListBox *clb = (wxCheckListBox *)listbox;
- clb->Check( sel, !clb->IsChecked(sel) );
+ clb->Check( sel, !clb->IsChecked(sel) );
- wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() );
- event.SetEventObject( listbox );
- event.SetInt( sel );
- listbox->GetEventHandler()->ProcessEvent( event );
+ wxCommandEvent new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() );
+ new_event.SetEventObject( listbox );
+ new_event.SetInt( sel );
+ ret = listbox->GetEventHandler()->ProcessEvent( new_event );
+ }
+#endif // wxUSE_CHECKLISTBOX
+
+ if (ret)
+ {
+ gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
+ return TRUE;
+ }
return FALSE;
}
-#endif // wxUSE_CHECKLISTBOX
//-----------------------------------------------------------------------------
// "select" and "deselect"
event.m_commandInt = n;
- listbox->GetEventHandler()->ProcessEvent( event );
+ listbox->GetEventHandler()->AddPendingEvent( event );
+// listbox->GetEventHandler()->ProcessEvent( event );
}
//-----------------------------------------------------------------------------
gtk_widget_show( GTK_WIDGET(m_list) );
- wxSize newSize = size;
- if (newSize.x == -1) newSize.x = 100;
- if (newSize.y == -1) newSize.y = 110;
- SetSize( newSize.x, newSize.y );
+ SetSizeOrDefault( size );
if ( style & wxLB_SORT )
{
// this will change DoAppend() behaviour
m_strings = new wxSortedArrayString;
}
+ else
+ {
+ m_strings = (wxSortedArrayString *)NULL;
+ }
for (int i = 0; i < n; i++)
{
PostCreation();
- SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW ) );
+ SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) );
SetForegroundColour( parent->GetForegroundColour() );
SetFont( parent->GetFont() );
wxListBox::~wxListBox()
{
Clear();
+ if (m_strings)
+ delete m_strings;
}
void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
GList *children = m_list->children;
int length = g_list_length(children);
-
+
wxCHECK_RET( pos <= length, wxT("invalid index in wxListBox::InsertItems") );
size_t nItems = items.GetCount();
{
// need to determine the index
int index = m_strings->Add( item );
-
- // only if not at the end anyway
- if (index != GetCount())
- {
- GtkAddItem( item, index );
-
- wxNode *node = m_clientList.Nth( index );
+
+ // only if not at the end anyway
+ if (index != GetCount())
+ {
+ GtkAddItem( item, index );
+
+ wxNode *node = m_clientList.Nth( index );
m_clientList.Insert( node, (wxObject *)NULL );
-
- return index;
- }
+
+ return index;
+ }
}
-
+
GtkAddItem(item);
m_clientList.Append((wxObject *)NULL);
GList *gitem_list = g_list_alloc ();
gitem_list->data = list_item;
-
+
if (pos == -1)
gtk_list_append_items( GTK_LIST (m_list), gitem_list );
else
(GtkSignalFunc)gtk_listbox_button_release_callback,
(gpointer) this );
-#if wxUSE_CHECKLISTBOX
- if (m_hasCheckBoxes)
- {
- gtk_signal_connect( GTK_OBJECT(list_item),
+ gtk_signal_connect( GTK_OBJECT(list_item),
"key_press_event",
(GtkSignalFunc)gtk_listbox_key_press_callback,
(gpointer)this );
- }
-#endif // wxUSE_CHECKLISTBOX
-
- gtk_widget_show( list_item );
ConnectWidget( list_item );
+ gtk_widget_show( list_item );
+
if (GTK_WIDGET_REALIZED(m_widget))
{
gtk_widget_realize( list_item );
gtk_widget_realize( GTK_BIN(list_item)->child );
// Apply current widget style to the new list_item
- if (m_widgetStyle)
- {
+ if (m_widgetStyle)
+ {
gtk_widget_set_style( GTK_WIDGET( list_item ), m_widgetStyle );
GtkBin *bin = GTK_BIN( list_item );
GtkWidget *label = GTK_WIDGET( bin->child );
wxCHECK_MSG( m_list != NULL, FALSE, wxT("invalid listbox") );
GList *target = g_list_nth( m_list->children, n );
- if (target)
- {
- GList *child = m_list->selection;
- while (child)
- {
- if (child->data == target->data) return TRUE;
- child = child->next;
- }
- }
- wxFAIL_MSG(wxT("wrong listbox index"));
+ wxCHECK_MSG( target, FALSE, wxT("invalid listbox index") );
- return FALSE;
+ return (GTK_WIDGET(target->data)->state == GTK_STATE_SELECTED) ;
}
void wxListBox::SetSelection( int n, bool select )
GtkEnableEvents();
}
-void wxListBox::DoSetFirstItem( int WXUNUSED(n) )
+void wxListBox::DoSetFirstItem( int n )
{
- wxFAIL_MSG(wxT("wxListBox::SetFirstItem not implemented"));
+ wxCHECK_RET( m_list, wxT("invalid listbox") );
+
+ if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_list))
+ return;
+
+ // terribly efficient
+ const gchar *vadjustment_key = "gtk-vadjustment";
+ guint vadjustment_key_id = g_quark_from_static_string (vadjustment_key);
+
+ GtkAdjustment *adjustment =
+ (GtkAdjustment*) gtk_object_get_data_by_id (GTK_OBJECT (m_list), vadjustment_key_id);
+ wxCHECK_RET( adjustment, wxT("invalid listbox code") );
+
+ GList *target = g_list_nth( m_list->children, n );
+ wxCHECK_RET( target, wxT("invalid listbox index") );
+
+ GtkWidget *item = GTK_WIDGET(target->data);
+ wxCHECK_RET( item, wxT("invalid listbox code") );
+
+ // find the last item before this one which is already realized
+ size_t nItemsBefore;
+ for ( nItemsBefore = 0; item && (item->allocation.y == -1); nItemsBefore++ )
+ {
+ target = target->prev;
+ if ( !target )
+ {
+ // nothing we can do if there are no allocated items yet
+ return;
+ }
+
+ item = GTK_WIDGET(target->data);
+ }
+
+ gtk_adjustment_set_value(adjustment,
+ item->allocation.y +
+ nItemsBefore*item->allocation.height);
}
// ----------------------------------------------------------------------------
bool wxListBox::IsOwnGtkWindow( GdkWindow *window )
{
- if (wxWindow::IsOwnGtkWindow( window )) return TRUE;
+ if (GTK_WIDGET(m_list)->window == window) return TRUE;
GList *child = m_list->children;
while (child)
as setting the cursor in a parent window also effects the
windows above so that checking for the current cursor is
not possible. */
-
+
gdk_window_set_cursor( GTK_WIDGET(m_list)->window, cursor.GetCursor() );
GList *child = m_list->children;
{
GtkBin *bin = GTK_BIN( child->data );
GtkWidget *label = GTK_WIDGET( bin->child );
-
+
if (!label->window)
break;
else
UpdateWindowUI();
}
+wxSize wxListBox::DoGetBestSize() const
+{
+ return wxSize(100, 110);
+}
+
#endif