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"
44 /* Forward declararations */
46 static void gtk_socket_class_init (GtkSocketClass *klass);
47 static void gtk_socket_init (GtkSocket *socket);
48 static void gtk_socket_finalize (GObject *object);
49 static void gtk_socket_notify (GObject *object,
51 static void gtk_socket_realize (GtkWidget *widget);
52 static void gtk_socket_unrealize (GtkWidget *widget);
53 static void gtk_socket_size_request (GtkWidget *widget,
54 GtkRequisition *requisition);
55 static void gtk_socket_size_allocate (GtkWidget *widget,
56 GtkAllocation *allocation);
57 static void gtk_socket_hierarchy_changed (GtkWidget *widget,
58 GtkWidget *old_toplevel);
59 static void gtk_socket_grab_notify (GtkWidget *widget,
60 gboolean was_grabbed);
61 static gboolean gtk_socket_key_event (GtkWidget *widget,
63 static gboolean gtk_socket_focus (GtkWidget *widget,
64 GtkDirectionType direction);
65 static void gtk_socket_remove (GtkContainer *container,
67 static void gtk_socket_forall (GtkContainer *container,
68 gboolean include_internals,
70 gpointer callback_data);
78 GdkModifierType accel_mods;
87 static guint socket_signals[LAST_SIGNAL] = { 0 };
89 static GtkWidgetClass *parent_class = NULL;
92 * _gtk_socket_get_private:
94 * @socket: a #GtkSocket
96 * Returns the private data associated with a GtkSocket, creating it
100 _gtk_socket_get_private (GtkSocket *socket)
102 GtkSocketPrivate *private;
103 static GQuark private_quark = 0;
106 private_quark = g_quark_from_static_string ("gtk-socket-private");
108 private = g_object_get_qdata (G_OBJECT (socket), private_quark);
112 private = g_new0 (GtkSocketPrivate, 1);
113 private->resize_count = 0;
115 g_object_set_qdata_full (G_OBJECT (socket), private_quark,
116 private, (GDestroyNotify) g_free);
123 gtk_socket_get_type (void)
125 static GType socket_type = 0;
129 static const GTypeInfo socket_info =
131 sizeof (GtkSocketClass),
132 NULL, /* base_init */
133 NULL, /* base_finalize */
134 (GClassInitFunc) gtk_socket_class_init,
135 NULL, /* class_finalize */
136 NULL, /* class_data */
138 16, /* n_preallocs */
139 (GInstanceInitFunc) gtk_socket_init,
142 socket_type = g_type_register_static (GTK_TYPE_CONTAINER, I_("GtkSocket"),
150 gtk_socket_finalize (GObject *object)
152 GtkSocket *socket = GTK_SOCKET (object);
154 g_object_unref (socket->accel_group);
155 socket->accel_group = NULL;
157 G_OBJECT_CLASS (parent_class)->finalize (object);
161 gtk_socket_class_init (GtkSocketClass *class)
163 GtkWidgetClass *widget_class;
164 GtkContainerClass *container_class;
165 GObjectClass *gobject_class;
167 gobject_class = (GObjectClass *) class;
168 widget_class = (GtkWidgetClass*) class;
169 container_class = (GtkContainerClass*) class;
171 parent_class = g_type_class_peek_parent (class);
173 gobject_class->finalize = gtk_socket_finalize;
174 gobject_class->notify = gtk_socket_notify;
176 widget_class->realize = gtk_socket_realize;
177 widget_class->unrealize = gtk_socket_unrealize;
178 widget_class->size_request = gtk_socket_size_request;
179 widget_class->size_allocate = gtk_socket_size_allocate;
180 widget_class->hierarchy_changed = gtk_socket_hierarchy_changed;
181 widget_class->grab_notify = gtk_socket_grab_notify;
182 widget_class->key_press_event = gtk_socket_key_event;
183 widget_class->key_release_event = gtk_socket_key_event;
184 widget_class->focus = gtk_socket_focus;
186 /* We don't want to show_all/hide_all the in-process
189 widget_class->show_all = gtk_widget_show;
190 widget_class->hide_all = gtk_widget_hide;
192 container_class->remove = gtk_socket_remove;
193 container_class->forall = gtk_socket_forall;
195 socket_signals[PLUG_ADDED] =
196 g_signal_new (I_("plug_added"),
197 G_OBJECT_CLASS_TYPE (class),
199 G_STRUCT_OFFSET (GtkSocketClass, plug_added),
201 _gtk_marshal_VOID__VOID,
203 socket_signals[PLUG_REMOVED] =
204 g_signal_new (I_("plug_removed"),
205 G_OBJECT_CLASS_TYPE (class),
207 G_STRUCT_OFFSET (GtkSocketClass, plug_removed),
208 _gtk_boolean_handled_accumulator, NULL,
209 _gtk_marshal_BOOLEAN__VOID,
214 gtk_socket_init (GtkSocket *socket)
216 socket->request_width = 0;
217 socket->request_height = 0;
218 socket->current_width = 0;
219 socket->current_height = 0;
221 socket->plug_window = NULL;
222 socket->plug_widget = NULL;
223 socket->focus_in = FALSE;
224 socket->have_size = FALSE;
225 socket->need_map = FALSE;
226 socket->active = FALSE;
228 socket->accel_group = gtk_accel_group_new ();
229 g_object_set_data (G_OBJECT (socket->accel_group), I_("gtk-socket"), socket);
235 * Create a new empty #GtkSocket.
237 * Return value: the new #GtkSocket.
240 gtk_socket_new (void)
244 socket = g_object_new (GTK_TYPE_SOCKET, NULL);
246 return GTK_WIDGET (socket);
251 * @socket_: a #GtkSocket
252 * @wid: the window ID of an existing toplevel window.
254 * Reparents a pre-existing toplevel window into a #GtkSocket. This is
255 * meant to embed clients that do not know about embedding into a
256 * #GtkSocket, however doing so is inherently unreliable, and using
257 * this function is not recommended.
259 * The #GtkSocket must have already be added into a toplevel window
260 * before you can make this call.
263 gtk_socket_steal (GtkSocket *socket,
266 g_return_if_fail (GTK_IS_SOCKET (socket));
267 g_return_if_fail (GTK_WIDGET_ANCHORED (socket));
269 if (!GTK_WIDGET_REALIZED (socket))
270 gtk_widget_realize (GTK_WIDGET (socket));
272 _gtk_socket_add_window (socket, wid, TRUE);
277 * @socket_: a #GtkSocket
278 * @window_id: the window ID of a client participating in the XEMBED protocol.
280 * Adds an XEMBED client, such as a #GtkPlug, to the #GtkSocket. The
281 * client may be in the same process or in a different process.
283 * To embed a #GtkPlug in a #GtkSocket, you can either create the
284 * #GtkPlug with <literal>gtk_plug_new (0)</literal>, call
285 * gtk_plug_get_id() to get the window ID of the plug, and then pass that to the
286 * gtk_socket_add_id(), or you can call gtk_socket_get_id() to get the
287 * window ID for the socket, and call gtk_plug_new() passing in that
290 * The #GtkSocket must have already be added into a toplevel window
291 * before you can make this call.
294 gtk_socket_add_id (GtkSocket *socket,
295 GdkNativeWindow window_id)
297 g_return_if_fail (GTK_IS_SOCKET (socket));
298 g_return_if_fail (GTK_WIDGET_ANCHORED (socket));
300 if (!GTK_WIDGET_REALIZED (socket))
301 gtk_widget_realize (GTK_WIDGET (socket));
303 _gtk_socket_add_window (socket, window_id, TRUE);
308 * @socket_: a #GtkSocket.
310 * Gets the window ID of a #GtkSocket widget, which can then
311 * be used to create a client embedded inside the socket, for
312 * instance with gtk_plug_new().
314 * The #GtkSocket must have already be added into a toplevel window
315 * before you can make this call.
317 * Return value: the window ID for the socket
320 gtk_socket_get_id (GtkSocket *socket)
322 g_return_val_if_fail (GTK_IS_SOCKET (socket), 0);
323 g_return_val_if_fail (GTK_WIDGET_ANCHORED (socket), 0);
325 if (!GTK_WIDGET_REALIZED (socket))
326 gtk_widget_realize (GTK_WIDGET (socket));
328 return _gtk_socket_windowing_get_id (socket);
332 gtk_socket_realize (GtkWidget *widget)
335 GdkWindowAttr attributes;
336 gint attributes_mask;
338 g_return_if_fail (GTK_IS_SOCKET (widget));
340 socket = GTK_SOCKET (widget);
341 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
343 attributes.window_type = GDK_WINDOW_CHILD;
344 attributes.x = widget->allocation.x;
345 attributes.y = widget->allocation.y;
346 attributes.width = widget->allocation.width;
347 attributes.height = widget->allocation.height;
348 attributes.wclass = GDK_INPUT_OUTPUT;
349 attributes.visual = gtk_widget_get_visual (widget);
350 attributes.colormap = gtk_widget_get_colormap (widget);
351 attributes.event_mask = GDK_FOCUS_CHANGE_MASK;
353 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
355 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
356 &attributes, attributes_mask);
357 gdk_window_set_user_data (widget->window, socket);
359 widget->style = gtk_style_attach (widget->style, widget->window);
360 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
362 _gtk_socket_windowing_realize_window (socket);
364 gdk_window_add_filter (widget->window,
365 _gtk_socket_windowing_filter_func,
368 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
370 /* We sync here so that we make sure that if the XID for
371 * our window is passed to another application, SubstructureRedirectMask
372 * will be set by the time the other app creates its window.
374 gdk_display_sync (gtk_widget_get_display (widget));
378 * _gtk_socket_end_embedding:
380 * @socket: a #GtkSocket
382 * Called to end the embedding of a plug in the socket.
385 _gtk_socket_end_embedding (GtkSocket *socket)
387 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
388 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
391 if (toplevel && GTK_IS_WINDOW (toplevel))
392 _gtk_socket_windowing_end_embedding_toplevel (socket);
394 g_object_unref (socket->plug_window);
395 socket->plug_window = NULL;
396 socket->current_width = 0;
397 socket->current_height = 0;
398 private->resize_count = 0;
400 /* Remove from end to avoid indexes shifting. This is evil */
401 for (i = socket->accel_group->n_accels - 1; i >= 0; i--)
403 GtkAccelGroupEntry *accel_entry = &socket->accel_group->priv_accels[i];
404 gtk_accel_group_disconnect (socket->accel_group, accel_entry->closure);
409 gtk_socket_unrealize (GtkWidget *widget)
411 GtkSocket *socket = GTK_SOCKET (widget);
413 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
415 if (socket->plug_widget)
417 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
419 else if (socket->plug_window)
421 _gtk_socket_end_embedding (socket);
424 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
425 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
429 gtk_socket_size_request (GtkWidget *widget,
430 GtkRequisition *requisition)
432 GtkSocket *socket = GTK_SOCKET (widget);
434 if (socket->plug_widget)
436 gtk_widget_size_request (socket->plug_widget, requisition);
440 if (socket->is_mapped && !socket->have_size && socket->plug_window)
441 _gtk_socket_windowing_size_request (socket);
443 if (socket->is_mapped && socket->have_size)
445 requisition->width = MAX (socket->request_width, 1);
446 requisition->height = MAX (socket->request_height, 1);
450 requisition->width = 1;
451 requisition->height = 1;
457 gtk_socket_size_allocate (GtkWidget *widget,
458 GtkAllocation *allocation)
462 g_return_if_fail (GTK_IS_SOCKET (widget));
463 g_return_if_fail (allocation != NULL);
465 socket = GTK_SOCKET (widget);
467 widget->allocation = *allocation;
468 if (GTK_WIDGET_REALIZED (widget))
470 gdk_window_move_resize (widget->window,
471 allocation->x, allocation->y,
472 allocation->width, allocation->height);
474 if (socket->plug_widget)
476 GtkAllocation child_allocation;
478 child_allocation.x = 0;
479 child_allocation.y = 0;
480 child_allocation.width = allocation->width;
481 child_allocation.height = allocation->height;
483 gtk_widget_size_allocate (socket->plug_widget, &child_allocation);
485 else if (socket->plug_window)
487 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
489 gdk_error_trap_push ();
491 if (allocation->width != socket->current_width ||
492 allocation->height != socket->current_height)
494 gdk_window_move_resize (socket->plug_window,
496 allocation->width, allocation->height);
497 if (private->resize_count)
498 private->resize_count--;
500 GTK_NOTE (PLUGSOCKET,
501 g_message ("GtkSocket - allocated: %d %d",
502 allocation->width, allocation->height));
503 socket->current_width = allocation->width;
504 socket->current_height = allocation->height;
507 if (socket->need_map)
509 gdk_window_show (socket->plug_window);
510 socket->need_map = FALSE;
513 while (private->resize_count)
515 _gtk_socket_windowing_send_configure_event (socket);
516 private->resize_count--;
517 GTK_NOTE (PLUGSOCKET,
518 g_message ("GtkSocket - sending synthetic configure: %d %d",
519 allocation->width, allocation->height));
522 gdk_display_sync (gtk_widget_get_display (widget));
523 gdk_error_trap_pop ();
529 activate_key (GtkAccelGroup *accel_group,
530 GObject *acceleratable,
532 GdkModifierType accel_mods,
533 GrabbedKey *grabbed_key)
535 GdkEvent *gdk_event = gtk_get_current_event ();
537 GtkSocket *socket = g_object_get_data (G_OBJECT (accel_group), "gtk-socket");
538 gboolean retval = FALSE;
540 if (gdk_event && gdk_event->type == GDK_KEY_PRESS && socket->plug_window)
542 _gtk_socket_windowing_send_key_event (socket, gdk_event, TRUE);
547 gdk_event_free (gdk_event);
553 find_accel_key (GtkAccelKey *key,
557 GrabbedKey *grabbed_key = data;
559 return (key->accel_key == grabbed_key->accel_key &&
560 key->accel_mods == grabbed_key->accel_mods);
564 * _gtk_socket_add_grabbed_key:
566 * @socket: a #GtkSocket
568 * @modifiers: modifiers for the key
570 * Called from the GtkSocket platform-specific backend when the
571 * corresponding plug has told the socket to grab a key.
574 _gtk_socket_add_grabbed_key (GtkSocket *socket,
576 GdkModifierType modifiers)
579 GrabbedKey *grabbed_key;
581 grabbed_key = g_new (GrabbedKey, 1);
583 grabbed_key->accel_key = keyval;
584 grabbed_key->accel_mods = modifiers;
586 if (gtk_accel_group_find (socket->accel_group,
590 g_warning ("GtkSocket: request to add already present grabbed key %u,%#x\n",
592 g_free (grabbed_key);
596 closure = g_cclosure_new (G_CALLBACK (activate_key), grabbed_key, (GClosureNotify)g_free);
598 gtk_accel_group_connect (socket->accel_group, keyval, modifiers, GTK_ACCEL_LOCKED,
603 * _gtk_socket_remove_grabbed_key:
605 * @socket: a #GtkSocket
607 * @modifiers: modifiers for the key
609 * Called from the GtkSocket backend when the corresponding plug has
610 * told the socket to remove a key grab.
613 _gtk_socket_remove_grabbed_key (GtkSocket *socket,
615 GdkModifierType modifiers)
619 for (i = 0; i < socket->accel_group->n_accels; i++)
621 GtkAccelGroupEntry *accel_entry = &socket->accel_group->priv_accels[i];
622 if (accel_entry->key.accel_key == keyval &&
623 accel_entry->key.accel_mods == modifiers)
625 gtk_accel_group_disconnect (socket->accel_group,
626 accel_entry->closure);
631 g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
636 socket_update_focus_in (GtkSocket *socket)
638 gboolean focus_in = FALSE;
640 if (socket->plug_window)
642 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
644 if (GTK_WIDGET_TOPLEVEL (toplevel) &&
645 GTK_WINDOW (toplevel)->has_toplevel_focus &&
646 gtk_widget_is_focus (GTK_WIDGET (socket)))
650 if (focus_in != socket->focus_in)
652 socket->focus_in = focus_in;
654 _gtk_socket_windowing_focus_change (socket, focus_in);
659 socket_update_active (GtkSocket *socket)
661 gboolean active = FALSE;
663 if (socket->plug_window)
665 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
667 if (GTK_WIDGET_TOPLEVEL (toplevel) &&
668 GTK_WINDOW (toplevel)->is_active)
672 if (active != socket->active)
674 socket->active = active;
676 _gtk_socket_windowing_update_active (socket, active);
681 gtk_socket_hierarchy_changed (GtkWidget *widget,
682 GtkWidget *old_toplevel)
684 GtkSocket *socket = GTK_SOCKET (widget);
685 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
687 if (toplevel && !GTK_IS_WINDOW (toplevel))
690 if (toplevel != socket->toplevel)
692 if (socket->toplevel)
694 gtk_window_remove_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
695 g_signal_handlers_disconnect_by_func (socket->toplevel,
696 socket_update_focus_in,
698 g_signal_handlers_disconnect_by_func (socket->toplevel,
699 socket_update_active,
703 socket->toplevel = toplevel;
707 gtk_window_add_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
708 g_signal_connect_swapped (socket->toplevel, "notify::has-toplevel-focus",
709 G_CALLBACK (socket_update_focus_in), socket);
710 g_signal_connect_swapped (socket->toplevel, "notify::is-active",
711 G_CALLBACK (socket_update_active), socket);
714 socket_update_focus_in (socket);
715 socket_update_active (socket);
720 gtk_socket_grab_notify (GtkWidget *widget,
721 gboolean was_grabbed)
723 GtkSocket *socket = GTK_SOCKET (widget);
725 if (!socket->same_app)
726 _gtk_socket_windowing_update_modality (socket, !was_grabbed);
730 gtk_socket_key_event (GtkWidget *widget,
733 GtkSocket *socket = GTK_SOCKET (widget);
735 if (GTK_WIDGET_HAS_FOCUS (socket) && socket->plug_window && !socket->plug_widget)
737 _gtk_socket_windowing_send_key_event (socket, (GdkEvent *) event, FALSE);
746 gtk_socket_notify (GObject *object,
749 if (!strcmp (pspec->name, "is-focus"))
751 socket_update_focus_in (GTK_SOCKET (object));
755 * _gtk_socket_claim_focus:
757 * @socket: a #GtkSocket
760 * Claims focus for the socket. XXX send_event?
763 _gtk_socket_claim_focus (GtkSocket *socket,
767 socket->focus_in = TRUE; /* Otherwise, our notify handler will send FOCUS_IN */
769 /* Oh, the trickery... */
771 GTK_WIDGET_SET_FLAGS (socket, GTK_CAN_FOCUS);
772 gtk_widget_grab_focus (GTK_WIDGET (socket));
773 GTK_WIDGET_UNSET_FLAGS (socket, GTK_CAN_FOCUS);
777 gtk_socket_focus (GtkWidget *widget,
778 GtkDirectionType direction)
782 g_return_val_if_fail (GTK_IS_SOCKET (widget), FALSE);
784 socket = GTK_SOCKET (widget);
786 if (socket->plug_widget)
787 return gtk_widget_child_focus (socket->plug_widget, direction);
789 if (!gtk_widget_is_focus (widget))
791 _gtk_socket_windowing_focus (socket, direction);
792 _gtk_socket_claim_focus (socket, FALSE);
801 gtk_socket_remove (GtkContainer *container,
804 GtkSocket *socket = GTK_SOCKET (container);
806 g_return_if_fail (child == socket->plug_widget);
808 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
812 gtk_socket_forall (GtkContainer *container,
813 gboolean include_internals,
814 GtkCallback callback,
815 gpointer callback_data)
817 GtkSocket *socket = GTK_SOCKET (container);
819 if (socket->plug_widget)
820 (* callback) (socket->plug_widget, callback_data);
824 * _gtk_socket_add_window:
826 * @socket: a #GtkSocket
827 * @xid: the native identifier for a window
828 * @need_reparent: whether the socket's plug's window needs to be
829 * reparented to the socket
831 * Adds a window to a GtkSocket.
834 _gtk_socket_add_window (GtkSocket *socket,
836 gboolean need_reparent)
838 GtkWidget *widget = GTK_WIDGET (socket);
839 GdkDisplay *display = gtk_widget_get_display (widget);
840 gpointer user_data = NULL;
842 socket->plug_window = gdk_window_lookup_for_display (display, xid);
844 if (socket->plug_window)
846 g_object_ref (socket->plug_window);
847 gdk_window_get_user_data (socket->plug_window, &user_data);
850 if (user_data) /* A widget's window in this process */
852 GtkWidget *child_widget = user_data;
854 if (!GTK_IS_PLUG (child_widget))
856 g_warning (G_STRLOC ": Can't add non-GtkPlug to GtkSocket");
857 socket->plug_window = NULL;
858 gdk_error_trap_pop ();
863 _gtk_plug_add_to_socket (GTK_PLUG (child_widget), socket);
865 else /* A foreign window */
868 GdkDragProtocol protocol;
870 gdk_error_trap_push ();
872 if (!socket->plug_window)
874 socket->plug_window = gdk_window_foreign_new_for_display (display, xid);
875 if (!socket->plug_window) /* was deleted before we could get it */
877 gdk_error_trap_pop ();
882 _gtk_socket_windowing_select_plug_window_input (socket);
884 if (gdk_error_trap_pop ())
886 g_object_unref (socket->plug_window);
887 socket->plug_window = NULL;
891 /* OK, we now will reliably get destroy notification on socket->plug_window */
893 gdk_error_trap_push ();
897 gdk_window_hide (socket->plug_window); /* Shouldn't actually be necessary for XEMBED, but just in case */
898 gdk_window_reparent (socket->plug_window, widget->window, 0, 0);
901 socket->have_size = FALSE;
903 _gtk_socket_windowing_embed_get_info (socket);
905 socket->need_map = socket->is_mapped;
907 if (gdk_drag_get_protocol_for_display (display, xid, &protocol))
908 gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
911 gdk_display_sync (display);
912 gdk_error_trap_pop ();
914 gdk_window_add_filter (socket->plug_window,
915 _gtk_socket_windowing_filter_func,
918 /* Add a pointer to the socket on our toplevel window */
920 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
921 if (toplevel && GTK_IS_WINDOW (toplevel))
922 gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
924 _gtk_socket_windowing_embed_notify (socket);
926 socket_update_active (socket);
927 socket_update_focus_in (socket);
929 gtk_widget_queue_resize (GTK_WIDGET (socket));
932 if (socket->plug_window)
933 g_signal_emit (socket, socket_signals[PLUG_ADDED], 0);
937 * _gtk_socket_handle_map_request:
939 * @socket: a #GtkSocket
941 * Called from the GtkSocket backend when the plug has been mapped.
944 _gtk_socket_handle_map_request (GtkSocket *socket)
946 if (!socket->is_mapped)
948 socket->is_mapped = TRUE;
949 socket->need_map = TRUE;
951 gtk_widget_queue_resize (GTK_WIDGET (socket));
956 * _gtk_socket_unmap_notify:
958 * @socket: a #GtkSocket
960 * Called from the GtkSocket backend when the plug has been unmapped ???
963 _gtk_socket_unmap_notify (GtkSocket *socket)
965 if (socket->is_mapped)
967 socket->is_mapped = FALSE;
968 gtk_widget_queue_resize (GTK_WIDGET (socket));
973 * _gtk_socket_advance_toplevel_focus:
975 * @socket: a #GtkSocket
976 * @direction: a direction
978 * Called from the GtkSocket backend when the corresponding plug
979 * has told the socket to move the focus.
982 _gtk_socket_advance_toplevel_focus (GtkSocket *socket,
983 GtkDirectionType direction)
987 GtkContainer *container;
989 GtkWidget *old_focus_child;
992 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
996 if (!GTK_WIDGET_TOPLEVEL (toplevel) || GTK_IS_PLUG (toplevel))
998 gtk_widget_child_focus (toplevel,direction);
1002 container = GTK_CONTAINER (toplevel);
1003 window = GTK_WINDOW (toplevel);
1004 bin = GTK_BIN (toplevel);
1006 /* This is a copy of gtk_window_focus(), modified so that we
1007 * can detect wrap-around.
1009 old_focus_child = container->focus_child;
1011 if (old_focus_child)
1013 if (gtk_widget_child_focus (old_focus_child, direction))
1016 /* We are allowed exactly one wrap-around per sequence of focus
1019 if (_gtk_socket_windowing_embed_get_focus_wrapped ())
1022 _gtk_socket_windowing_embed_set_focus_wrapped ();
1025 if (window->focus_widget)
1027 /* Wrapped off the end, clear the focus setting for the toplevel */
1028 parent = window->focus_widget->parent;
1031 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
1032 parent = GTK_WIDGET (parent)->parent;
1035 gtk_window_set_focus (GTK_WINDOW (container), NULL);
1038 /* Now try to focus the first widget in the window */
1041 if (gtk_widget_child_focus (bin->child, direction))
1046 #define __GTK_SOCKET_C__
1047 #include "gtkaliasdef.c"