static void
spaning_renderer_render (GtkCellRenderer      *cell,
                         cairo_t              *cr,
			 GtkWidget            *widget,
			 const GdkRectangle   *background_area,
			 const GdkRectangle   *cell_area,
			 GtkCellRendererState  flags)
{
	GiggleSpaningRendererPriv *priv = GET_PRIV (cell);
	GtkTreeViewColumn         *first_column, *last_column;
	GdkRectangle               first_area, last_area;
	int                        first = priv->first;
	int                        last = priv->last;
	GdkRectangle               real_background_area;
	GdkRectangle               real_cell_area;
	GList                     *columns;

	columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (widget));

	if (last < 0)
		last = g_list_length (columns) - 1;

	first_column = g_list_nth_data (columns, first);
	last_column = g_list_nth_data (columns, last);

	g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (first_column));
	g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (last_column));

	gtk_tree_view_get_cell_area (GTK_TREE_VIEW (widget), NULL, first_column, &first_area);
	gtk_tree_view_get_cell_area (GTK_TREE_VIEW (widget), NULL, last_column, &last_area);

	real_cell_area.x      = first_area.x;
	real_cell_area.y      = cell_area->y;
	real_cell_area.width  = last_area.x + last_area.width - first_area.x;
	real_cell_area.height = cell_area->height;

	gtk_tree_view_get_background_area (GTK_TREE_VIEW (widget), NULL, first_column, &first_area);
	gtk_tree_view_get_background_area (GTK_TREE_VIEW (widget), NULL, last_column, &last_area);

	real_background_area.x      = first_area.x;
	real_background_area.y      = cell_area->y;
	real_background_area.width  = last_area.x + last_area.width - first_area.x;
	real_background_area.height = cell_area->height;

	GTK_CELL_RENDERER_CLASS (giggle_spaning_renderer_parent_class)->render
		(cell, cr, widget, &real_background_area, &real_cell_area, flags);

	g_list_free (columns);
}
Exemple #2
0
static gboolean
qtcTreeViewLeave(GtkWidget *widget, GdkEventMotion *event, void *data)
{
    QTC_UNUSED(event);
    QTC_UNUSED(data);
    if (GTK_IS_TREE_VIEW(widget)) {
        QtCTreeView *tv = qtcTreeViewLookupHash(widget, false);
        if (tv) {
            GtkTreeView *treeView = GTK_TREE_VIEW(widget);
            QtcRect rect = {0, 0, -1, -1 };
            QtcRect alloc = qtcWidgetGetAllocation(widget);

            if (tv->path && tv->column) {
                gtk_tree_view_get_background_area(
                    treeView, tv->path, tv->column, (GdkRectangle*)&rect);
            }
            if (tv->fullWidth) {
                rect.x = 0;
                rect.width = alloc.width;
            }
            if (tv->path) {
                gtk_tree_path_free(tv->path);
            }
            tv->path = NULL;
            tv->column = NULL;

            gtk_tree_view_convert_bin_window_to_widget_coords(
                treeView, rect.x, rect.y, &rect.x, &rect.y);
            gtk_widget_queue_draw_area(
                widget, rect.x, rect.y, rect.width, rect.height);
        }
    }
    return false;
}
static void
gm_cell_renderer_expander_render (GtkCellRenderer      *cell,
                                  GdkWindow            *window,
                                  GtkWidget            *widget,
                                  GdkRectangle         *background_area,
                                  GdkRectangle         *cell_area,
                                  GdkRectangle         *expose_area,
                                  G_GNUC_UNUSED GtkCellRendererState  flags)
{
  GmCellRendererExpander     *expander;
  GmCellRendererExpanderPriv *priv;
  GtkExpanderStyle                expander_style;
  gint                            x_offset, y_offset;
  guint xpad, ypad;
  GtkAllocation allocation;

  expander = (GmCellRendererExpander*) cell;
  priv = GET_PRIV (expander);
  g_object_get (G_OBJECT (cell),
		"xpad", &xpad,
		"ypad", &ypad,
		NULL);
  gtk_widget_get_allocation (widget, &allocation);

  if (priv->animation_node) {
    GtkTreePath *path;
    GdkRectangle rect;

    /* Not sure if I like this ... */
    path = gtk_tree_row_reference_get_path (priv->animation_node);
    gtk_tree_view_get_background_area (priv->animation_view, path,
                                       NULL, &rect);
    gtk_tree_path_free (path);

    if (background_area->y == rect.y)
      expander_style = priv->animation_style;
    else
      expander_style = priv->expander_style;
  } else
    expander_style = priv->expander_style;

  gm_cell_renderer_expander_get_size (cell, widget, cell_area,
                                      &x_offset, &y_offset,
                                      NULL, NULL);

  gtk_paint_expander (gtk_widget_get_style (widget),
                      window,
                      GTK_STATE_NORMAL,
                      expose_area,
                      widget,
                      "treeview",
                      cell_area->x + x_offset + xpad + priv->expander_size / 2,
                      cell_area->y + y_offset + ypad + priv->expander_size / 2,
                      expander_style);
  gtk_paint_hline (gtk_widget_get_style (widget), window, GTK_STATE_NORMAL, NULL, widget, NULL, 0,
                   allocation.width, cell_area->y + cell_area->height);
}
Exemple #4
0
static void
usage_view_update_row_and_header_height (PlannerView *view)
{
	GtkTreeView        *tv;
	PlannerUsageChart  *chart;
	gint                row_height;
	gint                header_height;
	gint                height;
	GList              *cols, *l;
	GtkTreeViewColumn  *col;
	GtkRequisition      req;
	GtkTreePath       *path;
	GdkRectangle       rect;

	tv = GTK_TREE_VIEW (PLANNER_USAGE_VIEW (view)->priv->tree);
	chart = PLANNER_USAGE_VIEW (view)->priv->chart;

	/* Get the row and header heights. */
	cols = gtk_tree_view_get_columns (tv);
	row_height = 0;
	header_height = 0;

	path = gtk_tree_path_new_first ();

	for (l = cols; l; l = l->next) {
		col = l->data;

		gtk_widget_size_request (col->button, &req);
		header_height = MAX (header_height, req.height);

		gtk_tree_view_column_cell_get_size (col,
						    NULL,
						    NULL,
						    NULL,
						    NULL,
						    &height);
		row_height = MAX (row_height, height);

		gtk_tree_view_get_background_area (tv,
						   path,
						   col,
						   &rect);

		row_height = MAX (row_height, rect.height);
	}

	if (path)
		gtk_tree_path_free (path);

	g_list_free (cols);

	/* Sync with the chart widget. */
	g_object_set (chart,
		      "header_height", header_height,
		      "row_height", row_height,
		      NULL);
}
Exemple #5
0
static void
cv_tree_focus (chan *ch)
{
	GtkTreeView *tree = ((treeview *)ch->cv)->tree;
	GtkTreeModel *model = gtk_tree_view_get_model (tree);
	GtkTreePath *path;
	GtkTreeIter parent;
	GdkRectangle cell_rect;
	GdkRectangle vis_rect;
	gint dest_y;

	/* expand the parent node */
	if (gtk_tree_model_iter_parent (model, &parent, &ch->iter))
	{
		path = gtk_tree_model_get_path (model, &parent);
		if (path)
		{
			/*if (!gtk_tree_view_row_expanded (tree, path))
			{
				gtk_tree_path_free (path);
				return;
			}*/
			gtk_tree_view_expand_row (tree, path, FALSE);
			gtk_tree_path_free (path);
		}
	}

	path = gtk_tree_model_get_path (model, &ch->iter);
	if (path)
	{
		/* This full section does what
		 * gtk_tree_view_scroll_to_cell (tree, path, NULL, TRUE, 0.5, 0.5);
		 * does, except it only scrolls the window if the provided cell is
		 * not visible. Basic algorithm taken from gtktreeview.c */

		/* obtain information to see if the cell is visible */
		gtk_tree_view_get_background_area (tree, path, NULL, &cell_rect);
		gtk_tree_view_get_visible_rect (tree, &vis_rect);

		/* The cordinates aren't offset correctly */
		gtk_tree_view_widget_to_tree_coords( tree, cell_rect.x, cell_rect.y, NULL, &cell_rect.y );

		/* only need to scroll if out of bounds */
		if (cell_rect.y < vis_rect.y ||
				cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
		{
			dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * 0.5);
			if (dest_y < 0)
				dest_y = 0;
			gtk_tree_view_scroll_to_point (tree, -1, dest_y);
		}
		/* theft done, now make it focused like */
		gtk_tree_view_set_cursor (tree, path, NULL, FALSE);
		gtk_tree_path_free (path);
	}
}
Exemple #6
0
static VALUE
rg_get_background_area(VALUE self, VALUE path, VALUE column)
{
    GdkRectangle rect;
    gtk_tree_view_get_background_area(_SELF(self), 
                                      NIL_P(path) ? NULL : RVAL2GTKTREEPATH(path),
                                      NIL_P(column) ? NULL : TREEVIEW_COL(column), 
                                      &rect);
    return BOXED2RVAL(&rect, GDK_TYPE_RECTANGLE);
}
Exemple #7
0
static void
test_position (GtkTreeView *tree_view,
	       GtkTreePath *path,
	       gboolean     use_align,
	       gdouble      row_align)
{
	gint pos;
	gchar *path_str;
	GdkRectangle rect;
	GtkTreeModel *model;
	gint row_start;

	/* Get the location of the path we scrolled to */
	gtk_tree_view_get_background_area (GTK_TREE_VIEW (tree_view),
					   path, NULL, &rect);

	row_start = get_row_start_for_index (GTK_TREE_VIEW (tree_view),
					     gtk_tree_path_get_indices (path)[0]);

	/* Ugh */
	pos = get_pos_from_path (GTK_TREE_VIEW (tree_view),
				 path, rect.height,
			         gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (tree_view)));

	/* This is only tested for during test_single() */
	model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
	if (gtk_tree_model_iter_n_children (model, NULL) == 1) {
                GtkAllocation allocation;
		GtkTreePath *tmppath;

		/* Test nothing is dangling at the bottom; read
		 * description for test_single() for more information.
		 */

		/* FIXME: hardcoded width */
                gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
		if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree_view), 0, allocation.height - 30, &tmppath, NULL, NULL, NULL)) {
			g_assert_not_reached ();
			gtk_tree_path_free (tmppath);
		}
	}

	path_str = gtk_tree_path_to_string (path);
	if (use_align) {
		assert_position_with_align (tree_view, pos, rect.y,
                                            row_start, rect.height, row_align);
	} else {
		assert_position_without_align (tree_view, row_start, rect.height);
	}

	g_free (path_str);
}
Exemple #8
0
static int
get_row_start_for_index (GtkTreeView *tree_view, int index)
{
	gint height1, height2;
	gint row_start;
	GtkTreePath *path;
	GdkRectangle rect;

	path = gtk_tree_path_new_from_indices (0, -1);
	gtk_tree_view_get_background_area (tree_view, path, NULL, &rect);
	height1 = rect.height;

	gtk_tree_path_next (path);
	gtk_tree_view_get_background_area (tree_view, path, NULL, &rect);
	height2 = rect.height;
	gtk_tree_path_free (path);

	row_start = (index / 2) * height1 + (index / 2) * height2;
	if (index % 2)
		row_start += height1;

	return row_start;
}
Exemple #9
0
static void
maybe_check_cursor_position (GtkTreeView *treeview,
                             gint         x,
                             gint         y,
                             gint         width,
                             gint         height,
                             ThemeMatchData *match_data)
{
  GtkTreePath *cursor_path;
  GdkRectangle cursor_rect;
  GdkRectangle paint_rect;

  gtk_tree_view_get_cursor (treeview, &cursor_path, NULL);
  if (!cursor_path)
    return;

  /* we only really care about the vertical position here */

  gtk_tree_view_get_background_area (treeview, cursor_path, NULL, &cursor_rect);
  gtk_tree_path_free (cursor_path);

  paint_rect.y = y;
  paint_rect.height = height;

  paint_rect.x = cursor_rect.x = x;
  paint_rect.width = cursor_rect.width = width;

  if (!gdk_rectangle_intersect (&paint_rect, &cursor_rect, &paint_rect))
    return;

  /* We're painting the cursor row background, so distinguish between focused
   * and non-focused treeview so that we can paint the passive focus ring when
   * non-focused. (gtk_paint_focus is used to paint the focus ring when focused.)
   * Knowing that treeview always uses GTK_SHADOW_NONE, it should be (more or
   * less) safe to (ab)use it for passive focus.
   *
   * Passive focus:
   *   function = FLAT_BOX
   *   state    = SELECTED / NORMAL
   *   shadow   = OUT
   *
   * Selection / normal row:
   *   function = FLAT_BOX
   *   state    = SELECTED / NORMAL
   *   shadow   = NONE
   */
  if (!gtk_widget_has_focus (GTK_WIDGET (treeview)))
    match_data->shadow = GTK_SHADOW_OUT;
}
Exemple #10
0
static void
test_editable_position (GtkWidget   *tree_view,
			GtkWidget   *editable,
			GtkTreePath *cursor_path)
{
        GtkAllocation allocation;
	GdkRectangle rect;

	gtk_tree_view_get_background_area (GTK_TREE_VIEW (tree_view),
					   cursor_path, NULL, &rect);

	/* There are all in bin_window coordinates */
        gtk_widget_get_allocation (editable, &allocation);
        g_assert (allocation.y == rect.y + ((rect.height - allocation.height) / 2));
}
static void
gossip_cell_renderer_expander_render (GtkCellRenderer      *cell,
                                      cairo_t              *cr,
                                      GtkWidget            *widget,
                                      const GdkRectangle   *background_area,
                                      const GdkRectangle   *cell_area,
                                      GtkCellRendererState  flags)
{
    GossipCellRendererExpander     *expander;
    GossipCellRendererExpanderPriv *priv;
    GtkExpanderStyle                expander_style;
    gint                            x_offset, y_offset;
    gint                            xpad, ypad;

    expander = (GossipCellRendererExpander*) cell;
    priv = GET_PRIV (expander);

    if (priv->animation_node) {
        GtkTreePath *path;
        GdkRectangle rect;

        /* Not sure if I like this ... */
        path = gtk_tree_row_reference_get_path (priv->animation_node);
        gtk_tree_view_get_background_area (priv->animation_view, path,
                                           NULL, &rect);
        gtk_tree_path_free (path);

        if (background_area->y == rect.y)
            expander_style = priv->animation_style;
        else
            expander_style = priv->expander_style;
    } else
        expander_style = priv->expander_style;

    gossip_cell_renderer_expander_get_size (cell, widget, cell_area,
                                            &x_offset, &y_offset,
                                            NULL, NULL);
    gtk_cell_renderer_get_padding (cell, &xpad, &ypad);

    gtk_paint_expander (gtk_widget_get_style (widget),
                        cr,
                        GTK_STATE_NORMAL,
                        widget,
                        "treeview",
                        cell_area->x + x_offset + xpad + priv->expander_size / 2,
                        cell_area->y + y_offset + ypad + priv->expander_size / 2,
                        expander_style);
}
static void
empathy_cell_renderer_expander_render (GtkCellRenderer      *cell,
				      GdkWindow            *window,
				      GtkWidget            *widget,
				      GdkRectangle         *background_area,
				      GdkRectangle         *cell_area,
				      GdkRectangle         *expose_area,
				      GtkCellRendererState  flags)
{
	EmpathyCellRendererExpander     *expander;
	EmpathyCellRendererExpanderPriv *priv;
	GtkExpanderStyle                expander_style;
	gint                            x_offset, y_offset;

	expander = (EmpathyCellRendererExpander*) cell;
	priv = GET_PRIV (expander);

	if (priv->animation_node) {
		GtkTreePath *path;
		GdkRectangle rect;

		/* Not sure if I like this ... */
		path = gtk_tree_row_reference_get_path (priv->animation_node);
		gtk_tree_view_get_background_area (priv->animation_view, path,
						   NULL, &rect);
		gtk_tree_path_free (path);

		if (background_area->y == rect.y)
			expander_style = priv->animation_style;
		else
			expander_style = priv->expander_style;
	} else
		expander_style = priv->expander_style;

	empathy_cell_renderer_expander_get_size (cell, widget, cell_area,
						&x_offset, &y_offset,
						NULL, NULL);

	gtk_paint_expander (widget->style,
			    window,
			    GTK_STATE_NORMAL,
			    expose_area,
			    widget,
			    "treeview",
			    cell_area->x + x_offset + cell->xpad + priv->expander_size / 2,
			    cell_area->y + y_offset + cell->ypad + priv->expander_size / 2,
			    expander_style);
}
static void
invalidate_node (GtkTreeView *tree_view,
		 GtkTreePath *path)
{
       GdkWindow    *bin_window;
       GdkRectangle  rect;

       bin_window = gtk_tree_view_get_bin_window (tree_view);

       gtk_tree_view_get_background_area (tree_view, path, NULL, &rect);

       rect.x = 0;
       rect.width = GTK_WIDGET (tree_view)->allocation.width;

       gdk_window_invalidate_rect (bin_window, &rect, TRUE);
}
Exemple #14
0
static void
test_editable_position (GtkWidget   *tree_view,
			GtkWidget   *editable,
			GtkTreePath *cursor_path)
{
	GdkRectangle rect;
	GtkAdjustment *vadj;

	gtk_tree_view_get_background_area (GTK_TREE_VIEW (tree_view),
					   cursor_path, NULL, &rect);

	vadj = gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (tree_view));

	/* There are all in bin_window coordinates */
	g_assert (editable->allocation.y == rect.y + ((rect.height - editable->allocation.height) / 2));
}
Exemple #15
0
static void
cb_realize_treeview (GtkWidget *list, GtkWidget *sw)
{
	GtkRequisition req;
	GdkRectangle rect;
	GtkTreePath *clip = g_object_get_data (G_OBJECT (list), "clip");

	gtk_widget_get_preferred_size (GTK_WIDGET (list), &req, NULL);

	gtk_tree_view_get_background_area (GTK_TREE_VIEW (list),
					   clip, NULL, &rect);

	gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW (sw), req.width);

	gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (sw), rect.y);
}
Exemple #16
0
/* Test for GNOME bugzilla bug 359231 */
static void
test_bug359231 (void)
{
	int i;
	int height1, height2;
	GtkTreePath *path;
	GtkTreeIter iter, child;
	GtkTreeStore *store;
	GdkRectangle rect;
	ScrollFixture *fixture;

	/* See #359231. */
	g_test_bug ("359231");

	/* Create model (GtkTreeStore in this case) */
	store = gtk_tree_store_new (1, G_TYPE_STRING);

	gtk_tree_store_append (store, &iter, NULL);
	gtk_tree_store_set (store, &iter, 0, "Foo", -1);

	for (i = 0; i < 4; i++) {
		gtk_tree_store_append (store, &child, &iter);
		gtk_tree_store_set (store, &child, 0, "Two\nLines", -1);
	}
	
	fixture = g_new0 (ScrollFixture, 1);
	scroll_fixture_setup (fixture, GTK_TREE_MODEL (store), NULL);
	gtk_widget_show_all (fixture->window);

	while (gtk_events_pending ())
		gtk_main_iteration ();

	/* Prepend some rows at the top, expand */
	gtk_tree_store_prepend (store, &iter, NULL);
	gtk_tree_store_set (store, &iter, 0, "Foo", -1);

	gtk_tree_store_prepend (store, &child, &iter);
	gtk_tree_store_set (store, &child, 0, "Two\nLines", -1);

	gtk_tree_view_expand_all (GTK_TREE_VIEW (fixture->tree_view));

	while (gtk_events_pending ())
		gtk_main_iteration ();

	/* Test if height of row 0:0 is correct */
	path = gtk_tree_path_new_from_indices (0, -1);
	gtk_tree_view_get_background_area (GTK_TREE_VIEW (fixture->tree_view),
					   path, NULL, &rect);
	height1 = rect.height;

	gtk_tree_path_down (path);
	gtk_tree_view_get_background_area (GTK_TREE_VIEW (fixture->tree_view),
					   path, NULL, &rect);
	height2 = rect.height;
	gtk_tree_path_free (path);

	g_assert (height2 > height1);

	/* Clean up; the tear down also cleans up the model */
	scroll_fixture_teardown (fixture, NULL);
}
Exemple #17
0
static void
qtcTreeViewUpdatePosition(GtkWidget *widget, int x, int y)
{
    if (GTK_IS_TREE_VIEW(widget)) {
        QtCTreeView *tv = qtcTreeViewLookupHash(widget, false);
        if (tv) {
            GtkTreeView *treeView = GTK_TREE_VIEW(widget);
            GtkTreePath *path = NULL;
            GtkTreeViewColumn *column = NULL;

            gtk_tree_view_get_path_at_pos(treeView, x, y, &path,
                                          &column, 0L, 0L);

            if (!qtcTreeViewSamePath(tv->path, path)) {
                // prepare update area
                // get old rectangle
                QtcRect oldRect = {0, 0, -1, -1 };
                QtcRect newRect = {0, 0, -1, -1 };
                QtcRect updateRect;
                QtcRect alloc = qtcWidgetGetAllocation(widget);

                if (tv->path && tv->column) {
                    gtk_tree_view_get_background_area(
                        treeView, tv->path, tv->column,
                        (GdkRectangle*)&oldRect);
                }
                if (tv->fullWidth) {
                    oldRect.x = 0;
                    oldRect.width = alloc.width;
                }

                // get new rectangle and update position
                if (path && column) {
                    gtk_tree_view_get_background_area(
                        treeView, path, column, (GdkRectangle*)&newRect);
                }
                if (path && column && tv->fullWidth) {
                    newRect.x = 0;
                    newRect.width = alloc.width;
                }

                // take the union of both rectangles
                if (oldRect.width > 0 && oldRect.height > 0) {
                    if (newRect.width > 0 && newRect.height > 0) {
                        qtcRectUnion(&oldRect, &newRect, &updateRect);
                    } else {
                        updateRect = oldRect;
                    }
                } else {
                    updateRect = newRect;
                }

                // store new cell info
                if (tv->path)
                    gtk_tree_path_free(tv->path);
                tv->path = path ? gtk_tree_path_copy(path) : NULL;
                tv->column = column;

                // convert to widget coordinates and schedule redraw
                gtk_tree_view_convert_bin_window_to_widget_coords(
                    treeView, updateRect.x, updateRect.y,
                    &updateRect.x, &updateRect.y);
                gtk_widget_queue_draw_area(
                    widget, updateRect.x, updateRect.y,
                    updateRect.width, updateRect.height);
            }

            if (path) {
                gtk_tree_path_free(path);
            }
        }
    }
}