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 static void gtk_plug_get_property (GObject *object,
43 static void gtk_plug_finalize (GObject *object);
44 static void gtk_plug_realize (GtkWidget *widget);
45 static void gtk_plug_unrealize (GtkWidget *widget);
46 static void gtk_plug_show (GtkWidget *widget);
47 static void gtk_plug_hide (GtkWidget *widget);
48 static void gtk_plug_map (GtkWidget *widget);
49 static void gtk_plug_unmap (GtkWidget *widget);
50 static void gtk_plug_size_allocate (GtkWidget *widget,
51 GtkAllocation *allocation);
52 static gboolean gtk_plug_key_press_event (GtkWidget *widget,
54 static gboolean gtk_plug_focus_event (GtkWidget *widget,
55 GdkEventFocus *event);
56 static void gtk_plug_set_focus (GtkWindow *window,
58 static gboolean gtk_plug_focus (GtkWidget *widget,
59 GtkDirectionType direction);
60 static void gtk_plug_check_resize (GtkContainer *container);
61 static void gtk_plug_keys_changed (GtkWindow *window);
63 static GtkBinClass *bin_class = NULL;
67 guint accelerator_key;
68 GdkModifierType accelerator_mods;
82 static guint plug_signals[LAST_SIGNAL] = { 0 };
84 G_DEFINE_TYPE (GtkPlug, gtk_plug, GTK_TYPE_WINDOW)
87 gtk_plug_get_property (GObject *object,
92 GtkPlug *plug = GTK_PLUG (object);
97 g_value_set_boolean (value, plug->socket_window != NULL);
99 case PROP_SOCKET_WINDOW:
100 g_value_set_object (value, plug->socket_window);
103 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
109 gtk_plug_class_init (GtkPlugClass *class)
111 GObjectClass *gobject_class = (GObjectClass *)class;
112 GtkWidgetClass *widget_class = (GtkWidgetClass *)class;
113 GtkWindowClass *window_class = (GtkWindowClass *)class;
114 GtkContainerClass *container_class = (GtkContainerClass *)class;
116 bin_class = g_type_class_peek (GTK_TYPE_BIN);
118 gobject_class->get_property = gtk_plug_get_property;
119 gobject_class->finalize = gtk_plug_finalize;
121 widget_class->realize = gtk_plug_realize;
122 widget_class->unrealize = gtk_plug_unrealize;
123 widget_class->key_press_event = gtk_plug_key_press_event;
124 widget_class->focus_in_event = gtk_plug_focus_event;
125 widget_class->focus_out_event = gtk_plug_focus_event;
127 widget_class->show = gtk_plug_show;
128 widget_class->hide = gtk_plug_hide;
129 widget_class->map = gtk_plug_map;
130 widget_class->unmap = gtk_plug_unmap;
131 widget_class->size_allocate = gtk_plug_size_allocate;
133 widget_class->focus = gtk_plug_focus;
135 container_class->check_resize = gtk_plug_check_resize;
137 window_class->set_focus = gtk_plug_set_focus;
138 window_class->keys_changed = gtk_plug_keys_changed;
143 * %TRUE if the plug is embedded in a socket.
147 g_object_class_install_property (gobject_class,
149 g_param_spec_boolean ("embedded",
151 P_("Whether or not the plug is embedded"),
153 GTK_PARAM_READABLE));
156 * GtkPlug:socket-window:
158 * The window of the socket the plug is embedded in.
162 g_object_class_install_property (gobject_class,
164 g_param_spec_object ("socket-window",
166 P_("The window of the socket the plug is embedded in"),
168 GTK_PARAM_READABLE));
172 * @plug: the object on which the signal was emitted
174 * Gets emitted when the plug becomes embedded in a socket
175 * and when the embedding ends.
177 plug_signals[EMBEDDED] =
178 g_signal_new (I_("embedded"),
179 G_OBJECT_CLASS_TYPE (class),
181 G_STRUCT_OFFSET (GtkPlugClass, embedded),
183 _gtk_marshal_VOID__VOID,
188 gtk_plug_init (GtkPlug *plug)
192 window = GTK_WINDOW (plug);
194 window->type = GTK_WINDOW_TOPLEVEL;
198 gtk_plug_set_is_child (GtkPlug *plug,
201 g_assert (!GTK_WIDGET (plug)->parent);
205 if (plug->modality_window)
206 _gtk_plug_handle_modality_off (plug);
208 if (plug->modality_group)
210 gtk_window_group_remove_window (plug->modality_group, GTK_WINDOW (plug));
211 g_object_unref (plug->modality_group);
212 plug->modality_group = NULL;
215 /* As a toplevel, the MAPPED flag doesn't correspond
216 * to whether the widget->window is mapped; we unmap
217 * here, but don't bother remapping -- we will get mapped
218 * by gtk_widget_set_parent ().
220 if (GTK_WIDGET_MAPPED (plug))
221 gtk_widget_unmap (GTK_WIDGET (plug));
223 _gtk_window_set_is_toplevel (GTK_WINDOW (plug), FALSE);
224 gtk_container_set_resize_mode (GTK_CONTAINER (plug), GTK_RESIZE_PARENT);
226 _gtk_widget_propagate_hierarchy_changed (GTK_WIDGET (plug), GTK_WIDGET (plug));
230 if (GTK_WINDOW (plug)->focus_widget)
231 gtk_window_set_focus (GTK_WINDOW (plug), NULL);
232 if (GTK_WINDOW (plug)->default_widget)
233 gtk_window_set_default (GTK_WINDOW (plug), NULL);
235 plug->modality_group = gtk_window_group_new ();
236 gtk_window_group_add_window (plug->modality_group, GTK_WINDOW (plug));
238 _gtk_window_set_is_toplevel (GTK_WINDOW (plug), TRUE);
239 gtk_container_set_resize_mode (GTK_CONTAINER (plug), GTK_RESIZE_QUEUE);
241 _gtk_widget_propagate_hierarchy_changed (GTK_WIDGET (plug), NULL);
249 * Gets the window ID of a #GtkPlug widget, which can then
250 * be used to embed this window inside another window, for
251 * instance with gtk_socket_add_id().
253 * Return value: the window ID for the plug
256 gtk_plug_get_id (GtkPlug *plug)
258 g_return_val_if_fail (GTK_IS_PLUG (plug), 0);
260 if (!GTK_WIDGET_REALIZED (plug))
261 gtk_widget_realize (GTK_WIDGET (plug));
263 return _gtk_plug_windowing_get_id (plug);
267 * gtk_plug_get_embedded:
270 * Determines whether the plug is embedded in a socket.
272 * Return value: %TRUE if the plug is embedded in a socket
277 gtk_plug_get_embedded (GtkPlug *plug)
279 g_return_val_if_fail (GTK_IS_PLUG (plug), FALSE);
281 return plug->socket_window != NULL;
285 * gtk_plug_get_socket_window:
288 * Retrieves the socket the plug is embedded in.
290 * Return value: the window of the socket, or %NULL
295 gtk_plug_get_socket_window (GtkPlug *plug)
297 g_return_val_if_fail (GTK_IS_PLUG (plug), NULL);
299 return plug->socket_window;
303 * _gtk_plug_add_to_socket:
305 * @socket_: a #GtkSocket
307 * Adds a plug to a socket within the same application.
310 _gtk_plug_add_to_socket (GtkPlug *plug,
316 g_return_if_fail (GTK_IS_PLUG (plug));
317 g_return_if_fail (GTK_IS_SOCKET (socket_));
318 g_return_if_fail (GTK_WIDGET_REALIZED (socket_));
320 widget = GTK_WIDGET (plug);
322 gtk_plug_set_is_child (plug, TRUE);
323 plug->same_app = TRUE;
324 socket_->same_app = TRUE;
325 socket_->plug_widget = widget;
327 plug->socket_window = GTK_WIDGET (socket_)->window;
328 g_object_ref (plug->socket_window);
330 if (GTK_WIDGET_REALIZED (widget))
332 gdk_drawable_get_size (GDK_DRAWABLE (widget->window), &w, &h);
333 gdk_window_reparent (widget->window, plug->socket_window, -w, -h);
336 gtk_widget_set_parent (widget, GTK_WIDGET (socket_));
338 g_signal_emit_by_name (socket_, "plug-added");
342 * _gtk_plug_send_delete_event:
343 * @widget: a #GtkWidget
345 * Send a GDK_DELETE event to the @widget and destroy it if
346 * necessary. Internal GTK function, called from this file or the
347 * backend-specific GtkPlug implementation.
350 _gtk_plug_send_delete_event (GtkWidget *widget)
352 GdkEvent *event = gdk_event_new (GDK_DELETE);
354 event->any.window = g_object_ref (widget->window);
355 event->any.send_event = FALSE;
357 g_object_ref (widget);
359 if (!gtk_widget_event (widget, event))
360 gtk_widget_destroy (widget);
362 g_object_unref (widget);
364 gdk_event_free (event);
368 * _gtk_plug_remove_from_socket:
370 * @socket_: a #GtkSocket
372 * Removes a plug from a socket within the same application.
375 _gtk_plug_remove_from_socket (GtkPlug *plug,
380 gboolean widget_was_visible;
382 g_return_if_fail (GTK_IS_PLUG (plug));
383 g_return_if_fail (GTK_IS_SOCKET (socket_));
384 g_return_if_fail (GTK_WIDGET_REALIZED (plug));
386 widget = GTK_WIDGET (plug);
388 if (GTK_WIDGET_IN_REPARENT (widget))
392 g_object_ref (socket_);
394 widget_was_visible = GTK_WIDGET_VISIBLE (plug);
396 gdk_window_hide (widget->window);
397 GTK_PRIVATE_SET_FLAG (plug, GTK_IN_REPARENT);
398 gdk_window_reparent (widget->window,
399 gtk_widget_get_root_window (widget),
401 gtk_widget_unparent (GTK_WIDGET (plug));
402 GTK_PRIVATE_UNSET_FLAG (plug, GTK_IN_REPARENT);
404 socket_->plug_widget = NULL;
405 if (socket_->plug_window != NULL)
407 g_object_unref (socket_->plug_window);
408 socket_->plug_window = NULL;
411 socket_->same_app = FALSE;
413 plug->same_app = FALSE;
414 if (plug->socket_window != NULL)
416 g_object_unref (plug->socket_window);
417 plug->socket_window = NULL;
419 gtk_plug_set_is_child (plug, FALSE);
421 g_signal_emit_by_name (socket_, "plug-removed", &result);
423 gtk_widget_destroy (GTK_WIDGET (socket_));
426 _gtk_plug_send_delete_event (widget);
428 g_object_unref (plug);
430 if (widget_was_visible && GTK_WIDGET_VISIBLE (socket_))
431 gtk_widget_queue_resize (GTK_WIDGET (socket_));
433 g_object_unref (socket_);
437 * gtk_plug_construct:
439 * @socket_id: the XID of the socket's window.
441 * Finish the initialization of @plug for a given #GtkSocket identified by
442 * @socket_id. This function will generally only be used by classes deriving from #GtkPlug.
445 gtk_plug_construct (GtkPlug *plug,
446 GdkNativeWindow socket_id)
448 gtk_plug_construct_for_display (plug, gdk_display_get_default (), socket_id);
452 * gtk_plug_construct_for_display:
454 * @display: the #GdkDisplay associated with @socket_id's
456 * @socket_id: the XID of the socket's window.
458 * Finish the initialization of @plug for a given #GtkSocket identified by
459 * @socket_id which is currently displayed on @display.
460 * This function will generally only be used by classes deriving from #GtkPlug.
465 gtk_plug_construct_for_display (GtkPlug *plug,
467 GdkNativeWindow socket_id)
471 gpointer user_data = NULL;
473 plug->socket_window = gdk_window_lookup_for_display (display, socket_id);
474 if (plug->socket_window)
476 gdk_window_get_user_data (plug->socket_window, &user_data);
480 if (GTK_IS_SOCKET (user_data))
481 _gtk_plug_add_to_socket (plug, user_data);
484 g_warning (G_STRLOC "Can't create GtkPlug as child of non-GtkSocket");
485 plug->socket_window = NULL;
489 g_object_ref (plug->socket_window);
492 plug->socket_window = gdk_window_foreign_new_for_display (display, socket_id);
494 if (plug->socket_window) {
495 g_signal_emit (plug, plug_signals[EMBEDDED], 0);
497 g_object_notify (G_OBJECT (plug), "embedded");
504 * @socket_id: the window ID of the socket, or 0.
506 * Creates a new plug widget inside the #GtkSocket identified
507 * by @socket_id. If @socket_id is 0, the plug is left "unplugged" and
508 * can later be plugged into a #GtkSocket by gtk_socket_add_id().
510 * Return value: the new #GtkPlug widget.
513 gtk_plug_new (GdkNativeWindow socket_id)
515 return gtk_plug_new_for_display (gdk_display_get_default (), socket_id);
519 * gtk_plug_new_for_display:
520 * @display : the #GdkDisplay on which @socket_id is displayed
521 * @socket_id: the XID of the socket's window.
523 * Create a new plug widget inside the #GtkSocket identified by socket_id.
525 * Return value: the new #GtkPlug widget.
530 gtk_plug_new_for_display (GdkDisplay *display,
531 GdkNativeWindow socket_id)
535 plug = g_object_new (GTK_TYPE_PLUG, NULL);
536 gtk_plug_construct_for_display (plug, display, socket_id);
537 return GTK_WIDGET (plug);
541 gtk_plug_finalize (GObject *object)
543 GtkPlug *plug = GTK_PLUG (object);
545 if (plug->grabbed_keys)
547 g_hash_table_destroy (plug->grabbed_keys);
548 plug->grabbed_keys = NULL;
551 G_OBJECT_CLASS (gtk_plug_parent_class)->finalize (object);
555 gtk_plug_unrealize (GtkWidget *widget)
557 GtkPlug *plug = GTK_PLUG (widget);
559 if (plug->socket_window != NULL)
561 gdk_window_set_user_data (plug->socket_window, NULL);
562 g_object_unref (plug->socket_window);
563 plug->socket_window = NULL;
565 g_object_notify (G_OBJECT (widget), "embedded");
570 if (plug->modality_window)
571 _gtk_plug_handle_modality_off (plug);
573 gtk_window_group_remove_window (plug->modality_group, GTK_WINDOW (plug));
574 g_object_unref (plug->modality_group);
577 GTK_WIDGET_CLASS (gtk_plug_parent_class)->unrealize (widget);
581 gtk_plug_realize (GtkWidget *widget)
583 GtkWindow *window = GTK_WINDOW (widget);
584 GtkPlug *plug = GTK_PLUG (widget);
585 GdkWindowAttr attributes;
586 gint attributes_mask;
588 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
590 attributes.window_type = GDK_WINDOW_CHILD; /* XXX GDK_WINDOW_PLUG ? */
591 attributes.title = window->title;
592 attributes.wmclass_name = window->wmclass_name;
593 attributes.wmclass_class = window->wmclass_class;
594 attributes.width = widget->allocation.width;
595 attributes.height = widget->allocation.height;
596 attributes.wclass = GDK_INPUT_OUTPUT;
598 /* this isn't right - we should match our parent's visual/colormap.
599 * though that will require handling "foreign" colormaps */
600 attributes.visual = gtk_widget_get_visual (widget);
601 attributes.colormap = gtk_widget_get_colormap (widget);
602 attributes.event_mask = gtk_widget_get_events (widget);
603 attributes.event_mask |= (GDK_EXPOSURE_MASK |
605 GDK_KEY_RELEASE_MASK |
606 GDK_ENTER_NOTIFY_MASK |
607 GDK_LEAVE_NOTIFY_MASK |
610 attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
611 attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
612 attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
614 if (gtk_widget_is_toplevel (widget))
616 attributes.window_type = GDK_WINDOW_TOPLEVEL;
618 gdk_error_trap_push ();
619 if (plug->socket_window)
620 widget->window = gdk_window_new (plug->socket_window,
621 &attributes, attributes_mask);
622 else /* If it's a passive plug, we use the root window */
623 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
624 &attributes, attributes_mask);
626 gdk_display_sync (gtk_widget_get_display (widget));
627 if (gdk_error_trap_pop ()) /* Uh-oh */
629 gdk_error_trap_push ();
630 gdk_window_destroy (widget->window);
632 gdk_error_trap_pop ();
633 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
634 &attributes, attributes_mask);
637 gdk_window_add_filter (widget->window,
638 _gtk_plug_windowing_filter_func,
641 plug->modality_group = gtk_window_group_new ();
642 gtk_window_group_add_window (plug->modality_group, window);
644 _gtk_plug_windowing_realize_toplevel (plug);
647 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
648 &attributes, attributes_mask);
650 gdk_window_set_user_data (widget->window, window);
652 widget->style = gtk_style_attach (widget->style, widget->window);
653 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
655 gdk_window_enable_synchronized_configure (widget->window);
659 gtk_plug_show (GtkWidget *widget)
661 if (gtk_widget_is_toplevel (widget))
662 GTK_WIDGET_CLASS (gtk_plug_parent_class)->show (widget);
664 GTK_WIDGET_CLASS (bin_class)->show (widget);
668 gtk_plug_hide (GtkWidget *widget)
670 if (gtk_widget_is_toplevel (widget))
671 GTK_WIDGET_CLASS (gtk_plug_parent_class)->hide (widget);
673 GTK_WIDGET_CLASS (bin_class)->hide (widget);
676 /* From gdkinternals.h */
677 void gdk_synthesize_window_state (GdkWindow *window,
678 GdkWindowState unset_flags,
679 GdkWindowState set_flags);
682 gtk_plug_map (GtkWidget *widget)
684 if (gtk_widget_is_toplevel (widget))
686 GtkBin *bin = GTK_BIN (widget);
687 GtkPlug *plug = GTK_PLUG (widget);
689 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
692 GTK_WIDGET_VISIBLE (bin->child) &&
693 !GTK_WIDGET_MAPPED (bin->child))
694 gtk_widget_map (bin->child);
696 _gtk_plug_windowing_map_toplevel (plug);
698 gdk_synthesize_window_state (widget->window,
699 GDK_WINDOW_STATE_WITHDRAWN,
703 GTK_WIDGET_CLASS (bin_class)->map (widget);
707 gtk_plug_unmap (GtkWidget *widget)
709 if (gtk_widget_is_toplevel (widget))
711 GtkPlug *plug = GTK_PLUG (widget);
713 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
715 gdk_window_hide (widget->window);
717 _gtk_plug_windowing_unmap_toplevel (plug);
719 gdk_synthesize_window_state (widget->window,
721 GDK_WINDOW_STATE_WITHDRAWN);
724 GTK_WIDGET_CLASS (bin_class)->unmap (widget);
728 gtk_plug_size_allocate (GtkWidget *widget,
729 GtkAllocation *allocation)
731 if (gtk_widget_is_toplevel (widget))
732 GTK_WIDGET_CLASS (gtk_plug_parent_class)->size_allocate (widget, allocation);
735 GtkBin *bin = GTK_BIN (widget);
737 widget->allocation = *allocation;
739 if (GTK_WIDGET_REALIZED (widget))
740 gdk_window_move_resize (widget->window,
741 allocation->x, allocation->y,
742 allocation->width, allocation->height);
744 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
746 GtkAllocation child_allocation;
748 child_allocation.x = child_allocation.y = GTK_CONTAINER (widget)->border_width;
749 child_allocation.width =
750 MAX (1, (gint)allocation->width - child_allocation.x * 2);
751 child_allocation.height =
752 MAX (1, (gint)allocation->height - child_allocation.y * 2);
754 gtk_widget_size_allocate (bin->child, &child_allocation);
761 gtk_plug_key_press_event (GtkWidget *widget,
764 if (gtk_widget_is_toplevel (widget))
765 return GTK_WIDGET_CLASS (gtk_plug_parent_class)->key_press_event (widget, event);
771 gtk_plug_focus_event (GtkWidget *widget,
772 GdkEventFocus *event)
774 /* We eat focus-in events and focus-out events, since they
775 * can be generated by something like a keyboard grab on
776 * a child of the plug.
782 gtk_plug_set_focus (GtkWindow *window,
785 GtkPlug *plug = GTK_PLUG (window);
787 GTK_WINDOW_CLASS (gtk_plug_parent_class)->set_focus (window, focus);
789 /* Ask for focus from embedder
792 if (focus && !window->has_toplevel_focus)
793 _gtk_plug_windowing_set_focus (plug);
797 grabbed_key_hash (gconstpointer a)
799 const GrabbedKey *key = a;
802 h = key->accelerator_key << 16;
803 h ^= key->accelerator_key >> 16;
804 h ^= key->accelerator_mods;
810 grabbed_key_equal (gconstpointer a, gconstpointer b)
812 const GrabbedKey *keya = a;
813 const GrabbedKey *keyb = b;
815 return (keya->accelerator_key == keyb->accelerator_key &&
816 keya->accelerator_mods == keyb->accelerator_mods);
820 add_grabbed_key (gpointer key, gpointer val, gpointer data)
822 GrabbedKey *grabbed_key = key;
823 GtkPlug *plug = data;
825 if (!plug->grabbed_keys ||
826 !g_hash_table_lookup (plug->grabbed_keys, grabbed_key))
828 _gtk_plug_windowing_add_grabbed_key (plug,
829 grabbed_key->accelerator_key,
830 grabbed_key->accelerator_mods);
835 add_grabbed_key_always (gpointer key,
839 GrabbedKey *grabbed_key = key;
840 GtkPlug *plug = data;
842 _gtk_plug_windowing_add_grabbed_key (plug,
843 grabbed_key->accelerator_key,
844 grabbed_key->accelerator_mods);
848 * _gtk_plug_add_all_grabbed_keys:
852 * Calls _gtk_plug_windowing_add_grabbed_key() on all the grabbed keys
856 _gtk_plug_add_all_grabbed_keys (GtkPlug *plug)
858 if (plug->grabbed_keys)
859 g_hash_table_foreach (plug->grabbed_keys, add_grabbed_key_always, plug);
863 remove_grabbed_key (gpointer key, gpointer val, gpointer data)
865 GrabbedKey *grabbed_key = key;
866 GtkPlug *plug = data;
868 if (!plug->grabbed_keys ||
869 !g_hash_table_lookup (plug->grabbed_keys, grabbed_key))
871 _gtk_plug_windowing_remove_grabbed_key (plug,
872 grabbed_key->accelerator_key,
873 grabbed_key->accelerator_mods);
878 keys_foreach (GtkWindow *window,
880 GdkModifierType modifiers,
881 gboolean is_mnemonic,
884 GHashTable *new_grabbed_keys = data;
885 GrabbedKey *key = g_slice_new (GrabbedKey);
887 key->accelerator_key = keyval;
888 key->accelerator_mods = modifiers;
890 g_hash_table_replace (new_grabbed_keys, key, key);
894 grabbed_key_free (gpointer data)
896 g_slice_free (GrabbedKey, data);
900 gtk_plug_keys_changed (GtkWindow *window)
902 GHashTable *new_grabbed_keys, *old_grabbed_keys;
903 GtkPlug *plug = GTK_PLUG (window);
905 new_grabbed_keys = g_hash_table_new_full (grabbed_key_hash, grabbed_key_equal, (GDestroyNotify)grabbed_key_free, NULL);
906 _gtk_window_keys_foreach (window, keys_foreach, new_grabbed_keys);
908 if (plug->socket_window)
909 g_hash_table_foreach (new_grabbed_keys, add_grabbed_key, plug);
911 old_grabbed_keys = plug->grabbed_keys;
912 plug->grabbed_keys = new_grabbed_keys;
914 if (old_grabbed_keys)
916 if (plug->socket_window)
917 g_hash_table_foreach (old_grabbed_keys, remove_grabbed_key, plug);
918 g_hash_table_destroy (old_grabbed_keys);
923 gtk_plug_focus (GtkWidget *widget,
924 GtkDirectionType direction)
926 GtkBin *bin = GTK_BIN (widget);
927 GtkPlug *plug = GTK_PLUG (widget);
928 GtkWindow *window = GTK_WINDOW (widget);
929 GtkContainer *container = GTK_CONTAINER (widget);
930 GtkWidget *old_focus_child = container->focus_child;
933 /* We override GtkWindow's behavior, since we don't want wrapping here.
937 if (gtk_widget_child_focus (old_focus_child, direction))
940 if (window->focus_widget)
942 /* Wrapped off the end, clear the focus setting for the toplevel */
943 parent = window->focus_widget->parent;
946 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
947 parent = GTK_WIDGET (parent)->parent;
950 gtk_window_set_focus (GTK_WINDOW (container), NULL);
955 /* Try to focus the first widget in the window */
956 if (bin->child && gtk_widget_child_focus (bin->child, direction))
960 if (!GTK_CONTAINER (window)->focus_child)
961 _gtk_plug_windowing_focus_to_parent (plug, direction);
967 gtk_plug_check_resize (GtkContainer *container)
969 if (gtk_widget_is_toplevel (GTK_WIDGET (container)))
970 GTK_CONTAINER_CLASS (gtk_plug_parent_class)->check_resize (container);
972 GTK_CONTAINER_CLASS (bin_class)->check_resize (container);
976 * _gtk_plug_handle_modality_on:
980 * Called from the GtkPlug backend when the corresponding socket has
981 * told the plug that it modality has toggled on.
984 _gtk_plug_handle_modality_on (GtkPlug *plug)
986 if (!plug->modality_window)
988 plug->modality_window = gtk_window_new (GTK_WINDOW_POPUP);
989 gtk_window_set_screen (GTK_WINDOW (plug->modality_window),
990 gtk_widget_get_screen (GTK_WIDGET (plug)));
991 gtk_widget_realize (plug->modality_window);
992 gtk_window_group_add_window (plug->modality_group, GTK_WINDOW (plug->modality_window));
993 gtk_grab_add (plug->modality_window);
998 * _gtk_plug_handle_modality_off:
1002 * Called from the GtkPlug backend when the corresponding socket has
1003 * told the plug that it modality has toggled off.
1006 _gtk_plug_handle_modality_off (GtkPlug *plug)
1008 if (plug->modality_window)
1010 gtk_widget_destroy (plug->modality_window);
1011 plug->modality_window = NULL;
1016 * _gtk_plug_focus_first_last:
1019 * @direction: a direction
1021 * Called from the GtkPlug backend when the corresponding socket has
1022 * told the plug that it has received the focus.
1025 _gtk_plug_focus_first_last (GtkPlug *plug,
1026 GtkDirectionType direction)
1028 GtkWindow *window = GTK_WINDOW (plug);
1031 if (window->focus_widget)
1033 parent = window->focus_widget->parent;
1036 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
1037 parent = GTK_WIDGET (parent)->parent;
1040 gtk_window_set_focus (GTK_WINDOW (plug), NULL);
1043 gtk_widget_child_focus (GTK_WIDGET (plug), direction);
1046 #define __GTK_PLUG_C__
1047 #include "gtkaliasdef.c"