diff gtk/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 4c20df806370
children f0df014e44d8
line wrap: on
line diff
--- a/gtk/dw.c	Tue Sep 27 22:38:25 2011 +0000
+++ b/gtk/dw.c	Wed Sep 28 08:22:48 2011 +0000
@@ -5435,6 +5435,19 @@
 #endif
 }
 
+/* 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:
@@ -5446,7 +5459,30 @@
    int _locked_by_me = FALSE;
 
    DW_MUTEX_LOCK;
-   gtk_progress_bar_update(GTK_PROGRESS_BAR(handle), (gfloat)position/100);
+   if(position == DW_PERCENT_INDETERMINATE)
+   {
+      /* Check if we are indeterminate already */
+      if(!gtk_object_get_data(GTK_OBJECT(handle), "_dw_alive"))
+      {
+         /* If not become indeterminate... and start a timer to continue */
+         gtk_progress_bar_pulse(GTK_PROGRESS_BAR(handle));
+         gtk_object_set_data(GTK_OBJECT(handle), "_dw_alive", 
+             GINT_TO_POINTER(gtk_timeout_add(100, (GtkFunction)_dw_update_progress_bar, (gpointer)handle)));
+      }
+   }
+   else
+   {
+      int tag = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(handle), "_dw_alive"));
+  
+      if(tag)
+      {
+         /* Cancel the existing timer if one is there */
+         gtk_timeout_remove(tag); 
+         gtk_object_set_data(GTK_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;
 }