]> Pileus Git - ~andy/gtk/commitdiff
Add a progress cell renderer, based on the one found in Epiphany.
authorMatthias Clasen <matthiasc@src.gnome.org>
Wed, 12 May 2004 16:07:44 +0000 (16:07 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 12 May 2004 16:07:44 +0000 (16:07 +0000)
12 files changed:
ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/gtk/gtk-sections.txt
docs/reference/gtk/gtk.types
gtk/Makefile.am
gtk/gtk.h
gtk/gtkcellrendererprogress.c [new file with mode: 0644]
gtk/gtkcellrendererprogress.h [new file with mode: 0644]
tests/testtreeedit.c

index 296f65b2975039d7e724d58bcc41bdea7e48d23a..c43c8fa76f9be89f4323eabc5695692ba8cda9b7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2004-05-12  Matthias Clasen  <mclasen@redhat.com>
+
+       * tests/testtreeedit.c: Add a progress column.
+
+       * gtk/Makefile.am: Add gtkcellrendererprogress.[hc] in the right
+       places.
+
+       * gtk/gtk.h: Include gtkcellrendererprogress.h.
+
+       * gtk/gtkcellrendererprogress.[hc]: A progress cell renderer,
+       based on the one found in Epiphany.
+
 2004-05-11  Michael Natterer  <mitch@gimp.org>
 
        * gtk/gtkcombobox.c (gtk_combo_box_popup)
index 296f65b2975039d7e724d58bcc41bdea7e48d23a..c43c8fa76f9be89f4323eabc5695692ba8cda9b7 100644 (file)
@@ -1,3 +1,15 @@
+2004-05-12  Matthias Clasen  <mclasen@redhat.com>
+
+       * tests/testtreeedit.c: Add a progress column.
+
+       * gtk/Makefile.am: Add gtkcellrendererprogress.[hc] in the right
+       places.
+
+       * gtk/gtk.h: Include gtkcellrendererprogress.h.
+
+       * gtk/gtkcellrendererprogress.[hc]: A progress cell renderer,
+       based on the one found in Epiphany.
+
 2004-05-11  Michael Natterer  <mitch@gimp.org>
 
        * gtk/gtkcombobox.c (gtk_combo_box_popup)
index 296f65b2975039d7e724d58bcc41bdea7e48d23a..c43c8fa76f9be89f4323eabc5695692ba8cda9b7 100644 (file)
@@ -1,3 +1,15 @@
+2004-05-12  Matthias Clasen  <mclasen@redhat.com>
+
+       * tests/testtreeedit.c: Add a progress column.
+
+       * gtk/Makefile.am: Add gtkcellrendererprogress.[hc] in the right
+       places.
+
+       * gtk/gtk.h: Include gtkcellrendererprogress.h.
+
+       * gtk/gtkcellrendererprogress.[hc]: A progress cell renderer,
+       based on the one found in Epiphany.
+
 2004-05-11  Michael Natterer  <mitch@gimp.org>
 
        * gtk/gtkcombobox.c (gtk_combo_box_popup)
index 296f65b2975039d7e724d58bcc41bdea7e48d23a..c43c8fa76f9be89f4323eabc5695692ba8cda9b7 100644 (file)
@@ -1,3 +1,15 @@
+2004-05-12  Matthias Clasen  <mclasen@redhat.com>
+
+       * tests/testtreeedit.c: Add a progress column.
+
+       * gtk/Makefile.am: Add gtkcellrendererprogress.[hc] in the right
+       places.
+
+       * gtk/gtk.h: Include gtkcellrendererprogress.h.
+
+       * gtk/gtkcellrendererprogress.[hc]: A progress cell renderer,
+       based on the one found in Epiphany.
+
 2004-05-11  Michael Natterer  <mitch@gimp.org>
 
        * gtk/gtkcombobox.c (gtk_combo_box_popup)
index 4b236a7e40ec14dc70d71c115d042eff13ff88b1..685a0e7f8412829833d5e28f8a2a952a21a47eb9 100644 (file)
@@ -1,3 +1,9 @@
+2004-05-12  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.types: Add gtk_cell_renderer_toggle_get_type.
+
+       * gtk/gtk-sections.txt: Add section for GtkCellRendererProgress.
+
 Wed May 12 00:30:57 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gdk/tmpl/gcs.sgml: Additions.
index 0f0ab82039d848b83ce45ad988760662a4afe913..664fc9f9d61c8015bda0ae22a078a5fab7c7e186 100644 (file)
@@ -4007,6 +4007,22 @@ GTK_CELL_RENDERER_TOGGLE_GET_CLASS
 gtk_cell_renderer_toggle_get_type
 </SECTION>
 
+<SECTION>
+<FILE>gtkcellrendererprogress</FILE>
+<TITLE>GtkCellRendererProgress</TITLE>
+GtkCellRendererProgress
+gtk_cell_renderer_progress_new
+<SUBSECTION Standard>
+GTK_CELL_RENDERER_PROGRESS
+GTK_IS_CELL_RENDERER_PROGRESS
+GTK_TYPE_CELL_RENDERER_PROGRESS
+GTK_CELL_RENDERER_PROGRESS_CLASS
+GTK_IS_CELL_RENDERER_PROGRESS_CLASS
+GTK_CELL_RENDERER_PROGRESS_GET_CLASS
+<SUBSECTION Private>
+gtk_cell_renderer_progress_get_type
+</SECTION>
+
 <SECTION>
 <FILE>gtkliststore</FILE>
 <TITLE>GtkListStore</TITLE>
index 29c23751d391120ab7242f0794b4c14e4a5a2aad..5a511ef320781dc13efc814fcfe280e40cca3441 100644 (file)
@@ -20,6 +20,7 @@ gtk_cell_renderer_get_type
 gtk_cell_renderer_pixbuf_get_type
 gtk_cell_renderer_text_get_type
 gtk_cell_renderer_toggle_get_type
+gtk_cell_renderer_progress_get_type
 gtk_check_button_get_type
 gtk_check_menu_item_get_type
 gtk_clist_get_type
index 41606ad93848b6f009cc9cdda526300c2791729e..3a9cdd3c84e0ef4001ebafd84d18031d4d024037 100644 (file)
@@ -118,6 +118,7 @@ gtk_public_h_sources =          \
        gtkcelllayout.h         \
        gtkcellrenderer.h       \
        gtkcellrendererpixbuf.h \
+       gtkcellrendererprogress.h \
        gtkcellrenderertext.h   \
        gtkcellrenderertoggle.h \
        gtkcheckbutton.h        \
@@ -321,6 +322,7 @@ gtk_c_sources =                 \
        gtkcelllayout.c         \
        gtkcellrenderer.c       \
        gtkcellrendererpixbuf.c \
+       gtkcellrendererprogress.c \
        gtkcellrendererseptext.c\
        gtkcellrenderertext.c   \
        gtkcellrenderertoggle.c \
index e52a1a6d03b5cc63c93ac017acde202e17e52852..b8482520147a3f216401cd73f9df7e32efbffac3 100644 (file)
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -48,6 +48,7 @@
 #include <gtk/gtkcelllayout.h>
 #include <gtk/gtkcellrenderer.h>
 #include <gtk/gtkcellrendererpixbuf.h>
+#include <gtk/gtkcellrendererprogress.h>
 #include <gtk/gtkcellrenderertext.h>
 #include <gtk/gtkcellrenderertoggle.h>
 #include <gtk/gtkcheckbutton.h>
diff --git a/gtk/gtkcellrendererprogress.c b/gtk/gtkcellrendererprogress.c
new file mode 100644 (file)
index 0000000..64116d2
--- /dev/null
@@ -0,0 +1,381 @@
+/* gtkcellrendererprogress.c
+ * Copyright (C) 2002 Naba Kumar <kh_naba@users.sourceforge.net>
+ * heavily modified by Jörgen Scheibengruber <mfcn@gmx.de>
+ * heavily modified by Marco Pesenti Gritti <marco@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+/*
+ * Modified by the GTK+ Team and others 1997-2004.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+#include "config.h"
+#include <stdlib.h>
+#include "gtkcellrendererprogress.h"
+#include "gtkintl.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,
+       PROP_VALUE,
+       PROP_TEXT
+}; 
+
+struct _GtkCellRendererProgressPrivate
+{
+  gint value;
+  gchar *text;
+  gchar *label;
+  gint min_h;
+  gint min_w;
+};
+
+static void gtk_cell_renderer_progress_finalize     (GObject                 *object);
+static void gtk_cell_renderer_progress_get_property (GObject                 *object,
+                                                    guint                    param_id,
+                                                    GValue                  *value,
+                                                    GParamSpec              *pspec);
+static void gtk_cell_renderer_progress_set_property (GObject                 *object,
+                                                    guint                    param_id,
+                                                    const GValue            *value,
+                                                    GParamSpec              *pspec);
+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,
+                                                    gint                    *width,
+                                                    gint                    *height);
+static void gtk_cell_renderer_progress_get_size     (GtkCellRenderer         *cell,
+                                                    GtkWidget               *widget,
+                                                    GdkRectangle            *cell_area,
+                                                    gint                    *x_offset,
+                                                    gint                    *y_offset,
+                                                    gint                    *width,
+                                                    gint                    *height);
+static void gtk_cell_renderer_progress_render       (GtkCellRenderer         *cell,
+                                                    GdkWindow               *window,
+                                                    GtkWidget               *widget,
+                                                    GdkRectangle            *background_area,
+                                                    GdkRectangle            *cell_area,
+                                                    GdkRectangle            *expose_area,
+                                                    guint                    flags);
+
+     
+G_DEFINE_TYPE (GtkCellRendererProgress, gtk_cell_renderer_progress, GTK_TYPE_CELL_RENDERER);
+
+static void
+gtk_cell_renderer_progress_class_init (GtkCellRendererProgressClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
+  
+  object_class->finalize = gtk_cell_renderer_progress_finalize;
+  object_class->get_property = gtk_cell_renderer_progress_get_property;
+  object_class->set_property = gtk_cell_renderer_progress_set_property;
+  
+  cell_class->get_size = gtk_cell_renderer_progress_get_size;
+  cell_class->render = gtk_cell_renderer_progress_render;
+  
+  /**
+   * GtkCellRendererProgress:value:
+   * 
+   * The "value" property determines the percentage to which the
+   * progress bar will be "filled in". 
+   *
+   * Since: 2.6
+   **/
+  g_object_class_install_property (object_class,
+                                  PROP_VALUE,
+                                  g_param_spec_int ("value",
+                                                    P_("Value"),
+                                                    P_("Value of the progress bar"),
+                                                    -2, 100, 0,
+                                                    G_PARAM_READWRITE));
+
+  /**
+   * GtkCellRendererProgress:text:
+   * 
+   * The "text" property determines the label which will be drawn
+   * over the progress bar. Setting this property to %NULL causes the default 
+   * label to be displayed. Setting this property to an empty string causes 
+   * no label to be displayed.
+   *
+   * Since: 2.6
+   **/
+  g_object_class_install_property (object_class,
+                                  PROP_TEXT,
+                                  g_param_spec_string ("text",
+                                                       P_("Text"),
+                                                       P_("Text on the progress bar"),
+                                                       NULL,
+                                                       G_PARAM_READWRITE));
+
+  g_type_class_add_private (object_class, 
+                           sizeof (GtkCellRendererProgressPrivate));
+}
+
+static void
+gtk_cell_renderer_progress_init (GtkCellRendererProgress *cellprogress)
+{
+  cellprogress->priv = GTK_CELL_RENDERER_PROGRESS_GET_PRIVATE (cellprogress);
+  cellprogress->priv->value = 0;
+  cellprogress->priv->text = NULL;
+  cellprogress->priv->label = NULL;
+  cellprogress->priv->min_w = -1;
+}
+
+
+/**
+ * gtk_cell_renderer_progress_new:
+ * 
+ * Creates a new #GtkCellRendererProgress. 
+ *
+ * Return value: the new cell renderer
+ *
+ * Since: 2.6
+ **/
+GtkCellRenderer*
+gtk_cell_renderer_progress_new (void)
+{
+  return GTK_CELL_RENDERER (g_object_new (GTK_TYPE_CELL_RENDERER_PROGRESS, NULL));
+}
+
+static void
+gtk_cell_renderer_progress_finalize (GObject *object)
+{
+  GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (object);
+  
+  g_free (cellprogress->priv->text);
+  g_free (cellprogress->priv->label);
+  
+  G_OBJECT_CLASS (gtk_cell_renderer_progress_parent_class)->finalize (object);
+}
+
+static void
+gtk_cell_renderer_progress_get_property (GObject *object,
+                                        guint param_id,
+                                        GValue *value,
+                                        GParamSpec *pspec)
+{
+  GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (object);
+  
+  switch (param_id)
+    {
+    case PROP_VALUE:
+      g_value_set_int (value, cellprogress->priv->value);
+      break;
+    case PROP_TEXT:
+      g_value_set_string (value, cellprogress->priv->text);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+    }
+}
+
+static void
+gtk_cell_renderer_progress_set_property (GObject *object,
+                                        guint param_id,
+                                        const GValue *value,
+                                        GParamSpec   *pspec)
+{
+  GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (object);
+  
+  switch (param_id)
+    {
+    case PROP_VALUE:
+      gtk_cell_renderer_progress_set_value (cellprogress, 
+                                           g_value_get_int (value));
+      break;
+    case PROP_TEXT:
+      gtk_cell_renderer_progress_set_text (cellprogress,
+                                          g_value_get_string (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+    }
+}
+
+static void
+gtk_cell_renderer_progress_set_value (GtkCellRendererProgress *cellprogress, 
+                                     gint                     value)
+{
+  gchar *text;
+  
+  cellprogress->priv->value = value;
+
+  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);
+  
+  g_free (cellprogress->priv->label);
+  cellprogress->priv->label = text;
+}
+
+static void
+gtk_cell_renderer_progress_set_text (GtkCellRendererProgress *cellprogress, 
+                                    gchar                   *text)
+{
+  gchar *new_text;
+
+  new_text = g_strdup (text);
+  g_free (cellprogress->priv->text);
+  cellprogress->priv->text = new_text;
+
+  /* Update the label */
+  gtk_cell_renderer_progress_set_value (cellprogress, cellprogress->priv->value);
+}
+
+static void
+compute_dimensions (GtkWidget   *widget, 
+                   const gchar *text, 
+                   gint        *width, 
+                   gint        *height)
+{
+  PangoRectangle logical_rect;
+  PangoLayout *layout;
+  
+  layout = gtk_widget_create_pango_layout (widget, text);
+  pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+  
+  if (width)
+    *width = logical_rect.width + XPAD * 2 + widget->style->xthickness * 2;
+  
+  if (height)
+    *height = logical_rect.height + YPAD * 2 + widget->style->ythickness * 2;
+  
+  g_object_unref (G_OBJECT (layout));
+}
+
+static void
+gtk_cell_renderer_progress_get_size (GtkCellRenderer *cell,
+                                    GtkWidget       *widget,
+                                    GdkRectangle    *cell_area,
+                                    gint            *x_offset,
+                                    gint            *y_offset,
+                                    gint            *width,
+                                    gint            *height)
+{
+  GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (cell);
+  gint w, h;
+  
+  if (cellprogress->priv->min_w < 0)
+    compute_dimensions (widget, _("Unknown"),
+                       &cellprogress->priv->min_w,
+                       &cellprogress->priv->min_h);
+  
+  compute_dimensions (widget, cellprogress->priv->label, &w, &h);
+  
+  if (width)
+      *width = MAX (cellprogress->priv->min_w, w);
+  
+  if (height)
+    *height = MIN (cellprogress->priv->min_h, h);
+}
+
+static void
+gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
+                                  GdkWindow       *window,
+                                  GtkWidget       *widget,
+                                  GdkRectangle    *background_area,
+                                  GdkRectangle    *cell_area,
+                                  GdkRectangle    *expose_area,
+                                  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;
+
+  is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
+  
+  gc = gdk_gc_new (window);
+  
+  x = cell_area->x + XPAD;
+  y = cell_area->y + 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);
+  
+  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);
+  
+  layout = gtk_widget_create_pango_layout (widget, cellprogress->priv->label);
+  pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+  
+  pos = (w - logical_rect.width)/2;
+  
+  clip.x = x;
+  clip.y = y;
+  clip.width = is_rtl ? w - perc_w : perc_w;
+  clip.height = h; 
+
+  gtk_paint_layout (widget->style, window, 
+                   is_rtl ? GTK_STATE_NORMAL : GTK_STATE_SELECTED,
+                   FALSE, &clip, widget, "progressbar",
+                   x + pos, y + (h - logical_rect.height)/2,
+                   layout);
+
+  clip.x = clip.x + clip.width;
+  clip.width = w - clip.width;
+
+  gtk_paint_layout (widget->style, window, 
+                   is_rtl ?  GTK_STATE_SELECTED : GTK_STATE_NORMAL,
+                   FALSE, &clip, widget, "progressbar",
+                   x + pos, y + (h - logical_rect.height)/2,
+                   layout);
+  
+  g_object_unref (G_OBJECT (layout));
+  g_object_unref (G_OBJECT (gc));
+}
+
diff --git a/gtk/gtkcellrendererprogress.h b/gtk/gtkcellrendererprogress.h
new file mode 100644 (file)
index 0000000..7417f79
--- /dev/null
@@ -0,0 +1,75 @@
+/* gtkcellrendererprogress.h
+ * Copyright (C) 2002 Naba Kumar <kh_naba@users.sourceforge.net>
+ * modified by Jörgen Scheibengruber <mfcn@gmx.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+/*
+ * Modified by the GTK+ Team and others 1997-2004.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+#ifndef __GTK_CELL_RENDERER_PROGRESS_H__
+#define __GTK_CELL_RENDERER_PROGRESS_H__
+
+#include <gtk/gtkcellrenderer.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CELL_RENDERER_PROGRESS (gtk_cell_renderer_progress_get_type ())
+#define GTK_CELL_RENDERER_PROGRESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CELL_RENDERER_PROGRESS, GtkCellRendererProgress))
+#define GTK_CELL_RENDERER_PROGRESS_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CELL_RENDERER_PROGRESS, GtkCellRendererProgressClass))
+#define GTK_IS_CELL_RENDERER_PROGRESS(obj)       (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CELL_RENDERER_PROGRESS))
+#define GTK_IS_CELL_RENDERER_PROGRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CELL_RENDERER_PROGRESS))
+#define GTK_CELL_RENDERER_PROGRESS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CELL_RENDERER_PROGRESS, GtkCellRendererProgressClass))
+
+typedef struct _GtkCellRendererProgress         GtkCellRendererProgress;
+typedef struct _GtkCellRendererProgressClass    GtkCellRendererProgressClass;
+typedef struct _GtkCellRendererProgressPrivate  GtkCellRendererProgressPrivate;
+
+enum
+{
+  GTK_PROGRESS_CELL_UNKNOWN = -1,
+  GTK_PROGRESS_CELL_FAILED = -2
+};
+
+struct _GtkCellRendererProgress
+{
+  GtkCellRenderer parent_instance;
+  
+  /*< private >*/
+  GtkCellRendererProgressPrivate *priv;
+};
+
+struct _GtkCellRendererProgressClass
+{
+  GtkCellRendererClass parent_class;
+
+  /* Padding for future expansion */
+  void (*_gtk_reserved1) (void);
+  void (*_gtk_reserved2) (void);
+  void (*_gtk_reserved3) (void);
+  void (*_gtk_reserved4) (void);
+};
+
+GType           gtk_cell_renderer_progress_get_type (void);
+GtkCellRenderer* gtk_cell_renderer_progress_new      (void);
+
+G_END_DECLS
+
+#endif  /* __GTK_CELL_RENDERER_PROGRESS_H__ */
index 8303d39fb92eb489f58268b95a09c79664788c50..a4fc8da108d9281330c776daf55b4614f7be3d83 100644 (file)
@@ -4,22 +4,24 @@
 typedef struct {
   const gchar *string;
   gboolean is_editable;
+  gint progress;
 } ListEntry;
 
 enum {
   STRING_COLUMN,
   IS_EDITABLE_COLUMN,
   PIXBUF_COLUMN,
+  PROGRESS_COLUMN,
   NUM_COLUMNS
 };
 
 static ListEntry model_strings[] =
 {
-  {"A simple string", TRUE },
-  {"Another string!", TRUE },
-  {"Guess what, a third string. This one can't be edited", FALSE },
-  {"And then a fourth string. Neither can this", FALSE },
-  {"Multiline\nFun!", TRUE },
+  {"A simple string", TRUE, 0 },
+  {"Another string!", TRUE, 10 },
+  {"Guess what, a third string. This one can't be edited", FALSE, 47 },
+  {"And then a fourth string. Neither can this", FALSE, 48 },
+  {"Multiline\nFun!", TRUE, 75 },
   { NULL }
 };
 
@@ -39,7 +41,8 @@ create_model (void)
   model = gtk_tree_store_new (NUM_COLUMNS,
                              G_TYPE_STRING,
                              G_TYPE_BOOLEAN,
-                             GDK_TYPE_PIXBUF);
+                             GDK_TYPE_PIXBUF,
+                             G_TYPE_INT);
 
   for (i = 0; model_strings[i].string != NULL; i++)
     {
@@ -49,6 +52,7 @@ create_model (void)
                          STRING_COLUMN, model_strings[i].string,
                          IS_EDITABLE_COLUMN, model_strings[i].is_editable,
                          PIXBUF_COLUMN, foo,
+                         PROGRESS_COLUMN, model_strings[i].progress,
                          -1);
     }
   
@@ -116,6 +120,9 @@ main (gint argc, gchar **argv)
   
   gtk_init (&argc, &argv);
 
+  if (g_getenv ("RTL"))
+    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
+
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), "GtkTreeView editing sample");
   g_signal_connect (window, "destroy", gtk_main_quit, NULL);
@@ -174,6 +181,14 @@ main (gint argc, gchar **argv)
                                               renderer,
                                               "active", IS_EDITABLE_COLUMN,
                                               NULL);
+
+  renderer = gtk_cell_renderer_progress_new ();
+  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
+                                              -1, "Progress",
+                                              renderer,
+                                              "value", PROGRESS_COLUMN,
+                                              NULL);
+
   gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
   
   gtk_window_set_default_size (GTK_WINDOW (window),