summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorJonathan Blandford <jrb@redhat.com>2004-08-31 21:15:51 +0000
committerJonathan Blandford <jrb@src.gnome.org>2004-08-31 21:15:51 +0000
commit08bc720614a530b39c626d91ac322f835c9f7775 (patch)
treee4e43aaa5d6e65a7579cc490f2d1fad3e2fdc7d6 /gtk
parentc0ba86bc81753b1061a4d4f29c6f9ceb2f3c51db (diff)
downloadgtk+-08bc720614a530b39c626d91ac322f835c9f7775.tar.gz
constrain cell area to passed in cell_area, #147867
Tue Aug 31 17:07:41 2004 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_cell_process_action): constrain cell area to passed in cell_area, #147867 * gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_get_size): if ellipsizing, get_size is only 3 chars wide. * docs/tree-column-sizing.png: Add Matthias's excellent image.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkcellrenderertext.c26
-rw-r--r--gtk/gtktreeviewcolumn.c29
2 files changed, 50 insertions, 5 deletions
diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c
index ef64be14da..4c7bd27788 100644
--- a/gtk/gtkcellrenderertext.c
+++ b/gtk/gtkcellrenderertext.c
@@ -1382,12 +1382,32 @@ gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
pango_layout_get_pixel_extents (layout, NULL, &rect);
- if (width)
- *width = GTK_CELL_RENDERER (celltext)->xpad * 2 + rect.width;
-
if (height)
*height = GTK_CELL_RENDERER (celltext)->ypad * 2 + rect.height;
+ /* The minimum size for ellipsized labels is ~ 3 chars */
+ if (width)
+ {
+ if (priv->ellipsize)
+ {
+ PangoContext *context;
+ PangoFontMetrics *metrics;
+ gint char_width;
+
+ context = pango_layout_get_context (layout);
+ metrics = pango_context_get_metrics (context, widget->style->font_desc, NULL);
+
+ char_width = pango_font_metrics_get_approximate_char_width (metrics);
+ pango_font_metrics_unref (metrics);
+
+ *width += (PANGO_PIXELS (char_width) * 3);
+ }
+ else
+ {
+ *width = GTK_CELL_RENDERER (celltext)->xpad * 2 + rect.width;
+ }
+ }
+
if (cell_area)
{
if (x_offset)
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index 70349d9646..eea8180433 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -2621,6 +2621,9 @@ gtk_tree_view_column_cell_get_size (GtkTreeViewColumn *tree_column,
/* rendering, event handling and rendering focus are somewhat complicated, and
* quite a bit of code. Rather than duplicate them, we put them together to
* keep the code in one place.
+ *
+ * To better understand what's going on, check out
+ * docs/tree-column-sizing.png
*/
enum {
CELL_ACTION_RENDER,
@@ -2713,10 +2716,10 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column,
if (info->expand == TRUE)
expand_cell_count ++;
full_requested_width += info->requested_width;
+ /* FIXME: We prolly need to include tree_column->spacing here */
}
- extra_space = cell_area->width + horizontal_separator - full_requested_width;
-
+ extra_space = cell_area->width - full_requested_width;
if (extra_space < 0)
extra_space = 0;
else if (extra_space > 0 && expand_cell_count > 0)
@@ -2740,13 +2743,26 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column,
info->real_width = info->requested_width + (info->expand?extra_space:0);
+ /* We constrain ourselves to only the width available */
+ if (real_cell_area.x + info->real_width > cell_area->x + cell_area->width)
+ {
+ info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
+ }
+
+ if (real_cell_area.x > cell_area->x + cell_area->width)
+ break;
+
real_cell_area.width = info->real_width;
+
real_background_area.width=
real_cell_area.x + real_cell_area.width - real_background_area.x;
real_cell_area.width -= 2 * focus_line_width;
rtl_cell_area = real_cell_area;
rtl_background_area = real_background_area;
+
+
+
if (rtl)
{
rtl_cell_area.x = cell_area->x + cell_area->width - (real_cell_area.x - cell_area->x) - real_cell_area.width;
@@ -2895,6 +2911,15 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column,
info->real_width = info->requested_width + (info->expand?extra_space:0);
+ /* We constrain ourselves to only the width available */
+ if (real_cell_area.x + info->real_width > cell_area->x + cell_area->width)
+ {
+ info->real_width = cell_area->x + cell_area->width - real_cell_area.x;
+ }
+
+ if (real_cell_area.x > cell_area->x + cell_area->width)
+ break;
+
real_cell_area.width = info->real_width;
real_background_area.width =
real_cell_area.x + real_cell_area.width - real_background_area.x;