[gnome-flashback/wip/segeiger/gnome-3-18-inputmethods: 4/5] Use CandidateBox



commit 808f59d9de0b42f6422f1aadba5cce7614020f63
Author: Sebastian Geiger <sbastig gmx net>
Date:   Sun Jan 17 18:08:58 2016 +0100

    Use CandidateBox
    
    Still need to rebase and merge this in the main commit

 .../libinput-sources/gf-candidate-area.c           |   64 +++++--------------
 1 files changed, 17 insertions(+), 47 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/gf-candidate-area.c 
b/gnome-flashback/libinput-sources/gf-candidate-area.c
index ae603cc..e69c1bd 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-area.c
+++ b/gnome-flashback/libinput-sources/gf-candidate-area.c
@@ -18,6 +18,7 @@
 #include "config.h"
 
 #include "gf-candidate-area.h"
+#include "gf-candidate-box.h"
 
 #define MAX_CANDIDATES_PER_PAGE 16
 
@@ -36,8 +37,6 @@ struct _GfCandidateArea
   GtkWidget       *next_button;
 
   GSList          *candidate_boxes;
-  GSList          *index_labels;
-  GSList          *candidate_labels;
 
   IBusOrientation  orientation;
   guint            cursor_position;
@@ -63,7 +62,7 @@ button_clicked_cb (GtkWidget       *widget,
 {
   int index;
 
-  index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "index"));
+  index = gf_candidate_box_get_index (GF_CANDIDATE_BOX (widget));
 
   g_signal_emit (area,  signals[SIGNAL_CANDIDATE_CLICKED], 0, index, event);
 
@@ -177,8 +176,6 @@ gf_candidate_area_set_candidates (GfCandidateArea *area,
     {
       gboolean visible;
       GtkWidget *candidate_box;
-      GtkWidget *index_label;
-      GtkWidget *candidate_label;
       const gchar *index_text;
 
       visible = i < g_slist_length (candidates);
@@ -189,19 +186,16 @@ gf_candidate_area_set_candidates (GfCandidateArea *area,
       if (!visible)
         continue;
 
-      index_label = g_slist_nth_data (area->index_labels, i);
-
       if (indexes && g_slist_nth_data (indexes, i))
           index_text = g_slist_nth_data (indexes, i);
       else
           index_text = DEFAULT_INDEX_LABELS [i];
 
-      gtk_label_set_text (GTK_LABEL(index_label), index_text);
-
-      candidate_label = g_slist_nth_data (area->candidate_labels, i);
+      gf_candidate_box_set_index_label (GF_CANDIDATE_BOX (candidate_box),
+                                        index_text);
 
-      gtk_label_set_text (GTK_LABEL (candidate_label),
-                          g_slist_nth_data (candidates, i));
+      gf_candidate_box_set_candidate_label (GF_CANDIDATE_BOX (candidate_box),
+                                            g_slist_nth_data (candidates, i));
     }
 
   current_candidate = g_slist_nth_data (area->candidate_boxes,
@@ -262,43 +256,19 @@ gf_candidate_area_init (GfCandidateArea *area)
 
   for (i = 0; i < MAX_CANDIDATES_PER_PAGE; i++)
     {
-      GtkWidget *event_box,
-                *box,
-                *index_label,
-                *candidate_label;
-
-      event_box = gtk_event_box_new();
-      box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-      context = gtk_widget_get_style_context (box);
-      gtk_style_context_add_class (context, "candidate-box");
-      gtk_container_add (GTK_CONTAINER (area), event_box);
-      gtk_container_add (GTK_CONTAINER (event_box), box);
-      g_object_set_data (G_OBJECT (box), "index,", GINT_TO_POINTER(i));
-
-      index_label = gtk_label_new (NULL);
-      context = gtk_widget_get_style_context (index_label);
-      gtk_style_context_add_class (context, "candidate-index");
-
-      candidate_label = gtk_label_new (NULL);
-      context = gtk_widget_get_style_context (candidate_label);
-      gtk_style_context_add_class (context, "candidate-label");
-
-      gtk_container_add (GTK_CONTAINER (box), index_label);
-      gtk_container_add (GTK_CONTAINER (box), candidate_label);
-
-      gtk_widget_show_all (box);
-
-      area->candidate_boxes = g_slist_append (area->candidate_boxes, box);
-      area->index_labels = g_slist_append (area->index_labels,
-                                           index_label);
-      area->candidate_labels = g_slist_append (area->candidate_labels,
-                                               candidate_label);
-
-      g_signal_connect (event_box, "button-release-event",
+      GtkWidget *candidate_box;
+
+      candidate_box = gf_candidate_box_new (i);
+      gtk_container_add (GTK_CONTAINER (area), candidate_box);
+
+      area->candidate_boxes = g_slist_append (area->candidate_boxes,
+                                              candidate_box);
+
+      g_signal_connect (candidate_box, "button-release-event",
                         G_CALLBACK (button_clicked_cb), area);
-      g_signal_connect (event_box, "enter-notify-event",
+      g_signal_connect (candidate_box, "enter-notify-event",
                         G_CALLBACK (box_mouse_enter_cb), area);
-      g_signal_connect (event_box, "leave-notify-event",
+      g_signal_connect (candidate_box, "leave-notify-event",
                         G_CALLBACK (box_mouse_leave_cb), area);
     }
 


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