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 GtkAllocation allocation;
370 GtkSocket *socket = GTK_SOCKET (widget);
372 GdkWindowAttr attributes;
373 gint attributes_mask;
375 gtk_widget_set_realized (widget, TRUE);
377 gtk_widget_get_allocation (widget, &allocation);
379 attributes.window_type = GDK_WINDOW_CHILD;
380 attributes.x = allocation.x;
381 attributes.y = allocation.y;
382 attributes.width = allocation.width;
383 attributes.height = allocation.height;
384 attributes.wclass = GDK_INPUT_OUTPUT;
385 attributes.visual = gtk_widget_get_visual (widget);
386 attributes.colormap = gtk_widget_get_colormap (widget);
387 attributes.event_mask = GDK_FOCUS_CHANGE_MASK;
389 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
391 window = gdk_window_new (gtk_widget_get_parent_window (widget),
392 &attributes, attributes_mask);
393 gtk_widget_set_window (widget, window);
394 gdk_window_set_user_data (window, socket);
396 gtk_widget_style_attach (widget);
397 gtk_style_set_background (gtk_widget_get_style (widget),
398 window, GTK_STATE_NORMAL);
400 _gtk_socket_windowing_realize_window (socket);
402 gdk_window_add_filter (window,
403 _gtk_socket_windowing_filter_func,
406 /* We sync here so that we make sure that if the XID for
407 * our window is passed to another application, SubstructureRedirectMask
408 * will be set by the time the other app creates its window.
410 gdk_display_sync (gtk_widget_get_display (widget));
414 * _gtk_socket_end_embedding:
416 * @socket: a #GtkSocket
418 * Called to end the embedding of a plug in the socket.
421 _gtk_socket_end_embedding (GtkSocket *socket)
423 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
424 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
426 if (GTK_IS_WINDOW (toplevel))
427 _gtk_socket_windowing_end_embedding_toplevel (socket);
429 g_object_unref (socket->plug_window);
430 socket->plug_window = NULL;
431 socket->current_width = 0;
432 socket->current_height = 0;
433 private->resize_count = 0;
435 gtk_accel_group_disconnect (socket->accel_group, NULL);
439 gtk_socket_unrealize (GtkWidget *widget)
441 GtkSocket *socket = GTK_SOCKET (widget);
443 gtk_widget_set_realized (widget, FALSE);
445 if (socket->plug_widget)
447 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
449 else if (socket->plug_window)
451 _gtk_socket_end_embedding (socket);
454 GTK_WIDGET_CLASS (gtk_socket_parent_class)->unrealize (widget);
458 gtk_socket_size_request (GtkWidget *widget,
459 GtkRequisition *requisition)
461 GtkSocket *socket = GTK_SOCKET (widget);
463 if (socket->plug_widget)
465 gtk_widget_size_request (socket->plug_widget, requisition);
469 if (socket->is_mapped && !socket->have_size && socket->plug_window)
470 _gtk_socket_windowing_size_request (socket);
472 if (socket->is_mapped && socket->have_size)
474 requisition->width = MAX (socket->request_width, 1);
475 requisition->height = MAX (socket->request_height, 1);
479 requisition->width = 1;
480 requisition->height = 1;
486 gtk_socket_size_allocate (GtkWidget *widget,
487 GtkAllocation *allocation)
489 GtkSocket *socket = GTK_SOCKET (widget);
491 gtk_widget_set_allocation (widget, allocation);
492 if (gtk_widget_get_realized (widget))
494 gdk_window_move_resize (gtk_widget_get_window (widget),
495 allocation->x, allocation->y,
496 allocation->width, allocation->height);
498 if (socket->plug_widget)
500 GtkAllocation child_allocation;
502 child_allocation.x = 0;
503 child_allocation.y = 0;
504 child_allocation.width = allocation->width;
505 child_allocation.height = allocation->height;
507 gtk_widget_size_allocate (socket->plug_widget, &child_allocation);
509 else if (socket->plug_window)
511 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
513 gdk_error_trap_push ();
515 if (allocation->width != socket->current_width ||
516 allocation->height != socket->current_height)
518 gdk_window_move_resize (socket->plug_window,
520 allocation->width, allocation->height);
521 if (private->resize_count)
522 private->resize_count--;
524 GTK_NOTE (PLUGSOCKET,
525 g_message ("GtkSocket - allocated: %d %d",
526 allocation->width, allocation->height));
527 socket->current_width = allocation->width;
528 socket->current_height = allocation->height;
531 if (socket->need_map)
533 gdk_window_show (socket->plug_window);
534 socket->need_map = FALSE;
537 while (private->resize_count)
539 _gtk_socket_windowing_send_configure_event (socket);
540 private->resize_count--;
541 GTK_NOTE (PLUGSOCKET,
542 g_message ("GtkSocket - sending synthetic configure: %d %d",
543 allocation->width, allocation->height));
546 gdk_display_sync (gtk_widget_get_display (widget));
547 gdk_error_trap_pop ();
553 activate_key (GtkAccelGroup *accel_group,
554 GObject *acceleratable,
556 GdkModifierType accel_mods,
557 GrabbedKey *grabbed_key)
559 GdkEvent *gdk_event = gtk_get_current_event ();
561 GtkSocket *socket = g_object_get_data (G_OBJECT (accel_group), "gtk-socket");
562 gboolean retval = FALSE;
564 if (gdk_event && gdk_event->type == GDK_KEY_PRESS && socket->plug_window)
566 _gtk_socket_windowing_send_key_event (socket, gdk_event, FALSE);
571 gdk_event_free (gdk_event);
577 find_accel_key (GtkAccelKey *key,
581 GrabbedKey *grabbed_key = data;
583 return (key->accel_key == grabbed_key->accel_key &&
584 key->accel_mods == grabbed_key->accel_mods);
588 * _gtk_socket_add_grabbed_key:
590 * @socket: a #GtkSocket
592 * @modifiers: modifiers for the key
594 * Called from the GtkSocket platform-specific backend when the
595 * corresponding plug has told the socket to grab a key.
598 _gtk_socket_add_grabbed_key (GtkSocket *socket,
600 GdkModifierType modifiers)
603 GrabbedKey *grabbed_key;
605 grabbed_key = g_new (GrabbedKey, 1);
607 grabbed_key->accel_key = keyval;
608 grabbed_key->accel_mods = modifiers;
610 if (gtk_accel_group_find (socket->accel_group,
614 g_warning ("GtkSocket: request to add already present grabbed key %u,%#x\n",
616 g_free (grabbed_key);
620 closure = g_cclosure_new (G_CALLBACK (activate_key), grabbed_key, (GClosureNotify)g_free);
622 gtk_accel_group_connect (socket->accel_group, keyval, modifiers, GTK_ACCEL_LOCKED,
627 * _gtk_socket_remove_grabbed_key:
629 * @socket: a #GtkSocket
631 * @modifiers: modifiers for the key
633 * Called from the GtkSocket backend when the corresponding plug has
634 * told the socket to remove a key grab.
637 _gtk_socket_remove_grabbed_key (GtkSocket *socket,
639 GdkModifierType modifiers)
641 if (!gtk_accel_group_disconnect_key (socket->accel_group, keyval, modifiers))
642 g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
647 socket_update_focus_in (GtkSocket *socket)
649 gboolean focus_in = FALSE;
651 if (socket->plug_window)
653 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
655 if (gtk_widget_is_toplevel (toplevel) &&
656 gtk_window_has_toplevel_focus (GTK_WINDOW (toplevel)) &&
657 gtk_widget_is_focus (GTK_WIDGET (socket)))
661 if (focus_in != socket->focus_in)
663 socket->focus_in = focus_in;
665 _gtk_socket_windowing_focus_change (socket, focus_in);
670 socket_update_active (GtkSocket *socket)
672 gboolean active = FALSE;
674 if (socket->plug_window)
676 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
678 if (gtk_widget_is_toplevel (toplevel) &&
679 gtk_window_is_active (GTK_WINDOW (toplevel)))
683 if (active != socket->active)
685 socket->active = active;
687 _gtk_socket_windowing_update_active (socket, active);
692 gtk_socket_hierarchy_changed (GtkWidget *widget,
693 GtkWidget *old_toplevel)
695 GtkSocket *socket = GTK_SOCKET (widget);
696 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
698 if (toplevel && !GTK_IS_WINDOW (toplevel))
701 if (toplevel != socket->toplevel)
703 if (socket->toplevel)
705 gtk_window_remove_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
706 g_signal_handlers_disconnect_by_func (socket->toplevel,
707 socket_update_focus_in,
709 g_signal_handlers_disconnect_by_func (socket->toplevel,
710 socket_update_active,
714 socket->toplevel = toplevel;
718 gtk_window_add_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
719 g_signal_connect_swapped (socket->toplevel, "notify::has-toplevel-focus",
720 G_CALLBACK (socket_update_focus_in), socket);
721 g_signal_connect_swapped (socket->toplevel, "notify::is-active",
722 G_CALLBACK (socket_update_active), socket);
725 socket_update_focus_in (socket);
726 socket_update_active (socket);
731 gtk_socket_grab_notify (GtkWidget *widget,
732 gboolean was_grabbed)
734 GtkSocket *socket = GTK_SOCKET (widget);
736 if (!socket->same_app)
737 _gtk_socket_windowing_update_modality (socket, !was_grabbed);
741 gtk_socket_key_event (GtkWidget *widget,
744 GtkSocket *socket = GTK_SOCKET (widget);
746 if (gtk_widget_has_focus (widget) && socket->plug_window && !socket->plug_widget)
748 _gtk_socket_windowing_send_key_event (socket, (GdkEvent *) event, FALSE);
757 gtk_socket_notify (GObject *object,
760 if (!strcmp (pspec->name, "is-focus"))
762 socket_update_focus_in (GTK_SOCKET (object));
766 * _gtk_socket_claim_focus:
768 * @socket: a #GtkSocket
771 * Claims focus for the socket. XXX send_event?
774 _gtk_socket_claim_focus (GtkSocket *socket,
777 GtkWidget *widget = GTK_WIDGET (socket);
780 socket->focus_in = TRUE; /* Otherwise, our notify handler will send FOCUS_IN */
782 /* Oh, the trickery... */
784 gtk_widget_set_can_focus (widget, TRUE);
785 gtk_widget_grab_focus (widget);
786 gtk_widget_set_can_focus (widget, FALSE);
790 gtk_socket_focus (GtkWidget *widget,
791 GtkDirectionType direction)
793 GtkSocket *socket = GTK_SOCKET (widget);
795 if (socket->plug_widget)
796 return gtk_widget_child_focus (socket->plug_widget, direction);
798 if (!gtk_widget_is_focus (widget))
800 _gtk_socket_windowing_focus (socket, direction);
801 _gtk_socket_claim_focus (socket, FALSE);
810 gtk_socket_remove (GtkContainer *container,
813 GtkSocket *socket = GTK_SOCKET (container);
815 g_return_if_fail (child == socket->plug_widget);
817 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
821 gtk_socket_forall (GtkContainer *container,
822 gboolean include_internals,
823 GtkCallback callback,
824 gpointer callback_data)
826 GtkSocket *socket = GTK_SOCKET (container);
828 if (socket->plug_widget)
829 (* callback) (socket->plug_widget, callback_data);
833 * _gtk_socket_add_window:
835 * @socket: a #GtkSocket
836 * @xid: the native identifier for a window
837 * @need_reparent: whether the socket's plug's window needs to be
838 * reparented to the socket
840 * Adds a window to a GtkSocket.
843 _gtk_socket_add_window (GtkSocket *socket,
845 gboolean need_reparent)
847 GtkWidget *widget = GTK_WIDGET (socket);
848 GdkDisplay *display = gtk_widget_get_display (widget);
849 gpointer user_data = NULL;
851 socket->plug_window = gdk_window_lookup_for_display (display, xid);
853 if (socket->plug_window)
855 g_object_ref (socket->plug_window);
856 gdk_window_get_user_data (socket->plug_window, &user_data);
859 if (user_data) /* A widget's window in this process */
861 GtkWidget *child_widget = user_data;
863 if (!GTK_IS_PLUG (child_widget))
865 g_warning (G_STRLOC ": Can't add non-GtkPlug to GtkSocket");
866 socket->plug_window = NULL;
867 gdk_error_trap_pop ();
872 _gtk_plug_add_to_socket (GTK_PLUG (child_widget), socket);
874 else /* A foreign window */
877 GdkDragProtocol protocol;
879 gdk_error_trap_push ();
881 if (!socket->plug_window)
883 socket->plug_window = gdk_window_foreign_new_for_display (display, xid);
884 if (!socket->plug_window) /* was deleted before we could get it */
886 gdk_error_trap_pop ();
891 _gtk_socket_windowing_select_plug_window_input (socket);
893 if (gdk_error_trap_pop ())
895 g_object_unref (socket->plug_window);
896 socket->plug_window = NULL;
900 /* OK, we now will reliably get destroy notification on socket->plug_window */
902 gdk_error_trap_push ();
906 gdk_window_hide (socket->plug_window); /* Shouldn't actually be necessary for XEMBED, but just in case */
907 gdk_window_reparent (socket->plug_window,
908 gtk_widget_get_window (widget),
912 socket->have_size = FALSE;
914 _gtk_socket_windowing_embed_get_info (socket);
916 socket->need_map = socket->is_mapped;
918 if (gdk_drag_get_protocol_for_display (display, xid, &protocol))
919 gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
922 gdk_display_sync (display);
923 gdk_error_trap_pop ();
925 gdk_window_add_filter (socket->plug_window,
926 _gtk_socket_windowing_filter_func,
929 /* Add a pointer to the socket on our toplevel window */
931 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
932 if (GTK_IS_WINDOW (toplevel))
933 gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
935 _gtk_socket_windowing_embed_notify (socket);
937 socket_update_active (socket);
938 socket_update_focus_in (socket);
940 gtk_widget_queue_resize (GTK_WIDGET (socket));
943 if (socket->plug_window)
944 g_signal_emit (socket, socket_signals[PLUG_ADDED], 0);
948 * _gtk_socket_handle_map_request:
950 * @socket: a #GtkSocket
952 * Called from the GtkSocket backend when the plug has been mapped.
955 _gtk_socket_handle_map_request (GtkSocket *socket)
957 if (!socket->is_mapped)
959 socket->is_mapped = TRUE;
960 socket->need_map = TRUE;
962 gtk_widget_queue_resize (GTK_WIDGET (socket));
967 * _gtk_socket_unmap_notify:
969 * @socket: a #GtkSocket
971 * Called from the GtkSocket backend when the plug has been unmapped ???
974 _gtk_socket_unmap_notify (GtkSocket *socket)
976 if (socket->is_mapped)
978 socket->is_mapped = FALSE;
979 gtk_widget_queue_resize (GTK_WIDGET (socket));
984 * _gtk_socket_advance_toplevel_focus:
986 * @socket: a #GtkSocket
987 * @direction: a direction
989 * Called from the GtkSocket backend when the corresponding plug
990 * has told the socket to move the focus.
993 _gtk_socket_advance_toplevel_focus (GtkSocket *socket,
994 GtkDirectionType direction)
998 GtkContainer *container;
1000 GtkWidget *focus_widget;
1001 GtkWidget *toplevel;
1002 GtkWidget *old_focus_child;
1005 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
1009 if (!gtk_widget_is_toplevel (toplevel) || GTK_IS_PLUG (toplevel))
1011 gtk_widget_child_focus (toplevel,direction);
1015 container = GTK_CONTAINER (toplevel);
1016 window = GTK_WINDOW (toplevel);
1017 bin = GTK_BIN (toplevel);
1019 /* This is a copy of gtk_window_focus(), modified so that we
1020 * can detect wrap-around.
1022 old_focus_child = gtk_container_get_focus_child (container);
1024 if (old_focus_child)
1026 if (gtk_widget_child_focus (old_focus_child, direction))
1029 /* We are allowed exactly one wrap-around per sequence of focus
1032 if (_gtk_socket_windowing_embed_get_focus_wrapped ())
1035 _gtk_socket_windowing_embed_set_focus_wrapped ();
1038 focus_widget = gtk_window_get_focus (window);
1041 /* Wrapped off the end, clear the focus setting for the toplevel */
1042 parent = gtk_widget_get_parent (focus_widget);
1045 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
1046 parent = gtk_widget_get_parent (parent);
1049 gtk_window_set_focus (GTK_WINDOW (container), NULL);
1052 /* Now try to focus the first widget in the window */
1053 child = gtk_bin_get_child (bin);
1056 if (gtk_widget_child_focus (child, direction))