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     gtk2_paint_arrow(widget_type, state, shadow_type, getStrFor(env, detail),
  42             x, y, w, h, arrow_type, TRUE);
  43 }
  44 
  45 /*
  46  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
  47  * Method:    native_paint_box
  48  * Signature: (IIILjava/lang/String;IIIIII)V
  49  */
  50 JNIEXPORT void JNICALL
  51 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1box(
  52         JNIEnv *env, jobject this,
  53         jint widget_type, jint state, jint shadow_type, jstring detail,
  54         jint x, jint y, jint w, jint h,
  55         jint synth_state, jint dir)
  56 {
  57     gtk2_paint_box(widget_type, state, shadow_type, getStrFor(env, detail),
  58                    x, y, w, h, synth_state, dir);
  59 }
  60 
  61 /*
  62  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
  63  * Method:    native_paint_box_gap
  64  * Signature: (IIILjava/lang/String;IIIIIII)V
  65  */
  66 JNIEXPORT void JNICALL
  67 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1box_1gap(
  68         JNIEnv *env, jobject this,
  69         jint widget_type, jint state, jint shadow_type, jstring detail,
  70         jint x, jint y, jint w, jint h,
  71         jint gap_side, jint gap_x, jint gap_w)
  72 {
  73     gtk2_paint_box_gap(widget_type, state, shadow_type, getStrFor(env, detail),
  74             x, y, w, h, gap_side, gap_x, gap_w);
  75 }
  76 
  77 /*
  78  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
  79  * Method:    native_paint_check
  80  * Signature: (IILjava/lang/String;IIII)V
  81  */
  82 JNIEXPORT void JNICALL
  83 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1check(
  84         JNIEnv *env, jobject this,
  85         jint widget_type, jint synth_state, jstring detail,
  86         jint x, jint y, jint w, jint h)
  87 {
  88     gtk2_paint_check(widget_type, synth_state, getStrFor(env, detail),
  89                      x, y, w, h);
  90 }
  91 
  92 /*
  93  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
  94  * Method:    native_paint_expander
  95  * Signature: (IILjava/lang/String;IIIII)V
  96  */
  97 JNIEXPORT void JNICALL
  98 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1expander(
  99         JNIEnv *env, jobject this,
 100         jint widget_type, jint state, jstring detail,
 101         jint x, jint y, jint w, jint h, jint expander_style)
 102 {
 103     gtk2_paint_expander(widget_type, state, getStrFor(env, detail),
 104             x, y, w, h, expander_style);
 105 }
 106 
 107 /*
 108  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 109  * Method:    native_paint_extension
 110  * Signature: (IIILjava/lang/String;IIIII)V
 111  */
 112 JNIEXPORT void JNICALL
 113 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1extension(
 114         JNIEnv *env, jobject this,
 115         jint widget_type, jint state, jint shadow_type, jstring detail,
 116         jint x, jint y, jint w, jint h, jint placement)
 117 {
 118     gtk2_paint_extension(widget_type, state, shadow_type,
 119             getStrFor(env, detail), x, y, w, h, placement);
 120 }
 121 
 122 /*
 123  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 124  * Method:    native_paint_flat_box
 125  * Signature: (IIILjava/lang/String;IIII)V
 126  */
 127 JNIEXPORT void JNICALL
 128 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1flat_1box(
 129         JNIEnv *env, jobject this,
 130         jint widget_type, jint state, jint shadow_type, jstring detail,
 131         jint x, jint y, jint w, jint h, jboolean has_focus)
 132 {
 133     gtk2_paint_flat_box(widget_type, state, shadow_type,
 134             getStrFor(env, detail), x, y, w, h, has_focus);
 135 }
 136 
 137 /*
 138  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 139  * Method:    native_paint_focus
 140  * Signature: (IILjava/lang/String;IIII)V
 141  */
 142 JNIEXPORT void JNICALL
 143 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1focus(
 144         JNIEnv *env, jobject this,
 145         jint widget_type, jint state, jstring detail,
 146         jint x, jint y, jint w, jint h)
 147 {
 148     gtk2_paint_focus(widget_type, state, getStrFor(env, detail),
 149             x, y, w, h);
 150 }
 151 
 152 /*
 153  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 154  * Method:    native_paint_handle
 155  * Signature: (IIILjava/lang/String;IIIII)V
 156  */
 157 JNIEXPORT void JNICALL
 158 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1handle(
 159         JNIEnv *env, jobject this,
 160         jint widget_type, jint state, jint shadow_type, jstring detail,
 161         jint x, jint y, jint w, jint h, jint orientation)
 162 {
 163     gtk2_paint_handle(widget_type, state, shadow_type, getStrFor(env, detail),
 164             x, y, w, h, orientation);
 165 }
 166 
 167 /*
 168  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 169  * Method:    native_paint_hline
 170  * Signature: (IILjava/lang/String;IIII)V
 171  */
 172 JNIEXPORT void JNICALL
 173 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1hline(
 174         JNIEnv *env, jobject this,
 175         jint widget_type, jint state, jstring detail,
 176         jint x, jint y, jint w, jint h)
 177 {
 178     gtk2_paint_hline(widget_type, state, getStrFor(env, detail),
 179             x, y, w, h);
 180 }
 181 
 182 /*
 183  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 184  * Method:    native_paint_option
 185  * Signature: (IILjava/lang/String;IIII)V
 186  */
 187 JNIEXPORT void JNICALL
 188 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1option(
 189         JNIEnv *env, jobject this,
 190         jint widget_type, jint synth_state, jstring detail,
 191         jint x, jint y, jint w, jint h)
 192 {
 193     gtk2_paint_option(widget_type, synth_state, getStrFor(env, detail),
 194                       x, y, w, h);
 195 }
 196 
 197 /*
 198  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 199  * Method:    native_paint_shadow
 200  * Signature: (IIILjava/lang/String;IIIIII)V
 201  */
 202 JNIEXPORT void JNICALL
 203 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1shadow(
 204         JNIEnv *env, jobject this,
 205         jint widget_type, jint state, jint shadow_type, jstring detail,
 206         jint x, jint y, jint w, jint h,
 207         jint synth_state, jint dir)
 208 {
 209     gtk2_paint_shadow(widget_type, state, shadow_type, getStrFor(env, detail),
 210                       x, y, w, h, synth_state, dir);
 211 }
 212 
 213 /*
 214  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 215  * Method:    native_paint_slider
 216  * Signature: (IIILjava/lang/String;IIIII)V
 217  */
 218 JNIEXPORT void JNICALL
 219 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1slider(
 220         JNIEnv *env, jobject this,
 221         jint widget_type, jint state, jint shadow_type, jstring detail,
 222         jint x, jint y, jint w, jint h, jint orientation)
 223 {
 224     gtk2_paint_slider(widget_type, state, shadow_type, getStrFor(env, detail),
 225             x, y, w, h, orientation);
 226 }
 227 
 228 /*
 229  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 230  * Method:    native_paint_vline
 231  * Signature: (IILjava/lang/String;IIII)V
 232  */
 233 JNIEXPORT void JNICALL
 234 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1vline(
 235         JNIEnv *env, jobject this,
 236         jint widget_type, jint state, jstring detail,
 237         jint x, jint y, jint w, jint h)
 238 {
 239     gtk2_paint_vline(widget_type, state, getStrFor(env, detail),
 240             x, y, w, h);
 241 }
 242 
 243 /*
 244  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 245  * Method:    native_paint_background
 246  * Signature: (IIIIII)V
 247  */
 248 JNIEXPORT void JNICALL
 249 Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1background(
 250         JNIEnv *env, jobject this, jint widget_type, jint state,
 251         jint x, jint y, jint w, jint h)
 252 {
 253     gtk_paint_background(widget_type, state, x, y, w, h);
 254 }
 255 
 256 /*
 257  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 258  * Method:    nativeStartPainting
 259  * Signature: (II)V
 260  */
 261 JNIEXPORT void JNICALL
 262 Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeStartPainting(
 263         JNIEnv *env, jobject this, jint w, jint h)
 264 {
 265     gtk2_init_painting(w, h);
 266 }
 267 
 268 /*
 269  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 270  * Method:    nativeFinishPainting
 271  * Signature: ([III)I
 272  */
 273 JNIEXPORT jint JNICALL
 274 Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeFinishPainting(
 275         JNIEnv *env, jobject this, jintArray dest, jint width, jint height)
 276 {
 277     jint transparency;
 278     gint *buffer = (gint*) (*env)->GetPrimitiveArrayCritical(env, dest, 0);
 279     transparency = gtk2_copy_image(buffer, width, height);
 280     (*env)->ReleasePrimitiveArrayCritical(env, dest, buffer, 0);
 281     return transparency;
 282 }
 283 
 284 /*
 285  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 286  * Method:    native_switch_theme
 287  * Signature: ()V
 288  */
 289 JNIEXPORT void JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1switch_1theme(
 290         JNIEnv *env, jobject this)
 291 {
 292     flush_gtk_event_loop();
 293 }
 294 
 295 /*
 296  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 297  * Method:    native_get_gtk_setting
 298  * Signature: (I)Ljava/lang/Object;
 299  */
 300 JNIEXPORT jobject JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1get_1gtk_1setting(
 301         JNIEnv *env, jobject this, jint property)
 302 {
 303     return gtk2_get_setting(env, property);
 304 }
 305 
 306 /*
 307  * Class:     com_sun_java_swing_plaf_gtk_GTKEngine
 308  * Method:    nativeSetRangeValue
 309  * Signature: (IDDDD)V
 310  */
 311 JNIEXPORT void JNICALL
 312 Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeSetRangeValue(
 313         JNIEnv *env, jobject this, jint widget_type,
 314         jdouble value, jdouble min, jdouble max, jdouble visible)
 315 {
 316     gtk2_set_range_value(widget_type, value, min, max, visible);
 317 }