Index: gtktreeview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeview.c,v
retrieving revision 1.309
diff -u -b -B -p -r1.309 gtktreeview.c
--- gtktreeview.c	5 Feb 2003 23:48:10 -0000	1.309
+++ gtktreeview.c	16 Feb 2003 23:35:41 -0000
@@ -1558,11 +1558,14 @@ invalidate_column (GtkTreeView       *tr
   gint column_offset = 0;
   GList *list;
   GtkWidget *widget = GTK_WIDGET (tree_view);
+  gboolean rtl;
 
   if (!GTK_WIDGET_REALIZED (widget))
     return;
 
-  for (list = tree_view->priv->columns; list; list = list->next)
+  rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
+  for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
+       list; list = (rtl ? list->prev : list->next))
     {
       GtkTreeViewColumn *tmpcolumn = list->data;
       if (tmpcolumn == column)
@@ -1586,9 +1589,11 @@ static void
 invalidate_last_column (GtkTreeView *tree_view)
 {
   GList *last_column;
+  gboolean rtl;
 
-  for (last_column = g_list_last (tree_view->priv->columns);
-       last_column; last_column = last_column->prev)
+  rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
+  for (last_column = (rtl? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
+       last_column; last_column = (rtl ? last_column->next : last_column->prev))
     {
       if (GTK_TREE_VIEW_COLUMN (last_column->data)->visible)
         {
@@ -1603,10 +1608,11 @@ static void
 gtk_tree_view_size_allocate_columns (GtkWidget *widget)
 {
   GtkTreeView *tree_view;
-  GList *list, *last_column;
+  GList *list, *first_column, *last_column;
   GtkTreeViewColumn *column;
   GtkAllocation allocation;
   gint width = 0;
+  gboolean rtl;
 
   tree_view = GTK_TREE_VIEW (widget);
 
@@ -1617,10 +1623,18 @@ gtk_tree_view_size_allocate_columns (Gtk
   if (last_column == NULL)
     return;
 
+  for (first_column = g_list_first (tree_view->priv->columns);
+       first_column && !(GTK_TREE_VIEW_COLUMN (first_column->data)->visible);
+       first_column = first_column->next)
+    ;
+
   allocation.y = 0;
   allocation.height = tree_view->priv->header_height;
 
-  for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
+  rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
+  for (list = (rtl ? last_column : first_column); 
+       list != (rtl ? first_column->prev : last_column->next);
+       list = (rtl ? list->prev : list->next)) 
     {
       gint real_requested_width = 0;
       gint old_width;
@@ -1674,7 +1688,7 @@ gtk_tree_view_size_allocate_columns (Gtk
       allocation.x = width;
       column->width = real_requested_width;
 
-      if (list == last_column &&
+      if (list == (rtl ? first_column : last_column) &&
 	  width + real_requested_width < widget->allocation.width)
 	{
 	  column->width += (widget->allocation.width - column->width - width);
@@ -1827,6 +1841,7 @@ gtk_tree_view_button_press (GtkWidget   
       GtkCellRenderer *focus_cell = NULL;
       gint column_handled_click = FALSE;
       gboolean emit_row_activated = FALSE;
+      gboolean rtl;
 
       if (!GTK_WIDGET_HAS_FOCUS (widget))
 	gtk_widget_grab_focus (widget);
@@ -1869,7 +1884,9 @@ gtk_tree_view_button_press (GtkWidget   
       background_area.x = 0;
 
       /* Let the column have a chance at selecting it. */
-      for (list = tree_view->priv->columns; list; list = list->next)
+      rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
+      for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
+	   list; list = (rtl ? list->prev : list->next))
 	{
 	  column = list->data;
 
@@ -2873,9 +2890,12 @@ gtk_tree_view_bin_expose (GtkWidget     
   gint focus_line_width;
   gboolean allow_rules;
   gboolean has_special_cell;
+  gboolean rtl;
 
   g_return_val_if_fail (GTK_IS_TREE_VIEW (widget), FALSE);
 
+  rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
+
   tree_view = GTK_TREE_VIEW (widget);
 
   gtk_widget_style_get (widget,
@@ -2933,11 +2953,11 @@ gtk_tree_view_bin_expose (GtkWidget     
   gdk_drawable_get_size (tree_view->priv->bin_window,
                          &bin_window_width, NULL);
 
-  for (last_column = g_list_last (tree_view->priv->columns);
+  for (last_column = rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns);
        last_column &&
 	 !(GTK_TREE_VIEW_COLUMN (last_column->data)->visible) &&
 	 GTK_WIDGET_CAN_FOCUS (GTK_TREE_VIEW_COLUMN (last_column->data)->button);
-       last_column = last_column->prev)
+       last_column = rtl ? last_column->next : last_column->prev)
     ;
 
   /* Actually process the expose event.  To do this, we want to
@@ -2970,7 +2990,8 @@ gtk_tree_view_bin_expose (GtkWidget     
 
       has_special_cell = gtk_tree_view_has_special_cell (tree_view);
 
-      for (list = tree_view->priv->columns; list; list = list->next)
+      for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
+	   list; list = (rtl ? list->prev : list->next))
 	{
 	  GtkTreeViewColumn *column = list->data;
 	  const gchar *detail = NULL;
@@ -3531,6 +3552,9 @@ gtk_tree_view_key_press (GtkWidget   *wi
 {
   GtkTreeView *tree_view = (GtkTreeView *) widget;
   GList *list;
+  gboolean rtl;
+
+  rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
 
   if (GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_IN_COLUMN_DRAG))
     {
@@ -3542,7 +3566,6 @@ gtk_tree_view_key_press (GtkWidget   *wi
       return TRUE;
     }
 
-  /* FIXME: this is prolly broken when we go bidi */
   if (tree_view->priv->columns && (event->state & GDK_SHIFT_MASK)
       && (event->keyval == GDK_Left || event->keyval == GDK_Right))
     {
@@ -3593,7 +3616,6 @@ gtk_tree_view_key_press (GtkWidget   *wi
 	}
     }
 
-  /* FIXME: broken when we go bidi? */
   if (tree_view->priv->columns && (event->state & GDK_CONTROL_MASK) &&
       (event->keyval == GDK_Left || event->keyval == GDK_Right
        || event->keyval == GDK_Home || event->keyval == GDK_End))
@@ -3604,7 +3626,7 @@ gtk_tree_view_key_press (GtkWidget   *wi
 	  GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (list->data);
 	  if (GTK_WIDGET_HAS_FOCUS (column->button))
 	    {
-	      if (event->keyval == GDK_Left)
+	      if (event->keyval == (rtl ? GDK_Right : GDK_Left))
 	        {
 		  GtkTreeViewColumn *col;
 		  col = gtk_tree_view_get_drop_column (tree_view, column, DROP_LEFT);
@@ -3612,7 +3634,7 @@ gtk_tree_view_key_press (GtkWidget   *wi
 		    gtk_tree_view_move_column_after (tree_view, column, col);
 		  return TRUE;
 		}
-	      else if (event->keyval == GDK_Right)
+	      else if (event->keyval == (rtl ? GDK_Left : GDK_Right))
 	        {
 		  GtkTreeViewColumn *col;
 		  col = gtk_tree_view_get_drop_column (tree_view, column, DROP_RIGHT);
@@ -3641,7 +3663,6 @@ gtk_tree_view_key_press (GtkWidget   *wi
 	}
     }
 
-  /* FIXME: this is prolly broken when we go bidi */
   if (tree_view->priv->columns &&
       GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_HEADERS_VISIBLE) &&
       (event->keyval == GDK_Left || event->keyval == GDK_Right))
@@ -3653,7 +3674,7 @@ gtk_tree_view_key_press (GtkWidget   *wi
 	  GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN (list->data);
 	  if (GTK_WIDGET_HAS_FOCUS (column->button))
 	    {
-	      if (event->keyval == GDK_Left && list->prev)
+	      if (event->keyval == (rtl ? GDK_Right : GDK_Left) && list->prev)
 	        {
 		  GList *tmp;
 
@@ -3670,7 +3691,7 @@ gtk_tree_view_key_press (GtkWidget   *wi
 		  gtk_adjustment_set_value (tree_view->priv->hadjustment, CLAMP (width, tree_view->priv->hadjustment->lower, tree_view->priv->hadjustment->upper - tree_view->priv->hadjustment->page_size));
 		  return TRUE;
 		}
-	      else if (event->keyval == GDK_Right && list->next)
+	      else if (event->keyval == (rtl ? GDK_Left : GDK_Right) && list->next)
 	        {
 		  GList *tmp;
 
@@ -5509,6 +5530,7 @@ gtk_tree_view_header_focus (GtkTreeView 
 
   GList *last_column, *first_column;
   GList *tmp_list;
+  gboolean rtl;
 
   if (! GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_HEADERS_VISIBLE))
     return FALSE;
@@ -5544,6 +5566,13 @@ gtk_tree_view_header_focus (GtkTreeView 
     }
 
 
+   rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
+   if (rtl) {
+     GList *temp = first_column;
+     first_column = last_column;
+     last_column = temp;
+   }
+
   switch (dir)
     {
     case GTK_DIR_TAB_BACKWARD:
@@ -6755,7 +6784,9 @@ gtk_tree_view_is_expander_column (GtkTre
     }
   else
     {
-      for (list = tree_view->priv->columns; list; list = list->next)
+      gboolean rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
+      for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
+	   list; list = (rtl ? list->prev : list->next))
 	if (((GtkTreeViewColumn *)list->data)->visible)
 	  break;
       if (list && list->data == column)
@@ -7365,6 +7396,9 @@ gtk_tree_view_move_cursor_left_right (Gt
   GtkTreeIter iter;
   GList *list;
   gboolean found_column = FALSE;
+  gboolean rtl;
+
+  rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
 
   if (! GTK_WIDGET_HAS_FOCUS (tree_view))
     return;
@@ -7415,9 +7449,9 @@ gtk_tree_view_move_cursor_left_right (Gt
 	}
     loop_end:
       if (count == 1)
-	list = list->next;
+	list = rtl ? list->prev : list->next;
       else
-	list = list->prev;
+	list = rtl ? list->next : list->prev;
     }
 
   if (found_column)
