Example #1
0
static void
relation_arrow_get_bounds (PlannerRelationArrow *arrow,
			   gdouble              *x1,
			   gdouble              *y1,
			   gdouble              *x2,
			   gdouble              *y2)
{
	PlannerRelationArrowPriv *priv;
	GnomeCanvasItem          *item;
	gdouble                   wx1, wy1, wx2, wy2;
	gint                      cx1, cy1, cx2, cy2;
	gint                      i;

	item = GNOME_CANVAS_ITEM (arrow);
	priv = arrow->priv;

	/* Get the items bbox in canvas pixel coordinates. */

	/* Silence warning. */
	wx1 = G_MAXDOUBLE;
	wy1 = G_MAXDOUBLE;
	wx2 = -G_MAXDOUBLE;
	wy2 = -G_MAXDOUBLE;

	for (i = 0; i < priv->num_points; i++) {
		wx1 = MIN (wx1, priv->points[i].x);
		wy1 = MIN (wy1, priv->points[i].y);
		wx2 = MAX (wx2, priv->points[i].x);
		wy2 = MAX (wy2, priv->points[i].y);
	}

	/* We could do better here, but this is good enough. */
	wx1 -= ARROW_SIZE / 2;
	wy1 -= ARROW_SIZE / 2;
	wx2 += ARROW_SIZE / 2;
	wy2 += ARROW_SIZE / 2;

	gnome_canvas_item_i2w (item, &wx1, &wy1);
	gnome_canvas_item_i2w (item, &wx2, &wy2);
	gnome_canvas_w2c (item->canvas, wx1, wy1, &cx1, &cy1);
	gnome_canvas_w2c (item->canvas, wx2, wy2, &cx2, &cy2);

	*x1 = cx1 - 1;
	*y1 = cy1 - 1;
	*x2 = cx2 + 1;
	*y2 = cy2 + 1;
}
/*
 * Handles the events on the ETableFieldChooserItem
 */
static gint
etfci_event (GnomeCanvasItem *item,
             GdkEvent *e)
{
	ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item);
	GnomeCanvas *canvas = item->canvas;
	gint x, y;

	switch (e->type) {
	case GDK_MOTION_NOTIFY:
		gnome_canvas_w2c (canvas, e->motion.x, e->motion.y, &x, &y);

		if (etfci_maybe_start_drag (etfci, x, y))
			etfci_start_drag (etfci, e, x, y);
		break;

	case GDK_BUTTON_PRESS:
		gnome_canvas_w2c (canvas, e->button.x, e->button.y, &x, &y);

		if (e->button.button == 1) {
			etfci->click_x = x;
			etfci->click_y = y;
			etfci->maybe_drag = TRUE;
		}
		break;

	case GDK_BUTTON_RELEASE: {
		etfci->maybe_drag = FALSE;
		break;
	}

	default:
		return FALSE;
	}
	return TRUE;
}
Example #3
0
static gint
gnc_header_event (GnomeCanvasItem *item, GdkEvent *event)
{
    GncHeader *header = GNC_HEADER(item);
    GnomeCanvas *canvas = item->canvas;
    int x, y;
    int col;

    switch (event->type)
    {
    case GDK_MOTION_NOTIFY:

        gnome_canvas_w2c (canvas, event->motion.x, event->motion.y,
                          &x, &y);

        if (header->in_resize)
        {
            int change = x - header->resize_x;
            int new_width;

            if (!header->needs_ungrab)
            {
                gnome_canvas_item_grab (item,
                                        GDK_POINTER_MOTION_MASK |
                                        GDK_BUTTON_RELEASE_MASK,
                                        header->resize_cursor,
                                        event->button.time);
                header->needs_ungrab = TRUE;
            }

            new_width = header->resize_col_width + change;

            if (new_width >= 0)
            {
                header->resize_x = x;
                header->resize_col_width = new_width;
                gnc_header_request_redraw (header);
            }

            break;
        }

        if (pointer_on_resize_line(header, x, y, &col) &&
                gnucash_style_col_is_resizable (header->style, col))
            gdk_window_set_cursor (GTK_WIDGET(canvas)->window,
                                   header->resize_cursor);
        else
            gdk_window_set_cursor (GTK_WIDGET(canvas)->window,
                                   header->normal_cursor);
        break;

    case GDK_BUTTON_PRESS:
    {
        int col;

        if (event->button.button != 1)
            break;

        gnome_canvas_w2c (canvas, event->button.x, event->button.y,
                          &x, &y);

        if (pointer_on_resize_line (header, x, y, &col))
            col = find_resize_col (header, col);
        else
            col = -1;

        if (col > -1)
        {
            CellDimensions *cd;

            cd = gnucash_style_get_cell_dimensions
                 (header->style, 0, col);

            header->in_resize = TRUE;
            header->resize_col = col;
            header->resize_col_width = cd->pixel_width;
            header->resize_x = x;
        }

        break;
    }
    case GDK_BUTTON_RELEASE:
    {
        if (event->button.button != 1)
            break;

        gnome_canvas_w2c (canvas, event->button.x, event->button.y,
                          &x, &y);

        if (header->in_resize)
        {
            if (header->needs_ungrab)
            {
                gnome_canvas_item_ungrab (item,
                                          event->button.time);
                header->needs_ungrab = FALSE;

                gnc_header_resize_column
                (header,
                 header->resize_col,
                 header->resize_col_width);
            }
            header->in_resize = FALSE;
            header->resize_col = -1;
        }

        break;
    }

    case GDK_2BUTTON_PRESS:
    {
        gboolean on_line;
        int ptr_col;
        int resize_col;

        if (event->button.button != 1)
            break;

        gnome_canvas_w2c (canvas, event->button.x, event->button.y,
                          &x, &y);

        on_line = pointer_on_resize_line (header, x, y, &ptr_col);

        /* If we're on a resize line and the column to the right is zero
           width, resize that one. */
        if (on_line)
            resize_col = find_resize_col (header, ptr_col);
        else
            resize_col = ptr_col;

        if (resize_col > -1)
        {
            header->in_resize = FALSE;
            header->resize_col = -1;
            if (header->needs_ungrab)
            {
                gnome_canvas_item_ungrab (item,
                                          event->button.time);
                header->needs_ungrab = FALSE;
            }

            gnc_header_auto_resize_column (header, resize_col);
        }

    }
    break;

    default:
        break;
    }

    return TRUE;
}
Example #4
0
void
gnucash_cursor_configure (GnucashCursor *cursor)
{
    GnomeCanvasItem *item;
    GnucashItemCursor *block_cursor;
    GnucashItemCursor *cell_cursor;
    GnomeCanvas *canvas;
    gint x, y, w, h;
    double wx, wy;

    g_return_if_fail (cursor != NULL);
    g_return_if_fail (GNUCASH_IS_CURSOR (cursor));

    canvas = GNOME_CANVAS(GNOME_CANVAS_ITEM(cursor)->canvas);

    item = GNOME_CANVAS_ITEM (cursor);

    gnucash_cursor_get_pixel_coords (cursor, &x, &y, &w, &h);
    gnome_canvas_item_set (GNOME_CANVAS_ITEM(cursor),
                           "GnomeCanvasGroup::x", (double)x,
                           "GnomeCanvasGroup::y", (double)y,
                           NULL);

    cursor->w = w;
    cursor->h = h + 1;

    item->x1 = cursor->x = x;
    item->y1 = cursor->y = y;
    item->x2 = x + w;
    item->y2 = y + h + 1;

    item = cursor->cursor[GNUCASH_CURSOR_BLOCK];
    block_cursor = GNUCASH_ITEM_CURSOR (item);

    wx = 0;
    wy = 0;

    gnome_canvas_item_i2w (item, &wx, &wy);
    gnome_canvas_w2c (canvas, wx, wy, &block_cursor->x, &block_cursor->y);
    block_cursor->w = w;
    block_cursor->h = h + 1;

    item->x1 = block_cursor->x;
    item->y1 = block_cursor->y;
    item->x2 = block_cursor->x + w;
    item->y2 = block_cursor->y + h + 1;

    item = cursor->cursor[GNUCASH_CURSOR_CELL];
    cell_cursor = GNUCASH_ITEM_CURSOR(item);

    gnucash_sheet_style_get_cell_pixel_rel_coords (cursor->style,
            cell_cursor->row,
            cell_cursor->col,
            &x, &y, &w, &h);
    wx = x - block_cursor->x;
    wy = y;

    gnome_canvas_item_i2w (item, &wx, &wy);
    gnome_canvas_w2c (canvas, wx, wy, &cell_cursor->x, &cell_cursor->y);
    cell_cursor->w = w;
    cell_cursor->h = h;

    item->x1 = cell_cursor->x;
    item->y1 = cell_cursor->y;
    item->x2 = cell_cursor->x + w;
    item->y2 = cell_cursor->y + h;
}
Example #5
0
static void
relation_arrow_draw (GnomeCanvasItem *item,
		     GdkDrawable     *drawable,
		     gint             x,
		     gint             y,
		     gint             width,
		     gint             height)
{
	PlannerRelationArrow     *arrow;
	PlannerRelationArrowPriv *priv;
#ifdef USE_AFFINE
	gdouble                   i2c[6];
	ArtPoint                  i1, i2, c1, c2;
#else
	gdouble                   i2w_dx;
	gdouble                   i2w_dy;
	gdouble                   dx1, dy1, dx2, dy2;
#endif
	gint                      cx1, cy1, cx2, cy2;
	GdkGC                    *gc;
	GdkPoint                  points[4];
	gint                      i;

	arrow = PLANNER_RELATION_ARROW (item);
	priv = arrow->priv;

	gc = gdk_gc_new (drawable);
	gdk_gc_set_line_attributes (gc,
				    1,
				    GDK_LINE_SOLID,
				    GDK_CAP_BUTT,
				    GDK_JOIN_MITER);

	/* Silence warning. */
	cx1 = 0;
	cy1 = 0;
	cx2 = 0;
	cy2 = 0;

#ifdef USE_AFFINE
	/* Get item area in canvas coordinates. */
	gnome_canvas_item_i2c_affine (item, i2c);
#endif

	for (i = 0; i < priv->num_points - 1; i++) {
#ifdef USE_AFFINE
		i1.x = priv->points[i].x;
		i1.y = priv->points[i].y;
		i2.x = priv->points[i+1].x;
		i2.y = priv->points[i+1].y;
		art_affine_point (&c1, &i1, i2c);
		art_affine_point (&c2, &i2, i2c);
		cx1 = floor (c1.x + 0.5) - x;
		cy1 = floor (c1.y + 0.5) - y;
		cx2 = floor (c2.x + 0.5) - x;
		cy2 = floor (c2.y + 0.5) - y;
#else
		i2w_dx = 0.0;
		i2w_dy = 0.0;
		gnome_canvas_item_i2w (item, &i2w_dx, &i2w_dy);

		dx1 = priv->points[i].x;
		dy1 = priv->points[i].y;
		dx2 = priv->points[i+1].x;
		dy2 = priv->points[i+1].y;

		gnome_canvas_w2c (item->canvas,
				  dx1 + i2w_dx,
				  dy1 + i2w_dy,
				  &cx1,
				  &cy1);

		gnome_canvas_w2c (item->canvas,
				  dx2 + i2w_dx,
				  dy2 + i2w_dy,
				  &cx2,
				  &cy2);

		cx1 -= x;
		cy1 -= y;
		cx2 -= x;
		cy2 -= y;
#endif

		gdk_draw_line (drawable,
			       gc,
			       cx1,
			       cy1,
			       cx2,
			       cy2);
	}

	relation_arrow_setup_arrow (priv->arrow_dir,
					points,
					cx1,
					cy1,
					cx2,
					cy2);

	gdk_draw_polygon (drawable,
			  gc,
			  TRUE,
			  (GdkPoint *) &points,
			  4);

	g_object_unref (gc);
}