Merge from the pain train
[official-gcc.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkScrollBarPeer.c
blob790c90109aeaec2165cb6b56ebb00d92962f49fa
1 /* gtkscrollbarpeer.c -- Native implementation of GtkScrollbarPeer
2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 #include "gtkpeer.h"
40 #include "gnu_java_awt_peer_gtk_GtkComponentPeer.h"
41 #include "gnu_java_awt_peer_gtk_GtkScrollbarPeer.h"
43 static void post_change_event (GtkRange *range, jobject peer);
45 JNIEXPORT void JNICALL
46 Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_create
47 (JNIEnv *env, jobject obj, jint orientation, jint value,
48 jint min, jint max, jint step_incr, jint page_incr, jint visible_amount)
50 GtkWidget *scrollbar;
51 GtkObject *adj;
53 /* Create global reference and save it for future use */
54 NSA_SET_GLOBAL_REF (env, obj);
56 gdk_threads_enter ();
58 adj = gtk_adjustment_new ((gdouble) value,
59 (gdouble) min,
60 (gdouble) max,
61 (gdouble) step_incr,
62 (gdouble) page_incr,
63 (gdouble) visible_amount);
65 scrollbar = (orientation) ? gtk_vscrollbar_new (GTK_ADJUSTMENT (adj)) :
66 gtk_hscrollbar_new (GTK_ADJUSTMENT (adj));
68 GTK_RANGE (scrollbar)->round_digits = 0;
69 /* These calls seem redundant but they are not. They clamp values
70 so that the slider's entirety is always between the two
71 steppers. */
72 gtk_range_set_range (GTK_RANGE (scrollbar), (gdouble) min, (gdouble) max);
73 gtk_range_set_value (GTK_RANGE (scrollbar), (gdouble) value);
75 gdk_threads_leave ();
77 NSA_SET_PTR (env, obj, scrollbar);
80 JNIEXPORT void JNICALL
81 Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_connectSignals
82 (JNIEnv *env, jobject obj)
84 void *ptr = NSA_GET_PTR (env, obj);
85 jobject *gref = NSA_GET_GLOBAL_REF (env, obj);
86 g_assert (gref);
88 gdk_threads_enter ();
90 g_signal_connect (G_OBJECT (ptr), "value-changed",
91 G_CALLBACK (post_change_event), *gref);
93 gdk_threads_leave ();
95 /* Connect the superclass signals. */
96 Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj);
100 JNIEXPORT void JNICALL
101 Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setLineIncrement
102 (JNIEnv *env, jobject obj, jint amount)
104 void *ptr;
105 GtkAdjustment *adj;
107 ptr = NSA_GET_PTR (env, obj);
109 gdk_threads_enter ();
111 adj = gtk_range_get_adjustment (GTK_RANGE (ptr));
112 adj->step_increment = (gdouble) amount;
113 gtk_adjustment_changed (adj);
115 gdk_threads_leave ();
118 JNIEXPORT void JNICALL
119 Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setPageIncrement
120 (JNIEnv *env, jobject obj, jint amount)
122 void *ptr;
123 GtkAdjustment *adj;
125 ptr = NSA_GET_PTR (env, obj);
127 gdk_threads_enter ();
129 adj = gtk_range_get_adjustment (GTK_RANGE (ptr));
130 adj->page_increment = (gdouble) amount;
131 gtk_adjustment_changed (adj);
133 gdk_threads_leave ();
136 JNIEXPORT void JNICALL
137 Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_setValues
138 (JNIEnv *env, jobject obj, jint value, jint visible, jint min, jint max)
140 void *ptr;
141 GtkAdjustment *adj;
143 ptr = NSA_GET_PTR (env, obj);
145 gdk_threads_enter ();
147 adj = gtk_range_get_adjustment (GTK_RANGE (ptr));
148 adj->page_size = (gdouble) visible;
150 gtk_range_set_range (GTK_RANGE (ptr), (gdouble) min, (gdouble) max);
151 gtk_range_set_value (GTK_RANGE (ptr), (gdouble) value);
153 gtk_adjustment_changed (adj);
155 gdk_threads_leave ();
158 static void
159 post_change_event (GtkRange *range, jobject peer)
161 GtkAdjustment *adj;
162 adj = gtk_range_get_adjustment (range);
163 (*gdk_env())->CallVoidMethod (gdk_env(), peer, postAdjustmentEventID,
164 AWT_ADJUSTMENT_TRACK, (jint) adj->value);