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"
41 * @Short_description: Toplevel for embedding into other processes
43 * @See_also: #GtkSocket
45 * Together with #GtkSocket, #GtkPlug provides the ability
46 * to embed widgets from one process into another process
47 * in a fashion that is transparent to the user. One
48 * process creates a #GtkSocket widget and passes the
49 * ID of that widget's window to the other process,
50 * which then creates a #GtkPlug with that window ID.
51 * Any widgets contained in the #GtkPlug then will appear
52 * inside the first application's window.
55 * The #GtkPlug and #GtkSocket widgets are currently not available
56 * on all platforms supported by GTK+.
60 static void gtk_plug_get_property (GObject *object,
64 static void gtk_plug_finalize (GObject *object);
65 static void gtk_plug_realize (GtkWidget *widget);
66 static void gtk_plug_unrealize (GtkWidget *widget);
67 static void gtk_plug_show (GtkWidget *widget);
68 static void gtk_plug_hide (GtkWidget *widget);
69 static void gtk_plug_map (GtkWidget *widget);
70 static void gtk_plug_unmap (GtkWidget *widget);
71 static void gtk_plug_size_allocate (GtkWidget *widget,
72 GtkAllocation *allocation);
73 static gboolean gtk_plug_key_press_event (GtkWidget *widget,
75 static gboolean gtk_plug_focus_event (GtkWidget *widget,
76 GdkEventFocus *event);
77 static void gtk_plug_set_focus (GtkWindow *window,
79 static gboolean gtk_plug_focus (GtkWidget *widget,
80 GtkDirectionType direction);
81 static void gtk_plug_check_resize (GtkContainer *container);
82 static void gtk_plug_keys_changed (GtkWindow *window);
84 static GtkBinClass *bin_class = NULL;
88 guint accelerator_key;
89 GdkModifierType accelerator_mods;
103 static guint plug_signals[LAST_SIGNAL] = { 0 };
105 G_DEFINE_TYPE (GtkPlug, gtk_plug, GTK_TYPE_WINDOW)
108 gtk_plug_get_property (GObject *object,
113 GtkPlug *plug = GTK_PLUG (object);
118 g_value_set_boolean (value, plug->socket_window != NULL);
120 case PROP_SOCKET_WINDOW:
121 g_value_set_object (value, plug->socket_window);
124 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
130 gtk_plug_class_init (GtkPlugClass *class)
132 GObjectClass *gobject_class = (GObjectClass *)class;
133 GtkWidgetClass *widget_class = (GtkWidgetClass *)class;
134 GtkWindowClass *window_class = (GtkWindowClass *)class;
135 GtkContainerClass *container_class = (GtkContainerClass *)class;
137 bin_class = g_type_class_peek (GTK_TYPE_BIN);
139 gobject_class->get_property = gtk_plug_get_property;
140 gobject_class->finalize = gtk_plug_finalize;
142 widget_class->realize = gtk_plug_realize;
143 widget_class->unrealize = gtk_plug_unrealize;
144 widget_class->key_press_event = gtk_plug_key_press_event;
145 widget_class->focus_in_event = gtk_plug_focus_event;
146 widget_class->focus_out_event = gtk_plug_focus_event;
148 widget_class->show = gtk_plug_show;
149 widget_class->hide = gtk_plug_hide;
150 widget_class->map = gtk_plug_map;
151 widget_class->unmap = gtk_plug_unmap;
152 widget_class->size_allocate = gtk_plug_size_allocate;
154 widget_class->focus = gtk_plug_focus;
156 container_class->check_resize = gtk_plug_check_resize;
158 window_class->set_focus = gtk_plug_set_focus;
159 window_class->keys_changed = gtk_plug_keys_changed;
164 * %TRUE if the plug is embedded in a socket.
168 g_object_class_install_property (gobject_class,
170 g_param_spec_boolean ("embedded",
172 P_("Whether or not the plug is embedded"),
174 GTK_PARAM_READABLE));
177 * GtkPlug:socket-window:
179 * The window of the socket the plug is embedded in.
183 g_object_class_install_property (gobject_class,
185 g_param_spec_object ("socket-window",
187 P_("The window of the socket the plug is embedded in"),
189 GTK_PARAM_READABLE));
193 * @plug: the object on which the signal was emitted
195 * Gets emitted when the plug becomes embedded in a socket.
197 plug_signals[EMBEDDED] =
198 g_signal_new (I_("embedded"),
199 G_OBJECT_CLASS_TYPE (class),
201 G_STRUCT_OFFSET (GtkPlugClass, embedded),
203 _gtk_marshal_VOID__VOID,
208 gtk_plug_init (GtkPlug *plug)
212 window = GTK_WINDOW (plug);
214 window->type = GTK_WINDOW_TOPLEVEL;
218 gtk_plug_set_is_child (GtkPlug *plug,
221 g_assert (!GTK_WIDGET (plug)->parent);
225 if (plug->modality_window)
226 _gtk_plug_handle_modality_off (plug);
228 if (plug->modality_group)
230 gtk_window_group_remove_window (plug->modality_group, GTK_WINDOW (plug));
231 g_object_unref (plug->modality_group);
232 plug->modality_group = NULL;
235 /* As a toplevel, the MAPPED flag doesn't correspond
236 * to whether the widget->window is mapped; we unmap
237 * here, but don't bother remapping -- we will get mapped
238 * by gtk_widget_set_parent ().
240 if (gtk_widget_get_mapped (GTK_WIDGET (plug)))
241 gtk_widget_unmap (GTK_WIDGET (plug));
243 _gtk_window_set_is_toplevel (GTK_WINDOW (plug), FALSE);
244 gtk_container_set_resize_mode (GTK_CONTAINER (plug), GTK_RESIZE_PARENT);
246 _gtk_widget_propagate_hierarchy_changed (GTK_WIDGET (plug), GTK_WIDGET (plug));
250 if (GTK_WINDOW (plug)->focus_widget)
251 gtk_window_set_focus (GTK_WINDOW (plug), NULL);
252 if (GTK_WINDOW (plug)->default_widget)
253 gtk_window_set_default (GTK_WINDOW (plug), NULL);
255 plug->modality_group = gtk_window_group_new ();
256 gtk_window_group_add_window (plug->modality_group, GTK_WINDOW (plug));
258 _gtk_window_set_is_toplevel (GTK_WINDOW (plug), TRUE);
259 gtk_container_set_resize_mode (GTK_CONTAINER (plug), GTK_RESIZE_QUEUE);
261 _gtk_widget_propagate_hierarchy_changed (GTK_WIDGET (plug), NULL);
269 * Gets the window ID of a #GtkPlug widget, which can then
270 * be used to embed this window inside another window, for
271 * instance with gtk_socket_add_id().
273 * Return value: the window ID for the plug
276 gtk_plug_get_id (GtkPlug *plug)
278 g_return_val_if_fail (GTK_IS_PLUG (plug), 0);
280 if (!gtk_widget_get_realized (GTK_WIDGET (plug)))
281 gtk_widget_realize (GTK_WIDGET (plug));
283 return _gtk_plug_windowing_get_id (plug);
287 * gtk_plug_get_embedded:
290 * Determines whether the plug is embedded in a socket.
292 * Return value: %TRUE if the plug is embedded in a socket
297 gtk_plug_get_embedded (GtkPlug *plug)
299 g_return_val_if_fail (GTK_IS_PLUG (plug), FALSE);
301 return plug->socket_window != NULL;
305 * gtk_plug_get_socket_window:
308 * Retrieves the socket the plug is embedded in.
310 * Return value: the window of the socket, or %NULL
315 gtk_plug_get_socket_window (GtkPlug *plug)
317 g_return_val_if_fail (GTK_IS_PLUG (plug), NULL);
319 return plug->socket_window;
323 * _gtk_plug_add_to_socket:
325 * @socket_: a #GtkSocket
327 * Adds a plug to a socket within the same application.
330 _gtk_plug_add_to_socket (GtkPlug *plug,
336 g_return_if_fail (GTK_IS_PLUG (plug));
337 g_return_if_fail (GTK_IS_SOCKET (socket_));
338 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (socket_)));
340 widget = GTK_WIDGET (plug);
342 gtk_plug_set_is_child (plug, TRUE);
343 plug->same_app = TRUE;
344 socket_->same_app = TRUE;
345 socket_->plug_widget = widget;
347 plug->socket_window = GTK_WIDGET (socket_)->window;
348 g_object_ref (plug->socket_window);
349 g_signal_emit (plug, plug_signals[EMBEDDED], 0);
350 g_object_notify (G_OBJECT (plug), "embedded");
352 if (gtk_widget_get_realized (widget))
354 gdk_drawable_get_size (GDK_DRAWABLE (widget->window), &w, &h);
355 gdk_window_reparent (widget->window, plug->socket_window, -w, -h);
358 gtk_widget_set_parent (widget, GTK_WIDGET (socket_));
360 g_signal_emit_by_name (socket_, "plug-added");
364 * _gtk_plug_send_delete_event:
365 * @widget: a #GtkWidget
367 * Send a GDK_DELETE event to the @widget and destroy it if
368 * necessary. Internal GTK function, called from this file or the
369 * backend-specific GtkPlug implementation.
372 _gtk_plug_send_delete_event (GtkWidget *widget)
374 GdkEvent *event = gdk_event_new (GDK_DELETE);
376 event->any.window = g_object_ref (widget->window);
377 event->any.send_event = FALSE;
379 g_object_ref (widget);
381 if (!gtk_widget_event (widget, event))
382 gtk_widget_destroy (widget);
384 g_object_unref (widget);
386 gdk_event_free (event);
390 * _gtk_plug_remove_from_socket:
392 * @socket_: a #GtkSocket
394 * Removes a plug from a socket within the same application.
397 _gtk_plug_remove_from_socket (GtkPlug *plug,
402 gboolean widget_was_visible;
404 g_return_if_fail (GTK_IS_PLUG (plug));
405 g_return_if_fail (GTK_IS_SOCKET (socket_));
406 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (plug)));
408 widget = GTK_WIDGET (plug);
410 if (GTK_WIDGET_IN_REPARENT (widget))
414 g_object_ref (socket_);
416 widget_was_visible = gtk_widget_get_visible (widget);
418 gdk_window_hide (widget->window);
419 GTK_PRIVATE_SET_FLAG (plug, GTK_IN_REPARENT);
420 gdk_window_reparent (widget->window,
421 gtk_widget_get_root_window (widget),
423 gtk_widget_unparent (GTK_WIDGET (plug));
424 GTK_PRIVATE_UNSET_FLAG (plug, GTK_IN_REPARENT);
426 socket_->plug_widget = NULL;
427 if (socket_->plug_window != NULL)
429 g_object_unref (socket_->plug_window);
430 socket_->plug_window = NULL;
433 socket_->same_app = FALSE;
435 plug->same_app = FALSE;
436 if (plug->socket_window != NULL)
438 g_object_unref (plug->socket_window);
439 plug->socket_window = NULL;
441 gtk_plug_set_is_child (plug, FALSE);
443 g_signal_emit_by_name (socket_, "plug-removed", &result);
445 gtk_widget_destroy (GTK_WIDGET (socket_));
448 _gtk_plug_send_delete_event (widget);
450 g_object_unref (plug);
452 if (widget_was_visible && gtk_widget_get_visible (GTK_WIDGET (socket_)))
453 gtk_widget_queue_resize (GTK_WIDGET (socket_));
455 g_object_unref (socket_);
459 * gtk_plug_construct:
461 * @socket_id: the XID of the socket's window.
463 * Finish the initialization of @plug for a given #GtkSocket identified by
464 * @socket_id. This function will generally only be used by classes deriving from #GtkPlug.
467 gtk_plug_construct (GtkPlug *plug,
468 GdkNativeWindow socket_id)
470 gtk_plug_construct_for_display (plug, gdk_display_get_default (), socket_id);
474 * gtk_plug_construct_for_display:
476 * @display: the #GdkDisplay associated with @socket_id's
478 * @socket_id: the XID of the socket's window.
480 * Finish the initialization of @plug for a given #GtkSocket identified by
481 * @socket_id which is currently displayed on @display.
482 * This function will generally only be used by classes deriving from #GtkPlug.
487 gtk_plug_construct_for_display (GtkPlug *plug,
489 GdkNativeWindow socket_id)
493 gpointer user_data = NULL;
495 plug->socket_window = gdk_window_lookup_for_display (display, socket_id);
496 if (plug->socket_window)
498 gdk_window_get_user_data (plug->socket_window, &user_data);
502 if (GTK_IS_SOCKET (user_data))
503 _gtk_plug_add_to_socket (plug, user_data);
506 g_warning (G_STRLOC "Can't create GtkPlug as child of non-GtkSocket");
507 plug->socket_window = NULL;
511 g_object_ref (plug->socket_window);
514 plug->socket_window = gdk_window_foreign_new_for_display (display, socket_id);
516 if (plug->socket_window) {
517 g_signal_emit (plug, plug_signals[EMBEDDED], 0);
519 g_object_notify (G_OBJECT (plug), "embedded");
526 * @socket_id: the window ID of the socket, or 0.
528 * Creates a new plug widget inside the #GtkSocket identified
529 * by @socket_id. If @socket_id is 0, the plug is left "unplugged" and
530 * can later be plugged into a #GtkSocket by gtk_socket_add_id().
532 * Return value: the new #GtkPlug widget.
535 gtk_plug_new (GdkNativeWindow socket_id)
537 return gtk_plug_new_for_display (gdk_display_get_default (), socket_id);
541 * gtk_plug_new_for_display:
542 * @display : the #GdkDisplay on which @socket_id is displayed
543 * @socket_id: the XID of the socket's window.
545 * Create a new plug widget inside the #GtkSocket identified by socket_id.
547 * Return value: the new #GtkPlug widget.
552 gtk_plug_new_for_display (GdkDisplay *display,
553 GdkNativeWindow socket_id)
557 plug = g_object_new (GTK_TYPE_PLUG, NULL);
558 gtk_plug_construct_for_display (plug, display, socket_id);
559 return GTK_WIDGET (plug);
563 gtk_plug_finalize (GObject *object)
565 GtkPlug *plug = GTK_PLUG (object);
567 if (plug->grabbed_keys)
569 g_hash_table_destroy (plug->grabbed_keys);
570 plug->grabbed_keys = NULL;
573 G_OBJECT_CLASS (gtk_plug_parent_class)->finalize (object);
577 gtk_plug_unrealize (GtkWidget *widget)
579 GtkPlug *plug = GTK_PLUG (widget);
581 if (plug->socket_window != NULL)
583 gdk_window_set_user_data (plug->socket_window, NULL);
584 g_object_unref (plug->socket_window);
585 plug->socket_window = NULL;
587 g_object_notify (G_OBJECT (widget), "embedded");
592 if (plug->modality_window)
593 _gtk_plug_handle_modality_off (plug);
595 gtk_window_group_remove_window (plug->modality_group, GTK_WINDOW (plug));
596 g_object_unref (plug->modality_group);
599 GTK_WIDGET_CLASS (gtk_plug_parent_class)->unrealize (widget);
603 gtk_plug_realize (GtkWidget *widget)
605 GtkWindow *window = GTK_WINDOW (widget);
606 GtkPlug *plug = GTK_PLUG (widget);
607 GdkWindowAttr attributes;
608 gint attributes_mask;
610 gtk_widget_set_realized (widget, TRUE);
612 attributes.window_type = GDK_WINDOW_CHILD; /* XXX GDK_WINDOW_PLUG ? */
613 attributes.title = window->title;
614 attributes.wmclass_name = window->wmclass_name;
615 attributes.wmclass_class = window->wmclass_class;
616 attributes.width = widget->allocation.width;
617 attributes.height = widget->allocation.height;
618 attributes.wclass = GDK_INPUT_OUTPUT;
620 /* this isn't right - we should match our parent's visual/colormap.
621 * though that will require handling "foreign" colormaps */
622 attributes.visual = gtk_widget_get_visual (widget);
623 attributes.colormap = gtk_widget_get_colormap (widget);
624 attributes.event_mask = gtk_widget_get_events (widget);
625 attributes.event_mask |= (GDK_EXPOSURE_MASK |
627 GDK_KEY_RELEASE_MASK |
628 GDK_ENTER_NOTIFY_MASK |
629 GDK_LEAVE_NOTIFY_MASK |
632 attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
633 attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
634 attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
636 if (gtk_widget_is_toplevel (widget))
638 attributes.window_type = GDK_WINDOW_TOPLEVEL;
640 gdk_error_trap_push ();
641 if (plug->socket_window)
642 widget->window = gdk_window_new (plug->socket_window,
643 &attributes, attributes_mask);
644 else /* If it's a passive plug, we use the root window */
645 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
646 &attributes, attributes_mask);
648 gdk_display_sync (gtk_widget_get_display (widget));
649 if (gdk_error_trap_pop ()) /* Uh-oh */
651 gdk_error_trap_push ();
652 gdk_window_destroy (widget->window);
654 gdk_error_trap_pop ();
655 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
656 &attributes, attributes_mask);
659 gdk_window_add_filter (widget->window,
660 _gtk_plug_windowing_filter_func,
663 plug->modality_group = gtk_window_group_new ();
664 gtk_window_group_add_window (plug->modality_group, window);
666 _gtk_plug_windowing_realize_toplevel (plug);
669 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
670 &attributes, attributes_mask);
672 gdk_window_set_user_data (widget->window, window);
674 widget->style = gtk_style_attach (widget->style, widget->window);
675 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
677 gdk_window_enable_synchronized_configure (widget->window);
681 gtk_plug_show (GtkWidget *widget)
683 if (gtk_widget_is_toplevel (widget))
684 GTK_WIDGET_CLASS (gtk_plug_parent_class)->show (widget);
686 GTK_WIDGET_CLASS (bin_class)->show (widget);
690 gtk_plug_hide (GtkWidget *widget)
692 if (gtk_widget_is_toplevel (widget))
693 GTK_WIDGET_CLASS (gtk_plug_parent_class)->hide (widget);
695 GTK_WIDGET_CLASS (bin_class)->hide (widget);
698 /* From gdkinternals.h */
699 void gdk_synthesize_window_state (GdkWindow *window,
700 GdkWindowState unset_flags,
701 GdkWindowState set_flags);
704 gtk_plug_map (GtkWidget *widget)
706 if (gtk_widget_is_toplevel (widget))
708 GtkBin *bin = GTK_BIN (widget);
709 GtkPlug *plug = GTK_PLUG (widget);
711 gtk_widget_set_mapped (widget, TRUE);
714 gtk_widget_get_visible (bin->child) &&
715 !gtk_widget_get_mapped (bin->child))
716 gtk_widget_map (bin->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)
753 if (gtk_widget_is_toplevel (widget))
754 GTK_WIDGET_CLASS (gtk_plug_parent_class)->size_allocate (widget, allocation);
757 GtkBin *bin = GTK_BIN (widget);
759 widget->allocation = *allocation;
761 if (gtk_widget_get_realized (widget))
762 gdk_window_move_resize (widget->window,
763 allocation->x, allocation->y,
764 allocation->width, allocation->height);
766 if (bin->child && gtk_widget_get_visible (bin->child))
768 GtkAllocation child_allocation;
770 child_allocation.x = child_allocation.y = GTK_CONTAINER (widget)->border_width;
771 child_allocation.width =
772 MAX (1, (gint)allocation->width - child_allocation.x * 2);
773 child_allocation.height =
774 MAX (1, (gint)allocation->height - child_allocation.y * 2);
776 gtk_widget_size_allocate (bin->child, &child_allocation);
783 gtk_plug_key_press_event (GtkWidget *widget,
786 if (gtk_widget_is_toplevel (widget))
787 return GTK_WIDGET_CLASS (gtk_plug_parent_class)->key_press_event (widget, event);
793 gtk_plug_focus_event (GtkWidget *widget,
794 GdkEventFocus *event)
796 /* We eat focus-in events and focus-out events, since they
797 * can be generated by something like a keyboard grab on
798 * a child of the plug.
804 gtk_plug_set_focus (GtkWindow *window,
807 GtkPlug *plug = GTK_PLUG (window);
809 GTK_WINDOW_CLASS (gtk_plug_parent_class)->set_focus (window, focus);
811 /* Ask for focus from embedder
814 if (focus && !window->has_toplevel_focus)
815 _gtk_plug_windowing_set_focus (plug);
819 grabbed_key_hash (gconstpointer a)
821 const GrabbedKey *key = a;
824 h = key->accelerator_key << 16;
825 h ^= key->accelerator_key >> 16;
826 h ^= key->accelerator_mods;
832 grabbed_key_equal (gconstpointer a, gconstpointer b)
834 const GrabbedKey *keya = a;
835 const GrabbedKey *keyb = b;
837 return (keya->accelerator_key == keyb->accelerator_key &&
838 keya->accelerator_mods == keyb->accelerator_mods);
842 add_grabbed_key (gpointer key, gpointer val, gpointer data)
844 GrabbedKey *grabbed_key = key;
845 GtkPlug *plug = data;
847 if (!plug->grabbed_keys ||
848 !g_hash_table_lookup (plug->grabbed_keys, grabbed_key))
850 _gtk_plug_windowing_add_grabbed_key (plug,
851 grabbed_key->accelerator_key,
852 grabbed_key->accelerator_mods);
857 add_grabbed_key_always (gpointer key,
861 GrabbedKey *grabbed_key = key;
862 GtkPlug *plug = data;
864 _gtk_plug_windowing_add_grabbed_key (plug,
865 grabbed_key->accelerator_key,
866 grabbed_key->accelerator_mods);
870 * _gtk_plug_add_all_grabbed_keys:
874 * Calls _gtk_plug_windowing_add_grabbed_key() on all the grabbed keys
878 _gtk_plug_add_all_grabbed_keys (GtkPlug *plug)
880 if (plug->grabbed_keys)
881 g_hash_table_foreach (plug->grabbed_keys, add_grabbed_key_always, plug);
885 remove_grabbed_key (gpointer key, gpointer val, gpointer data)
887 GrabbedKey *grabbed_key = key;
888 GtkPlug *plug = data;
890 if (!plug->grabbed_keys ||
891 !g_hash_table_lookup (plug->grabbed_keys, grabbed_key))
893 _gtk_plug_windowing_remove_grabbed_key (plug,
894 grabbed_key->accelerator_key,
895 grabbed_key->accelerator_mods);
900 keys_foreach (GtkWindow *window,
902 GdkModifierType modifiers,
903 gboolean is_mnemonic,
906 GHashTable *new_grabbed_keys = data;
907 GrabbedKey *key = g_slice_new (GrabbedKey);
909 key->accelerator_key = keyval;
910 key->accelerator_mods = modifiers;
912 g_hash_table_replace (new_grabbed_keys, key, key);
916 grabbed_key_free (gpointer data)
918 g_slice_free (GrabbedKey, data);
922 gtk_plug_keys_changed (GtkWindow *window)
924 GHashTable *new_grabbed_keys, *old_grabbed_keys;
925 GtkPlug *plug = GTK_PLUG (window);
927 new_grabbed_keys = g_hash_table_new_full (grabbed_key_hash, grabbed_key_equal, (GDestroyNotify)grabbed_key_free, NULL);
928 _gtk_window_keys_foreach (window, keys_foreach, new_grabbed_keys);
930 if (plug->socket_window)
931 g_hash_table_foreach (new_grabbed_keys, add_grabbed_key, plug);
933 old_grabbed_keys = plug->grabbed_keys;
934 plug->grabbed_keys = new_grabbed_keys;
936 if (old_grabbed_keys)
938 if (plug->socket_window)
939 g_hash_table_foreach (old_grabbed_keys, remove_grabbed_key, plug);
940 g_hash_table_destroy (old_grabbed_keys);
945 gtk_plug_focus (GtkWidget *widget,
946 GtkDirectionType direction)
948 GtkBin *bin = GTK_BIN (widget);
949 GtkPlug *plug = GTK_PLUG (widget);
950 GtkWindow *window = GTK_WINDOW (widget);
951 GtkContainer *container = GTK_CONTAINER (widget);
952 GtkWidget *old_focus_child = container->focus_child;
955 /* We override GtkWindow's behavior, since we don't want wrapping here.
959 if (gtk_widget_child_focus (old_focus_child, direction))
962 if (window->focus_widget)
964 /* Wrapped off the end, clear the focus setting for the toplevel */
965 parent = window->focus_widget->parent;
968 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
969 parent = GTK_WIDGET (parent)->parent;
972 gtk_window_set_focus (GTK_WINDOW (container), NULL);
977 /* Try to focus the first widget in the window */
978 if (bin->child && gtk_widget_child_focus (bin->child, direction))
982 if (!GTK_CONTAINER (window)->focus_child)
983 _gtk_plug_windowing_focus_to_parent (plug, direction);
989 gtk_plug_check_resize (GtkContainer *container)
991 if (gtk_widget_is_toplevel (GTK_WIDGET (container)))
992 GTK_CONTAINER_CLASS (gtk_plug_parent_class)->check_resize (container);
994 GTK_CONTAINER_CLASS (bin_class)->check_resize (container);
998 * _gtk_plug_handle_modality_on:
1002 * Called from the GtkPlug backend when the corresponding socket has
1003 * told the plug that it modality has toggled on.
1006 _gtk_plug_handle_modality_on (GtkPlug *plug)
1008 if (!plug->modality_window)
1010 plug->modality_window = gtk_window_new (GTK_WINDOW_POPUP);
1011 gtk_window_set_screen (GTK_WINDOW (plug->modality_window),
1012 gtk_widget_get_screen (GTK_WIDGET (plug)));
1013 gtk_widget_realize (plug->modality_window);
1014 gtk_window_group_add_window (plug->modality_group, GTK_WINDOW (plug->modality_window));
1015 gtk_grab_add (plug->modality_window);
1020 * _gtk_plug_handle_modality_off:
1024 * Called from the GtkPlug backend when the corresponding socket has
1025 * told the plug that it modality has toggled off.
1028 _gtk_plug_handle_modality_off (GtkPlug *plug)
1030 if (plug->modality_window)
1032 gtk_widget_destroy (plug->modality_window);
1033 plug->modality_window = NULL;
1038 * _gtk_plug_focus_first_last:
1041 * @direction: a direction
1043 * Called from the GtkPlug backend when the corresponding socket has
1044 * told the plug that it has received the focus.
1047 _gtk_plug_focus_first_last (GtkPlug *plug,
1048 GtkDirectionType direction)
1050 GtkWindow *window = GTK_WINDOW (plug);
1053 if (window->focus_widget)
1055 parent = window->focus_widget->parent;
1058 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
1059 parent = GTK_WIDGET (parent)->parent;
1062 gtk_window_set_focus (GTK_WINDOW (plug), NULL);
1065 gtk_widget_child_focus (GTK_WIDGET (plug), direction);
1068 #define __GTK_PLUG_C__
1069 #include "gtkaliasdef.c"