Scrollbar.java (next_scrollbar_number): New field.
2004-02-05 Thomas Fitzsimmons <fitzsim@redhat.com> * java/awt/Scrollbar.java (next_scrollbar_number): New field. (Scrollbar (int, int, int, int, int)): Make default page increment 10. (setValues): Only call peer.setValues if one of the values has changed. (generateName): New method. (getUniqueLong): New method. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollBarPeer.c (range_scrollbar): Remove structure. (post_adjustment_event): Remove function. (post_change_event): Accept jobject argument. (create): Cast jints to gdoubles. Round scrollbar values to the nearest integer. Clamp min, max and value settings. (connectJObject): Connect hook to widget->window. (connectSignals): Remove range_scrollbar structure variables. Remove "move-slider" connection. Pass global peer reference to "value-changed" callback. (setLineIncrement): Cast jint value to gdouble. (setPageIncrement): Likewise. (setValues): Likewise. Clamp min, max and value settings. From-SVN: r77332
This commit is contained in:
parent
6039a93dd7
commit
bc1ec7f70e
@ -1,3 +1,26 @@
|
||||
2004-02-05 Thomas Fitzsimmons <fitzsim@redhat.com>
|
||||
|
||||
* java/awt/Scrollbar.java (next_scrollbar_number): New field.
|
||||
(Scrollbar (int, int, int, int, int)): Make default page
|
||||
increment 10.
|
||||
(setValues): Only call peer.setValues if one of the values has
|
||||
changed.
|
||||
(generateName): New method.
|
||||
(getUniqueLong): New method.
|
||||
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkScrollBarPeer.c
|
||||
(range_scrollbar): Remove structure.
|
||||
(post_adjustment_event): Remove function.
|
||||
(post_change_event): Accept jobject argument.
|
||||
(create): Cast jints to gdoubles. Round scrollbar values to the
|
||||
nearest integer. Clamp min, max and value settings.
|
||||
(connectJObject): Connect hook to widget->window.
|
||||
(connectSignals): Remove range_scrollbar structure variables.
|
||||
Remove "move-slider" connection. Pass global peer reference to
|
||||
"value-changed" callback.
|
||||
(setLineIncrement): Cast jint value to gdouble.
|
||||
(setPageIncrement): Likewise.
|
||||
(setValues): Likewise. Clamp min, max and value settings.
|
||||
|
||||
2004-02-05 Michael Koch <konqueror@gmx.de>
|
||||
|
||||
* javax/swing/AbstractCellEditor.java
|
||||
|
@ -120,6 +120,11 @@ private AdjustmentListener adjustment_listeners;
|
||||
|
||||
private transient boolean valueIsAdjusting = false;
|
||||
|
||||
/*
|
||||
* The number used to generate the name returned by getName.
|
||||
*/
|
||||
private static transient long next_scrollbar_number = 0;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
@ -194,9 +199,8 @@ Scrollbar(int orientation, int value, int visibleAmount, int minimum,
|
||||
// Default is 1 according to online docs.
|
||||
lineIncrement = 1;
|
||||
|
||||
pageIncrement = (maximum - minimum) / 5;
|
||||
if (pageIncrement == 0)
|
||||
pageIncrement = 1;
|
||||
// Default is 10 according to javadocs.
|
||||
pageIncrement = 10;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
@ -394,15 +398,17 @@ setValues(int value, int visibleAmount, int minimum, int maximum)
|
||||
if (visibleAmount > maximum - minimum)
|
||||
visibleAmount = maximum - minimum;
|
||||
|
||||
ScrollbarPeer peer = (ScrollbarPeer) getPeer ();
|
||||
if (peer != null
|
||||
&& (this.value != value || this.visibleAmount != visibleAmount
|
||||
|| this.minimum != minimum || this.maximum != maximum))
|
||||
peer.setValues(value, visibleAmount, minimum, maximum);
|
||||
|
||||
this.value = value;
|
||||
this.visibleAmount = visibleAmount;
|
||||
this.minimum = minimum;
|
||||
this.maximum = maximum;
|
||||
|
||||
ScrollbarPeer sp = (ScrollbarPeer)getPeer();
|
||||
if (sp != null)
|
||||
sp.setValues(value, visibleAmount, minimum, maximum);
|
||||
|
||||
int range = maximum - minimum;
|
||||
if (lineIncrement > range)
|
||||
{
|
||||
@ -411,8 +417,8 @@ setValues(int value, int visibleAmount, int minimum, int maximum)
|
||||
else
|
||||
lineIncrement = range;
|
||||
|
||||
if (sp != null)
|
||||
sp.setLineIncrement(lineIncrement);
|
||||
if (peer != null)
|
||||
peer.setLineIncrement(lineIncrement);
|
||||
}
|
||||
|
||||
if (pageIncrement > range)
|
||||
@ -422,8 +428,8 @@ setValues(int value, int visibleAmount, int minimum, int maximum)
|
||||
else
|
||||
pageIncrement = range;
|
||||
|
||||
if (sp != null)
|
||||
sp.setPageIncrement(pageIncrement);
|
||||
if (peer != null)
|
||||
peer.setPageIncrement(pageIncrement);
|
||||
}
|
||||
}
|
||||
|
||||
@ -503,9 +509,9 @@ setLineIncrement(int lineIncrement)
|
||||
|
||||
this.lineIncrement = lineIncrement;
|
||||
|
||||
ScrollbarPeer sp = (ScrollbarPeer) getPeer ();
|
||||
if (sp != null)
|
||||
sp.setLineIncrement (this.lineIncrement);
|
||||
ScrollbarPeer peer = (ScrollbarPeer) getPeer ();
|
||||
if (peer != null)
|
||||
peer.setLineIncrement (this.lineIncrement);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
@ -584,9 +590,9 @@ setPageIncrement(int pageIncrement)
|
||||
|
||||
this.pageIncrement = pageIncrement;
|
||||
|
||||
ScrollbarPeer sp = (ScrollbarPeer) getPeer ();
|
||||
if (sp != null)
|
||||
sp.setPageIncrement (this.pageIncrement);
|
||||
ScrollbarPeer peer = (ScrollbarPeer) getPeer ();
|
||||
if (peer != null)
|
||||
peer.setPageIncrement (this.pageIncrement);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
@ -746,5 +752,20 @@ paramString()
|
||||
{
|
||||
this.valueIsAdjusting = valueIsAdjusting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique name for this scroll bar.
|
||||
*
|
||||
* @return A unique name for this scroll bar.
|
||||
*/
|
||||
String generateName ()
|
||||
{
|
||||
return "scrollbar" + getUniqueLong ();
|
||||
}
|
||||
|
||||
private static synchronized long getUniqueLong ()
|
||||
{
|
||||
return next_scrollbar_number++;
|
||||
}
|
||||
} // class Scrollbar
|
||||
|
||||
|
@ -40,72 +40,14 @@ exception statement from your version. */
|
||||
#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h"
|
||||
#include "gnu_java_awt_peer_gtk_GtkScrollbarPeer.h"
|
||||
|
||||
struct range_scrollbar
|
||||
{
|
||||
GtkRange *range;
|
||||
jobject *scrollbar;
|
||||
};
|
||||
|
||||
static void
|
||||
post_change_event (GtkRange *range,
|
||||
struct range_scrollbar *rs)
|
||||
{
|
||||
GtkAdjustment *adj;
|
||||
adj = gtk_range_get_adjustment (range);
|
||||
(*gdk_env)->CallVoidMethod (gdk_env, *(rs->scrollbar), postAdjustmentEventID,
|
||||
AWT_ADJUSTMENT_TRACK, (jint) adj->value);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
post_adjustment_event (GtkRange *range, GtkScrollType scroll,
|
||||
struct range_scrollbar *rs)
|
||||
{
|
||||
jint type;
|
||||
GtkAdjustment *adj;
|
||||
|
||||
adj = gtk_range_get_adjustment (range);
|
||||
|
||||
switch (scroll)
|
||||
{
|
||||
case GTK_SCROLL_STEP_UP:
|
||||
case GTK_SCROLL_STEP_RIGHT:
|
||||
case GTK_SCROLL_STEP_FORWARD:
|
||||
type = AWT_ADJUSTMENT_UNIT_INCREMENT;
|
||||
break;
|
||||
case GTK_SCROLL_STEP_DOWN:
|
||||
case GTK_SCROLL_STEP_LEFT:
|
||||
case GTK_SCROLL_STEP_BACKWARD:
|
||||
type = AWT_ADJUSTMENT_UNIT_DECREMENT;
|
||||
break;
|
||||
case GTK_SCROLL_PAGE_UP:
|
||||
case GTK_SCROLL_PAGE_RIGHT:
|
||||
case GTK_SCROLL_PAGE_FORWARD:
|
||||
type = AWT_ADJUSTMENT_BLOCK_INCREMENT;
|
||||
break;
|
||||
case GTK_SCROLL_PAGE_DOWN:
|
||||
case GTK_SCROLL_PAGE_LEFT:
|
||||
case GTK_SCROLL_PAGE_BACKWARD:
|
||||
type = AWT_ADJUSTMENT_BLOCK_DECREMENT;
|
||||
break;
|
||||
case GTK_SCROLL_JUMP:
|
||||
case GTK_SCROLL_NONE: /* Apparently generated when slider is dragged. */
|
||||
type = AWT_ADJUSTMENT_TRACK;
|
||||
break;
|
||||
default: /* Can this happen? If so, is this right? */
|
||||
return;
|
||||
}
|
||||
|
||||
(*gdk_env)->CallVoidMethod (gdk_env, *(rs->scrollbar), postAdjustmentEventID,
|
||||
type, (jint) adj->value);
|
||||
}
|
||||
static void post_change_event (GtkRange *range, jobject peer);
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_create
|
||||
(JNIEnv *env, jobject obj, jint orientation, jint value,
|
||||
jint min, jint max, jint step_incr, jint page_incr, jint visible_amount)
|
||||
{
|
||||
GtkWidget *sb;
|
||||
GtkWidget *scrollbar;
|
||||
GtkObject *adj;
|
||||
|
||||
/* Create global reference and save it for future use */
|
||||
@ -113,16 +55,26 @@ Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_create
|
||||
|
||||
gdk_threads_enter ();
|
||||
|
||||
adj = gtk_adjustment_new (value, min, max,
|
||||
step_incr, page_incr,
|
||||
visible_amount);
|
||||
adj = gtk_adjustment_new ((gdouble) value,
|
||||
(gdouble) min,
|
||||
(gdouble) max,
|
||||
(gdouble) step_incr,
|
||||
(gdouble) page_incr,
|
||||
(gdouble) visible_amount);
|
||||
|
||||
sb = (orientation) ? gtk_vscrollbar_new (GTK_ADJUSTMENT (adj)) :
|
||||
scrollbar = (orientation) ? gtk_vscrollbar_new (GTK_ADJUSTMENT (adj)) :
|
||||
gtk_hscrollbar_new (GTK_ADJUSTMENT (adj));
|
||||
|
||||
GTK_RANGE (scrollbar)->round_digits = 0;
|
||||
/* These calls seem redundant but they are not. They clamp values
|
||||
so that the slider's entirety is always between the two
|
||||
steppers. */
|
||||
gtk_range_set_range (GTK_RANGE (scrollbar), (gdouble) min, (gdouble) max);
|
||||
gtk_range_set_value (GTK_RANGE (scrollbar), (gdouble) value);
|
||||
|
||||
gdk_threads_leave ();
|
||||
|
||||
NSA_SET_PTR (env, obj, sb);
|
||||
NSA_SET_PTR (env, obj, scrollbar);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
@ -137,7 +89,7 @@ Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_connectJObject
|
||||
|
||||
gtk_widget_realize (GTK_WIDGET (ptr));
|
||||
|
||||
connect_awt_hook (env, obj, 1, GTK_SCROLLBAR (ptr)->range);
|
||||
connect_awt_hook (env, obj, 1, GTK_WIDGET (ptr)->window);
|
||||
|
||||
gdk_threads_leave ();
|
||||
}
|
||||
@ -146,27 +98,14 @@ JNIEXPORT void JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_connectSignals
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
struct range_scrollbar *rs;
|
||||
void *ptr = NSA_GET_PTR (env, obj);
|
||||
jobject *gref = NSA_GET_GLOBAL_REF (env, obj);
|
||||
g_assert (gref);
|
||||
|
||||
rs = (struct range_scrollbar *) malloc (sizeof (struct range_scrollbar));
|
||||
|
||||
gdk_threads_enter ();
|
||||
|
||||
gtk_widget_realize (GTK_WIDGET (ptr));
|
||||
|
||||
rs->range = GTK_RANGE (ptr);
|
||||
rs->scrollbar = gref;
|
||||
|
||||
g_signal_connect (G_OBJECT (GTK_RANGE (ptr)),
|
||||
"move-slider",
|
||||
GTK_SIGNAL_FUNC (post_adjustment_event), rs);
|
||||
|
||||
g_signal_connect (G_OBJECT (GTK_RANGE (ptr)),
|
||||
"value-changed",
|
||||
GTK_SIGNAL_FUNC (post_change_event), rs);
|
||||
g_signal_connect (G_OBJECT (ptr), "value-changed",
|
||||
G_CALLBACK (post_change_event), *gref);
|
||||
|
||||
gdk_threads_leave ();
|
||||
|
||||
@ -186,8 +125,8 @@ Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setLineIncrement
|
||||
|
||||
gdk_threads_enter ();
|
||||
|
||||
adj = GTK_RANGE (ptr)->adjustment;
|
||||
adj->step_increment = amount;
|
||||
adj = gtk_range_get_adjustment (GTK_RANGE (ptr));
|
||||
adj->step_increment = (gdouble) amount;
|
||||
gtk_adjustment_changed (adj);
|
||||
|
||||
gdk_threads_leave ();
|
||||
@ -204,8 +143,8 @@ Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setPageIncrement
|
||||
|
||||
gdk_threads_enter ();
|
||||
|
||||
adj = GTK_RANGE (ptr)->adjustment;
|
||||
adj->page_increment = amount;
|
||||
adj = gtk_range_get_adjustment (GTK_RANGE (ptr));
|
||||
adj->page_increment = (gdouble) amount;
|
||||
gtk_adjustment_changed (adj);
|
||||
|
||||
gdk_threads_leave ();
|
||||
@ -222,12 +161,22 @@ Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setValues
|
||||
|
||||
gdk_threads_enter ();
|
||||
|
||||
adj = GTK_RANGE (ptr)->adjustment;
|
||||
adj->value = value;
|
||||
adj->page_size = visible;
|
||||
adj->lower = min;
|
||||
adj->upper = max;
|
||||
adj = gtk_range_get_adjustment (GTK_RANGE (ptr));
|
||||
adj->page_size = (gdouble) visible;
|
||||
|
||||
gtk_range_set_range (GTK_RANGE (ptr), (gdouble) min, (gdouble) max);
|
||||
gtk_range_set_value (GTK_RANGE (ptr), (gdouble) value);
|
||||
|
||||
gtk_adjustment_changed (adj);
|
||||
|
||||
gdk_threads_leave ();
|
||||
}
|
||||
|
||||
static void
|
||||
post_change_event (GtkRange *range, jobject peer)
|
||||
{
|
||||
GtkAdjustment *adj;
|
||||
adj = gtk_range_get_adjustment (range);
|
||||
(*gdk_env)->CallVoidMethod (gdk_env, peer, postAdjustmentEventID,
|
||||
AWT_ADJUSTMENT_TRACK, (jint) adj->value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user