Flipping for scrolled windows



Another patch I've had sitting around for a while. This adds
directional flipping to GtkScrolledWindow, so the scrollbars
appear on the opposite side for RTL languages.

Trying this out it appears a bit stranger to me then some
of the other patches... this may just be because GtkCList and 
GtkTreeView don't properly flip properly yet either.

One could make the argument:

 - Putting the scrollbar on the right for LTR-languages 
   is just a convention and not a function of reading
   direction, so there is no particular to flip it for
   RTL language.

   (I use scrollbars on theleft for emacs and terminals...)

Opinions?
                                        Owen

Index: gtkscrolledwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkscrolledwindow.c,v
retrieving revision 1.54
diff -u -p -r1.54 gtkscrolledwindow.c
--- gtkscrolledwindow.c	2001/07/19 19:49:01	1.54
+++ gtkscrolledwindow.c	2001/09/24 16:06:55
@@ -771,16 +771,44 @@ gtk_scrolled_window_size_request (GtkWid
     }
 }
 
+static GtkCornerType 
+get_effective_window_placement (GtkScrolledWindow *scrollwin)
+{
+  if (gtk_widget_get_direction (GTK_WIDGET (scrollwin)) == GTK_TEXT_DIR_LTR)
+    {
+      return scrollwin->window_placement;
+    }
+  else
+    {
+      switch (scrollwin->window_placement)
+	{
+	case GTK_CORNER_TOP_LEFT:
+	  return GTK_CORNER_TOP_RIGHT;
+	case GTK_CORNER_BOTTOM_LEFT:
+	  return GTK_CORNER_BOTTOM_RIGHT;
+	case GTK_CORNER_TOP_RIGHT:
+	  return GTK_CORNER_TOP_LEFT;
+	case GTK_CORNER_BOTTOM_RIGHT:
+	  return GTK_CORNER_BOTTOM_RIGHT;
+	}
+    }
+
+  g_assert_not_reached ();
+  return GTK_CORNER_TOP_RIGHT;
+}
+
 static void
 gtk_scrolled_window_relative_allocation (GtkWidget     *widget,
 					 GtkAllocation *allocation)
 {
   GtkScrolledWindow *scrolled_window;
+  GtkCornerType window_placement;
 
   g_return_if_fail (widget != NULL);
   g_return_if_fail (allocation != NULL);
 
   scrolled_window = GTK_SCROLLED_WINDOW (widget);
+  window_placement = get_effective_window_placement (scrolled_window);
 
   allocation->x = GTK_CONTAINER (widget)->border_width;
   allocation->y = GTK_CONTAINER (widget)->border_width;
@@ -800,8 +828,8 @@ gtk_scrolled_window_relative_allocation 
       gtk_widget_get_child_requisition (scrolled_window->vscrollbar,
 					&vscrollbar_requisition);
   
-      if (scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT ||
-	  scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)
+      if (window_placement == GTK_CORNER_TOP_RIGHT ||
+	  window_placement == GTK_CORNER_BOTTOM_RIGHT)
 	allocation->x += (vscrollbar_requisition.width +
 			  SCROLLBAR_SPACING (scrolled_window));
 
@@ -815,8 +843,8 @@ gtk_scrolled_window_relative_allocation 
       gtk_widget_get_child_requisition (scrolled_window->hscrollbar,
 					&hscrollbar_requisition);
   
-      if (scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT ||
-	  scrolled_window->window_placement == GTK_CORNER_BOTTOM_RIGHT)
+      if (window_placement == GTK_CORNER_BOTTOM_LEFT ||
+	  window_placement == GTK_CORNER_BOTTOM_RIGHT)
 	allocation->y += (hscrollbar_requisition.height +
 			  SCROLLBAR_SPACING (scrolled_window));
 
@@ -834,6 +862,7 @@ gtk_scrolled_window_size_allocate (GtkWi
   GtkBin *bin;
   GtkAllocation relative_allocation;
   GtkAllocation child_allocation;
+  GtkCornerType window_placement;
   
   g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
   g_return_if_fail (allocation != NULL);
@@ -841,6 +870,8 @@ gtk_scrolled_window_size_allocate (GtkWi
   scrolled_window = GTK_SCROLLED_WINDOW (widget);
   bin = GTK_BIN (scrolled_window);
 
+  window_placement = get_effective_window_placement (scrolled_window);
+
   widget->allocation = *allocation;
 
   if (scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
@@ -906,8 +937,8 @@ gtk_scrolled_window_size_allocate (GtkWi
 	gtk_widget_show (scrolled_window->hscrollbar);
 
       child_allocation.x = relative_allocation.x;
-      if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT ||
-	  scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT)
+      if (window_placement == GTK_CORNER_TOP_LEFT ||
+	  window_placement == GTK_CORNER_TOP_RIGHT)
 	child_allocation.y = (relative_allocation.y +
 			      relative_allocation.height +
 			      SCROLLBAR_SPACING (scrolled_window) +
@@ -941,8 +972,8 @@ gtk_scrolled_window_size_allocate (GtkWi
       gtk_widget_get_child_requisition (scrolled_window->vscrollbar,
 					&vscrollbar_requisition);
 
-      if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT ||
-	  scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT)
+      if (window_placement == GTK_CORNER_TOP_LEFT ||
+	  window_placement == GTK_CORNER_BOTTOM_LEFT)
 	child_allocation.x = (relative_allocation.x +
 			      relative_allocation.width +
 			      SCROLLBAR_SPACING (scrolled_window) +




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