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"
40 #include "gtkextendedlayout.h"
45 /* Forward declararations */
47 static void gtk_socket_finalize (GObject *object);
48 static void gtk_socket_notify (GObject *object,
50 static void gtk_socket_realize (GtkWidget *widget);
51 static void gtk_socket_unrealize (GtkWidget *widget);
52 static void gtk_socket_size_request (GtkWidget *widget,
53 GtkRequisition *requisition);
54 static void gtk_socket_size_allocate (GtkWidget *widget,
55 GtkAllocation *allocation);
56 static void gtk_socket_hierarchy_changed (GtkWidget *widget,
57 GtkWidget *old_toplevel);
58 static void gtk_socket_grab_notify (GtkWidget *widget,
59 gboolean was_grabbed);
60 static gboolean gtk_socket_key_event (GtkWidget *widget,
62 static gboolean gtk_socket_focus (GtkWidget *widget,
63 GtkDirectionType direction);
64 static void gtk_socket_remove (GtkContainer *container,
66 static void gtk_socket_forall (GtkContainer *container,
67 gboolean include_internals,
69 gpointer callback_data);
71 static void gtk_socket_extended_layout_interface_init (GtkExtendedLayoutIface *iface);
78 GdkModifierType accel_mods;
87 static guint socket_signals[LAST_SIGNAL] = { 0 };
90 * _gtk_socket_get_private:
92 * @socket: a #GtkSocket
94 * Returns the private data associated with a GtkSocket, creating it
98 _gtk_socket_get_private (GtkSocket *socket)
100 return G_TYPE_INSTANCE_GET_PRIVATE (socket, GTK_TYPE_SOCKET, GtkSocketPrivate);
103 G_DEFINE_TYPE_WITH_CODE (GtkSocket, gtk_socket, GTK_TYPE_CONTAINER,
104 G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT,
105 gtk_socket_extended_layout_interface_init))
109 gtk_socket_finalize (GObject *object)
111 GtkSocket *socket = GTK_SOCKET (object);
113 g_object_unref (socket->accel_group);
114 socket->accel_group = NULL;
116 G_OBJECT_CLASS (gtk_socket_parent_class)->finalize (object);
120 gtk_socket_class_init (GtkSocketClass *class)
122 GtkWidgetClass *widget_class;
123 GtkContainerClass *container_class;
124 GObjectClass *gobject_class;
126 gobject_class = (GObjectClass *) class;
127 widget_class = (GtkWidgetClass*) class;
128 container_class = (GtkContainerClass*) class;
130 gobject_class->finalize = gtk_socket_finalize;
131 gobject_class->notify = gtk_socket_notify;
133 widget_class->realize = gtk_socket_realize;
134 widget_class->unrealize = gtk_socket_unrealize;
135 widget_class->size_request = gtk_socket_size_request;
136 widget_class->size_allocate = gtk_socket_size_allocate;
137 widget_class->hierarchy_changed = gtk_socket_hierarchy_changed;
138 widget_class->grab_notify = gtk_socket_grab_notify;
139 widget_class->key_press_event = gtk_socket_key_event;
140 widget_class->key_release_event = gtk_socket_key_event;
141 widget_class->focus = gtk_socket_focus;
143 /* We don't want to show_all/hide_all the in-process
146 widget_class->show_all = gtk_widget_show;
147 widget_class->hide_all = gtk_widget_hide;
149 container_class->remove = gtk_socket_remove;
150 container_class->forall = gtk_socket_forall;
153 * GtkSocket::plug-added:
154 * @socket_: the object which received the signal
156 * This signal is emitted when a client is successfully
157 * added to the socket.
159 socket_signals[PLUG_ADDED] =
160 g_signal_new (I_("plug-added"),
161 G_OBJECT_CLASS_TYPE (class),
163 G_STRUCT_OFFSET (GtkSocketClass, plug_added),
165 _gtk_marshal_VOID__VOID,
169 * GtkSocket::plug-removed:
170 * @socket_: the object which received the signal
172 * This signal is emitted when a client is removed from the socket.
173 * The default action is to destroy the #GtkSocket widget, so if you
174 * want to reuse it you must add a signal handler that returns %TRUE.
176 * Return value: %TRUE to stop other handlers from being invoked.
178 socket_signals[PLUG_REMOVED] =
179 g_signal_new (I_("plug-removed"),
180 G_OBJECT_CLASS_TYPE (class),
182 G_STRUCT_OFFSET (GtkSocketClass, plug_removed),
183 _gtk_boolean_handled_accumulator, NULL,
184 _gtk_marshal_BOOLEAN__VOID,
187 g_type_class_add_private (gobject_class, sizeof (GtkSocketPrivate));
191 gtk_socket_init (GtkSocket *socket)
193 GtkSocketPrivate *priv;
195 socket->request_width = 0;
196 socket->request_height = 0;
197 socket->current_width = 0;
198 socket->current_height = 0;
200 socket->plug_window = NULL;
201 socket->plug_widget = NULL;
202 socket->focus_in = FALSE;
203 socket->have_size = FALSE;
204 socket->need_map = FALSE;
205 socket->active = FALSE;
207 socket->accel_group = gtk_accel_group_new ();
208 g_object_set_data (G_OBJECT (socket->accel_group), I_("gtk-socket"), socket);
210 priv = _gtk_socket_get_private (socket);
211 priv->have_natural_size = FALSE;
217 * Create a new empty #GtkSocket.
219 * Return value: the new #GtkSocket.
222 gtk_socket_new (void)
226 socket = g_object_new (GTK_TYPE_SOCKET, NULL);
228 return GTK_WIDGET (socket);
233 * @socket_: a #GtkSocket
234 * @wid: the window ID of an existing toplevel window.
236 * Reparents a pre-existing toplevel window into a #GtkSocket. This is
237 * meant to embed clients that do not know about embedding into a
238 * #GtkSocket, however doing so is inherently unreliable, and using
239 * this function is not recommended.
241 * The #GtkSocket must have already be added into a toplevel window
242 * before you can make this call.
245 gtk_socket_steal (GtkSocket *socket,
248 g_return_if_fail (GTK_IS_SOCKET (socket));
249 g_return_if_fail (GTK_WIDGET_ANCHORED (socket));
251 if (!GTK_WIDGET_REALIZED (socket))
252 gtk_widget_realize (GTK_WIDGET (socket));
254 _gtk_socket_add_window (socket, wid, TRUE);
259 * @socket_: a #GtkSocket
260 * @window_id: the window ID of a client participating in the XEMBED protocol.
262 * Adds an XEMBED client, such as a #GtkPlug, to the #GtkSocket. The
263 * client may be in the same process or in a different process.
265 * To embed a #GtkPlug in a #GtkSocket, you can either create the
266 * #GtkPlug with <literal>gtk_plug_new (0)</literal>, call
267 * gtk_plug_get_id() to get the window ID of the plug, and then pass that to the
268 * gtk_socket_add_id(), or you can call gtk_socket_get_id() to get the
269 * window ID for the socket, and call gtk_plug_new() passing in that
272 * The #GtkSocket must have already be added into a toplevel window
273 * before you can make this call.
276 gtk_socket_add_id (GtkSocket *socket,
277 GdkNativeWindow window_id)
279 g_return_if_fail (GTK_IS_SOCKET (socket));
280 g_return_if_fail (GTK_WIDGET_ANCHORED (socket));
282 if (!GTK_WIDGET_REALIZED (socket))
283 gtk_widget_realize (GTK_WIDGET (socket));
285 _gtk_socket_add_window (socket, window_id, TRUE);
290 * @socket_: a #GtkSocket.
292 * Gets the window ID of a #GtkSocket widget, which can then
293 * be used to create a client embedded inside the socket, for
294 * instance with gtk_plug_new().
296 * The #GtkSocket must have already be added into a toplevel window
297 * before you can make this call.
299 * Return value: the window ID for the socket
302 gtk_socket_get_id (GtkSocket *socket)
304 g_return_val_if_fail (GTK_IS_SOCKET (socket), 0);
305 g_return_val_if_fail (GTK_WIDGET_ANCHORED (socket), 0);
307 if (!GTK_WIDGET_REALIZED (socket))
308 gtk_widget_realize (GTK_WIDGET (socket));
310 return _gtk_socket_windowing_get_id (socket);
314 * gtk_socket_get_plug_window:
315 * @socket_: a #GtkSocket.
317 * Retrieves the window of the plug. Use this to check if the plug has
318 * been created inside of the socket.
320 * Return value: the window of the plug if available, or %NULL
325 gtk_socket_get_plug_window (GtkSocket *socket)
327 g_return_val_if_fail (GTK_IS_SOCKET (socket), NULL);
329 return socket->plug_window;
333 gtk_socket_realize (GtkWidget *widget)
335 GtkSocket *socket = GTK_SOCKET (widget);
336 GdkWindowAttr attributes;
337 gint attributes_mask;
339 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
341 attributes.window_type = GDK_WINDOW_CHILD;
342 attributes.x = widget->allocation.x;
343 attributes.y = widget->allocation.y;
344 attributes.width = widget->allocation.width;
345 attributes.height = widget->allocation.height;
346 attributes.wclass = GDK_INPUT_OUTPUT;
347 attributes.visual = gtk_widget_get_visual (widget);
348 attributes.colormap = gtk_widget_get_colormap (widget);
349 attributes.event_mask = GDK_FOCUS_CHANGE_MASK;
351 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
353 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
354 &attributes, attributes_mask);
355 gdk_window_set_user_data (widget->window, socket);
357 widget->style = gtk_style_attach (widget->style, widget->window);
358 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
360 _gtk_socket_windowing_realize_window (socket);
362 gdk_window_add_filter (widget->window,
363 _gtk_socket_windowing_filter_func,
366 /* We sync here so that we make sure that if the XID for
367 * our window is passed to another application, SubstructureRedirectMask
368 * will be set by the time the other app creates its window.
370 gdk_display_sync (gtk_widget_get_display (widget));
374 * _gtk_socket_end_embedding:
376 * @socket: a #GtkSocket
378 * Called to end the embedding of a plug in the socket.
381 _gtk_socket_end_embedding (GtkSocket *socket)
383 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
384 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
386 if (GTK_IS_WINDOW (toplevel))
387 _gtk_socket_windowing_end_embedding_toplevel (socket);
389 g_object_unref (socket->plug_window);
390 socket->plug_window = NULL;
391 socket->current_width = 0;
392 socket->current_height = 0;
393 private->resize_count = 0;
395 gtk_accel_group_disconnect (socket->accel_group, NULL);
399 gtk_socket_unrealize (GtkWidget *widget)
401 GtkSocket *socket = GTK_SOCKET (widget);
403 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
405 if (socket->plug_widget)
407 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
409 else if (socket->plug_window)
411 _gtk_socket_end_embedding (socket);
414 GTK_WIDGET_CLASS (gtk_socket_parent_class)->unrealize (widget);
418 gtk_socket_size_request (GtkWidget *widget,
419 GtkRequisition *requisition)
421 GtkSocket *socket = GTK_SOCKET (widget);
423 if (socket->plug_widget)
425 gtk_widget_size_request (socket->plug_widget, requisition);
429 if (socket->is_mapped && !socket->have_size && socket->plug_window)
430 _gtk_socket_windowing_size_request (socket);
432 if (socket->is_mapped && socket->have_size)
434 requisition->width = MAX (socket->request_width, 1);
435 requisition->height = MAX (socket->request_height, 1);
439 requisition->width = 1;
440 requisition->height = 1;
446 gtk_socket_size_allocate (GtkWidget *widget,
447 GtkAllocation *allocation)
449 GtkSocket *socket = GTK_SOCKET (widget);
451 widget->allocation = *allocation;
452 if (GTK_WIDGET_REALIZED (widget))
454 gdk_window_move_resize (widget->window,
455 allocation->x, allocation->y,
456 allocation->width, allocation->height);
458 if (socket->plug_widget)
460 GtkAllocation child_allocation;
462 child_allocation.x = 0;
463 child_allocation.y = 0;
464 child_allocation.width = allocation->width;
465 child_allocation.height = allocation->height;
467 gtk_widget_size_allocate (socket->plug_widget, &child_allocation);
469 else if (socket->plug_window)
471 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
473 gdk_error_trap_push ();
475 if (allocation->width != socket->current_width ||
476 allocation->height != socket->current_height)
478 gdk_window_move_resize (socket->plug_window,
480 allocation->width, allocation->height);
481 if (private->resize_count)
482 private->resize_count--;
484 GTK_NOTE (PLUGSOCKET,
485 g_message ("GtkSocket - allocated: %d %d",
486 allocation->width, allocation->height));
487 socket->current_width = allocation->width;
488 socket->current_height = allocation->height;
491 if (socket->need_map)
493 gdk_window_show (socket->plug_window);
494 socket->need_map = FALSE;
497 while (private->resize_count)
499 _gtk_socket_windowing_send_configure_event (socket);
500 private->resize_count--;
501 GTK_NOTE (PLUGSOCKET,
502 g_message ("GtkSocket - sending synthetic configure: %d %d",
503 allocation->width, allocation->height));
506 gdk_display_sync (gtk_widget_get_display (widget));
507 gdk_error_trap_pop ();
513 activate_key (GtkAccelGroup *accel_group,
514 GObject *acceleratable,
516 GdkModifierType accel_mods,
517 GrabbedKey *grabbed_key)
519 GdkEvent *gdk_event = gtk_get_current_event ();
521 GtkSocket *socket = g_object_get_data (G_OBJECT (accel_group), "gtk-socket");
522 gboolean retval = FALSE;
524 if (gdk_event && gdk_event->type == GDK_KEY_PRESS && socket->plug_window)
526 _gtk_socket_windowing_send_key_event (socket, gdk_event, TRUE);
531 gdk_event_free (gdk_event);
537 find_accel_key (GtkAccelKey *key,
541 GrabbedKey *grabbed_key = data;
543 return (key->accel_key == grabbed_key->accel_key &&
544 key->accel_mods == grabbed_key->accel_mods);
548 * _gtk_socket_add_grabbed_key:
550 * @socket: a #GtkSocket
552 * @modifiers: modifiers for the key
554 * Called from the GtkSocket platform-specific backend when the
555 * corresponding plug has told the socket to grab a key.
558 _gtk_socket_add_grabbed_key (GtkSocket *socket,
560 GdkModifierType modifiers)
563 GrabbedKey *grabbed_key;
565 grabbed_key = g_new (GrabbedKey, 1);
567 grabbed_key->accel_key = keyval;
568 grabbed_key->accel_mods = modifiers;
570 if (gtk_accel_group_find (socket->accel_group,
574 g_warning ("GtkSocket: request to add already present grabbed key %u,%#x\n",
576 g_free (grabbed_key);
580 closure = g_cclosure_new (G_CALLBACK (activate_key), grabbed_key, (GClosureNotify)g_free);
582 gtk_accel_group_connect (socket->accel_group, keyval, modifiers, GTK_ACCEL_LOCKED,
587 * _gtk_socket_remove_grabbed_key:
589 * @socket: a #GtkSocket
591 * @modifiers: modifiers for the key
593 * Called from the GtkSocket backend when the corresponding plug has
594 * told the socket to remove a key grab.
597 _gtk_socket_remove_grabbed_key (GtkSocket *socket,
599 GdkModifierType modifiers)
601 if (!gtk_accel_group_disconnect_key (socket->accel_group, keyval, modifiers))
602 g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
607 socket_update_focus_in (GtkSocket *socket)
609 gboolean focus_in = FALSE;
611 if (socket->plug_window)
613 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
615 if (gtk_widget_is_toplevel (toplevel) &&
616 GTK_WINDOW (toplevel)->has_toplevel_focus &&
617 gtk_widget_is_focus (GTK_WIDGET (socket)))
621 if (focus_in != socket->focus_in)
623 socket->focus_in = focus_in;
625 _gtk_socket_windowing_focus_change (socket, focus_in);
630 socket_update_active (GtkSocket *socket)
632 gboolean active = FALSE;
634 if (socket->plug_window)
636 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
638 if (gtk_widget_is_toplevel (toplevel) &&
639 GTK_WINDOW (toplevel)->is_active)
643 if (active != socket->active)
645 socket->active = active;
647 _gtk_socket_windowing_update_active (socket, active);
652 gtk_socket_hierarchy_changed (GtkWidget *widget,
653 GtkWidget *old_toplevel)
655 GtkSocket *socket = GTK_SOCKET (widget);
656 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
658 if (toplevel && !GTK_IS_WINDOW (toplevel))
661 if (toplevel != socket->toplevel)
663 if (socket->toplevel)
665 gtk_window_remove_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
666 g_signal_handlers_disconnect_by_func (socket->toplevel,
667 socket_update_focus_in,
669 g_signal_handlers_disconnect_by_func (socket->toplevel,
670 socket_update_active,
674 socket->toplevel = toplevel;
678 gtk_window_add_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
679 g_signal_connect_swapped (socket->toplevel, "notify::has-toplevel-focus",
680 G_CALLBACK (socket_update_focus_in), socket);
681 g_signal_connect_swapped (socket->toplevel, "notify::is-active",
682 G_CALLBACK (socket_update_active), socket);
685 socket_update_focus_in (socket);
686 socket_update_active (socket);
691 gtk_socket_grab_notify (GtkWidget *widget,
692 gboolean was_grabbed)
694 GtkSocket *socket = GTK_SOCKET (widget);
696 if (!socket->same_app)
697 _gtk_socket_windowing_update_modality (socket, !was_grabbed);
701 gtk_socket_key_event (GtkWidget *widget,
704 GtkSocket *socket = GTK_SOCKET (widget);
706 if (GTK_WIDGET_HAS_FOCUS (socket) && socket->plug_window && !socket->plug_widget)
708 _gtk_socket_windowing_send_key_event (socket, (GdkEvent *) event, FALSE);
717 gtk_socket_notify (GObject *object,
720 if (!strcmp (pspec->name, "is-focus"))
722 socket_update_focus_in (GTK_SOCKET (object));
726 * _gtk_socket_claim_focus:
728 * @socket: a #GtkSocket
731 * Claims focus for the socket. XXX send_event?
734 _gtk_socket_claim_focus (GtkSocket *socket,
738 socket->focus_in = TRUE; /* Otherwise, our notify handler will send FOCUS_IN */
740 /* Oh, the trickery... */
742 GTK_WIDGET_SET_FLAGS (socket, GTK_CAN_FOCUS);
743 gtk_widget_grab_focus (GTK_WIDGET (socket));
744 GTK_WIDGET_UNSET_FLAGS (socket, GTK_CAN_FOCUS);
748 gtk_socket_focus (GtkWidget *widget,
749 GtkDirectionType direction)
751 GtkSocket *socket = GTK_SOCKET (widget);
753 if (socket->plug_widget)
754 return gtk_widget_child_focus (socket->plug_widget, direction);
756 if (!gtk_widget_is_focus (widget))
758 _gtk_socket_windowing_focus (socket, direction);
759 _gtk_socket_claim_focus (socket, FALSE);
768 gtk_socket_remove (GtkContainer *container,
771 GtkSocket *socket = GTK_SOCKET (container);
773 g_return_if_fail (child == socket->plug_widget);
775 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
779 gtk_socket_forall (GtkContainer *container,
780 gboolean include_internals,
781 GtkCallback callback,
782 gpointer callback_data)
784 GtkSocket *socket = GTK_SOCKET (container);
786 if (socket->plug_widget)
787 (* callback) (socket->plug_widget, callback_data);
791 * _gtk_socket_add_window:
793 * @socket: a #GtkSocket
794 * @xid: the native identifier for a window
795 * @need_reparent: whether the socket's plug's window needs to be
796 * reparented to the socket
798 * Adds a window to a GtkSocket.
801 _gtk_socket_add_window (GtkSocket *socket,
803 gboolean need_reparent)
805 GtkWidget *widget = GTK_WIDGET (socket);
806 GdkDisplay *display = gtk_widget_get_display (widget);
807 gpointer user_data = NULL;
809 socket->plug_window = gdk_window_lookup_for_display (display, xid);
811 if (socket->plug_window)
813 g_object_ref (socket->plug_window);
814 gdk_window_get_user_data (socket->plug_window, &user_data);
817 if (user_data) /* A widget's window in this process */
819 GtkWidget *child_widget = user_data;
821 if (!GTK_IS_PLUG (child_widget))
823 g_warning (G_STRLOC ": Can't add non-GtkPlug to GtkSocket");
824 socket->plug_window = NULL;
825 gdk_error_trap_pop ();
830 _gtk_plug_add_to_socket (GTK_PLUG (child_widget), socket);
832 else /* A foreign window */
835 GdkDragProtocol protocol;
837 gdk_error_trap_push ();
839 if (!socket->plug_window)
841 socket->plug_window = gdk_window_foreign_new_for_display (display, xid);
842 if (!socket->plug_window) /* was deleted before we could get it */
844 gdk_error_trap_pop ();
849 _gtk_socket_windowing_select_plug_window_input (socket);
851 if (gdk_error_trap_pop ())
853 g_object_unref (socket->plug_window);
854 socket->plug_window = NULL;
858 /* OK, we now will reliably get destroy notification on socket->plug_window */
860 gdk_error_trap_push ();
864 gdk_window_hide (socket->plug_window); /* Shouldn't actually be necessary for XEMBED, but just in case */
865 gdk_window_reparent (socket->plug_window, widget->window, 0, 0);
868 socket->have_size = FALSE;
870 _gtk_socket_windowing_embed_get_info (socket);
872 socket->need_map = socket->is_mapped;
874 if (gdk_drag_get_protocol_for_display (display, xid, &protocol))
875 gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
878 gdk_display_sync (display);
879 gdk_error_trap_pop ();
881 gdk_window_add_filter (socket->plug_window,
882 _gtk_socket_windowing_filter_func,
885 /* Add a pointer to the socket on our toplevel window */
887 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
888 if (GTK_IS_WINDOW (toplevel))
889 gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
891 _gtk_socket_windowing_embed_notify (socket);
893 socket_update_active (socket);
894 socket_update_focus_in (socket);
896 gtk_widget_queue_resize (GTK_WIDGET (socket));
899 if (socket->plug_window)
900 g_signal_emit (socket, socket_signals[PLUG_ADDED], 0);
904 * _gtk_socket_handle_map_request:
906 * @socket: a #GtkSocket
908 * Called from the GtkSocket backend when the plug has been mapped.
911 _gtk_socket_handle_map_request (GtkSocket *socket)
913 if (!socket->is_mapped)
915 socket->is_mapped = TRUE;
916 socket->need_map = TRUE;
918 gtk_widget_queue_resize (GTK_WIDGET (socket));
923 * _gtk_socket_unmap_notify:
925 * @socket: a #GtkSocket
927 * Called from the GtkSocket backend when the plug has been unmapped ???
930 _gtk_socket_unmap_notify (GtkSocket *socket)
932 if (socket->is_mapped)
934 socket->is_mapped = FALSE;
935 gtk_widget_queue_resize (GTK_WIDGET (socket));
940 * _gtk_socket_advance_toplevel_focus:
942 * @socket: a #GtkSocket
943 * @direction: a direction
945 * Called from the GtkSocket backend when the corresponding plug
946 * has told the socket to move the focus.
949 _gtk_socket_advance_toplevel_focus (GtkSocket *socket,
950 GtkDirectionType direction)
954 GtkContainer *container;
956 GtkWidget *old_focus_child;
959 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
963 if (!gtk_widget_is_toplevel (toplevel) || GTK_IS_PLUG (toplevel))
965 gtk_widget_child_focus (toplevel,direction);
969 container = GTK_CONTAINER (toplevel);
970 window = GTK_WINDOW (toplevel);
971 bin = GTK_BIN (toplevel);
973 /* This is a copy of gtk_window_focus(), modified so that we
974 * can detect wrap-around.
976 old_focus_child = container->focus_child;
980 if (gtk_widget_child_focus (old_focus_child, direction))
983 /* We are allowed exactly one wrap-around per sequence of focus
986 if (_gtk_socket_windowing_embed_get_focus_wrapped ())
989 _gtk_socket_windowing_embed_set_focus_wrapped ();
992 if (window->focus_widget)
994 /* Wrapped off the end, clear the focus setting for the toplevel */
995 parent = window->focus_widget->parent;
998 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
999 parent = GTK_WIDGET (parent)->parent;
1002 gtk_window_set_focus (GTK_WINDOW (container), NULL);
1005 /* Now try to focus the first widget in the window */
1008 if (gtk_widget_child_focus (bin->child, direction))
1014 gtk_socket_extended_layout_get_desired_size (GtkExtendedLayout *layout,
1015 GtkRequisition *minimal_size,
1016 GtkRequisition *desired_size)
1018 GtkSocket *socket = GTK_SOCKET (layout);
1019 GtkSocketPrivate *priv;
1021 if (socket->plug_widget)
1023 gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (socket->plug_widget),
1029 priv = _gtk_socket_get_private (socket);
1031 if (socket->is_mapped && !priv->have_natural_size && socket->plug_window)
1033 _gtk_socket_windowing_size_request (socket);
1034 _gtk_socket_windowing_get_natural_size (socket);
1037 if (socket->is_mapped && priv->have_natural_size)
1041 minimal_size->width = MAX (socket->request_width, 1);
1042 minimal_size->height = MAX (socket->request_height, 1);
1046 desired_size->width = MAX (priv->natural_width, 1);
1047 desired_size->height = MAX (priv->natural_height, 1);
1054 minimal_size->width = 1;
1055 minimal_size->height = 1;
1059 desired_size->width = 1;
1060 desired_size->height = 1;
1067 gtk_socket_extended_layout_interface_init (GtkExtendedLayoutIface *iface)
1069 iface->get_desired_size = gtk_socket_extended_layout_get_desired_size;
1073 #define __GTK_SOCKET_C__
1074 #include "gtkaliasdef.c"