[gtk+/wip/matthiasc/kill-key-events2: 7/10] testgtk: Drop snapshot



commit 4d17d03991a7839e5d5bbb95a09af182358cf0e6
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 3 13:01:47 2018 +0100

    testgtk: Drop snapshot
    
    This needs to be redone with modern snapshotting infrastructure.
    Lets drop it for now, it is somewhat duplicative with inspector
    features.

 tests/testgtk.c |  311 -------------------------------------------------------
 1 files changed, 0 insertions(+), 311 deletions(-)
---
diff --git a/tests/testgtk.c b/tests/testgtk.c
index a9ca784..b4f48b2 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -6611,316 +6611,6 @@ create_progress_bar (GtkWidget *widget)
 }
 
 /*
- * Properties
- */
-
-typedef struct {
-  int x;
-  int y;
-  gboolean found;
-  gboolean first;
-  GtkWidget *res_widget;
-} FindWidgetData;
-
-static void
-find_widget (GtkWidget *widget, FindWidgetData *data)
-{
-  GtkAllocation new_allocation;
-  gint x_offset = 0;
-  gint y_offset = 0;
-
-  gtk_widget_get_allocation (widget, &new_allocation);
-
-  if (data->found || !gtk_widget_get_mapped (widget))
-    return;
-
-  /* Note that in the following code, we only count the
-   * position as being inside a WINDOW widget if it is inside
-   * widget->window; points that are outside of widget->window
-   * but within the allocation are not counted. This is consistent
-   * with the way we highlight drag targets.
-   */
-  if (gtk_widget_get_has_window (widget))
-    {
-      new_allocation.x = 0;
-      new_allocation.y = 0;
-    }
-
-  if (gtk_widget_get_parent (widget) && !data->first)
-    {
-      GdkWindow *window = gtk_widget_get_window (widget);
-      while (window != gtk_widget_get_window (gtk_widget_get_parent (widget)))
-       {
-         gint tx, ty, twidth, theight;
-         
-          twidth = gdk_window_get_width (window);
-          theight = gdk_window_get_height (window);
-
-         if (new_allocation.x < 0)
-           {
-             new_allocation.width += new_allocation.x;
-             new_allocation.x = 0;
-           }
-         if (new_allocation.y < 0)
-           {
-             new_allocation.height += new_allocation.y;
-             new_allocation.y = 0;
-           }
-         if (new_allocation.x + new_allocation.width > twidth)
-           new_allocation.width = twidth - new_allocation.x;
-         if (new_allocation.y + new_allocation.height > theight)
-           new_allocation.height = theight - new_allocation.y;
-
-         gdk_window_get_position (window, &tx, &ty);
-         new_allocation.x += tx;
-         x_offset += tx;
-         new_allocation.y += ty;
-         y_offset += ty;
-
-         window = gdk_window_get_parent (window);
-       }
-    }
-
-  if ((data->x >= new_allocation.x) && (data->y >= new_allocation.y) &&
-      (data->x < new_allocation.x + new_allocation.width) && 
-      (data->y < new_allocation.y + new_allocation.height))
-    {
-      /* First, check if the drag is in a valid drop site in
-       * one of our children 
-       */
-      if (GTK_IS_CONTAINER (widget))
-       {
-         FindWidgetData new_data = *data;
-         
-         new_data.x -= x_offset;
-         new_data.y -= y_offset;
-         new_data.found = FALSE;
-         new_data.first = FALSE;
-         
-         gtk_container_forall (GTK_CONTAINER (widget),
-                               (GtkCallback)find_widget,
-                               &new_data);
-         
-         data->found = new_data.found;
-         if (data->found)
-           data->res_widget = new_data.res_widget;
-       }
-
-      /* If not, and this widget is registered as a drop site, check to
-       * emit "drag_motion" to check if we are actually in
-       * a drop site.
-       */
-      if (!data->found)
-       {
-         data->found = TRUE;
-         data->res_widget = widget;
-       }
-    }
-}
-
-static GtkWidget *
-find_widget_at_pointer (GdkDevice *device)
-{
-  GtkWidget *widget = NULL;
-  GdkWindow *pointer_window;
-  gint x, y;
-  FindWidgetData data;
- 
- pointer_window = gdk_device_get_window_at_position (device, NULL, NULL);
- 
- if (pointer_window)
-   {
-     gpointer widget_ptr;
-
-     gdk_window_get_user_data (pointer_window, &widget_ptr);
-     widget = widget_ptr;
-   }
-
- if (widget)
-   {
-     gdk_window_get_device_position (gtk_widget_get_window (widget),
-                                     device,
-                                    &x, &y, NULL);
-     
-     data.x = x;
-     data.y = y;
-     data.found = FALSE;
-     data.first = TRUE;
-
-     find_widget (widget, &data);
-     if (data.found)
-       return data.res_widget;
-     return widget;
-   }
- return NULL;
-}
-
-struct SnapshotData {
-  GtkWidget *toplevel_button;
-  GtkWidget **window;
-  GdkCursor *cursor;
-  gboolean in_query;
-  gboolean is_toplevel;
-  gint handler;
-};
-
-static void
-destroy_snapshot_data (GtkWidget             *widget,
-                      struct SnapshotData *data)
-{
-  if (*data->window)
-    *data->window = NULL;
-  
-  if (data->cursor)
-    {
-      g_object_unref (data->cursor);
-      data->cursor = NULL;
-    }
-
-  if (data->handler)
-    {
-      g_signal_handler_disconnect (widget, data->handler);
-      data->handler = 0;
-    }
-
-  g_free (data);
-}
-
-static gint
-snapshot_widget_event (GtkWidget              *widget,
-                      GdkEvent        *event,
-                      struct SnapshotData *data)
-{
-  GtkWidget *res_widget = NULL;
-
-  if (!data->in_query)
-    return FALSE;
-  
-  if (gdk_event_get_event_type (event) == GDK_BUTTON_RELEASE)
-    {
-      gtk_grab_remove (widget);
-      gdk_seat_ungrab (gdk_event_get_seat (event));
-
-      res_widget = find_widget_at_pointer (gdk_event_get_device (event));
-      if (data->is_toplevel && res_widget)
-       res_widget = gtk_widget_get_toplevel (res_widget);
-      if (res_widget)
-       {
-         cairo_surface_t *surface;
-         GtkWidget *window, *image;
-          GdkPixbuf *pixbuf;
-          int width, height;
-          cairo_t *cr;
-
-          width = gtk_widget_get_allocated_width (res_widget);
-          height = gtk_widget_get_allocated_height (res_widget);
-
-          surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
-
-          cr = cairo_create (surface);
-          gtk_widget_draw (res_widget, cr);
-          cairo_destroy (cr);
-
-          pixbuf = gdk_pixbuf_get_from_surface (surface,
-                                                0, 0,
-                                                width, height);
-          cairo_surface_destroy (surface);
-
-         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-          image = gtk_image_new_from_pixbuf (pixbuf);
-          g_object_unref (pixbuf);
-
-         gtk_container_add (GTK_CONTAINER (window), image);
-         gtk_widget_show (window);
-       }
-
-      data->in_query = FALSE;
-    }
-  return FALSE;
-}
-
-
-static void
-snapshot_widget (GtkButton *button,
-                struct SnapshotData *data)
-{
-  GtkWidget *widget = GTK_WIDGET (button);
-  GdkDevice *device;
-
-  device = gtk_get_current_event_device ();
-  if (device == NULL)
-    return;
-
-  data->is_toplevel = widget == data->toplevel_button;
-
-  if (!data->cursor)
-    data->cursor = gdk_cursor_new_from_name ("crosshair", NULL);
-
-  gdk_seat_grab (gdk_device_get_seat (device),
-                 gtk_widget_get_window (widget),
-                 GDK_SEAT_CAPABILITY_ALL_POINTING,
-                 TRUE, data->cursor, NULL, NULL, NULL);
-
-  g_signal_connect (button, "event",
-                   G_CALLBACK (snapshot_widget_event), data);
-
-  gtk_grab_add (widget);
-
-  data->in_query = TRUE;
-}
-
-static void
-create_snapshot (GtkWidget *widget)
-{
-  static GtkWidget *window = NULL;
-  GtkWidget *button;
-  GtkWidget *vbox;
-  struct SnapshotData *data;
-
-  data = g_new (struct SnapshotData, 1);
-  data->window = &window;
-  data->in_query = FALSE;
-  data->cursor = NULL;
-  data->handler = 0;
-
-  if (!window)
-    {
-      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
-      gtk_window_set_display (GTK_WINDOW (window),
-                             gtk_widget_get_display (widget));      
-
-      data->handler = g_signal_connect (window, "destroy",
-                                       G_CALLBACK (destroy_snapshot_data),
-                                       data);
-
-      gtk_window_set_title (GTK_WINDOW (window), "test snapshot");
-
-      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
-      gtk_container_add (GTK_CONTAINER (window), vbox);
-
-      button = gtk_button_new_with_label ("Snapshot widget");
-      gtk_box_pack_start (GTK_BOX (vbox), button);
-      g_signal_connect (button, "clicked",
-                       G_CALLBACK (snapshot_widget),
-                       data);
-
-      button = gtk_button_new_with_label ("Snapshot toplevel");
-      data->toplevel_button = button;
-      gtk_box_pack_start (GTK_BOX (vbox), button);
-      g_signal_connect (button, "clicked",
-                       G_CALLBACK (snapshot_widget),
-                       data);
-    }
-
-  if (!gtk_widget_get_visible (window))
-    gtk_widget_show (window);
-  else
-    gtk_widget_destroy (window);
-  
-}
-
-/*
  * Test scrolling
  */
 
@@ -7781,7 +7471,6 @@ struct {
   { "saved position", create_saved_position },
   { "scrolled windows", create_scrolled_windows },
   { "size groups", create_size_groups },
-  { "snapshot", create_snapshot },
   { "spinbutton", create_spins },
   { "statusbar", create_statusbar },
   { "test mainloop", create_mainloop, TRUE },


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]