[gtk+] Make GtkWidget::halign RTL-save
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Make GtkWidget::halign RTL-save
- Date: Wed, 30 Mar 2011 14:34:35 +0000 (UTC)
commit b2f872112a2a8d8dd915650718c70889ef0d0c8b
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Mar 30 02:25:12 2011 -0400
Make GtkWidget::halign RTL-save
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 | 3 +++
gtk/gtkwidget.c | 36 ++++++++++++++++++++++++++----------
tests/testadjustsize.c | 3 +++
tests/testexpand.c | 3 +++
4 files changed, 35 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h
index 2233b00..95cfb29 100644
--- a/gtk/gtkenums.h
+++ b/gtk/gtkenums.h
@@ -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
{
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index f1de106..46c9526 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -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);
}
}
diff --git a/tests/testadjustsize.c b/tests/testadjustsize.c
index c45522a..38cc055 100644
--- a/tests/testadjustsize.c
+++ b/tests/testadjustsize.c
@@ -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 ();
diff --git a/tests/testexpand.c b/tests/testexpand.c
index 801b60e..6f34fb7 100644
--- a/tests/testexpand.c
+++ b/tests/testexpand.c
@@ -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 ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]