diff --git a/ChangeLog b/ChangeLog index 86e695a0e2..16dc7904f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2005-07-21 Tor Lillqvist + * gtk/gtksocket-stub.c + * gtk/gtkplug-stub.c + * gtk/gtksocket-x11.c + * gtk/gtkplug-x11.c + * gtk/gtksocket-win32.c + * gtk/gtkplug-win32.c + * gtk/gtkwin32embed.h + * gtk/gtkwin32embed.c: New files, containing the backend-specific + parts of GtkPlug/Socket. + * gtk/gtkxembed.h * gtk/gtkxembed.c (_gtk_xembed_message_name): New function, used in error messages and debugging output. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 86e695a0e2..16dc7904f2 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,15 @@ 2005-07-21 Tor Lillqvist + * gtk/gtksocket-stub.c + * gtk/gtkplug-stub.c + * gtk/gtksocket-x11.c + * gtk/gtkplug-x11.c + * gtk/gtksocket-win32.c + * gtk/gtkplug-win32.c + * gtk/gtkwin32embed.h + * gtk/gtkwin32embed.c: New files, containing the backend-specific + parts of GtkPlug/Socket. + * gtk/gtkxembed.h * gtk/gtkxembed.c (_gtk_xembed_message_name): New function, used in error messages and debugging output. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 86e695a0e2..16dc7904f2 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,15 @@ 2005-07-21 Tor Lillqvist + * gtk/gtksocket-stub.c + * gtk/gtkplug-stub.c + * gtk/gtksocket-x11.c + * gtk/gtkplug-x11.c + * gtk/gtksocket-win32.c + * gtk/gtkplug-win32.c + * gtk/gtkwin32embed.h + * gtk/gtkwin32embed.c: New files, containing the backend-specific + parts of GtkPlug/Socket. + * gtk/gtkxembed.h * gtk/gtkxembed.c (_gtk_xembed_message_name): New function, used in error messages and debugging output. diff --git a/gtk/gtkplug-stub.c b/gtk/gtkplug-stub.c new file mode 100644 index 0000000000..3346f36ed2 --- /dev/null +++ b/gtk/gtkplug-stub.c @@ -0,0 +1,82 @@ +/* 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 Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Stub implementation of backend-specific GtkPlug functions. */ + +/* + * Modified by the GTK+ Team and others 1997-2000. 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 "gtkplugprivate.h" + +GdkNativeWindow +_gtk_plug_windowing_get_id (GtkPlug *plug) +{ + return 0; +} + +void +_gtk_plug_windowing_realize_toplevel (GtkPlug *plug) +{ +} + +void +_gtk_plug_windowing_map_toplevel (GtkPlug *plug) +{ +} + +void +_gtk_plug_windowing_unmap_toplevel (GtkPlug *plug) +{ +} + +void +_gtk_plug_windowing_set_focus (GtkPlug *plug) +{ +} + +void +_gtk_plug_windowing_add_grabbed_key (GtkPlug *plug, + guint accelerator_key, + GdkModifierType accelerator_mods) +{ +} + +void +_gtk_plug_windowing_remove_grabbed_key (GtkPlug *plug, + guint accelerator_key, + GdkModifierType accelerator_mods) +{ +} + +void +_gtk_plug_windowing_focus_to_parent (GtkPlug *plug, + GtkDirectionType direction) +{ +} + +GdkFilterReturn +_gtk_plug_windowing_filter_func (GdkXEvent *gdk_xevent, + GdkEvent *event, + gpointer data) +{ + return GDK_FILTER_CONTINUE; +} diff --git a/gtk/gtkplug-win32.c b/gtk/gtkplug-win32.c new file mode 100644 index 0000000000..329a7d8b76 --- /dev/null +++ b/gtk/gtkplug-win32.c @@ -0,0 +1,299 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * Copyright (C) 2005 Novell, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* By Tor Lillqvist 2005 */ + +/* + * Modified by the GTK+ Team and others 1997-2005. 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 "gtkmarshalers.h" +#include "gtkplug.h" +#include "gtkplugprivate.h" + +#include "win32/gdkwin32.h" + +#include "gtkwin32embed.h" + +GdkNativeWindow +_gtk_plug_windowing_get_id (GtkPlug *plug) +{ + return (GdkNativeWindow) GDK_WINDOW_HWND (GTK_WIDGET (plug)->window); +} + +void +_gtk_plug_windowing_realize_toplevel (GtkPlug *plug) +{ + if (plug->socket_window) + { + _gtk_win32_embed_send (plug->socket_window, + GTK_WIN32_EMBED_PARENT_NOTIFY, + (int) GDK_WINDOW_HWND (GTK_WIDGET (plug)->window), + GTK_WIN32_EMBED_PROTOCOL_VERSION); + _gtk_win32_embed_send (plug->socket_window, + GTK_WIN32_EMBED_EVENT_PLUG_MAPPED, 0, 0); + } +} + +void +_gtk_plug_windowing_map_toplevel (GtkPlug *plug) +{ + if (plug->socket_window) + _gtk_win32_embed_send (plug->socket_window, + GTK_WIN32_EMBED_EVENT_PLUG_MAPPED, + 1, 0); +} + +void +_gtk_plug_windowing_unmap_toplevel (GtkPlug *plug) +{ + if (plug->socket_window) + _gtk_win32_embed_send (plug->socket_window, + GTK_WIN32_EMBED_EVENT_PLUG_MAPPED, + 0, 0); +} + +void +_gtk_plug_windowing_set_focus (GtkPlug *plug) +{ + if (plug->socket_window) + _gtk_win32_embed_send (plug->socket_window, + GTK_WIN32_EMBED_REQUEST_FOCUS, + 0, 0); +} + +void +_gtk_plug_windowing_add_grabbed_key (GtkPlug *plug, + guint accelerator_key, + GdkModifierType accelerator_mods) +{ + if (plug->socket_window) + _gtk_win32_embed_send (plug->socket_window, + GTK_WIN32_EMBED_GRAB_KEY, + accelerator_key, accelerator_mods); +} + +void +_gtk_plug_windowing_remove_grabbed_key (GtkPlug *plug, + guint accelerator_key, + GdkModifierType accelerator_mods) +{ + if (plug->socket_window) + _gtk_win32_embed_send (plug->socket_window, + GTK_WIN32_EMBED_UNGRAB_KEY, + accelerator_key, accelerator_mods); +} + +void +_gtk_plug_windowing_focus_to_parent (GtkPlug *plug, + GtkDirectionType direction) +{ + GtkWin32EmbedMessageType message = GTK_WIN32_EMBED_FOCUS_PREV; + + switch (direction) + { + case GTK_DIR_UP: + case GTK_DIR_LEFT: + case GTK_DIR_TAB_BACKWARD: + message = GTK_WIN32_EMBED_FOCUS_PREV; + break; + case GTK_DIR_DOWN: + case GTK_DIR_RIGHT: + case GTK_DIR_TAB_FORWARD: + message = GTK_WIN32_EMBED_FOCUS_NEXT; + break; + } + + _gtk_win32_embed_send_focus_message (plug->socket_window, message, 0); +} + +GdkFilterReturn +_gtk_plug_windowing_filter_func (GdkXEvent *gdk_xevent, + GdkEvent *event, + gpointer data) +{ + GtkPlug *plug = GTK_PLUG (data); + MSG *msg = (MSG *) gdk_xevent; + GdkFilterReturn return_val = GDK_FILTER_CONTINUE; + + switch (msg->message) + { + /* What message should we look for to notice the reparenting? + * Maybe WM_WINDOWPOSCHANGED will work? This is handled in the + * X11 implementation by handling ReparentNotify. Handle this + * only for cross-process embedding, otherwise we get odd + * crashes in testsocket. + */ + case WM_WINDOWPOSCHANGED: + if (!plug->same_app) + { + HWND parent = GetAncestor (msg->hwnd, GA_PARENT); + gboolean was_embedded = plug->socket_window != NULL; + GdkScreen *screen = gdk_drawable_get_screen (event->any.window); + GdkDisplay *display = gdk_screen_get_display (screen); + + GTK_NOTE (PLUGSOCKET, g_printerr ("WM_WINDOWPOSCHANGED: hwnd=%p GA_PARENT=%p socket_window=%p\n", msg->hwnd, parent, plug->socket_window)); + g_object_ref (plug); + if (was_embedded) + { + /* End of embedding protocol for previous socket */ + if (parent != GDK_WINDOW_HWND (plug->socket_window)) + { + GtkWidget *widget = GTK_WIDGET (plug); + + GTK_NOTE (PLUGSOCKET, g_printerr ("was_embedded, current parent != socket_window\n")); + gdk_window_set_user_data (plug->socket_window, NULL); + g_object_unref (plug->socket_window); + plug->socket_window = NULL; + + /* Emit a delete window, as if the user attempted to + * close the toplevel. Only do this if we are being + * reparented to the desktop window. Moving from one + * embedder to another should be invisible to the app. + */ + if (parent == GetDesktopWindow ()) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("current parent is root window\n")); + _gtk_plug_send_delete_event (widget); + return_val = GDK_FILTER_REMOVE; + } + } + else + { + GTK_NOTE (PLUGSOCKET, g_printerr ("still same parent\n")); + goto done; + } + } + + if (parent != GetDesktopWindow ()) + { + /* Start of embedding protocol */ + + GTK_NOTE (PLUGSOCKET, g_printerr ("start of embedding\n")); + plug->socket_window = gdk_window_lookup_for_display (display, (GdkNativeWindow) parent); + if (plug->socket_window) + { + gpointer user_data = NULL; + + GTK_NOTE (PLUGSOCKET, g_printerr ("already had socket_window\n")); + gdk_window_get_user_data (plug->socket_window, &user_data); + + if (user_data) + { + g_warning (G_STRLOC "Plug reparented unexpectedly into window in the same process"); + plug->socket_window = NULL; + break; + } + + g_object_ref (plug->socket_window); + } + else + { + plug->socket_window = gdk_window_foreign_new_for_display (display, (GdkNativeWindow) parent); + if (!plug->socket_window) /* Already gone */ + break; + } + + _gtk_plug_add_all_grabbed_keys (plug); + + if (!was_embedded) + g_signal_emit_by_name (plug, "embedded"); + } + done: + g_object_unref (plug); + } + break; + + case WM_SIZE: + if (!plug->same_app && plug->socket_window) + { + _gtk_win32_embed_send (plug->socket_window, + GTK_WIN32_EMBED_PLUG_RESIZED, + 0, 0); + } + break; + + default: + if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_WINDOW_ACTIVATE)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkPlug: WINDOW_ACTIVATE received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_window_set_is_active (GTK_WINDOW (plug), TRUE); + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_WINDOW_DEACTIVATE)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkPlug: WINDOW_DEACTIVATE received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_window_set_is_active (GTK_WINDOW (plug), FALSE); + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_IN)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkPlug: FOCUS_IN received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_window_set_has_toplevel_focus (GTK_WINDOW (plug), TRUE); + switch (msg->wParam) + { + case GTK_WIN32_EMBED_FOCUS_CURRENT: + break; + case GTK_WIN32_EMBED_FOCUS_FIRST: + _gtk_plug_focus_first_last (plug, GTK_DIR_TAB_FORWARD); + break; + case GTK_WIN32_EMBED_FOCUS_LAST: + _gtk_plug_focus_first_last (plug, GTK_DIR_TAB_BACKWARD); + break; + } + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_OUT)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkPlug: FOCUS_OUT received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_window_set_has_toplevel_focus (GTK_WINDOW (plug), FALSE); + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_MODALITY_ON)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkPlug: MODALITY_ON received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_plug_handle_modality_on (plug); + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_MODALITY_OFF)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkPlug: MODALITY_OFF received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_plug_handle_modality_off (plug); + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + break; + } + + return return_val; +} diff --git a/gtk/gtkplug-x11.c b/gtk/gtkplug-x11.c new file mode 100644 index 0000000000..c2dff4a250 --- /dev/null +++ b/gtk/gtkplug-x11.c @@ -0,0 +1,328 @@ +/* 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 Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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 98/4/4 */ + +/* + * Modified by the GTK+ Team and others 1997-2000. 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 "gtkalias.h" +#include "gtkmain.h" +#include "gtkmarshalers.h" +#include "gtkplug.h" +#include "gtkprivate.h" +#include "gtkplugprivate.h" + +#include "x11/gdkx.h" + +#include "gtkxembed.h" + +static void xembed_set_info (GdkWindow *window, + unsigned long flags); + +GdkNativeWindow +_gtk_plug_windowing_get_id (GtkPlug *plug) +{ + return GDK_WINDOW_XWINDOW (GTK_WIDGET (plug)->window); +} + +void +_gtk_plug_windowing_realize_toplevel (GtkPlug *plug) +{ + xembed_set_info (GTK_WIDGET (plug)->window, 0); +} + +void +_gtk_plug_windowing_map_toplevel (GtkPlug *plug) +{ + xembed_set_info (GTK_WIDGET (plug)->window, XEMBED_MAPPED); +} + +void +_gtk_plug_windowing_unmap_toplevel (GtkPlug *plug) +{ + xembed_set_info (GTK_WIDGET (plug)->window, 0); +} + +void +_gtk_plug_windowing_set_focus (GtkPlug *plug) +{ + _gtk_xembed_send_message (plug->socket_window, + XEMBED_REQUEST_FOCUS, 0, 0, 0); +} + +void +_gtk_plug_windowing_add_grabbed_key (GtkPlug *plug, + guint accelerator_key, + GdkModifierType accelerator_mods) +{ + _gtk_xembed_send_message (plug->socket_window, XEMBED_GTK_GRAB_KEY, 0, + accelerator_key, accelerator_mods); +} + +void +_gtk_plug_windowing_remove_grabbed_key (GtkPlug *plug, + guint accelerator_key, + GdkModifierType accelerator_mods) +{ + _gtk_xembed_send_message (plug->socket_window, XEMBED_GTK_UNGRAB_KEY, 0, + accelerator_key, accelerator_mods); +} + +void +_gtk_plug_windowing_focus_to_parent (GtkPlug *plug, + GtkDirectionType direction) +{ + XEmbedMessageType message = XEMBED_FOCUS_PREV; /* Quiet GCC */ + + switch (direction) + { + case GTK_DIR_UP: + case GTK_DIR_LEFT: + case GTK_DIR_TAB_BACKWARD: + message = XEMBED_FOCUS_PREV; + break; + case GTK_DIR_DOWN: + case GTK_DIR_RIGHT: + case GTK_DIR_TAB_FORWARD: + message = XEMBED_FOCUS_NEXT; + break; + } + + _gtk_xembed_send_focus_message (plug->socket_window, message, 0); +} + +static void +xembed_set_info (GdkWindow *window, + unsigned long flags) +{ + GdkDisplay *display = gdk_drawable_get_display (window); + unsigned long buffer[2]; + + Atom xembed_info_atom = gdk_x11_get_xatom_by_name_for_display (display, "_XEMBED_INFO"); + + buffer[0] = GTK_XEMBED_PROTOCOL_VERSION; + buffer[1] = flags; + + XChangeProperty (GDK_DISPLAY_XDISPLAY (display), + GDK_WINDOW_XWINDOW (window), + xembed_info_atom, xembed_info_atom, 32, + PropModeReplace, + (unsigned char *)buffer, 2); +} + +static void +handle_xembed_message (GtkPlug *plug, + XEmbedMessageType message, + glong detail, + glong data1, + glong data2, + guint32 time) +{ + GtkWindow *window = GTK_WINDOW (plug); + + GTK_NOTE (PLUGSOCKET, + g_message ("GtkPlug: %s received", _gtk_xembed_message_name (message))); + + switch (message) + { + case XEMBED_EMBEDDED_NOTIFY: + break; + case XEMBED_WINDOW_ACTIVATE: + _gtk_window_set_is_active (window, TRUE); + break; + case XEMBED_WINDOW_DEACTIVATE: + _gtk_window_set_is_active (window, FALSE); + break; + + case XEMBED_MODALITY_ON: + _gtk_plug_handle_modality_on (plug); + break; + case XEMBED_MODALITY_OFF: + _gtk_plug_handle_modality_off (plug); + break; + + case XEMBED_FOCUS_IN: + _gtk_window_set_has_toplevel_focus (window, TRUE); + switch (detail) + { + case XEMBED_FOCUS_FIRST: + _gtk_plug_focus_first_last (plug, GTK_DIR_TAB_FORWARD); + break; + case XEMBED_FOCUS_LAST: + _gtk_plug_focus_first_last (plug, GTK_DIR_TAB_BACKWARD); + break; + case XEMBED_FOCUS_CURRENT: + break; + } + break; + + case XEMBED_FOCUS_OUT: + _gtk_window_set_has_toplevel_focus (window, FALSE); + break; + + case XEMBED_GRAB_KEY: + case XEMBED_UNGRAB_KEY: + case XEMBED_GTK_GRAB_KEY: + case XEMBED_GTK_UNGRAB_KEY: + case XEMBED_REQUEST_FOCUS: + case XEMBED_FOCUS_NEXT: + case XEMBED_FOCUS_PREV: + g_warning ("GtkPlug: Invalid _XEMBED message %s received", _gtk_xembed_message_name (message)); + break; + + default: + GTK_NOTE(PLUGSOCKET, + g_message ("GtkPlug: Ignoring unknown _XEMBED message of type %d", message)); + break; + } +} + +GdkFilterReturn +_gtk_plug_windowing_filter_func (GdkXEvent *gdk_xevent, + GdkEvent *event, + gpointer data) +{ + GdkScreen *screen = gdk_drawable_get_screen (event->any.window); + GdkDisplay *display = gdk_screen_get_display (screen); + GtkPlug *plug = GTK_PLUG (data); + XEvent *xevent = (XEvent *)gdk_xevent; + + GdkFilterReturn return_val; + + return_val = GDK_FILTER_CONTINUE; + + switch (xevent->type) + { + case ClientMessage: + if (xevent->xclient.message_type == gdk_x11_get_xatom_by_name_for_display (display, "_XEMBED")) + { + _gtk_xembed_push_message (xevent); + handle_xembed_message (plug, + xevent->xclient.data.l[1], + xevent->xclient.data.l[2], + xevent->xclient.data.l[3], + xevent->xclient.data.l[4], + xevent->xclient.data.l[0]); + _gtk_xembed_pop_message (); + + return_val = GDK_FILTER_REMOVE; + } + else if (xevent->xclient.message_type == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW")) + { + /* We filter these out because we take being reparented back to the + * root window as the reliable end of the embedding protocol + */ + + return GDK_FILTER_REMOVE; + } + break; + case ReparentNotify: + { + XReparentEvent *xre = &xevent->xreparent; + gboolean was_embedded = plug->socket_window != NULL; + + GTK_NOTE (PLUGSOCKET, g_message("GtkPlug: ReparentNotify received\n")); + + return_val = GDK_FILTER_REMOVE; + + g_object_ref (plug); + + if (was_embedded) + { + /* End of embedding protocol for previous socket */ + + GTK_NOTE (PLUGSOCKET, g_message ("GtkPlug: end of embedding\n")); + /* FIXME: race if we remove from another socket and + * then add to a local window before we get notification + * Probably need check in _gtk_plug_add_to_socket + */ + + if (xre->parent != GDK_WINDOW_XWINDOW (plug->socket_window)) + { + GtkWidget *widget = GTK_WIDGET (plug); + + gdk_window_set_user_data (plug->socket_window, NULL); + g_object_unref (plug->socket_window); + plug->socket_window = NULL; + + /* Emit a delete window, as if the user attempted + * to close the toplevel. Simple as to how we + * handle WM_DELETE_WINDOW, if it isn't handled + * we destroy the widget. BUt only do this if + * we are being reparented to the root window. + * Moving from one embedder to another should + * be invisible to the app. + */ + + if (xre->parent == GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen))) + { + GTK_NOTE (PLUGSOCKET, g_message ("GtkPlug: calling gtk_plug_send_delete_event()\n")); + _gtk_plug_send_delete_event (widget); + } + } + else + goto done; + } + + if (xre->parent != GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen))) + { + /* Start of embedding protocol */ + + GTK_NOTE (PLUGSOCKET, g_message ("GtkPlug: start of embedding\n")); + plug->socket_window = gdk_window_lookup_for_display (display, xre->parent); + if (plug->socket_window) + { + gpointer user_data = NULL; + gdk_window_get_user_data (plug->socket_window, &user_data); + + if (user_data) + { + g_warning (G_STRLOC "Plug reparented unexpectedly into window in the same process"); + plug->socket_window = NULL; + break; + } + + g_object_ref (plug->socket_window); + } + else + { + plug->socket_window = gdk_window_foreign_new_for_display (display, xre->parent); + if (!plug->socket_window) /* Already gone */ + break; + } + + _gtk_plug_add_all_grabbed_keys (plug); + + if (!was_embedded) + g_signal_emit_by_name (plug, "embedded"); + } + + done: + g_object_unref (plug); + + break; + } + } + + return GDK_FILTER_CONTINUE; +} diff --git a/gtk/gtksocket-stub.c b/gtk/gtksocket-stub.c new file mode 100644 index 0000000000..9895c227b0 --- /dev/null +++ b/gtk/gtksocket-stub.c @@ -0,0 +1,119 @@ +/* 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 Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Stub implementation of backend-specific GtkPlug functions. */ + +/* + * Modified by the GTK+ Team and others 1997-2000. 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 "gtksocketprivate.h" + +GdkNativeWindow +_gtk_socket_windowing_get_id (GtkSocket *socket) +{ + return 0; +} + +void +_gtk_socket_windowing_realize_window (GtkSocket *socket) +{ +} + +void +_gtk_socket_windowing_end_embedding_toplevel (GtkSocket *socket) +{ +} + +void +_gtk_socket_windowing_size_request (GtkSocket *socket) +{ +} + +void +_gtk_socket_windowing_send_key_event (GtkSocket *socket, + GdkEvent *gdk_event, + gboolean mask_key_presses) +{ +} + +void +_gtk_socket_windowing_focus_change (GtkSocket *socket, + gboolean focus_in) +{ +} + +void +_gtk_socket_windowing_update_active (GtkSocket *socket, + gboolean active) +{ +} + +void +_gtk_socket_windowing_update_modality (GtkSocket *socket, + gboolean modality) +{ +} + +void +_gtk_socket_windowing_focus (GtkSocket *socket, + GtkDirectionType direction) +{ +} + +void +_gtk_socket_windowing_send_configure_event (GtkSocket *socket) +{ +} + +void +_gtk_socket_windowing_select_plug_window_input (GtkSocket *socket) +{ +} + +void +_gtk_socket_windowing_embed_get_info (GtkSocket *socket) +{ +} + +void +_gtk_socket_windowing_embed_notify (GtkSocket *socket) +{ +} + +gboolean +_gtk_socket_windowing_embed_get_focus_wrapped (void) +{ + return FALSE; +} + +void +_gtk_socket_windowing_embed_set_focus_wrapped (void) +{ +} + +GdkFilterReturn +_gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent, + GdkEvent *event, + gpointer data) +{ + return GDK_FILTER_CONTINUE; +} diff --git a/gtk/gtksocket-win32.c b/gtk/gtksocket-win32.c new file mode 100644 index 0000000000..4db3957756 --- /dev/null +++ b/gtk/gtksocket-win32.c @@ -0,0 +1,305 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * Copyright (C) 2005 Novell, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* By Tor Lillqvist 2005 */ + +/* + * Modified by the GTK+ Team and others 1997-2005. 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 +#include + +#include "gtkwindow.h" +#include "gtkplug.h" +#include "gtkprivate.h" +#include "gtksocket.h" +#include "gtksocketprivate.h" + +#include "win32/gdkwin32.h" + +#include "gtkwin32embed.h" + +GdkNativeWindow +_gtk_socket_windowing_get_id (GtkSocket *socket) +{ + g_return_val_if_fail (GTK_IS_SOCKET (socket), 0); + g_return_val_if_fail (GTK_WIDGET_ANCHORED (socket), 0); + + if (!GTK_WIDGET_REALIZED (socket)) + gtk_widget_realize (GTK_WIDGET (socket)); + + return (GdkNativeWindow) GDK_WINDOW_HWND (GTK_WIDGET (socket)->window); +} + +void +_gtk_socket_windowing_realize_window (GtkSocket *socket) +{ + /* XXX Anything needed? */ +} + +void +_gtk_socket_windowing_end_embedding_toplevel (GtkSocket *socket) +{ + gtk_window_remove_embedded_xid (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (socket))), + (guint) GDK_WINDOW_HWND (socket->plug_window)); +} + +void +_gtk_socket_windowing_size_request (GtkSocket *socket) +{ + MINMAXINFO mmi; + + socket->request_width = 1; + socket->request_height = 1; + + mmi.ptMaxSize.x = mmi.ptMaxSize.y = 16000; /* ??? */ + mmi.ptMinTrackSize.x = mmi.ptMinTrackSize.y = 1; + mmi.ptMaxTrackSize.x = mmi.ptMaxTrackSize.y = 16000; /* ??? */ + mmi.ptMaxPosition.x = mmi.ptMaxPosition.y = 0; + + if (SendMessage (GDK_WINDOW_HWND (socket->plug_window), WM_GETMINMAXINFO, + 0, (LPARAM) &mmi) == 0) + { + socket->request_width = mmi.ptMinTrackSize.x; + socket->request_height = mmi.ptMinTrackSize.y; + } + socket->have_size = TRUE; +} + +void +_gtk_socket_windowing_send_key_event (GtkSocket *socket, + GdkEvent *gdk_event, + gboolean mask_key_presses) +{ + PostMessage (GDK_WINDOW_HWND (socket->plug_window), + (gdk_event->type == GDK_KEY_PRESS ? WM_KEYDOWN : WM_KEYUP), + gdk_event->key.hardware_keycode, 0); +} + +void +_gtk_socket_windowing_focus_change (GtkSocket *socket, + gboolean focus_in) +{ + if (focus_in) + _gtk_win32_embed_send_focus_message (socket->plug_window, + GTK_WIN32_EMBED_FOCUS_IN, + GTK_WIN32_EMBED_FOCUS_CURRENT); + else + _gtk_win32_embed_send (socket->plug_window, + GTK_WIN32_EMBED_FOCUS_OUT, + 0, 0); +} + +void +_gtk_socket_windowing_update_active (GtkSocket *socket, + gboolean active) +{ + _gtk_win32_embed_send (socket->plug_window, + (active ? GTK_WIN32_EMBED_WINDOW_ACTIVATE : GTK_WIN32_EMBED_WINDOW_DEACTIVATE), + 0, 0); +} + +void +_gtk_socket_windowing_update_modality (GtkSocket *socket, + gboolean modality) +{ + _gtk_win32_embed_send (socket->plug_window, + (modality ? GTK_WIN32_EMBED_MODALITY_ON : GTK_WIN32_EMBED_MODALITY_OFF), + 0, 0); +} + +void +_gtk_socket_windowing_focus (GtkSocket *socket, + GtkDirectionType direction) +{ + int detail = -1; + + switch (direction) + { + case GTK_DIR_UP: + case GTK_DIR_LEFT: + case GTK_DIR_TAB_BACKWARD: + detail = GTK_WIN32_EMBED_FOCUS_LAST; + break; + case GTK_DIR_DOWN: + case GTK_DIR_RIGHT: + case GTK_DIR_TAB_FORWARD: + detail = GTK_WIN32_EMBED_FOCUS_FIRST; + break; + } + + _gtk_win32_embed_send_focus_message (socket->plug_window, + GTK_WIN32_EMBED_FOCUS_IN, + detail); +} + +void +_gtk_socket_windowing_send_configure_event (GtkSocket *socket) +{ + /* XXX Nothing needed? */ +} + +void +_gtk_socket_windowing_select_plug_window_input (GtkSocket *socket) +{ + /* XXX Nothing needed? */ +} + +void +_gtk_socket_windowing_embed_get_info (GtkSocket *socket) +{ + socket->is_mapped = TRUE; /* XXX ? */ +} + +void +_gtk_socket_windowing_embed_notify (GtkSocket *socket) +{ + /* XXX Nothing needed? */ +} + +gboolean +_gtk_socket_windowing_embed_get_focus_wrapped (void) +{ + return _gtk_win32_embed_get_focus_wrapped (); +} + +void +_gtk_socket_windowing_embed_set_focus_wrapped (void) +{ + _gtk_win32_embed_set_focus_wrapped (); +} + +GdkFilterReturn +_gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent, + GdkEvent *event, + gpointer data) +{ + GtkSocket *socket; + GtkWidget *widget; + MSG *msg; + GdkFilterReturn return_val; + + socket = GTK_SOCKET (data); + + return_val = GDK_FILTER_CONTINUE; + + if (socket->plug_widget) + return return_val; + + widget = GTK_WIDGET (socket); + msg = (MSG *) gdk_xevent; + + switch (msg->message) + { + default: + if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_PARENT_NOTIFY)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkSocket: PARENT_NOTIFY received window=%#x version=%ld\n", msg->wParam, msg->lParam)); + /* If we some day different protocols deployed need to add + * some more elaborate version handshake + */ + if (msg->lParam != GTK_WIN32_EMBED_PROTOCOL_VERSION) + g_warning ("GTK Win32 embedding protocol version mismatch, " + "client uses version %ld, we understand version %d", + msg->lParam, GTK_WIN32_EMBED_PROTOCOL_VERSION); + if (!socket->plug_window) + { + _gtk_socket_add_window (socket, msg->wParam, FALSE); + + if (socket->plug_window) + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkSocket: window created")); + + return_val = GDK_FILTER_REMOVE; + } + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_EVENT_PLUG_MAPPED)) + { + gboolean was_mapped = socket->is_mapped; + gboolean is_mapped = msg->wParam != 0; + + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkSocket: PLUG_MAPPED received is_mapped:%d\n", is_mapped)); + if (was_mapped != is_mapped) + { + if (is_mapped) + _gtk_socket_handle_map_request (socket); + else + { + gdk_window_show (socket->plug_window); + _gtk_socket_unmap_notify (socket); + } + } + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_PLUG_RESIZED)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkSocket: PLUG_RESIZED received\n")); + socket->have_size = FALSE; + gtk_widget_queue_resize (widget); + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_REQUEST_FOCUS)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkSocket: REQUEST_FOCUS received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_socket_claim_focus (socket, TRUE); + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_NEXT)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkSocket: FOCUS_NEXT received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_socket_advance_toplevel_focus (socket, GTK_DIR_TAB_FORWARD); + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_PREV)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkSocket: FOCUS_PREV received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_socket_advance_toplevel_focus (socket, GTK_DIR_TAB_BACKWARD); + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_GRAB_KEY)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkSocket: GRAB_KEY received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_socket_add_grabbed_key (socket, msg->wParam, msg->lParam); + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + else if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_UNGRAB_KEY)) + { + GTK_NOTE (PLUGSOCKET, g_printerr ("GtkSocket: UNGRAB_KEY received\n")); + _gtk_win32_embed_push_message (msg); + _gtk_socket_remove_grabbed_key (socket, msg->wParam, msg->lParam); + _gtk_win32_embed_pop_message (); + return_val = GDK_FILTER_REMOVE; + } + break; + } + + return return_val; +} + diff --git a/gtk/gtksocket-x11.c b/gtk/gtksocket-x11.c new file mode 100644 index 0000000000..160af72e5c --- /dev/null +++ b/gtk/gtksocket-x11.c @@ -0,0 +1,620 @@ +/* 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 Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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 98/4/4 */ + +/* + * Modified by the GTK+ Team and others 1997-2000. 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 +#include + +#include "gdk/gdkkeysyms.h" +#include "gtkalias.h" +#include "gtkmain.h" +#include "gtkmarshalers.h" +#include "gtkwindow.h" +#include "gtkplug.h" +#include "gtkprivate.h" +#include "gtksocket.h" +#include "gtksocketprivate.h" +#include "gtkdnd.h" + +#include "x11/gdkx.h" + +#include "gtkxembed.h" +#include "gtkalias.h" + +static gboolean xembed_get_info (GdkWindow *gdk_window, + unsigned long *version, + unsigned long *flags); + +/* From Tk */ +#define EMBEDDED_APP_WANTS_FOCUS NotifyNormal+20 + +GdkNativeWindow +_gtk_socket_windowing_get_id (GtkSocket *socket) +{ + return GDK_WINDOW_XWINDOW (GTK_WIDGET (socket)->window); +} + +void +_gtk_socket_windowing_realize_window (GtkSocket *socket) +{ + GdkWindow *window = GTK_WIDGET (socket)->window; + XWindowAttributes xattrs; + + XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window), + GDK_WINDOW_XWINDOW (window), + &xattrs); + + XSelectInput (GDK_WINDOW_XDISPLAY (window), + GDK_WINDOW_XWINDOW (window), + xattrs.your_event_mask | + SubstructureNotifyMask | SubstructureRedirectMask); +} + +void +_gtk_socket_windowing_end_embedding_toplevel (GtkSocket *socket) +{ + gtk_window_remove_embedded_xid (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (socket))), + GDK_WINDOW_XWINDOW (socket->plug_window)); +} + +void +_gtk_socket_windowing_size_request (GtkSocket *socket) +{ + XSizeHints hints; + long supplied; + + gdk_error_trap_push (); + + socket->request_width = 1; + socket->request_height = 1; + + if (XGetWMNormalHints (GDK_WINDOW_XDISPLAY (socket->plug_window), + GDK_WINDOW_XWINDOW (socket->plug_window), + &hints, &supplied)) + { + 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; + + gdk_error_trap_pop (); +} + +void +_gtk_socket_windowing_send_key_event (GtkSocket *socket, + GdkEvent *gdk_event, + gboolean mask_key_presses) +{ + XEvent xevent; + GdkScreen *screen = gdk_drawable_get_screen (socket->plug_window); + + xevent.xkey.type = (gdk_event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease; + xevent.xkey.window = GDK_WINDOW_XWINDOW (socket->plug_window); + xevent.xkey.root = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen)); + xevent.xkey.subwindow = None; + xevent.xkey.time = gdk_event->key.time; + xevent.xkey.x = 0; + xevent.xkey.y = 0; + xevent.xkey.x_root = 0; + xevent.xkey.y_root = 0; + xevent.xkey.state = gdk_event->key.state; + xevent.xkey.keycode = gdk_event->key.hardware_keycode; + xevent.xkey.same_screen = True;/* FIXME ? */ + + gdk_error_trap_push (); + XSendEvent (GDK_WINDOW_XDISPLAY (socket->plug_window), + GDK_WINDOW_XWINDOW (socket->plug_window), + False, + (mask_key_presses ? KeyPressMask : NoEventMask), + &xevent); + gdk_display_sync (gdk_screen_get_display (screen)); + gdk_error_trap_pop (); +} + +void +_gtk_socket_windowing_focus_change (GtkSocket *socket, + gboolean focus_in) +{ + if (focus_in) + _gtk_xembed_send_focus_message (socket->plug_window, + XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT); + else + _gtk_xembed_send_message (socket->plug_window, + XEMBED_FOCUS_OUT, 0, 0, 0); +} + +void +_gtk_socket_windowing_update_active (GtkSocket *socket, + gboolean active) +{ + _gtk_xembed_send_message (socket->plug_window, + active ? XEMBED_WINDOW_ACTIVATE : XEMBED_WINDOW_DEACTIVATE, + 0, 0, 0); +} + +void +_gtk_socket_windowing_update_modality (GtkSocket *socket, + gboolean modality) +{ + _gtk_xembed_send_message (socket->plug_window, + modality ? XEMBED_MODALITY_ON : XEMBED_MODALITY_OFF, + 0, 0, 0); +} + +void +_gtk_socket_windowing_focus (GtkSocket *socket, + GtkDirectionType direction) +{ + gint detail = -1; + + switch (direction) + { + case GTK_DIR_UP: + case GTK_DIR_LEFT: + case GTK_DIR_TAB_BACKWARD: + detail = XEMBED_FOCUS_LAST; + break; + case GTK_DIR_DOWN: + case GTK_DIR_RIGHT: + case GTK_DIR_TAB_FORWARD: + detail = XEMBED_FOCUS_FIRST; + break; + } + + _gtk_xembed_send_focus_message (socket->plug_window, XEMBED_FOCUS_IN, detail); +} + +void +_gtk_socket_windowing_send_configure_event (GtkSocket *socket) +{ + XEvent event; + gint x, y; + + g_return_if_fail (socket->plug_window != NULL); + + event.xconfigure.type = ConfigureNotify; + + event.xconfigure.event = GDK_WINDOW_XWINDOW (socket->plug_window); + event.xconfigure.window = GDK_WINDOW_XWINDOW (socket->plug_window); + + /* The ICCCM says that synthetic events should have root relative + * coordinates. We still aren't really ICCCM compliant, since + * we don't send events when the real toplevel is moved. + */ + gdk_error_trap_push (); + gdk_window_get_origin (socket->plug_window, &x, &y); + gdk_error_trap_pop (); + + event.xconfigure.x = x; + event.xconfigure.y = y; + 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_WINDOW_XDISPLAY (socket->plug_window), + GDK_WINDOW_XWINDOW (socket->plug_window), + False, NoEventMask, &event); + gdk_display_sync (gtk_widget_get_display (GTK_WIDGET (socket))); + gdk_error_trap_pop (); +} + +void +_gtk_socket_windowing_select_plug_window_input (GtkSocket *socket) +{ + XSelectInput (GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (socket))), + GDK_WINDOW_XWINDOW (socket->plug_window), + StructureNotifyMask | PropertyChangeMask); +} + +void +_gtk_socket_windowing_embed_get_info (GtkSocket *socket) +{ + unsigned long version; + unsigned long flags; + + socket->xembed_version = -1; + if (xembed_get_info (socket->plug_window, &version, &flags)) + { + socket->xembed_version = MIN (GTK_XEMBED_PROTOCOL_VERSION, version); + socket->is_mapped = (flags & XEMBED_MAPPED) != 0; + } + else + { + /* FIXME, we should probably actually check the state before we started */ + socket->is_mapped = TRUE; + } +} + +void +_gtk_socket_windowing_embed_notify (GtkSocket *socket) +{ + _gtk_xembed_send_message (socket->plug_window, + XEMBED_EMBEDDED_NOTIFY, 0, + GDK_WINDOW_XWINDOW (GTK_WIDGET (socket)->window), + socket->xembed_version); +} + +static gboolean +xembed_get_info (GdkWindow *window, + unsigned long *version, + unsigned long *flags) +{ + GdkDisplay *display = gdk_drawable_get_display (window); + Atom xembed_info_atom = gdk_x11_get_xatom_by_name_for_display (display, "_XEMBED_INFO"); + Atom type; + int format; + unsigned long nitems, bytes_after; + unsigned char *data; + unsigned long *data_long; + int status; + + gdk_error_trap_push(); + status = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), + GDK_WINDOW_XWINDOW (window), + xembed_info_atom, + 0, 2, False, + xembed_info_atom, &type, &format, + &nitems, &bytes_after, &data); + gdk_error_trap_pop(); + + if (status != Success) + return FALSE; /* Window vanished? */ + + if (type == None) /* No info property */ + return FALSE; + + if (type != xembed_info_atom) + { + g_warning ("_XEMBED_INFO property has wrong type\n"); + return FALSE; + } + + if (nitems < 2) + { + g_warning ("_XEMBED_INFO too short\n"); + XFree (data); + return FALSE; + } + + data_long = (unsigned long *)data; + if (version) + *version = data_long[0]; + if (flags) + *flags = data_long[1] & XEMBED_MAPPED; + + XFree (data); + return TRUE; +} + +gboolean +_gtk_socket_windowing_embed_get_focus_wrapped (void) +{ + return _gtk_xembed_get_focus_wrapped (); +} + +void +_gtk_socket_windowing_embed_set_focus_wrapped (void) +{ + _gtk_xembed_set_focus_wrapped (); +} + +static void +handle_xembed_message (GtkSocket *socket, + XEmbedMessageType message, + glong detail, + glong data1, + glong data2, + guint32 time) +{ + GTK_NOTE (PLUGSOCKET, + g_message ("GtkSocket: %s received", _gtk_xembed_message_name (message))); + + switch (message) + { + case XEMBED_EMBEDDED_NOTIFY: + case XEMBED_WINDOW_ACTIVATE: + case XEMBED_WINDOW_DEACTIVATE: + case XEMBED_MODALITY_ON: + case XEMBED_MODALITY_OFF: + case XEMBED_FOCUS_IN: + case XEMBED_FOCUS_OUT: + g_warning ("GtkSocket: Invalid _XEMBED message %s received", _gtk_xembed_message_name (message)); + break; + + case XEMBED_REQUEST_FOCUS: + _gtk_socket_claim_focus (socket, TRUE); + break; + + case XEMBED_FOCUS_NEXT: + case XEMBED_FOCUS_PREV: + _gtk_socket_advance_toplevel_focus (socket, + (message == XEMBED_FOCUS_NEXT ? + GTK_DIR_TAB_FORWARD : GTK_DIR_TAB_BACKWARD)); + break; + + case XEMBED_GTK_GRAB_KEY: + _gtk_socket_add_grabbed_key (socket, data1, data2); + break; + case XEMBED_GTK_UNGRAB_KEY: + _gtk_socket_remove_grabbed_key (socket, data1, data2); + break; + + case XEMBED_GRAB_KEY: + case XEMBED_UNGRAB_KEY: + break; + + default: + GTK_NOTE (PLUGSOCKET, + g_message ("GtkSocket: Ignoring unknown _XEMBED message of type %d", message)); + break; + } +} + +GdkFilterReturn +_gtk_socket_windowing_filter_func (GdkXEvent *gdk_xevent, + GdkEvent *event, + gpointer data) +{ + GtkSocket *socket; + GtkWidget *widget; + GdkDisplay *display; + XEvent *xevent; + + GdkFilterReturn return_val; + + socket = GTK_SOCKET (data); + + return_val = GDK_FILTER_CONTINUE; + + if (socket->plug_widget) + return return_val; + + widget = GTK_WIDGET (socket); + xevent = (XEvent *)gdk_xevent; + display = gtk_widget_get_display (widget); + + switch (xevent->type) + { + case ClientMessage: + if (xevent->xclient.message_type == gdk_x11_get_xatom_by_name_for_display (display, "_XEMBED")) + { + _gtk_xembed_push_message (xevent); + handle_xembed_message (socket, + xevent->xclient.data.l[1], + xevent->xclient.data.l[2], + xevent->xclient.data.l[3], + xevent->xclient.data.l[4], + xevent->xclient.data.l[0]); + _gtk_xembed_pop_message (); + + return_val = GDK_FILTER_REMOVE; + } + break; + + case CreateNotify: + { + XCreateWindowEvent *xcwe = &xevent->xcreatewindow; + + if (!socket->plug_window) + { + _gtk_socket_add_window (socket, xcwe->window, FALSE); + + if (socket->plug_window) + { + GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - window created")); + } + } + + return_val = GDK_FILTER_REMOVE; + + break; + } + + case ConfigureRequest: + { + XConfigureRequestEvent *xcre = &xevent->xconfigurerequest; + + if (!socket->plug_window) + _gtk_socket_add_window (socket, xcre->window, FALSE); + + if (socket->plug_window) + { + GtkSocketPrivate *private = _gtk_socket_get_private (socket); + + if (xcre->value_mask & (CWWidth | CWHeight)) + { + GTK_NOTE (PLUGSOCKET, + g_message ("GtkSocket - configure request: %d %d", + socket->request_width, + socket->request_height)); + + private->resize_count++; + gtk_widget_queue_resize (widget); + } + else if (xcre->value_mask & (CWX | CWY)) + { + _gtk_socket_windowing_send_configure_event (socket); + } + /* Ignore stacking requests. */ + + return_val = GDK_FILTER_REMOVE; + } + break; + } + + case DestroyNotify: + { + XDestroyWindowEvent *xdwe = &xevent->xdestroywindow; + + /* Note that we get destroy notifies both from SubstructureNotify on + * our window and StructureNotify on socket->plug_window + */ + if (socket->plug_window && (xdwe->window == GDK_WINDOW_XWINDOW (socket->plug_window))) + { + gboolean result; + + GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - destroy notify")); + + gdk_window_destroy_notify (socket->plug_window); + _gtk_socket_end_embedding (socket); + + g_object_ref (widget); + g_signal_emit_by_name (widget, "plug_removed", 0, &result); + if (!result) + gtk_widget_destroy (widget); + g_object_unref (widget); + + return_val = GDK_FILTER_REMOVE; + } + break; + } + + case FocusIn: + if (xevent->xfocus.mode == EMBEDDED_APP_WANTS_FOCUS) + { + _gtk_socket_claim_focus (socket, TRUE); + } + 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, FALSE); + } + + if (socket->plug_window) + { + GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - Map Request")); + + _gtk_socket_handle_map_request (socket); + return_val = GDK_FILTER_REMOVE; + } + break; + case PropertyNotify: + if (socket->plug_window && + xevent->xproperty.window == GDK_WINDOW_XWINDOW (socket->plug_window)) + { + GdkDragProtocol protocol; + + if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_NORMAL_HINTS")) + { + GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - received PropertyNotify for plug's WM_NORMAL_HINTS")); + socket->have_size = FALSE; + gtk_widget_queue_resize (widget); + return_val = GDK_FILTER_REMOVE; + } + else if ((xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "XdndAware")) || + (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_RECEIVER_INFO"))) + { + gdk_error_trap_push (); + if (gdk_drag_get_protocol_for_display (display, + xevent->xproperty.window, + &protocol)) + gtk_drag_dest_set_proxy (GTK_WIDGET (socket), + socket->plug_window, + protocol, TRUE); + + gdk_display_sync (display); + gdk_error_trap_pop (); + return_val = GDK_FILTER_REMOVE; + } + else if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_XEMBED_INFO")) + { + unsigned long flags; + + if (xembed_get_info (socket->plug_window, NULL, &flags)) + { + gboolean was_mapped = socket->is_mapped; + gboolean is_mapped = (flags & XEMBED_MAPPED) != 0; + + if (was_mapped != is_mapped) + { + if (is_mapped) + _gtk_socket_handle_map_request (socket); + else + { + gdk_error_trap_push (); + gdk_window_show (socket->plug_window); + gdk_flush (); + gdk_error_trap_pop (); + + _gtk_socket_unmap_notify (socket); + } + } + } + return_val = GDK_FILTER_REMOVE; + } + } + break; + case ReparentNotify: + { + XReparentEvent *xre = &xevent->xreparent; + + GTK_NOTE (PLUGSOCKET, g_message ("GtkPlug: ReparentNotify received\n")); + if (!socket->plug_window && xre->parent == GDK_WINDOW_XWINDOW (widget->window)) + { + _gtk_socket_add_window (socket, xre->window, FALSE); + + if (socket->plug_window) + { + GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - window reparented")); + } + + return_val = GDK_FILTER_REMOVE; + } + + break; + } + case UnmapNotify: + if (socket->plug_window && + xevent->xunmap.window == GDK_WINDOW_XWINDOW (socket->plug_window)) + { + GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - Unmap notify")); + + _gtk_socket_unmap_notify (socket); + return_val = GDK_FILTER_REMOVE; + } + break; + + } + + return return_val; +} diff --git a/gtk/gtkwin32embed.c b/gtk/gtkwin32embed.c new file mode 100644 index 0000000000..609ec5b1cb --- /dev/null +++ b/gtk/gtkwin32embed.c @@ -0,0 +1,135 @@ +/* GTK - The GIMP Toolkit + * gtkwin32embed.c: Utilities for Win32 embedding + * Copyright (C) 2005, Novell, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* By Tor Lillqvist 2005 */ + +#include + +#include "win32/gdkwin32.h" + +#include "gtkwin32embed.h" + +static guint message_type[GTK_WIN32_EMBED_LAST]; + +static GSList *current_messages; + +guint +_gtk_win32_embed_message_type (GtkWin32EmbedMessageType type) +{ + if (type < 0 || type >= GTK_WIN32_EMBED_LAST) + return 0; + + if (message_type[type] == 0) + { + char name[100]; + sprintf (name, "gtk-win32-embed:%d", type); + message_type[type] = RegisterWindowMessage (name); + } + + return message_type[type]; +} + +void +_gtk_win32_embed_push_message (MSG *msg) +{ + MSG *message = g_new (MSG, 1); + + *message = *msg; + + current_messages = g_slist_prepend (current_messages, message); +} + +void +_gtk_win32_embed_pop_message (void) +{ + MSG *message = current_messages->data; + + current_messages = g_slist_delete_link (current_messages, current_messages); + + g_free (message); +} + +void +_gtk_win32_embed_send (GdkWindow *recipient, + GtkWin32EmbedMessageType message, + gint wparam, + gint lparam) +{ + PostMessage (GDK_WINDOW_HWND (recipient), + _gtk_win32_embed_message_type (message), + wparam, lparam); +} + +void +_gtk_win32_embed_send_focus_message (GdkWindow *recipient, + GtkWin32EmbedMessageType message, + gint wparam) +{ + int lparam = 0; + + if (!recipient) + return; + + g_return_if_fail (GDK_IS_WINDOW (recipient)); + g_return_if_fail (message == GTK_WIN32_EMBED_FOCUS_IN || + message == GTK_WIN32_EMBED_FOCUS_NEXT || + message == GTK_WIN32_EMBED_FOCUS_PREV); + + if (current_messages) + { + MSG *msg = current_messages->data; + if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_IN) || + msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_NEXT) || + msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_PREV)) + lparam = (msg->lParam & GTK_WIN32_EMBED_FOCUS_WRAPAROUND); + } + + _gtk_win32_embed_send (recipient, message, wparam, lparam); +} + +void +_gtk_win32_embed_set_focus_wrapped (void) +{ + MSG *msg; + + g_return_if_fail (current_messages != NULL); + + msg = current_messages->data; + + g_return_if_fail (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_PREV) || + msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_NEXT)); + + msg->lParam |= GTK_WIN32_EMBED_FOCUS_WRAPAROUND; +} + +gboolean +_gtk_win32_embed_get_focus_wrapped (void) +{ + MSG *msg; + + g_return_val_if_fail (current_messages != NULL, FALSE); + + msg = current_messages->data; + + return (msg->lParam & GTK_WIN32_EMBED_FOCUS_WRAPAROUND) != 0; +} + + + diff --git a/gtk/gtkwin32embed.h b/gtk/gtkwin32embed.h new file mode 100644 index 0000000000..4e2223ef33 --- /dev/null +++ b/gtk/gtkwin32embed.h @@ -0,0 +1,95 @@ +/* GTK - The GIMP Toolkit + * gtkwin32embed.h: Utilities for Win32 embedding + * Copyright (C) 2005, Novell, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* By Tor Lillqvist 2005 */ + +#ifndef __GTK_WIN32_EMBED_H__ +#define __GTK_WIN32_EMBED_H__ + +G_BEGIN_DECLS + +#define GTK_WIN32_EMBED_PROTOCOL_VERSION 1 + +/* + * When the plug and socket are in separate processes they use a + * simple protocol, more or less based on XEMBED. The protocol uses + * registered window messages. The name passed to + * RegisterWindowMessage() is gtk-win32-embed:%d, with %d being the + * numeric value of an GtkWin32EmbedMessageType enum. Each message + * carries the message type enum value and two integers, the "wparam" + * and "lparam", like all window messages. + * + * So far all the window messages are posted to the other + * process. Maybe some later enhancement will add also messages that + * are sent, i.e. where the sending process waits for the receiving + * process's window procedure to handle the message. + */ + +typedef enum { /* send or post? */ + /* First those sent from the socket + * to the plug + */ + GTK_WIN32_EMBED_WINDOW_ACTIVATE, /* post */ + GTK_WIN32_EMBED_WINDOW_DEACTIVATE, /* post */ + GTK_WIN32_EMBED_FOCUS_IN, /* post */ + GTK_WIN32_EMBED_FOCUS_OUT, /* post */ + GTK_WIN32_EMBED_MODALITY_ON, /* post */ + GTK_WIN32_EMBED_MODALITY_OFF, /* post */ + + /* Then the ones sent from the plug + * to the socket. + */ + GTK_WIN32_EMBED_PARENT_NOTIFY, /* post */ + GTK_WIN32_EMBED_EVENT_PLUG_MAPPED, /* post */ + GTK_WIN32_EMBED_PLUG_RESIZED, /* post */ + GTK_WIN32_EMBED_REQUEST_FOCUS, /* post */ + GTK_WIN32_EMBED_FOCUS_NEXT, /* post */ + GTK_WIN32_EMBED_FOCUS_PREV, /* post */ + GTK_WIN32_EMBED_GRAB_KEY, /* post */ + GTK_WIN32_EMBED_UNGRAB_KEY, /* post */ + GTK_WIN32_EMBED_LAST +} GtkWin32EmbedMessageType; + +/* wParam values for GTK_WIN32_EMBED_FOCUS_IN: */ +#define GTK_WIN32_EMBED_FOCUS_CURRENT 0 +#define GTK_WIN32_EMBED_FOCUS_FIRST 1 +#define GTK_WIN32_EMBED_FOCUS_LAST 2 + +/* Flags for lParam in GTK_WIN32_EMBED_FOCUS_IN, GTK_WIN32_EMBED_FOCUS_NEXT, + * GTK_WIN32_EMBED_FOCUS_PREV + */ +#define GTK_WIN32_EMBED_FOCUS_WRAPAROUND (1 << 0) + +guint _gtk_win32_embed_message_type (GtkWin32EmbedMessageType type); +void _gtk_win32_embed_push_message (MSG *msg); +void _gtk_win32_embed_pop_message (void); +void _gtk_win32_embed_send (GdkWindow *recipient, + GtkWin32EmbedMessageType message, + gint wparam, + gint lparam); +void _gtk_win32_embed_send_focus_message (GdkWindow *recipient, + GtkWin32EmbedMessageType message, + gint wparam); +void _gtk_win32_embed_set_focus_wrapped (void); +gboolean _gtk_win32_embed_get_focus_wrapped (void); + +G_END_DECLS + +#endif /* __GTK_WIN32_EMBED_H__ */