[gnome-shell] Add an active property to ShellButtonBox



commit 45c600cd258c8a2e491ea207bca07242819c9fd7
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sat Aug 29 12:00:20 2009 -0400

    Add an active property to ShellButtonBox
    
    Add an 'active' property to ShellButtonBox. This allows ShellButtonBox
    to be used as a "toggle button". It's up the application to connect
    it to the ::activate signal; there's no default handling of this.
    
    (It's seldom that the only time you want to toggle a toggle button
    through the user interface, so you need some connection to the backend
    data store in any case. Removing the default handling all-together
    prevents weird interactions.)
    
    When we have built-in styling for ShellButtonBox the 'active' state
    would be one of the elements that would be affect the styling.
    
    http://bugzilla.gnome.org/show_bug.cgi?id=593502

 src/shell-button-box.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-button-box.c b/src/shell-button-box.c
index 16c4659..25808a4 100644
--- a/src/shell-button-box.c
+++ b/src/shell-button-box.c
@@ -14,6 +14,7 @@
 G_DEFINE_TYPE(ShellButtonBox, shell_button_box, BIG_TYPE_BOX);
 
 struct _ShellButtonBoxPrivate {
+  gboolean active;
   gboolean held;
   gboolean hover;
   gboolean pressed;
@@ -29,6 +30,7 @@ enum
 enum {
   PROP_0,
 
+  PROP_ACTIVE,
   PROP_HOVER,
   PROP_PRESSED,
 };
@@ -36,6 +38,16 @@ enum {
 static guint shell_button_box_signals [LAST_SIGNAL] = { 0 };
 
 static void
+set_active (ShellButtonBox  *box,
+            gboolean         active)
+{
+  if (box->priv->active == active)
+    return;
+  box->priv->active = active;
+  g_object_notify (G_OBJECT (box), "active");
+}
+
+static void
 set_hover (ShellButtonBox  *box,
            gboolean         hover)
 {
@@ -150,8 +162,13 @@ shell_button_box_set_property(GObject         *object,
                               const GValue    *value,
                               GParamSpec      *pspec)
 {
+  ShellButtonBox *box = SHELL_BUTTON_BOX (object);
+
   switch (prop_id)
     {
+    case PROP_ACTIVE:
+      set_active (box, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -168,6 +185,9 @@ shell_button_box_get_property(GObject         *object,
 
   switch (prop_id)
     {
+    case PROP_ACTIVE:
+      g_value_set_boolean (value, box->priv->active);
+      break;
     case PROP_PRESSED:
       g_value_set_boolean (value, box->priv->pressed);
       break;
@@ -205,6 +225,21 @@ shell_button_box_class_init (ShellButtonBoxClass *klass)
                   G_TYPE_NONE, 0);
 
   /**
+   * ShellButtonBox:active
+   *
+   * The property allows the button to be used as a "toggle button"; it's up to the
+   * application to update the active property in response to the activate signal;
+   * it doesn't happen automatically.
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_ACTIVE,
+                                   g_param_spec_boolean ("active",
+                                                         "Active",
+                                                         "Whether the button persistently active",
+                                                         FALSE,
+                                                         G_PARAM_READWRITE));
+
+  /**
    * ShellButtonBox:hover
    *
    * This property tracks whether the mouse is over the button; note this



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