[gnome-builder/wip/plugins: 18/36] workspace: flip left/right for RTL



commit 7a6f867702ecfae1bd608817750ae221bb359fcd
Author: Christian Hergert <christian hergert me>
Date:   Sat Jun 6 14:33:33 2015 -0700

    workspace: flip left/right for RTL

 src/workspace/gb-workspace.c |   44 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 41 insertions(+), 3 deletions(-)
---
diff --git a/src/workspace/gb-workspace.c b/src/workspace/gb-workspace.c
index e4810d9..675fa9c 100644
--- a/src/workspace/gb-workspace.c
+++ b/src/workspace/gb-workspace.c
@@ -62,7 +62,10 @@ struct _GbWorkspace
   gdouble           drag_position;
 };
 
-G_DEFINE_TYPE (GbWorkspace, gb_workspace, GTK_TYPE_OVERLAY)
+static void buildable_init_iface (GtkBuildableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GbWorkspace, gb_workspace, GTK_TYPE_OVERLAY,
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_init_iface))
 
 enum {
   PROP_0,
@@ -80,6 +83,7 @@ enum {
   LAST_CHILD_PROP
 };
 
+static GtkBuildableIface *gb_workspace_parent_buildable_iface;
 static GParamSpec *gParamSpecs [LAST_PROP];
 static GParamSpec *gChildParamSpecs [LAST_CHILD_PROP];
 
@@ -918,6 +922,26 @@ gb_workspace_unmap (GtkWidget *widget)
   GTK_WIDGET_CLASS (gb_workspace_parent_class)->unmap (widget);
 }
 
+static GObject *
+gb_workspace_get_internal_child (GtkBuildable *buildable,
+                                 GtkBuilder   *builder,
+                                 const gchar  *childname)
+{
+  GbWorkspace *self = (GbWorkspace *)buildable;
+
+  g_assert (GB_IS_WORKSPACE (self));
+
+  /*
+   * Override default get_internal_child to handle RTL vs LTR.
+   */
+  if (ide_str_equal0 (childname, "left_pane"))
+    return G_OBJECT (gb_workspace_get_left_pane (self));
+  else if (ide_str_equal0 (childname, "right_pane"))
+    return G_OBJECT (gb_workspace_get_right_pane (self));
+
+  return gb_workspace_parent_buildable_iface->get_internal_child (buildable, builder, childname);
+}
+
 static void
 gb_workspace_finalize (GObject *object)
 {
@@ -982,6 +1006,14 @@ gb_workspace_set_property (GObject      *object,
 }
 
 static void
+buildable_init_iface (GtkBuildableIface *iface)
+{
+  gb_workspace_parent_buildable_iface = g_type_interface_peek_parent (iface);
+
+  iface->get_internal_child = gb_workspace_get_internal_child;
+}
+
+static void
 gb_workspace_class_init (GbWorkspaceClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -1109,7 +1141,10 @@ gb_workspace_get_left_pane (GbWorkspace *self)
 {
   g_return_val_if_fail (GB_IS_WORKSPACE (self), NULL);
 
-  return self->children [GTK_POS_LEFT].widget;
+  if (gtk_widget_get_state_flags (GTK_WIDGET (self)) & GTK_STATE_FLAG_DIR_RTL)
+    return self->children [GTK_POS_RIGHT].widget;
+  else
+    return self->children [GTK_POS_LEFT].widget;
 }
 
 GtkWidget *
@@ -1117,7 +1152,10 @@ gb_workspace_get_right_pane (GbWorkspace *self)
 {
   g_return_val_if_fail (GB_IS_WORKSPACE (self), NULL);
 
-  return self->children [GTK_POS_RIGHT].widget;
+  if (gtk_widget_get_state_flags (GTK_WIDGET (self)) & GTK_STATE_FLAG_DIR_RTL)
+    return self->children [GTK_POS_LEFT].widget;
+  else
+    return self->children [GTK_POS_RIGHT].widget;
 }
 
 GtkWidget *


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