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/.
30 #include "gtksocket.h"
34 #include "gdk/gdkkeysyms.h"
36 #include "gtkmarshalers.h"
37 #include "gtksizerequest.h"
38 #include "gtkwindow.h"
40 #include "gtkprivate.h"
41 #include "gtksocketprivate.h"
48 * @Short_description: Container for widgets from other processes
50 * @See_also: #GtkPlug, <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
52 * Together with #GtkPlug, #GtkSocket provides the ability
53 * to embed widgets from one process into another process
54 * in a fashion that is transparent to the user. One
55 * process creates a #GtkSocket widget and passes
56 * that widget's window ID to the other process,
57 * which then creates a #GtkPlug with that window ID.
58 * Any widgets contained in the #GtkPlug then will appear
59 * inside the first application's window.
61 * The socket's window ID is obtained by using
62 * gtk_socket_get_id(). Before using this function,
63 * the socket must have been realized, and for hence,
64 * have been added to its parent.
67 * <title>Obtaining the window ID of a socket.</title>
69 * GtkWidget *socket = gtk_socket_new (<!-- -->);
70 * gtk_widget_show (socket);
71 * gtk_container_add (GTK_CONTAINER (parent), socket);
73 * /<!---->* The following call is only necessary if one of
74 * * the ancestors of the socket is not yet visible.
76 * gtk_widget_realize (socket);
77 * g_print ("The ID of the sockets window is %#x\n",
78 * gtk_socket_get_id (socket));
82 * Note that if you pass the window ID of the socket to another
83 * process that will create a plug in the socket, you
84 * must make sure that the socket widget is not destroyed
85 * until that plug is created. Violating this rule will
86 * cause unpredictable consequences, the most likely
87 * consequence being that the plug will appear as a
88 * separate toplevel window. You can check if the plug
89 * has been created by using gtk_socket_get_plug_window(). If
90 * it returns a non-%NULL value, then the plug has been
91 * successfully created inside of the socket.
93 * When GTK+ is notified that the embedded window has been
94 * destroyed, then it will destroy the socket as well. You
95 * should always, therefore, be prepared for your sockets
96 * to be destroyed at any time when the main event loop
97 * is running. To prevent this from happening, you can
98 * connect to the #GtkSocket::plug-removed signal.
100 * The communication between a #GtkSocket and a #GtkPlug follows the
101 * <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
102 * protocol. This protocol has also been implemented in other toolkits, e.g.
103 * <application>Qt</application>, allowing the same level of integration
104 * when embedding a <application>Qt</application> widget in GTK or vice versa.
107 * The #GtkPlug and #GtkSocket widgets are currently not available
108 * on all platforms supported by GTK+.
112 /* Forward declararations */
114 static void gtk_socket_finalize (GObject *object);
115 static void gtk_socket_notify (GObject *object,
117 static void gtk_socket_realize (GtkWidget *widget);
118 static void gtk_socket_unrealize (GtkWidget *widget);
119 static void gtk_socket_size_request (GtkWidget *widget,
120 GtkRequisition *requisition);
121 static void gtk_socket_size_allocate (GtkWidget *widget,
122 GtkAllocation *allocation);
123 static void gtk_socket_hierarchy_changed (GtkWidget *widget,
124 GtkWidget *old_toplevel);
125 static void gtk_socket_grab_notify (GtkWidget *widget,
126 gboolean was_grabbed);
127 static gboolean gtk_socket_key_event (GtkWidget *widget,
129 static gboolean gtk_socket_focus (GtkWidget *widget,
130 GtkDirectionType direction);
131 static void gtk_socket_remove (GtkContainer *container,
133 static void gtk_socket_forall (GtkContainer *container,
134 gboolean include_internals,
135 GtkCallback callback,
136 gpointer callback_data);
144 GdkModifierType accel_mods;
153 static guint socket_signals[LAST_SIGNAL] = { 0 };
156 * _gtk_socket_get_private:
158 * @socket: a #GtkSocket
160 * Returns the private data associated with a GtkSocket, creating it
161 * first if necessary.
164 _gtk_socket_get_private (GtkSocket *socket)
166 return G_TYPE_INSTANCE_GET_PRIVATE (socket, GTK_TYPE_SOCKET, GtkSocketPrivate);
169 G_DEFINE_TYPE (GtkSocket, gtk_socket, GTK_TYPE_CONTAINER)
172 gtk_socket_finalize (GObject *object)
174 GtkSocket *socket = GTK_SOCKET (object);
176 g_object_unref (socket->accel_group);
177 socket->accel_group = NULL;
179 G_OBJECT_CLASS (gtk_socket_parent_class)->finalize (object);
183 gtk_socket_class_init (GtkSocketClass *class)
185 GtkWidgetClass *widget_class;
186 GtkContainerClass *container_class;
187 GObjectClass *gobject_class;
189 gobject_class = (GObjectClass *) class;
190 widget_class = (GtkWidgetClass*) class;
191 container_class = (GtkContainerClass*) class;
193 gobject_class->finalize = gtk_socket_finalize;
194 gobject_class->notify = gtk_socket_notify;
196 widget_class->realize = gtk_socket_realize;
197 widget_class->unrealize = gtk_socket_unrealize;
198 widget_class->size_request = gtk_socket_size_request;
199 widget_class->size_allocate = gtk_socket_size_allocate;
200 widget_class->hierarchy_changed = gtk_socket_hierarchy_changed;
201 widget_class->grab_notify = gtk_socket_grab_notify;
202 widget_class->key_press_event = gtk_socket_key_event;
203 widget_class->key_release_event = gtk_socket_key_event;
204 widget_class->focus = gtk_socket_focus;
206 /* We don't want to show_all/hide_all the in-process
209 widget_class->show_all = gtk_widget_show;
210 widget_class->hide_all = gtk_widget_hide;
212 container_class->remove = gtk_socket_remove;
213 container_class->forall = gtk_socket_forall;
216 * GtkSocket::plug-added:
217 * @socket_: the object which received the signal
219 * This signal is emitted when a client is successfully
220 * added to the socket.
222 socket_signals[PLUG_ADDED] =
223 g_signal_new (I_("plug-added"),
224 G_OBJECT_CLASS_TYPE (class),
226 G_STRUCT_OFFSET (GtkSocketClass, plug_added),
228 _gtk_marshal_VOID__VOID,
232 * GtkSocket::plug-removed:
233 * @socket_: the object which received the signal
235 * This signal is emitted when a client is removed from the socket.
236 * The default action is to destroy the #GtkSocket widget, so if you
237 * want to reuse it you must add a signal handler that returns %TRUE.
239 * Return value: %TRUE to stop other handlers from being invoked.
241 socket_signals[PLUG_REMOVED] =
242 g_signal_new (I_("plug-removed"),
243 G_OBJECT_CLASS_TYPE (class),
245 G_STRUCT_OFFSET (GtkSocketClass, plug_removed),
246 _gtk_boolean_handled_accumulator, NULL,
247 _gtk_marshal_BOOLEAN__VOID,
250 g_type_class_add_private (gobject_class, sizeof (GtkSocketPrivate));
254 gtk_socket_init (GtkSocket *socket)
256 socket->request_width = 0;
257 socket->request_height = 0;
258 socket->current_width = 0;
259 socket->current_height = 0;
261 socket->plug_window = NULL;
262 socket->plug_widget = NULL;
263 socket->focus_in = FALSE;
264 socket->have_size = FALSE;
265 socket->need_map = FALSE;
266 socket->active = FALSE;
268 socket->accel_group = gtk_accel_group_new ();
269 g_object_set_data (G_OBJECT (socket->accel_group), I_("gtk-socket"), socket);
275 * Create a new empty #GtkSocket.
277 * Return value: the new #GtkSocket.
280 gtk_socket_new (void)
284 socket = g_object_new (GTK_TYPE_SOCKET, NULL);
286 return GTK_WIDGET (socket);
291 * @socket_: a #GtkSocket
292 * @window_id: the window ID of a client participating in the XEMBED protocol.
294 * Adds an XEMBED client, such as a #GtkPlug, to the #GtkSocket. The
295 * client may be in the same process or in a different process.
297 * To embed a #GtkPlug in a #GtkSocket, you can either create the
298 * #GtkPlug with <literal>gtk_plug_new (0)</literal>, call
299 * gtk_plug_get_id() to get the window ID of the plug, and then pass that to the
300 * gtk_socket_add_id(), or you can call gtk_socket_get_id() to get the
301 * window ID for the socket, and call gtk_plug_new() passing in that
304 * The #GtkSocket must have already be added into a toplevel window
305 * before you can make this call.
308 gtk_socket_add_id (GtkSocket *socket,
309 GdkNativeWindow window_id)
311 g_return_if_fail (GTK_IS_SOCKET (socket));
312 g_return_if_fail (GTK_WIDGET_ANCHORED (socket));
314 if (!gtk_widget_get_realized (GTK_WIDGET (socket)))
315 gtk_widget_realize (GTK_WIDGET (socket));
317 _gtk_socket_add_window (socket, window_id, TRUE);
322 * @socket_: a #GtkSocket.
324 * Gets the window ID of a #GtkSocket widget, which can then
325 * be used to create a client embedded inside the socket, for
326 * instance with gtk_plug_new().
328 * The #GtkSocket must have already be added into a toplevel window
329 * before you can make this call.
331 * Return value: the window ID for the socket
334 gtk_socket_get_id (GtkSocket *socket)
336 g_return_val_if_fail (GTK_IS_SOCKET (socket), 0);
337 g_return_val_if_fail (GTK_WIDGET_ANCHORED (socket), 0);
339 if (!gtk_widget_get_realized (GTK_WIDGET (socket)))
340 gtk_widget_realize (GTK_WIDGET (socket));
342 return _gtk_socket_windowing_get_id (socket);
346 * gtk_socket_get_plug_window:
347 * @socket_: a #GtkSocket.
349 * Retrieves the window of the plug. Use this to check if the plug has
350 * been created inside of the socket.
352 * Return value: (transfer none): the window of the plug if available, or %NULL
357 gtk_socket_get_plug_window (GtkSocket *socket)
359 g_return_val_if_fail (GTK_IS_SOCKET (socket), NULL);
361 return socket->plug_window;
365 gtk_socket_realize (GtkWidget *widget)
367 GtkAllocation allocation;
368 GtkSocket *socket = GTK_SOCKET (widget);
370 GdkWindowAttr attributes;
371 gint attributes_mask;
373 gtk_widget_set_realized (widget, TRUE);
375 gtk_widget_get_allocation (widget, &allocation);
377 attributes.window_type = GDK_WINDOW_CHILD;
378 attributes.x = allocation.x;
379 attributes.y = allocation.y;
380 attributes.width = allocation.width;
381 attributes.height = allocation.height;
382 attributes.wclass = GDK_INPUT_OUTPUT;
383 attributes.visual = gtk_widget_get_visual (widget);
384 attributes.colormap = gtk_widget_get_colormap (widget);
385 attributes.event_mask = GDK_FOCUS_CHANGE_MASK;
387 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
389 window = gdk_window_new (gtk_widget_get_parent_window (widget),
390 &attributes, attributes_mask);
391 gtk_widget_set_window (widget, window);
392 gdk_window_set_user_data (window, socket);
394 gtk_widget_style_attach (widget);
395 gtk_style_set_background (gtk_widget_get_style (widget),
396 window, GTK_STATE_NORMAL);
398 _gtk_socket_windowing_realize_window (socket);
400 gdk_window_add_filter (window,
401 _gtk_socket_windowing_filter_func,
404 /* We sync here so that we make sure that if the XID for
405 * our window is passed to another application, SubstructureRedirectMask
406 * will be set by the time the other app creates its window.
408 gdk_display_sync (gtk_widget_get_display (widget));
412 * _gtk_socket_end_embedding:
414 * @socket: a #GtkSocket
416 * Called to end the embedding of a plug in the socket.
419 _gtk_socket_end_embedding (GtkSocket *socket)
421 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
422 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
424 if (GTK_IS_WINDOW (toplevel))
425 _gtk_socket_windowing_end_embedding_toplevel (socket);
427 g_object_unref (socket->plug_window);
428 socket->plug_window = NULL;
429 socket->current_width = 0;
430 socket->current_height = 0;
431 private->resize_count = 0;
433 gtk_accel_group_disconnect (socket->accel_group, NULL);
437 gtk_socket_unrealize (GtkWidget *widget)
439 GtkSocket *socket = GTK_SOCKET (widget);
441 gtk_widget_set_realized (widget, FALSE);
443 if (socket->plug_widget)
445 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
447 else if (socket->plug_window)
449 _gtk_socket_end_embedding (socket);
452 GTK_WIDGET_CLASS (gtk_socket_parent_class)->unrealize (widget);
456 gtk_socket_size_request (GtkWidget *widget,
457 GtkRequisition *requisition)
459 GtkSocket *socket = GTK_SOCKET (widget);
461 if (socket->plug_widget)
463 gtk_size_request_get_size (GTK_SIZE_REQUEST (socket->plug_widget),
468 if (socket->is_mapped && !socket->have_size && socket->plug_window)
469 _gtk_socket_windowing_size_request (socket);
471 if (socket->is_mapped && socket->have_size)
473 requisition->width = MAX (socket->request_width, 1);
474 requisition->height = MAX (socket->request_height, 1);
478 requisition->width = 1;
479 requisition->height = 1;
485 gtk_socket_size_allocate (GtkWidget *widget,
486 GtkAllocation *allocation)
488 GtkSocket *socket = GTK_SOCKET (widget);
490 gtk_widget_set_allocation (widget, allocation);
491 if (gtk_widget_get_realized (widget))
493 gdk_window_move_resize (gtk_widget_get_window (widget),
494 allocation->x, allocation->y,
495 allocation->width, allocation->height);
497 if (socket->plug_widget)
499 GtkAllocation child_allocation;
501 child_allocation.x = 0;
502 child_allocation.y = 0;
503 child_allocation.width = allocation->width;
504 child_allocation.height = allocation->height;
506 gtk_widget_size_allocate (socket->plug_widget, &child_allocation);
508 else if (socket->plug_window)
510 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
512 gdk_error_trap_push ();
514 if (allocation->width != socket->current_width ||
515 allocation->height != socket->current_height)
517 gdk_window_move_resize (socket->plug_window,
519 allocation->width, allocation->height);
520 if (private->resize_count)
521 private->resize_count--;
523 GTK_NOTE (PLUGSOCKET,
524 g_message ("GtkSocket - allocated: %d %d",
525 allocation->width, allocation->height));
526 socket->current_width = allocation->width;
527 socket->current_height = allocation->height;
530 if (socket->need_map)
532 gdk_window_show (socket->plug_window);
533 socket->need_map = FALSE;
536 while (private->resize_count)
538 _gtk_socket_windowing_send_configure_event (socket);
539 private->resize_count--;
540 GTK_NOTE (PLUGSOCKET,
541 g_message ("GtkSocket - sending synthetic configure: %d %d",
542 allocation->width, allocation->height));
545 gdk_error_trap_pop_ignored ();
551 activate_key (GtkAccelGroup *accel_group,
552 GObject *acceleratable,
554 GdkModifierType accel_mods,
555 GrabbedKey *grabbed_key)
557 GdkEvent *gdk_event = gtk_get_current_event ();
559 GtkSocket *socket = g_object_get_data (G_OBJECT (accel_group), "gtk-socket");
560 gboolean retval = FALSE;
562 if (gdk_event && gdk_event->type == GDK_KEY_PRESS && socket->plug_window)
564 _gtk_socket_windowing_send_key_event (socket, gdk_event, FALSE);
569 gdk_event_free (gdk_event);
575 find_accel_key (GtkAccelKey *key,
579 GrabbedKey *grabbed_key = data;
581 return (key->accel_key == grabbed_key->accel_key &&
582 key->accel_mods == grabbed_key->accel_mods);
586 * _gtk_socket_add_grabbed_key:
588 * @socket: a #GtkSocket
590 * @modifiers: modifiers for the key
592 * Called from the GtkSocket platform-specific backend when the
593 * corresponding plug has told the socket to grab a key.
596 _gtk_socket_add_grabbed_key (GtkSocket *socket,
598 GdkModifierType modifiers)
601 GrabbedKey *grabbed_key;
603 grabbed_key = g_new (GrabbedKey, 1);
605 grabbed_key->accel_key = keyval;
606 grabbed_key->accel_mods = modifiers;
608 if (gtk_accel_group_find (socket->accel_group,
612 g_warning ("GtkSocket: request to add already present grabbed key %u,%#x\n",
614 g_free (grabbed_key);
618 closure = g_cclosure_new (G_CALLBACK (activate_key), grabbed_key, (GClosureNotify)g_free);
620 gtk_accel_group_connect (socket->accel_group, keyval, modifiers, GTK_ACCEL_LOCKED,
625 * _gtk_socket_remove_grabbed_key:
627 * @socket: a #GtkSocket
629 * @modifiers: modifiers for the key
631 * Called from the GtkSocket backend when the corresponding plug has
632 * told the socket to remove a key grab.
635 _gtk_socket_remove_grabbed_key (GtkSocket *socket,
637 GdkModifierType modifiers)
639 if (!gtk_accel_group_disconnect_key (socket->accel_group, keyval, modifiers))
640 g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
645 socket_update_focus_in (GtkSocket *socket)
647 gboolean focus_in = FALSE;
649 if (socket->plug_window)
651 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
653 if (gtk_widget_is_toplevel (toplevel) &&
654 gtk_window_has_toplevel_focus (GTK_WINDOW (toplevel)) &&
655 gtk_widget_is_focus (GTK_WIDGET (socket)))
659 if (focus_in != socket->focus_in)
661 socket->focus_in = focus_in;
663 _gtk_socket_windowing_focus_change (socket, focus_in);
668 socket_update_active (GtkSocket *socket)
670 gboolean active = FALSE;
672 if (socket->plug_window)
674 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
676 if (gtk_widget_is_toplevel (toplevel) &&
677 gtk_window_is_active (GTK_WINDOW (toplevel)))
681 if (active != socket->active)
683 socket->active = active;
685 _gtk_socket_windowing_update_active (socket, active);
690 gtk_socket_hierarchy_changed (GtkWidget *widget,
691 GtkWidget *old_toplevel)
693 GtkSocket *socket = GTK_SOCKET (widget);
694 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
696 if (toplevel && !GTK_IS_WINDOW (toplevel))
699 if (toplevel != socket->toplevel)
701 if (socket->toplevel)
703 gtk_window_remove_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
704 g_signal_handlers_disconnect_by_func (socket->toplevel,
705 socket_update_focus_in,
707 g_signal_handlers_disconnect_by_func (socket->toplevel,
708 socket_update_active,
712 socket->toplevel = toplevel;
716 gtk_window_add_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
717 g_signal_connect_swapped (socket->toplevel, "notify::has-toplevel-focus",
718 G_CALLBACK (socket_update_focus_in), socket);
719 g_signal_connect_swapped (socket->toplevel, "notify::is-active",
720 G_CALLBACK (socket_update_active), socket);
723 socket_update_focus_in (socket);
724 socket_update_active (socket);
729 gtk_socket_grab_notify (GtkWidget *widget,
730 gboolean was_grabbed)
732 GtkSocket *socket = GTK_SOCKET (widget);
734 if (!socket->same_app)
735 _gtk_socket_windowing_update_modality (socket, !was_grabbed);
739 gtk_socket_key_event (GtkWidget *widget,
742 GtkSocket *socket = GTK_SOCKET (widget);
744 if (gtk_widget_has_focus (widget) && socket->plug_window && !socket->plug_widget)
746 _gtk_socket_windowing_send_key_event (socket, (GdkEvent *) event, FALSE);
755 gtk_socket_notify (GObject *object,
758 if (!strcmp (pspec->name, "is-focus"))
760 socket_update_focus_in (GTK_SOCKET (object));
764 * _gtk_socket_claim_focus:
766 * @socket: a #GtkSocket
769 * Claims focus for the socket. XXX send_event?
772 _gtk_socket_claim_focus (GtkSocket *socket,
775 GtkWidget *widget = GTK_WIDGET (socket);
778 socket->focus_in = TRUE; /* Otherwise, our notify handler will send FOCUS_IN */
780 /* Oh, the trickery... */
782 gtk_widget_set_can_focus (widget, TRUE);
783 gtk_widget_grab_focus (widget);
784 gtk_widget_set_can_focus (widget, FALSE);
788 gtk_socket_focus (GtkWidget *widget,
789 GtkDirectionType direction)
791 GtkSocket *socket = GTK_SOCKET (widget);
793 if (socket->plug_widget)
794 return gtk_widget_child_focus (socket->plug_widget, direction);
796 if (!gtk_widget_is_focus (widget))
798 _gtk_socket_windowing_focus (socket, direction);
799 _gtk_socket_claim_focus (socket, FALSE);
808 gtk_socket_remove (GtkContainer *container,
811 GtkSocket *socket = GTK_SOCKET (container);
813 g_return_if_fail (child == socket->plug_widget);
815 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
819 gtk_socket_forall (GtkContainer *container,
820 gboolean include_internals,
821 GtkCallback callback,
822 gpointer callback_data)
824 GtkSocket *socket = GTK_SOCKET (container);
826 if (socket->plug_widget)
827 (* callback) (socket->plug_widget, callback_data);
831 * _gtk_socket_add_window:
833 * @socket: a #GtkSocket
834 * @xid: the native identifier for a window
835 * @need_reparent: whether the socket's plug's window needs to be
836 * reparented to the socket
838 * Adds a window to a GtkSocket.
841 _gtk_socket_add_window (GtkSocket *socket,
843 gboolean need_reparent)
845 GtkWidget *widget = GTK_WIDGET (socket);
846 GdkDisplay *display = gtk_widget_get_display (widget);
847 gpointer user_data = NULL;
849 socket->plug_window = gdk_window_lookup_for_display (display, xid);
851 if (socket->plug_window)
853 g_object_ref (socket->plug_window);
854 gdk_window_get_user_data (socket->plug_window, &user_data);
857 if (user_data) /* A widget's window in this process */
859 GtkWidget *child_widget = user_data;
861 if (!GTK_IS_PLUG (child_widget))
863 g_warning (G_STRLOC ": Can't add non-GtkPlug to GtkSocket");
864 socket->plug_window = NULL;
865 gdk_error_trap_pop_ignored ();
870 _gtk_plug_add_to_socket (GTK_PLUG (child_widget), socket);
872 else /* A foreign window */
875 GdkDragProtocol protocol;
877 gdk_error_trap_push ();
879 if (!socket->plug_window)
881 socket->plug_window = gdk_window_foreign_new_for_display (display, xid);
882 if (!socket->plug_window) /* was deleted before we could get it */
884 gdk_error_trap_pop_ignored ();
889 _gtk_socket_windowing_select_plug_window_input (socket);
891 if (gdk_error_trap_pop ())
893 g_object_unref (socket->plug_window);
894 socket->plug_window = NULL;
898 /* OK, we now will reliably get destroy notification on socket->plug_window */
900 gdk_error_trap_push ();
904 gdk_window_hide (socket->plug_window); /* Shouldn't actually be necessary for XEMBED, but just in case */
905 gdk_window_reparent (socket->plug_window,
906 gtk_widget_get_window (widget),
910 socket->have_size = FALSE;
912 _gtk_socket_windowing_embed_get_info (socket);
914 socket->need_map = socket->is_mapped;
916 if (gdk_drag_get_protocol_for_display (display, xid, &protocol))
917 gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
920 gdk_error_trap_pop_ignored ();
922 gdk_window_add_filter (socket->plug_window,
923 _gtk_socket_windowing_filter_func,
926 /* Add a pointer to the socket on our toplevel window */
928 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
929 if (GTK_IS_WINDOW (toplevel))
930 gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
932 _gtk_socket_windowing_embed_notify (socket);
934 socket_update_active (socket);
935 socket_update_focus_in (socket);
937 gtk_widget_queue_resize (GTK_WIDGET (socket));
940 if (socket->plug_window)
941 g_signal_emit (socket, socket_signals[PLUG_ADDED], 0);
945 * _gtk_socket_handle_map_request:
947 * @socket: a #GtkSocket
949 * Called from the GtkSocket backend when the plug has been mapped.
952 _gtk_socket_handle_map_request (GtkSocket *socket)
954 if (!socket->is_mapped)
956 socket->is_mapped = TRUE;
957 socket->need_map = TRUE;
959 gtk_widget_queue_resize (GTK_WIDGET (socket));
964 * _gtk_socket_unmap_notify:
966 * @socket: a #GtkSocket
968 * Called from the GtkSocket backend when the plug has been unmapped ???
971 _gtk_socket_unmap_notify (GtkSocket *socket)
973 if (socket->is_mapped)
975 socket->is_mapped = FALSE;
976 gtk_widget_queue_resize (GTK_WIDGET (socket));
981 * _gtk_socket_advance_toplevel_focus:
983 * @socket: a #GtkSocket
984 * @direction: a direction
986 * Called from the GtkSocket backend when the corresponding plug
987 * has told the socket to move the focus.
990 _gtk_socket_advance_toplevel_focus (GtkSocket *socket,
991 GtkDirectionType direction)
995 GtkContainer *container;
997 GtkWidget *focus_widget;
999 GtkWidget *old_focus_child;
1002 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
1006 if (!gtk_widget_is_toplevel (toplevel) || GTK_IS_PLUG (toplevel))
1008 gtk_widget_child_focus (toplevel,direction);
1012 container = GTK_CONTAINER (toplevel);
1013 window = GTK_WINDOW (toplevel);
1014 bin = GTK_BIN (toplevel);
1016 /* This is a copy of gtk_window_focus(), modified so that we
1017 * can detect wrap-around.
1019 old_focus_child = gtk_container_get_focus_child (container);
1021 if (old_focus_child)
1023 if (gtk_widget_child_focus (old_focus_child, direction))
1026 /* We are allowed exactly one wrap-around per sequence of focus
1029 if (_gtk_socket_windowing_embed_get_focus_wrapped ())
1032 _gtk_socket_windowing_embed_set_focus_wrapped ();
1035 focus_widget = gtk_window_get_focus (window);
1038 /* Wrapped off the end, clear the focus setting for the toplevel */
1039 parent = gtk_widget_get_parent (focus_widget);
1042 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
1043 parent = gtk_widget_get_parent (parent);
1046 gtk_window_set_focus (GTK_WINDOW (container), NULL);
1049 /* Now try to focus the first widget in the window */
1050 child = gtk_bin_get_child (bin);
1053 if (gtk_widget_child_focus (child, direction))