示例#1
0
static VALUE
rg_convert_bin_window_to_tree_coords(VALUE self, VALUE bx, VALUE by)
{
    gint tx, ty;
    gtk_tree_view_convert_bin_window_to_tree_coords(_SELF(self),
                                                    NUM2INT(bx), NUM2INT(by),
                                                    &tx, &ty);
    return rb_ary_new3(2, INT2NUM(tx), INT2NUM(ty));
}
/* Scroll function taken/adapted from gtktreeview.c */
static gint
scroll_row_timeout (gpointer data)
{
	GtkTreeView *tree_view = data;
	GdkRectangle visible_rect;
	gint y, x;
	gint offset;
	gfloat value;
	GtkAdjustment* vadj;
	RbTreeDndData *priv_data;

	GDK_THREADS_ENTER ();

	priv_data = g_object_get_data (G_OBJECT (tree_view), RB_TREE_DND_STRING);
	g_return_val_if_fail(priv_data != NULL, TRUE);

	gdk_window_get_pointer (gtk_tree_view_get_bin_window (tree_view), &x, &y, NULL);
	gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &x, &y);
	gtk_tree_view_convert_bin_window_to_tree_coords (tree_view, x, y, &x, &y);

	gtk_tree_view_get_visible_rect (tree_view, &visible_rect);

	/* see if we are near the edge. */
	if (x < visible_rect.x && x > visible_rect.x + visible_rect.width)
	{
		GDK_THREADS_LEAVE ();
		priv_data->scroll_timeout = 0;
		return FALSE;
	}

	offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
	if (offset > 0)
	{
		offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
		if (offset < 0) 
		{
			GDK_THREADS_LEAVE ();
			priv_data->scroll_timeout = 0;
			return FALSE;
		}
	}

	vadj = gtk_tree_view_get_vadjustment (tree_view);
	value = CLAMP (vadj->value + offset, vadj->lower, vadj->upper - vadj->page_size);
	gtk_adjustment_set_value (vadj, value);

	/* don't remove it if we're on the edge and not scrolling */
	if (ABS (vadj->value - value) > 0.0001)
		remove_select_on_drag_timeout(tree_view);

	GDK_THREADS_LEAVE ();

	return TRUE;
}