1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* By Owen Taylor <otaylor@gtk.org> 98/4/4 */
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gdk/gdkkeysyms.h"
33 #include "gtkmarshalers.h"
34 #include "gtkwindow.h"
36 #include "gtkprivate.h"
37 #include "gtksocket.h"
38 #include "gtksocketprivate.h"
45 * @Short_description: Container for widgets from other processes
47 * @See_also: #GtkPlug, <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
49 * Together with #GtkPlug, #GtkSocket provides the ability
50 * to embed widgets from one process into another process
51 * in a fashion that is transparent to the user. One
52 * process creates a #GtkSocket widget and passes
53 * that widget's window ID to the other process,
54 * which then creates a #GtkPlug with that window ID.
55 * Any widgets contained in the #GtkPlug then will appear
56 * inside the first application's window.
58 * The socket's window ID is obtained by using
59 * gtk_socket_get_id(). Before using this function,
60 * the socket must have been realized, and for hence,
61 * have been added to its parent.
64 * <title>Obtaining the window ID of a socket.</title>
66 * GtkWidget *socket = gtk_socket_new (<!-- -->);
67 * gtk_widget_show (socket);
68 * gtk_container_add (GTK_CONTAINER (parent), socket);
70 * /<!---->* The following call is only necessary if one of
71 * * the ancestors of the socket is not yet visible.
73 * gtk_widget_realize (socket);
74 * g_print ("The ID of the sockets window is %#x\n",
75 * gtk_socket_get_id (socket));
79 * Note that if you pass the window ID of the socket to another
80 * process that will create a plug in the socket, you
81 * must make sure that the socket widget is not destroyed
82 * until that plug is created. Violating this rule will
83 * cause unpredictable consequences, the most likely
84 * consequence being that the plug will appear as a
85 * separate toplevel window. You can check if the plug
86 * has been created by using gtk_socket_get_plug_window(). If
87 * it returns a non-%NULL value, then the plug has been
88 * successfully created inside of the socket.
90 * When GTK+ is notified that the embedded window has been
91 * destroyed, then it will destroy the socket as well. You
92 * should always, therefore, be prepared for your sockets
93 * to be destroyed at any time when the main event loop
94 * is running. To prevent this from happening, you can
95 * connect to the #GtkSocket::plug-removed signal.
97 * The communication between a #GtkSocket and a #GtkPlug follows the
98 * <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
99 * protocol. This protocol has also been implemented in other toolkits, e.g.
100 * <application>Qt</application>, allowing the same level of integration
101 * when embedding a <application>Qt</application> widget in GTK or vice versa.
103 * A socket can also be used to swallow arbitrary
104 * pre-existing top-level windows using gtk_socket_steal(),
105 * though the integration when this is done will not be as close
106 * as between a #GtkPlug and a #GtkSocket.
109 * The #GtkPlug and #GtkSocket widgets are currently not available
110 * on all platforms supported by GTK+.
114 /* Forward declararations */
116 static void gtk_socket_finalize (GObject *object);
117 static void gtk_socket_notify (GObject *object,
119 static void gtk_socket_realize (GtkWidget *widget);
120 static void gtk_socket_unrealize (GtkWidget *widget);
121 static void gtk_socket_size_request (GtkWidget *widget,
122 GtkRequisition *requisition);
123 static void gtk_socket_size_allocate (GtkWidget *widget,
124 GtkAllocation *allocation);
125 static void gtk_socket_hierarchy_changed (GtkWidget *widget,
126 GtkWidget *old_toplevel);
127 static void gtk_socket_grab_notify (GtkWidget *widget,
128 gboolean was_grabbed);
129 static gboolean gtk_socket_key_event (GtkWidget *widget,
131 static gboolean gtk_socket_focus (GtkWidget *widget,
132 GtkDirectionType direction);
133 static void gtk_socket_remove (GtkContainer *container,
135 static void gtk_socket_forall (GtkContainer *container,
136 gboolean include_internals,
137 GtkCallback callback,
138 gpointer callback_data);
146 GdkModifierType accel_mods;
155 static guint socket_signals[LAST_SIGNAL] = { 0 };
158 * _gtk_socket_get_private:
160 * @socket: a #GtkSocket
162 * Returns the private data associated with a GtkSocket, creating it
163 * first if necessary.
166 _gtk_socket_get_private (GtkSocket *socket)
168 return G_TYPE_INSTANCE_GET_PRIVATE (socket, GTK_TYPE_SOCKET, GtkSocketPrivate);
171 G_DEFINE_TYPE (GtkSocket, gtk_socket, GTK_TYPE_CONTAINER)
174 gtk_socket_finalize (GObject *object)
176 GtkSocket *socket = GTK_SOCKET (object);
178 g_object_unref (socket->accel_group);
179 socket->accel_group = NULL;
181 G_OBJECT_CLASS (gtk_socket_parent_class)->finalize (object);
185 gtk_socket_class_init (GtkSocketClass *class)
187 GtkWidgetClass *widget_class;
188 GtkContainerClass *container_class;
189 GObjectClass *gobject_class;
191 gobject_class = (GObjectClass *) class;
192 widget_class = (GtkWidgetClass*) class;
193 container_class = (GtkContainerClass*) class;
195 gobject_class->finalize = gtk_socket_finalize;
196 gobject_class->notify = gtk_socket_notify;
198 widget_class->realize = gtk_socket_realize;
199 widget_class->unrealize = gtk_socket_unrealize;
200 widget_class->size_request = gtk_socket_size_request;
201 widget_class->size_allocate = gtk_socket_size_allocate;
202 widget_class->hierarchy_changed = gtk_socket_hierarchy_changed;
203 widget_class->grab_notify = gtk_socket_grab_notify;
204 widget_class->key_press_event = gtk_socket_key_event;
205 widget_class->key_release_event = gtk_socket_key_event;
206 widget_class->focus = gtk_socket_focus;
208 /* We don't want to show_all/hide_all the in-process
211 widget_class->show_all = gtk_widget_show;
212 widget_class->hide_all = gtk_widget_hide;
214 container_class->remove = gtk_socket_remove;
215 container_class->forall = gtk_socket_forall;
218 * GtkSocket::plug-added:
219 * @socket_: the object which received the signal
221 * This signal is emitted when a client is successfully
222 * added to the socket.
224 socket_signals[PLUG_ADDED] =
225 g_signal_new (I_("plug-added"),
226 G_OBJECT_CLASS_TYPE (class),
228 G_STRUCT_OFFSET (GtkSocketClass, plug_added),
230 _gtk_marshal_VOID__VOID,
234 * GtkSocket::plug-removed:
235 * @socket_: the object which received the signal
237 * This signal is emitted when a client is removed from the socket.
238 * The default action is to destroy the #GtkSocket widget, so if you
239 * want to reuse it you must add a signal handler that returns %TRUE.
241 * Return value: %TRUE to stop other handlers from being invoked.
243 socket_signals[PLUG_REMOVED] =
244 g_signal_new (I_("plug-removed"),
245 G_OBJECT_CLASS_TYPE (class),
247 G_STRUCT_OFFSET (GtkSocketClass, plug_removed),
248 _gtk_boolean_handled_accumulator, NULL,
249 _gtk_marshal_BOOLEAN__VOID,
252 g_type_class_add_private (gobject_class, sizeof (GtkSocketPrivate));
256 gtk_socket_init (GtkSocket *socket)
258 socket->request_width = 0;
259 socket->request_height = 0;
260 socket->current_width = 0;
261 socket->current_height = 0;
263 socket->plug_window = NULL;
264 socket->plug_widget = NULL;
265 socket->focus_in = FALSE;
266 socket->have_size = FALSE;
267 socket->need_map = FALSE;
268 socket->active = FALSE;
270 socket->accel_group = gtk_accel_group_new ();
271 g_object_set_data (G_OBJECT (socket->accel_group), I_("gtk-socket"), socket);
277 * Create a new empty #GtkSocket.
279 * Return value: the new #GtkSocket.
282 gtk_socket_new (void)
286 socket = g_object_new (GTK_TYPE_SOCKET, NULL);
288 return GTK_WIDGET (socket);
293 * @socket_: a #GtkSocket
294 * @window_id: the window ID of a client participating in the XEMBED protocol.
296 * Adds an XEMBED client, such as a #GtkPlug, to the #GtkSocket. The
297 * client may be in the same process or in a different process.
299 * To embed a #GtkPlug in a #GtkSocket, you can either create the
300 * #GtkPlug with <literal>gtk_plug_new (0)</literal>, call
301 * gtk_plug_get_id() to get the window ID of the plug, and then pass that to the
302 * gtk_socket_add_id(), or you can call gtk_socket_get_id() to get the
303 * window ID for the socket, and call gtk_plug_new() passing in that
306 * The #GtkSocket must have already be added into a toplevel window
307 * before you can make this call.
310 gtk_socket_add_id (GtkSocket *socket,
311 GdkNativeWindow window_id)
313 g_return_if_fail (GTK_IS_SOCKET (socket));
314 g_return_if_fail (GTK_WIDGET_ANCHORED (socket));
316 if (!gtk_widget_get_realized (GTK_WIDGET (socket)))
317 gtk_widget_realize (GTK_WIDGET (socket));
319 _gtk_socket_add_window (socket, window_id, TRUE);
324 * @socket_: a #GtkSocket.
326 * Gets the window ID of a #GtkSocket widget, which can then
327 * be used to create a client embedded inside the socket, for
328 * instance with gtk_plug_new().
330 * The #GtkSocket must have already be added into a toplevel window
331 * before you can make this call.
333 * Return value: the window ID for the socket
336 gtk_socket_get_id (GtkSocket *socket)
338 g_return_val_if_fail (GTK_IS_SOCKET (socket), 0);
339 g_return_val_if_fail (GTK_WIDGET_ANCHORED (socket), 0);
341 if (!gtk_widget_get_realized (GTK_WIDGET (socket)))
342 gtk_widget_realize (GTK_WIDGET (socket));
344 return _gtk_socket_windowing_get_id (socket);
348 * gtk_socket_get_plug_window:
349 * @socket_: a #GtkSocket.
351 * Retrieves the window of the plug. Use this to check if the plug has
352 * been created inside of the socket.
354 * Return value: the window of the plug if available, or %NULL
359 gtk_socket_get_plug_window (GtkSocket *socket)
361 g_return_val_if_fail (GTK_IS_SOCKET (socket), NULL);
363 return socket->plug_window;
367 gtk_socket_realize (GtkWidget *widget)
369 GtkSocket *socket = GTK_SOCKET (widget);
370 GdkWindowAttr attributes;
371 gint attributes_mask;
373 gtk_widget_set_realized (widget, TRUE);
375 attributes.window_type = GDK_WINDOW_CHILD;
376 attributes.x = widget->allocation.x;
377 attributes.y = widget->allocation.y;
378 attributes.width = widget->allocation.width;
379 attributes.height = widget->allocation.height;
380 attributes.wclass = GDK_INPUT_OUTPUT;
381 attributes.visual = gtk_widget_get_visual (widget);
382 attributes.colormap = gtk_widget_get_colormap (widget);
383 attributes.event_mask = GDK_FOCUS_CHANGE_MASK;
385 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
387 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
388 &attributes, attributes_mask);
389 gdk_window_set_user_data (widget->window, socket);
391 widget->style = gtk_style_attach (widget->style, widget->window);
392 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
394 _gtk_socket_windowing_realize_window (socket);
396 gdk_window_add_filter (widget->window,
397 _gtk_socket_windowing_filter_func,
400 /* We sync here so that we make sure that if the XID for
401 * our window is passed to another application, SubstructureRedirectMask
402 * will be set by the time the other app creates its window.
404 gdk_display_sync (gtk_widget_get_display (widget));
408 * _gtk_socket_end_embedding:
410 * @socket: a #GtkSocket
412 * Called to end the embedding of a plug in the socket.
415 _gtk_socket_end_embedding (GtkSocket *socket)
417 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
418 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
420 if (GTK_IS_WINDOW (toplevel))
421 _gtk_socket_windowing_end_embedding_toplevel (socket);
423 g_object_unref (socket->plug_window);
424 socket->plug_window = NULL;
425 socket->current_width = 0;
426 socket->current_height = 0;
427 private->resize_count = 0;
429 gtk_accel_group_disconnect (socket->accel_group, NULL);
433 gtk_socket_unrealize (GtkWidget *widget)
435 GtkSocket *socket = GTK_SOCKET (widget);
437 gtk_widget_set_realized (widget, FALSE);
439 if (socket->plug_widget)
441 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
443 else if (socket->plug_window)
445 _gtk_socket_end_embedding (socket);
448 GTK_WIDGET_CLASS (gtk_socket_parent_class)->unrealize (widget);
452 gtk_socket_size_request (GtkWidget *widget,
453 GtkRequisition *requisition)
455 GtkSocket *socket = GTK_SOCKET (widget);
457 if (socket->plug_widget)
459 gtk_widget_size_request (socket->plug_widget, requisition);
463 if (socket->is_mapped && !socket->have_size && socket->plug_window)
464 _gtk_socket_windowing_size_request (socket);
466 if (socket->is_mapped && socket->have_size)
468 requisition->width = MAX (socket->request_width, 1);
469 requisition->height = MAX (socket->request_height, 1);
473 requisition->width = 1;
474 requisition->height = 1;
480 gtk_socket_size_allocate (GtkWidget *widget,
481 GtkAllocation *allocation)
483 GtkSocket *socket = GTK_SOCKET (widget);
485 widget->allocation = *allocation;
486 if (gtk_widget_get_realized (widget))
488 gdk_window_move_resize (widget->window,
489 allocation->x, allocation->y,
490 allocation->width, allocation->height);
492 if (socket->plug_widget)
494 GtkAllocation child_allocation;
496 child_allocation.x = 0;
497 child_allocation.y = 0;
498 child_allocation.width = allocation->width;
499 child_allocation.height = allocation->height;
501 gtk_widget_size_allocate (socket->plug_widget, &child_allocation);
503 else if (socket->plug_window)
505 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
507 gdk_error_trap_push ();
509 if (allocation->width != socket->current_width ||
510 allocation->height != socket->current_height)
512 gdk_window_move_resize (socket->plug_window,
514 allocation->width, allocation->height);
515 if (private->resize_count)
516 private->resize_count--;
518 GTK_NOTE (PLUGSOCKET,
519 g_message ("GtkSocket - allocated: %d %d",
520 allocation->width, allocation->height));
521 socket->current_width = allocation->width;
522 socket->current_height = allocation->height;
525 if (socket->need_map)
527 gdk_window_show (socket->plug_window);
528 socket->need_map = FALSE;
531 while (private->resize_count)
533 _gtk_socket_windowing_send_configure_event (socket);
534 private->resize_count--;
535 GTK_NOTE (PLUGSOCKET,
536 g_message ("GtkSocket - sending synthetic configure: %d %d",
537 allocation->width, allocation->height));
540 gdk_display_sync (gtk_widget_get_display (widget));
541 gdk_error_trap_pop ();
547 activate_key (GtkAccelGroup *accel_group,
548 GObject *acceleratable,
550 GdkModifierType accel_mods,
551 GrabbedKey *grabbed_key)
553 GdkEvent *gdk_event = gtk_get_current_event ();
555 GtkSocket *socket = g_object_get_data (G_OBJECT (accel_group), "gtk-socket");
556 gboolean retval = FALSE;
558 if (gdk_event && gdk_event->type == GDK_KEY_PRESS && socket->plug_window)
560 _gtk_socket_windowing_send_key_event (socket, gdk_event, FALSE);
565 gdk_event_free (gdk_event);
571 find_accel_key (GtkAccelKey *key,
575 GrabbedKey *grabbed_key = data;
577 return (key->accel_key == grabbed_key->accel_key &&
578 key->accel_mods == grabbed_key->accel_mods);
582 * _gtk_socket_add_grabbed_key:
584 * @socket: a #GtkSocket
586 * @modifiers: modifiers for the key
588 * Called from the GtkSocket platform-specific backend when the
589 * corresponding plug has told the socket to grab a key.
592 _gtk_socket_add_grabbed_key (GtkSocket *socket,
594 GdkModifierType modifiers)
597 GrabbedKey *grabbed_key;
599 grabbed_key = g_new (GrabbedKey, 1);
601 grabbed_key->accel_key = keyval;
602 grabbed_key->accel_mods = modifiers;
604 if (gtk_accel_group_find (socket->accel_group,
608 g_warning ("GtkSocket: request to add already present grabbed key %u,%#x\n",
610 g_free (grabbed_key);
614 closure = g_cclosure_new (G_CALLBACK (activate_key), grabbed_key, (GClosureNotify)g_free);
616 gtk_accel_group_connect (socket->accel_group, keyval, modifiers, GTK_ACCEL_LOCKED,
621 * _gtk_socket_remove_grabbed_key:
623 * @socket: a #GtkSocket
625 * @modifiers: modifiers for the key
627 * Called from the GtkSocket backend when the corresponding plug has
628 * told the socket to remove a key grab.
631 _gtk_socket_remove_grabbed_key (GtkSocket *socket,
633 GdkModifierType modifiers)
635 if (!gtk_accel_group_disconnect_key (socket->accel_group, keyval, modifiers))
636 g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
641 socket_update_focus_in (GtkSocket *socket)
643 gboolean focus_in = FALSE;
645 if (socket->plug_window)
647 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
649 if (gtk_widget_is_toplevel (toplevel) &&
650 GTK_WINDOW (toplevel)->has_toplevel_focus &&
651 gtk_widget_is_focus (GTK_WIDGET (socket)))
655 if (focus_in != socket->focus_in)
657 socket->focus_in = focus_in;
659 _gtk_socket_windowing_focus_change (socket, focus_in);
664 socket_update_active (GtkSocket *socket)
666 gboolean active = FALSE;
668 if (socket->plug_window)
670 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
672 if (gtk_widget_is_toplevel (toplevel) &&
673 GTK_WINDOW (toplevel)->is_active)
677 if (active != socket->active)
679 socket->active = active;
681 _gtk_socket_windowing_update_active (socket, active);
686 gtk_socket_hierarchy_changed (GtkWidget *widget,
687 GtkWidget *old_toplevel)
689 GtkSocket *socket = GTK_SOCKET (widget);
690 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
692 if (toplevel && !GTK_IS_WINDOW (toplevel))
695 if (toplevel != socket->toplevel)
697 if (socket->toplevel)
699 gtk_window_remove_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
700 g_signal_handlers_disconnect_by_func (socket->toplevel,
701 socket_update_focus_in,
703 g_signal_handlers_disconnect_by_func (socket->toplevel,
704 socket_update_active,
708 socket->toplevel = toplevel;
712 gtk_window_add_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
713 g_signal_connect_swapped (socket->toplevel, "notify::has-toplevel-focus",
714 G_CALLBACK (socket_update_focus_in), socket);
715 g_signal_connect_swapped (socket->toplevel, "notify::is-active",
716 G_CALLBACK (socket_update_active), socket);
719 socket_update_focus_in (socket);
720 socket_update_active (socket);
725 gtk_socket_grab_notify (GtkWidget *widget,
726 gboolean was_grabbed)
728 GtkSocket *socket = GTK_SOCKET (widget);
730 if (!socket->same_app)
731 _gtk_socket_windowing_update_modality (socket, !was_grabbed);
735 gtk_socket_key_event (GtkWidget *widget,
738 GtkSocket *socket = GTK_SOCKET (widget);
740 if (gtk_widget_has_focus (widget) && socket->plug_window && !socket->plug_widget)
742 _gtk_socket_windowing_send_key_event (socket, (GdkEvent *) event, FALSE);
751 gtk_socket_notify (GObject *object,
754 if (!strcmp (pspec->name, "is-focus"))
756 socket_update_focus_in (GTK_SOCKET (object));
760 * _gtk_socket_claim_focus:
762 * @socket: a #GtkSocket
765 * Claims focus for the socket. XXX send_event?
768 _gtk_socket_claim_focus (GtkSocket *socket,
771 GtkWidget *widget = GTK_WIDGET (socket);
774 socket->focus_in = TRUE; /* Otherwise, our notify handler will send FOCUS_IN */
776 /* Oh, the trickery... */
778 gtk_widget_set_can_focus (widget, TRUE);
779 gtk_widget_grab_focus (widget);
780 gtk_widget_set_can_focus (widget, FALSE);
784 gtk_socket_focus (GtkWidget *widget,
785 GtkDirectionType direction)
787 GtkSocket *socket = GTK_SOCKET (widget);
789 if (socket->plug_widget)
790 return gtk_widget_child_focus (socket->plug_widget, direction);
792 if (!gtk_widget_is_focus (widget))
794 _gtk_socket_windowing_focus (socket, direction);
795 _gtk_socket_claim_focus (socket, FALSE);
804 gtk_socket_remove (GtkContainer *container,
807 GtkSocket *socket = GTK_SOCKET (container);
809 g_return_if_fail (child == socket->plug_widget);
811 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
815 gtk_socket_forall (GtkContainer *container,
816 gboolean include_internals,
817 GtkCallback callback,
818 gpointer callback_data)
820 GtkSocket *socket = GTK_SOCKET (container);
822 if (socket->plug_widget)
823 (* callback) (socket->plug_widget, callback_data);
827 * _gtk_socket_add_window:
829 * @socket: a #GtkSocket
830 * @xid: the native identifier for a window
831 * @need_reparent: whether the socket's plug's window needs to be
832 * reparented to the socket
834 * Adds a window to a GtkSocket.
837 _gtk_socket_add_window (GtkSocket *socket,
839 gboolean need_reparent)
841 GtkWidget *widget = GTK_WIDGET (socket);
842 GdkDisplay *display = gtk_widget_get_display (widget);
843 gpointer user_data = NULL;
845 socket->plug_window = gdk_window_lookup_for_display (display, xid);
847 if (socket->plug_window)
849 g_object_ref (socket->plug_window);
850 gdk_window_get_user_data (socket->plug_window, &user_data);
853 if (user_data) /* A widget's window in this process */
855 GtkWidget *child_widget = user_data;
857 if (!GTK_IS_PLUG (child_widget))
859 g_warning (G_STRLOC ": Can't add non-GtkPlug to GtkSocket");
860 socket->plug_window = NULL;
861 gdk_error_trap_pop ();
866 _gtk_plug_add_to_socket (GTK_PLUG (child_widget), socket);
868 else /* A foreign window */
871 GdkDragProtocol protocol;
873 gdk_error_trap_push ();
875 if (!socket->plug_window)
877 socket->plug_window = gdk_window_foreign_new_for_display (display, xid);
878 if (!socket->plug_window) /* was deleted before we could get it */
880 gdk_error_trap_pop ();
885 _gtk_socket_windowing_select_plug_window_input (socket);
887 if (gdk_error_trap_pop ())
889 g_object_unref (socket->plug_window);
890 socket->plug_window = NULL;
894 /* OK, we now will reliably get destroy notification on socket->plug_window */
896 gdk_error_trap_push ();
900 gdk_window_hide (socket->plug_window); /* Shouldn't actually be necessary for XEMBED, but just in case */
901 gdk_window_reparent (socket->plug_window, widget->window, 0, 0);
904 socket->have_size = FALSE;
906 _gtk_socket_windowing_embed_get_info (socket);
908 socket->need_map = socket->is_mapped;
910 if (gdk_drag_get_protocol_for_display (display, xid, &protocol))
911 gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
914 gdk_display_sync (display);
915 gdk_error_trap_pop ();
917 gdk_window_add_filter (socket->plug_window,
918 _gtk_socket_windowing_filter_func,
921 /* Add a pointer to the socket on our toplevel window */
923 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
924 if (GTK_IS_WINDOW (toplevel))
925 gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
927 _gtk_socket_windowing_embed_notify (socket);
929 socket_update_active (socket);
930 socket_update_focus_in (socket);
932 gtk_widget_queue_resize (GTK_WIDGET (socket));
935 if (socket->plug_window)
936 g_signal_emit (socket, socket_signals[PLUG_ADDED], 0);
940 * _gtk_socket_handle_map_request:
942 * @socket: a #GtkSocket
944 * Called from the GtkSocket backend when the plug has been mapped.
947 _gtk_socket_handle_map_request (GtkSocket *socket)
949 if (!socket->is_mapped)
951 socket->is_mapped = TRUE;
952 socket->need_map = TRUE;
954 gtk_widget_queue_resize (GTK_WIDGET (socket));
959 * _gtk_socket_unmap_notify:
961 * @socket: a #GtkSocket
963 * Called from the GtkSocket backend when the plug has been unmapped ???
966 _gtk_socket_unmap_notify (GtkSocket *socket)
968 if (socket->is_mapped)
970 socket->is_mapped = FALSE;
971 gtk_widget_queue_resize (GTK_WIDGET (socket));
976 * _gtk_socket_advance_toplevel_focus:
978 * @socket: a #GtkSocket
979 * @direction: a direction
981 * Called from the GtkSocket backend when the corresponding plug
982 * has told the socket to move the focus.
985 _gtk_socket_advance_toplevel_focus (GtkSocket *socket,
986 GtkDirectionType direction)
990 GtkContainer *container;
992 GtkWidget *old_focus_child;
995 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
999 if (!gtk_widget_is_toplevel (toplevel) || GTK_IS_PLUG (toplevel))
1001 gtk_widget_child_focus (toplevel,direction);
1005 container = GTK_CONTAINER (toplevel);
1006 window = GTK_WINDOW (toplevel);
1007 bin = GTK_BIN (toplevel);
1009 /* This is a copy of gtk_window_focus(), modified so that we
1010 * can detect wrap-around.
1012 old_focus_child = container->focus_child;
1014 if (old_focus_child)
1016 if (gtk_widget_child_focus (old_focus_child, direction))
1019 /* We are allowed exactly one wrap-around per sequence of focus
1022 if (_gtk_socket_windowing_embed_get_focus_wrapped ())
1025 _gtk_socket_windowing_embed_set_focus_wrapped ();
1028 if (window->focus_widget)
1030 /* Wrapped off the end, clear the focus setting for the toplevel */
1031 parent = window->focus_widget->parent;
1034 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
1035 parent = GTK_WIDGET (parent)->parent;
1038 gtk_window_set_focus (GTK_WINDOW (container), NULL);
1041 /* Now try to focus the first widget in the window */
1044 if (gtk_widget_child_focus (bin->child, direction))