Make GtkCellRendererProgress use GtkStyleContext

This commit is contained in:
Carlos Garnacho
2011-01-12 21:28:44 +01:00
parent 9b091ae330
commit 3285eff289

View File

@ -534,8 +534,9 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
GtkCellRendererState flags) GtkCellRendererState flags)
{ {
GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (cell); GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (cell);
GtkCellRendererProgressPrivate *priv= cellprogress->priv; GtkCellRendererProgressPrivate *priv= cellprogress->priv;
GtkStyle *style; GtkStyleContext *context;
GtkBorder padding, border;
PangoLayout *layout; PangoLayout *layout;
PangoRectangle logical_rect; PangoRectangle logical_rect;
gint x, y, w, h, x_pos, y_pos, bar_position, bar_size, start, full_size; gint x, y, w, h, x_pos, y_pos, bar_position, bar_size, start, full_size;
@ -543,8 +544,7 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
GdkRectangle clip; GdkRectangle clip;
gboolean is_rtl; 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; is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
gtk_cell_renderer_get_padding (cell, &xpad, &ypad); gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
@ -553,15 +553,21 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
w = cell_area->width - xpad * 2; w = cell_area->width - xpad * 2;
h = cell_area->height - ypad * 2; h = cell_area->height - ypad * 2;
/* FIXME: GtkProgressBar draws the box with "trough" detail, gtk_style_context_save (context);
* but some engines don't paint anything with that detail for gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
* non-GtkProgressBar widgets.
*/ gtk_render_background (context, cr, x, y, w, h);
gtk_paint_box (style, gtk_render_frame (context, cr, x, y, w, h);
cr,
GTK_STATE_NORMAL, GTK_SHADOW_IN, gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &border);
widget, NULL, gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL, &padding);
x, y, w, h);
x += border.left + padding.left;
y += border.top + padding.top;
w -= border.left + border.right + padding.left + padding.right;
h -= border.top + border.bottom + padding.top + padding.bottom;
gtk_style_context_restore (context);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{ {
@ -604,13 +610,15 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
clip.y = bar_position; clip.y = bar_position;
} }
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
if (bar_size > 0) if (bar_size > 0)
gtk_paint_box (style, gtk_render_activity (context, cr,
cr, clip.x, clip.y,
GTK_STATE_SELECTED, GTK_SHADOW_OUT, clip.width, clip.height);
widget, "bar",
clip.x, clip.y, gtk_style_context_restore (context);
clip.width, clip.height);
if (priv->label) if (priv->label)
{ {
@ -624,24 +632,29 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
else else
text_xalign = priv->text_xalign; text_xalign = priv->text_xalign;
x_pos = x + style->xthickness + text_xalign * x_pos = x + padding.left + text_xalign *
(w - 2 * style->xthickness - logical_rect.width); (w - padding.left - padding.right - logical_rect.width);
y_pos = y + style->ythickness + priv->text_yalign * y_pos = y + padding.top + priv->text_yalign *
(h - 2 * style->ythickness - logical_rect.height); (h - padding.top - padding.bottom - logical_rect.height);
cairo_save (cr); cairo_save (cr);
gdk_cairo_rectangle (cr, &clip); gdk_cairo_rectangle (cr, &clip);
cairo_clip (cr); cairo_clip (cr);
gtk_paint_layout (style, cr, gtk_style_context_save (context);
GTK_STATE_SELECTED, gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
FALSE, widget, "progressbar",
x_pos, y_pos,
layout);
gtk_render_layout (context, cr,
x_pos, y_pos,
layout);
gtk_style_context_restore (context);
cairo_restore (cr); cairo_restore (cr);
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
if (bar_position > start) if (bar_position > start)
{ {
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
@ -659,11 +672,9 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
gdk_cairo_rectangle (cr, &clip); gdk_cairo_rectangle (cr, &clip);
cairo_clip (cr); cairo_clip (cr);
gtk_paint_layout (style, cr, gtk_render_layout (context, cr,
GTK_STATE_NORMAL, x_pos, y_pos,
FALSE, widget, "progressbar", layout);
x_pos, y_pos,
layout);
cairo_restore (cr); cairo_restore (cr);
} }
@ -685,15 +696,14 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
gdk_cairo_rectangle (cr, &clip); gdk_cairo_rectangle (cr, &clip);
cairo_clip (cr); cairo_clip (cr);
gtk_paint_layout (style, cr, gtk_render_layout (context, cr,
GTK_STATE_NORMAL, x_pos, y_pos,
FALSE, widget, "progressbar", layout);
x_pos, y_pos,
layout);
cairo_restore (cr); cairo_restore (cr);
} }
gtk_style_context_restore (context);
g_object_unref (layout); g_object_unref (layout);
} }
} }