+extern "C" {
+static gint gtk_popup_button_press (GtkWidget *widget, GdkEvent *gdk_event, wxPopupWindow* win )
+{
+ GtkWidget *child = gtk_get_event_widget (gdk_event);
+
+ /* Ignore events sent out before we connected to the signal */
+ if (win->m_time >= ((GdkEventButton*)gdk_event)->time)
+ return FALSE;
+
+ /* We don't ask for button press events on the grab widget, so
+ * if an event is reported directly to the grab widget, it must
+ * be on a window outside the application (and thus we remove
+ * the popup window). Otherwise, we check if the widget is a child
+ * of the grab widget, and only remove the popup window if it
+ * is not. */
+ if (child != widget)
+ {
+ while (child)
+ {
+ if (child == widget)
+ return FALSE;
+ child = child->parent;
+ }
+ }
+
+ wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
+ event.SetEventObject( win );
+
+ (void)win->GetEventHandler()->ProcessEvent( event );
+
+ return TRUE;
+}
+}