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 "gtkmarshalers.h"
34 #include "gtkprivate.h"
35 #include "gtkplugprivate.h"
39 * @Short_description: Toplevel for embedding into other processes
41 * @See_also: #GtkSocket
43 * Together with #GtkSocket, #GtkPlug provides the ability
44 * to embed widgets from one process into another process
45 * in a fashion that is transparent to the user. One
46 * process creates a #GtkSocket widget and passes the
47 * ID of that widget's window to the other process,
48 * which then creates a #GtkPlug with that window ID.
49 * Any widgets contained in the #GtkPlug then will appear
50 * inside the first application's window.
53 * The #GtkPlug and #GtkSocket widgets are currently not available
54 * on all platforms supported by GTK+.
58 static void gtk_plug_get_property (GObject *object,
62 static void gtk_plug_finalize (GObject *object);
63 static void gtk_plug_realize (GtkWidget *widget);
64 static void gtk_plug_unrealize (GtkWidget *widget);
65 static void gtk_plug_show (GtkWidget *widget);
66 static void gtk_plug_hide (GtkWidget *widget);
67 static void gtk_plug_map (GtkWidget *widget);
68 static void gtk_plug_unmap (GtkWidget *widget);
69 static void gtk_plug_size_allocate (GtkWidget *widget,
70 GtkAllocation *allocation);
71 static gboolean gtk_plug_key_press_event (GtkWidget *widget,
73 static gboolean gtk_plug_focus_event (GtkWidget *widget,
74 GdkEventFocus *event);
75 static void gtk_plug_set_focus (GtkWindow *window,
77 static gboolean gtk_plug_focus (GtkWidget *widget,
78 GtkDirectionType direction);
79 static void gtk_plug_check_resize (GtkContainer *container);
80 static void gtk_plug_keys_changed (GtkWindow *window);
82 static GtkBinClass *bin_class = NULL;
86 guint accelerator_key;
87 GdkModifierType accelerator_mods;
101 static guint plug_signals[LAST_SIGNAL] = { 0 };
103 G_DEFINE_TYPE (GtkPlug, gtk_plug, GTK_TYPE_WINDOW)
106 gtk_plug_get_property (GObject *object,
111 GtkPlug *plug = GTK_PLUG (object);
116 g_value_set_boolean (value, plug->socket_window != NULL);
118 case PROP_SOCKET_WINDOW:
119 g_value_set_object (value, plug->socket_window);
122 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
128 gtk_plug_class_init (GtkPlugClass *class)
130 GObjectClass *gobject_class = (GObjectClass *)class;
131 GtkWidgetClass *widget_class = (GtkWidgetClass *)class;
132 GtkWindowClass *window_class = (GtkWindowClass *)class;
133 GtkContainerClass *container_class = (GtkContainerClass *)class;
135 bin_class = g_type_class_peek (GTK_TYPE_BIN);
137 gobject_class->get_property = gtk_plug_get_property;
138 gobject_class->finalize = gtk_plug_finalize;
140 widget_class->realize = gtk_plug_realize;
141 widget_class->unrealize = gtk_plug_unrealize;
142 widget_class->key_press_event = gtk_plug_key_press_event;
143 widget_class->focus_in_event = gtk_plug_focus_event;
144 widget_class->focus_out_event = gtk_plug_focus_event;
146 widget_class->show = gtk_plug_show;
147 widget_class->hide = gtk_plug_hide;
148 widget_class->map = gtk_plug_map;
149 widget_class->unmap = gtk_plug_unmap;
150 widget_class->size_allocate = gtk_plug_size_allocate;
152 widget_class->focus = gtk_plug_focus;
154 container_class->check_resize = gtk_plug_check_resize;
156 window_class->set_focus = gtk_plug_set_focus;
157 window_class->keys_changed = gtk_plug_keys_changed;
162 * %TRUE if the plug is embedded in a socket.
166 g_object_class_install_property (gobject_class,
168 g_param_spec_boolean ("embedded",
170 P_("Whether or not the plug is embedded"),
172 GTK_PARAM_READABLE));
175 * GtkPlug:socket-window:
177 * The window of the socket the plug is embedded in.
181 g_object_class_install_property (gobject_class,
183 g_param_spec_object ("socket-window",
185 P_("The window of the socket the plug is embedded in"),
187 GTK_PARAM_READABLE));
191 * @plug: the object on which the signal was emitted
193 * Gets emitted when the plug becomes embedded in a socket.
195 plug_signals[EMBEDDED] =
196 g_signal_new (I_("embedded"),
197 G_OBJECT_CLASS_TYPE (class),
199 G_STRUCT_OFFSET (GtkPlugClass, embedded),
201 _gtk_marshal_VOID__VOID,
206 gtk_plug_init (GtkPlug *plug)
210 window = GTK_WINDOW (plug);
212 window->type = GTK_WINDOW_TOPLEVEL;
216 gtk_plug_set_is_child (GtkPlug *plug,
219 g_assert (!GTK_WIDGET (plug)->parent);
223 if (plug->modality_window)
224 _gtk_plug_handle_modality_off (plug);
226 if (plug->modality_group)
228 gtk_window_group_remove_window (plug->modality_group, GTK_WINDOW (plug));
229 g_object_unref (plug->modality_group);
230 plug->modality_group = NULL;
233 /* As a toplevel, the MAPPED flag doesn't correspond
234 * to whether the widget->window is mapped; we unmap
235 * here, but don't bother remapping -- we will get mapped
236 * by gtk_widget_set_parent ().
238 if (gtk_widget_get_mapped (GTK_WIDGET (plug)))
239 gtk_widget_unmap (GTK_WIDGET (plug));
241 _gtk_window_set_is_toplevel (GTK_WINDOW (plug), FALSE);
242 gtk_container_set_resize_mode (GTK_CONTAINER (plug), GTK_RESIZE_PARENT);
244 _gtk_widget_propagate_hierarchy_changed (GTK_WIDGET (plug), GTK_WIDGET (plug));
248 if (GTK_WINDOW (plug)->focus_widget)
249 gtk_window_set_focus (GTK_WINDOW (plug), NULL);
250 if (GTK_WINDOW (plug)->default_widget)
251 gtk_window_set_default (GTK_WINDOW (plug), NULL);
253 plug->modality_group = gtk_window_group_new ();
254 gtk_window_group_add_window (plug->modality_group, GTK_WINDOW (plug));
256 _gtk_window_set_is_toplevel (GTK_WINDOW (plug), TRUE);
257 gtk_container_set_resize_mode (GTK_CONTAINER (plug), GTK_RESIZE_QUEUE);
259 _gtk_widget_propagate_hierarchy_changed (GTK_WIDGET (plug), NULL);
267 * Gets the window ID of a #GtkPlug widget, which can then
268 * be used to embed this window inside another window, for
269 * instance with gtk_socket_add_id().
271 * Return value: the window ID for the plug
274 gtk_plug_get_id (GtkPlug *plug)
276 g_return_val_if_fail (GTK_IS_PLUG (plug), 0);
278 if (!gtk_widget_get_realized (GTK_WIDGET (plug)))
279 gtk_widget_realize (GTK_WIDGET (plug));
281 return _gtk_plug_windowing_get_id (plug);
285 * gtk_plug_get_embedded:
288 * Determines whether the plug is embedded in a socket.
290 * Return value: %TRUE if the plug is embedded in a socket
295 gtk_plug_get_embedded (GtkPlug *plug)
297 g_return_val_if_fail (GTK_IS_PLUG (plug), FALSE);
299 return plug->socket_window != NULL;
303 * gtk_plug_get_socket_window:
306 * Retrieves the socket the plug is embedded in.
308 * Return value: the window of the socket, or %NULL
313 gtk_plug_get_socket_window (GtkPlug *plug)
315 g_return_val_if_fail (GTK_IS_PLUG (plug), NULL);
317 return plug->socket_window;
321 * _gtk_plug_add_to_socket:
323 * @socket_: a #GtkSocket
325 * Adds a plug to a socket within the same application.
328 _gtk_plug_add_to_socket (GtkPlug *plug,
334 g_return_if_fail (GTK_IS_PLUG (plug));
335 g_return_if_fail (GTK_IS_SOCKET (socket_));
336 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (socket_)));
338 widget = GTK_WIDGET (plug);
340 gtk_plug_set_is_child (plug, TRUE);
341 plug->same_app = TRUE;
342 socket_->same_app = TRUE;
343 socket_->plug_widget = widget;
345 plug->socket_window = GTK_WIDGET (socket_)->window;
346 g_object_ref (plug->socket_window);
347 g_signal_emit (plug, plug_signals[EMBEDDED], 0);
348 g_object_notify (G_OBJECT (plug), "embedded");
350 if (gtk_widget_get_realized (widget))
352 gdk_drawable_get_size (GDK_DRAWABLE (widget->window), &w, &h);
353 gdk_window_reparent (widget->window, plug->socket_window, -w, -h);
356 gtk_widget_set_parent (widget, GTK_WIDGET (socket_));
358 g_signal_emit_by_name (socket_, "plug-added");
362 * _gtk_plug_send_delete_event:
363 * @widget: a #GtkWidget
365 * Send a GDK_DELETE event to the @widget and destroy it if
366 * necessary. Internal GTK function, called from this file or the
367 * backend-specific GtkPlug implementation.
370 _gtk_plug_send_delete_event (GtkWidget *widget)
372 GdkEvent *event = gdk_event_new (GDK_DELETE);
374 event->any.window = g_object_ref (widget->window);
375 event->any.send_event = FALSE;
377 g_object_ref (widget);
379 if (!gtk_widget_event (widget, event))
380 gtk_widget_destroy (widget);
382 g_object_unref (widget);
384 gdk_event_free (event);
388 * _gtk_plug_remove_from_socket:
390 * @socket_: a #GtkSocket
392 * Removes a plug from a socket within the same application.
395 _gtk_plug_remove_from_socket (GtkPlug *plug,
400 gboolean widget_was_visible;
402 g_return_if_fail (GTK_IS_PLUG (plug));
403 g_return_if_fail (GTK_IS_SOCKET (socket_));
404 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (plug)));
406 widget = GTK_WIDGET (plug);
408 if (GTK_WIDGET_IN_REPARENT (widget))
412 g_object_ref (socket_);
414 widget_was_visible = gtk_widget_get_visible (widget);
416 gdk_window_hide (widget->window);
417 GTK_PRIVATE_SET_FLAG (plug, GTK_IN_REPARENT);
418 gdk_window_reparent (widget->window,
419 gtk_widget_get_root_window (widget),
421 gtk_widget_unparent (GTK_WIDGET (plug));
422 GTK_PRIVATE_UNSET_FLAG (plug, GTK_IN_REPARENT);
424 socket_->plug_widget = NULL;
425 if (socket_->plug_window != NULL)
427 g_object_unref (socket_->plug_window);
428 socket_->plug_window = NULL;
431 socket_->same_app = FALSE;
433 plug->same_app = FALSE;
434 if (plug->socket_window != NULL)
436 g_object_unref (plug->socket_window);
437 plug->socket_window = NULL;
439 gtk_plug_set_is_child (plug, FALSE);
441 g_signal_emit_by_name (socket_, "plug-removed", &result);
443 gtk_widget_destroy (GTK_WIDGET (socket_));
446 _gtk_plug_send_delete_event (widget);
448 g_object_unref (plug);
450 if (widget_was_visible && gtk_widget_get_visible (GTK_WIDGET (socket_)))
451 gtk_widget_queue_resize (GTK_WIDGET (socket_));
453 g_object_unref (socket_);
457 * gtk_plug_construct:
459 * @socket_id: the XID of the socket's window.
461 * Finish the initialization of @plug for a given #GtkSocket identified by
462 * @socket_id. This function will generally only be used by classes deriving from #GtkPlug.
465 gtk_plug_construct (GtkPlug *plug,
466 GdkNativeWindow socket_id)
468 gtk_plug_construct_for_display (plug, gdk_display_get_default (), socket_id);
472 * gtk_plug_construct_for_display:
474 * @display: the #GdkDisplay associated with @socket_id's
476 * @socket_id: the XID of the socket's window.
478 * Finish the initialization of @plug for a given #GtkSocket identified by
479 * @socket_id which is currently displayed on @display.
480 * This function will generally only be used by classes deriving from #GtkPlug.
485 gtk_plug_construct_for_display (GtkPlug *plug,
487 GdkNativeWindow socket_id)
491 gpointer user_data = NULL;
493 plug->socket_window = gdk_window_lookup_for_display (display, socket_id);
494 if (plug->socket_window)
496 gdk_window_get_user_data (plug->socket_window, &user_data);
500 if (GTK_IS_SOCKET (user_data))
501 _gtk_plug_add_to_socket (plug, user_data);
504 g_warning (G_STRLOC "Can't create GtkPlug as child of non-GtkSocket");
505 plug->socket_window = NULL;
509 g_object_ref (plug->socket_window);
512 plug->socket_window = gdk_window_foreign_new_for_display (display, socket_id);
514 if (plug->socket_window) {
515 g_signal_emit (plug, plug_signals[EMBEDDED], 0);
517 g_object_notify (G_OBJECT (plug), "embedded");
524 * @socket_id: the window ID of the socket, or 0.
526 * Creates a new plug widget inside the #GtkSocket identified
527 * by @socket_id. If @socket_id is 0, the plug is left "unplugged" and
528 * can later be plugged into a #GtkSocket by gtk_socket_add_id().
530 * Return value: the new #GtkPlug widget.
533 gtk_plug_new (GdkNativeWindow socket_id)
535 return gtk_plug_new_for_display (gdk_display_get_default (), socket_id);
539 * gtk_plug_new_for_display:
540 * @display : the #GdkDisplay on which @socket_id is displayed
541 * @socket_id: the XID of the socket's window.
543 * Create a new plug widget inside the #GtkSocket identified by socket_id.
545 * Return value: the new #GtkPlug widget.
550 gtk_plug_new_for_display (GdkDisplay *display,
551 GdkNativeWindow socket_id)
555 plug = g_object_new (GTK_TYPE_PLUG, NULL);
556 gtk_plug_construct_for_display (plug, display, socket_id);
557 return GTK_WIDGET (plug);
561 gtk_plug_finalize (GObject *object)
563 GtkPlug *plug = GTK_PLUG (object);
565 if (plug->grabbed_keys)
567 g_hash_table_destroy (plug->grabbed_keys);
568 plug->grabbed_keys = NULL;
571 G_OBJECT_CLASS (gtk_plug_parent_class)->finalize (object);
575 gtk_plug_unrealize (GtkWidget *widget)
577 GtkPlug *plug = GTK_PLUG (widget);
579 if (plug->socket_window != NULL)
581 gdk_window_set_user_data (plug->socket_window, NULL);
582 g_object_unref (plug->socket_window);
583 plug->socket_window = NULL;
585 g_object_notify (G_OBJECT (widget), "embedded");
590 if (plug->modality_window)
591 _gtk_plug_handle_modality_off (plug);
593 gtk_window_group_remove_window (plug->modality_group, GTK_WINDOW (plug));
594 g_object_unref (plug->modality_group);
597 GTK_WIDGET_CLASS (gtk_plug_parent_class)->unrealize (widget);
601 gtk_plug_realize (GtkWidget *widget)
603 GtkWindow *window = GTK_WINDOW (widget);
604 GtkPlug *plug = GTK_PLUG (widget);
605 GdkWindowAttr attributes;
606 gint attributes_mask;
608 gtk_widget_set_realized (widget, TRUE);
610 attributes.window_type = GDK_WINDOW_CHILD; /* XXX GDK_WINDOW_PLUG ? */
611 attributes.title = window->title;
612 attributes.wmclass_name = window->wmclass_name;
613 attributes.wmclass_class = window->wmclass_class;
614 attributes.width = widget->allocation.width;
615 attributes.height = widget->allocation.height;
616 attributes.wclass = GDK_INPUT_OUTPUT;
618 /* this isn't right - we should match our parent's visual/colormap.
619 * though that will require handling "foreign" colormaps */
620 attributes.visual = gtk_widget_get_visual (widget);
621 attributes.colormap = gtk_widget_get_colormap (widget);
622 attributes.event_mask = gtk_widget_get_events (widget);
623 attributes.event_mask |= (GDK_EXPOSURE_MASK |
625 GDK_KEY_RELEASE_MASK |
626 GDK_ENTER_NOTIFY_MASK |
627 GDK_LEAVE_NOTIFY_MASK |
630 attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
631 attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
632 attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
634 if (gtk_widget_is_toplevel (widget))
636 attributes.window_type = GDK_WINDOW_TOPLEVEL;
638 gdk_error_trap_push ();
639 if (plug->socket_window)
640 widget->window = gdk_window_new (plug->socket_window,
641 &attributes, attributes_mask);
642 else /* If it's a passive plug, we use the root window */
643 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
644 &attributes, attributes_mask);
646 gdk_display_sync (gtk_widget_get_display (widget));
647 if (gdk_error_trap_pop ()) /* Uh-oh */
649 gdk_error_trap_push ();
650 gdk_window_destroy (widget->window);
652 gdk_error_trap_pop ();
653 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
654 &attributes, attributes_mask);
657 gdk_window_add_filter (widget->window,
658 _gtk_plug_windowing_filter_func,
661 plug->modality_group = gtk_window_group_new ();
662 gtk_window_group_add_window (plug->modality_group, window);
664 _gtk_plug_windowing_realize_toplevel (plug);
667 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
668 &attributes, attributes_mask);
670 gdk_window_set_user_data (widget->window, window);
672 widget->style = gtk_style_attach (widget->style, widget->window);
673 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
675 gdk_window_enable_synchronized_configure (widget->window);
679 gtk_plug_show (GtkWidget *widget)
681 if (gtk_widget_is_toplevel (widget))
682 GTK_WIDGET_CLASS (gtk_plug_parent_class)->show (widget);
684 GTK_WIDGET_CLASS (bin_class)->show (widget);
688 gtk_plug_hide (GtkWidget *widget)
690 if (gtk_widget_is_toplevel (widget))
691 GTK_WIDGET_CLASS (gtk_plug_parent_class)->hide (widget);
693 GTK_WIDGET_CLASS (bin_class)->hide (widget);
696 /* From gdkinternals.h */
697 void gdk_synthesize_window_state (GdkWindow *window,
698 GdkWindowState unset_flags,
699 GdkWindowState set_flags);
702 gtk_plug_map (GtkWidget *widget)
704 if (gtk_widget_is_toplevel (widget))
706 GtkBin *bin = GTK_BIN (widget);
707 GtkPlug *plug = GTK_PLUG (widget);
710 gtk_widget_set_mapped (widget, TRUE);
712 child = gtk_bin_get_child (bin);
714 gtk_widget_get_visible (child) &&
715 !gtk_widget_get_mapped (child))
716 gtk_widget_map (child);
718 _gtk_plug_windowing_map_toplevel (plug);
720 gdk_synthesize_window_state (widget->window,
721 GDK_WINDOW_STATE_WITHDRAWN,
725 GTK_WIDGET_CLASS (bin_class)->map (widget);
729 gtk_plug_unmap (GtkWidget *widget)
731 if (gtk_widget_is_toplevel (widget))
733 GtkPlug *plug = GTK_PLUG (widget);
735 gtk_widget_set_mapped (widget, FALSE);
737 gdk_window_hide (widget->window);
739 _gtk_plug_windowing_unmap_toplevel (plug);
741 gdk_synthesize_window_state (widget->window,
743 GDK_WINDOW_STATE_WITHDRAWN);
746 GTK_WIDGET_CLASS (bin_class)->unmap (widget);
750 gtk_plug_size_allocate (GtkWidget *widget,
751 GtkAllocation *allocation)
755 if (gtk_widget_is_toplevel (widget))
756 GTK_WIDGET_CLASS (gtk_plug_parent_class)->size_allocate (widget, allocation);
759 GtkBin *bin = GTK_BIN (widget);
761 widget->allocation = *allocation;
763 if (gtk_widget_get_realized (widget))
764 gdk_window_move_resize (widget->window,
765 allocation->x, allocation->y,
766 allocation->width, allocation->height);
768 child = gtk_bin_get_child (bin);
770 if (child != NULL && gtk_widget_get_visible (child))
772 GtkAllocation child_allocation;
774 child_allocation.x = child_allocation.y = gtk_container_get_border_width (GTK_CONTAINER (widget));
775 child_allocation.width =
776 MAX (1, (gint)allocation->width - child_allocation.x * 2);
777 child_allocation.height =
778 MAX (1, (gint)allocation->height - child_allocation.y * 2);
780 gtk_widget_size_allocate (child, &child_allocation);
787 gtk_plug_key_press_event (GtkWidget *widget,
790 if (gtk_widget_is_toplevel (widget))
791 return GTK_WIDGET_CLASS (gtk_plug_parent_class)->key_press_event (widget, event);
797 gtk_plug_focus_event (GtkWidget *widget,
798 GdkEventFocus *event)
800 /* We eat focus-in events and focus-out events, since they
801 * can be generated by something like a keyboard grab on
802 * a child of the plug.
808 gtk_plug_set_focus (GtkWindow *window,
811 GtkPlug *plug = GTK_PLUG (window);
813 GTK_WINDOW_CLASS (gtk_plug_parent_class)->set_focus (window, focus);
815 /* Ask for focus from embedder
818 if (focus && !window->has_toplevel_focus)
819 _gtk_plug_windowing_set_focus (plug);
823 grabbed_key_hash (gconstpointer a)
825 const GrabbedKey *key = a;
828 h = key->accelerator_key << 16;
829 h ^= key->accelerator_key >> 16;
830 h ^= key->accelerator_mods;
836 grabbed_key_equal (gconstpointer a, gconstpointer b)
838 const GrabbedKey *keya = a;
839 const GrabbedKey *keyb = b;
841 return (keya->accelerator_key == keyb->accelerator_key &&
842 keya->accelerator_mods == keyb->accelerator_mods);
846 add_grabbed_key (gpointer key, gpointer val, gpointer data)
848 GrabbedKey *grabbed_key = key;
849 GtkPlug *plug = data;
851 if (!plug->grabbed_keys ||
852 !g_hash_table_lookup (plug->grabbed_keys, grabbed_key))
854 _gtk_plug_windowing_add_grabbed_key (plug,
855 grabbed_key->accelerator_key,
856 grabbed_key->accelerator_mods);
861 add_grabbed_key_always (gpointer key,
865 GrabbedKey *grabbed_key = key;
866 GtkPlug *plug = data;
868 _gtk_plug_windowing_add_grabbed_key (plug,
869 grabbed_key->accelerator_key,
870 grabbed_key->accelerator_mods);
874 * _gtk_plug_add_all_grabbed_keys:
878 * Calls _gtk_plug_windowing_add_grabbed_key() on all the grabbed keys
882 _gtk_plug_add_all_grabbed_keys (GtkPlug *plug)
884 if (plug->grabbed_keys)
885 g_hash_table_foreach (plug->grabbed_keys, add_grabbed_key_always, plug);
889 remove_grabbed_key (gpointer key, gpointer val, gpointer data)
891 GrabbedKey *grabbed_key = key;
892 GtkPlug *plug = data;
894 if (!plug->grabbed_keys ||
895 !g_hash_table_lookup (plug->grabbed_keys, grabbed_key))
897 _gtk_plug_windowing_remove_grabbed_key (plug,
898 grabbed_key->accelerator_key,
899 grabbed_key->accelerator_mods);
904 keys_foreach (GtkWindow *window,
906 GdkModifierType modifiers,
907 gboolean is_mnemonic,
910 GHashTable *new_grabbed_keys = data;
911 GrabbedKey *key = g_slice_new (GrabbedKey);
913 key->accelerator_key = keyval;
914 key->accelerator_mods = modifiers;
916 g_hash_table_replace (new_grabbed_keys, key, key);
920 grabbed_key_free (gpointer data)
922 g_slice_free (GrabbedKey, data);
926 gtk_plug_keys_changed (GtkWindow *window)
928 GHashTable *new_grabbed_keys, *old_grabbed_keys;
929 GtkPlug *plug = GTK_PLUG (window);
931 new_grabbed_keys = g_hash_table_new_full (grabbed_key_hash, grabbed_key_equal, (GDestroyNotify)grabbed_key_free, NULL);
932 _gtk_window_keys_foreach (window, keys_foreach, new_grabbed_keys);
934 if (plug->socket_window)
935 g_hash_table_foreach (new_grabbed_keys, add_grabbed_key, plug);
937 old_grabbed_keys = plug->grabbed_keys;
938 plug->grabbed_keys = new_grabbed_keys;
940 if (old_grabbed_keys)
942 if (plug->socket_window)
943 g_hash_table_foreach (old_grabbed_keys, remove_grabbed_key, plug);
944 g_hash_table_destroy (old_grabbed_keys);
949 gtk_plug_focus (GtkWidget *widget,
950 GtkDirectionType direction)
952 GtkBin *bin = GTK_BIN (widget);
953 GtkPlug *plug = GTK_PLUG (widget);
954 GtkWindow *window = GTK_WINDOW (widget);
955 GtkContainer *container = GTK_CONTAINER (widget);
957 GtkWidget *old_focus_child;
960 old_focus_child = gtk_container_get_focus_child (container);
961 /* We override GtkWindow's behavior, since we don't want wrapping here.
965 if (gtk_widget_child_focus (old_focus_child, direction))
968 if (window->focus_widget)
970 /* Wrapped off the end, clear the focus setting for the toplevel */
971 parent = window->focus_widget->parent;
974 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
975 parent = GTK_WIDGET (parent)->parent;
978 gtk_window_set_focus (GTK_WINDOW (container), NULL);
983 /* Try to focus the first widget in the window */
984 child = gtk_bin_get_child (bin);
985 if (child && gtk_widget_child_focus (child, direction))
989 if (!gtk_container_get_focus_child (GTK_CONTAINER (window)))
990 _gtk_plug_windowing_focus_to_parent (plug, direction);
996 gtk_plug_check_resize (GtkContainer *container)
998 if (gtk_widget_is_toplevel (GTK_WIDGET (container)))
999 GTK_CONTAINER_CLASS (gtk_plug_parent_class)->check_resize (container);
1001 GTK_CONTAINER_CLASS (bin_class)->check_resize (container);
1005 * _gtk_plug_handle_modality_on:
1009 * Called from the GtkPlug backend when the corresponding socket has
1010 * told the plug that it modality has toggled on.
1013 _gtk_plug_handle_modality_on (GtkPlug *plug)
1015 if (!plug->modality_window)
1017 plug->modality_window = gtk_window_new (GTK_WINDOW_POPUP);
1018 gtk_window_set_screen (GTK_WINDOW (plug->modality_window),
1019 gtk_widget_get_screen (GTK_WIDGET (plug)));
1020 gtk_widget_realize (plug->modality_window);
1021 gtk_window_group_add_window (plug->modality_group, GTK_WINDOW (plug->modality_window));
1022 gtk_grab_add (plug->modality_window);
1027 * _gtk_plug_handle_modality_off:
1031 * Called from the GtkPlug backend when the corresponding socket has
1032 * told the plug that it modality has toggled off.
1035 _gtk_plug_handle_modality_off (GtkPlug *plug)
1037 if (plug->modality_window)
1039 gtk_widget_destroy (plug->modality_window);
1040 plug->modality_window = NULL;
1045 * _gtk_plug_focus_first_last:
1048 * @direction: a direction
1050 * Called from the GtkPlug backend when the corresponding socket has
1051 * told the plug that it has received the focus.
1054 _gtk_plug_focus_first_last (GtkPlug *plug,
1055 GtkDirectionType direction)
1057 GtkWindow *window = GTK_WINDOW (plug);
1060 if (window->focus_widget)
1062 parent = window->focus_widget->parent;
1065 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
1066 parent = GTK_WIDGET (parent)->parent;
1069 gtk_window_set_focus (GTK_WINDOW (plug), NULL);
1072 gtk_widget_child_focus (GTK_WIDGET (plug), direction);