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



commit 7c01c73259307e47de1f979828d40b7f6e5d0d73
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           |   33 ++++++++++++++++++++
 .../libinput-sources/gf-candidate-popup.c          |    4 ++
 3 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/gnome-flashback/Adwaita.css b/gnome-flashback/Adwaita.css
index 794e263..253b543 100644
--- a/gnome-flashback/Adwaita.css
+++ b/gnome-flashback/Adwaita.css
@@ -18,3 +18,7 @@ FlashbackLabelWindow
 {
   font-size: 40px;
 }
+
+GfCandidateBox.selected {
+    background: #7b7b7b;
+}
diff --git a/gnome-flashback/libinput-sources/gf-candidate-area.c 
b/gnome-flashback/libinput-sources/gf-candidate-area.c
index 6cb2da3..a5bdb9b 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-area.c
+++ b/gnome-flashback/libinput-sources/gf-candidate-area.c
@@ -91,6 +91,7 @@ void
 gf_candidate_area_set_orientation (GfCandidateArea *area,
                                    IBusOrientation  orientation)
 {
+  GtkStyleContext *context;
   GtkWidget *image;
 
   if (area->orientation == orientation)
@@ -103,6 +104,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);
@@ -116,6 +121,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);
@@ -134,6 +143,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++)
     {
@@ -161,7 +172,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
@@ -218,6 +242,7 @@ gf_candidate_area_class_init (GfCandidateAreaClass *area_class)
 static void
 gf_candidate_area_init (GfCandidateArea *area)
 {
+  GtkStyleContext *context;
   GtkWidget *prev_image, *next_image;
   guint i;
 
@@ -236,6 +261,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);
 
@@ -243,11 +270,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]