]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/listbox.cpp
fixed subtle SetDirectory bug re-introduced by latest changes (explained in comment...
[wxWidgets.git] / src / gtk / listbox.cpp
index 37154d6edaf17c94dcc63c8d03043d189a416269..d8810ddae08a9a1170624ff9a3d1f597483d0dd9 100644 (file)
@@ -51,6 +51,8 @@ extern bool           g_blockEventsOnDrag;
 extern bool           g_blockEventsOnScroll;
 extern wxCursor       g_globalCursor;
 extern wxWindowGTK   *g_delayedFocus;
+extern wxWindowGTK   *g_focusWindow;
+extern wxWindowGTK   *g_focusWindowLast;
 
 static bool       g_hasDoubleClicked = FALSE;
 
@@ -87,6 +89,68 @@ extern "C" gint wxlistbox_idle_callback( gpointer gdata )
     return TRUE;
 }
 
+//-----------------------------------------------------------------------------
+// "focus_in_event"
+//-----------------------------------------------------------------------------
+
+static gint gtk_listitem_focus_in_callback( GtkWidget *widget,
+                                          GdkEvent *WXUNUSED(event),
+                                          wxWindow *win )
+{
+    if (g_isIdle)
+        wxapp_install_idle_handler();
+
+    g_focusWindowLast =
+    g_focusWindow = win;
+
+    // does the window itself think that it has the focus?
+    if ( !win->m_hasFocus )
+    {
+        // not yet, notify it
+        win->m_hasFocus = TRUE;
+        
+        wxChildFocusEvent eventChildFocus(win);
+        (void)win->GetEventHandler()->ProcessEvent(eventChildFocus);
+
+        wxFocusEvent eventFocus(wxEVT_SET_FOCUS, win->GetId());
+        eventFocus.SetEventObject(win);
+
+        (void)win->GetEventHandler()->ProcessEvent(eventFocus);
+    }
+
+    return FALSE;
+}
+
+//-----------------------------------------------------------------------------
+// "focus_out_event"
+//-----------------------------------------------------------------------------
+
+static gint gtk_listitem_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk_event, wxWindowGTK *win )
+{
+    if (g_isIdle)
+        wxapp_install_idle_handler();
+
+    g_focusWindow = (wxWindowGTK *)NULL;
+
+    // don't send the window a kill focus event if it thinks that it doesn't
+    // have focus already
+    if ( win->m_hasFocus )
+    {
+        win->m_hasFocus = FALSE;
+
+        wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
+        event.SetEventObject( win );
+
+        // even if we did process the event in wx code, still let GTK itself
+        // process it too as otherwise bad things happen, especially in GTK2
+        // where the text control simply aborts the program if it doesn't get
+        // the matching focus out event
+        (void)win->GetEventHandler()->ProcessEvent( event );
+    }
+
+    return FALSE;
+}
+
 //-----------------------------------------------------------------------------
 // "button_release_event"
 //-----------------------------------------------------------------------------
@@ -607,6 +671,14 @@ void wxListBox::GtkAddItem( const wxString &item, int pos )
                            (GtkSignalFunc)gtk_listbox_key_press_callback,
                            (gpointer)this );
 
+
+    gtk_signal_connect( GTK_OBJECT(list_item), "focus_in_event",
+            GTK_SIGNAL_FUNC(gtk_listitem_focus_in_callback), (gpointer)this );
+
+    gtk_signal_connect( GTK_OBJECT(list_item), "focus_out_event",
+            GTK_SIGNAL_FUNC(gtk_listitem_focus_out_callback), (gpointer)this );
+
+
     ConnectWidget( list_item );
 
     gtk_widget_show( list_item );