Ejemplo n.º 1
0
Archivo: testdnd2.c Proyecto: GYGit/gtk
static void
window_drag_begin (GtkWidget      *widget,
                   GdkDragContext *context,
                   gpointer        data)
{
  GdkPixbuf *pixbuf;
  GtkWidget *window;
  GtkWidget *image;
  int hotspot;

  hotspot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (data), "hotspot"));

  window = g_object_get_data (G_OBJECT (widget), "drag window");
  if (window == NULL)
    {
      window = gtk_window_new (GTK_WINDOW_POPUP);
      g_print ("creating new drag widget\n");
      pixbuf = get_image_pixbuf (GTK_IMAGE (data));
      image = gtk_image_new_from_pixbuf (pixbuf);
      g_object_unref (pixbuf);
      gtk_widget_show (image);
      gtk_container_add (GTK_CONTAINER (window), image);
      g_object_ref (window);
      g_object_set_data (G_OBJECT (widget), "drag window", window);
      g_signal_connect (window, "destroy", G_CALLBACK (window_destroyed), widget);
    }
  else
    g_print ("reusing drag widget\n");

  gtk_drag_set_icon_widget (context, window, 0, 0);

  if (hotspot == CENTER)
    g_signal_connect (widget, "drag-end", G_CALLBACK (window_drag_end), window);
}
Ejemplo n.º 2
0
Archivo: testdnd2.c Proyecto: GYGit/gtk
static void
image_drag_begin (GtkWidget      *widget,
                  GdkDragContext *context,
                  gpointer        data)
{
  GdkPixbuf *pixbuf;
  gint hotspot;
  gint hot_x, hot_y;

  pixbuf = get_image_pixbuf (GTK_IMAGE (data));
  hotspot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (data), "hotspot"));
  switch (hotspot)
    {
    default:
    case TOP_LEFT:
      hot_x = 0;
      hot_y = 0;
      break;
    case CENTER:
      hot_x = gdk_pixbuf_get_width (pixbuf) / 2;
      hot_y = gdk_pixbuf_get_height (pixbuf) / 2;
      break;
    case BOTTOM_RIGHT:
      hot_x = gdk_pixbuf_get_width (pixbuf);
      hot_y = gdk_pixbuf_get_height (pixbuf);
      break;
    }
  gtk_drag_set_icon_pixbuf (context, pixbuf, hot_x, hot_y);
  g_object_unref (pixbuf);
}
Ejemplo n.º 3
0
Archivo: testdnd2.c Proyecto: GYGit/gtk
void
image_drag_data_get (GtkWidget        *widget,
                     GdkDragContext   *context,
                     GtkSelectionData *selection_data,
                     guint             info,
                     guint             time,
                     gpointer          data)
{
  GdkPixbuf *pixbuf;
  const gchar *name;

  switch (info)
    {
    case TARGET_IMAGE:
      pixbuf = get_image_pixbuf (GTK_IMAGE (data));
      gtk_selection_data_set_pixbuf (selection_data, pixbuf);
      g_object_unref (pixbuf);
      break;
    case TARGET_TEXT:
      if (gtk_image_get_storage_type (GTK_IMAGE (data)) == GTK_IMAGE_ICON_NAME)
        gtk_image_get_icon_name (GTK_IMAGE (data), &name, NULL);
      else
        name = "Boo!";
      gtk_selection_data_set_text (selection_data, name, -1);
      break;
    default:
      g_assert_not_reached ();
    }
}
Ejemplo n.º 4
0
static void
drag_begin (GtkWidget      *widget,
            GdkDragContext *context,
            gpointer        data)
{
  GdkPixbuf *pixbuf;

  pixbuf = get_image_pixbuf (GTK_IMAGE (data));
  gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
  g_object_unref (pixbuf);
}
Ejemplo n.º 5
0
static void
copy_image (GtkMenuItem *item,
            gpointer     data)
{
  GtkClipboard *clipboard;
  GdkPixbuf *pixbuf;

  clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
  pixbuf = get_image_pixbuf (GTK_IMAGE (data));

  gtk_clipboard_set_image (clipboard, pixbuf);
  g_object_unref (pixbuf);
}
Ejemplo n.º 6
0
void
drag_data_get  (GtkWidget        *widget,
                GdkDragContext   *context,
                GtkSelectionData *selection_data,
                guint             info,
                guint             time,
                gpointer          data)
{
  GdkPixbuf *pixbuf;

  pixbuf = get_image_pixbuf (GTK_IMAGE (data));
  gtk_selection_data_set_pixbuf (selection_data, pixbuf);
  g_object_unref (pixbuf);
}