Ejemplo n.º 1
0
static VALUE
rg_m_set_icon(int argc, VALUE *argv, VALUE self)
{
    VALUE context, obj, pixmap = Qnil, mask = Qnil, hot_x, hot_y;

    if (argc == 6) {
        rb_scan_args(argc, argv, "60", &context, &obj, &pixmap, &mask, &hot_x, &hot_y);
        gtk_drag_set_icon_pixmap(RVAL2DC(context),
                                 GDK_COLORMAP(RVAL2GOBJ(obj)), 
                                 GDK_PIXMAP(RVAL2GOBJ(pixmap)),
                                 GDK_BITMAP(RVAL2GOBJ(mask)), 
                                 NUM2INT(hot_x), NUM2INT(hot_y));
    } else {
        rb_scan_args(argc, argv, "40", &context, &obj, &hot_x, &hot_y);

        if (TYPE(obj) == T_SYMBOL){
            gtk_drag_set_icon_stock(RVAL2DC(context), rb_id2name(SYM2ID(obj)),
                                    NUM2INT(hot_x), NUM2INT(hot_y));
        } else if (rb_obj_is_kind_of(obj, GTYPE2CLASS(GTK_TYPE_WIDGET))){
            gtk_drag_set_icon_widget(RVAL2DC(context), RVAL2WIDGET(obj),
                                     NUM2INT(hot_x), NUM2INT(hot_y));
        } else if (rb_obj_is_kind_of(obj, GTYPE2CLASS(GDK_TYPE_PIXBUF))){
            gtk_drag_set_icon_pixbuf(RVAL2DC(context),
                                     GDK_PIXBUF(RVAL2GOBJ(obj)),
                                     NUM2INT(hot_x), NUM2INT(hot_y));
        } else {
            rb_raise(rb_eArgError, "invalid argument %s", rb_class2name(CLASS_OF(obj)));
        }
    }
    return self;
}
static void
carrick_list_drag_begin (GtkWidget      *widget,
                         GdkDragContext *context,
                         CarrickList    *list)
{
  CarrickListPrivate *priv = list->priv;
  gint                x, y;

  carrick_service_item_set_active (CARRICK_SERVICE_ITEM (widget), FALSE);

  /* save old place in list for drag-failures */
  gtk_container_child_get (GTK_CONTAINER (priv->box),
                           widget,
                           "position", &priv->drag_position,
                           NULL);
  priv->drop_position = priv->drag_position;

  /* remove widget from list and setup dnd popup window */
  priv->drag_window = gtk_window_new (GTK_WINDOW_POPUP);
  gtk_widget_set_size_request (priv->drag_window,
                               widget->allocation.width,
                               widget->allocation.height);
  gtk_widget_get_pointer (widget, &x, &y);
  gtk_widget_reparent (widget, priv->drag_window);
  gtk_drag_set_icon_widget (context,
                            priv->drag_window,
                            x, y);
}
Ejemplo n.º 3
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.º 4
0
Archivo: testdnd2.c Proyecto: GYGit/gtk
static void
spinner_drag_begin (GtkWidget      *widget,
                    GdkDragContext *context,
                    gpointer        data)
{
  GtkWidget *spinner;

  g_print ("GtkWidget::drag-begin\n");
  spinner = g_object_new (GTK_TYPE_SPINNER,
                          "visible", TRUE,
                          "active",  TRUE,
                          NULL);
  gtk_drag_set_icon_widget (context, spinner, 0, 0);
  g_object_set_data (G_OBJECT (context), "spinner", spinner);
}
Ejemplo n.º 5
0
void wxDropSource::PrepareIcon( int action, GdkDragContext *context )
{
    // get the right icon to display
    wxIcon *icon = NULL;
    if ( action & GDK_ACTION_MOVE )
        icon = &m_iconMove;
    else if ( action & GDK_ACTION_COPY )
        icon = &m_iconCopy;
    else
        icon = &m_iconNone;

    GdkBitmap *mask;
    if ( icon->GetMask() )
        mask = icon->GetMask()->GetBitmap();
    else
        mask = NULL;

    GdkPixmap *pixmap = icon->GetPixmap();

    gint width,height;
    gdk_window_get_size (pixmap, &width, &height);

    GdkColormap *colormap = gtk_widget_get_colormap( m_widget );
    gtk_widget_push_visual (gdk_colormap_get_visual (colormap));
    gtk_widget_push_colormap (colormap);

    m_iconWindow = gtk_window_new (GTK_WINDOW_POPUP);
    gtk_widget_set_events (m_iconWindow, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
    gtk_widget_set_app_paintable (GTK_WIDGET (m_iconWindow), TRUE);

    gtk_widget_pop_visual ();
    gtk_widget_pop_colormap ();

    gtk_widget_set_usize (m_iconWindow, width, height);
    gtk_widget_realize (m_iconWindow);

    gtk_signal_connect( GTK_OBJECT(m_iconWindow), "configure_event",
                        GTK_SIGNAL_FUNC(gtk_dnd_window_configure_callback), (gpointer)this );

    gdk_window_set_back_pixmap (m_iconWindow->window, pixmap, FALSE);

    if (mask)
        gtk_widget_shape_combine_mask (m_iconWindow, mask, 0, 0);

    gtk_drag_set_icon_widget( context, m_iconWindow, 0, 0 );
}
Ejemplo n.º 6
0
int
clip_GTK_DRAGSETICONWIDGET(ClipMachine * cm)
{
        C_object *ccontext = _fetch_co_arg(cm);
	C_widget     *cwid = _fetch_cwidget(cm, _clip_spar(cm, 2));
        gint         hot_x = _clip_parni(cm, 3);
        gint         hot_y = _clip_parni(cm, 4);

	CHECKCWID(cwid, GTK_IS_WIDGET);
	if (!ccontext || ccontext->type != GDK_TYPE_DRAG_CONTEXT)
        	goto err;
	CHECKARG(3, NUMERIC_t);
	CHECKARG(4, NUMERIC_t);

        gtk_drag_set_icon_widget((GdkDragContext*)ccontext->object,
        	GTK_WIDGET(cwid->widget),
        	hot_x, hot_y );

	return 0;
err:
	return 1;
}
Ejemplo n.º 7
0
static void
hand_display_drag_begin (GtkWidget *hand, GdkDragContext *dc, gpointer data /* unused */)
{
	HandDisplay *handdisp = HAND_DISPLAY (hand);
	assert (handdisp->cur_drag >= 0 && handdisp->cur_drag < 52);
	handdisp->cards[handdisp->cur_drag] |= HAND_DISPLAY_INVISIBLE_CARD;
	handdisp->cur_click = -1;
	redraw_card (hand, handdisp->cur_drag);

	/* create drag widget */
	if (drag_win) { /* should be NULL, but happens sometimes */
		gtk_widget_destroy (drag_win);
		drag_win = NULL;
	}
	drag_win = gtk_window_new (GTK_WINDOW_POPUP);
	GtkWidget *card = hand_display_new (HAND_DISPLAY_MODE_CARD);
	hand_display_set_style (HAND_DISPLAY (card), handdisp->style);
	hand_display_card_set_card (HAND_DISPLAY (card), handdisp->cur_drag);
	gtk_container_add (GTK_CONTAINER (drag_win), card);
	gtk_drag_set_icon_widget (dc, drag_win, 0, 0);
	gtk_widget_show_all (drag_win);
}
Ejemplo n.º 8
0
static void
gimp_color_area_drag_begin (GtkWidget      *widget,
                            GdkDragContext *context)
{
  GimpRGB    color;
  GtkWidget *window;
  GtkWidget *frame;
  GtkWidget *color_area;

  window = gtk_window_new (GTK_WINDOW_POPUP);
  gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DND);
  gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (widget));

  gtk_widget_realize (window);

  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
  gtk_container_add (GTK_CONTAINER (window), frame);

  gimp_color_area_get_color (GIMP_COLOR_AREA (widget), &color);

  color_area = gimp_color_area_new (&color,
                                    GIMP_COLOR_AREA (widget)->type,
                                    0);

  gtk_widget_set_size_request (color_area,
                               DRAG_PREVIEW_SIZE, DRAG_PREVIEW_SIZE);
  gtk_container_add (GTK_CONTAINER (frame), color_area);
  gtk_widget_show (color_area);
  gtk_widget_show (frame);

  g_object_set_data_full (G_OBJECT (widget),
                          "gimp-color-area-drag-window",
                          window,
                          (GDestroyNotify) gtk_widget_destroy);

  gtk_drag_set_icon_widget (context, window,
                            DRAG_ICON_OFFSET, DRAG_ICON_OFFSET);
}
Ejemplo n.º 9
0
void DragIcon::useForDrag(GdkDragContext* context, const IntPoint& hotspot)
{
    gtk_drag_set_icon_widget(context, m_window, hotspot.x(), hotspot.y());
}
Ejemplo n.º 10
0
static void
gstyle_color_widget_drag_gesture_update (GtkGestureDrag    *gesture,
                                         gdouble            offset_x,
                                         gdouble            offset_y,
                                         GstyleColorWidget *self)
{
  GdkDragContext *context;
  GdkEventSequence *sequence;
  const GdkEvent *event;
  gdouble start_x, start_y;
  GtkAllocation allocation;
  GstylePaletteWidgetDndLockFlags dnd_lock;
  GtkWidget *container;
  GdkDragAction drag_action;
  gint button;

  g_assert (GTK_IS_GESTURE (gesture));
  g_assert (GSTYLE_IS_COLOR_WIDGET (self));

  dnd_lock = get_palette_widget_dnd_lock (self);
  if ((dnd_lock & GSTYLE_PALETTE_WIDGET_DND_LOCK_FLAGS_DRAG) != 0)
    return;

  button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
  if (!gtk_drag_check_threshold (GTK_WIDGET (self), 0, 0, offset_x, offset_y) ||
      button != GDK_BUTTON_PRIMARY)
    return;

  gtk_widget_get_allocation (GTK_WIDGET (self), &allocation);
  self->dnd_color_widget = gstyle_color_widget_copy (self);

  if (self->filter_func != NULL && GSTYLE_IS_COLOR (self->filtered_color))
    gstyle_color_widget_set_color (self->dnd_color_widget, self->filtered_color);

  self->dnd_window = gtk_window_new (GTK_WINDOW_POPUP);

  gtk_widget_set_size_request (self->dnd_window, allocation.width, allocation.height);
  gtk_window_set_screen (GTK_WINDOW (self->dnd_window), gtk_widget_get_screen (GTK_WIDGET (self)));

  gtk_container_add (GTK_CONTAINER (self->dnd_window), GTK_WIDGET (self->dnd_color_widget));
  gtk_widget_show_all (self->dnd_window);
  gtk_widget_set_opacity (self->dnd_window, GSTYLE_COLOR_WIDGET_DRAG_ICON_OPACITY);

  sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
  gtk_gesture_drag_get_start_point (GTK_GESTURE_DRAG (gesture), &start_x, &start_y);
  event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);

  container = gtk_widget_get_ancestor (GTK_WIDGET (self), GSTYLE_TYPE_PALETTE_WIDGET);
  if (container != NULL && GSTYLE_IS_PALETTE_WIDGET (container))
    drag_action = (GDK_ACTION_MOVE | GDK_ACTION_COPY);
  else
    drag_action = GDK_ACTION_COPY;

  context = gtk_drag_begin_with_coordinates (GTK_WIDGET (self),
                                             self->target_list,
                                             drag_action,
                                             button,
                                             (GdkEvent*)event,
                                             start_x, start_y);

  gtk_drag_set_icon_widget (context, self->dnd_window, 0, 0);
}
Ejemplo n.º 11
0
void wxDropSource::PrepareIcon( int action, GdkDragContext *context )
{
    // get the right icon to display
    wxIcon *icon = NULL;
    if ( action & GDK_ACTION_MOVE )
        icon = &m_iconMove;
    else if ( action & GDK_ACTION_COPY )
        icon = &m_iconCopy;
    else
        icon = &m_iconNone;

#ifndef __WXGTK3__
    GdkBitmap *mask;
    if ( icon->GetMask() )
        mask = *icon->GetMask();
    else
        mask = NULL;

    GdkPixmap *pixmap = icon->GetPixmap();

    GdkColormap *colormap = gtk_widget_get_colormap( m_widget );
    gtk_widget_push_colormap (colormap);
#endif

    m_iconWindow = gtk_window_new (GTK_WINDOW_POPUP);
    gtk_widget_set_events (m_iconWindow, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
    gtk_widget_set_app_paintable (m_iconWindow, TRUE);

#ifdef __WXGTK3__
    gtk_widget_set_visual(m_iconWindow, gtk_widget_get_visual(m_widget));
#else
    gtk_widget_pop_colormap ();
#endif

    gtk_widget_set_size_request (m_iconWindow, icon->GetWidth(), icon->GetHeight());
    gtk_widget_realize (m_iconWindow);

    g_signal_connect (m_iconWindow, "configure_event",
                      G_CALLBACK (gtk_dnd_window_configure_callback), this);

#ifdef __WXGTK3__
    cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(m_iconWindow));
    icon->SetSourceSurface(cr, 0, 0);
    cairo_pattern_t* pattern = cairo_get_source(cr);
    gdk_window_set_background_pattern(gtk_widget_get_window(m_iconWindow), pattern);
    cairo_destroy(cr);
    cairo_surface_t* mask = NULL;
    if (icon->GetMask())
        mask = *icon->GetMask();
    if (mask)
    {
        cairo_region_t* region = gdk_cairo_region_create_from_surface(mask);
        gtk_widget_shape_combine_region(m_iconWindow, region);
        cairo_region_destroy(region);
    }
#else
    gdk_window_set_back_pixmap(gtk_widget_get_window(m_iconWindow), pixmap, false);

    if (mask)
        gtk_widget_shape_combine_mask (m_iconWindow, mask, 0, 0);
#endif

    gtk_drag_set_icon_widget( context, m_iconWindow, 0, 0 );
}