* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* By Owen Taylor <otaylor@gtk.org> 98/4/4 */
/*
- * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include "gdkconfig.h"
-
-#if defined (GDK_WINDOWING_X11)
-#include "x11/gdkx.h"
-#elif defined (GDK_WINDOWING_WIN32)
-#include "win32/gdkwin32.h"
-#elif defined(GDK_WINDOWING_FB)
-#include "linux-fb/gdkfb.h"
-#endif
+#include "config.h"
+#include <string.h>
#include "gdk/gdkkeysyms.h"
+#include "gtkmain.h"
+#include "gtkmarshalers.h"
#include "gtkwindow.h"
-#include "gtksignal.h"
+#include "gtkplug.h"
+#include "gtkprivate.h"
#include "gtksocket.h"
+#include "gtksocketprivate.h"
#include "gtkdnd.h"
+#include "gtkintl.h"
-#ifdef GDK_WINDOWING_X11
+
+/**
+ * SECTION:gtksocket
+ * @Short_description: Container for widgets from other processes
+ * @Title: GtkSocket
+ * @See_also: #GtkPlug, <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
+ *
+ * Together with #GtkPlug, #GtkSocket provides the ability
+ * to embed widgets from one process into another process
+ * in a fashion that is transparent to the user. One
+ * process creates a #GtkSocket widget and passes
+ * that widget's window ID to the other process,
+ * which then creates a #GtkPlug with that window ID.
+ * Any widgets contained in the #GtkPlug then will appear
+ * inside the first application's window.
+ *
+ * The socket's window ID is obtained by using
+ * gtk_socket_get_id(). Before using this function,
+ * the socket must have been realized, and for hence,
+ * have been added to its parent.
+ *
+ * <example>
+ * <title>Obtaining the window ID of a socket.</title>
+ * <programlisting>
+ * GtkWidget *socket = gtk_socket_new (<!-- -->);
+ * gtk_widget_show (socket);
+ * gtk_container_add (GTK_CONTAINER (parent), socket);
+ *
+ * /<!---->* The following call is only necessary if one of
+ * * the ancestors of the socket is not yet visible.
+ * *<!---->/
+ * gtk_widget_realize (socket);
+ * g_print ("The ID of the sockets window is %#x\n",
+ * gtk_socket_get_id (socket));
+ * </programlisting>
+ * </example>
+ *
+ * Note that if you pass the window ID of the socket to another
+ * process that will create a plug in the socket, you
+ * must make sure that the socket widget is not destroyed
+ * until that plug is created. Violating this rule will
+ * cause unpredictable consequences, the most likely
+ * consequence being that the plug will appear as a
+ * separate toplevel window. You can check if the plug
+ * has been created by using gtk_socket_get_plug_window(). If
+ * it returns a non-%NULL value, then the plug has been
+ * successfully created inside of the socket.
+ *
+ * When GTK+ is notified that the embedded window has been
+ * destroyed, then it will destroy the socket as well. You
+ * should always, therefore, be prepared for your sockets
+ * to be destroyed at any time when the main event loop
+ * is running. To prevent this from happening, you can
+ * connect to the #GtkSocket::plug-removed signal.
+ *
+ * The communication between a #GtkSocket and a #GtkPlug follows the
+ * <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
+ * protocol. This protocol has also been implemented in other toolkits, e.g.
+ * <application>Qt</application>, allowing the same level of integration
+ * when embedding a <application>Qt</application> widget in GTK or vice versa.
+ *
+ * A socket can also be used to swallow arbitrary
+ * pre-existing top-level windows using gtk_socket_steal(),
+ * though the integration when this is done will not be as close
+ * as between a #GtkPlug and a #GtkSocket.
+ *
+ * <note>
+ * The #GtkPlug and #GtkSocket widgets are currently not available
+ * on all platforms supported by GTK+.
+ * </note>
+ */
/* Forward declararations */
-static void gtk_socket_class_init (GtkSocketClass *klass);
-static void gtk_socket_init (GtkSocket *socket);
-static void gtk_socket_realize (GtkWidget *widget);
-static void gtk_socket_unrealize (GtkWidget *widget);
-static void gtk_socket_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_socket_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static gint gtk_socket_focus_in_event (GtkWidget *widget,
- GdkEventFocus *event);
-static void gtk_socket_claim_focus (GtkSocket *socket);
-static gint gtk_socket_focus_out_event (GtkWidget *widget,
- GdkEventFocus *event);
-static void gtk_socket_send_configure_event (GtkSocket *socket);
-static gint gtk_socket_focus (GtkContainer *container,
- GtkDirectionType direction);
-static GdkFilterReturn gtk_socket_filter_func (GdkXEvent *gdk_xevent,
- GdkEvent *event,
- gpointer data);
-
-/* From Tk */
-#define EMBEDDED_APP_WANTS_FOCUS NotifyNormal+20
+static void gtk_socket_finalize (GObject *object);
+static void gtk_socket_notify (GObject *object,
+ GParamSpec *pspec);
+static void gtk_socket_realize (GtkWidget *widget);
+static void gtk_socket_unrealize (GtkWidget *widget);
+static void gtk_socket_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void gtk_socket_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static void gtk_socket_hierarchy_changed (GtkWidget *widget,
+ GtkWidget *old_toplevel);
+static void gtk_socket_grab_notify (GtkWidget *widget,
+ gboolean was_grabbed);
+static gboolean gtk_socket_key_event (GtkWidget *widget,
+ GdkEventKey *event);
+static gboolean gtk_socket_focus (GtkWidget *widget,
+ GtkDirectionType direction);
+static void gtk_socket_remove (GtkContainer *container,
+ GtkWidget *widget);
+static void gtk_socket_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data);
+
/* Local data */
-static GtkWidgetClass *parent_class = NULL;
+typedef struct
+{
+ guint accel_key;
+ GdkModifierType accel_mods;
+} GrabbedKey;
+
+enum {
+ PLUG_ADDED,
+ PLUG_REMOVED,
+ LAST_SIGNAL
+};
+
+static guint socket_signals[LAST_SIGNAL] = { 0 };
-GtkType
-gtk_socket_get_type (void)
+/*
+ * _gtk_socket_get_private:
+ *
+ * @socket: a #GtkSocket
+ *
+ * Returns the private data associated with a GtkSocket, creating it
+ * first if necessary.
+ */
+GtkSocketPrivate *
+_gtk_socket_get_private (GtkSocket *socket)
{
- static GtkType socket_type = 0;
+ return G_TYPE_INSTANCE_GET_PRIVATE (socket, GTK_TYPE_SOCKET, GtkSocketPrivate);
+}
- if (!socket_type)
- {
- static const GTypeInfo socket_info =
- {
- sizeof (GtkSocketClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_socket_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkSocket),
- 16, /* n_preallocs */
- (GInstanceInitFunc) gtk_socket_init,
- };
-
- socket_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkSocket", &socket_info);
- }
+G_DEFINE_TYPE (GtkSocket, gtk_socket, GTK_TYPE_CONTAINER)
+
+static void
+gtk_socket_finalize (GObject *object)
+{
+ GtkSocket *socket = GTK_SOCKET (object);
+
+ g_object_unref (socket->accel_group);
+ socket->accel_group = NULL;
- return socket_type;
+ G_OBJECT_CLASS (gtk_socket_parent_class)->finalize (object);
}
static void
gtk_socket_class_init (GtkSocketClass *class)
{
- GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
+ GObjectClass *gobject_class;
- object_class = (GtkObjectClass*) class;
+ gobject_class = (GObjectClass *) class;
widget_class = (GtkWidgetClass*) class;
container_class = (GtkContainerClass*) class;
- parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
+ gobject_class->finalize = gtk_socket_finalize;
+ gobject_class->notify = gtk_socket_notify;
widget_class->realize = gtk_socket_realize;
widget_class->unrealize = gtk_socket_unrealize;
widget_class->size_request = gtk_socket_size_request;
widget_class->size_allocate = gtk_socket_size_allocate;
- widget_class->focus_in_event = gtk_socket_focus_in_event;
- widget_class->focus_out_event = gtk_socket_focus_out_event;
-
- container_class->focus = gtk_socket_focus;
+ widget_class->hierarchy_changed = gtk_socket_hierarchy_changed;
+ widget_class->grab_notify = gtk_socket_grab_notify;
+ widget_class->key_press_event = gtk_socket_key_event;
+ widget_class->key_release_event = gtk_socket_key_event;
+ widget_class->focus = gtk_socket_focus;
+
+ /* We don't want to show_all/hide_all the in-process
+ * plug, if any.
+ */
+ widget_class->show_all = gtk_widget_show;
+ widget_class->hide_all = gtk_widget_hide;
+
+ container_class->remove = gtk_socket_remove;
+ container_class->forall = gtk_socket_forall;
+
+ /**
+ * GtkSocket::plug-added:
+ * @socket_: the object which received the signal
+ *
+ * This signal is emitted when a client is successfully
+ * added to the socket.
+ */
+ socket_signals[PLUG_ADDED] =
+ g_signal_new (I_("plug-added"),
+ G_OBJECT_CLASS_TYPE (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkSocketClass, plug_added),
+ NULL, NULL,
+ _gtk_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ /**
+ * GtkSocket::plug-removed:
+ * @socket_: the object which received the signal
+ *
+ * This signal is emitted when a client is removed from the socket.
+ * The default action is to destroy the #GtkSocket widget, so if you
+ * want to reuse it you must add a signal handler that returns %TRUE.
+ *
+ * Return value: %TRUE to stop other handlers from being invoked.
+ */
+ socket_signals[PLUG_REMOVED] =
+ g_signal_new (I_("plug-removed"),
+ G_OBJECT_CLASS_TYPE (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkSocketClass, plug_removed),
+ _gtk_boolean_handled_accumulator, NULL,
+ _gtk_marshal_BOOLEAN__VOID,
+ G_TYPE_BOOLEAN, 0);
+
+ g_type_class_add_private (gobject_class, sizeof (GtkSocketPrivate));
}
static void
socket->current_height = 0;
socket->plug_window = NULL;
- socket->same_app = FALSE;
+ socket->plug_widget = NULL;
socket->focus_in = FALSE;
socket->have_size = FALSE;
socket->need_map = FALSE;
+ socket->active = FALSE;
+
+ socket->accel_group = gtk_accel_group_new ();
+ g_object_set_data (G_OBJECT (socket->accel_group), I_("gtk-socket"), socket);
}
+/**
+ * gtk_socket_new:
+ *
+ * Create a new empty #GtkSocket.
+ *
+ * Return value: the new #GtkSocket.
+ **/
GtkWidget*
gtk_socket_new (void)
{
GtkSocket *socket;
- socket = gtk_type_new (GTK_TYPE_SOCKET);
+ socket = g_object_new (GTK_TYPE_SOCKET, NULL);
return GTK_WIDGET (socket);
}
+/**
+ * gtk_socket_add_id:
+ * @socket_: a #GtkSocket
+ * @window_id: the window ID of a client participating in the XEMBED protocol.
+ *
+ * Adds an XEMBED client, such as a #GtkPlug, to the #GtkSocket. The
+ * client may be in the same process or in a different process.
+ *
+ * To embed a #GtkPlug in a #GtkSocket, you can either create the
+ * #GtkPlug with <literal>gtk_plug_new (0)</literal>, call
+ * gtk_plug_get_id() to get the window ID of the plug, and then pass that to the
+ * gtk_socket_add_id(), or you can call gtk_socket_get_id() to get the
+ * window ID for the socket, and call gtk_plug_new() passing in that
+ * ID.
+ *
+ * The #GtkSocket must have already be added into a toplevel window
+ * before you can make this call.
+ **/
void
-gtk_socket_steal (GtkSocket *socket, GdkNativeWindow id)
+gtk_socket_add_id (GtkSocket *socket,
+ GdkNativeWindow window_id)
{
- GtkWidget *widget;
-
- widget = GTK_WIDGET (socket);
-
- socket->plug_window = gdk_window_lookup (id);
+ g_return_if_fail (GTK_IS_SOCKET (socket));
+ g_return_if_fail (GTK_WIDGET_ANCHORED (socket));
- gdk_error_trap_push ();
-
- if (socket->plug_window && socket->plug_window->user_data)
- {
- /*
- GtkWidget *child_widget;
+ if (!gtk_widget_get_realized (GTK_WIDGET (socket)))
+ gtk_widget_realize (GTK_WIDGET (socket));
- child_widget = GTK_WIDGET (socket->plug_window->user_data);
- */
+ _gtk_socket_add_window (socket, window_id, TRUE);
+}
- g_warning("Stealing from same app not yet implemented");
-
- socket->same_app = TRUE;
- }
- else
- {
- socket->plug_window = gdk_window_foreign_new (id);
- if (!socket->plug_window) /* was deleted before we could get it */
- {
- gdk_error_trap_pop ();
- return;
- }
-
- socket->same_app = FALSE;
- socket->have_size = FALSE;
+/**
+ * gtk_socket_get_id:
+ * @socket_: a #GtkSocket.
+ *
+ * Gets the window ID of a #GtkSocket widget, which can then
+ * be used to create a client embedded inside the socket, for
+ * instance with gtk_plug_new().
+ *
+ * The #GtkSocket must have already be added into a toplevel window
+ * before you can make this call.
+ *
+ * Return value: the window ID for the socket
+ **/
+GdkNativeWindow
+gtk_socket_get_id (GtkSocket *socket)
+{
+ g_return_val_if_fail (GTK_IS_SOCKET (socket), 0);
+ g_return_val_if_fail (GTK_WIDGET_ANCHORED (socket), 0);
- XSelectInput (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW(socket->plug_window),
- StructureNotifyMask | PropertyChangeMask);
+ if (!gtk_widget_get_realized (GTK_WIDGET (socket)))
+ gtk_widget_realize (GTK_WIDGET (socket));
- gtk_widget_queue_resize (widget);
- }
+ return _gtk_socket_windowing_get_id (socket);
+}
- gdk_window_hide (socket->plug_window);
- gdk_window_reparent (socket->plug_window, widget->window, 0, 0);
+/**
+ * gtk_socket_get_plug_window:
+ * @socket_: a #GtkSocket.
+ *
+ * Retrieves the window of the plug. Use this to check if the plug has
+ * been created inside of the socket.
+ *
+ * Return value: the window of the plug if available, or %NULL
+ *
+ * Since: 2.14
+ **/
+GdkWindow*
+gtk_socket_get_plug_window (GtkSocket *socket)
+{
+ g_return_val_if_fail (GTK_IS_SOCKET (socket), NULL);
- gdk_flush ();
- gdk_error_trap_pop ();
-
- socket->need_map = TRUE;
+ return socket->plug_window;
}
static void
gtk_socket_realize (GtkWidget *widget)
{
- GtkSocket *socket;
+ GtkSocket *socket = GTK_SOCKET (widget);
GdkWindowAttr attributes;
gint attributes_mask;
- XWindowAttributes xattrs;
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_SOCKET (widget));
-
- socket = GTK_SOCKET (widget);
- GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+ gtk_widget_set_realized (widget, TRUE);
attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = widget->allocation.x;
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
- XGetWindowAttributes (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW (widget->window),
- &xattrs);
-
- XSelectInput (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW(widget->window),
- xattrs.your_event_mask |
- SubstructureNotifyMask | SubstructureRedirectMask);
+ _gtk_socket_windowing_realize_window (socket);
- gdk_window_add_filter (widget->window, gtk_socket_filter_func, widget);
-
- GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+ gdk_window_add_filter (widget->window,
+ _gtk_socket_windowing_filter_func,
+ widget);
/* We sync here so that we make sure that if the XID for
* our window is passed to another application, SubstructureRedirectMask
* will be set by the time the other app creates its window.
*/
- gdk_flush();
+ gdk_display_sync (gtk_widget_get_display (widget));
+}
+
+/**
+ * _gtk_socket_end_embedding:
+ *
+ * @socket: a #GtkSocket
+ *
+ * Called to end the embedding of a plug in the socket.
+ */
+void
+_gtk_socket_end_embedding (GtkSocket *socket)
+{
+ GtkSocketPrivate *private = _gtk_socket_get_private (socket);
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
+
+ if (GTK_IS_WINDOW (toplevel))
+ _gtk_socket_windowing_end_embedding_toplevel (socket);
+
+ g_object_unref (socket->plug_window);
+ socket->plug_window = NULL;
+ socket->current_width = 0;
+ socket->current_height = 0;
+ private->resize_count = 0;
+
+ gtk_accel_group_disconnect (socket->accel_group, NULL);
}
static void
gtk_socket_unrealize (GtkWidget *widget)
{
- GtkSocket *socket;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_SOCKET (widget));
+ GtkSocket *socket = GTK_SOCKET (widget);
- socket = GTK_SOCKET (widget);
+ gtk_widget_set_realized (widget, FALSE);
- if (socket->plug_window)
+ if (socket->plug_widget)
{
- GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
- if (toplevel && GTK_IS_WINDOW (toplevel))
- gtk_window_remove_embedded_xid (GTK_WINDOW (toplevel),
- GDK_WINDOW_XWINDOW (socket->plug_window));
+ _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
+ }
+ else if (socket->plug_window)
+ {
+ _gtk_socket_end_embedding (socket);
}
- if (GTK_WIDGET_CLASS (parent_class)->unrealize)
- (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+ GTK_WIDGET_CLASS (gtk_socket_parent_class)->unrealize (widget);
}
-
-static void
+
+static void
gtk_socket_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
- GtkSocket *socket;
+ GtkSocket *socket = GTK_SOCKET (widget);
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_SOCKET (widget));
- g_return_if_fail (requisition != NULL);
-
- socket = GTK_SOCKET (widget);
-
- if (!socket->have_size && socket->plug_window)
+ if (socket->plug_widget)
{
- XSizeHints hints;
- long supplied;
+ gtk_widget_size_request (socket->plug_widget, requisition);
+ }
+ else
+ {
+ if (socket->is_mapped && !socket->have_size && socket->plug_window)
+ _gtk_socket_windowing_size_request (socket);
- gdk_error_trap_push ();
-
- if (XGetWMNormalHints (GDK_DISPLAY(),
- GDK_WINDOW_XWINDOW (socket->plug_window),
- &hints, &supplied))
+ if (socket->is_mapped && socket->have_size)
{
- /* This is obsolete, according the X docs, but many programs
- * still use it */
- if (hints.flags & (PSize | USSize))
- {
- socket->request_width = hints.width;
- socket->request_height = hints.height;
- }
- else if (hints.flags & PMinSize)
- {
- socket->request_width = hints.min_width;
- socket->request_height = hints.min_height;
- }
- else if (hints.flags & PBaseSize)
- {
- socket->request_width = hints.base_width;
- socket->request_height = hints.base_height;
- }
+ requisition->width = MAX (socket->request_width, 1);
+ requisition->height = MAX (socket->request_height, 1);
+ }
+ else
+ {
+ requisition->width = 1;
+ requisition->height = 1;
}
- socket->have_size = TRUE; /* don't check again? */
-
- gdk_error_trap_pop ();
}
-
- requisition->width = MAX (socket->request_width, 1);
- requisition->height = MAX (socket->request_height, 1);
}
static void
gtk_socket_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
- GtkSocket *socket;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_SOCKET (widget));
- g_return_if_fail (allocation != NULL);
-
- socket = GTK_SOCKET (widget);
+ GtkSocket *socket = GTK_SOCKET (widget);
widget->allocation = *allocation;
- if (GTK_WIDGET_REALIZED (widget))
+ if (gtk_widget_get_realized (widget))
{
gdk_window_move_resize (widget->window,
allocation->x, allocation->y,
allocation->width, allocation->height);
- if (socket->plug_window)
+ if (socket->plug_widget)
+ {
+ GtkAllocation child_allocation;
+
+ child_allocation.x = 0;
+ child_allocation.y = 0;
+ child_allocation.width = allocation->width;
+ child_allocation.height = allocation->height;
+
+ gtk_widget_size_allocate (socket->plug_widget, &child_allocation);
+ }
+ else if (socket->plug_window)
{
+ GtkSocketPrivate *private = _gtk_socket_get_private (socket);
+
gdk_error_trap_push ();
- if (!socket->need_map &&
- (allocation->width == socket->current_width) &&
- (allocation->height == socket->current_height))
- {
- gtk_socket_send_configure_event (socket);
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - allocated no change: %d %d",
- allocation->width, allocation->height));
- }
- else
+ if (allocation->width != socket->current_width ||
+ allocation->height != socket->current_height)
{
gdk_window_move_resize (socket->plug_window,
0, 0,
allocation->width, allocation->height);
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - allocated: %d %d",
- allocation->width, allocation->height));
+ if (private->resize_count)
+ private->resize_count--;
+
+ GTK_NOTE (PLUGSOCKET,
+ g_message ("GtkSocket - allocated: %d %d",
+ allocation->width, allocation->height));
socket->current_width = allocation->width;
socket->current_height = allocation->height;
}
socket->need_map = FALSE;
}
- gdk_flush ();
+ while (private->resize_count)
+ {
+ _gtk_socket_windowing_send_configure_event (socket);
+ private->resize_count--;
+ GTK_NOTE (PLUGSOCKET,
+ g_message ("GtkSocket - sending synthetic configure: %d %d",
+ allocation->width, allocation->height));
+ }
+
+ gdk_display_sync (gtk_widget_get_display (widget));
gdk_error_trap_pop ();
}
}
}
-static gint
-gtk_socket_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
+static gboolean
+activate_key (GtkAccelGroup *accel_group,
+ GObject *acceleratable,
+ guint accel_key,
+ GdkModifierType accel_mods,
+ GrabbedKey *grabbed_key)
{
- GtkSocket *socket;
- g_return_val_if_fail (GTK_IS_SOCKET (widget), FALSE);
- socket = GTK_SOCKET (widget);
+ GdkEvent *gdk_event = gtk_get_current_event ();
+
+ GtkSocket *socket = g_object_get_data (G_OBJECT (accel_group), "gtk-socket");
+ gboolean retval = FALSE;
- if (socket->focus_in && socket->plug_window)
+ if (gdk_event && gdk_event->type == GDK_KEY_PRESS && socket->plug_window)
{
- gdk_error_trap_push ();
- XSetInputFocus (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW (socket->plug_window),
- RevertToParent, GDK_CURRENT_TIME);
- gdk_flush();
- gdk_error_trap_pop ();
+ _gtk_socket_windowing_send_key_event (socket, gdk_event, FALSE);
+ retval = TRUE;
}
-
- return TRUE;
+
+ if (gdk_event)
+ gdk_event_free (gdk_event);
+
+ return retval;
}
-static gint
-gtk_socket_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
+static gboolean
+find_accel_key (GtkAccelKey *key,
+ GClosure *closure,
+ gpointer data)
{
- GtkWidget *toplevel;
- GtkSocket *socket;
+ GrabbedKey *grabbed_key = data;
+
+ return (key->accel_key == grabbed_key->accel_key &&
+ key->accel_mods == grabbed_key->accel_mods);
+}
- g_return_val_if_fail (GTK_IS_SOCKET (widget), FALSE);
- socket = GTK_SOCKET (widget);
+/**
+ * _gtk_socket_add_grabbed_key:
+ *
+ * @socket: a #GtkSocket
+ * @keyval: a key
+ * @modifiers: modifiers for the key
+ *
+ * Called from the GtkSocket platform-specific backend when the
+ * corresponding plug has told the socket to grab a key.
+ */
+void
+_gtk_socket_add_grabbed_key (GtkSocket *socket,
+ guint keyval,
+ GdkModifierType modifiers)
+{
+ GClosure *closure;
+ GrabbedKey *grabbed_key;
- toplevel = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
+ grabbed_key = g_new (GrabbedKey, 1);
- if (toplevel)
+ grabbed_key->accel_key = keyval;
+ grabbed_key->accel_mods = modifiers;
+
+ if (gtk_accel_group_find (socket->accel_group,
+ find_accel_key,
+ &grabbed_key))
{
- XSetInputFocus (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW (toplevel->window),
- RevertToParent, CurrentTime); /* FIXME? */
+ g_warning ("GtkSocket: request to add already present grabbed key %u,%#x\n",
+ keyval, modifiers);
+ g_free (grabbed_key);
+ return;
}
- socket->focus_in = FALSE;
+ closure = g_cclosure_new (G_CALLBACK (activate_key), grabbed_key, (GClosureNotify)g_free);
+
+ gtk_accel_group_connect (socket->accel_group, keyval, modifiers, GTK_ACCEL_LOCKED,
+ closure);
+}
- return TRUE;
+/**
+ * _gtk_socket_remove_grabbed_key:
+ *
+ * @socket: a #GtkSocket
+ * @keyval: a key
+ * @modifiers: modifiers for the key
+ *
+ * Called from the GtkSocket backend when the corresponding plug has
+ * told the socket to remove a key grab.
+ */
+void
+_gtk_socket_remove_grabbed_key (GtkSocket *socket,
+ guint keyval,
+ GdkModifierType modifiers)
+{
+ if (!gtk_accel_group_disconnect_key (socket->accel_group, keyval, modifiers))
+ g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
+ keyval, modifiers);
}
static void
-gtk_socket_claim_focus (GtkSocket *socket)
+socket_update_focus_in (GtkSocket *socket)
{
-
- socket->focus_in = TRUE;
-
- /* Oh, the trickery... */
-
- GTK_WIDGET_SET_FLAGS (socket, GTK_CAN_FOCUS);
- gtk_widget_grab_focus (GTK_WIDGET (socket));
- GTK_WIDGET_UNSET_FLAGS (socket, GTK_CAN_FOCUS);
-
- /* FIXME: we might grab the focus even if we don't have
- * it as an app... (and see _focus_in ()) */
+ gboolean focus_in = FALSE;
+
if (socket->plug_window)
{
- gdk_error_trap_push ();
- XSetInputFocus (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW (socket->plug_window),
- RevertToParent, GDK_CURRENT_TIME);
- gdk_flush ();
- gdk_error_trap_pop ();
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
+
+ if (gtk_widget_is_toplevel (toplevel) &&
+ GTK_WINDOW (toplevel)->has_toplevel_focus &&
+ gtk_widget_is_focus (GTK_WIDGET (socket)))
+ focus_in = TRUE;
+ }
+
+ if (focus_in != socket->focus_in)
+ {
+ socket->focus_in = focus_in;
+
+ _gtk_socket_windowing_focus_change (socket, focus_in);
}
}
-static gint
-gtk_socket_focus (GtkContainer *container, GtkDirectionType direction)
+static void
+socket_update_active (GtkSocket *socket)
{
- GtkSocket *socket;
+ gboolean active = FALSE;
- g_return_val_if_fail (GTK_IS_SOCKET (container), FALSE);
-
- socket = GTK_SOCKET (container);
-
- if (!socket->focus_in && socket->plug_window)
+ if (socket->plug_window)
{
- XEvent xevent;
-
- gtk_socket_claim_focus (socket);
-
- xevent.xkey.type = KeyPress;
- xevent.xkey.display = GDK_DISPLAY ();
- xevent.xkey.window = GDK_WINDOW_XWINDOW (socket->plug_window);
- xevent.xkey.root = GDK_ROOT_WINDOW (); /* FIXME */
- xevent.xkey.time = GDK_CURRENT_TIME; /* FIXME */
- /* FIXME, the following might cause big problems for
- * non-GTK apps */
- xevent.xkey.x = 0;
- xevent.xkey.y = 0;
- xevent.xkey.x_root = 0;
- xevent.xkey.y_root = 0;
- xevent.xkey.state = 0;
- xevent.xkey.same_screen = TRUE; /* FIXME ? */
-
- switch (direction)
- {
- case GTK_DIR_UP:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Up);
- break;
- case GTK_DIR_DOWN:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Down);
- break;
- case GTK_DIR_LEFT:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Left);
- break;
- case GTK_DIR_RIGHT:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Right);
- break;
- case GTK_DIR_TAB_FORWARD:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Tab);
- break;
- case GTK_DIR_TAB_BACKWARD:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Tab);
- xevent.xkey.state = ShiftMask;
- break;
- }
-
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
- gdk_error_trap_push ();
- XSendEvent (gdk_display,
- GDK_WINDOW_XWINDOW (socket->plug_window),
- False, NoEventMask, &xevent);
- gdk_flush();
- gdk_error_trap_pop ();
-
- return TRUE;
+ if (gtk_widget_is_toplevel (toplevel) &&
+ GTK_WINDOW (toplevel)->is_active)
+ active = TRUE;
}
- else
+
+ if (active != socket->active)
{
- return FALSE;
+ socket->active = active;
+
+ _gtk_socket_windowing_update_active (socket, active);
}
}
static void
-gtk_socket_send_configure_event (GtkSocket *socket)
+gtk_socket_hierarchy_changed (GtkWidget *widget,
+ GtkWidget *old_toplevel)
{
- XEvent event;
+ GtkSocket *socket = GTK_SOCKET (widget);
+ GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
- g_return_if_fail (socket->plug_window != NULL);
+ if (toplevel && !GTK_IS_WINDOW (toplevel))
+ toplevel = NULL;
- event.xconfigure.type = ConfigureNotify;
- event.xconfigure.display = gdk_display;
-
- event.xconfigure.event = GDK_WINDOW_XWINDOW (socket->plug_window);
- event.xconfigure.window = GDK_WINDOW_XWINDOW (socket->plug_window);
+ if (toplevel != socket->toplevel)
+ {
+ if (socket->toplevel)
+ {
+ gtk_window_remove_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
+ g_signal_handlers_disconnect_by_func (socket->toplevel,
+ socket_update_focus_in,
+ socket);
+ g_signal_handlers_disconnect_by_func (socket->toplevel,
+ socket_update_active,
+ socket);
+ }
- event.xconfigure.x = 0;
- event.xconfigure.y = 0;
- event.xconfigure.width = GTK_WIDGET(socket)->allocation.width;
- event.xconfigure.height = GTK_WIDGET(socket)->allocation.height;
+ socket->toplevel = toplevel;
- event.xconfigure.border_width = 0;
- event.xconfigure.above = None;
- event.xconfigure.override_redirect = False;
+ if (toplevel)
+ {
+ gtk_window_add_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
+ g_signal_connect_swapped (socket->toplevel, "notify::has-toplevel-focus",
+ G_CALLBACK (socket_update_focus_in), socket);
+ g_signal_connect_swapped (socket->toplevel, "notify::is-active",
+ G_CALLBACK (socket_update_active), socket);
+ }
- gdk_error_trap_push ();
- XSendEvent (gdk_display,
- GDK_WINDOW_XWINDOW (socket->plug_window),
- False, NoEventMask, &event);
- gdk_flush ();
- gdk_error_trap_pop ();
+ socket_update_focus_in (socket);
+ socket_update_active (socket);
+ }
}
static void
-gtk_socket_add_window (GtkSocket *socket, GdkNativeWindow xid)
+gtk_socket_grab_notify (GtkWidget *widget,
+ gboolean was_grabbed)
{
- socket->plug_window = gdk_window_lookup (xid);
- socket->same_app = TRUE;
+ GtkSocket *socket = GTK_SOCKET (widget);
- if (!socket->plug_window)
+ if (!socket->same_app)
+ _gtk_socket_windowing_update_modality (socket, !was_grabbed);
+}
+
+static gboolean
+gtk_socket_key_event (GtkWidget *widget,
+ GdkEventKey *event)
+{
+ GtkSocket *socket = GTK_SOCKET (widget);
+
+ if (gtk_widget_has_focus (widget) && socket->plug_window && !socket->plug_widget)
{
- GtkWidget *toplevel;
- GdkDragProtocol protocol;
-
- socket->plug_window = gdk_window_foreign_new (xid);
- if (!socket->plug_window) /* Already gone */
- return;
-
- socket->same_app = FALSE;
+ _gtk_socket_windowing_send_key_event (socket, (GdkEvent *) event, FALSE);
- gdk_error_trap_push ();
- XSelectInput (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW(socket->plug_window),
- StructureNotifyMask | PropertyChangeMask);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+static void
+gtk_socket_notify (GObject *object,
+ GParamSpec *pspec)
+{
+ if (!strcmp (pspec->name, "is-focus"))
+ return;
+ socket_update_focus_in (GTK_SOCKET (object));
+}
+
+/**
+ * _gtk_socket_claim_focus:
+ *
+ * @socket: a #GtkSocket
+ * @send_event: huh?
+ *
+ * Claims focus for the socket. XXX send_event?
+ */
+void
+_gtk_socket_claim_focus (GtkSocket *socket,
+ gboolean send_event)
+{
+ GtkWidget *widget = GTK_WIDGET (socket);
+
+ if (!send_event)
+ socket->focus_in = TRUE; /* Otherwise, our notify handler will send FOCUS_IN */
- if (gdk_drag_get_protocol (xid, &protocol))
- gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
- protocol, TRUE);
- gdk_flush ();
- gdk_error_trap_pop ();
+ /* Oh, the trickery... */
+
+ gtk_widget_set_can_focus (widget, TRUE);
+ gtk_widget_grab_focus (widget);
+ gtk_widget_set_can_focus (widget, FALSE);
+}
- gdk_window_add_filter (socket->plug_window,
- gtk_socket_filter_func, socket);
+static gboolean
+gtk_socket_focus (GtkWidget *widget,
+ GtkDirectionType direction)
+{
+ GtkSocket *socket = GTK_SOCKET (widget);
- /* Add a pointer to the socket on our toplevel window */
+ if (socket->plug_widget)
+ return gtk_widget_child_focus (socket->plug_widget, direction);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
- if (toplevel && GTK_IS_WINDOW (toplevel))
- {
- gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
- }
+ if (!gtk_widget_is_focus (widget))
+ {
+ _gtk_socket_windowing_focus (socket, direction);
+ _gtk_socket_claim_focus (socket, FALSE);
+
+ return TRUE;
}
+ else
+ return FALSE;
}
-static GdkFilterReturn
-gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
+static void
+gtk_socket_remove (GtkContainer *container,
+ GtkWidget *child)
{
- GtkSocket *socket;
- GtkWidget *widget;
- XEvent *xevent;
+ GtkSocket *socket = GTK_SOCKET (container);
+
+ g_return_if_fail (child == socket->plug_widget);
+
+ _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
+}
+
+static void
+gtk_socket_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ GtkSocket *socket = GTK_SOCKET (container);
+
+ if (socket->plug_widget)
+ (* callback) (socket->plug_widget, callback_data);
+}
- GdkFilterReturn return_val;
+/**
+ * _gtk_socket_add_window:
+ *
+ * @socket: a #GtkSocket
+ * @xid: the native identifier for a window
+ * @need_reparent: whether the socket's plug's window needs to be
+ * reparented to the socket
+ *
+ * Adds a window to a GtkSocket.
+ */
+void
+_gtk_socket_add_window (GtkSocket *socket,
+ GdkNativeWindow xid,
+ gboolean need_reparent)
+{
+ GtkWidget *widget = GTK_WIDGET (socket);
+ GdkDisplay *display = gtk_widget_get_display (widget);
+ gpointer user_data = NULL;
- socket = GTK_SOCKET (data);
- widget = GTK_WIDGET (socket);
- xevent = (XEvent *)gdk_xevent;
+ socket->plug_window = gdk_window_lookup_for_display (display, xid);
- return_val = GDK_FILTER_CONTINUE;
+ if (socket->plug_window)
+ {
+ g_object_ref (socket->plug_window);
+ gdk_window_get_user_data (socket->plug_window, &user_data);
+ }
- switch (xevent->type)
+ if (user_data) /* A widget's window in this process */
{
- case CreateNotify:
- {
- XCreateWindowEvent *xcwe = &xevent->xcreatewindow;
-
- if (!socket->plug_window)
- {
- gtk_socket_add_window (socket, xcwe->window);
-
- gdk_error_trap_push ();
- gdk_window_move_resize(socket->plug_window,
- 0, 0,
- widget->allocation.width,
- widget->allocation.height);
- gdk_flush ();
- gdk_error_trap_pop ();
-
- socket->request_width = xcwe->width;
- socket->request_height = xcwe->height;
- socket->have_size = TRUE;
-
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - window created with size: %d %d",
- socket->request_width,
- socket->request_height));
-
- gtk_widget_queue_resize (widget);
- }
-
- return_val = GDK_FILTER_REMOVE;
-
- break;
- }
+ GtkWidget *child_widget = user_data;
- case ConfigureRequest:
- {
- XConfigureRequestEvent *xcre = &xevent->xconfigurerequest;
-
- if (!socket->plug_window)
- gtk_socket_add_window (socket, xcre->window);
-
- if (xcre->window == GDK_WINDOW_XWINDOW (socket->plug_window))
- {
- if (xcre->value_mask & (CWWidth | CWHeight))
- {
- socket->request_width = xcre->width;
- socket->request_height = xcre->height;
- socket->have_size = TRUE;
-
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - configure request: %d %d",
- socket->request_width,
- socket->request_height));
-
- gtk_widget_queue_resize (widget);
- }
- else if (xcre->value_mask & (CWX | CWY))
- {
- gtk_socket_send_configure_event (socket);
- }
- /* Ignore stacking requests. */
-
- return_val = GDK_FILTER_REMOVE;
- }
- break;
- }
-
- case DestroyNotify:
- {
- XDestroyWindowEvent *xdwe = &xevent->xdestroywindow;
-
- if (socket->plug_window &&
- (xdwe->window == GDK_WINDOW_XWINDOW (socket->plug_window)))
- {
- GtkWidget *toplevel;
-
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - destroy notify"));
-
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
- if (toplevel && GTK_IS_WINDOW (toplevel))
- gtk_window_remove_embedded_xid (GTK_WINDOW (toplevel), xdwe->window);
- gdk_window_destroy_notify (socket->plug_window);
- gtk_widget_destroy (widget);
-
- socket->plug_window = NULL;
-
- return_val = GDK_FILTER_REMOVE;
- }
- break;
- }
-
- case FocusIn:
- if (xevent->xfocus.mode == EMBEDDED_APP_WANTS_FOCUS)
- {
- gtk_socket_claim_focus (socket);
- }
- else if (xevent->xfocus.detail == NotifyInferior)
+ if (!GTK_IS_PLUG (child_widget))
{
-#if 0
- GtkWidget *toplevel;
- toplevel = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
+ g_warning (G_STRLOC ": Can't add non-GtkPlug to GtkSocket");
+ socket->plug_window = NULL;
+ gdk_error_trap_pop ();
- if (toplevel)
+ return;
+ }
+
+ _gtk_plug_add_to_socket (GTK_PLUG (child_widget), socket);
+ }
+ else /* A foreign window */
+ {
+ GtkWidget *toplevel;
+ GdkDragProtocol protocol;
+
+ gdk_error_trap_push ();
+
+ if (!socket->plug_window)
+ {
+ socket->plug_window = gdk_window_foreign_new_for_display (display, xid);
+ if (!socket->plug_window) /* was deleted before we could get it */
{
- XSetInputFocus (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW (toplevel->window),
- RevertToParent, CurrentTime); /* FIXME? */
+ gdk_error_trap_pop ();
+ return;
}
-#endif
}
- return_val = GDK_FILTER_REMOVE;
- break;
- case FocusOut:
- return_val = GDK_FILTER_REMOVE;
- break;
- case MapRequest:
- if (!socket->plug_window)
- gtk_socket_add_window (socket, xevent->xmaprequest.window);
- if (xevent->xmaprequest.window ==
- GDK_WINDOW_XWINDOW (socket->plug_window))
+ _gtk_socket_windowing_select_plug_window_input (socket);
+
+ if (gdk_error_trap_pop ())
{
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - Map Request"));
+ g_object_unref (socket->plug_window);
+ socket->plug_window = NULL;
+ return;
+ }
+
+ /* OK, we now will reliably get destroy notification on socket->plug_window */
- gdk_error_trap_push ();
- gdk_window_show (socket->plug_window);
- gdk_flush ();
- gdk_error_trap_pop ();
+ gdk_error_trap_push ();
- return_val = GDK_FILTER_REMOVE;
- }
- break;
- case PropertyNotify:
- if (xevent->xproperty.window ==
- GDK_WINDOW_XWINDOW (socket->plug_window))
+ if (need_reparent)
{
- GdkDragProtocol protocol;
-
- if ((xevent->xproperty.atom == gdk_atom_intern ("XdndAware", FALSE)) ||
- (xevent->xproperty.atom == gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE)))
- {
- gdk_error_trap_push ();
- if (gdk_drag_get_protocol (xevent->xproperty.window, &protocol))
- gtk_drag_dest_set_proxy (GTK_WIDGET (socket),
- socket->plug_window,
- protocol, TRUE);
- gdk_flush ();
- gdk_error_trap_pop ();
- }
- return_val = GDK_FILTER_REMOVE;
+ gdk_window_hide (socket->plug_window); /* Shouldn't actually be necessary for XEMBED, but just in case */
+ gdk_window_reparent (socket->plug_window, widget->window, 0, 0);
}
+
+ socket->have_size = FALSE;
+
+ _gtk_socket_windowing_embed_get_info (socket);
+
+ socket->need_map = socket->is_mapped;
+
+ if (gdk_drag_get_protocol_for_display (display, xid, &protocol))
+ gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
+ protocol, TRUE);
+
+ gdk_display_sync (display);
+ gdk_error_trap_pop ();
+
+ gdk_window_add_filter (socket->plug_window,
+ _gtk_socket_windowing_filter_func,
+ socket);
+
+ /* Add a pointer to the socket on our toplevel window */
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
+ if (GTK_IS_WINDOW (toplevel))
+ gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
+
+ _gtk_socket_windowing_embed_notify (socket);
+
+ socket_update_active (socket);
+ socket_update_focus_in (socket);
+
+ gtk_widget_queue_resize (GTK_WIDGET (socket));
}
- return return_val;
+ if (socket->plug_window)
+ g_signal_emit (socket, socket_signals[PLUG_ADDED], 0);
}
-#else
-
-GtkType
-gtk_socket_get_type (void)
+/**
+ * _gtk_socket_handle_map_request:
+ *
+ * @socket: a #GtkSocket
+ *
+ * Called from the GtkSocket backend when the plug has been mapped.
+ */
+void
+_gtk_socket_handle_map_request (GtkSocket *socket)
{
- g_error ("GtkSocket not implemented");
- return 0;
+ if (!socket->is_mapped)
+ {
+ socket->is_mapped = TRUE;
+ socket->need_map = TRUE;
+
+ gtk_widget_queue_resize (GTK_WIDGET (socket));
+ }
}
-GtkWidget*
-gtk_socket_new ()
+/**
+ * _gtk_socket_unmap_notify:
+ *
+ * @socket: a #GtkSocket
+ *
+ * Called from the GtkSocket backend when the plug has been unmapped ???
+ */
+void
+_gtk_socket_unmap_notify (GtkSocket *socket)
{
- g_error ("GtkSocket not implemented");
- return NULL;
+ if (socket->is_mapped)
+ {
+ socket->is_mapped = FALSE;
+ gtk_widget_queue_resize (GTK_WIDGET (socket));
+ }
}
-void
-gtk_socket_steal (GtkSocket *socket, GdkNativeWindow id)
+/**
+ * _gtk_socket_advance_toplevel_focus:
+ *
+ * @socket: a #GtkSocket
+ * @direction: a direction
+ *
+ * Called from the GtkSocket backend when the corresponding plug
+ * has told the socket to move the focus.
+ */
+void
+_gtk_socket_advance_toplevel_focus (GtkSocket *socket,
+ GtkDirectionType direction)
{
- g_error ("GtkSocket not implemented");
-}
+ GtkBin *bin;
+ GtkWindow *window;
+ GtkContainer *container;
+ GtkWidget *child;
+ GtkWidget *toplevel;
+ GtkWidget *old_focus_child;
+ GtkWidget *parent;
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
+ if (!toplevel)
+ return;
+
+ if (!gtk_widget_is_toplevel (toplevel) || GTK_IS_PLUG (toplevel))
+ {
+ gtk_widget_child_focus (toplevel,direction);
+ return;
+ }
+
+ container = GTK_CONTAINER (toplevel);
+ window = GTK_WINDOW (toplevel);
+ bin = GTK_BIN (toplevel);
+
+ /* This is a copy of gtk_window_focus(), modified so that we
+ * can detect wrap-around.
+ */
+ old_focus_child = gtk_container_get_focus_child (container);
+
+ if (old_focus_child)
+ {
+ if (gtk_widget_child_focus (old_focus_child, direction))
+ return;
+
+ /* We are allowed exactly one wrap-around per sequence of focus
+ * events
+ */
+ if (_gtk_socket_windowing_embed_get_focus_wrapped ())
+ return;
+ else
+ _gtk_socket_windowing_embed_set_focus_wrapped ();
+ }
+
+ if (window->focus_widget)
+ {
+ /* Wrapped off the end, clear the focus setting for the toplevel */
+ parent = window->focus_widget->parent;
+ while (parent)
+ {
+ gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
+ parent = GTK_WIDGET (parent)->parent;
+ }
+
+ gtk_window_set_focus (GTK_WINDOW (container), NULL);
+ }
-#endif /* GDK_WINDOWING */
+ /* Now try to focus the first widget in the window */
+ child = gtk_bin_get_child (bin);
+ if (child)
+ {
+ if (gtk_widget_child_focus (child, direction))
+ return;
+ }
+}