]> Pileus Git - ~andy/gtk/commitdiff
Make GtkWidget::halign RTL-save
authorMatthias Clasen <mclasen@redhat.com>
Wed, 30 Mar 2011 06:25:12 +0000 (02:25 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 30 Mar 2011 14:34:02 +0000 (10:34 -0400)
This commit makes GTK_ALIGN_START/_END pay attention to
the text direction when used in horizontal context.

This is how similar parameters in GtkMisc and GtkAlignment work,
and is generally expected of GTK+ positioning parameters. And this
is new GTK+ 3 api, so it is basically still unused at this point.

If explicit right/left turn out to be needed at some point, we
can expand the enumeration with new values.

gtk/gtkenums.h
gtk/gtkwidget.c
tests/testadjustsize.c
tests/testexpand.c

index 2233b00b7f8ebc3196753802ede75b74708bcccf..95cfb299baceed7465cd315f1f9042dadab72c27 100644 (file)
@@ -63,6 +63,9 @@ G_BEGIN_DECLS
  * you have for example a 16x16 icon inside a 32x32 space, the icon
  * could be scaled and stretched, it could be centered, or it could be
  * positioned to one side of the space.
+ *
+ * Note that in horizontal context @GTK_ALIGN_START and @GTK_ALIGN_END
+ * are interpreted relative to text direction.
  */
 typedef enum
 {
index f1de106b9797271cc411769d52ca48ca5bde1731..46c9526b6f00ee169aeba8d05e53640b65cdf1e9 100644 (file)
@@ -5115,11 +5115,27 @@ gtk_widget_real_size_allocate (GtkWidget     *widget,
      }
 }
 
+/* translate initial/final into start/end */
+static GtkAlign
+effective_align (GtkAlign         align,
+                 GtkTextDirection direction)
+{
+  switch (align)
+    {
+    case GTK_ALIGN_START:
+      return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
+    case GTK_ALIGN_END:
+      return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
+    default:
+      return align;
+    }
+}
+
 static void
-adjust_for_align(GtkAlign           align,
-                 gint              *natural_size,
-                 gint              *allocated_pos,
-                 gint              *allocated_size)
+adjust_for_align (GtkAlign  align,
+                  gint     *natural_size,
+                  gint     *allocated_pos,
+                  gint     *allocated_size)
 {
   switch (align)
     {
@@ -5177,18 +5193,18 @@ gtk_widget_real_adjust_size_allocation (GtkWidget         *widget,
     {
       adjust_for_margin (aux_info->margin.left,
                          aux_info->margin.right,
-                         minimum_size, natural_size, 
-                        allocated_pos, allocated_size);
-      adjust_for_align (aux_info->halign,
+                         minimum_size, natural_size,
+                         allocated_pos, allocated_size);
+      adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
                         natural_size, allocated_pos, allocated_size);
     }
   else
     {
       adjust_for_margin (aux_info->margin.top,
                          aux_info->margin.bottom,
-                         minimum_size, natural_size, 
-                        allocated_pos, allocated_size);
-      adjust_for_align (aux_info->valign,
+                         minimum_size, natural_size,
+                         allocated_pos, allocated_size);
+      adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
                         natural_size, allocated_pos, allocated_size);
     }
 }
index c45522ad33eeb8762ed25d95684e86df09421995..38cc0553a6f466fae4f3d228446c293b1b023af4 100644 (file)
@@ -436,6 +436,9 @@ main (int argc, char *argv[])
 {
   gtk_init (&argc, &argv);
 
+  if (g_getenv ("RTL"))
+    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
+
   open_test_window ();
   open_control_window ();
   open_alignment_window ();
index 801b60e7ceffb8127d2941f322a6d220c453356d..6f34fb71e0c2027b386bef7eb5f2b48816d88443 100644 (file)
@@ -200,6 +200,9 @@ main (int argc, char *argv[])
 {
   gtk_init (&argc, &argv);
 
+  if (g_getenv ("RTL"))
+    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
+
   create_box_window ();
   create_table_window ();