box: Add RTL support for sibling paths

We want the reverse path when the box is right-to-left.
This commit is contained in:
Benjamin Otte
2011-05-28 00:17:01 +02:00
parent bdb8c64dd0
commit 2bc0fca209

View File

@ -155,6 +155,8 @@ static void gtk_box_size_allocate (GtkWidget *widget,
static void gtk_box_compute_expand (GtkWidget *widget, static void gtk_box_compute_expand (GtkWidget *widget,
gboolean *hexpand, gboolean *hexpand,
gboolean *vexpand); gboolean *vexpand);
static void gtk_box_direction_changed (GtkWidget *widget,
GtkTextDirection previous_direction);
static void gtk_box_set_property (GObject *object, static void gtk_box_set_property (GObject *object,
guint prop_id, guint prop_id,
@ -223,6 +225,7 @@ gtk_box_class_init (GtkBoxClass *class)
widget_class->get_preferred_height_for_width = gtk_box_get_preferred_height_for_width; widget_class->get_preferred_height_for_width = gtk_box_get_preferred_height_for_width;
widget_class->get_preferred_width_for_height = gtk_box_get_preferred_width_for_height; widget_class->get_preferred_width_for_height = gtk_box_get_preferred_width_for_height;
widget_class->compute_expand = gtk_box_compute_expand; widget_class->compute_expand = gtk_box_compute_expand;
widget_class->direction_changed = gtk_box_direction_changed;
container_class->add = gtk_box_add; container_class->add = gtk_box_add;
container_class->remove = gtk_box_remove; container_class->remove = gtk_box_remove;
@ -840,7 +843,8 @@ typedef struct _CountingData CountingData;
struct _CountingData { struct _CountingData {
GtkWidget *widget; GtkWidget *widget;
gboolean found; gboolean found;
guint count; guint before;
guint after;
}; };
static void static void
@ -855,23 +859,19 @@ count_widget_position (GtkWidget *widget,
return; return;
#endif #endif
if (count->found)
return;
if (count->widget == widget) if (count->widget == widget)
{
count->found = TRUE; count->found = TRUE;
return; else if (count->found)
} count->after++;
else
count->count++; count->before++;
} }
static guint static guint
gtk_box_get_visible_position (GtkBox *box, gtk_box_get_visible_position (GtkBox *box,
GtkWidget *child) GtkWidget *child)
{ {
CountingData count = { child, FALSE, 0 }; CountingData count = { child, FALSE, 0, 0 };
/* forall iterates in visible order */ /* forall iterates in visible order */
gtk_container_forall (GTK_CONTAINER (box), gtk_container_forall (GTK_CONTAINER (box),
@ -879,20 +879,11 @@ gtk_box_get_visible_position (GtkBox *box,
&count); &count);
g_assert (count.found); g_assert (count.found);
return count.count; if (box->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
} gtk_widget_get_direction (GTK_WIDGET (box)) == GTK_TEXT_DIR_RTL)
return count.after;
static void else
add_widget_to_path (GtkWidget *widget, return count.before;
gpointer path)
{
#if 0
/* We cannot reliably detect changes in widget visibility */
if (!gtk_widget_get_visible (widget))
return;
#endif
gtk_widget_path_append_for_widget (path, widget);
} }
static GtkWidgetPath * static GtkWidgetPath *
@ -908,11 +899,25 @@ gtk_box_get_path_for_child (GtkContainer *container,
if (private->sibling_path == NULL) if (private->sibling_path == NULL)
{ {
GList *list, *children;
private->sibling_path = gtk_widget_path_new (); private->sibling_path = gtk_widget_path_new ();
/* forall iterates in visible order */
gtk_container_forall (container, /* get_children works in visible order */
add_widget_to_path, children = gtk_container_get_children (container);
private->sibling_path); if (private->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_widget_get_direction (GTK_WIDGET (box)) == GTK_TEXT_DIR_RTL)
children = g_list_reverse (children);
for (list = children; list; list = list->next)
{
#if 0
/* We cannot reliably detect changes in widget visibility */
if (!gtk_widget_get_visible (list->data))
return;
#endif
gtk_widget_path_append_for_widget (private->sibling_path, list->data);
}
g_list_free (children);
} }
path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (container))); path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (container)));
@ -943,6 +948,12 @@ gtk_box_invalidate_order (GtkBox *box)
NULL); NULL);
} }
static void
gtk_box_direction_changed (GtkWidget *widget,
GtkTextDirection previous_direction)
{
gtk_box_invalidate_order (GTK_BOX (widget));
}
static void static void
gtk_box_pack (GtkBox *box, gtk_box_pack (GtkBox *box,
GtkWidget *child, GtkWidget *child,