+}
+
+static void
+gtk_cell_renderer_text_get_preferred_width (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ GtkCellRendererTextPrivate *priv;
+ GtkCellRendererText *celltext;
+ PangoLayout *layout;
+ PangoContext *context;
+ PangoFontMetrics *metrics;
+ PangoRectangle rect;
+ gint char_width, text_width, ellipsize_chars, xpad;
+ gint min_width, nat_width;
+
+ /* "width-chars" Hard-coded minimum width:
+ * - minimum size should be MAX (width-chars, strlen ("..."));
+ * - natural size should be MAX (width-chars, strlen (label->text));
+ *
+ * "wrap-width" User specified natural wrap width
+ * - minimum size should be MAX (width-chars, 0)
+ * - natural size should be MIN (wrap-width, strlen (label->text))
+ */
+
+ celltext = GTK_CELL_RENDERER_TEXT (cell);
+ priv = celltext->priv;
+
+ gtk_cell_renderer_get_padding (cell, &xpad, NULL);
+
+ layout = get_layout (celltext, widget, NULL, 0);
+
+ /* Fetch the length of the complete unwrapped text */
+ pango_layout_set_width (layout, -1);
+ pango_layout_get_extents (layout, NULL, &rect);
+ text_width = rect.width;
+
+ /* Fetch the average size of a charachter */
+ context = pango_layout_get_context (layout);
+ 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);
+
+ pango_font_metrics_unref (metrics);
+ g_object_unref (layout);
+
+ /* enforce minimum width for ellipsized labels at ~3 chars */
+ if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE)
+ ellipsize_chars = 3;