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;
81 static guint plug_signals[LAST_SIGNAL] = { 0 };
83 G_DEFINE_TYPE (GtkPlug, gtk_plug, GTK_TYPE_WINDOW)
86 gtk_plug_get_property (GObject *object,
91 GtkPlug *plug = GTK_PLUG (object);
96 g_value_set_boolean (value, plug->socket_window != NULL);
99 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
105 gtk_plug_class_init (GtkPlugClass *class)
107 GObjectClass *gobject_class = (GObjectClass *)class;
108 GtkWidgetClass *widget_class = (GtkWidgetClass *)class;
109 GtkWindowClass *window_class = (GtkWindowClass *)class;
110 GtkContainerClass *container_class = (GtkContainerClass *)class;
112 bin_class = g_type_class_peek (GTK_TYPE_BIN);
114 gobject_class->get_property = gtk_plug_get_property;
115 gobject_class->finalize = gtk_plug_finalize;
117 widget_class->realize = gtk_plug_realize;
118 widget_class->unrealize = gtk_plug_unrealize;
119 widget_class->key_press_event = gtk_plug_key_press_event;
120 widget_class->focus_in_event = gtk_plug_focus_event;
121 widget_class->focus_out_event = gtk_plug_focus_event;
123 widget_class->show = gtk_plug_show;
124 widget_class->hide = gtk_plug_hide;
125 widget_class->map = gtk_plug_map;
126 widget_class->unmap = gtk_plug_unmap;
127 widget_class->size_allocate = gtk_plug_size_allocate;
129 widget_class->focus = gtk_plug_focus;
131 container_class->check_resize = gtk_plug_check_resize;
133 window_class->set_focus = gtk_plug_set_focus;
134 window_class->keys_changed = gtk_plug_keys_changed;
139 * %TRUE if the plug is embedded in a socket.
143 g_object_class_install_property (gobject_class,
145 g_param_spec_boolean ("embedded",
147 P_("Whether or not the plug is embedded"),
149 GTK_PARAM_READABLE));
151 plug_signals[EMBEDDED] =
152 g_signal_new (I_("embedded"),
153 G_OBJECT_CLASS_TYPE (class),
155 G_STRUCT_OFFSET (GtkPlugClass, embedded),
157 _gtk_marshal_VOID__VOID,
162 gtk_plug_init (GtkPlug *plug)
166 window = GTK_WINDOW (plug);
168 window->type = GTK_WINDOW_TOPLEVEL;
172 gtk_plug_set_is_child (GtkPlug *plug,
175 g_assert (!GTK_WIDGET (plug)->parent);
179 if (plug->modality_window)
180 _gtk_plug_handle_modality_off (plug);
182 if (plug->modality_group)
184 gtk_window_group_remove_window (plug->modality_group, GTK_WINDOW (plug));
185 g_object_unref (plug->modality_group);
186 plug->modality_group = NULL;
189 /* As a toplevel, the MAPPED flag doesn't correspond
190 * to whether the widget->window is mapped; we unmap
191 * here, but don't bother remapping -- we will get mapped
192 * by gtk_widget_set_parent ().
194 if (GTK_WIDGET_MAPPED (plug))
195 gtk_widget_unmap (GTK_WIDGET (plug));
197 GTK_WIDGET_UNSET_FLAGS (plug, GTK_TOPLEVEL);
198 gtk_container_set_resize_mode (GTK_CONTAINER (plug), GTK_RESIZE_PARENT);
200 _gtk_widget_propagate_hierarchy_changed (GTK_WIDGET (plug), GTK_WIDGET (plug));
204 if (GTK_WINDOW (plug)->focus_widget)
205 gtk_window_set_focus (GTK_WINDOW (plug), NULL);
206 if (GTK_WINDOW (plug)->default_widget)
207 gtk_window_set_default (GTK_WINDOW (plug), NULL);
209 plug->modality_group = gtk_window_group_new ();
210 gtk_window_group_add_window (plug->modality_group, GTK_WINDOW (plug));
212 GTK_WIDGET_SET_FLAGS (plug, GTK_TOPLEVEL);
213 gtk_container_set_resize_mode (GTK_CONTAINER (plug), GTK_RESIZE_QUEUE);
215 _gtk_widget_propagate_hierarchy_changed (GTK_WIDGET (plug), NULL);
223 * Gets the window ID of a #GtkPlug widget, which can then
224 * be used to embed this window inside another window, for
225 * instance with gtk_socket_add_id().
227 * Return value: the window ID for the plug
230 gtk_plug_get_id (GtkPlug *plug)
232 g_return_val_if_fail (GTK_IS_PLUG (plug), 0);
234 if (!GTK_WIDGET_REALIZED (plug))
235 gtk_widget_realize (GTK_WIDGET (plug));
237 return _gtk_plug_windowing_get_id (plug);
241 * _gtk_plug_add_to_socket:
243 * @socket_: a #GtkSocket
245 * Adds a plug to a socket within the same application.
248 _gtk_plug_add_to_socket (GtkPlug *plug,
254 g_return_if_fail (GTK_IS_PLUG (plug));
255 g_return_if_fail (GTK_IS_SOCKET (socket_));
256 g_return_if_fail (GTK_WIDGET_REALIZED (socket_));
258 widget = GTK_WIDGET (plug);
260 gtk_plug_set_is_child (plug, TRUE);
261 plug->same_app = TRUE;
262 socket_->same_app = TRUE;
263 socket_->plug_widget = widget;
265 plug->socket_window = GTK_WIDGET (socket_)->window;
267 if (GTK_WIDGET_REALIZED (widget))
269 gdk_drawable_get_size (GDK_DRAWABLE (widget->window), &w, &h);
270 gdk_window_reparent (widget->window, plug->socket_window, -w, -h);
273 gtk_widget_set_parent (widget, GTK_WIDGET (socket_));
275 g_signal_emit_by_name (socket_, "plug_added");
279 * _gtk_plug_send_delete_event:
280 * @widget: a #GtkWidget
282 * Send a GDK_DELETE event to the @widget and destroy it if
283 * necessary. Internal GTK function, called from this file or the
284 * backend-specific GtkPlug implementation.
287 _gtk_plug_send_delete_event (GtkWidget *widget)
289 GdkEvent *event = gdk_event_new (GDK_DELETE);
291 event->any.window = g_object_ref (widget->window);
292 event->any.send_event = FALSE;
294 gtk_widget_ref (widget);
296 if (!gtk_widget_event (widget, event))
297 gtk_widget_destroy (widget);
299 gtk_widget_unref (widget);
301 gdk_event_free (event);
305 * _gtk_plug_remove_from_socket:
307 * @socket_: a #GtkSocket
309 * Removes a plug from a socket within the same application.
312 _gtk_plug_remove_from_socket (GtkPlug *plug,
317 gboolean widget_was_visible;
319 g_return_if_fail (GTK_IS_PLUG (plug));
320 g_return_if_fail (GTK_IS_SOCKET (socket_));
321 g_return_if_fail (GTK_WIDGET_REALIZED (plug));
323 widget = GTK_WIDGET (plug);
325 if (GTK_WIDGET_IN_REPARENT (widget))
329 g_object_ref (socket_);
331 widget_was_visible = GTK_WIDGET_VISIBLE (plug);
333 gdk_window_hide (widget->window);
334 GTK_PRIVATE_SET_FLAG (plug, GTK_IN_REPARENT);
335 gdk_window_reparent (widget->window,
336 gtk_widget_get_root_window (widget),
338 gtk_widget_unparent (GTK_WIDGET (plug));
339 GTK_PRIVATE_UNSET_FLAG (plug, GTK_IN_REPARENT);
341 socket_->plug_widget = NULL;
342 if (socket_->plug_window != NULL)
344 g_object_unref (socket_->plug_window);
345 socket_->plug_window = NULL;
348 socket_->same_app = FALSE;
350 plug->same_app = FALSE;
351 plug->socket_window = NULL;
353 gtk_plug_set_is_child (plug, FALSE);
355 g_signal_emit_by_name (socket_, "plug_removed", &result);
357 gtk_widget_destroy (GTK_WIDGET (socket_));
360 _gtk_plug_send_delete_event (widget);
362 g_object_unref (plug);
364 if (widget_was_visible && GTK_WIDGET_VISIBLE (socket_))
365 gtk_widget_queue_resize (GTK_WIDGET (socket_));
367 g_object_unref (socket_);
371 * gtk_plug_construct:
373 * @socket_id: the XID of the socket's window.
375 * Finish the initialization of @plug for a given #GtkSocket identified by
376 * @socket_id. This function will generally only be used by classes deriving from #GtkPlug.
379 gtk_plug_construct (GtkPlug *plug,
380 GdkNativeWindow socket_id)
382 gtk_plug_construct_for_display (plug, gdk_display_get_default (), socket_id);
386 * gtk_plug_construct_for_display:
388 * @display: the #GdkDisplay associated with @socket_id's
390 * @socket_id: the XID of the socket's window.
392 * Finish the initialization of @plug for a given #GtkSocket identified by
393 * @socket_id which is currently displayed on @display.
394 * This function will generally only be used by classes deriving from #GtkPlug.
399 gtk_plug_construct_for_display (GtkPlug *plug,
401 GdkNativeWindow socket_id)
405 gpointer user_data = NULL;
407 plug->socket_window = gdk_window_lookup_for_display (display, socket_id);
409 if (plug->socket_window)
410 gdk_window_get_user_data (plug->socket_window, &user_data);
412 plug->socket_window = gdk_window_foreign_new_for_display (display, socket_id);
416 if (GTK_IS_SOCKET (user_data))
417 _gtk_plug_add_to_socket (plug, user_data);
420 g_warning (G_STRLOC "Can't create GtkPlug as child of non-GtkSocket");
421 plug->socket_window = NULL;
425 if (plug->socket_window) {
426 g_signal_emit (plug, plug_signals[EMBEDDED], 0);
428 g_object_notify (G_OBJECT (plug), "embedded");
435 * @socket_id: the window ID of the socket, or 0.
437 * Creates a new plug widget inside the #GtkSocket identified
438 * by @socket_id. If @socket_id is 0, the plug is left "unplugged" and
439 * can later be plugged into a #GtkSocket by gtk_socket_add_id().
441 * Return value: the new #GtkPlug widget.
444 gtk_plug_new (GdkNativeWindow socket_id)
446 return gtk_plug_new_for_display (gdk_display_get_default (), socket_id);
450 * gtk_plug_new_for_display:
451 * @display : the #GdkDisplay on which @socket_id is displayed
452 * @socket_id: the XID of the socket's window.
454 * Create a new plug widget inside the #GtkSocket identified by socket_id.
456 * Return value: the new #GtkPlug widget.
461 gtk_plug_new_for_display (GdkDisplay *display,
462 GdkNativeWindow socket_id)
466 plug = g_object_new (GTK_TYPE_PLUG, NULL);
467 gtk_plug_construct_for_display (plug, display, socket_id);
468 return GTK_WIDGET (plug);
472 gtk_plug_finalize (GObject *object)
474 GtkPlug *plug = GTK_PLUG (object);
476 if (plug->grabbed_keys)
478 g_hash_table_destroy (plug->grabbed_keys);
479 plug->grabbed_keys = NULL;
482 G_OBJECT_CLASS (gtk_plug_parent_class)->finalize (object);
486 gtk_plug_unrealize (GtkWidget *widget)
490 g_return_if_fail (GTK_IS_PLUG (widget));
492 plug = GTK_PLUG (widget);
494 if (plug->socket_window != NULL)
496 gdk_window_set_user_data (plug->socket_window, NULL);
497 g_object_unref (plug->socket_window);
498 plug->socket_window = NULL;
500 g_object_notify (G_OBJECT (widget), "embedded");
505 if (plug->modality_window)
506 _gtk_plug_handle_modality_off (plug);
508 gtk_window_group_remove_window (plug->modality_group, GTK_WINDOW (plug));
509 g_object_unref (plug->modality_group);
512 if (GTK_WIDGET_CLASS (gtk_plug_parent_class)->unrealize)
513 (* GTK_WIDGET_CLASS (gtk_plug_parent_class)->unrealize) (widget);
517 gtk_plug_realize (GtkWidget *widget)
521 GdkWindowAttr attributes;
522 gint attributes_mask;
524 g_return_if_fail (GTK_IS_PLUG (widget));
526 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
527 window = GTK_WINDOW (widget);
528 plug = GTK_PLUG (widget);
530 attributes.window_type = GDK_WINDOW_CHILD; /* XXX GDK_WINDOW_PLUG ? */
531 attributes.title = window->title;
532 attributes.wmclass_name = window->wmclass_name;
533 attributes.wmclass_class = window->wmclass_class;
534 attributes.width = widget->allocation.width;
535 attributes.height = widget->allocation.height;
536 attributes.wclass = GDK_INPUT_OUTPUT;
538 /* this isn't right - we should match our parent's visual/colormap.
539 * though that will require handling "foreign" colormaps */
540 attributes.visual = gtk_widget_get_visual (widget);
541 attributes.colormap = gtk_widget_get_colormap (widget);
542 attributes.event_mask = gtk_widget_get_events (widget);
543 attributes.event_mask |= (GDK_EXPOSURE_MASK |
545 GDK_KEY_RELEASE_MASK |
546 GDK_ENTER_NOTIFY_MASK |
547 GDK_LEAVE_NOTIFY_MASK |
550 attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
551 attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
552 attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
554 if (GTK_WIDGET_TOPLEVEL (widget))
556 attributes.window_type = GDK_WINDOW_TOPLEVEL;
558 gdk_error_trap_push ();
559 if (plug->socket_window)
560 widget->window = gdk_window_new (plug->socket_window,
561 &attributes, attributes_mask);
562 else /* If it's a passive plug, we use the root window */
563 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
564 &attributes, attributes_mask);
566 gdk_display_sync (gtk_widget_get_display (widget));
567 if (gdk_error_trap_pop ()) /* Uh-oh */
569 gdk_error_trap_push ();
570 gdk_window_destroy (widget->window);
572 gdk_error_trap_pop ();
573 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
574 &attributes, attributes_mask);
577 gdk_window_add_filter (widget->window,
578 _gtk_plug_windowing_filter_func,
581 plug->modality_group = gtk_window_group_new ();
582 gtk_window_group_add_window (plug->modality_group, window);
584 _gtk_plug_windowing_realize_toplevel (plug);
587 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
588 &attributes, attributes_mask);
590 gdk_window_set_user_data (widget->window, window);
592 widget->style = gtk_style_attach (widget->style, widget->window);
593 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
595 gdk_window_enable_synchronized_configure (widget->window);
599 gtk_plug_show (GtkWidget *widget)
601 if (GTK_WIDGET_TOPLEVEL (widget))
602 GTK_WIDGET_CLASS (gtk_plug_parent_class)->show (widget);
604 GTK_WIDGET_CLASS (bin_class)->show (widget);
608 gtk_plug_hide (GtkWidget *widget)
610 if (GTK_WIDGET_TOPLEVEL (widget))
611 GTK_WIDGET_CLASS (gtk_plug_parent_class)->hide (widget);
613 GTK_WIDGET_CLASS (bin_class)->hide (widget);
616 /* From gdkinternals.h */
617 void gdk_synthesize_window_state (GdkWindow *window,
618 GdkWindowState unset_flags,
619 GdkWindowState set_flags);
622 gtk_plug_map (GtkWidget *widget)
624 if (GTK_WIDGET_TOPLEVEL (widget))
626 GtkBin *bin = GTK_BIN (widget);
627 GtkPlug *plug = GTK_PLUG (widget);
629 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
632 GTK_WIDGET_VISIBLE (bin->child) &&
633 !GTK_WIDGET_MAPPED (bin->child))
634 gtk_widget_map (bin->child);
636 _gtk_plug_windowing_map_toplevel (plug);
638 gdk_synthesize_window_state (widget->window,
639 GDK_WINDOW_STATE_WITHDRAWN,
643 GTK_WIDGET_CLASS (bin_class)->map (widget);
647 gtk_plug_unmap (GtkWidget *widget)
649 if (GTK_WIDGET_TOPLEVEL (widget))
651 GtkPlug *plug = GTK_PLUG (widget);
653 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
655 gdk_window_hide (widget->window);
657 _gtk_plug_windowing_unmap_toplevel (plug);
659 gdk_synthesize_window_state (widget->window,
661 GDK_WINDOW_STATE_WITHDRAWN);
664 GTK_WIDGET_CLASS (bin_class)->unmap (widget);
668 gtk_plug_size_allocate (GtkWidget *widget,
669 GtkAllocation *allocation)
671 if (GTK_WIDGET_TOPLEVEL (widget))
672 GTK_WIDGET_CLASS (gtk_plug_parent_class)->size_allocate (widget, allocation);
675 GtkBin *bin = GTK_BIN (widget);
677 widget->allocation = *allocation;
679 if (GTK_WIDGET_REALIZED (widget))
680 gdk_window_move_resize (widget->window,
681 allocation->x, allocation->y,
682 allocation->width, allocation->height);
684 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
686 GtkAllocation child_allocation;
688 child_allocation.x = child_allocation.y = GTK_CONTAINER (widget)->border_width;
689 child_allocation.width =
690 MAX (1, (gint)allocation->width - child_allocation.x * 2);
691 child_allocation.height =
692 MAX (1, (gint)allocation->height - child_allocation.y * 2);
694 gtk_widget_size_allocate (bin->child, &child_allocation);
701 gtk_plug_key_press_event (GtkWidget *widget,
704 if (GTK_WIDGET_TOPLEVEL (widget))
705 return GTK_WIDGET_CLASS (gtk_plug_parent_class)->key_press_event (widget, event);
711 gtk_plug_focus_event (GtkWidget *widget,
712 GdkEventFocus *event)
714 /* We eat focus-in events and focus-out events, since they
715 * can be generated by something like a keyboard grab on
716 * a child of the plug.
722 gtk_plug_set_focus (GtkWindow *window,
725 GtkPlug *plug = GTK_PLUG (window);
727 GTK_WINDOW_CLASS (gtk_plug_parent_class)->set_focus (window, focus);
729 /* Ask for focus from embedder
732 if (focus && !window->has_toplevel_focus)
733 _gtk_plug_windowing_set_focus (plug);
737 grabbed_key_hash (gconstpointer a)
739 const GrabbedKey *key = a;
742 h = key->accelerator_key << 16;
743 h ^= key->accelerator_key >> 16;
744 h ^= key->accelerator_mods;
750 grabbed_key_equal (gconstpointer a, gconstpointer b)
752 const GrabbedKey *keya = a;
753 const GrabbedKey *keyb = b;
755 return (keya->accelerator_key == keyb->accelerator_key &&
756 keya->accelerator_mods == keyb->accelerator_mods);
760 add_grabbed_key (gpointer key, gpointer val, gpointer data)
762 GrabbedKey *grabbed_key = key;
763 GtkPlug *plug = data;
765 if (!plug->grabbed_keys ||
766 !g_hash_table_lookup (plug->grabbed_keys, grabbed_key))
768 _gtk_plug_windowing_add_grabbed_key (plug,
769 grabbed_key->accelerator_key,
770 grabbed_key->accelerator_mods);
775 add_grabbed_key_always (gpointer key,
779 GrabbedKey *grabbed_key = key;
780 GtkPlug *plug = data;
782 _gtk_plug_windowing_add_grabbed_key (plug,
783 grabbed_key->accelerator_key,
784 grabbed_key->accelerator_mods);
788 * _gtk_plug_add_all_grabbed_keys:
792 * Calls _gtk_plug_windowing_add_grabbed_key() on all the grabbed keys
796 _gtk_plug_add_all_grabbed_keys (GtkPlug *plug)
798 if (plug->grabbed_keys)
799 g_hash_table_foreach (plug->grabbed_keys, add_grabbed_key_always, plug);
803 remove_grabbed_key (gpointer key, gpointer val, gpointer data)
805 GrabbedKey *grabbed_key = key;
806 GtkPlug *plug = data;
808 if (!plug->grabbed_keys ||
809 !g_hash_table_lookup (plug->grabbed_keys, grabbed_key))
811 _gtk_plug_windowing_remove_grabbed_key (plug,
812 grabbed_key->accelerator_key,
813 grabbed_key->accelerator_mods);
818 keys_foreach (GtkWindow *window,
820 GdkModifierType modifiers,
821 gboolean is_mnemonic,
824 GHashTable *new_grabbed_keys = data;
825 GrabbedKey *key = g_slice_new (GrabbedKey);
827 key->accelerator_key = keyval;
828 key->accelerator_mods = modifiers;
830 g_hash_table_replace (new_grabbed_keys, key, key);
834 grabbed_key_free (gpointer data)
836 g_slice_free (GrabbedKey, data);
840 gtk_plug_keys_changed (GtkWindow *window)
842 GHashTable *new_grabbed_keys, *old_grabbed_keys;
843 GtkPlug *plug = GTK_PLUG (window);
845 new_grabbed_keys = g_hash_table_new_full (grabbed_key_hash, grabbed_key_equal, (GDestroyNotify)grabbed_key_free, NULL);
846 _gtk_window_keys_foreach (window, keys_foreach, new_grabbed_keys);
848 if (plug->socket_window)
849 g_hash_table_foreach (new_grabbed_keys, add_grabbed_key, plug);
851 old_grabbed_keys = plug->grabbed_keys;
852 plug->grabbed_keys = new_grabbed_keys;
854 if (old_grabbed_keys)
856 if (plug->socket_window)
857 g_hash_table_foreach (old_grabbed_keys, remove_grabbed_key, plug);
858 g_hash_table_destroy (old_grabbed_keys);
863 gtk_plug_focus (GtkWidget *widget,
864 GtkDirectionType direction)
866 GtkBin *bin = GTK_BIN (widget);
867 GtkPlug *plug = GTK_PLUG (widget);
868 GtkWindow *window = GTK_WINDOW (widget);
869 GtkContainer *container = GTK_CONTAINER (widget);
870 GtkWidget *old_focus_child = container->focus_child;
873 /* We override GtkWindow's behavior, since we don't want wrapping here.
877 if (gtk_widget_child_focus (old_focus_child, direction))
880 if (window->focus_widget)
882 /* Wrapped off the end, clear the focus setting for the toplevel */
883 parent = window->focus_widget->parent;
886 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
887 parent = GTK_WIDGET (parent)->parent;
890 gtk_window_set_focus (GTK_WINDOW (container), NULL);
895 /* Try to focus the first widget in the window */
896 if (bin->child && gtk_widget_child_focus (bin->child, direction))
900 if (!GTK_CONTAINER (window)->focus_child)
901 _gtk_plug_windowing_focus_to_parent (plug, direction);
907 gtk_plug_check_resize (GtkContainer *container)
909 if (GTK_WIDGET_TOPLEVEL (container))
910 GTK_CONTAINER_CLASS (gtk_plug_parent_class)->check_resize (container);
912 GTK_CONTAINER_CLASS (bin_class)->check_resize (container);
916 * _gtk_plug_handle_modality_on:
920 * Called from the GtkPlug backend when the corresponding socket has
921 * told the plug that it modality has toggled on.
924 _gtk_plug_handle_modality_on (GtkPlug *plug)
926 if (!plug->modality_window)
928 plug->modality_window = gtk_window_new (GTK_WINDOW_POPUP);
929 gtk_window_set_screen (GTK_WINDOW (plug->modality_window),
930 gtk_widget_get_screen (GTK_WIDGET (plug)));
931 gtk_widget_realize (plug->modality_window);
932 gtk_window_group_add_window (plug->modality_group, GTK_WINDOW (plug->modality_window));
933 gtk_grab_add (plug->modality_window);
938 * _gtk_plug_handle_modality_off:
942 * Called from the GtkPlug backend when the corresponding socket has
943 * told the plug that it modality has toggled off.
946 _gtk_plug_handle_modality_off (GtkPlug *plug)
948 if (plug->modality_window)
950 gtk_widget_destroy (plug->modality_window);
951 plug->modality_window = NULL;
956 * _gtk_plug_focus_first_last:
959 * @direction: a direction
961 * Called from the GtkPlug backend when the corresponding socket has
962 * told the plug that it has received the focus.
965 _gtk_plug_focus_first_last (GtkPlug *plug,
966 GtkDirectionType direction)
968 GtkWindow *window = GTK_WINDOW (plug);
971 if (window->focus_widget)
973 parent = window->focus_widget->parent;
976 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
977 parent = GTK_WIDGET (parent)->parent;
980 gtk_window_set_focus (GTK_WINDOW (plug), NULL);
983 gtk_widget_child_focus (GTK_WIDGET (plug), direction);
986 #define __GTK_PLUG_C__
987 #include "gtkaliasdef.c"