]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcellrendererprogress.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkcellrendererprogress.c
index a6d7288b8bad08d7e839622734cfb4503480b493..2e4b9b31c37376564d589b907b5723f90a3afa47 100644 (file)
@@ -14,9 +14,7 @@
  * 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.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 /*
  * Modified by the GTK+ Team and others 1997-2007.  See the AUTHORS
 #include "gtkintl.h"
 
 
+/**
+ * SECTION:gtkcellrendererprogress
+ * @Short_description: Renders numbers as progress bars
+ * @Title: GtkCellRendererProgress
+ *
+ * #GtkCellRendererProgress renders a numeric value as a progress par in a cell.
+ * Additionally, it can display a text on top of the progress bar.
+ *
+ * The #GtkCellRendererProgress cell renderer was added in GTK+ 2.6.
+ */
+
+
 enum
 {
   PROP_0,
@@ -83,18 +93,17 @@ static void compute_dimensions                      (GtkCellRenderer         *ce
                                                     gint                    *height);
 static void gtk_cell_renderer_progress_get_size     (GtkCellRenderer         *cell,
                                                     GtkWidget               *widget,
-                                                    GdkRectangle            *cell_area,
+                                                    const GdkRectangle      *cell_area,
                                                     gint                    *x_offset,
                                                     gint                    *y_offset,
                                                     gint                    *width,
                                                     gint                    *height);
 static void gtk_cell_renderer_progress_render       (GtkCellRenderer         *cell,
-                                                    GdkWindow               *window,
+                                                    cairo_t                 *cr,
                                                     GtkWidget               *widget,
-                                                    GdkRectangle            *background_area,
-                                                    GdkRectangle            *cell_area,
-                                                    GdkRectangle            *expose_area,
-                                                    guint                    flags);
+                                                    const GdkRectangle      *background_area,
+                                                    const GdkRectangle      *cell_area,
+                                                    GtkCellRendererState    flags);
 
      
 G_DEFINE_TYPE_WITH_CODE (GtkCellRendererProgress, gtk_cell_renderer_progress, GTK_TYPE_CELL_RENDERER,
@@ -344,7 +353,7 @@ gtk_cell_renderer_progress_set_property (GObject *object,
       priv->orientation = g_value_get_enum (value);
       break;
     case PROP_INVERTED:
-      priv->orientation = g_value_get_boolean (value);
+      priv->inverted = g_value_get_boolean (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -435,13 +444,13 @@ compute_dimensions (GtkCellRenderer *cell,
 }
 
 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)
+gtk_cell_renderer_progress_get_size (GtkCellRenderer    *cell,
+                                    GtkWidget          *widget,
+                                    const GdkRectangle *cell_area,
+                                    gint               *x_offset,
+                                    gint               *y_offset,
+                                    gint               *width,
+                                    gint               *height)
 {
   GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (cell);
   GtkCellRendererProgressPrivate *priv = cellprogress->priv;
@@ -527,17 +536,17 @@ get_bar_position (gint     start,
 }
 
 static void
-gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
-                                  GdkWindow       *window,
-                                  GtkWidget       *widget,
-                                  GdkRectangle    *background_area,
-                                  GdkRectangle    *cell_area,
-                                  GdkRectangle    *expose_area,
-                                  guint            flags)
+gtk_cell_renderer_progress_render (GtkCellRenderer      *cell,
+                                   cairo_t              *cr,
+                                  GtkWidget            *widget,
+                                  const GdkRectangle   *background_area,
+                                  const GdkRectangle   *cell_area,
+                                  GtkCellRendererState  flags)
 {
   GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (cell);
-  GtkCellRendererProgressPrivate *priv= cellprogress->priv; 
-  GtkStyle *style;
+  GtkCellRendererProgressPrivate *priv= cellprogress->priv;
+  GtkStyleContext *context;
+  GtkBorder padding;
   PangoLayout *layout;
   PangoRectangle logical_rect;
   gint x, y, w, h, x_pos, y_pos, bar_position, bar_size, start, full_size;
@@ -545,8 +554,7 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
   GdkRectangle clip;
   gboolean is_rtl;
 
-  style = gtk_widget_get_style (widget);
-
+  context = gtk_widget_get_style_context (widget);
   is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
 
   gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
@@ -555,15 +563,20 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
   w = cell_area->width - xpad * 2;
   h = cell_area->height - ypad * 2;
 
-  /* FIXME: GtkProgressBar draws the box with "trough" detail,
-   * but some engines don't paint anything with that detail for
-   * non-GtkProgressBar widgets.
-   */
-  gtk_paint_box (style,
-                window,
-                GTK_STATE_NORMAL, GTK_SHADOW_IN, 
-                NULL, widget, NULL,
-                x, y, w, h);
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
+
+  gtk_render_background (context, cr, x, y, w, h);
+  gtk_render_frame (context, cr, x, y, w, h);
+
+  gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL, &padding);
+
+  x += padding.left;
+  y += padding.top;
+  w -= padding.left + padding.right;
+  h -= padding.top + padding.bottom;
+
+  gtk_style_context_restore (context);
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
@@ -606,12 +619,15 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
       clip.y = bar_position;
     }
 
-  gtk_paint_box (style,
-                window,
-                GTK_STATE_SELECTED, GTK_SHADOW_OUT,
-                &clip, widget, "bar",
-                clip.x, clip.y,
-                clip.width, clip.height);
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
+
+  if (bar_size > 0)
+    gtk_render_activity (context, cr,
+                         clip.x, clip.y,
+                         clip.width, clip.height);
+
+  gtk_style_context_restore (context);
 
   if (priv->label)
     {
@@ -625,17 +641,28 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
       else
        text_xalign = priv->text_xalign;
 
-      x_pos = x + style->xthickness + text_xalign *
-       (w - 2 * style->xthickness - logical_rect.width);
+      x_pos = x + padding.left + text_xalign *
+       (w - padding.left - padding.right - logical_rect.width);
+
+      y_pos = y + padding.top + priv->text_yalign *
+       (h - padding.top - padding.bottom - logical_rect.height);
+
+      cairo_save (cr);
+      gdk_cairo_rectangle (cr, &clip);
+      cairo_clip (cr);
+
+      gtk_style_context_save (context);
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
 
-      y_pos = y + style->ythickness + priv->text_yalign *
-       (h - 2 * style->ythickness - logical_rect.height);
+      gtk_render_layout (context, cr,
+                         x_pos, y_pos,
+                         layout);
 
-      gtk_paint_layout (style, window,
-                       GTK_STATE_SELECTED,
-                       FALSE, &clip, widget, "progressbar",
-                       x_pos, y_pos, 
-                       layout);
+      gtk_style_context_restore (context);
+      cairo_restore (cr);
+
+      gtk_style_context_save (context);
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
 
       if (bar_position > start)
         {
@@ -650,11 +677,15 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
              clip.height = bar_position - y;
            }
 
-          gtk_paint_layout (style, window,
-                           GTK_STATE_NORMAL,
-                           FALSE, &clip, widget, "progressbar",
-                           x_pos, y_pos,
-                           layout);
+          cairo_save (cr);
+          gdk_cairo_rectangle (cr, &clip);
+          cairo_clip (cr);
+
+          gtk_render_layout (context, cr,
+                             x_pos, y_pos,
+                             layout);
+
+          cairo_restore (cr);
         }
 
       if (bar_position + bar_size < start + full_size)
@@ -670,13 +701,18 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
              clip.height = y + h - (bar_position + bar_size);
            }
 
-          gtk_paint_layout (style, window,
-                           GTK_STATE_NORMAL,
-                           FALSE, &clip, widget, "progressbar",
-                           x_pos, y_pos,
-                           layout);
+          cairo_save (cr);
+          gdk_cairo_rectangle (cr, &clip);
+          cairo_clip (cr);
+
+          gtk_render_layout (context, cr,
+                             x_pos, y_pos,
+                             layout);
+
+          cairo_restore (cr);
         }
 
+      gtk_style_context_restore (context);
       g_object_unref (layout);
     }
 }