⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtksocket.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 2 页
字号:
/* 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 "gdk/gdkx.h"#include "gdk/gdkkeysyms.h"#include "gtkwindow.h"#include "gtksignal.h"#include "gtksocket.h"#include "gtkdnd.h"/* 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;guintgtk_socket_get_type (){  static guint socket_type = 0;  if (!socket_type)    {      static const GtkTypeInfo socket_info =      {	"GtkSocket",	sizeof (GtkSocket),	sizeof (GtkSocketClass),	(GtkClassInitFunc) gtk_socket_class_init,	(GtkObjectInitFunc) gtk_socket_init,	(GtkArgSetFunc) NULL,	(GtkArgGetFunc) NULL      };      socket_type = gtk_type_unique (gtk_container_get_type (), &socket_info);    }  return socket_type;}static voidgtk_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_widget_get_type ());  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 voidgtk_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 (){  GtkSocket *socket;  socket = gtk_type_new (gtk_socket_get_type ());  return GTK_WIDGET (socket);}void           gtk_socket_steal (GtkSocket *socket, guint32 id){  GtkWidget *widget;  widget = GTK_WIDGET (socket);    socket->plug_window = gdk_window_lookup (id);  gdk_error_trap_push ();    if (socket->plug_window && socket->plug_window->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 voidgtk_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 voidgtk_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 voidgtk_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 gintgtk_socket_focus_in_event (GtkWidget *widget, GdkEventFocus *event){  GtkSocket *socket;  g_return_val_if_fail (GTK_IS_SOCKET (widget), FALSE);  socket = GTK_SOCKET (widget);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -