+static GtkWidgetPath *
+gtk_path_bar_get_path_for_child (GtkContainer *container,
+ GtkWidget *child)
+{
+ GtkPathBar *path_bar = GTK_PATH_BAR (container);
+ GtkWidgetPath *path;
+
+ path = _gtk_widget_create_path (GTK_WIDGET (path_bar));
+
+ if (gtk_widget_get_visible (child) &&
+ gtk_widget_get_child_visible (child))
+ {
+ GtkWidgetPath *sibling_path;
+ GList *visible_children;
+ GList *l;
+ int pos;
+
+ /* 1. Build the list of visible children, in visually left-to-right order
+ * (i.e. independently of the widget's direction). Note that our
+ * button_list is stored in innermost-to-outermost path order!
+ */
+
+ visible_children = NULL;
+
+ if (gtk_widget_get_visible (path_bar->down_slider_button) &&
+ gtk_widget_get_child_visible (path_bar->down_slider_button))
+ visible_children = g_list_prepend (visible_children, path_bar->down_slider_button);
+
+ for (l = path_bar->button_list; l; l = l->next)
+ {
+ ButtonData *data = l->data;
+
+ if (gtk_widget_get_visible (data->button) &&
+ gtk_widget_get_child_visible (data->button))
+ visible_children = g_list_prepend (visible_children, data->button);
+ }
+
+ if (gtk_widget_get_visible (path_bar->up_slider_button) &&
+ gtk_widget_get_child_visible (path_bar->up_slider_button))
+ visible_children = g_list_prepend (visible_children, path_bar->up_slider_button);
+
+ if (gtk_widget_get_direction (GTK_WIDGET (path_bar)) == GTK_TEXT_DIR_RTL)
+ visible_children = g_list_reverse (visible_children);
+
+ /* 2. Find the index of the child within that list */
+
+ pos = 0;
+
+ for (l = visible_children; l; l = l->next)
+ {
+ GtkWidget *button = l->data;
+
+ if (button == child)
+ break;
+
+ pos++;
+ }
+
+ /* 3. Build the path */
+
+ sibling_path = gtk_widget_path_new ();
+
+ for (l = visible_children; l; l = l->next)
+ gtk_widget_path_append_for_widget (sibling_path, l->data);
+
+ gtk_widget_path_append_with_siblings (path, sibling_path, pos);
+
+ g_list_free (visible_children);
+ gtk_widget_path_unref (sibling_path);
+ }
+ else
+ gtk_widget_path_append_for_widget (path, child);
+
+ return path;
+}
+