]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtksocket.c
Adapt cast macros to standard.
[~andy/gtk] / gtk / gtksocket.c
index c673f617e876c49c68cd9cf414e033cbe5e1684b..d13cd995ec6ad12469e9a0072731b86ba7b08e15 100644 (file)
 
 /* By Owen Taylor <otaylor@gtk.org>              98/4/4 */
 
-#include "gdk/gdkx.h"
+/*
+ * 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 "gdkx.h"
 #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);
@@ -47,14 +56,6 @@ static GdkFilterReturn gtk_socket_filter_func   (GdkXEvent *gdk_xevent,
                                                 GdkEvent *event, 
                                                 gpointer data);
 
-#define DEBUG_PLUGSOCKET
-
-#ifdef DEBUG_PLUGSOCKET
-#define DPRINTF(arg) g_print arg
-#else
-#define DPRINTF(arg)
-#endif
-
 /* From Tk */
 #define EMBEDDED_APP_WANTS_FOCUS NotifyNormal+20
 
@@ -62,10 +63,10 @@ static GdkFilterReturn gtk_socket_filter_func   (GdkXEvent *gdk_xevent,
 
 static GtkWidgetClass *parent_class = NULL;
 
-guint
+GtkType
 gtk_socket_get_type ()
 {
-  static guint socket_type = 0;
+  static GtkType socket_type = 0;
 
   if (!socket_type)
     {
@@ -143,6 +144,8 @@ gtk_socket_steal (GtkSocket *socket, guint32 id)
   
   socket->plug_window = gdk_window_lookup (id);
 
+  gdk_error_trap_push ();
+  
   if (socket->plug_window && socket->plug_window->user_data)
     {
       /*
@@ -158,6 +161,12 @@ gtk_socket_steal (GtkSocket *socket, guint32 id)
   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;
 
@@ -170,6 +179,10 @@ gtk_socket_steal (GtkSocket *socket, guint32 id)
 
   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;
 }
 
@@ -264,6 +277,8 @@ gtk_socket_size_request (GtkWidget      *widget,
     {
       XSizeHints hints;
       long supplied;
+
+      gdk_error_trap_push ();
       
       if (XGetWMNormalHints (GDK_DISPLAY(),
                             GDK_WINDOW_XWINDOW (socket->plug_window),
@@ -288,10 +303,12 @@ gtk_socket_size_request (GtkWidget      *widget,
            }
        }
       socket->have_size = TRUE;        /* don't check again? */
+
+      gdk_error_trap_pop ();
     }
 
-  requisition->width = socket->request_width;
-  requisition->height = socket->request_height;
+  requisition->width = MAX (socket->request_width, 1);
+  requisition->height = MAX (socket->request_height, 1);
 }
 
 static void
@@ -315,21 +332,25 @@ gtk_socket_size_allocate (GtkWidget     *widget,
 
       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);
-             DPRINTF(( "No change: %d %d\n",
-                     allocation->width, allocation->height));
+             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);
-             DPRINTF(("configuring: %d %d\n",
-                     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;
            }
@@ -340,6 +361,8 @@ gtk_socket_size_allocate (GtkWidget     *widget,
              socket->need_map = FALSE;
            }
 
+         gdk_flush ();
+         gdk_error_trap_pop ();
        }
     }
 }
@@ -351,12 +374,15 @@ gtk_socket_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
   g_return_val_if_fail (GTK_IS_SOCKET (widget), FALSE);
   socket = GTK_SOCKET (widget);
 
-  DPRINTF (( "Got focus\n"));
-
   if (socket->focus_in && socket->plug_window)
-    XSetInputFocus (GDK_DISPLAY (),
-                   GDK_WINDOW_XWINDOW (socket->plug_window),
-                   RevertToParent, GDK_CURRENT_TIME);
+    {
+      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;
 }
@@ -399,9 +425,14 @@ gtk_socket_claim_focus (GtkSocket *socket)
   /* FIXME: we might grab the focus even if we don't have
    * it as an app... (and see _focus_in ()) */
   if (socket->plug_window)
-    XSetInputFocus (GDK_DISPLAY (),
-                   GDK_WINDOW_XWINDOW (socket->plug_window),
-                   RevertToParent, GDK_CURRENT_TIME);
+    {
+      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 
@@ -456,10 +487,14 @@ gtk_socket_focus (GtkContainer *container, GtkDirectionType direction)
          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
@@ -489,10 +524,13 @@ gtk_socket_send_configure_event (GtkSocket *socket)
   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
@@ -505,17 +543,23 @@ gtk_socket_add_window (GtkSocket *socket, guint32 xid)
     {
       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);
@@ -553,22 +597,24 @@ gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
 
        if (!socket->plug_window)
          {
-           g_print("Here!\n");
-
            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;
-           
-           DPRINTF(("Window created with size: %d %d\n",
-                    socket->request_width,
-                    socket->request_height));
+
+           GTK_NOTE(PLUGSOCKET,
+                    g_message ("GtkSocket - window created with size: %d %d",
+                               socket->request_width,
+                               socket->request_height));
            
            gtk_widget_queue_resize (widget);
          }
@@ -593,9 +639,10 @@ gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
                socket->request_height = xcre->height;
                socket->have_size = TRUE;
                
-               DPRINTF(("Configure request: %d %d\n",
-                       socket->request_width,
-                       socket->request_height));
+               GTK_NOTE(PLUGSOCKET,
+                        g_message ("GtkSocket - configure request: %d %d",
+                                   socket->request_width,
+                                   socket->request_height));
                
                gtk_widget_queue_resize (widget);
              }
@@ -618,8 +665,9 @@ gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
            (xdwe->window == GDK_WINDOW_XWINDOW (socket->plug_window)))
          {
            GtkWidget *toplevel;
-           
-           DPRINTF(("Destroy Notify\n"));
+
+           GTK_NOTE(PLUGSOCKET,
+                    g_message ("GtkSocket - destroy notify"));
            
            toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
            if (toplevel && GTK_IS_WINDOW (toplevel))
@@ -665,9 +713,13 @@ gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
       if (xevent->xmaprequest.window ==
          GDK_WINDOW_XWINDOW (socket->plug_window))
        {
-         DPRINTF(("Map Request\n"));
-           
+         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;
        }
@@ -681,10 +733,13 @@ gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
          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;
        }
@@ -692,3 +747,27 @@ gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
 
   return return_val;
 }
+
+#elif defined (GDK_WINDOWING_WIN32)
+
+guint
+gtk_socket_get_type ()
+{
+  g_error ("GtkSocket not implemented");
+  return 42;
+}
+
+GtkWidget*
+gtk_socket_new ()
+{
+  g_error ("GtkSocket not implemented");
+  return NULL;
+}
+
+void           
+gtk_socket_steal (GtkSocket *socket, guint32 id)
+{
+  g_error ("GtkSocket not implemented");
+}
+
+#endif /* GDK_WINDOWING */