GtkAllocation *allocation);
static void gtk_label_state_flags_changed (GtkWidget *widget,
GtkStateFlags prev_state);
-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,
cairo_t *cr);
static gboolean gtk_label_focus (GtkWidget *widget,
widget_class->destroy = gtk_label_destroy;
widget_class->size_allocate = gtk_label_size_allocate;
widget_class->state_flags_changed = gtk_label_state_flags_changed;
- 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;
widget_class->realize = gtk_label_realize;
widget_class->unrealize = gtk_label_unrealize;
GtkSettings *settings;
gboolean shortcuts_connected;
+ /* The PangoContext is replaced when the screen changes, so clear the layouts */
+ gtk_label_clear_layout (GTK_LABEL (widget));
+
if (!gtk_widget_has_screen (widget))
return;
}
}
-static PangoFontMetrics *
-get_font_metrics (PangoContext *context, GtkWidget *widget)
-{
- GtkStyleContext *style_context;
- const PangoFontDescription *font;
- PangoFontMetrics *retval;
-
- style_context = gtk_widget_get_style_context (widget);
- font = gtk_style_context_get_font (style_context, GTK_STATE_FLAG_NORMAL);
-
- retval = pango_context_get_metrics (context,
- font,
- pango_context_get_language (context));
-
- return retval;
-}
-
/**
* gtk_label_get_measuring_layout:
* @label: the label
pango_attr_list_insert (attrs, attribute);
}
}
- else if (priv->markup_attrs && priv->markup_attrs)
+ else if (priv->markup_attrs || priv->attrs)
attrs = pango_attr_list_new ();
else
attrs = NULL;
gint char_width, digit_width;
context = pango_layout_get_context (layout);
- metrics = get_font_metrics (context, GTK_WIDGET (label));
+ metrics = pango_context_get_metrics (context,
+ pango_context_get_font_description (context),
+ pango_context_get_language (context));
char_width = pango_font_metrics_get_approximate_char_width (metrics);
digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
pango_font_metrics_unref (metrics);
static void
gtk_label_get_preferred_layout_size (GtkLabel *label,
- PangoRectangle *widest,
- PangoRectangle *highest)
+ PangoRectangle *smallest,
+ PangoRectangle *widest)
{
GtkLabelPrivate *priv = label->priv;
PangoLayout *layout;
priv->width_chars > -1 ? char_pixels * priv->width_chars
: 0);
- pango_layout_get_extents (layout, NULL, highest);
- highest->width = MAX (highest->width, char_pixels * priv->width_chars);
- highest->x = highest->y = 0;
+ pango_layout_get_extents (layout, NULL, smallest);
+ smallest->width = MAX (smallest->width, char_pixels * priv->width_chars);
+ smallest->x = smallest->y = 0;
if (priv->max_width_chars > -1 && widest->width > char_pixels * priv->max_width_chars)
{
layout = gtk_label_get_measuring_layout (label,
layout,
- MAX (highest->width, char_pixels * priv->max_width_chars));
+ MAX (smallest->width, char_pixels * priv->max_width_chars));
pango_layout_get_extents (layout, NULL, widest);
widest->width = MAX (widest->width, char_pixels * priv->width_chars);
widest->x = widest->y = 0;
}
- g_assert (widest->width >= highest->width);
}
else
{
- *highest = *widest;
+ *smallest = *widest;
}
- g_assert (widest->height <= highest->height);
+ if (widest->width < smallest->width)
+ *smallest = *widest;
g_object_unref (layout);
}
GtkLabel *label = GTK_LABEL (widget);
GtkLabelPrivate *priv = label->priv;
PangoRectangle widest_rect;
- PangoRectangle highest_rect;
+ PangoRectangle smallest_rect;
GtkBorder border;
- gtk_label_get_preferred_layout_size (label, &widest_rect, &highest_rect);
+ gtk_label_get_preferred_layout_size (label, &smallest_rect, &widest_rect);
/* Now that we have minimum and natural sizes in pango extents, apply a possible transform */
if (priv->have_transform)
matrix = pango_context_get_matrix (context);
pango_matrix_transform_rectangle (matrix, &widest_rect);
- pango_matrix_transform_rectangle (matrix, &highest_rect);
+ pango_matrix_transform_rectangle (matrix, &smallest_rect);
/* Bump the size in case of ellipsize to ensure pango has
* enough space in the angles (note, we could alternatively set the
*/
widest_rect.height += ROTATION_ELLIPSIZE_PADDING * 2 * PANGO_SCALE;
widest_rect.width += ROTATION_ELLIPSIZE_PADDING * 2 * PANGO_SCALE;
- highest_rect.height += ROTATION_ELLIPSIZE_PADDING * 2 * PANGO_SCALE;
- highest_rect.width += ROTATION_ELLIPSIZE_PADDING * 2 * PANGO_SCALE;
+ smallest_rect.height += ROTATION_ELLIPSIZE_PADDING * 2 * PANGO_SCALE;
+ smallest_rect.width += ROTATION_ELLIPSIZE_PADDING * 2 * PANGO_SCALE;
}
}
widest_rect.width = PANGO_PIXELS_CEIL (widest_rect.width);
widest_rect.height = PANGO_PIXELS_CEIL (widest_rect.height);
- highest_rect.width = PANGO_PIXELS_CEIL (highest_rect.width);
- highest_rect.height = PANGO_PIXELS_CEIL (highest_rect.height);
+ smallest_rect.width = PANGO_PIXELS_CEIL (smallest_rect.width);
+ smallest_rect.height = PANGO_PIXELS_CEIL (smallest_rect.height);
_gtk_misc_get_padding_and_border (GTK_MISC (label), &border);
*/
get_size_for_allocation (label,
GTK_ORIENTATION_VERTICAL,
- highest_rect.height,
+ smallest_rect.height,
minimum_size, natural_size);
}
else
{
/* Normal desired width */
- *minimum_size = highest_rect.width;
+ *minimum_size = smallest_rect.width;
*natural_size = widest_rect.width;
}
/* A vertically rotated label does w4h, so return the base
* desired height (text length)
*/
- *minimum_size = widest_rect.height;
- *natural_size = highest_rect.height;
+ *minimum_size = MIN (smallest_rect.height, widest_rect.height);
+ *natural_size = MAX (smallest_rect.height, widest_rect.height);
}
*minimum_size += border.top + border.bottom;
gtk_label_update_cursor (label);
}
- /* We have to clear the layout, fonts etc. may have changed */
- gtk_label_clear_layout (label);
-
if (GTK_WIDGET_CLASS (gtk_label_parent_class)->state_flags_changed)
GTK_WIDGET_CLASS (gtk_label_parent_class)->state_flags_changed (widget, prev_state);
}
-static void
-gtk_label_style_updated (GtkWidget *widget)
-{
- GtkLabel *label = GTK_LABEL (widget);
-
- GTK_WIDGET_CLASS (gtk_label_parent_class)->style_updated (widget);
-
- /* We have to clear the layout, fonts etc. may have changed */
- gtk_label_clear_layout (label);
-}
-
-static void
-gtk_label_direction_changed (GtkWidget *widget,
- GtkTextDirection previous_dir)
-{
- GtkLabel *label = GTK_LABEL (widget);
- GtkLabelPrivate *priv = label->priv;
-
- if (priv->layout)
- pango_layout_context_changed (priv->layout);
-
- GTK_WIDGET_CLASS (gtk_label_parent_class)->direction_changed (widget, previous_dir);
-}
-
static void
get_layout_location (GtkLabel *label,
gint *xp,
priv->select_info->window = gdk_window_new (gtk_widget_get_window (widget),
&attributes, attributes_mask);
- gdk_window_set_user_data (priv->select_info->window, widget);
+ gtk_widget_register_window (widget, priv->select_info->window);
if (attributes_mask & GDK_WA_CURSOR)
g_object_unref (attributes.cursor);
if (priv->select_info->window == NULL)
return;
- gdk_window_set_user_data (priv->select_info->window, NULL);
+ gtk_widget_unregister_window (GTK_WIDGET (label), priv->select_info->window);
gdk_window_destroy (priv->select_info->window);
priv->select_info->window = NULL;
}