From d99742e1cb7751af872faffd7aec6747c8a02da6 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 19 Dec 2009 10:31:16 -0500 Subject: [PATCH] implement extended layout for GtkCellRendererText --- gtk/gtkcellrenderertext.c | 46 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c index bbdd21b917..e2cc48ff77 100644 --- a/gtk/gtkcellrenderertext.c +++ b/gtk/gtkcellrenderertext.c @@ -21,6 +21,7 @@ #include #include "gtkcellrenderertext.h" #include "gtkeditable.h" +#include "gtkextendedlayout.h" #include "gtkentry.h" #include "gtkmarshalers.h" #include "gtkintl.h" @@ -61,6 +62,8 @@ static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer GdkRectangle *cell_area, GtkCellRendererState flags); +static void gtk_cell_renderer_text_extended_layout_init (GtkExtendedLayoutIface *iface); + enum { EDITED, LAST_SIGNAL @@ -148,9 +151,12 @@ struct _GtkCellRendererTextPrivate gint wrap_width; GtkWidget *entry; + GtkWidget *owner; }; -G_DEFINE_TYPE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER) +G_DEFINE_TYPE_WITH_CODE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER, + G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT, + gtk_cell_renderer_text_extended_layout_init)) static void gtk_cell_renderer_text_init (GtkCellRendererText *celltext) @@ -1494,6 +1500,7 @@ get_size (GtkCellRenderer *cell, GtkCellRendererTextPrivate *priv; priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell); + priv->owner = widget; if (celltext->calc_fixed_height) { @@ -1930,5 +1937,42 @@ gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer } } +static void +gtk_cell_renderer_text_extended_layout_get_desired_size (GtkExtendedLayout *layout, + GtkRequisition *minimal_size, + GtkRequisition *desired_size) +{ + GtkCellRendererTextPrivate *priv; + + priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (layout); + + if (minimal_size) + { + get_size (GTK_CELL_RENDERER (layout), + priv->owner, NULL, NULL, NULL, NULL, + &minimal_size->width, &minimal_size->height); + } + + if (desired_size) + { + PangoEllipsizeMode ellipsize; + + ellipsize = priv->ellipsize; + priv->ellipsize = PANGO_ELLIPSIZE_NONE; + + get_size (GTK_CELL_RENDERER (layout), + priv->owner, NULL, NULL, NULL, NULL, + &desired_size->width, &desired_size->height); + + priv->ellipsize = ellipsize; + } +} + +static void +gtk_cell_renderer_text_extended_layout_init (GtkExtendedLayoutIface *iface) +{ + iface->get_desired_size = gtk_cell_renderer_text_extended_layout_get_desired_size; +} + #define __GTK_CELL_RENDERER_TEXT_C__ #include "gtkaliasdef.c"