]> Pileus Git - ~andy/gtk/commitdiff
Added some rules to GtkCellAreaBox for rendering the last cell.
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Wed, 1 Dec 2010 13:42:54 +0000 (22:42 +0900)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Wed, 1 Dec 2010 13:56:06 +0000 (22:56 +0900)
 - When we reach a cell that is out of the render area, break out
   of the loop (for columns user resized too small)
 - CLAMP the size of the last renderer to fit into the area
   (so that renderers get a chance to ellipsize when rendered
   with a space less than allocation, same reason as above).
 - Hand out remaining space in the render area to the last cell,
   this is for shallow rows in the expand column which may recieve
   more than the allocated width.

gtk/gtkcellareabox.c
tests/testtreeview.c

index 12988e6ad26a9d45884fa5bd2d548678071ee24c..a3a241c8dde0fab1e9c90a89307cc29d9f02f9f3 100644 (file)
@@ -1172,6 +1172,38 @@ gtk_cell_area_box_render (GtkCellArea          *area,
          cell_background.height = cell->size;
        }
 
+      /* Stop rendering cells if they flow out of the render area,
+       * this can happen because the render area can actually be
+       * smaller than the requested area (treeview columns can
+       * be user resizable and can be resized to be smaller than
+       * the actual requested area). */
+      if (cell_background.x > cell_area->x + cell_area->width ||
+         cell_background.y > cell_area->y + cell_area->height)
+       break;
+
+      /* Special case for the last cell... let the last cell consume the remaining
+       * space in the area (the last cell is allowed to consume the remaining space if
+       * the space given for rendering is actually larger than allocation, this can
+       * happen in the expander GtkTreeViewColumn where only the deepest depth column
+       * receives the allocation... shallow columns recieve more width). */
+      if (!l->next)
+       {
+         cell_background.width  = cell_area->x + cell_area->width  - cell_background.x;
+         cell_background.height = cell_area->y + cell_area->height - cell_background.y;
+       }
+      else
+       {
+         /* If the cell we are rendering doesnt fit into the remaining space, clip it
+          * so that the underlying renderer has a chance to deal with it (for instance
+          * text renderers get a chance to ellipsize).
+          */
+         if (cell_background.x + cell_background.width > cell_area->x + cell_area->width)
+           cell_background.width = cell_area->x + cell_area->width - cell_background.x;
+
+         if (cell_background.y + cell_background.height > cell_area->y + cell_area->height)
+           cell_background.height = cell_area->y + cell_area->height - cell_background.y;
+       }
+
       /* Remove margins from the background area to produce the cell area
        */
       gtk_cell_area_inner_cell_area (area, widget, &cell_background, &inner_area);
index d28cb3520adaaa64d88df5820fb883dd0c5586fb..c252ebfc8c5b70b380c0591b35430e53bf312c13 100644 (file)
@@ -351,7 +351,7 @@ set_columns_type (GtkTreeView *tree_view, ColumnsType type)
       gtk_tree_view_set_rules_hint (tree_view, TRUE);
       
       rend = gtk_cell_renderer_text_new ();
-      
+
       col = gtk_tree_view_column_new_with_attributes ("Column 1",
                                                       rend,
                                                       "text", 1,