1 /*
   2  * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 #include <stdlib.h>
  27 #include "gtk2_interface.h"
  28 #include "com_sun_java_swing_plaf_gtk_GTKEngine.h"
  29 
  30 /*
  31  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
  32  * Method:    native_paint_arrow
  33  * Signature: (IIILjava/lang/String;IIIII)V
  34  */
  35 JNIEXPORT void JNICALL
  36 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1arrow(
  37         JNIEnv *env, jobject this,
  38         jint widget_type, jint state, jint shadow_type, jstring detail,
  39         jint x, jint y, jint w, jint h, jint arrow_type)
  40 {
  41     fp_gdk_threads_enter();
  42     gtk2_paint_arrow(widget_type, state, shadow_type, getStrFor(env, detail),
  43             x, y, w, h, arrow_type, TRUE);
  44     fp_gdk_threads_leave();
  45 }
  46 
  47 /*
  48  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
  49  * Method:    native_paint_box
  50  * Signature: (IIILjava/lang/String;IIIIII)V
  51  */
  52 JNIEXPORT void JNICALL
  53 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1box(
  54         JNIEnv *env, jobject this,
  55         jint widget_type, jint state, jint shadow_type, jstring detail,
  56         jint x, jint y, jint w, jint h,
  57         jint synth_state, jint dir)
  58 {
  59     fp_gdk_threads_enter();
  60     gtk2_paint_box(widget_type, state, shadow_type, getStrFor(env, detail),
  61                    x, y, w, h, synth_state, dir);
  62     fp_gdk_threads_leave();
  63 }
  64 
  65 /*
  66  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
  67  * Method:    native_paint_box_gap
  68  * Signature: (IIILjava/lang/String;IIIIIII)V
  69  */
  70 JNIEXPORT void JNICALL
  71 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1box_1gap(
  72         JNIEnv *env, jobject this,
  73         jint widget_type, jint state, jint shadow_type, jstring detail,
  74         jint x, jint y, jint w, jint h,
  75         jint gap_side, jint gap_x, jint gap_w)
  76 {
  77     fp_gdk_threads_enter();
  78     gtk2_paint_box_gap(widget_type, state, shadow_type, getStrFor(env, detail),
  79             x, y, w, h, gap_side, gap_x, gap_w);
  80     fp_gdk_threads_leave();
  81 }
  82 
  83 /*
  84  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
  85  * Method:    native_paint_check
  86  * Signature: (IILjava/lang/String;IIII)V
  87  */
  88 JNIEXPORT void JNICALL
  89 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1check(
  90         JNIEnv *env, jobject this,
  91         jint widget_type, jint synth_state, jstring detail,
  92         jint x, jint y, jint w, jint h)
  93 {
  94     fp_gdk_threads_enter();
  95     gtk2_paint_check(widget_type, synth_state, getStrFor(env, detail),
  96                      x, y, w, h);
  97     fp_gdk_threads_leave();
  98 }
  99 
 100 /*
 101  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 102  * Method:    native_paint_expander
 103  * Signature: (IILjava/lang/String;IIIII)V
 104  */
 105 JNIEXPORT void JNICALL
 106 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1expander(
 107         JNIEnv *env, jobject this,
 108         jint widget_type, jint state, jstring detail,
 109         jint x, jint y, jint w, jint h, jint expander_style)
 110 {
 111     fp_gdk_threads_enter();
 112     gtk2_paint_expander(widget_type, state, getStrFor(env, detail),
 113             x, y, w, h, expander_style);
 114     fp_gdk_threads_leave();
 115 }
 116 
 117 /*
 118  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 119  * Method:    native_paint_extension
 120  * Signature: (IIILjava/lang/String;IIIII)V
 121  */
 122 JNIEXPORT void JNICALL
 123 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1extension(
 124         JNIEnv *env, jobject this,
 125         jint widget_type, jint state, jint shadow_type, jstring detail,
 126         jint x, jint y, jint w, jint h, jint placement)
 127 {
 128     fp_gdk_threads_enter();
 129     gtk2_paint_extension(widget_type, state, shadow_type,
 130             getStrFor(env, detail), x, y, w, h, placement);
 131     fp_gdk_threads_leave();
 132 }
 133 
 134 /*
 135  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 136  * Method:    native_paint_flat_box
 137  * Signature: (IIILjava/lang/String;IIII)V
 138  */
 139 JNIEXPORT void JNICALL
 140 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1flat_1box(
 141         JNIEnv *env, jobject this,
 142         jint widget_type, jint state, jint shadow_type, jstring detail,
 143         jint x, jint y, jint w, jint h, jboolean has_focus)
 144 {
 145     fp_gdk_threads_enter();
 146     gtk2_paint_flat_box(widget_type, state, shadow_type,
 147             getStrFor(env, detail), x, y, w, h, has_focus);
 148     fp_gdk_threads_leave();
 149 }
 150 
 151 /*
 152  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 153  * Method:    native_paint_focus
 154  * Signature: (IILjava/lang/String;IIII)V
 155  */
 156 JNIEXPORT void JNICALL
 157 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1focus(
 158         JNIEnv *env, jobject this,
 159         jint widget_type, jint state, jstring detail,
 160         jint x, jint y, jint w, jint h)
 161 {
 162     fp_gdk_threads_enter();
 163     gtk2_paint_focus(widget_type, state, getStrFor(env, detail),
 164             x, y, w, h);
 165     fp_gdk_threads_leave();
 166 }
 167 
 168 /*
 169  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 170  * Method:    native_paint_handle
 171  * Signature: (IIILjava/lang/String;IIIII)V
 172  */
 173 JNIEXPORT void JNICALL
 174 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1handle(
 175         JNIEnv *env, jobject this,
 176         jint widget_type, jint state, jint shadow_type, jstring detail,
 177         jint x, jint y, jint w, jint h, jint orientation)
 178 {
 179     fp_gdk_threads_enter();
 180     gtk2_paint_handle(widget_type, state, shadow_type, getStrFor(env, detail),
 181             x, y, w, h, orientation);
 182     fp_gdk_threads_leave();
 183 }
 184 
 185 /*
 186  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 187  * Method:    native_paint_hline
 188  * Signature: (IILjava/lang/String;IIII)V
 189  */
 190 JNIEXPORT void JNICALL
 191 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1hline(
 192         JNIEnv *env, jobject this,
 193         jint widget_type, jint state, jstring detail,
 194         jint x, jint y, jint w, jint h)
 195 {
 196     fp_gdk_threads_enter();
 197     gtk2_paint_hline(widget_type, state, getStrFor(env, detail),
 198             x, y, w, h);
 199     fp_gdk_threads_leave();
 200 }
 201 
 202 /*
 203  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 204  * Method:    native_paint_option
 205  * Signature: (IILjava/lang/String;IIII)V
 206  */
 207 JNIEXPORT void JNICALL
 208 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1option(
 209         JNIEnv *env, jobject this,
 210         jint widget_type, jint synth_state, jstring detail,
 211         jint x, jint y, jint w, jint h)
 212 {
 213     fp_gdk_threads_enter();
 214     gtk2_paint_option(widget_type, synth_state, getStrFor(env, detail),
 215                       x, y, w, h);
 216     fp_gdk_threads_leave();
 217 }
 218 
 219 /*
 220  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 221  * Method:    native_paint_shadow
 222  * Signature: (IIILjava/lang/String;IIIIII)V
 223  */
 224 JNIEXPORT void JNICALL
 225 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1shadow(
 226         JNIEnv *env, jobject this,
 227         jint widget_type, jint state, jint shadow_type, jstring detail,
 228         jint x, jint y, jint w, jint h,
 229         jint synth_state, jint dir)
 230 {
 231     fp_gdk_threads_enter();
 232     gtk2_paint_shadow(widget_type, state, shadow_type, getStrFor(env, detail),
 233                       x, y, w, h, synth_state, dir);
 234     fp_gdk_threads_leave();
 235 }
 236 
 237 /*
 238  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 239  * Method:    native_paint_slider
 240  * Signature: (IIILjava/lang/String;IIIII)V
 241  */
 242 JNIEXPORT void JNICALL
 243 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1slider(
 244         JNIEnv *env, jobject this,
 245         jint widget_type, jint state, jint shadow_type, jstring detail,
 246         jint x, jint y, jint w, jint h, jint orientation)
 247 {
 248     fp_gdk_threads_enter();
 249     gtk2_paint_slider(widget_type, state, shadow_type, getStrFor(env, detail),
 250             x, y, w, h, orientation);
 251     fp_gdk_threads_leave();
 252 }
 253 
 254 /*
 255  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 256  * Method:    native_paint_vline
 257  * Signature: (IILjava/lang/String;IIII)V
 258  */
 259 JNIEXPORT void JNICALL
 260 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1vline(
 261         JNIEnv *env, jobject this,
 262         jint widget_type, jint state, jstring detail,
 263         jint x, jint y, jint w, jint h)
 264 {
 265     fp_gdk_threads_enter();
 266     gtk2_paint_vline(widget_type, state, getStrFor(env, detail),
 267             x, y, w, h);
 268     fp_gdk_threads_leave();
 269 }
 270 
 271 /*
 272  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 273  * Method:    native_paint_background
 274  * Signature: (IIIIII)V
 275  */
 276 JNIEXPORT void JNICALL
 277 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1background(
 278         JNIEnv *env, jobject this, jint widget_type, jint state,
 279         jint x, jint y, jint w, jint h)
 280 {
 281     fp_gdk_threads_enter();
 282     gtk_paint_background(widget_type, state, x, y, w, h);
 283     fp_gdk_threads_leave();
 284 }
 285 
 286 /*
 287  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 288  * Method:    nativeStartPainting
 289  * Signature: (II)V
 290  */
 291 JNIEXPORT void JNICALL
 292 Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeStartPainting(
 293         JNIEnv *env, jobject this, jint w, jint h)
 294 {
 295     fp_gdk_threads_enter();
 296     gtk2_init_painting(w, h);
 297     fp_gdk_threads_leave();
 298 }
 299 
 300 /*
 301  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 302  * Method:    nativeFinishPainting
 303  * Signature: ([III)I
 304  */
 305 JNIEXPORT jint JNICALL
 306 Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeFinishPainting(
 307         JNIEnv *env, jobject this, jintArray dest, jint width, jint height)
 308 {
 309     jint transparency;
 310     gint *buffer = (gint*) (*env)->GetPrimitiveArrayCritical(env, dest, 0);
 311     fp_gdk_threads_enter();
 312     transparency = gtk2_copy_image(buffer, width, height);
 313     fp_gdk_threads_leave();
 314     (*env)->ReleasePrimitiveArrayCritical(env, dest, buffer, 0);
 315     return transparency;
 316 }
 317 
 318 /*
 319  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 320  * Method:    native_switch_theme
 321  * Signature: ()V
 322  */
 323 JNIEXPORT void JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1switch_1theme(
 324         JNIEnv *env, jobject this)
 325 {
 326     fp_gdk_threads_enter();
 327     flush_gtk_event_loop();
 328     fp_gdk_threads_leave();
 329 }
 330 
 331 /*
 332  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 333  * Method:    native_get_gtk_setting
 334  * Signature: (I)Ljava/lang/Object;
 335  */
 336 JNIEXPORT jobject JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1get_1gtk_1setting(
 337         JNIEnv *env, jobject this, jint property)
 338 {
 339     jobject obj;
 340     fp_gdk_threads_enter();
 341     obj = gtk2_get_setting(env, property);
 342     fp_gdk_threads_leave();
 343     return obj;
 344 }
 345 
 346 /*
 347  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 348  * Method:    nativeSetRangeValue
 349  * Signature: (IDDDD)V
 350  */
 351 JNIEXPORT void JNICALL
 352 Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeSetRangeValue(
 353         JNIEnv *env, jobject this, jint widget_type,
 354         jdouble value, jdouble min, jdouble max, jdouble visible)
 355 {
 356     fp_gdk_threads_enter();
 357     gtk2_set_range_value(widget_type, value, min, max, visible);
 358     fp_gdk_threads_leave();
 359 }