]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/listbox.cpp
added test mode to wxLongLongWx which allowed to find the bug in operator*=()
[wxWidgets.git] / src / gtk1 / listbox.cpp
index 9027f25b83ee71094c42c7385986079fc93841df..b3f0b65c4aa276c43876470bba0d6a5d6bb9ddec 100644 (file)
 #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
@@ -170,32 +167,52 @@ gtk_listbox_button_press_callback( GtkWidget *widget,
 // "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 );
+    }
+    
+#if wxUSE_CHECKLISTBOX
+    if ((gdk_event->keyval == ' ') && (listbox->m_hasCheckBoxes) && (!ret))
+    {
+        int sel = listbox->GtkGetIndex( widget );
 
-    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 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
 
-    wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() );
-    event.SetEventObject( listbox );
-    event.SetInt( sel );
-    listbox->GetEventHandler()->ProcessEvent( event );
+    if (ret)
+    {
+        gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
+        return TRUE;
+    }
 
     return FALSE;
 }
-#endif // wxUSE_CHECKLISTBOX
 
 //-----------------------------------------------------------------------------
 // "select" and "deselect"
@@ -236,7 +253,8 @@ static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox
 
     event.m_commandInt = n;
 
-    listbox->GetEventHandler()->ProcessEvent( event );
+    listbox->GetEventHandler()->AddPendingEvent( event );
+//    listbox->GetEventHandler()->ProcessEvent( event );
 }
 
 //-----------------------------------------------------------------------------
@@ -309,12 +327,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
 
     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 )
     {
@@ -461,20 +474,15 @@ void wxListBox::GtkAddItem( const wxString &item, int pos )
                         (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 );
@@ -853,7 +861,7 @@ GtkWidget *wxListBox::GetConnectWidget()
 
 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)
@@ -926,4 +934,9 @@ void wxListBox::OnInternalIdle()
     UpdateWindowUI();
 }
 
+wxSize wxListBox::DoGetBestSize() const
+{
+    return wxSize(100, 110);
+}
+
 #endif