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.event_mask = GDK_FOCUS_CHANGE_MASK;
386 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
388 window = gdk_window_new (gtk_widget_get_parent_window (widget),
389 &attributes, attributes_mask);
390 gtk_widget_set_window (widget, window);
391 gdk_window_set_user_data (window, socket);
393 gtk_widget_style_attach (widget);
394 gtk_style_set_background (gtk_widget_get_style (widget),
395 window, GTK_STATE_NORMAL);
397 _gtk_socket_windowing_realize_window (socket);
399 gdk_window_add_filter (window,
400 _gtk_socket_windowing_filter_func,
403 /* We sync here so that we make sure that if the XID for
404 * our window is passed to another application, SubstructureRedirectMask
405 * will be set by the time the other app creates its window.
407 gdk_display_sync (gtk_widget_get_display (widget));
411 * _gtk_socket_end_embedding:
413 * @socket: a #GtkSocket
415 * Called to end the embedding of a plug in the socket.
418 _gtk_socket_end_embedding (GtkSocket *socket)
420 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
421 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
423 if (GTK_IS_WINDOW (toplevel))
424 _gtk_socket_windowing_end_embedding_toplevel (socket);
426 g_object_unref (socket->plug_window);
427 socket->plug_window = NULL;
428 socket->current_width = 0;
429 socket->current_height = 0;
430 private->resize_count = 0;
432 gtk_accel_group_disconnect (socket->accel_group, NULL);
436 gtk_socket_unrealize (GtkWidget *widget)
438 GtkSocket *socket = GTK_SOCKET (widget);
440 gtk_widget_set_realized (widget, FALSE);
442 if (socket->plug_widget)
444 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
446 else if (socket->plug_window)
448 _gtk_socket_end_embedding (socket);
451 GTK_WIDGET_CLASS (gtk_socket_parent_class)->unrealize (widget);
455 gtk_socket_size_request (GtkWidget *widget,
456 GtkRequisition *requisition)
458 GtkSocket *socket = GTK_SOCKET (widget);
460 if (socket->plug_widget)
462 gtk_widget_get_preferred_size (socket->plug_widget, requisition, NULL);
466 if (socket->is_mapped && !socket->have_size && socket->plug_window)
467 _gtk_socket_windowing_size_request (socket);
469 if (socket->is_mapped && socket->have_size)
471 requisition->width = MAX (socket->request_width, 1);
472 requisition->height = MAX (socket->request_height, 1);
476 requisition->width = 1;
477 requisition->height = 1;
483 gtk_socket_size_allocate (GtkWidget *widget,
484 GtkAllocation *allocation)
486 GtkSocket *socket = GTK_SOCKET (widget);
488 gtk_widget_set_allocation (widget, allocation);
489 if (gtk_widget_get_realized (widget))
491 gdk_window_move_resize (gtk_widget_get_window (widget),
492 allocation->x, allocation->y,
493 allocation->width, allocation->height);
495 if (socket->plug_widget)
497 GtkAllocation child_allocation;
499 child_allocation.x = 0;
500 child_allocation.y = 0;
501 child_allocation.width = allocation->width;
502 child_allocation.height = allocation->height;
504 gtk_widget_size_allocate (socket->plug_widget, &child_allocation);
506 else if (socket->plug_window)
508 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
510 gdk_error_trap_push ();
512 if (allocation->width != socket->current_width ||
513 allocation->height != socket->current_height)
515 gdk_window_move_resize (socket->plug_window,
517 allocation->width, allocation->height);
518 if (private->resize_count)
519 private->resize_count--;
521 GTK_NOTE (PLUGSOCKET,
522 g_message ("GtkSocket - allocated: %d %d",
523 allocation->width, allocation->height));
524 socket->current_width = allocation->width;
525 socket->current_height = allocation->height;
528 if (socket->need_map)
530 gdk_window_show (socket->plug_window);
531 socket->need_map = FALSE;
534 while (private->resize_count)
536 _gtk_socket_windowing_send_configure_event (socket);
537 private->resize_count--;
538 GTK_NOTE (PLUGSOCKET,
539 g_message ("GtkSocket - sending synthetic configure: %d %d",
540 allocation->width, allocation->height));
543 gdk_error_trap_pop_ignored ();
549 activate_key (GtkAccelGroup *accel_group,
550 GObject *acceleratable,
552 GdkModifierType accel_mods,
553 GrabbedKey *grabbed_key)
555 GdkEvent *gdk_event = gtk_get_current_event ();
557 GtkSocket *socket = g_object_get_data (G_OBJECT (accel_group), "gtk-socket");
558 gboolean retval = FALSE;
560 if (gdk_event && gdk_event->type == GDK_KEY_PRESS && socket->plug_window)
562 _gtk_socket_windowing_send_key_event (socket, gdk_event, FALSE);
567 gdk_event_free (gdk_event);
573 find_accel_key (GtkAccelKey *key,
577 GrabbedKey *grabbed_key = data;
579 return (key->accel_key == grabbed_key->accel_key &&
580 key->accel_mods == grabbed_key->accel_mods);
584 * _gtk_socket_add_grabbed_key:
586 * @socket: a #GtkSocket
588 * @modifiers: modifiers for the key
590 * Called from the GtkSocket platform-specific backend when the
591 * corresponding plug has told the socket to grab a key.
594 _gtk_socket_add_grabbed_key (GtkSocket *socket,
596 GdkModifierType modifiers)
599 GrabbedKey *grabbed_key;
601 grabbed_key = g_new (GrabbedKey, 1);
603 grabbed_key->accel_key = keyval;
604 grabbed_key->accel_mods = modifiers;
606 if (gtk_accel_group_find (socket->accel_group,
610 g_warning ("GtkSocket: request to add already present grabbed key %u,%#x\n",
612 g_free (grabbed_key);
616 closure = g_cclosure_new (G_CALLBACK (activate_key), grabbed_key, (GClosureNotify)g_free);
618 gtk_accel_group_connect (socket->accel_group, keyval, modifiers, GTK_ACCEL_LOCKED,
623 * _gtk_socket_remove_grabbed_key:
625 * @socket: a #GtkSocket
627 * @modifiers: modifiers for the key
629 * Called from the GtkSocket backend when the corresponding plug has
630 * told the socket to remove a key grab.
633 _gtk_socket_remove_grabbed_key (GtkSocket *socket,
635 GdkModifierType modifiers)
637 if (!gtk_accel_group_disconnect_key (socket->accel_group, keyval, modifiers))
638 g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
643 socket_update_focus_in (GtkSocket *socket)
645 gboolean focus_in = FALSE;
647 if (socket->plug_window)
649 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
651 if (gtk_widget_is_toplevel (toplevel) &&
652 gtk_window_has_toplevel_focus (GTK_WINDOW (toplevel)) &&
653 gtk_widget_is_focus (GTK_WIDGET (socket)))
657 if (focus_in != socket->focus_in)
659 socket->focus_in = focus_in;
661 _gtk_socket_windowing_focus_change (socket, focus_in);
666 socket_update_active (GtkSocket *socket)
668 gboolean active = FALSE;
670 if (socket->plug_window)
672 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
674 if (gtk_widget_is_toplevel (toplevel) &&
675 gtk_window_is_active (GTK_WINDOW (toplevel)))
679 if (active != socket->active)
681 socket->active = active;
683 _gtk_socket_windowing_update_active (socket, active);
688 gtk_socket_hierarchy_changed (GtkWidget *widget,
689 GtkWidget *old_toplevel)
691 GtkSocket *socket = GTK_SOCKET (widget);
692 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
694 if (toplevel && !GTK_IS_WINDOW (toplevel))
697 if (toplevel != socket->toplevel)
699 if (socket->toplevel)
701 gtk_window_remove_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
702 g_signal_handlers_disconnect_by_func (socket->toplevel,
703 socket_update_focus_in,
705 g_signal_handlers_disconnect_by_func (socket->toplevel,
706 socket_update_active,
710 socket->toplevel = toplevel;
714 gtk_window_add_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
715 g_signal_connect_swapped (socket->toplevel, "notify::has-toplevel-focus",
716 G_CALLBACK (socket_update_focus_in), socket);
717 g_signal_connect_swapped (socket->toplevel, "notify::is-active",
718 G_CALLBACK (socket_update_active), socket);
721 socket_update_focus_in (socket);
722 socket_update_active (socket);
727 gtk_socket_grab_notify (GtkWidget *widget,
728 gboolean was_grabbed)
730 GtkSocket *socket = GTK_SOCKET (widget);
732 if (!socket->same_app)
733 _gtk_socket_windowing_update_modality (socket, !was_grabbed);
737 gtk_socket_key_event (GtkWidget *widget,
740 GtkSocket *socket = GTK_SOCKET (widget);
742 if (gtk_widget_has_focus (widget) && socket->plug_window && !socket->plug_widget)
744 _gtk_socket_windowing_send_key_event (socket, (GdkEvent *) event, FALSE);
753 gtk_socket_notify (GObject *object,
756 if (!strcmp (pspec->name, "is-focus"))
758 socket_update_focus_in (GTK_SOCKET (object));
762 * _gtk_socket_claim_focus:
764 * @socket: a #GtkSocket
767 * Claims focus for the socket. XXX send_event?
770 _gtk_socket_claim_focus (GtkSocket *socket,
773 GtkWidget *widget = GTK_WIDGET (socket);
776 socket->focus_in = TRUE; /* Otherwise, our notify handler will send FOCUS_IN */
778 /* Oh, the trickery... */
780 gtk_widget_set_can_focus (widget, TRUE);
781 gtk_widget_grab_focus (widget);
782 gtk_widget_set_can_focus (widget, FALSE);
786 gtk_socket_focus (GtkWidget *widget,
787 GtkDirectionType direction)
789 GtkSocket *socket = GTK_SOCKET (widget);
791 if (socket->plug_widget)
792 return gtk_widget_child_focus (socket->plug_widget, direction);
794 if (!gtk_widget_is_focus (widget))
796 _gtk_socket_windowing_focus (socket, direction);
797 _gtk_socket_claim_focus (socket, FALSE);
806 gtk_socket_remove (GtkContainer *container,
809 GtkSocket *socket = GTK_SOCKET (container);
811 g_return_if_fail (child == socket->plug_widget);
813 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
817 gtk_socket_forall (GtkContainer *container,
818 gboolean include_internals,
819 GtkCallback callback,
820 gpointer callback_data)
822 GtkSocket *socket = GTK_SOCKET (container);
824 if (socket->plug_widget)
825 (* callback) (socket->plug_widget, callback_data);
829 * _gtk_socket_add_window:
831 * @socket: a #GtkSocket
832 * @xid: the native identifier for a window
833 * @need_reparent: whether the socket's plug's window needs to be
834 * reparented to the socket
836 * Adds a window to a GtkSocket.
839 _gtk_socket_add_window (GtkSocket *socket,
841 gboolean need_reparent)
843 GtkWidget *widget = GTK_WIDGET (socket);
844 GdkDisplay *display = gtk_widget_get_display (widget);
845 gpointer user_data = NULL;
847 socket->plug_window = gdk_window_lookup_for_display (display, xid);
849 if (socket->plug_window)
851 g_object_ref (socket->plug_window);
852 gdk_window_get_user_data (socket->plug_window, &user_data);
855 if (user_data) /* A widget's window in this process */
857 GtkWidget *child_widget = user_data;
859 if (!GTK_IS_PLUG (child_widget))
861 g_warning (G_STRLOC ": Can't add non-GtkPlug to GtkSocket");
862 socket->plug_window = NULL;
863 gdk_error_trap_pop_ignored ();
868 _gtk_plug_add_to_socket (GTK_PLUG (child_widget), socket);
870 else /* A foreign window */
873 GdkDragProtocol protocol;
875 gdk_error_trap_push ();
877 if (!socket->plug_window)
879 socket->plug_window = gdk_window_foreign_new_for_display (display, xid);
880 if (!socket->plug_window) /* was deleted before we could get it */
882 gdk_error_trap_pop_ignored ();
887 _gtk_socket_windowing_select_plug_window_input (socket);
889 if (gdk_error_trap_pop ())
891 g_object_unref (socket->plug_window);
892 socket->plug_window = NULL;
896 /* OK, we now will reliably get destroy notification on socket->plug_window */
898 gdk_error_trap_push ();
902 gdk_window_hide (socket->plug_window); /* Shouldn't actually be necessary for XEMBED, but just in case */
903 gdk_window_reparent (socket->plug_window,
904 gtk_widget_get_window (widget),
908 socket->have_size = FALSE;
910 _gtk_socket_windowing_embed_get_info (socket);
912 socket->need_map = socket->is_mapped;
914 if (gdk_drag_get_protocol_for_display (display, xid, &protocol))
915 gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
918 gdk_error_trap_pop_ignored ();
920 gdk_window_add_filter (socket->plug_window,
921 _gtk_socket_windowing_filter_func,
924 /* Add a pointer to the socket on our toplevel window */
926 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
927 if (GTK_IS_WINDOW (toplevel))
928 gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
930 _gtk_socket_windowing_embed_notify (socket);
932 socket_update_active (socket);
933 socket_update_focus_in (socket);
935 gtk_widget_queue_resize (GTK_WIDGET (socket));
938 if (socket->plug_window)
939 g_signal_emit (socket, socket_signals[PLUG_ADDED], 0);
943 * _gtk_socket_handle_map_request:
945 * @socket: a #GtkSocket
947 * Called from the GtkSocket backend when the plug has been mapped.
950 _gtk_socket_handle_map_request (GtkSocket *socket)
952 if (!socket->is_mapped)
954 socket->is_mapped = TRUE;
955 socket->need_map = TRUE;
957 gtk_widget_queue_resize (GTK_WIDGET (socket));
962 * _gtk_socket_unmap_notify:
964 * @socket: a #GtkSocket
966 * Called from the GtkSocket backend when the plug has been unmapped ???
969 _gtk_socket_unmap_notify (GtkSocket *socket)
971 if (socket->is_mapped)
973 socket->is_mapped = FALSE;
974 gtk_widget_queue_resize (GTK_WIDGET (socket));
979 * _gtk_socket_advance_toplevel_focus:
981 * @socket: a #GtkSocket
982 * @direction: a direction
984 * Called from the GtkSocket backend when the corresponding plug
985 * has told the socket to move the focus.
988 _gtk_socket_advance_toplevel_focus (GtkSocket *socket,
989 GtkDirectionType direction)
993 GtkContainer *container;
995 GtkWidget *focus_widget;
997 GtkWidget *old_focus_child;
1000 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
1004 if (!gtk_widget_is_toplevel (toplevel) || GTK_IS_PLUG (toplevel))
1006 gtk_widget_child_focus (toplevel,direction);
1010 container = GTK_CONTAINER (toplevel);
1011 window = GTK_WINDOW (toplevel);
1012 bin = GTK_BIN (toplevel);
1014 /* This is a copy of gtk_window_focus(), modified so that we
1015 * can detect wrap-around.
1017 old_focus_child = gtk_container_get_focus_child (container);
1019 if (old_focus_child)
1021 if (gtk_widget_child_focus (old_focus_child, direction))
1024 /* We are allowed exactly one wrap-around per sequence of focus
1027 if (_gtk_socket_windowing_embed_get_focus_wrapped ())
1030 _gtk_socket_windowing_embed_set_focus_wrapped ();
1033 focus_widget = gtk_window_get_focus (window);
1036 /* Wrapped off the end, clear the focus setting for the toplevel */
1037 parent = gtk_widget_get_parent (focus_widget);
1040 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
1041 parent = gtk_widget_get_parent (parent);
1044 gtk_window_set_focus (GTK_WINDOW (container), NULL);
1047 /* Now try to focus the first widget in the window */
1048 child = gtk_bin_get_child (bin);
1051 if (gtk_widget_child_focus (child, direction))