+ clip.width = bar_size;
+ clip.x = bar_position;
+ }
+ else
+ {
+ clip.x = x;
+ clip.width = w;
+
+ start = y;
+ full_size = h;
+
+ bar_size = get_bar_size (priv->pulse, priv->value, full_size);
+
+ if (priv->inverted)
+ bar_position = get_bar_position (start, full_size, bar_size,
+ priv->pulse, priv->offset, TRUE);
+ else
+ bar_position = get_bar_position (start, full_size, bar_size,
+ priv->pulse, priv->offset, FALSE);
+
+ clip.height = bar_size;
+ clip.y = bar_position;
+ }
+
+ 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)
+ {
+ gfloat text_xalign;
+
+ layout = gtk_widget_create_pango_layout (widget, priv->label);
+ pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+ if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
+ text_xalign = 1.0 - priv->text_xalign;
+ else
+ text_xalign = priv->text_xalign;
+
+ 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);
+
+ gtk_render_layout (context, cr,
+ 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)
+ {
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ clip.x = x;
+ clip.width = bar_position - x;
+ }
+ else
+ {
+ clip.y = y;
+ clip.height = bar_position - y;
+ }
+
+ 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)
+ {
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ clip.x = bar_position + bar_size;
+ clip.width = x + w - (bar_position + bar_size);
+ }
+ else
+ {
+ clip.y = bar_position + bar_size;
+ clip.height = y + h - (bar_position + bar_size);
+ }
+
+ 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);
+ }
+}