gtk2/gtk/gtksocket.c
Havoc Pennington df4fc36721 Make this compile without framebuffer enabled
2000-06-20  Havoc Pennington  <hp@redhat.com>

* modules/linux-fb/Makefile.am: Make this compile
without framebuffer enabled

* gdk/linux-fb/Makefile.am: Add conditional to not build
framebuffer unless specified in configure

* gdk/gdkdraw.c (gdk_draw_drawable): Fix bug where I was getting
the size of the target instead of source if -1 was passed for
width/height

* gdk/x11/gdkgeometry-x11.c (gdk_window_compute_position): Fix
width/height confusion.

2000-06-19  Havoc Pennington  <hp@redhat.com>

* gdk/x11/gdkx.h (GDK_WINDOW_XWINDOW): change this to be
GDK_DRAWABLE_XID. In the future, we probably want to make it
faster with G_DISABLE_CHECKS turned on.

2000-06-14  Havoc Pennington  <hp@redhat.com>

        * gdk/Makefile.am: add gdkpixmap.c

	* gdk/gdk.c: s/gdk_window_init/_gdk_windowing_window_init/
	s/gdk_image_init/_gdk_windowing_image_init

	* gdk/gdkcolor.c: make ref/unref compat wrappers for GObject
	ref/unref

	* gdk/gdkcolor.h: make GdkColormap a GObject subclass

	* gdk/gdkcompat.h: remove GdkWindowType compat, since
	GdkWindowType is now non-deprecated;
	change gdk_window_get_type() compat to be
	gdk_window_get_window_type().

	* gdk/gdkdnd.h: make GdkDragContext a GObject.

	* gdk/gdkdraw.c, gdk/gdkdraw.h: Convert GdkDrawable to a pure
	virtual GObject. Make all functions call into the vtable.
	Move gdk_image_put() guts in here. Remove GdkDrawableType
	and gdk_drawable_get_type(), these are now GdkWindow-specific.
	draw_image, get_depth, get_size, set_colormap, get_colormap,
	get_visual added to the vtable.

	* gdk/gdkgc.h, gdk/gdkgc.c: Convert GdkGC to a pure virtual
	GObject. Virtualize everything.
	(gdk_gc_new_with_values): remove check for destroyed window,
	because now GdkWindow::create_gc will check this.
	(gdk_gc_set_values): New function to set GC values, this
	was already implemented but wasn't in the header

	* gdk/gdkimage.h, gdk/gdkimage.c: Convert GdkImage to a GObject.

	* gdk/gdkinternals.h: Remove _gdk_window_alloc(), remove
	_gdk_window_draw_image(), remove _gdk_windowing_window_class,
	remove _gdk_window_class; add _gdk_window_impl_get_type() and
	_gdk_pixmap_impl_get_type(). Rename gdk_window_init to
	_gdk_windowing_window_init, rename gdk_image_init to
	_gdk_windowing_image_init.

	* gdk/gdkpango.c: Reflect GObject-ification of PangoContext.
	(gdk_draw_layout): Remove check for destroyed window,
	because all the drawable methods already check it.

	* gdk/gdkpixmap.h, gdk/gdkpixmap.c: Convert GdkPixmap to GObject.
	Add gdkpixmap.c which contains implementation of GdkDrawable
	virtual table (by chaining to a platform-specific implementation
	object).

	* gdk/gdkprivate.h: Remove GDK_IS_WINDOW, GDK_IS_PIXMAP,
	GDK_DRAWABLE_DESTROYED. Add GDK_WINDOW_DESTROYED. Replace
	GDK_DRAWABLE_TYPE with GDK_WINDOW_TYPE. Remove GdkDrawablePrivate,
	GdkWindowPrivate, GdkImageClass, GdkImagePrivate, GdkGCPrivate,
	GdkColormapPrivate.

	* gdk/gdktypes.h: #include <glib-object.h>

	* gdk/gdkwindow.h, gdk/gdkwindow.c: Convert GdkWindow to GObject.
	Move most functionality to platform-specific implementation
	object. GdkWindow itself now handles the backing store, then
	chains to the platform-specific implementation.
	(gdk_window_get_window_type): return GdkWindowType of the window.
	(gdk_window_peek_children): New routine, returns the children of
	a GdkWindow
	(gdk_window_get_children): Was in X11-specific code and did
	XQueryTree. Changed to simply return a copy of window->children;
	so it can go in cross-platform code.

	* gdk/x11/Makefile.am: fix broken MKINSTALLDIRS path

	* gdk/x11/gdkcolor-x11.c: implement X-specific parts of
	GdkColormap; just changed to use the new private data instead
	of casting to GdkColormapPrivate.

	* gdk/x11/gdkcursor-x11.c: added a couple typechecks to
	gdk_cursor_new().

	* gdk/x11/gdkdnd-x11.c: Change the way we access private fields
	(private data member in the GObject).
	(xdnd_manager_source_filter): Function had broken
	error handling, fix it (use gdk_error_trap_push).

	* gdk/x11/gdkdrawable-x11.c: This file now implements
	a base class for GdkWindowImplX11/GdkPixmapImplX11. This
	base class is purely for the convenience of the X port,
	and not part of the interface to cross-platform GDK.

	* gdk/x11/gdkevents-x11.c: Reflect various renamings.

	* gdk/x11/gdkgc-x11.c: Implement a subclass of GdkGC that's
	specific to X, and returned by the create_gc virtual method
	of GdkDrawableImplX11.
	(gdk_x11_gc_set_dashes): Change this to take an array of gint8
	rather than gchar, this was also changed in the GdkGC vtable.
	(gdk_x11_gc_values_to_xvalues): If GdkGCValues is NULL, or the
	mask is 0, return immediately, instead of checking every flag.
	This is faster, and keeps us from segfaulting if values is NULL
	and the mask contains some nonzero flags.

	* gdk/x11/gdkgeometry-x11.c: deal with all the rearranging of
	GdkWindow.

	* gdk/x11/gdkglobals-x11.c: change type of grab window, since
	GdkWindowPrivate is gone.

	* gdk/x11/gdkim-x11.c: rename things that got renamed.

	* gdk/x11/gdkimage-x11.c: implement in terms of GObject, and
	remove the image_put stuff that got transferred to GdkDrawable.

	* gdk/x11/gdkinput.c: renamings

	* gdk/x11/gdkmain-x11.c: #include <pango/pangox.h>

	* gdk/x11/gdkpixmap-x11.c: GObject conversion

	* gdk/x11/gdkprivate-x11.h: indentation fixes

	* gdk/x11/gdkproperty-x11.c: renamings

	* gdk/x11/gdkselection-x11.c: renamings

	* gdk/x11/gdkwindow-x11.c: Restructuring and renaming; this now
	implements the platform-specific "impl" object.
	Moved gdk_window_get_children to gdk/gdkwindow.c

	* gdk/x11/gdkx.h: Remove all the private structs and private datas
	that no longer exist. Add declaration of GdkGCX11 object here.
	Fix all the macros to still work.

	* gtk/gtk-boxed.defs: Remove GtkStyle, GdkColormap, GdkWindow,
	GdkDragContext from the boxed types since they are now GObjects.

	* gtk/gtkstyle.h, gtk/gtkstyle.c: Converted GtkStyle to a GObject,
	moved xthickness/ythickness into the instance. GtkStyleClass
	functions are now in the standard vtable for GtkStyle, so you have
	to create a GObject subclass to write a theme engine.
	(gtk_style_copy): fixed a leaked PangoFontDescription
	(gtk_style_init): renamed gtk_style_realize, so gtk_style_init
	can be the standard GObject function.

	* Throughout GTK:
	s/style->klass->[xy]thickness/style->[xy]thickness
	s/pango_layout_unref/g_object_unref/

	* gtk/gtkrc.h, gtk/gtkrc.c: Converted GtkRcStyle to a GObject.

	* gtk/gtksocket.c: Use gdk_window_get_user_data() instead of
	accessing GDK internals.

	* gtk/gtkwidget.c: Use gdk_window_peek_children() instead of
	accessing GDK internals.
2000-06-20 21:04:44 +00:00

790 lines
20 KiB
C

/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* By Owen Taylor <otaylor@gtk.org> 98/4/4 */
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "gdkconfig.h"
#if defined (GDK_WINDOWING_X11)
#include "x11/gdkx.h"
#elif defined (GDK_WINDOWING_WIN32)
#include "win32/gdkwin32.h"
#elif defined(GDK_WINDOWING_FB)
#include "linux-fb/gdkfb.h"
#endif
#include "gdk/gdkkeysyms.h"
#include "gtkwindow.h"
#include "gtksignal.h"
#include "gtksocket.h"
#include "gtkdnd.h"
#ifdef GDK_WINDOWING_X11
/* Forward declararations */
static void gtk_socket_class_init (GtkSocketClass *klass);
static void gtk_socket_init (GtkSocket *socket);
static void gtk_socket_realize (GtkWidget *widget);
static void gtk_socket_unrealize (GtkWidget *widget);
static void gtk_socket_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_socket_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static gint gtk_socket_focus_in_event (GtkWidget *widget,
GdkEventFocus *event);
static void gtk_socket_claim_focus (GtkSocket *socket);
static gint gtk_socket_focus_out_event (GtkWidget *widget,
GdkEventFocus *event);
static void gtk_socket_send_configure_event (GtkSocket *socket);
static gint gtk_socket_focus (GtkContainer *container,
GtkDirectionType direction);
static GdkFilterReturn gtk_socket_filter_func (GdkXEvent *gdk_xevent,
GdkEvent *event,
gpointer data);
/* From Tk */
#define EMBEDDED_APP_WANTS_FOCUS NotifyNormal+20
/* Local data */
static GtkWidgetClass *parent_class = NULL;
GtkType
gtk_socket_get_type (void)
{
static GtkType socket_type = 0;
if (!socket_type)
{
static const GTypeInfo socket_info =
{
sizeof (GtkSocketClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_socket_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkSocket),
16, /* n_preallocs */
(GInstanceInitFunc) gtk_socket_init,
};
socket_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkSocket", &socket_info);
}
return socket_type;
}
static void
gtk_socket_class_init (GtkSocketClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
object_class = (GtkObjectClass*) class;
widget_class = (GtkWidgetClass*) class;
container_class = (GtkContainerClass*) class;
parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
widget_class->realize = gtk_socket_realize;
widget_class->unrealize = gtk_socket_unrealize;
widget_class->size_request = gtk_socket_size_request;
widget_class->size_allocate = gtk_socket_size_allocate;
widget_class->focus_in_event = gtk_socket_focus_in_event;
widget_class->focus_out_event = gtk_socket_focus_out_event;
container_class->focus = gtk_socket_focus;
}
static void
gtk_socket_init (GtkSocket *socket)
{
socket->request_width = 0;
socket->request_height = 0;
socket->current_width = 0;
socket->current_height = 0;
socket->plug_window = NULL;
socket->same_app = FALSE;
socket->focus_in = FALSE;
socket->have_size = FALSE;
socket->need_map = FALSE;
}
GtkWidget*
gtk_socket_new (void)
{
GtkSocket *socket;
socket = gtk_type_new (GTK_TYPE_SOCKET);
return GTK_WIDGET (socket);
}
void
gtk_socket_steal (GtkSocket *socket, GdkNativeWindow id)
{
GtkWidget *widget;
gpointer user_data = NULL;
widget = GTK_WIDGET (socket);
socket->plug_window = gdk_window_lookup (id);
gdk_error_trap_push ();
if (socket->plug_window)
gdk_window_get_user_data (socket->plug_window,
&user_data);
if (user_data)
{
/*
GtkWidget *child_widget;
child_widget = GTK_WIDGET (socket->plug_window->user_data);
*/
g_warning("Stealing from same app not yet implemented");
socket->same_app = TRUE;
}
else
{
socket->plug_window = gdk_window_foreign_new (id);
if (!socket->plug_window) /* was deleted before we could get it */
{
gdk_error_trap_pop ();
return;
}
socket->same_app = FALSE;
socket->have_size = FALSE;
XSelectInput (GDK_DISPLAY (),
GDK_WINDOW_XWINDOW(socket->plug_window),
StructureNotifyMask | PropertyChangeMask);
gtk_widget_queue_resize (widget);
}
gdk_window_hide (socket->plug_window);
gdk_window_reparent (socket->plug_window, widget->window, 0, 0);
gdk_flush ();
gdk_error_trap_pop ();
socket->need_map = TRUE;
}
static void
gtk_socket_realize (GtkWidget *widget)
{
GtkSocket *socket;
GdkWindowAttr attributes;
gint attributes_mask;
XWindowAttributes xattrs;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SOCKET (widget));
socket = GTK_SOCKET (widget);
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = GDK_FOCUS_CHANGE_MASK;
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
gdk_window_set_user_data (widget->window, socket);
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
XGetWindowAttributes (GDK_DISPLAY (),
GDK_WINDOW_XWINDOW (widget->window),
&xattrs);
XSelectInput (GDK_DISPLAY (),
GDK_WINDOW_XWINDOW(widget->window),
xattrs.your_event_mask |
SubstructureNotifyMask | SubstructureRedirectMask);
gdk_window_add_filter (widget->window, gtk_socket_filter_func, widget);
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
/* We sync here so that we make sure that if the XID for
* our window is passed to another application, SubstructureRedirectMask
* will be set by the time the other app creates its window.
*/
gdk_flush();
}
static void
gtk_socket_unrealize (GtkWidget *widget)
{
GtkSocket *socket;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SOCKET (widget));
socket = GTK_SOCKET (widget);
if (socket->plug_window)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
if (toplevel && GTK_IS_WINDOW (toplevel))
gtk_window_remove_embedded_xid (GTK_WINDOW (toplevel),
GDK_WINDOW_XWINDOW (socket->plug_window));
}
if (GTK_WIDGET_CLASS (parent_class)->unrealize)
(* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
}
static void
gtk_socket_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkSocket *socket;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SOCKET (widget));
g_return_if_fail (requisition != NULL);
socket = GTK_SOCKET (widget);
if (!socket->have_size && socket->plug_window)
{
XSizeHints hints;
long supplied;
gdk_error_trap_push ();
if (XGetWMNormalHints (GDK_DISPLAY(),
GDK_WINDOW_XWINDOW (socket->plug_window),
&hints, &supplied))
{
/* This is obsolete, according the X docs, but many programs
* still use it */
if (hints.flags & (PSize | USSize))
{
socket->request_width = hints.width;
socket->request_height = hints.height;
}
else if (hints.flags & PMinSize)
{
socket->request_width = hints.min_width;
socket->request_height = hints.min_height;
}
else if (hints.flags & PBaseSize)
{
socket->request_width = hints.base_width;
socket->request_height = hints.base_height;
}
}
socket->have_size = TRUE; /* don't check again? */
gdk_error_trap_pop ();
}
requisition->width = MAX (socket->request_width, 1);
requisition->height = MAX (socket->request_height, 1);
}
static void
gtk_socket_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkSocket *socket;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SOCKET (widget));
g_return_if_fail (allocation != NULL);
socket = GTK_SOCKET (widget);
widget->allocation = *allocation;
if (GTK_WIDGET_REALIZED (widget))
{
gdk_window_move_resize (widget->window,
allocation->x, allocation->y,
allocation->width, allocation->height);
if (socket->plug_window)
{
gdk_error_trap_push ();
if (!socket->need_map &&
(allocation->width == socket->current_width) &&
(allocation->height == socket->current_height))
{
gtk_socket_send_configure_event (socket);
GTK_NOTE(PLUGSOCKET,
g_message ("GtkSocket - allocated no change: %d %d",
allocation->width, allocation->height));
}
else
{
gdk_window_move_resize (socket->plug_window,
0, 0,
allocation->width, allocation->height);
GTK_NOTE(PLUGSOCKET,
g_message ("GtkSocket - allocated: %d %d",
allocation->width, allocation->height));
socket->current_width = allocation->width;
socket->current_height = allocation->height;
}
if (socket->need_map)
{
gdk_window_show (socket->plug_window);
socket->need_map = FALSE;
}
gdk_flush ();
gdk_error_trap_pop ();
}
}
}
static gint
gtk_socket_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
{
GtkSocket *socket;
g_return_val_if_fail (GTK_IS_SOCKET (widget), FALSE);
socket = GTK_SOCKET (widget);
if (socket->focus_in && socket->plug_window)
{
gdk_error_trap_push ();
XSetInputFocus (GDK_DISPLAY (),
GDK_WINDOW_XWINDOW (socket->plug_window),
RevertToParent, GDK_CURRENT_TIME);
gdk_flush();
gdk_error_trap_pop ();
}
return TRUE;
}
static gint
gtk_socket_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
{
GtkWidget *toplevel;
GtkSocket *socket;
g_return_val_if_fail (GTK_IS_SOCKET (widget), FALSE);
socket = GTK_SOCKET (widget);
toplevel = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
if (toplevel)
{
XSetInputFocus (GDK_DISPLAY (),
GDK_WINDOW_XWINDOW (toplevel->window),
RevertToParent, CurrentTime); /* FIXME? */
}
socket->focus_in = FALSE;
return TRUE;
}
static void
gtk_socket_claim_focus (GtkSocket *socket)
{
socket->focus_in = TRUE;
/* Oh, the trickery... */
GTK_WIDGET_SET_FLAGS (socket, GTK_CAN_FOCUS);
gtk_widget_grab_focus (GTK_WIDGET (socket));
GTK_WIDGET_UNSET_FLAGS (socket, GTK_CAN_FOCUS);
/* FIXME: we might grab the focus even if we don't have
* it as an app... (and see _focus_in ()) */
if (socket->plug_window)
{
gdk_error_trap_push ();
XSetInputFocus (GDK_DISPLAY (),
GDK_WINDOW_XWINDOW (socket->plug_window),
RevertToParent, GDK_CURRENT_TIME);
gdk_flush ();
gdk_error_trap_pop ();
}
}
static gint
gtk_socket_focus (GtkContainer *container, GtkDirectionType direction)
{
GtkSocket *socket;
g_return_val_if_fail (GTK_IS_SOCKET (container), FALSE);
socket = GTK_SOCKET (container);
if (!socket->focus_in && socket->plug_window)
{
XEvent xevent;
gtk_socket_claim_focus (socket);
xevent.xkey.type = KeyPress;
xevent.xkey.display = GDK_DISPLAY ();
xevent.xkey.window = GDK_WINDOW_XWINDOW (socket->plug_window);
xevent.xkey.root = GDK_ROOT_WINDOW (); /* FIXME */
xevent.xkey.time = GDK_CURRENT_TIME; /* FIXME */
/* FIXME, the following might cause big problems for
* non-GTK apps */
xevent.xkey.x = 0;
xevent.xkey.y = 0;
xevent.xkey.x_root = 0;
xevent.xkey.y_root = 0;
xevent.xkey.state = 0;
xevent.xkey.same_screen = TRUE; /* FIXME ? */
switch (direction)
{
case GTK_DIR_UP:
xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Up);
break;
case GTK_DIR_DOWN:
xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Down);
break;
case GTK_DIR_LEFT:
xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Left);
break;
case GTK_DIR_RIGHT:
xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Right);
break;
case GTK_DIR_TAB_FORWARD:
xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Tab);
break;
case GTK_DIR_TAB_BACKWARD:
xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Tab);
xevent.xkey.state = ShiftMask;
break;
}
gdk_error_trap_push ();
XSendEvent (gdk_display,
GDK_WINDOW_XWINDOW (socket->plug_window),
False, NoEventMask, &xevent);
gdk_flush();
gdk_error_trap_pop ();
return TRUE;
}
else
{
return FALSE;
}
}
static void
gtk_socket_send_configure_event (GtkSocket *socket)
{
XEvent event;
g_return_if_fail (socket->plug_window != NULL);
event.xconfigure.type = ConfigureNotify;
event.xconfigure.display = gdk_display;
event.xconfigure.event = GDK_WINDOW_XWINDOW (socket->plug_window);
event.xconfigure.window = GDK_WINDOW_XWINDOW (socket->plug_window);
event.xconfigure.x = 0;
event.xconfigure.y = 0;
event.xconfigure.width = GTK_WIDGET(socket)->allocation.width;
event.xconfigure.height = GTK_WIDGET(socket)->allocation.height;
event.xconfigure.border_width = 0;
event.xconfigure.above = None;
event.xconfigure.override_redirect = False;
gdk_error_trap_push ();
XSendEvent (gdk_display,
GDK_WINDOW_XWINDOW (socket->plug_window),
False, NoEventMask, &event);
gdk_flush ();
gdk_error_trap_pop ();
}
static void
gtk_socket_add_window (GtkSocket *socket, GdkNativeWindow xid)
{
socket->plug_window = gdk_window_lookup (xid);
socket->same_app = TRUE;
if (!socket->plug_window)
{
GtkWidget *toplevel;
GdkDragProtocol protocol;
socket->plug_window = gdk_window_foreign_new (xid);
if (!socket->plug_window) /* Already gone */
return;
socket->same_app = FALSE;
gdk_error_trap_push ();
XSelectInput (GDK_DISPLAY (),
GDK_WINDOW_XWINDOW(socket->plug_window),
StructureNotifyMask | PropertyChangeMask);
if (gdk_drag_get_protocol (xid, &protocol))
gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
protocol, TRUE);
gdk_flush ();
gdk_error_trap_pop ();
gdk_window_add_filter (socket->plug_window,
gtk_socket_filter_func, socket);
/* Add a pointer to the socket on our toplevel window */
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
if (toplevel && GTK_IS_WINDOW (toplevel))
{
gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
}
}
}
static GdkFilterReturn
gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
{
GtkSocket *socket;
GtkWidget *widget;
XEvent *xevent;
GdkFilterReturn return_val;
socket = GTK_SOCKET (data);
widget = GTK_WIDGET (socket);
xevent = (XEvent *)gdk_xevent;
return_val = GDK_FILTER_CONTINUE;
switch (xevent->type)
{
case CreateNotify:
{
XCreateWindowEvent *xcwe = &xevent->xcreatewindow;
if (!socket->plug_window)
{
gtk_socket_add_window (socket, xcwe->window);
gdk_error_trap_push ();
gdk_window_move_resize(socket->plug_window,
0, 0,
widget->allocation.width,
widget->allocation.height);
gdk_flush ();
gdk_error_trap_pop ();
socket->request_width = xcwe->width;
socket->request_height = xcwe->height;
socket->have_size = TRUE;
GTK_NOTE(PLUGSOCKET,
g_message ("GtkSocket - window created with size: %d %d",
socket->request_width,
socket->request_height));
gtk_widget_queue_resize (widget);
}
return_val = GDK_FILTER_REMOVE;
break;
}
case ConfigureRequest:
{
XConfigureRequestEvent *xcre = &xevent->xconfigurerequest;
if (!socket->plug_window)
gtk_socket_add_window (socket, xcre->window);
if (xcre->window == GDK_WINDOW_XWINDOW (socket->plug_window))
{
if (xcre->value_mask & (CWWidth | CWHeight))
{
socket->request_width = xcre->width;
socket->request_height = xcre->height;
socket->have_size = TRUE;
GTK_NOTE(PLUGSOCKET,
g_message ("GtkSocket - configure request: %d %d",
socket->request_width,
socket->request_height));
gtk_widget_queue_resize (widget);
}
else if (xcre->value_mask & (CWX | CWY))
{
gtk_socket_send_configure_event (socket);
}
/* Ignore stacking requests. */
return_val = GDK_FILTER_REMOVE;
}
break;
}
case DestroyNotify:
{
XDestroyWindowEvent *xdwe = &xevent->xdestroywindow;
if (socket->plug_window &&
(xdwe->window == GDK_WINDOW_XWINDOW (socket->plug_window)))
{
GtkWidget *toplevel;
GTK_NOTE(PLUGSOCKET,
g_message ("GtkSocket - destroy notify"));
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
if (toplevel && GTK_IS_WINDOW (toplevel))
gtk_window_remove_embedded_xid (GTK_WINDOW (toplevel), xdwe->window);
gdk_window_destroy_notify (socket->plug_window);
gtk_widget_destroy (widget);
socket->plug_window = NULL;
return_val = GDK_FILTER_REMOVE;
}
break;
}
case FocusIn:
if (xevent->xfocus.mode == EMBEDDED_APP_WANTS_FOCUS)
{
gtk_socket_claim_focus (socket);
}
else if (xevent->xfocus.detail == NotifyInferior)
{
#if 0
GtkWidget *toplevel;
toplevel = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
if (toplevel)
{
XSetInputFocus (GDK_DISPLAY (),
GDK_WINDOW_XWINDOW (toplevel->window),
RevertToParent, CurrentTime); /* FIXME? */
}
#endif
}
return_val = GDK_FILTER_REMOVE;
break;
case FocusOut:
return_val = GDK_FILTER_REMOVE;
break;
case MapRequest:
if (!socket->plug_window)
gtk_socket_add_window (socket, xevent->xmaprequest.window);
if (xevent->xmaprequest.window ==
GDK_WINDOW_XWINDOW (socket->plug_window))
{
GTK_NOTE(PLUGSOCKET,
g_message ("GtkSocket - Map Request"));
gdk_error_trap_push ();
gdk_window_show (socket->plug_window);
gdk_flush ();
gdk_error_trap_pop ();
return_val = GDK_FILTER_REMOVE;
}
break;
case PropertyNotify:
if (xevent->xproperty.window ==
GDK_WINDOW_XWINDOW (socket->plug_window))
{
GdkDragProtocol protocol;
if ((xevent->xproperty.atom == gdk_atom_intern ("XdndAware", FALSE)) ||
(xevent->xproperty.atom == gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE)))
{
gdk_error_trap_push ();
if (gdk_drag_get_protocol (xevent->xproperty.window, &protocol))
gtk_drag_dest_set_proxy (GTK_WIDGET (socket),
socket->plug_window,
protocol, TRUE);
gdk_flush ();
gdk_error_trap_pop ();
}
return_val = GDK_FILTER_REMOVE;
}
}
return return_val;
}
#else
GtkType
gtk_socket_get_type (void)
{
g_error ("GtkSocket not implemented");
return 0;
}
GtkWidget*
gtk_socket_new ()
{
g_error ("GtkSocket not implemented");
return NULL;
}
void
gtk_socket_steal (GtkSocket *socket, GdkNativeWindow id)
{
g_error ("GtkSocket not implemented");
}
#endif /* GDK_WINDOWING */