gtk3: honor lookup table labels and orientation
authorDaiki Ueno <ueno@unixuser.org>
Wed, 14 Mar 2012 02:07:47 +0000 (11:07 +0900)
committerDaiki Ueno <ueno@unixuser.org>
Wed, 14 Mar 2012 02:07:47 +0000 (11:07 +0900)
BUG=none
TEST=manual

Review URL: https://codereview.appspot.com/5798074

ui/gtk3/candidatearea.vala
ui/gtk3/candidatepanel.vala

index 13ebf76..85a830d 100644 (file)
@@ -34,6 +34,11 @@ class CandidateArea : Gtk.Box {
     private uint m_focus_candidate;
     private bool m_show_cursor;
 
+    private const string LABELS[] = {
+        "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.",
+        "9.", "0.", "a.", "b.", "c.", "d.", "e.", "f."
+    };
+
     public signal void candidate_clicked(uint index, uint button, uint state);
     public signal void page_up();
     public signal void page_down();
@@ -61,19 +66,12 @@ class CandidateArea : Gtk.Box {
             show_all();
     }
 
-    public void set_labels(string[] labels) {
-        if (labels == null) {
-            const string labels[] = {
-                "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.",
-                "9.", "0.", "a.", "b.", "c.", "d.", "e.", "f."
-            };
-            for (int i = 0 ; i < 16; i++)
-                m_labels[i].set_text(labels[i]);
-        } else {
-            int i = 0;
-            foreach (string label in labels)
-                m_labels[i].set_text(label);
-        }
+    public void set_labels(IBus.Text[] labels) {
+        int i;
+        for (i = 0; i < int.min(16, labels.length); i++)
+            m_labels[i].set_text(labels[i].get_text());
+        for (; i < 16; i++)
+            m_labels[i].set_text(LABELS[i]);
     }
 
     public void set_candidates(IBus.Text[] candidates,
@@ -130,11 +128,6 @@ class CandidateArea : Gtk.Box {
             w.destroy();
         }
 
-        const string labels[] = {
-            "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.",
-            "9.", "0.", "a.", "b.", "c.", "d.", "e.", "f."
-        };
-
         Gtk.Button prev_button = new Gtk.Button();
         prev_button.clicked.connect((b) => page_up());
         prev_button.set_image(new Gtk.Image.from_icon_name(Gtk.Stock.GO_UP, Gtk.IconSize.MENU));
@@ -171,7 +164,7 @@ class CandidateArea : Gtk.Box {
             m_candidates = {};
             m_widgets = {};
             for (int i = 0; i < 16; i++) {
-                Gtk.Label label = new Gtk.Label(labels[i]);
+                Gtk.Label label = new Gtk.Label(LABELS[i]);
                 label.set_alignment(0.0f, 0.5f);
                 label.show();
                 m_labels += label;
@@ -215,7 +208,7 @@ class CandidateArea : Gtk.Box {
             m_candidates = {};
             m_widgets = {};
             for (int i = 0; i < 16; i++) {
-                Gtk.Label label = new Gtk.Label(labels[i]);
+                Gtk.Label label = new Gtk.Label(LABELS[i]);
                 label.set_alignment(0.0f, 0.5f);
                 label.show();
                 m_labels += label;
index 614ccea..a029e8f 100644 (file)
@@ -79,6 +79,20 @@ public class CandidatePanel : Gtk.HBox{
         m_candidate_area.set_vertical(vertical);
     }
 
+    private void set_orientation(IBus.Orientation orientation) {
+        switch (orientation) {
+        case IBus.Orientation.VERTICAL:
+            m_candidate_area.set_vertical(true);
+            break;
+        case IBus.Orientation.HORIZONTAL:
+            m_candidate_area.set_vertical(false);
+            break;
+        case IBus.Orientation.SYSTEM:
+            m_candidate_area.set_vertical(m_vertical);
+            break;
+        }
+    }
+
     public void set_cursor_location(int x, int y, int width, int height) {
         Gdk.Rectangle location = Gdk.Rectangle(){
             x = x, y = y, width = width, height = height };
@@ -88,7 +102,7 @@ public class CandidatePanel : Gtk.HBox{
         adjust_window_position();
     }
 
-    public void set_labels(string[] labels) {
+    private void set_labels(IBus.Text[] labels) {
         m_candidate_area.set_labels(labels);
     }
 
@@ -118,6 +132,8 @@ public class CandidatePanel : Gtk.HBox{
         IBus.Text[] candidates = {};
         uint cursor_in_page = 0;
         bool show_cursor = true;
+        IBus.Text[] labels = {};
+        IBus.Orientation orientation = IBus.Orientation.SYSTEM;
 
         if (table != null) {
             uint page_size = table.get_page_size();
@@ -130,8 +146,19 @@ public class CandidatePanel : Gtk.HBox{
             uint page_end_pos = uint.min(page_start_pos + page_size, ncandidates);
             for (uint i = page_start_pos; i < page_end_pos; i++)
                 candidates += table.get_candidate(i);
+
+            for (uint i = 0; i < page_size; i++) {
+                IBus.Text? label = table.get_label(i);
+                if (label != null)
+                    labels += label;
+            }
+
+            orientation = (IBus.Orientation)table.get_orientation();
         }
         m_candidate_area.set_candidates(candidates, cursor_in_page, show_cursor);
+        set_labels(labels);
+        set_orientation(orientation);
+
         if (candidates.length != 0)
             m_candidate_area.show_all();
         else