[gtk+] Add GtkSpinner::animation-duration style property



commit e9a240cd52270992249223485714649d7ddb44f3
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Oct 14 18:43:05 2009 +0100

    Add GtkSpinner::animation-duration style property

 demos/gtk-demo/list_store.c  |    4 +++-
 gtk/gtkcellrendererspinner.c |    5 +++--
 gtk/gtkspinner.c             |   25 ++++++++++++++++++++++---
 3 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/demos/gtk-demo/list_store.c b/demos/gtk-demo/list_store.c
index 33a7189..156ddf6 100644
--- a/demos/gtk-demo/list_store.c
+++ b/demos/gtk-demo/list_store.c
@@ -275,8 +275,10 @@ do_list_store (GtkWidget *do_widget)
   if (!GTK_WIDGET_VISIBLE (window))
     {
       gtk_widget_show_all (window);
-      if (timeout == 0)
+      if (timeout == 0) {
+        //FIXME this should use the animation-duration instead
         timeout = g_timeout_add (80, spinner_timeout, NULL);
+      }
     }
   else
     {
diff --git a/gtk/gtkcellrendererspinner.c b/gtk/gtkcellrendererspinner.c
index 4eb6220..0e2c4d9 100644
--- a/gtk/gtkcellrendererspinner.c
+++ b/gtk/gtkcellrendererspinner.c
@@ -130,9 +130,10 @@ gtk_cell_renderer_spinner_class_init (GtkCellRendererSpinnerClass *klass)
    * Pulse of the spinner. Increment this value to draw the next frame of the
    * spinner animation. Usually, you would update this value in a timeout.
    *
-   * The #GtkSpinner widget draws one full cycle of the animation per second.
+   * The #GtkSpinner widget draws one full cycle of the animation per second by default.
    * You can learn about the number of frames used by the theme
-   * by looking at the #GtkSpinner:num-steps style property
+   * by looking at the #GtkSpinner:num-steps style property and the duration
+   * of the cycle by looking at #GtkSpinner:cycle-duration.
    *
    * Since 2.20
    */
diff --git a/gtk/gtkspinner.c b/gtk/gtkspinner.c
index db9307c..061e532 100644
--- a/gtk/gtkspinner.c
+++ b/gtk/gtkspinner.c
@@ -67,6 +67,7 @@ struct _GtkSpinnerPrivate
 {
   guint current;
   guint num_steps;
+  guint cycle_duration;
   guint timeout;
 };
 
@@ -128,18 +129,35 @@ gtk_spinner_class_init (GtkSpinnerClass *klass)
    * GtkSpinner:num-steps:
    *
    * The number of steps for the spinner to complete a full loop.
-   * The animation will complete a full cycle in one second.
+   * The animation will complete a full cycle in one second by default
+   * (see the #GtkSpinner:cycle-duration style property).
    *
    * Since: 2.20
    */
   gtk_widget_class_install_style_property (widget_class,
                                            g_param_spec_uint ("num-steps",
                                                              P_("Number of steps"),
-                                                             P_("The number of steps for the spinner to complete a full loop. The animation will complete a full cycle in one second."),
+                                                             P_("The number of steps for the spinner to complete a full loop. The animation will complete a full cycle in one second by default (see #GtkSpinner::cycle-duration)."),
                                                              1,
                                                              G_MAXUINT,
                                                              12,
                                                              G_PARAM_READABLE));
+
+  /**
+   * GtkSpinner::cycle-duration:
+   *
+   * The duration in milliseconds for the spinner to complete a full cycle.
+   *
+   * Since: 2.20
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_uint ("cycle-duration",
+                                                             P_("Animation duration"),
+                                                             P_("The length of time in milliseconds for the spinner to complete a full loop"),
+                                                             500,
+                                                             G_MAXUINT,
+                                                             1000,
+                                                             G_PARAM_READABLE));
 }
 
 static void
@@ -252,6 +270,7 @@ gtk_spinner_style_set (GtkWidget *widget,
 
   gtk_widget_style_get (GTK_WIDGET (widget),
                         "num-steps", &(priv->num_steps),
+                        "cycle-duration", &(priv->cycle_duration),
                         NULL);
 
   if (priv->current > priv->num_steps)
@@ -515,7 +534,7 @@ gtk_spinner_start (GtkSpinner *spinner)
   if (priv->timeout != 0)
     return;
 
-  priv->timeout = gdk_threads_add_timeout (1000 / priv->num_steps, gtk_spinner_timeout, spinner);
+  priv->timeout = gdk_threads_add_timeout (priv->cycle_duration / priv->num_steps, gtk_spinner_timeout, spinner);
   g_object_notify (G_OBJECT (spinner), "active");
 }
 



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