[gtk+/gtk-style-context: 474/540] GtkLabel: Use style context for rendering.
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-style-context: 474/540] GtkLabel: Use style context for rendering.
- Date: Fri, 3 Dec 2010 03:15:57 +0000 (UTC)
commit cc6d1c0d6e53977e7fcf431fe40d7e15fc4e8517
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Nov 24 01:24:46 2010 +0100
GtkLabel: Use style context for rendering.
gtk/gtklabel.c | 72 +++++++++++++++++++++++++++++++++++---------------------
1 files changed, 45 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 63b9cd0..55bc6c3 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -221,8 +221,7 @@ static void gtk_label_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_label_state_changed (GtkWidget *widget,
GtkStateType state);
-static void gtk_label_style_set (GtkWidget *widget,
- GtkStyle *previous_style);
+static void gtk_label_style_updated (GtkWidget *widget);
static void gtk_label_direction_changed (GtkWidget *widget,
GtkTextDirection previous_dir);
static gint gtk_label_draw (GtkWidget *widget,
@@ -407,7 +406,7 @@ gtk_label_class_init (GtkLabelClass *class)
widget_class->destroy = gtk_label_destroy;
widget_class->size_allocate = gtk_label_size_allocate;
widget_class->state_changed = gtk_label_state_changed;
- widget_class->style_set = gtk_label_style_set;
+ widget_class->style_updated = gtk_label_style_updated;
widget_class->query_tooltip = gtk_label_query_tooltip;
widget_class->direction_changed = gtk_label_direction_changed;
widget_class->draw = gtk_label_draw;
@@ -3806,8 +3805,7 @@ gtk_label_state_changed (GtkWidget *widget,
}
static void
-gtk_label_style_set (GtkWidget *widget,
- GtkStyle *previous_style)
+gtk_label_style_updated (GtkWidget *widget)
{
GtkLabel *label = GTK_LABEL (widget);
@@ -4065,7 +4063,8 @@ gtk_label_draw (GtkWidget *widget,
GtkLabelPrivate *priv = label->priv;
GtkLabelSelectionInfo *info = priv->select_info;
GtkAllocation allocation;
- GtkStyle *style;
+ GtkStyleContext *context;
+ GtkStateFlags state;
GdkWindow *window;
gint x, y;
@@ -4073,22 +4072,22 @@ gtk_label_draw (GtkWidget *widget,
if (priv->text && (*priv->text != '\0'))
{
+ GdkRGBA *bg_color, *fg_color;
+
get_layout_location (label, &x, &y);
- style = gtk_widget_get_style (widget);
+ context = gtk_widget_get_style_context (widget);
window = gtk_widget_get_window (widget);
gtk_widget_get_allocation (widget, &allocation);
cairo_translate (cr, -allocation.x, -allocation.y);
- gtk_paint_layout (style,
- cr,
- gtk_widget_get_state (widget),
- FALSE,
- widget,
- "label",
- x, y,
- priv->layout);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_set_state (context, state);
+
+ gtk_render_layout (context, cr,
+ x, y,
+ priv->layout);
if (info &&
(info->selection_anchor != info->selection_end))
@@ -4121,19 +4120,28 @@ gtk_label_draw (GtkWidget *widget,
gdk_cairo_region (cr, clip);
cairo_clip (cr);
- state = GTK_STATE_SELECTED;
- if (!gtk_widget_has_focus (widget))
- state = GTK_STATE_ACTIVE;
+ state = GTK_STATE_FLAG_SELECTED;
+
+ if (gtk_widget_has_focus (widget))
+ state |= GTK_STATE_FLAG_FOCUSED;
- gdk_cairo_set_source_color (cr, &style->base[state]);
+ gtk_style_context_get (context, state,
+ "background-color", &bg_color,
+ "color", &fg_color,
+ NULL);
+
+ gdk_cairo_set_source_rgba (cr, bg_color);
cairo_paint (cr);
- gdk_cairo_set_source_color (cr, &style->text[state]);
+ gdk_cairo_set_source_rgba (cr, fg_color);
cairo_move_to (cr, x, y);
_gtk_pango_fill_layout (cr, priv->layout);
cairo_restore (cr);
cairo_region_destroy (clip);
+
+ gdk_rgba_free (bg_color);
+ gdk_rgba_free (fg_color);
}
else if (info)
{
@@ -4143,7 +4151,6 @@ gtk_label_draw (GtkWidget *widget,
cairo_region_t *clip;
GdkRectangle rect;
GdkColor *text_color;
- GdkColor *base_color;
GdkColor *link_color;
GdkColor *visited_link_color;
@@ -4156,6 +4163,8 @@ gtk_label_draw (GtkWidget *widget,
if (active_link)
{
+ GdkRGBA *bg_color;
+
range[0] = active_link->start;
range[1] = active_link->end;
@@ -4174,12 +4183,17 @@ gtk_label_draw (GtkWidget *widget,
text_color = visited_link_color;
else
text_color = link_color;
+
if (info->link_clicked)
- base_color = &style->base[GTK_STATE_ACTIVE];
+ state = GTK_STATE_FLAG_ACTIVE;
else
- base_color = &style->base[GTK_STATE_PRELIGHT];
+ state = GTK_STATE_FLAG_PRELIGHT;
- gdk_cairo_set_source_color (cr, base_color);
+ gtk_style_context_get (context, state,
+ "background-color", &bg_color,
+ NULL);
+
+ gdk_cairo_set_source_rgba (cr, bg_color);
cairo_paint (cr);
gdk_cairo_set_source_color (cr, text_color);
@@ -4188,6 +4202,7 @@ gtk_label_draw (GtkWidget *widget,
gdk_color_free (link_color);
gdk_color_free (visited_link_color);
+ gdk_rgba_free (bg_color);
cairo_restore (cr);
}
@@ -4203,9 +4218,12 @@ gtk_label_draw (GtkWidget *widget,
1);
cairo_region_get_extents (clip, &rect);
- gtk_paint_focus (style, cr, gtk_widget_get_state (widget),
- widget, "label",
- rect.x, rect.y, rect.width, rect.height);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_set_state (context, state);
+
+ gtk_render_focus (context, cr,
+ rect.x, rect.y,
+ rect.width, rect.height);
cairo_region_destroy (clip);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]