diff gtk3/dw.c @ 1190:76262040ed5f

Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos() to show a rotating or otherwise indeterminate percent bar on supported platforms. Platforms which don't support it will either show no progress or potentially growing and contracting progress in the future if that doesn't look too weird. Committed from Windows so may be fixes coming for the other platforms soon.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 28 Sep 2011 08:22:48 +0000
parents 415c25f87d57
children 40500dabb112
line wrap: on
line diff
--- a/gtk3/dw.c	Tue Sep 27 22:38:25 2011 +0000
+++ b/gtk3/dw.c	Wed Sep 28 08:22:48 2011 +0000
@@ -4762,6 +4762,19 @@
 {
 }
 
+/* Internal function to update the progress bar
+ * while in an indeterminate state. 
+ */
+gboolean _dw_update_progress_bar(gpointer data)
+{
+   if(g_object_get_data(G_OBJECT(data, "_dw_alive")))
+   {
+      gtk_progress_bar_pulse(GTK_PROGRESS_BAR(data));
+      return FALSE;
+   }
+   return TRUE;
+}
+
 /*
  * Sets the percent bar position.
  * Parameters:
@@ -4773,7 +4786,24 @@
    int _locked_by_me = FALSE;
 
    DW_MUTEX_LOCK;
-   gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(handle), (gfloat)position/100);
+   if(position == DW_PERCENT_INDETERMINATE)
+   {
+      /* Check if we are indeterminate already */
+      if(!g_object_get_data(G_OBJECT(handle), "_dw_alive"))
+      {
+         /* If not become indeterminate... and start a timer to continue */
+         gtk_progress_bar_pulse(GTK_PROGRESS_BAR(handle));
+         g_object_set_data(G_OBJECT(handle), "_dw_alive", GINT_TO_POINTER(1));
+         g_timeout_add(100, (GSourceFunc)_dw_update_progress_bar, (gpointer)handle);
+      }
+   }
+   else
+   {
+      /* Cancel the existing timer if one is there */
+      g_object_set_data(G_OBJECT(handle), "_dw_alive", NULL);
+      /* Set the position like normal */
+      gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(handle), (gfloat)position/100);
+   }
    DW_MUTEX_UNLOCK;
 }