patch to attach expander arrows to a GtkTextViewColumn and more



Hi,

This is a patch that change the behaviour of GtkTreeView for expander
arrows and adds support for (mouse) buttons 6 and 7 under X11.

gtk_tree_view_{set,get}_expander_column now expects/returns
GtkTreeViewColumn instead of gint, as it seems far more logical to me that
expander arrows follow a tree view column when it is draged/dropped than
stay at the same location. People wanting this behaviour may still be able
to have it catching the columns-changed signal.
The default behaviour is to draw expander arrows left justified (as of the
old behaviour with expander_column set to 0)
You can revert to the default passing NULL as the col argument to
set_expander_column

Under X11, buttons 6 and 7 correspond to a second wheel of a mouse.
They now generate GDK_SCROLL events with direction GDK_SCROLL_LEFT and
GDK_SCROLL_RIGHT (see bug #55424).
The patch also fixes GtkRange to account for these events (GDK_SCROLL_LEFT
has the same behaviour as GDK_SCROLL_UP).

Contrary to previous patches I sent here and on bugzilla -- forgive me for
any inconvenience --, this patch is -- I hope! -- done "according to the
rule book".

Here's the changelog entry:
Fri Jun  1 18:12:29 2001  Thomas Broyer  <tbroyer ltgt net>

	* gtk/gtktreeprivate.h:
	Add a TEXT_VIEW_IS_EXPANDER_ARROW macro and change
	expander_arrow in GtkTreeViewPrivate from gint to
	GtkTreeViewColumn*
	
	* gtk/gtktreeview.[ch] (gtk_tree_view_{set,get}_expander_column):
	Use a GtkTreeViewColumn* instead of gint.

	Throughout: Expander arrows are now attached to a
	GtkTreeViewColumn and follow it when dragged/dropped.

	* gdk/x11/gdkevents-x11.c (gdk_event_translate):
	buttons 6 and 7 generate GDK_SCROLL events (with direction
	GDK_SCROLL_LEFT and GDK_SCROLL_RIGHT)

	* gtk/gtkrange.c (gtk_range_scrol_event): Handle
	GDK_SCROLL_LEFT the same way as GDK_SCROLL_UP

Tom.
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.1991
diff -u -r1.1991 ChangeLog
--- ChangeLog	2001/05/31 19:11:14	1.1991
+++ ChangeLog	2001/06/01 22:55:35
@@ -1,3 +1,23 @@
+Fri Jun  1 18:12:29 2001  Thomas Broyer  <tbroyer ltgt net>
+
+	* gtk/gtktreeprivate.h:
+	Add a TEXT_VIEW_IS_EXPANDER_ARROW macro and change
+	expander_arrow in GtkTreeViewPrivate from gint to
+	GtkTreeViewColumn*
+	
+	* gtk/gtktreeview.[ch] (gtk_tree_view_{set,get}_expander_column):
+	Use a GtkTreeViewColumn* instead of gint.
+
+	Throughout: Expander arrows are now attached to a
+	GtkTreeViewColumn and follow it when dragged/dropped.
+
+	* gdk/x11/gdkevents-x11.c (gdk_event_translate):
+	buttons 6 and 7 generate GDK_SCROLL events (with direction
+	GDK_SCROLL_LEFT and GDK_SCROLL_RIGHT)
+
+	* gtk/gtkrange.c (gtk_range_scrol_event): Handle
+	GDK_SCROLL_LEFT the same way as GDK_SCROLL_UP
+
 Thu May 31 12:43:57 2001  Owen Taylor  <otaylor redhat com>
 
 	* gtk/gtkoptionmenu.c: Account for the fact that the border
Index: gdk/x11/gdkevents-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkevents-x11.c,v
retrieving revision 1.50
diff -u -r1.50 gdkevents-x11.c
--- gdk/x11/gdkevents-x11.c	2001/05/30 20:40:27	1.50
+++ gdk/x11/gdkevents-x11.c	2001/06/01 22:55:36
@@ -650,11 +650,14 @@
       
       /* If we get a ButtonPress event where the button is 4 or 5,
 	 it's a Scroll event */
-      if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5)
+      if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5
+	  || xevent->xbutton.button == 6 || xevent->xbutton.button == 7)
 	{
 	  event->scroll.type = GDK_SCROLL;
 	  event->scroll.direction = (xevent->xbutton.button == 4) ? 
-	    GDK_SCROLL_UP : GDK_SCROLL_DOWN;
+	    GDK_SCROLL_UP : (xevent->xbutton.button == 5) ? 
+	    GDK_SCROLL_DOWN : (xevent->xbutton.button == 6) ? 
+	    GDK_SCROLL_LEFT : GDK_SCROLL_RIGHT;
 	  event->scroll.window = window;
 	  event->scroll.time = xevent->xbutton.x;
 	  event->scroll.x = xevent->xbutton.x + xoffset;
@@ -699,7 +702,8 @@
 	}
       
       /* We treat button presses as scroll wheel events, so ignore the release */
-      if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5)
+      if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5
+	  || xevent->xbutton.button == 6 || xevent->xbutton.button == 7)
 	{
 	  return_val = FALSE;
 	  break;
Index: gtk/gtkrange.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkrange.c,v
retrieving revision 1.53
diff -u -r1.53 gtkrange.c
--- gtk/gtkrange.c	2001/05/17 16:22:04	1.53
+++ gtk/gtkrange.c	2001/06/01 22:55:37
@@ -1117,7 +1117,7 @@
   if (GTK_WIDGET_REALIZED (range))
     {
       GtkAdjustment *adj = GTK_RANGE (range)->adjustment;
-      gdouble new_value = adj->value + ((event->direction == GDK_SCROLL_UP) ? 
+      gdouble new_value = adj->value + ((event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_LEFT) ? 
 					-adj->page_increment / 2: 
 					adj->page_increment / 2);
       new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size);
Index: gtk/gtktreeprivate.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeprivate.h,v
retrieving revision 1.22
diff -u -r1.22 gtktreeprivate.h
--- gtk/gtktreeprivate.h	2001/05/25 15:43:53	1.22
+++ gtk/gtktreeprivate.h	2001/06/01 22:55:37
@@ -60,6 +60,7 @@
 #define TREE_VIEW_HEADER_HEIGHT(tree_view)        (GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_HEADERS_VISIBLE)?tree_view->priv->header_height:0)
 #define TREE_VIEW_COLUMN_WIDTH(column)             (CLAMP (column->width, (column->min_width!=-1)?column->min_width:column->width, (column->max_width!=-1)?column->max_width:column->width))
 #define TREE_VIEW_DRAW_EXPANDERS(tree_view)       (!GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_IS_LIST)&&GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_SHOW_EXPANDERS))
+#define TREE_VIEW_IS_EXPANDER_COLUMN(tree_view, col) ((tree_view->priv->expander_column==col)||((tree_view->priv->expander_column==NULL)&&(tree_view->priv->columns->data==col)))
 
  /* This lovely little value is used to determine how far away from the title bar
   * you can move the mouse and still have a column drag work.
@@ -101,7 +102,7 @@
   GtkTreeViewColumn *drag_column;
   gint drag_column_x;
 
-  gint expander_column;
+  GtkTreeViewColumn *expander_column;
 
   /* Focus code */
   GtkTreeViewColumn *focus_column;
Index: gtk/gtktreeview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeview.c,v
retrieving revision 1.84
diff -u -r1.84 gtktreeview.c
--- gtk/gtktreeview.c	2001/05/25 23:10:49	1.84
+++ gtk/gtktreeview.c	2001/06/01 22:55:40
@@ -417,13 +417,11 @@
 
   g_object_class_install_property (o_class,
                                    PROP_EXPANDER_COLUMN,
-                                   g_param_spec_uint ("expander_column",
-						      _("Expand Column"),
-						      _("Set the column number for the expander column"),
-						      0,
-						      G_MAXINT,
-						      0,
-						      G_PARAM_READWRITE));
+                                   g_param_spec_object ("expander_column",
+							_("Expander Column"),
+							_("Set the column for the expander column"),
+							GTK_TYPE_TREE_VIEW_COLUMN,
+							G_PARAM_READWRITE));
 
   g_object_class_install_property (o_class,
                                    PROP_REORDERABLE,
@@ -589,7 +587,7 @@
       gtk_tree_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
       break;
     case PROP_EXPANDER_COLUMN:
-      gtk_tree_view_set_expander_column (tree_view, g_value_get_uint (value));
+      gtk_tree_view_set_expander_column (tree_view, GTK_TREE_VIEW_COLUMN (g_value_get_object (value)));
       break;
     case PROP_REORDERABLE:
       gtk_tree_view_set_reorderable (tree_view, g_value_get_boolean (value));
@@ -627,7 +625,7 @@
       g_value_set_boolean (value, gtk_tree_view_get_headers_visible (tree_view));
       break;
     case PROP_EXPANDER_COLUMN:
-      g_value_set_uint (value, tree_view->priv->expander_column);
+      g_value_set_object (value, G_OBJECT (tree_view->priv->expander_column));
       break;
     case PROP_REORDERABLE:
       g_value_set_boolean (value, tree_view->priv->reorderable);
@@ -1216,7 +1214,7 @@
       background_area.x = 0;
       /* Let the cell have a chance at selecting it. */
 
-      for (i = 0, list = tree_view->priv->columns; i < tree_view->priv->n_columns; i++, list = list->next)
+      for (list = tree_view->priv->columns; list; list = list->next)
 	{
 	  GtkTreeIter iter;
 
@@ -1226,7 +1224,7 @@
 	    continue;
 
 	  background_area.width = column->displayed_width;
-	  if (i == tree_view->priv->expander_column &&
+	  if (TREE_VIEW_IS_EXPANDER_COLUMN (tree_view, column) &&
               TREE_VIEW_DRAW_EXPANDERS(tree_view))
 	    {
 	      cell_area = background_area;
@@ -2156,7 +2154,7 @@
   GtkTreeIter iter;
   gint new_y;
   gint y_offset, x_offset, cell_offset;
-  gint i, max_height;
+  gint max_height;
   gint depth;
   GdkRectangle background_area;
   GdkRectangle cell_area;
@@ -2256,7 +2254,7 @@
 
       parity = _gtk_rbtree_node_find_parity (tree, node);
 
-      for (i = 0, list = tree_view->priv->columns; i < tree_view->priv->n_columns; i++, list = list->next)
+      for (list = tree_view->priv->columns; list; list = list->next)
 	{
 	  GtkTreeViewColumn *column = list->data;
 	  const gchar *detail = NULL;
@@ -2346,7 +2344,7 @@
                               background_area.width,
                               background_area.height);
 
-	  if (i == tree_view->priv->expander_column &&
+	  if (TREE_VIEW_IS_EXPANDER_COLUMN(tree_view, column) &&
               TREE_VIEW_DRAW_EXPANDERS(tree_view))
 	    {
 	      cell_area.x += depth*tree_view->priv->tab_offset;
@@ -4482,7 +4480,6 @@
   GtkTreeViewColumn *tmp_column = NULL;
   gint total_width;
   GList *list;
-  gint i;
 
   if (x1)
     *x1 = 0;
@@ -4490,7 +4487,6 @@
   if (x2)
     *x2 = 0;
 
-  i = 0;
   total_width = 0;
   for (list = tree_view->priv->columns; list; list = list->next)
     {
@@ -4501,8 +4497,6 @@
 
       if (tmp_column->visible)
         total_width += tmp_column->width;
-
-      ++i;
     }
 
   if (tmp_column != column)
@@ -4515,7 +4509,7 @@
    * to the cell renderer.
    */
 
-  if (i == tree_view->priv->expander_column)
+  if (TREE_VIEW_IS_EXPANDER_COLUMN (tree_view, column))
     total_width += tree_view->priv->tab_offset * _gtk_rbtree_get_depth (tree);
 
   if (x1)
@@ -4539,15 +4533,13 @@
   GList *list;
   GtkTreeViewColumn *tmp_column = NULL;
   gint total_width;
-  gint i;
 
-  i = 0;
   total_width = 0;
   for (list = tree_view->priv->columns; list; list = list->next)
     {
       tmp_column = list->data;
 
-      if (i == tree_view->priv->expander_column)
+      if (TREE_VIEW_IS_EXPANDER_COLUMN (tree_view, tmp_column))
         {
           x_offset = total_width;
           break;
@@ -4555,8 +4547,6 @@
 
       if (tmp_column->visible)
         total_width += tmp_column->width;
-
-      ++i;
     }
 
   if (x1)
@@ -4637,11 +4627,8 @@
   GtkTreeViewColumn *column;
   GList *list;
   gint max_height = 0;
-  gint i;
   gint vertical_separator;
 
-  i = 0;
-
   gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical_separator", &vertical_separator, NULL);
   /* do stuff with node */
   for (list = tree_view->priv->columns; list; list = list->next)
@@ -4653,25 +4640,20 @@
 	continue;
 
       if (column->column_type == GTK_TREE_VIEW_COLUMN_FIXED)
-        {
-          ++i;
-          continue;
-        }
+        continue;
 
       gtk_tree_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
 
       gtk_tree_view_column_cell_get_size (column, NULL, NULL, NULL, &width, &height);
       max_height = MAX (max_height, vertical_separator + height);
 
-      if (i == tree_view->priv->expander_column &&
+      if (TREE_VIEW_IS_EXPANDER_COLUMN (tree_view, column) &&
           TREE_VIEW_DRAW_EXPANDERS (tree_view))
 	_gtk_tree_view_column_set_width (column,
                                         MAX (column->width, depth * tree_view->priv->tab_offset + width));
       else
         _gtk_tree_view_column_set_width (column,
                                         MAX (column->width, width));
-
-      ++i;
     }
   return max_height;
 }
@@ -4732,7 +4714,6 @@
   GtkTreeViewColumn *column;
   gint max_height;
   gint vertical_separator;
-  gint i;
 
   TREE_VIEW_INTERNAL_ASSERT_VOID (tree != NULL);
 
@@ -4746,7 +4727,7 @@
     {
       max_height = 0;
       /* Do stuff with node */
-      for (list = tree_view->priv->columns, i = 0; i < tree_view->priv->n_columns; list = list->next, i++)
+      for (list = tree_view->priv->columns; list; list = list->next)
 	{
 	  gint height = 0, width = 0;
 	  column = list->data;
@@ -4766,7 +4747,7 @@
 	    {
 	      continue;
 	    }
-	  if (i == tree_view->priv->expander_column &&
+	  if (TREE_VIEW_IS_EXPANDER_COLUMN (tree_view, column) &&
               TREE_VIEW_DRAW_EXPANDERS (tree_view))
             _gtk_tree_view_column_set_width (column,
                                             MAX (column->width, depth * tree_view->priv->tab_offset + width));
@@ -4792,14 +4773,13 @@
 {
   GtkTreeViewColumn *column;
   GList *list;
-  gint i;
   gboolean retval = FALSE;
   gint tmpheight;
 
   if (height)
     *height = 0;
 
-  for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
+  for (list = tree_view->priv->columns; list; list = list->next)
     {
       gint width;
       column = list->data;
@@ -4823,7 +4803,7 @@
 					      NULL, NULL, NULL,
 					      &width, NULL);
 	}
-      if (i == tree_view->priv->expander_column &&
+      if (TREE_VIEW_IS_EXPANDER_COLUMN (tree_view, column) &&
           TREE_VIEW_DRAW_EXPANDERS (tree_view))
 	{
 	  if (depth * tree_view->priv->tab_offset + width > column->width)
@@ -6291,16 +6271,29 @@
  * @tree_view: A #GtkTreeView
  * @col: The column to draw the expander arrow at.
  * 
- * Sets the column offset to draw the expander arrow at.
+ * Sets the column to draw the expander arrow at. It must be in
+ * @tree_view.
  **/
 void
-gtk_tree_view_set_expander_column (GtkTreeView *tree_view,
-                                   gint         col)
+gtk_tree_view_set_expander_column (GtkTreeView       *tree_view,
+                                   GtkTreeViewColumn *col)
 {
   g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
+  if (col != NULL)
+    g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (col));
 
   if (tree_view->priv->expander_column != col)
     {
+      GList *list;
+
+      for (list = tree_view->priv->columns; list; list = list->next)
+        {
+	  if (list->data == col)
+	    break;
+	}
+      if (!list)
+	return;
+
       tree_view->priv->expander_column = col;
 
       g_object_notify (G_OBJECT (tree_view), "expander_column");
@@ -6309,17 +6302,17 @@
 
 /**
  * gtk_tree_view_get_expander_column:
- * @tree_view:
+ * @tree_view: A #GtkTreeView
  *
- * Returns the offset of the column that is the current expander column.  This
+ * Returns the column that is the current expander column.  This
  * column has the expander arrow drawn next to it.
  *
- * Return value: The offset of the expander column.
+ * Return value: The expander column.
  **/
-gint
+GtkTreeViewColumn *
 gtk_tree_view_get_expander_column (GtkTreeView *tree_view)
 {
-  g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), -1);
+  g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL);
 
   return tree_view->priv->expander_column;
 }
@@ -7452,7 +7445,6 @@
   GtkRBTree    *tree;
   GtkRBNode    *node;
   GtkCellRenderer *cell;
-  gint i;
   gint cell_offset;
   GList *list;
   GdkRectangle background_area;
@@ -7507,7 +7499,7 @@
                       bin_window_width + 1,
                       background_area.height + 1);
 
-  for (i = 0, list = tree_view->priv->columns; i < tree_view->priv->n_columns; i++, list = list->next)
+  for (list = tree_view->priv->columns; list; list = list->next)
     {
       GtkTreeViewColumn *column = list->data;
       GdkRectangle cell_area;
@@ -7531,7 +7523,7 @@
       cell_area.y += vertical_separator / 2;
       cell_area.height -= vertical_separator;
 
-      if (i == tree_view->priv->expander_column &&
+      if (TREE_VIEW_IS_EXPANDER_COLUMN (tree_view, column) &&
           TREE_VIEW_DRAW_EXPANDERS(tree_view))
         {
           cell_area.x += depth * tree_view->priv->tab_offset;
Index: gtk/gtktreeview.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeview.h,v
retrieving revision 1.24
diff -u -r1.24 gtktreeview.h
--- gtk/gtktreeview.h	2001/05/25 20:41:43	1.24
+++ gtk/gtktreeview.h	2001/06/01 22:55:40
@@ -152,8 +152,8 @@
 								    GtkTreeViewColumn         *column,
 								    GtkTreeViewColumn         *base_column);
 void                   gtk_tree_view_set_expander_column           (GtkTreeView               *tree_view,
-								    gint                       col);
-gint                   gtk_tree_view_get_expander_column           (GtkTreeView               *tree_view);
+								    GtkTreeViewColumn         *col);
+GtkTreeViewColumn     *gtk_tree_view_get_expander_column           (GtkTreeView               *tree_view);
 void                   gtk_tree_view_set_column_drag_function      (GtkTreeView               *tree_view,
 								    GtkTreeViewColumnDropFunc  func,
 								    gpointer                   user_data,


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