[gnome-calendar/wip/gbsneto/date-chooser: 7/7] date-chooser: support hovering days



commit faf85a7fb011fb9c31930ec6bae543bc84929e86
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Jul 23 17:38:33 2016 -0300

    date-chooser: support hovering days
    
    Another fixup in order to make the current date chooser
    more streamlined with GNOME Shell's calendar.

 data/theme/gtk-styles.css   |   10 +++++++++-
 src/gcal-date-chooser-day.c |   36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/data/theme/gtk-styles.css b/data/theme/gtk-styles.css
index f2a8d44..1d12f6b 100644
--- a/data/theme/gtk-styles.css
+++ b/data/theme/gtk-styles.css
@@ -316,8 +316,16 @@ datechooser day.other-month {
     color: @theme_insensitive_fg_color;
 }
 
+datechooser day:hover,
+datechooser day:selected {
+    border-radius: 50%;
+}
+
+datechooser day:hover {
+    background-color: alpha(@theme_fg_color, 0.1);
+}
+
 datechooser day:selected {
     color: @theme_selected_fg_color;
     background-color: @theme_selected_bg_color;
-    border-radius: 50%;
 }
diff --git a/src/gcal-date-chooser-day.c b/src/gcal-date-chooser-day.c
index 018bec7..38595d0 100644
--- a/src/gcal-date-chooser-day.c
+++ b/src/gcal-date-chooser-day.c
@@ -167,7 +167,9 @@ gcal_date_chooser_day_realize (GtkWidget *widget)
   attributes.event_mask = gtk_widget_get_events (widget);
   attributes.event_mask |= GDK_BUTTON_PRESS_MASK
                            | GDK_BUTTON_RELEASE_MASK
-                           | GDK_TOUCH_MASK;
+                           | GDK_TOUCH_MASK
+                           | GDK_ENTER_NOTIFY_MASK
+                           | GDK_LEAVE_NOTIFY_MASK;
 
   attributes_mask = GDK_WA_X | GDK_WA_Y;
 
@@ -301,6 +303,36 @@ gcal_date_chooser_day_get_preferred_height (GtkWidget *widget,
     *natural = MAX (nat, min_height);
 }
 
+static gboolean
+gcal_date_chooser_day_enter_notify_event (GtkWidget        *widget,
+                                          GdkEventCrossing *event)
+{
+  GtkStyleContext *context;
+  GtkStateFlags state;
+
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_style_context_get_state (context);
+
+  gtk_style_context_set_state (context, state | GTK_STATE_FLAG_PRELIGHT);
+
+  return GDK_EVENT_PROPAGATE;
+}
+
+static gboolean
+gcal_date_chooser_day_leave_notify_event (GtkWidget        *widget,
+                                          GdkEventCrossing *event)
+{
+  GtkStyleContext *context;
+  GtkStateFlags state;
+
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_style_context_get_state (context);
+
+  gtk_style_context_set_state (context, state & ~GTK_STATE_FLAG_PRELIGHT);
+
+  return GDK_EVENT_PROPAGATE;
+}
+
 static void
 gcal_date_chooser_day_class_init (GcalDateChooserDayClass *class)
 {
@@ -319,6 +351,8 @@ gcal_date_chooser_day_class_init (GcalDateChooserDayClass *class)
   widget_class->drag_data_get = gcal_date_chooser_day_drag_data_get;
   widget_class->get_preferred_width = gcal_date_chooser_day_get_preferred_width;
   widget_class->get_preferred_height = gcal_date_chooser_day_get_preferred_height;
+  widget_class->enter_notify_event = gcal_date_chooser_day_enter_notify_event;
+  widget_class->leave_notify_event = gcal_date_chooser_day_leave_notify_event;
 
   signals[SELECTED] = g_signal_new ("selected",
                                     GCAL_TYPE_DATE_CHOOSER_DAY,


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