[gnome-flashback/wip/segeiger/gnome-3-18-inputmethods: 2/3] input-sources: add style classes and highlight selected candidate



commit 824c359a787f6adefc576acbb4d4b7fbf38409c6
Author: Sebastian Geiger <sbastig gmx net>
Date:   Sun Jan 17 11:54:24 2016 +0100

    input-sources: add style classes and highlight selected candidate

 gnome-flashback/Adwaita.css                        |    4 +
 .../libinput-sources/gf-candidate-area.c           |   80 +++++++++++++++++++-
 .../libinput-sources/gf-candidate-area.h           |    3 +
 .../libinput-sources/gf-candidate-popup.c          |    4 +
 4 files changed, 90 insertions(+), 1 deletions(-)
---
diff --git a/gnome-flashback/Adwaita.css b/gnome-flashback/Adwaita.css
index 794e263..b03f1ae 100644
--- a/gnome-flashback/Adwaita.css
+++ b/gnome-flashback/Adwaita.css
@@ -18,3 +18,7 @@ FlashbackLabelWindow
 {
   font-size: 40px;
 }
+
+.candidate-box.selected {
+    background: #7b7b7b;
+}
diff --git a/gnome-flashback/libinput-sources/gf-candidate-area.c 
b/gnome-flashback/libinput-sources/gf-candidate-area.c
index e485898..ae60b17 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-area.c
+++ b/gnome-flashback/libinput-sources/gf-candidate-area.c
@@ -89,6 +89,54 @@ next_button_clicked_cb (GtkButton       *button,
 }
 
 void
+gf_candidate_area_set_orientation (GfCandidateArea *area,
+                                   IBusOrientation  orientation)
+{
+  GtkStyleContext *context;
+  GtkWidget *image;
+
+  if (area->orientation == orientation)
+    return;
+
+  area->orientation = orientation;
+
+  if (area->orientation == IBUS_ORIENTATION_HORIZONTAL)
+    {
+      gtk_orientable_set_orientation (GTK_ORIENTABLE (area->button_box),
+                                      GTK_ORIENTATION_HORIZONTAL);
+
+      context = gtk_widget_get_style_context (GTK_WIDGET (area));
+      gtk_style_context_add_class(context, "horizontal");
+      gtk_style_context_remove_class(context, "vertical");
+
+      image = gtk_button_get_image(GTK_BUTTON (area->prev_button));
+      gtk_image_set_from_icon_name(GTK_IMAGE (image), "go-previous-symbolic",
+                                   GTK_ICON_SIZE_BUTTON);
+
+      image = gtk_button_get_image(GTK_BUTTON (area->next_button));
+      gtk_image_set_from_icon_name(GTK_IMAGE (image), "go-next-symbolic",
+                                   GTK_ICON_SIZE_BUTTON);
+    }
+  else
+    {
+      gtk_orientable_set_orientation (GTK_ORIENTABLE (area->button_box),
+                                      GTK_ORIENTATION_VERTICAL);
+
+      context = gtk_widget_get_style_context (GTK_WIDGET (area));
+      gtk_style_context_add_class (context, "vertical");
+      gtk_style_context_remove_class(context, "horizontal");
+
+      image = gtk_button_get_image(GTK_BUTTON (area->prev_button));
+      gtk_image_set_from_icon_name(GTK_IMAGE (image), "go-up-symbolic",
+                                   GTK_ICON_SIZE_BUTTON);
+
+      image = gtk_button_get_image(GTK_BUTTON (area->next_button));
+      gtk_image_set_from_icon_name(GTK_IMAGE (image), "go-down-symbolic",
+                                   GTK_ICON_SIZE_BUTTON);
+    }
+}
+
+void
 gf_candidate_area_set_candidates (GfCandidateArea *area,
                                   GSList          *indexes,
                                   GSList          *candidates,
@@ -96,6 +144,8 @@ gf_candidate_area_set_candidates (GfCandidateArea *area,
                                   gboolean         cursor_visible)
 {
   guint i;
+  GtkWidget *current_candidate;
+  GtkStyleContext *context;
 
   for (i = 0; i < MAX_CANDIDATES_PER_PAGE; i++)
     {
@@ -128,7 +178,20 @@ gf_candidate_area_set_candidates (GfCandidateArea *area,
                           g_slist_nth_data (candidates, i));
     }
 
+  current_candidate = g_slist_nth_data (area->candidate_boxes,
+                                        area->cursor_position);
+  context = gtk_widget_get_style_context (current_candidate);
+  gtk_style_context_remove_class (context, "selected");
+
   area->cursor_position = cursor_position;
+
+  if (cursor_visible)
+    {
+      current_candidate = g_slist_nth_data (area->candidate_boxes,
+                                            cursor_position);
+      context = gtk_widget_get_style_context (current_candidate);
+      gtk_style_context_add_class (context, "selected");
+    }
 }
 
 void
@@ -167,6 +230,7 @@ gf_candidate_area_class_init (GfCandidateAreaClass *area_class)
 static void
 gf_candidate_area_init (GfCandidateArea *area)
 {
+  GtkStyleContext *context;
   GtkWidget *prev_image, *next_image;
   int i;
 
@@ -179,13 +243,19 @@ gf_candidate_area_init (GfCandidateArea *area)
 
       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);
@@ -203,6 +273,8 @@ gf_candidate_area_init (GfCandidateArea *area)
     }
 
   area->button_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  context = gtk_widget_get_style_context (area->button_box);
+  gtk_style_context_add_class (context, "candidate-page-button-box");
 
   gtk_container_add (GTK_CONTAINER (area), area->button_box);
 
@@ -210,11 +282,17 @@ gf_candidate_area_init (GfCandidateArea *area)
                                              GTK_ICON_SIZE_BUTTON);
   area->prev_button = gtk_button_new_with_label ("Prev");
   gtk_button_set_image (GTK_BUTTON (area->prev_button), prev_image);
+  context = gtk_widget_get_style_context (area->prev_button);
+  gtk_style_context_add_class (context, "candidate-page-button");
+  gtk_style_context_add_class (context, "candidate-page-button-previous");
 
   next_image = gtk_image_new_from_icon_name ("go-next-symbolic",
                                              GTK_ICON_SIZE_BUTTON);
   area->next_button = gtk_button_new_with_label ("Next");
   gtk_button_set_image (GTK_BUTTON (area->next_button), next_image);
+  context = gtk_widget_get_style_context (area->next_button);
+  gtk_style_context_add_class (context, "candidate-page-button");
+  gtk_style_context_add_class (context, "candidate-page-button-next");
 
   gtk_container_add (GTK_CONTAINER (area->button_box), area->prev_button);
   gtk_container_add (GTK_CONTAINER (area->button_box), area->next_button);
diff --git a/gnome-flashback/libinput-sources/gf-candidate-area.h 
b/gnome-flashback/libinput-sources/gf-candidate-area.h
index 9137dce..9a41e53 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-area.h
+++ b/gnome-flashback/libinput-sources/gf-candidate-area.h
@@ -30,6 +30,9 @@ G_DECLARE_FINAL_TYPE (GfCandidateArea, gf_candidate_area,
 
 GtkWidget* gf_candidate_area_new             (void);
 
+void       gf_candidate_area_set_orientation (GfCandidateArea *area,
+                                              IBusOrientation  orientation);
+
 void       gf_candidate_area_set_candidates  (GfCandidateArea *area,
                                               GSList          *indexes,
                                               GSList          *candidates,
diff --git a/gnome-flashback/libinput-sources/gf-candidate-popup.c 
b/gnome-flashback/libinput-sources/gf-candidate-popup.c
index 0950655..58fc373 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-popup.c
+++ b/gnome-flashback/libinput-sources/gf-candidate-popup.c
@@ -319,10 +319,14 @@ gf_candidate_popup_class_init (GfCandidatePopupClass *popup_class)
 static void
 gf_candidate_popup_init (GfCandidatePopup *popup)
 {
+  GtkStyleContext *context;
+
   popup->candidate_area = gf_candidate_area_new();
 
   popup->window = gtk_window_new (GTK_WINDOW_POPUP);
   gtk_window_set_default_size (GTK_WINDOW (popup->window), 1, 1);
+  context = gtk_widget_get_style_context (popup->window);
+  gtk_style_context_add_class (context, "candidate-popup");
 
   popup->box_layout = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_container_add (GTK_CONTAINER (popup->window), popup->box_layout);


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