X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fec195b2c10388d2b4e0c87d16aa9dc1ffc449a7..884a37aed25b5cdabcc6f9f7604878aa97ecb031:/src/gtk1/listbox.cpp diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 37154d6eda..d8810ddae0 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -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 );