Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] ProgressBar update

Attached is a patch that will remove the calls to deprecated
methods for the ProgressBar widget in the gtk2 bindings.  Please
let me know if there are any issues with this code.

Thanks
-Jeff




Index: Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java
===================================================================
RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java,v
retrieving revision 1.8
diff -u -r1.8 ProgressBar.java
--- Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java	18 Jun 2002 13:12:15 -0000	1.8
+++ Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java	9 Jul 2002 00:08:22 -0000
@@ -7,10 +7,8 @@
  * http://www.eclipse.org/legal/cpl-v10.html
  */
 
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.internal.gtk.OS;
 
 /**
  * Instances of the receiver represent is an unselectable
@@ -70,32 +68,34 @@
 	return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
 }
 
-void configureBar (int selection, int minimum, int maximum) {
-	OS.gtk_progress_configure (handle, selection, minimum, maximum);
-	/*
-	* Feature in GTK.  The progress bar does
-	* not redraw right away when a value is
-	* changed.  This is not strictly incorrect
-	* but unexpected.  The fix is to force all
-	* outstanding redraws to be delivered.
-	*/
-	OS.gdk_flush ();
-	int window = paintWindow ();
-	OS.gdk_window_process_updates (window, false);
+void configureBar (int selection, int minimum, int maximum, boolean forceRefresh) {
+	OS.gtk_progress_bar_set_fraction(handle, ((100.0 / (maximum - minimum)) * selection) / 100);
+	if (forceRefresh) {
+		/*
+		* Feature in GTK.  The progress bar does
+		* not redraw right away when a value is
+		* changed.  This is not strictly incorrect
+		* but unexpected.  The fix is to force all
+		* outstanding redraws to be delivered.
+		*/
+		OS.gdk_flush ();
+		int window = paintWindow ();
+		OS.gdk_window_process_updates (window, false);
+	}
 }
 
 void createHandle (int index) {
 	state |= HANDLE;
 	handle = OS.gtk_progress_bar_new ();
 	if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-	OS.gtk_progress_configure (handle, value, min, max);
+	configureBar(value, min, max, false);
 	int parentHandle = parent.parentingHandle ();
 	OS.gtk_container_add (parentHandle, handle);
 	OS.gtk_widget_show (handle);
 	int orientation = (style & SWT.VERTICAL) != 0 ? OS.GTK_PROGRESS_TOP_TO_BOTTOM : OS.GTK_PROGRESS_LEFT_TO_RIGHT;
 	OS.gtk_progress_bar_set_orientation (handle, orientation);		
 	int style = (this.style & SWT.SMOOTH) == 0 ? OS.GTK_PROGRESS_DISCRETE : OS.GTK_PROGRESS_CONTINUOUS;
-	OS.gtk_progress_bar_set_bar_style (handle, style);
+	OS.GTK_PROGRESS_BAR_SET_BAR_STYLE(handle, style);
 }
 
 /**
@@ -160,7 +160,7 @@
 	if (maximum < 0) return;
 	max = maximum;
 	if (value > maximum) value = maximum;
-	configureBar (value, min, max);
+	configureBar (value, min, max, true);
 }
 
 /**
@@ -180,7 +180,7 @@
 	if (minimum < 0) return;
 	if (value < minimum) value = minimum;
 	min = minimum;
-	configureBar (value, min, max);
+	configureBar (value, min, max, true);
 }
 
 /**
@@ -199,8 +199,6 @@
 	checkWidget ();
 	if (x < 0) return;
 	value = x;
-	configureBar (value, min, max);
+	configureBar (value, min, max, true);
 }
-
-
 }
Index: Eclipse SWT PI/gtk/library/swt.c
===================================================================
RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT PI/gtk/library/swt.c,v
retrieving revision 1.66
diff -u -r1.66 swt.c
--- Eclipse SWT PI/gtk/library/swt.c	18 Jun 2002 14:27:48 -0000	1.66
+++ Eclipse SWT PI/gtk/library/swt.c	9 Jul 2002 00:08:21 -0000
@@ -282,6 +298,16 @@
 	return (jint)((GtkScrolledWindow *)arg0)->vscrollbar;
 }
 
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_gtk_OS_GTK_1PROGRESS_1BAR_1SET_1BAR_1STYLE
+	(JNIEnv *env, jclass that, jint arg0, jint arg1)
+{
+	DEBUG_CALL("gtk_1progress_1bar_1set_1bar_1style\n")
+
+	((GtkProgressBar*)arg0)->bar_style = (GtkProgressBarStyle)arg1;
+}
+
+
+
 JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_OS_PANGO_1PIXELS
 	(JNIEnv *env, jclass that, jint arg0)
 {
@@ -3130,14 +3203,6 @@
 	return (jint)gtk_progress_bar_new();
 }
 
-JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_gtk_OS_gtk_1progress_1bar_1set_1bar_1style
-	(JNIEnv *env, jclass that, jint arg0, jint arg1)
-{
-	DEBUG_CALL("gtk_1progress_1bar_1set_1bar_1style\n")
-
-	gtk_progress_bar_set_bar_style((GtkProgressBar *)arg0, (GtkProgressBarStyle)arg1);
-}
-
 JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_gtk_OS_gtk_1progress_1bar_1set_1orientation
 	(JNIEnv *env, jclass that, jint arg0, jint arg1)
 {
@@ -3146,12 +3211,12 @@
 	gtk_progress_bar_set_orientation((GtkProgressBar *)arg0, (GtkProgressBarOrientation)arg1);
 }
 
-JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_gtk_OS_gtk_1progress_1configure
-	(JNIEnv *env, jclass that, jint arg0, jdouble arg1, jdouble arg2, jdouble arg3)
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_gtk_OS_gtk_1progress_1bar_1set_1fraction
+        (JNIEnv *env, jclass that, jint arg0, jdouble arg1)
 {
-	DEBUG_CALL("gtk_1progress_1configure\n")
+        DEBUG_CALL("gtk_1progress_1bar_1set_1fraction\n")
 
-	gtk_progress_configure((GtkProgress *)arg0, (gdouble)arg1, (gdouble)arg2, (gdouble)arg3);
+        gtk_progress_bar_set_fraction((GtkProgressBar*)arg0, (gdouble)arg1);
 }
 
 JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_OS_gtk_1radio_1button_1group
Index: Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
===================================================================
RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java,v
retrieving revision 1.109
diff -u -r1.109 OS.java
--- Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java	18 Jun 2002 14:38:14 -0000	1.109
+++ Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java	9 Jul 2002 00:08:21 -0000
@@ -297,6 +299,7 @@
 public static final native int GTK_WIDGET_TYPE(int wid);
 public static final native void GTK_WIDGET_UNSET_FLAGS(int wid, int flag);
 public static final native boolean GTK_WIDGET_VISIBLE(int wid);
+public static final native void GTK_PROGRESS_BAR_SET_BAR_STYLE(int pbar, int style);
 public static final native int PANGO_PIXELS(int dimension);
 public static final native int g_filename_to_utf8(int opsysstring, int len, int bytes_read, int bytes_written, int error);
 public static final native void g_free(int mem);
@@ -598,13 +607,14 @@
 public static final native int gtk_pixmap_new(int pixmap, int mask);
 public static final native void gtk_pixmap_set(int pixmap, int val, int mask);
 public static final native int gtk_progress_bar_new();
-public static final native void gtk_progress_bar_set_bar_style(int pbar, int style);
 public static final native void gtk_progress_bar_set_orientation(int pbar, int orientation);
-public static final native void gtk_progress_configure(int progress, double value, double min, double max);
+public static final native void gtk_progress_bar_set_fraction(int pbar, double fraction);
 public static final native int gtk_radio_button_group(int radio_button);
 public static final native int gtk_radio_button_new(int group);
 public static final native int gtk_radio_menu_item_new_with_label(int group, byte[] label);
 public static final native int gtk_range_get_adjustment(int range);
 public static final native void gtk_rc_style_set_xthickness(int style, int thickness);
 public static final native void gtk_rc_style_set_ythickness(int style, int thickness);
 public static final native void gtk_scale_set_digits(int scale, int digits);
 public static final native void gtk_scale_set_draw_value(int scale, boolean draw_value);
 public static final native int gtk_scrolled_window_get_hadjustment(int scrolled_window);

Back to the top