#include "config.h"
#include <stdlib.h>
+
#include "gtkcellrendererprogress.h"
+#include "gtkprivate.h"
#include "gtkintl.h"
+#include "gtkalias.h"
#define GTK_CELL_RENDERER_PROGRESS_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
GTK_TYPE_CELL_RENDERER_PROGRESS, \
GtkCellRendererProgressPrivate))
-#define XPAD 4
-#define YPAD 8
-
enum
{
PROP_0,
static void gtk_cell_renderer_progress_set_value (GtkCellRendererProgress *cellprogress,
gint value);
static void gtk_cell_renderer_progress_set_text (GtkCellRendererProgress *cellprogress,
- gchar *text);
-static void compute_dimensions (GtkWidget *widget,
+ const gchar *text);
+static void compute_dimensions (GtkCellRenderer *cell,
+ GtkWidget *widget,
const gchar *text,
gint *width,
gint *height);
guint flags);
-G_DEFINE_TYPE (GtkCellRendererProgress, gtk_cell_renderer_progress, GTK_TYPE_CELL_RENDERER);
+G_DEFINE_TYPE (GtkCellRendererProgress, gtk_cell_renderer_progress, GTK_TYPE_CELL_RENDERER)
static void
gtk_cell_renderer_progress_class_init (GtkCellRendererProgressClass *klass)
g_param_spec_int ("value",
P_("Value"),
P_("Value of the progress bar"),
- -2, 100, 0,
- G_PARAM_READWRITE));
+ 0, 100, 0,
+ GTK_PARAM_READWRITE));
/**
* GtkCellRendererProgress:text:
P_("Text"),
P_("Text on the progress bar"),
NULL,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_type_class_add_private (object_class,
sizeof (GtkCellRendererProgressPrivate));
cellprogress->priv->text = NULL;
cellprogress->priv->label = NULL;
cellprogress->priv->min_w = -1;
+ cellprogress->priv->min_h = -1;
}
GtkCellRenderer*
gtk_cell_renderer_progress_new (void)
{
- return GTK_CELL_RENDERER (g_object_new (GTK_TYPE_CELL_RENDERER_PROGRESS, NULL));
+ return g_object_new (GTK_TYPE_CELL_RENDERER_PROGRESS, NULL);
}
static void
if (cellprogress->priv->text)
text = g_strdup (cellprogress->priv->text);
- else if (cellprogress->priv->value == GTK_PROGRESS_CELL_FAILED)
- /* Translator hint: this is a label on progress bars inside a tree view.
- */
- text = g_strdup (_("Failed"));
- else if (cellprogress->priv->value == GTK_PROGRESS_CELL_UNKNOWN)
- /* Translator hint: this is a label on progress bars inside a tree view.
- */
- text = g_strdup (_("Unknown"));
else
- /* Translator hint: this is the default label on progress bars
- * inside a tree view. %d will be replaced by the percentage
- */
- text = g_strdup_printf (_("%d %%"), cellprogress->priv->value);
+ /* do not translate the part before the | */
+ text = g_strdup_printf (Q_("progress bar label|%d %%"),
+ cellprogress->priv->value);
g_free (cellprogress->priv->label);
cellprogress->priv->label = text;
static void
gtk_cell_renderer_progress_set_text (GtkCellRendererProgress *cellprogress,
- gchar *text)
+ const gchar *text)
{
gchar *new_text;
}
static void
-compute_dimensions (GtkWidget *widget,
- const gchar *text,
- gint *width,
- gint *height)
+compute_dimensions (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ const gchar *text,
+ gint *width,
+ gint *height)
{
PangoRectangle logical_rect;
PangoLayout *layout;
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
if (width)
- *width = logical_rect.width + XPAD * 2 + widget->style->xthickness * 2;
+ *width = logical_rect.width + cell->xpad * 2 + widget->style->xthickness * 2;
if (height)
- *height = logical_rect.height + YPAD * 2 + widget->style->ythickness * 2;
+ *height = logical_rect.height + cell->ypad * 2 + widget->style->ythickness * 2;
- g_object_unref (G_OBJECT (layout));
+ g_object_unref (layout);
}
static void
{
GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (cell);
gint w, h;
-
+ gchar *text;
+
if (cellprogress->priv->min_w < 0)
- compute_dimensions (widget, _("Unknown"),
- &cellprogress->priv->min_w,
- &cellprogress->priv->min_h);
+ {
+ text = g_strdup_printf (Q_("progress bar label|%d %%"), 100);
+ compute_dimensions (cell, widget, text,
+ &cellprogress->priv->min_w,
+ &cellprogress->priv->min_h);
+ g_free (text);
+ }
- compute_dimensions (widget, cellprogress->priv->label, &w, &h);
+ compute_dimensions (cell, widget, cellprogress->priv->label, &w, &h);
if (width)
- *width = MAX (cellprogress->priv->min_w, w);
+ *width = MAX (cellprogress->priv->min_w, w);
if (height)
*height = MIN (cellprogress->priv->min_h, h);
+
+ /* FIXME: at the moment cell_area is only set when we are requesting
+ * the size for drawing the focus rectangle. We now just return
+ * the last size we used for drawing the progress bar, which will
+ * work for now. Not a really nice solution though.
+ */
+ if (cell_area)
+ {
+ if (width)
+ *width = cell_area->width;
+ if (height)
+ *height = cell_area->height;
+ }
+
+ if (x_offset) *x_offset = 0;
+ if (y_offset) *y_offset = 0;
}
static void
guint flags)
{
GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (cell);
- GdkGC *gc;
PangoLayout *layout;
PangoRectangle logical_rect;
gint x, y, w, h, perc_w, pos;
GdkRectangle clip;
gboolean is_rtl;
+ cairo_t *cr;
is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
- gc = gdk_gc_new (window);
+ cr = gdk_cairo_create (window);
- x = cell_area->x + XPAD;
- y = cell_area->y + YPAD;
+ x = cell_area->x + cell->xpad;
+ y = cell_area->y + cell->ypad;
- w = cell_area->width - XPAD * 2;
- h = cell_area->height - YPAD * 2;
-
- gdk_gc_set_rgb_fg_color (gc, &widget->style->fg[GTK_STATE_NORMAL]);
- gdk_draw_rectangle (window, gc, TRUE, x, y, w, h);
+ w = cell_area->width - cell->xpad * 2;
+ h = cell_area->height - cell->ypad * 2;
+
+ cairo_rectangle (cr, x, y, w, h);
+ gdk_cairo_set_source_color (cr, &widget->style->fg[GTK_STATE_NORMAL]);
+ cairo_fill (cr);
x += widget->style->xthickness;
y += widget->style->ythickness;
w -= widget->style->xthickness * 2;
h -= widget->style->ythickness * 2;
- gdk_gc_set_rgb_fg_color (gc, &widget->style->bg[GTK_STATE_NORMAL]);
- gdk_draw_rectangle (window, gc, TRUE, x, y, w, h);
- gdk_gc_set_rgb_fg_color (gc, &widget->style->bg[GTK_STATE_SELECTED]);
- perc_w = w * cellprogress->priv->value / 100;
- gdk_draw_rectangle (window, gc, TRUE, is_rtl ? (x + w - perc_w) : x, y, perc_w, h);
+ cairo_rectangle (cr, x, y, w, h);
+ gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_NORMAL]);
+ cairo_fill (cr);
+
+ perc_w = w * MAX (0, cellprogress->priv->value) / 100;
+
+ cairo_rectangle (cr, is_rtl ? (x + w - perc_w) : x, y, perc_w, h);
+ gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_SELECTED]);
+ cairo_fill (cr);
layout = gtk_widget_create_pango_layout (widget, cellprogress->priv->label);
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
x + pos, y + (h - logical_rect.height)/2,
layout);
- g_object_unref (G_OBJECT (layout));
- g_object_unref (G_OBJECT (gc));
+ g_object_unref (layout);
+ cairo_destroy (cr);
}
+#define __GTK_CELL_RENDERER_PROGRESS_C__
+#include "gtkaliasdef.c"