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/.
29 #include "gtkmarshalers.h"
31 #include "gtkprivate.h"
32 #include "gtkplugprivate.h"
36 static void gtk_plug_class_init (GtkPlugClass *klass);
37 static void gtk_plug_init (GtkPlug *plug);
38 static void gtk_plug_finalize (GObject *object);
39 static void gtk_plug_realize (GtkWidget *widget);
40 static void gtk_plug_unrealize (GtkWidget *widget);
41 static void gtk_plug_show (GtkWidget *widget);
42 static void gtk_plug_hide (GtkWidget *widget);
43 static void gtk_plug_map (GtkWidget *widget);
44 static void gtk_plug_unmap (GtkWidget *widget);
45 static void gtk_plug_size_allocate (GtkWidget *widget,
46 GtkAllocation *allocation);
47 static gboolean gtk_plug_key_press_event (GtkWidget *widget,
49 static gboolean gtk_plug_focus_event (GtkWidget *widget,
50 GdkEventFocus *event);
51 static void gtk_plug_set_focus (GtkWindow *window,
53 static gboolean gtk_plug_focus (GtkWidget *widget,
54 GtkDirectionType direction);
55 static void gtk_plug_check_resize (GtkContainer *container);
56 static void gtk_plug_keys_changed (GtkWindow *window);
58 static GtkWindowClass *parent_class = NULL;
59 static GtkBinClass *bin_class = NULL;
63 guint accelerator_key;
64 GdkModifierType accelerator_mods;
72 static guint plug_signals[LAST_SIGNAL] = { 0 };
75 gtk_plug_get_type (void)
77 static GType plug_type = 0;
81 static const GTypeInfo plug_info =
83 sizeof (GtkPlugClass),
85 NULL, /* base_finalize */
86 (GClassInitFunc) gtk_plug_class_init,
87 NULL, /* class_finalize */
88 NULL, /* class_data */
91 (GInstanceInitFunc) gtk_plug_init,
94 plug_type = g_type_register_static (GTK_TYPE_WINDOW, "GtkPlug",
102 gtk_plug_class_init (GtkPlugClass *class)
104 GObjectClass *gobject_class = (GObjectClass *)class;
105 GtkWidgetClass *widget_class = (GtkWidgetClass *)class;
106 GtkWindowClass *window_class = (GtkWindowClass *)class;
107 GtkContainerClass *container_class = (GtkContainerClass *)class;
109 parent_class = g_type_class_peek_parent (class);
110 bin_class = g_type_class_peek (GTK_TYPE_BIN);
112 gobject_class->finalize = gtk_plug_finalize;
114 widget_class->realize = gtk_plug_realize;
115 widget_class->unrealize = gtk_plug_unrealize;
116 widget_class->key_press_event = gtk_plug_key_press_event;
117 widget_class->focus_in_event = gtk_plug_focus_event;
118 widget_class->focus_out_event = gtk_plug_focus_event;
120 widget_class->show = gtk_plug_show;
121 widget_class->hide = gtk_plug_hide;
122 widget_class->map = gtk_plug_map;
123 widget_class->unmap = gtk_plug_unmap;
124 widget_class->size_allocate = gtk_plug_size_allocate;
126 widget_class->focus = gtk_plug_focus;
128 container_class->check_resize = gtk_plug_check_resize;
130 window_class->set_focus = gtk_plug_set_focus;
131 window_class->keys_changed = gtk_plug_keys_changed;
133 plug_signals[EMBEDDED] =
134 g_signal_new ("embedded",
135 G_OBJECT_CLASS_TYPE (class),
137 G_STRUCT_OFFSET (GtkPlugClass, embedded),
139 _gtk_marshal_VOID__VOID,
144 gtk_plug_init (GtkPlug *plug)
148 window = GTK_WINDOW (plug);
150 window->type = GTK_WINDOW_TOPLEVEL;
154 gtk_plug_set_is_child (GtkPlug *plug,
157 g_assert (!GTK_WIDGET (plug)->parent);
161 if (plug->modality_window)
162 _gtk_plug_handle_modality_off (plug);
164 if (plug->modality_group)
166 gtk_window_group_remove_window (plug->modality_group, GTK_WINDOW (plug));
167 g_object_unref (plug->modality_group);
168 plug->modality_group = NULL;
171 /* As a toplevel, the MAPPED flag doesn't correspond
172 * to whether the widget->window is mapped; we unmap
173 * here, but don't bother remapping -- we will get mapped
174 * by gtk_widget_set_parent ().
176 if (GTK_WIDGET_MAPPED (plug))
177 gtk_widget_unmap (GTK_WIDGET (plug));
179 GTK_WIDGET_UNSET_FLAGS (plug, GTK_TOPLEVEL);
180 gtk_container_set_resize_mode (GTK_CONTAINER (plug), GTK_RESIZE_PARENT);
182 _gtk_widget_propagate_hierarchy_changed (GTK_WIDGET (plug), GTK_WIDGET (plug));
186 if (GTK_WINDOW (plug)->focus_widget)
187 gtk_window_set_focus (GTK_WINDOW (plug), NULL);
188 if (GTK_WINDOW (plug)->default_widget)
189 gtk_window_set_default (GTK_WINDOW (plug), NULL);
191 plug->modality_group = gtk_window_group_new ();
192 gtk_window_group_add_window (plug->modality_group, GTK_WINDOW (plug));
194 GTK_WIDGET_SET_FLAGS (plug, GTK_TOPLEVEL);
195 gtk_container_set_resize_mode (GTK_CONTAINER (plug), GTK_RESIZE_QUEUE);
197 _gtk_widget_propagate_hierarchy_changed (GTK_WIDGET (plug), NULL);
205 * Gets the window ID of a #GtkPlug widget, which can then
206 * be used to embed this window inside another window, for
207 * instance with gtk_socket_add_id().
209 * Return value: the window ID for the plug
212 gtk_plug_get_id (GtkPlug *plug)
214 g_return_val_if_fail (GTK_IS_PLUG (plug), 0);
216 if (!GTK_WIDGET_REALIZED (plug))
217 gtk_widget_realize (GTK_WIDGET (plug));
219 return _gtk_plug_windowing_get_id (plug);
223 * _gtk_plug_add_to_socket:
225 * @socket_: a #GtkSocket
227 * Adds a plug to a socket within the same application.
230 _gtk_plug_add_to_socket (GtkPlug *plug,
236 g_return_if_fail (GTK_IS_PLUG (plug));
237 g_return_if_fail (GTK_IS_SOCKET (socket));
238 g_return_if_fail (GTK_WIDGET_REALIZED (socket));
240 widget = GTK_WIDGET (plug);
242 gtk_plug_set_is_child (plug, TRUE);
243 plug->same_app = TRUE;
244 socket->same_app = TRUE;
245 socket->plug_widget = widget;
247 plug->socket_window = GTK_WIDGET (socket)->window;
249 if (GTK_WIDGET_REALIZED (widget))
251 gdk_drawable_get_size (GDK_DRAWABLE (widget->window), &w, &h);
252 gdk_window_reparent (widget->window, plug->socket_window, -w, -h);
255 gtk_widget_set_parent (widget, GTK_WIDGET (socket));
257 g_signal_emit_by_name (socket, "plug_added", 0);
261 * _gtk_plug_send_delete_event:
262 * widget: a #GtkWidget
264 * Send a GDK_DELETE event to the @widget and destroy it if
265 * necessary. Internal GTK function, called from this file or the
266 * backend-specific GtkPlug implementation.
269 _gtk_plug_send_delete_event (GtkWidget *widget)
271 GdkEvent *event = gdk_event_new (GDK_DELETE);
273 event->any.window = g_object_ref (widget->window);
274 event->any.send_event = FALSE;
276 gtk_widget_ref (widget);
278 if (!gtk_widget_event (widget, event))
279 gtk_widget_destroy (widget);
281 gtk_widget_unref (widget);
283 gdk_event_free (event);
287 * _gtk_plug_remove_from_socket:
289 * @socket: a #GtkSocket
291 * Removes a plug from a socket within the same application.
294 _gtk_plug_remove_from_socket (GtkPlug *plug,
299 gboolean widget_was_visible;
301 g_return_if_fail (GTK_IS_PLUG (plug));
302 g_return_if_fail (GTK_IS_SOCKET (socket));
303 g_return_if_fail (GTK_WIDGET_REALIZED (plug));
305 widget = GTK_WIDGET (plug);
307 if (GTK_WIDGET_IN_REPARENT (widget))
311 g_object_ref (socket);
313 widget_was_visible = GTK_WIDGET_VISIBLE (plug);
315 gdk_window_hide (widget->window);
316 GTK_PRIVATE_SET_FLAG (plug, GTK_IN_REPARENT);
317 gdk_window_reparent (widget->window,
318 gtk_widget_get_root_window (widget),
320 gtk_widget_unparent (GTK_WIDGET (plug));
321 GTK_PRIVATE_UNSET_FLAG (plug, GTK_IN_REPARENT);
323 socket->plug_widget = NULL;
324 if (socket->plug_window != NULL)
326 g_object_unref (socket->plug_window);
327 socket->plug_window = NULL;
330 socket->same_app = FALSE;
332 plug->same_app = FALSE;
333 plug->socket_window = NULL;
335 gtk_plug_set_is_child (plug, FALSE);
337 g_signal_emit_by_name (socket, "plug_removed", &result);
339 gtk_widget_destroy (GTK_WIDGET (socket));
342 _gtk_plug_send_delete_event (widget);
344 g_object_unref (plug);
346 if (widget_was_visible && GTK_WIDGET_VISIBLE (socket))
347 gtk_widget_queue_resize (GTK_WIDGET (socket));
349 g_object_unref (socket);
353 * gtk_plug_construct:
355 * @socket_id: the XID of the socket's window.
357 * Finish the initialization of @plug for a given #GtkSocket identified by
358 * @socket_id. This function will generally only be used by classes deriving from #GtkPlug.
361 gtk_plug_construct (GtkPlug *plug,
362 GdkNativeWindow socket_id)
364 gtk_plug_construct_for_display (plug, gdk_display_get_default (), socket_id);
368 * gtk_plug_construct_for_display:
370 * @display: the #GdkDisplay associated with @socket_id's
372 * @socket_id: the XID of the socket's window.
374 * Finish the initialization of @plug for a given #GtkSocket identified by
375 * @socket_id which is currently displayed on @display.
376 * This function will generally only be used by classes deriving from #GtkPlug.
381 gtk_plug_construct_for_display (GtkPlug *plug,
383 GdkNativeWindow socket_id)
387 gpointer user_data = NULL;
389 plug->socket_window = gdk_window_lookup_for_display (display, socket_id);
391 if (plug->socket_window)
392 gdk_window_get_user_data (plug->socket_window, &user_data);
394 plug->socket_window = gdk_window_foreign_new_for_display (display, socket_id);
398 if (GTK_IS_SOCKET (user_data))
399 _gtk_plug_add_to_socket (plug, user_data);
402 g_warning (G_STRLOC "Can't create GtkPlug as child of non-GtkSocket");
403 plug->socket_window = NULL;
407 if (plug->socket_window)
408 g_signal_emit (plug, plug_signals[EMBEDDED], 0);
414 * @socket_id: the window ID of the socket, or 0.
416 * Creates a new plug widget inside the #GtkSocket identified
417 * by @socket_id. If @socket_id is 0, the plug is left "unplugged" and
418 * can later be plugged into a #GtkSocket by gtk_socket_add_id().
420 * Return value: the new #GtkPlug widget.
423 gtk_plug_new (GdkNativeWindow socket_id)
425 return gtk_plug_new_for_display (gdk_display_get_default (), socket_id);
429 * gtk_plug_new_for_display:
430 * @display : the #GdkDisplay on which @socket_id is displayed
431 * @socket_id: the XID of the socket's window.
433 * Create a new plug widget inside the #GtkSocket identified by socket_id.
435 * Return value: the new #GtkPlug widget.
440 gtk_plug_new_for_display (GdkDisplay *display,
441 GdkNativeWindow socket_id)
445 plug = g_object_new (GTK_TYPE_PLUG, NULL);
446 gtk_plug_construct_for_display (plug, display, socket_id);
447 return GTK_WIDGET (plug);
451 gtk_plug_finalize (GObject *object)
453 GtkPlug *plug = GTK_PLUG (object);
455 if (plug->grabbed_keys)
457 g_hash_table_destroy (plug->grabbed_keys);
458 plug->grabbed_keys = NULL;
461 G_OBJECT_CLASS (parent_class)->finalize (object);
465 gtk_plug_unrealize (GtkWidget *widget)
469 g_return_if_fail (GTK_IS_PLUG (widget));
471 plug = GTK_PLUG (widget);
473 if (plug->socket_window != NULL)
475 gdk_window_set_user_data (plug->socket_window, NULL);
476 g_object_unref (plug->socket_window);
477 plug->socket_window = NULL;
482 if (plug->modality_window)
483 _gtk_plug_handle_modality_off (plug);
485 gtk_window_group_remove_window (plug->modality_group, GTK_WINDOW (plug));
486 g_object_unref (plug->modality_group);
489 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
490 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
494 gtk_plug_realize (GtkWidget *widget)
498 GdkWindowAttr attributes;
499 gint attributes_mask;
501 g_return_if_fail (GTK_IS_PLUG (widget));
503 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
504 window = GTK_WINDOW (widget);
505 plug = GTK_PLUG (widget);
507 attributes.window_type = GDK_WINDOW_CHILD; /* XXX GDK_WINDOW_PLUG ? */
508 attributes.title = window->title;
509 attributes.wmclass_name = window->wmclass_name;
510 attributes.wmclass_class = window->wmclass_class;
511 attributes.width = widget->allocation.width;
512 attributes.height = widget->allocation.height;
513 attributes.wclass = GDK_INPUT_OUTPUT;
515 /* this isn't right - we should match our parent's visual/colormap.
516 * though that will require handling "foreign" colormaps */
517 attributes.visual = gtk_widget_get_visual (widget);
518 attributes.colormap = gtk_widget_get_colormap (widget);
519 attributes.event_mask = gtk_widget_get_events (widget);
520 attributes.event_mask |= (GDK_EXPOSURE_MASK |
522 GDK_KEY_RELEASE_MASK |
523 GDK_ENTER_NOTIFY_MASK |
524 GDK_LEAVE_NOTIFY_MASK |
527 attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
528 attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
529 attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
531 if (GTK_WIDGET_TOPLEVEL (widget))
533 attributes.window_type = GDK_WINDOW_TOPLEVEL;
535 gdk_error_trap_push ();
536 if (plug->socket_window)
537 widget->window = gdk_window_new (plug->socket_window,
538 &attributes, attributes_mask);
539 else /* If it's a passive plug, we use the root window */
540 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
541 &attributes, attributes_mask);
543 gdk_display_sync (gtk_widget_get_display (widget));
544 if (gdk_error_trap_pop ()) /* Uh-oh */
546 gdk_error_trap_push ();
547 gdk_window_destroy (widget->window);
549 gdk_error_trap_pop ();
550 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
551 &attributes, attributes_mask);
554 gdk_window_add_filter (widget->window,
555 _gtk_plug_windowing_filter_func,
558 plug->modality_group = gtk_window_group_new ();
559 gtk_window_group_add_window (plug->modality_group, window);
561 _gtk_plug_windowing_realize_toplevel (plug);
564 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
565 &attributes, attributes_mask);
567 gdk_window_set_user_data (widget->window, window);
569 widget->style = gtk_style_attach (widget->style, widget->window);
570 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
572 gdk_window_enable_synchronized_configure (widget->window);
576 gtk_plug_show (GtkWidget *widget)
578 if (GTK_WIDGET_TOPLEVEL (widget))
579 GTK_WIDGET_CLASS (parent_class)->show (widget);
581 GTK_WIDGET_CLASS (bin_class)->show (widget);
585 gtk_plug_hide (GtkWidget *widget)
587 if (GTK_WIDGET_TOPLEVEL (widget))
588 GTK_WIDGET_CLASS (parent_class)->hide (widget);
590 GTK_WIDGET_CLASS (bin_class)->hide (widget);
593 /* From gdkinternals.h */
594 void gdk_synthesize_window_state (GdkWindow *window,
595 GdkWindowState unset_flags,
596 GdkWindowState set_flags);
599 gtk_plug_map (GtkWidget *widget)
601 if (GTK_WIDGET_TOPLEVEL (widget))
603 GtkBin *bin = GTK_BIN (widget);
604 GtkPlug *plug = GTK_PLUG (widget);
606 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
609 GTK_WIDGET_VISIBLE (bin->child) &&
610 !GTK_WIDGET_MAPPED (bin->child))
611 gtk_widget_map (bin->child);
613 _gtk_plug_windowing_map_toplevel (plug);
615 gdk_synthesize_window_state (widget->window,
616 GDK_WINDOW_STATE_WITHDRAWN,
620 GTK_WIDGET_CLASS (bin_class)->map (widget);
624 gtk_plug_unmap (GtkWidget *widget)
626 if (GTK_WIDGET_TOPLEVEL (widget))
628 GtkPlug *plug = GTK_PLUG (widget);
630 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
632 gdk_window_hide (widget->window);
634 _gtk_plug_windowing_unmap_toplevel (plug);
636 gdk_synthesize_window_state (widget->window,
638 GDK_WINDOW_STATE_WITHDRAWN);
641 GTK_WIDGET_CLASS (bin_class)->unmap (widget);
645 gtk_plug_size_allocate (GtkWidget *widget,
646 GtkAllocation *allocation)
648 if (GTK_WIDGET_TOPLEVEL (widget))
649 GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
652 GtkBin *bin = GTK_BIN (widget);
654 widget->allocation = *allocation;
656 if (GTK_WIDGET_REALIZED (widget))
657 gdk_window_move_resize (widget->window,
658 allocation->x, allocation->y,
659 allocation->width, allocation->height);
661 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
663 GtkAllocation child_allocation;
665 child_allocation.x = child_allocation.y = GTK_CONTAINER (widget)->border_width;
666 child_allocation.width =
667 MAX (1, (gint)allocation->width - child_allocation.x * 2);
668 child_allocation.height =
669 MAX (1, (gint)allocation->height - child_allocation.y * 2);
671 gtk_widget_size_allocate (bin->child, &child_allocation);
678 gtk_plug_key_press_event (GtkWidget *widget,
681 if (GTK_WIDGET_TOPLEVEL (widget))
682 return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event);
688 gtk_plug_focus_event (GtkWidget *widget,
689 GdkEventFocus *event)
691 /* We eat focus-in events and focus-out events, since they
692 * can be generated by something like a keyboard grab on
693 * a child of the plug.
699 gtk_plug_set_focus (GtkWindow *window,
702 GtkPlug *plug = GTK_PLUG (window);
704 GTK_WINDOW_CLASS (parent_class)->set_focus (window, focus);
706 /* Ask for focus from embedder
709 if (focus && !window->has_toplevel_focus)
710 _gtk_plug_windowing_set_focus (plug);
714 grabbed_key_hash (gconstpointer a)
716 const GrabbedKey *key = a;
719 h = key->accelerator_key << 16;
720 h ^= key->accelerator_key >> 16;
721 h ^= key->accelerator_mods;
727 grabbed_key_equal (gconstpointer a, gconstpointer b)
729 const GrabbedKey *keya = a;
730 const GrabbedKey *keyb = b;
732 return (keya->accelerator_key == keyb->accelerator_key &&
733 keya->accelerator_mods == keyb->accelerator_mods);
737 add_grabbed_key (gpointer key, gpointer val, gpointer data)
739 GrabbedKey *grabbed_key = key;
740 GtkPlug *plug = data;
742 if (!plug->grabbed_keys ||
743 !g_hash_table_lookup (plug->grabbed_keys, grabbed_key))
745 _gtk_plug_windowing_add_grabbed_key (plug,
746 grabbed_key->accelerator_key,
747 grabbed_key->accelerator_mods);
752 add_grabbed_key_always (gpointer key,
756 GrabbedKey *grabbed_key = key;
757 GtkPlug *plug = data;
759 _gtk_plug_windowing_add_grabbed_key (plug,
760 grabbed_key->accelerator_key,
761 grabbed_key->accelerator_mods);
765 * _gtk_plug_add_all_grabbed_keys:
769 * Calls _gtk_plug_windowing_add_grabbed_key() on all the grabbed keys
773 _gtk_plug_add_all_grabbed_keys (GtkPlug *plug)
775 if (plug->grabbed_keys)
776 g_hash_table_foreach (plug->grabbed_keys, add_grabbed_key_always, plug);
780 remove_grabbed_key (gpointer key, gpointer val, gpointer data)
782 GrabbedKey *grabbed_key = key;
783 GtkPlug *plug = data;
785 if (!plug->grabbed_keys ||
786 !g_hash_table_lookup (plug->grabbed_keys, grabbed_key))
788 _gtk_plug_windowing_remove_grabbed_key (plug,
789 grabbed_key->accelerator_key,
790 grabbed_key->accelerator_mods);
795 keys_foreach (GtkWindow *window,
797 GdkModifierType modifiers,
798 gboolean is_mnemonic,
801 GHashTable *new_grabbed_keys = data;
802 GrabbedKey *key = g_new (GrabbedKey, 1);
804 key->accelerator_key = keyval;
805 key->accelerator_mods = modifiers;
807 g_hash_table_replace (new_grabbed_keys, key, key);
811 gtk_plug_keys_changed (GtkWindow *window)
813 GHashTable *new_grabbed_keys, *old_grabbed_keys;
814 GtkPlug *plug = GTK_PLUG (window);
816 new_grabbed_keys = g_hash_table_new_full (grabbed_key_hash, grabbed_key_equal, (GDestroyNotify)g_free, NULL);
817 _gtk_window_keys_foreach (window, keys_foreach, new_grabbed_keys);
819 if (plug->socket_window)
820 g_hash_table_foreach (new_grabbed_keys, add_grabbed_key, plug);
822 old_grabbed_keys = plug->grabbed_keys;
823 plug->grabbed_keys = new_grabbed_keys;
825 if (old_grabbed_keys)
827 if (plug->socket_window)
828 g_hash_table_foreach (old_grabbed_keys, remove_grabbed_key, plug);
829 g_hash_table_destroy (old_grabbed_keys);
834 gtk_plug_focus (GtkWidget *widget,
835 GtkDirectionType direction)
837 GtkBin *bin = GTK_BIN (widget);
838 GtkPlug *plug = GTK_PLUG (widget);
839 GtkWindow *window = GTK_WINDOW (widget);
840 GtkContainer *container = GTK_CONTAINER (widget);
841 GtkWidget *old_focus_child = container->focus_child;
844 /* We override GtkWindow's behavior, since we don't want wrapping here.
848 if (gtk_widget_child_focus (old_focus_child, direction))
851 if (window->focus_widget)
853 /* Wrapped off the end, clear the focus setting for the toplevel */
854 parent = window->focus_widget->parent;
857 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
858 parent = GTK_WIDGET (parent)->parent;
861 gtk_window_set_focus (GTK_WINDOW (container), NULL);
866 /* Try to focus the first widget in the window */
867 if (bin->child && gtk_widget_child_focus (bin->child, direction))
871 if (!GTK_CONTAINER (window)->focus_child)
872 _gtk_plug_windowing_focus_to_parent (plug, direction);
878 gtk_plug_check_resize (GtkContainer *container)
880 if (GTK_WIDGET_TOPLEVEL (container))
881 GTK_CONTAINER_CLASS (parent_class)->check_resize (container);
883 GTK_CONTAINER_CLASS (bin_class)->check_resize (container);
887 * _gtk_plug_handle_modality_on:
891 * Called from the GtkPlug backend when the corresponding socket has
892 * told the plug that it modality has toggled on.
895 _gtk_plug_handle_modality_on (GtkPlug *plug)
897 if (!plug->modality_window)
899 plug->modality_window = gtk_window_new (GTK_WINDOW_POPUP);
900 gtk_window_set_screen (GTK_WINDOW (plug->modality_window),
901 gtk_widget_get_screen (GTK_WIDGET (plug)));
902 gtk_widget_realize (plug->modality_window);
903 gtk_window_group_add_window (plug->modality_group, GTK_WINDOW (plug->modality_window));
904 gtk_grab_add (plug->modality_window);
909 * _gtk_plug_handle_modality_off:
913 * Called from the GtkPlug backend when the corresponding socket has
914 * told the plug that it modality has toggled off.
917 _gtk_plug_handle_modality_off (GtkPlug *plug)
919 if (plug->modality_window)
921 gtk_widget_destroy (plug->modality_window);
922 plug->modality_window = NULL;
927 * _gtk_plug_focus_first_last:
930 * @direction: a direction
932 * Called from the GtkPlug backend when the corresponding socket has
933 * told the plug that it has received the focus.
936 _gtk_plug_focus_first_last (GtkPlug *plug,
937 GtkDirectionType direction)
939 GtkWindow *window = GTK_WINDOW (plug);
942 if (window->focus_widget)
944 parent = window->focus_widget->parent;
947 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
948 parent = GTK_WIDGET (parent)->parent;
951 gtk_window_set_focus (GTK_WINDOW (plug), NULL);
954 gtk_widget_child_focus (GTK_WIDGET (plug), direction);
957 #define __GTK_PLUG_C__
958 #include "gtkaliasdef.c"