mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-29 06:51:10 +00:00
Use the new style context API in GtkLabel.
This commit is contained in:
parent
561346bd40
commit
4a7e746bbc
@ -2273,11 +2273,13 @@ gtk_label_get_link_colors (GtkWidget *widget,
|
|||||||
GdkColor **link_color,
|
GdkColor **link_color,
|
||||||
GdkColor **visited_link_color)
|
GdkColor **visited_link_color)
|
||||||
{
|
{
|
||||||
gtk_widget_ensure_style (widget);
|
GtkStyleContext *context;
|
||||||
gtk_widget_style_get (widget,
|
|
||||||
"link-color", link_color,
|
context = gtk_widget_get_style_context (widget);
|
||||||
"visited-link-color", visited_link_color,
|
gtk_style_context_get_style (context,
|
||||||
NULL);
|
"link-color", link_color,
|
||||||
|
"visited-link-color", visited_link_color,
|
||||||
|
NULL);
|
||||||
if (!*link_color)
|
if (!*link_color)
|
||||||
*link_color = gdk_color_copy (&default_link_color);
|
*link_color = gdk_color_copy (&default_link_color);
|
||||||
if (!*visited_link_color)
|
if (!*visited_link_color)
|
||||||
@ -3007,13 +3009,25 @@ gtk_label_clear_layout (GtkLabel *label)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PangoFontMetrics *
|
||||||
|
get_font_metrics (PangoContext *context, GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GtkStyleContext *style_context;
|
||||||
|
PangoFontDescription *font;
|
||||||
|
|
||||||
|
style_context = gtk_widget_get_style_context (widget);
|
||||||
|
gtk_style_context_get (style_context, 0, "font", &font, NULL);
|
||||||
|
|
||||||
|
return pango_context_get_metrics (context,
|
||||||
|
font,
|
||||||
|
pango_context_get_language (context));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_label_width (GtkLabel *label,
|
get_label_width (GtkLabel *label,
|
||||||
gint *minimum,
|
gint *minimum,
|
||||||
gint *natural)
|
gint *natural)
|
||||||
{
|
{
|
||||||
GtkWidgetAuxInfo *aux_info;
|
|
||||||
GtkLabelPrivate *priv;
|
GtkLabelPrivate *priv;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
PangoContext *context;
|
PangoContext *context;
|
||||||
@ -3022,14 +3036,10 @@ get_label_width (GtkLabel *label,
|
|||||||
gint char_width, digit_width, char_pixels, text_width, ellipsize_chars, guess_width;
|
gint char_width, digit_width, char_pixels, text_width, ellipsize_chars, guess_width;
|
||||||
|
|
||||||
priv = label->priv;
|
priv = label->priv;
|
||||||
aux_info = _gtk_widget_get_aux_info (GTK_WIDGET (label), FALSE);
|
|
||||||
|
|
||||||
layout = pango_layout_copy (priv->layout);
|
layout = pango_layout_copy (priv->layout);
|
||||||
context = pango_layout_get_context (layout);
|
context = pango_layout_get_context (layout);
|
||||||
metrics = pango_context_get_metrics (context,
|
metrics = get_font_metrics (context, GTK_WIDGET (label));
|
||||||
gtk_widget_get_style (GTK_WIDGET (label))->font_desc,
|
|
||||||
pango_context_get_language (context));
|
|
||||||
|
|
||||||
char_width = pango_font_metrics_get_approximate_char_width (metrics);
|
char_width = pango_font_metrics_get_approximate_char_width (metrics);
|
||||||
digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
|
digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
|
||||||
char_pixels = MAX (char_width, digit_width);
|
char_pixels = MAX (char_width, digit_width);
|
||||||
@ -3108,11 +3118,16 @@ get_label_width (GtkLabel *label,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if a width-request is set, use that as the requested label width */
|
/* if a width-request is set, use that as the requested label width */
|
||||||
if ((priv->wrap || priv->ellipsize || priv->width_chars > 0 || priv->max_width_chars > 0) &&
|
if (priv->wrap || priv->ellipsize || priv->width_chars > 0 || priv->max_width_chars > 0)
|
||||||
aux_info && aux_info->width > 0)
|
|
||||||
{
|
{
|
||||||
*minimum = aux_info->width * PANGO_SCALE;
|
GtkWidgetAuxInfo *aux_info;
|
||||||
*natural = MAX (*natural, *minimum);
|
|
||||||
|
aux_info = _gtk_widget_get_aux_info (GTK_WIDGET (label), FALSE);
|
||||||
|
if (aux_info && aux_info->width > 0)
|
||||||
|
{
|
||||||
|
*minimum = aux_info->width * PANGO_SCALE;
|
||||||
|
*natural = MAX (*natural, *minimum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (layout);
|
g_object_unref (layout);
|
||||||
@ -3143,10 +3158,7 @@ get_label_wrap_width (GtkLabel *label)
|
|||||||
|
|
||||||
layout = pango_layout_copy (priv->layout);
|
layout = pango_layout_copy (priv->layout);
|
||||||
context = pango_layout_get_context (layout);
|
context = pango_layout_get_context (layout);
|
||||||
metrics = pango_context_get_metrics (context,
|
metrics = get_font_metrics (context, GTK_WIDGET (label));
|
||||||
gtk_widget_get_style (GTK_WIDGET (label))->font_desc,
|
|
||||||
pango_context_get_language (context));
|
|
||||||
|
|
||||||
char_width = pango_font_metrics_get_approximate_char_width (metrics);
|
char_width = pango_font_metrics_get_approximate_char_width (metrics);
|
||||||
digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
|
digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
|
||||||
char_pixels = MAX (char_width, digit_width);
|
char_pixels = MAX (char_width, digit_width);
|
||||||
@ -3353,9 +3365,7 @@ get_single_line_height (GtkWidget *widget,
|
|||||||
gint ascent, descent;
|
gint ascent, descent;
|
||||||
|
|
||||||
context = pango_layout_get_context (layout);
|
context = pango_layout_get_context (layout);
|
||||||
metrics = pango_context_get_metrics (context, gtk_widget_get_style (widget)->font_desc,
|
metrics = get_font_metrics (context, widget);
|
||||||
pango_context_get_language (context));
|
|
||||||
|
|
||||||
ascent = pango_font_metrics_get_ascent (metrics);
|
ascent = pango_font_metrics_get_ascent (metrics);
|
||||||
descent = pango_font_metrics_get_descent (metrics);
|
descent = pango_font_metrics_get_descent (metrics);
|
||||||
pango_font_metrics_unref (metrics);
|
pango_font_metrics_unref (metrics);
|
||||||
|
Loading…
Reference in New Issue
Block a user