diff options
author | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2010-11-25 17:41:26 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2010-11-25 17:41:26 +0900 |
commit | 2dd2c7ce054313a3e31b162ce78507c295926e0b (patch) | |
tree | e03608c8ec7887f3292ffbf729923b466c804e3f /gtk/gtkcellrenderertext.c | |
parent | 5f7787ab2ead2cdd11ebe17b16dd9498daaaf9c5 (diff) | |
download | gtk+-2dd2c7ce054313a3e31b162ce78507c295926e0b.tar.gz |
Added gtk_cell_renderer_get_aligned_area() and class vfunc.
Since a cell renderer might use more space than the natural
size when recieving expand space it's impossible to know how
much space is actually used to render content.
Adding this virtual method to allow text renderers to implement
it, the base default method uses height-for-width apis and aligns
the cell assuming the renderer uses a fixed size.
This commit removes the similar code from gtkcellarea and
subclasses.
Diffstat (limited to 'gtk/gtkcellrenderertext.c')
-rw-r--r-- | gtk/gtkcellrenderertext.c | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c index a93f16c9dc..f7df6b140c 100644 --- a/gtk/gtkcellrenderertext.c +++ b/gtk/gtkcellrenderertext.c @@ -84,6 +84,13 @@ static void gtk_cell_renderer_text_get_preferred_height_for_width (GtkCell gint width, gint *minimum_height, gint *natural_height); +static void gtk_cell_renderer_text_get_aligned_area (GtkCellRenderer *cell, + GtkWidget *widget, + GtkCellRendererState flags, + const GdkRectangle *cell_area, + GdkRectangle *aligned_area); + + enum { EDITED, @@ -240,6 +247,7 @@ gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class) cell_class->get_preferred_width = gtk_cell_renderer_text_get_preferred_width; cell_class->get_preferred_height = gtk_cell_renderer_text_get_preferred_height; cell_class->get_preferred_height_for_width = gtk_cell_renderer_text_get_preferred_height_for_width; + cell_class->get_aligned_area = gtk_cell_renderer_text_get_aligned_area; g_object_class_install_property (object_class, PROP_TEXT, @@ -1731,30 +1739,8 @@ get_size (GtkCellRenderer *cell, if (height) *height = ypad * 2 + rect.height; - /* The minimum size for ellipsized labels is ~ 3 chars */ if (width) - { - if (priv->ellipsize || priv->width_chars > 0) - { - PangoContext *context; - PangoFontMetrics *metrics; - gint char_width; - - context = pango_layout_get_context (layout); - metrics = pango_context_get_metrics (context, - gtk_widget_get_style (widget)->font_desc, - pango_context_get_language (context)); - - char_width = pango_font_metrics_get_approximate_char_width (metrics); - pango_font_metrics_unref (metrics); - - *width = xpad * 2 + (PANGO_PIXELS (char_width) * MAX (priv->width_chars, 3)); - } - else - { - *width = xpad * 2 + rect.x + rect.width; - } - } + *width = xpad * 2 + rect.x + rect.width; if (cell_area) { @@ -2250,3 +2236,24 @@ gtk_cell_renderer_text_get_preferred_height (GtkCellRenderer *cell, minimum_size, natural_size); } +static void +gtk_cell_renderer_text_get_aligned_area (GtkCellRenderer *cell, + GtkWidget *widget, + GtkCellRendererState flags, + const GdkRectangle *cell_area, + GdkRectangle *aligned_area) +{ + GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell); + PangoLayout *layout; + gint x_offset = 0; + gint y_offset = 0; + + layout = get_layout (celltext, widget, cell_area, flags); + get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, + &aligned_area->width, &aligned_area->height); + + aligned_area->x = cell_area->x + x_offset; + aligned_area->y = cell_area->y + y_offset; + + g_object_unref (layout); +} |