comparison 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
comparison
equal deleted inserted replaced
1189:c5419ef79a77 1190:76262040ed5f
5433 } 5433 }
5434 DW_MUTEX_UNLOCK; 5434 DW_MUTEX_UNLOCK;
5435 #endif 5435 #endif
5436 } 5436 }
5437 5437
5438 /* Internal function to update the progress bar
5439 * while in an indeterminate state.
5440 */
5441 gboolean _dw_update_progress_bar(gpointer data)
5442 {
5443 if(g_object_get_data(G_OBJECT(data, "_dw_alive")))
5444 {
5445 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(data));
5446 return FALSE;
5447 }
5448 return TRUE;
5449 }
5450
5438 /* 5451 /*
5439 * Sets the percent bar position. 5452 * Sets the percent bar position.
5440 * Parameters: 5453 * Parameters:
5441 * handle: Handle to the percent bar to be set. 5454 * handle: Handle to the percent bar to be set.
5442 * position: Position of the percent bar withing the range. 5455 * position: Position of the percent bar withing the range.
5444 void dw_percent_set_pos(HWND handle, unsigned int position) 5457 void dw_percent_set_pos(HWND handle, unsigned int position)
5445 { 5458 {
5446 int _locked_by_me = FALSE; 5459 int _locked_by_me = FALSE;
5447 5460
5448 DW_MUTEX_LOCK; 5461 DW_MUTEX_LOCK;
5449 gtk_progress_bar_update(GTK_PROGRESS_BAR(handle), (gfloat)position/100); 5462 if(position == DW_PERCENT_INDETERMINATE)
5463 {
5464 /* Check if we are indeterminate already */
5465 if(!gtk_object_get_data(GTK_OBJECT(handle), "_dw_alive"))
5466 {
5467 /* If not become indeterminate... and start a timer to continue */
5468 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(handle));
5469 gtk_object_set_data(GTK_OBJECT(handle), "_dw_alive",
5470 GINT_TO_POINTER(gtk_timeout_add(100, (GtkFunction)_dw_update_progress_bar, (gpointer)handle)));
5471 }
5472 }
5473 else
5474 {
5475 int tag = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(handle), "_dw_alive"));
5476
5477 if(tag)
5478 {
5479 /* Cancel the existing timer if one is there */
5480 gtk_timeout_remove(tag);
5481 gtk_object_set_data(GTK_OBJECT(handle), "_dw_alive", NULL);
5482 }
5483 /* Set the position like normal */
5484 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(handle), (gfloat)position/100);
5485 }
5450 DW_MUTEX_UNLOCK; 5486 DW_MUTEX_UNLOCK;
5451 } 5487 }
5452 5488
5453 /* 5489 /*
5454 * Returns the position of the slider. 5490 * Returns the position of the slider.