GtkTreeView focus drawing patch



Hi:

Here is what I hope is the last of the focus drawing patches for
awhile... 

What it does:

(1) increases size requests for tree/table cells to account for thicker
focus lines;
(2) draws focus using a gtk state fg color appropriate to the focussed
row;
(3) uses the normal GtkEntry focus mechanism (text caret) for editable
fields;
(4) maintains sizing compat with previous version

OK to commit?

(p.s. - jrb the (unrelated) issue with large size expanders not getting 
quite enough space is still there, any suggestions?)

Regards,

Bill
Bill
Index: gtk/gtktreeview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeview.c,v
retrieving revision 1.203
diff -u -r1.203 gtktreeview.c
--- gtk/gtktreeview.c	2002/01/24 22:07:35	1.203
+++ gtk/gtktreeview.c	2002/01/25 18:21:49
@@ -2855,6 +2855,7 @@
 	  GtkRBTree *tree = NULL;
 	  GtkRBNode *node = NULL;
 	  gint width;
+	  gint focus_line_width;
 
           switch (tree_view->priv->drag_dest_pos)
             {
@@ -2874,14 +2875,17 @@
 		break;
 	      gdk_drawable_get_size (tree_view->priv->bin_window,
 				     &width, NULL);
+	      gtk_widget_style_get (widget, "focus-line-width", &focus_line_width, NULL);
 	      gtk_paint_focus (widget->style,
 			       tree_view->priv->bin_window,
 			       GTK_WIDGET_STATE (widget),
 			       NULL,
 			       widget,
 			       "treeview-drop-indicator",
-			       0, BACKGROUND_FIRST_PIXEL (tree_view, tree, node),
-			       width, BACKGROUND_HEIGHT (node));
+			       0, BACKGROUND_FIRST_PIXEL (tree_view, tree, node)
+			       - focus_line_width / 2,
+			       width, BACKGROUND_HEIGHT (node)
+			       - focus_line_width + 1);
 
               break;
             }
Index: gtk/gtktreeviewcolumn.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeviewcolumn.c,v
retrieving revision 1.89
diff -u -r1.89 gtktreeviewcolumn.c
--- gtk/gtktreeviewcolumn.c	2002/01/24 20:42:48	1.89
+++ gtk/gtktreeviewcolumn.c	2002/01/25 18:21:49
@@ -2125,6 +2125,7 @@
 {
   GList *list;
   gboolean first_cell = TRUE;
+  gint focus_line_width;
 
   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
 
@@ -2133,6 +2134,8 @@
   if (width)
     * width = 0;
 
+  gtk_widget_style_get (tree_column->tree_view, "focus-line-width", &focus_line_width, NULL);
+  
   for (list = tree_column->cell_list; list; list = list->next)
     {
       GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data;
@@ -2156,8 +2159,8 @@
 				  &new_height);
 
       if (height)
-	* height = MAX (*height, new_height);
-      info->requested_width = MAX (info->requested_width, new_width);
+	* height = MAX (*height, new_height) + focus_line_width * 2;
+      info->requested_width = MAX (info->requested_width, new_width) + focus_line_width * 2;
       if (width)
 	* width += info->requested_width;
       first_cell = TRUE;
@@ -2184,6 +2187,7 @@
   gint full_requested_width = 0;
   gint extra_space;
   gint min_x, min_y, max_x, max_y;
+  gint focus_line_width;
 
   min_x = G_MAXINT;
   min_y = G_MAXINT;
@@ -2192,6 +2196,8 @@
 
   real_cell_area = *cell_area;
 
+  gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
+			"focus-line-width", &focus_line_width, NULL);
   /* Find out how my extra space we have to allocate */
   for (list = tree_column->cell_list; list; list = list->next)
     {
@@ -2221,6 +2227,7 @@
 
       real_cell_area.width = info->requested_width +
 	(info->expand?extra_space:0);
+      real_cell_area.x += focus_line_width;
       if (render)
 	{
 	  gtk_cell_renderer_render (info->cell,
@@ -2278,17 +2285,17 @@
       if (min_x >= max_x || min_y >= max_y)
 	{
 	  *focus_rectangle = *cell_area;
-	  focus_rectangle->x -= 1;
-	  focus_rectangle->y -= 1;
-	  focus_rectangle->width += 2;
-	  focus_rectangle->height += 2;
+	  focus_rectangle->x -= focus_line_width;
+	  focus_rectangle->y -= focus_line_width;
+	  focus_rectangle->width += 2 * focus_line_width;
+	  focus_rectangle->height += 2 * focus_line_width;
 	}
       else
 	{
-	  focus_rectangle->x = min_x - 1;
-	  focus_rectangle->y = min_y - 1;
-	  focus_rectangle->width = (max_x - min_x) + 2;
-	  focus_rectangle->height = (max_y - min_y) + 2;
+	  focus_rectangle->x = min_x - focus_line_width;
+	  focus_rectangle->y = min_y - focus_line_width;
+	  focus_rectangle->width = (max_x - min_x) + 2 * focus_line_width;
+	  focus_rectangle->height = (max_y - min_y) + 2 * focus_line_width;
 	}
     }
 }
@@ -2394,23 +2401,28 @@
 				      GdkRectangle            *expose_area,
 				      guint                    flags)
 {
+  gint focus_line_width;
+  GtkStateType cell_state;
+  
   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
+  gtk_widget_style_get (GTK_WIDGET (tree_column->tree_view),
+			"focus-line-width", &focus_line_width, NULL);
   if (tree_column->editable_widget)
     {
       /* This function is only called on the editable row when editing.
        */
-
+#if 0
       gtk_paint_focus (tree_column->tree_view->style,
 		       window,
 		       GTK_WIDGET_STATE (tree_column->tree_view),
 		       NULL,
 		       tree_column->tree_view,
 		       "treeview",
-		       cell_area->x - 1,
-		       cell_area->y - 1,
-		       cell_area->width + 2,
-		       cell_area->height + 2);
-      
+		       cell_area->x - focus_line_width,
+		       cell_area->y - focus_line_width,
+		       cell_area->width + 2 * focus_line_width,
+		       cell_area->height + 2 * focus_line_width);
+#endif      
     }
   else
     {
@@ -2423,10 +2435,13 @@
 						 flags,
 						 FALSE,
 						 &focus_rectangle);
-      
+
+      cell_state = flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
+	      (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
+	      (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL));
       gtk_paint_focus (tree_column->tree_view->style,
 		       window,
-		       GTK_WIDGET_STATE (tree_column->tree_view),
+		       cell_state,
 		       NULL,
 		       tree_column->tree_view,
 		       "treeview",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]