changeset 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 c5419ef79a77
children 40500dabb112
files dw.h dwtest.c gtk/dw.c gtk3/dw.c mac/dw.m os2/dw.c win/dw.c
diffstat 7 files changed, 132 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Tue Sep 27 22:38:25 2011 +0000
+++ b/dw.h	Wed Sep 28 08:22:48 2011 +0000
@@ -1390,6 +1390,8 @@
 #define DW_MENU_SEPARATOR ""
 #define DW_NOMENU 0
 
+#define DW_PERCENT_INDETERMINATE ((unsigned int)-1)
+
 /* Return value error codes */
 #define DW_ERROR_NONE      0
 #define DW_ERROR_GENERAL   1
--- a/dwtest.c	Tue Sep 27 22:38:25 2011 +0000
+++ b/dwtest.c	Wed Sep 28 08:22:48 2011 +0000
@@ -72,6 +72,7 @@
     combobox2,
     spinbutton,
     slider,
+	percent,
     notebookbox,
     notebookbox1,
     notebookbox2,
@@ -570,19 +571,9 @@
     return 0;
 }
 
-int DWSIGNAL redraw_button_box_callback(HWND window, void *data)
+int DWSIGNAL percent_button_box_callback(HWND window, void *data)
 {
-#if 0
-
-    long x, y, width, height;
-    dw_window_get_pos_size(filetoolbarbox , &x, &y, &width, &height);
-    dw_window_destroy( filetoolbarbox );
-    create_button(1);
-    dw_window_set_pos_size(filetoolbarbox, x, y, width, height);
-#else
-    dw_window_enable( window);
-    dw_window_destroy( noncheckable_menuitem );
-#endif
+    dw_percent_set_pos(percent, DW_PERCENT_INDETERMINATE);
     return 0;
 }
 
@@ -629,7 +620,7 @@
 /* Callback to handle user selection of the slider position */
 void DWSIGNAL slider_valuechanged_callback(HWND hwnd, int value, void *data)
 {
-    dw_messagebox("DWTest", DW_MB_OK, "New value from slider: %d\n", value);
+    dw_percent_set_pos(percent, value * 10);
 }
 
 /* Handle size change of the main render window */
@@ -1193,9 +1184,12 @@
     dw_spinbutton_set_pos( spinbutton, 30 );
     dw_signal_connect( spinbutton, DW_SIGNAL_VALUE_CHANGED, DW_SIGNAL_FUNC(spinbutton_valuechanged_callback), NULL );
     /* make a slider */
-    slider = dw_slider_new( FALSE, 10, 0 ); /* no point in specifying text */
+    slider = dw_slider_new( FALSE, 11, 0 ); /* no point in specifying text */
     dw_box_pack_start( combox, slider, 200, 20, TRUE, FALSE, 0);
     dw_signal_connect( slider, DW_SIGNAL_VALUE_CHANGED, DW_SIGNAL_FUNC(slider_valuechanged_callback), NULL );
+    /* make a percent */
+    percent = dw_percent_new( 0 );
+    dw_box_pack_start( combox, percent, 200, 20, TRUE, FALSE, 0);
 }
 
 void create_button( int redraw)
@@ -1216,7 +1210,7 @@
 
     abutton1 = dw_bitmapbutton_new_from_data( "A button from data", 0, folder_ico, 1718 );
     dw_box_pack_start( filetoolbarbox, abutton1, 25, 25, FALSE, FALSE, 0);
-    dw_signal_connect( abutton1, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(redraw_button_box_callback), NULL );
+    dw_signal_connect( abutton1, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(percent_button_box_callback), NULL );
     dw_box_pack_start( filetoolbarbox, 0, 25, 5, FALSE, FALSE, 0 );
     if ( redraw )
     {
--- 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;
 }
 
--- 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;
 }
 
--- a/mac/dw.m	Tue Sep 27 22:38:25 2011 +0000
+++ b/mac/dw.m	Wed Sep 28 08:22:48 2011 +0000
@@ -3740,7 +3740,17 @@
 void API dw_percent_set_pos(HWND handle, unsigned int position)
 {
     DWPercent *percent = handle;
-    [percent setDoubleValue:(double)position];
+
+    /* Handle indeterminate */
+    if(position == DW_PERCENT_INDETERMINATE)
+        [percent setIndeterminate:YES];
+    else
+    {
+        /* Handle normal */
+        if([percent isIndeterminate])
+            [percent setIndeterminate:NO];
+        [percent setDoubleValue:(double)position];
+    }
 }
 
 /*
--- a/os2/dw.c	Tue Sep 27 22:38:25 2011 +0000
+++ b/os2/dw.c	Wed Sep 28 08:22:48 2011 +0000
@@ -6725,10 +6725,18 @@
 void API dw_percent_set_pos(HWND handle, unsigned int position)
 {
    int range = _dw_percent_get_range(handle);
-   int mypos = ((float)position/100)*range;
-
-   if(range)
-   {
+
+   /* OS/2 doesn't really support indeterminate... */
+   if(position == DW_PERCENT_INDETERMINATE)
+   {
+      /* So set the position to 0 */
+      WinSendMsg(handle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_RANGEVALUE), (MPARAM)0);
+   }
+   else if(range)
+   {
+      /* Otherwise set the position as usual */
+      int mypos = ((float)position/100)*range;
+  
       _dw_int_set(handle, mypos);
       WinSendMsg(handle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_RANGEVALUE), (MPARAM)mypos);
    }
--- a/win/dw.c	Tue Sep 27 22:38:25 2011 +0000
+++ b/win/dw.c	Wed Sep 28 08:22:48 2011 +0000
@@ -7061,7 +7061,36 @@
  */
 void API dw_percent_set_pos(HWND handle, unsigned int position)
 {
-   SendMessage(handle, PBM_SETPOS, (WPARAM)position, 0);
+   if(position == DW_PERCENT_INDETERMINATE)
+   {
+      /* If our common controls supports it... */
+      if((dwComctlVer >= PACKVERSION(6,0)))
+      {
+          /* Enable the style on the control */
+          SetWindowLong(handle, GWL_STYLE, GetWindowLong(handle, GWL_STYLE) | PBS_MARQUEE);
+          /* Start the bar going */
+          SendMessage(handle, PBM_SETMARQUEE, 1, 100);
+      }
+      else
+         SendMessage(handle, PBM_SETPOS, 0, 0);
+   }
+   else
+   {
+      if((dwComctlVer >= PACKVERSION(6,0)))
+      {
+          unsigned long style = GetWindowLong(handle, GWL_STYLE);
+  
+          if(style & PBS_MARQUEE)
+          {
+             /* Stop the bar */
+             SendMessage(handle, PBM_SETMARQUEE, 0, 0);
+             /* Disable the style on the control */
+             SetWindowLong(handle, GWL_STYLE, style & ~PBS_MARQUEE);
+          }
+      }
+      /* Otherwise just set the position */
+      SendMessage(handle, PBM_SETPOS, (WPARAM)position, 0);
+   }
 }
 
 /*