mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 05:31:07 +00:00
GtkLabel: Use style context for rendering.
This commit is contained in:
parent
0fce9342ef
commit
90dd2eb42b
@ -221,8 +221,7 @@ static void gtk_label_size_allocate (GtkWidget *widget,
|
|||||||
GtkAllocation *allocation);
|
GtkAllocation *allocation);
|
||||||
static void gtk_label_state_changed (GtkWidget *widget,
|
static void gtk_label_state_changed (GtkWidget *widget,
|
||||||
GtkStateType state);
|
GtkStateType state);
|
||||||
static void gtk_label_style_set (GtkWidget *widget,
|
static void gtk_label_style_updated (GtkWidget *widget);
|
||||||
GtkStyle *previous_style);
|
|
||||||
static void gtk_label_direction_changed (GtkWidget *widget,
|
static void gtk_label_direction_changed (GtkWidget *widget,
|
||||||
GtkTextDirection previous_dir);
|
GtkTextDirection previous_dir);
|
||||||
static gint gtk_label_draw (GtkWidget *widget,
|
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->destroy = gtk_label_destroy;
|
||||||
widget_class->size_allocate = gtk_label_size_allocate;
|
widget_class->size_allocate = gtk_label_size_allocate;
|
||||||
widget_class->state_changed = gtk_label_state_changed;
|
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->query_tooltip = gtk_label_query_tooltip;
|
||||||
widget_class->direction_changed = gtk_label_direction_changed;
|
widget_class->direction_changed = gtk_label_direction_changed;
|
||||||
widget_class->draw = gtk_label_draw;
|
widget_class->draw = gtk_label_draw;
|
||||||
@ -3806,8 +3805,7 @@ gtk_label_state_changed (GtkWidget *widget,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_label_style_set (GtkWidget *widget,
|
gtk_label_style_updated (GtkWidget *widget)
|
||||||
GtkStyle *previous_style)
|
|
||||||
{
|
{
|
||||||
GtkLabel *label = GTK_LABEL (widget);
|
GtkLabel *label = GTK_LABEL (widget);
|
||||||
|
|
||||||
@ -4065,7 +4063,8 @@ gtk_label_draw (GtkWidget *widget,
|
|||||||
GtkLabelPrivate *priv = label->priv;
|
GtkLabelPrivate *priv = label->priv;
|
||||||
GtkLabelSelectionInfo *info = priv->select_info;
|
GtkLabelSelectionInfo *info = priv->select_info;
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
GtkStyle *style;
|
GtkStyleContext *context;
|
||||||
|
GtkStateFlags state;
|
||||||
GdkWindow *window;
|
GdkWindow *window;
|
||||||
gint x, y;
|
gint x, y;
|
||||||
|
|
||||||
@ -4073,22 +4072,22 @@ gtk_label_draw (GtkWidget *widget,
|
|||||||
|
|
||||||
if (priv->text && (*priv->text != '\0'))
|
if (priv->text && (*priv->text != '\0'))
|
||||||
{
|
{
|
||||||
|
GdkRGBA *bg_color, *fg_color;
|
||||||
|
|
||||||
get_layout_location (label, &x, &y);
|
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);
|
window = gtk_widget_get_window (widget);
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
|
|
||||||
cairo_translate (cr, -allocation.x, -allocation.y);
|
cairo_translate (cr, -allocation.x, -allocation.y);
|
||||||
|
|
||||||
gtk_paint_layout (style,
|
state = gtk_widget_get_state_flags (widget);
|
||||||
cr,
|
gtk_style_context_set_state (context, state);
|
||||||
gtk_widget_get_state (widget),
|
|
||||||
FALSE,
|
gtk_render_layout (context, cr,
|
||||||
widget,
|
x, y,
|
||||||
"label",
|
priv->layout);
|
||||||
x, y,
|
|
||||||
priv->layout);
|
|
||||||
|
|
||||||
if (info &&
|
if (info &&
|
||||||
(info->selection_anchor != info->selection_end))
|
(info->selection_anchor != info->selection_end))
|
||||||
@ -4121,19 +4120,28 @@ gtk_label_draw (GtkWidget *widget,
|
|||||||
gdk_cairo_region (cr, clip);
|
gdk_cairo_region (cr, clip);
|
||||||
cairo_clip (cr);
|
cairo_clip (cr);
|
||||||
|
|
||||||
state = GTK_STATE_SELECTED;
|
state = GTK_STATE_FLAG_SELECTED;
|
||||||
if (!gtk_widget_has_focus (widget))
|
|
||||||
state = GTK_STATE_ACTIVE;
|
|
||||||
|
|
||||||
gdk_cairo_set_source_color (cr, &style->base[state]);
|
if (gtk_widget_has_focus (widget))
|
||||||
|
state |= GTK_STATE_FLAG_FOCUSED;
|
||||||
|
|
||||||
|
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);
|
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);
|
cairo_move_to (cr, x, y);
|
||||||
_gtk_pango_fill_layout (cr, priv->layout);
|
_gtk_pango_fill_layout (cr, priv->layout);
|
||||||
|
|
||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
cairo_region_destroy (clip);
|
cairo_region_destroy (clip);
|
||||||
|
|
||||||
|
gdk_rgba_free (bg_color);
|
||||||
|
gdk_rgba_free (fg_color);
|
||||||
}
|
}
|
||||||
else if (info)
|
else if (info)
|
||||||
{
|
{
|
||||||
@ -4143,7 +4151,6 @@ gtk_label_draw (GtkWidget *widget,
|
|||||||
cairo_region_t *clip;
|
cairo_region_t *clip;
|
||||||
GdkRectangle rect;
|
GdkRectangle rect;
|
||||||
GdkColor *text_color;
|
GdkColor *text_color;
|
||||||
GdkColor *base_color;
|
|
||||||
GdkColor *link_color;
|
GdkColor *link_color;
|
||||||
GdkColor *visited_link_color;
|
GdkColor *visited_link_color;
|
||||||
|
|
||||||
@ -4156,6 +4163,8 @@ gtk_label_draw (GtkWidget *widget,
|
|||||||
|
|
||||||
if (active_link)
|
if (active_link)
|
||||||
{
|
{
|
||||||
|
GdkRGBA *bg_color;
|
||||||
|
|
||||||
range[0] = active_link->start;
|
range[0] = active_link->start;
|
||||||
range[1] = active_link->end;
|
range[1] = active_link->end;
|
||||||
|
|
||||||
@ -4174,12 +4183,17 @@ gtk_label_draw (GtkWidget *widget,
|
|||||||
text_color = visited_link_color;
|
text_color = visited_link_color;
|
||||||
else
|
else
|
||||||
text_color = link_color;
|
text_color = link_color;
|
||||||
if (info->link_clicked)
|
|
||||||
base_color = &style->base[GTK_STATE_ACTIVE];
|
|
||||||
else
|
|
||||||
base_color = &style->base[GTK_STATE_PRELIGHT];
|
|
||||||
|
|
||||||
gdk_cairo_set_source_color (cr, base_color);
|
if (info->link_clicked)
|
||||||
|
state = GTK_STATE_FLAG_ACTIVE;
|
||||||
|
else
|
||||||
|
state = GTK_STATE_FLAG_PRELIGHT;
|
||||||
|
|
||||||
|
gtk_style_context_get (context, state,
|
||||||
|
"background-color", &bg_color,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
gdk_cairo_set_source_rgba (cr, bg_color);
|
||||||
cairo_paint (cr);
|
cairo_paint (cr);
|
||||||
|
|
||||||
gdk_cairo_set_source_color (cr, text_color);
|
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 (link_color);
|
||||||
gdk_color_free (visited_link_color);
|
gdk_color_free (visited_link_color);
|
||||||
|
gdk_rgba_free (bg_color);
|
||||||
|
|
||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
@ -4203,9 +4218,12 @@ gtk_label_draw (GtkWidget *widget,
|
|||||||
1);
|
1);
|
||||||
cairo_region_get_extents (clip, &rect);
|
cairo_region_get_extents (clip, &rect);
|
||||||
|
|
||||||
gtk_paint_focus (style, cr, gtk_widget_get_state (widget),
|
state = gtk_widget_get_state_flags (widget);
|
||||||
widget, "label",
|
gtk_style_context_set_state (context, state);
|
||||||
rect.x, rect.y, rect.width, rect.height);
|
|
||||||
|
gtk_render_focus (context, cr,
|
||||||
|
rect.x, rect.y,
|
||||||
|
rect.width, rect.height);
|
||||||
|
|
||||||
cairo_region_destroy (clip);
|
cairo_region_destroy (clip);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user