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



commit 8fa7f69756f72cfc188e3022c1d3db0a63432e8b
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           |   41 +++++++++++++++++++-
 .../libinput-sources/gf-candidate-popup.c          |    4 ++
 3 files changed, 48 insertions(+), 1 deletions(-)
---
diff --git a/gnome-flashback/Adwaita.css b/gnome-flashback/Adwaita.css
index 794e263..b9f1085 100644
--- a/gnome-flashback/Adwaita.css
+++ b/gnome-flashback/Adwaita.css
@@ -18,3 +18,7 @@ FlashbackLabelWindow
 {
   font-size: 40px;
 }
+
+.selected .candidate-box {
+    background: #7b7b7b;
+}
diff --git a/gnome-flashback/libinput-sources/gf-candidate-area.c 
b/gnome-flashback/libinput-sources/gf-candidate-area.c
index 7cb03d4..ae60b17 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-area.c
+++ b/gnome-flashback/libinput-sources/gf-candidate-area.c
@@ -92,6 +92,7 @@ void
 gf_candidate_area_set_orientation (GfCandidateArea *area,
                                    IBusOrientation  orientation)
 {
+  GtkStyleContext *context;
   GtkWidget *image;
 
   if (area->orientation == orientation)
@@ -104,6 +105,10 @@ gf_candidate_area_set_orientation (GfCandidateArea *area,
       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);
@@ -117,6 +122,10 @@ gf_candidate_area_set_orientation (GfCandidateArea *area,
       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);
@@ -135,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++)
     {
@@ -167,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
@@ -206,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;
 
@@ -218,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);
@@ -242,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);
 
@@ -249,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-popup.c 
b/gnome-flashback/libinput-sources/gf-candidate-popup.c
index 8f59163..251ad02 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-popup.c
+++ b/gnome-flashback/libinput-sources/gf-candidate-popup.c
@@ -315,10 +315,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_widget_set_size_request (GTK_WIDGET (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]