[california/wip/734698-agenda] Fixes prelight and border issues



commit b148236eea3ec0a00bf18b57a759db4bea5db702
Author: Jim Nelson <jim yorba org>
Date:   Tue Dec 2 20:30:45 2014 -0800

    Fixes prelight and border issues
    
    So, GtkListBox can stay.

 src/rc/view-agenda-date-row.ui         |    1 +
 src/toolkit/toolkit-listbox-model.vala |   14 ++++++++++++++
 src/toolkit/toolkit.vala               |   15 +++++++++++++++
 src/view/agenda/agenda-controller.vala |    5 +++++
 src/view/agenda/agenda-date-row.vala   |   11 ++++++++---
 5 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/src/rc/view-agenda-date-row.ui b/src/rc/view-agenda-date-row.ui
index 0021891..6dcfa8c 100644
--- a/src/rc/view-agenda-date-row.ui
+++ b/src/rc/view-agenda-date-row.ui
@@ -10,6 +10,7 @@
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="margin_right">6</property>
+        <property name="margin_top">3</property>
         <property name="xalign">1</property>
         <property name="yalign">0</property>
         <property name="label">(date)</property>
diff --git a/src/toolkit/toolkit-listbox-model.vala b/src/toolkit/toolkit-listbox-model.vala
index 92ef654..4fb36ae 100644
--- a/src/toolkit/toolkit-listbox-model.vala
+++ b/src/toolkit/toolkit-listbox-model.vala
@@ -58,6 +58,11 @@ public class ListBoxModel<G> : BaseObject {
     public signal void added(G item);
     
     /**
+     * Fired when a GtkListBoxRow is added to the { link listbox}.
+     */
+    public signal void row_added(Gtk.ListBoxRow row, G item);
+    
+    /**
      * Fired when an item is removed from the { link ListBoxModel}.
      *
      * @see remove
@@ -65,6 +70,11 @@ public class ListBoxModel<G> : BaseObject {
     public signal void removed(G item);
     
     /**
+     * Fired when a GtkListBoxRow is removed from the { link listbox}.
+     */
+    public signal void row_removed(Gtk.ListBoxRow row, G item);
+    
+    /**
      * Fired when the { link listbox} activates an item.
      *
      * Gtk.ListBox can activate an item with a double- or single-click, depending on configuration.
@@ -107,6 +117,7 @@ public class ListBoxModel<G> : BaseObject {
      * Returns true if the model (and therefore the listbox) were altered due to the addition.
      *
      * @see added
+     * @see row_added
      */
     public bool add(G item) {
         if (items.has_key(item))
@@ -131,6 +142,7 @@ public class ListBoxModel<G> : BaseObject {
         size = size + 1;
         
         added(item);
+        row_added(row, item);
         
         return true;
     }
@@ -158,6 +170,7 @@ public class ListBoxModel<G> : BaseObject {
      * Returns true if the model (and therefore the listbox) were altered due to the removal.
      *
      * @see removed
+     * @see row_removed
      */
     public bool remove(G item) {
         return internal_remove(item, true);
@@ -192,6 +205,7 @@ public class ListBoxModel<G> : BaseObject {
         size = (size - 1).clamp(0, int.MAX);
         
         removed(item);
+        row_removed(row, item);
         
         return true;
     }
diff --git a/src/toolkit/toolkit.vala b/src/toolkit/toolkit.vala
index f407356..1ea43fa 100644
--- a/src/toolkit/toolkit.vala
+++ b/src/toolkit/toolkit.vala
@@ -136,4 +136,19 @@ public void destroy_later(Gtk.Widget widget) {
     }, Priority.LOW);
 }
 
+/**
+ * Prevent prelight when a mouse hovers over the widget.
+ *
+ * This operates by preventing the Gtk.StateFlag.PRELIGHT state from being entered.  This may have
+ * negative effects for some widgets and should be used with caution.
+ */
+public void prevent_prelight(Gtk.Widget widget) {
+    widget.state_flags_changed.connect(on_state_flags_changed);
+}
+
+private void on_state_flags_changed(Gtk.Widget widget, Gtk.StateFlags old_state_flags) {
+    if ((widget.get_state_flags() & Gtk.StateFlags.PRELIGHT) != 0)
+        widget.unset_state_flags(Gtk.StateFlags.PRELIGHT);
+}
+
 }
diff --git a/src/view/agenda/agenda-controller.vala b/src/view/agenda/agenda-controller.vala
index e382cd3..2e80b48 100644
--- a/src/view/agenda/agenda-controller.vala
+++ b/src/view/agenda/agenda-controller.vala
@@ -69,6 +69,11 @@ public class Controller : BaseObject, View.Controllable {
             Calendar.System.today.adjust_by(1, Calendar.DateUnit.MONTH));
         listbox_model = new Toolkit.ListBoxModel<Calendar.Date>(listbox, model_presentation);
         
+        // Don't prelight the DateRows, as they can't be selected or activated
+        listbox_model.row_added.connect((row, item) => {
+            Toolkit.prevent_prelight(row);
+        });
+        
         listbox.selection_mode = Gtk.SelectionMode.NONE;
         listbox.activate_on_single_click = false;
         
diff --git a/src/view/agenda/agenda-date-row.vala b/src/view/agenda/agenda-date-row.vala
index c006888..2b3acdb 100644
--- a/src/view/agenda/agenda-date-row.vala
+++ b/src/view/agenda/agenda-date-row.vala
@@ -21,12 +21,17 @@ private class DateRow : Gtk.Box {
     [GtkChild]
     private Gtk.ListBox event_listbox;
     
-    private Toolkit.ListBoxModel<Component.Event> model;
+    private Toolkit.ListBoxModel<Component.Event> listbox_model;
     
     public DateRow(Calendar.Date date) {
         this.date = date;
         
-        model = new Toolkit.ListBoxModel<Component.Event>(event_listbox, model_presentation);
+        listbox_model = new Toolkit.ListBoxModel<Component.Event>(event_listbox, model_presentation);
+        
+        // Don't prelight the DateRows, as they can't be selected or activated
+        listbox_model.row_added.connect((row, item) => {
+            Toolkit.prevent_prelight(row);
+        });
         
         date_label.label = date.to_pretty_string(DATE_PRETTY_FLAGS);
         
@@ -43,7 +48,7 @@ private class DateRow : Gtk.Box {
     }
     
     public void add_event(Component.Event event) {
-        model.add(event);
+        listbox_model.add(event);
     }
     
     private Gtk.Widget model_presentation(Component.Event event) {


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