1/* 2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26#include <stdlib.h> 27#include "gtk_interface.h" 28#include "com_sun_java_swing_plaf_gtk_GTKEngine.h" 29 30/* Static buffer for conversion from java.lang.String to UTF-8 */ 31static char conversionBuffer[CONV_BUFFER_SIZE]; 32 33const char *getStrFor(JNIEnv *env, jstring val) 34{ 35 int length = (*env)->GetStringLength(env, val); 36 if (length > CONV_BUFFER_SIZE-1) 37 { 38 length = CONV_BUFFER_SIZE-1; 39 } 40 41 (*env)->GetStringUTFRegion(env, val, 0, length, conversionBuffer); 42 return conversionBuffer; 43} 44 45/* 46 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 47 * Method: native_paint_arrow 48 * Signature: (IIILjava/lang/String;IIIII)V 49 */ 50JNIEXPORT void JNICALL 51Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1arrow( 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, jint arrow_type) 55{ 56 gtk->gdk_threads_enter(); 57 gtk->paint_arrow(widget_type, state, shadow_type, getStrFor(env, detail), 58 x, y, w, h, arrow_type, TRUE); 59 gtk->gdk_threads_leave(); 60} 61 62/* 63 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 64 * Method: native_paint_box 65 * Signature: (IIILjava/lang/String;IIIIII)V 66 */ 67JNIEXPORT void JNICALL 68Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1box( 69 JNIEnv *env, jobject this, 70 jint widget_type, jint state, jint shadow_type, jstring detail, 71 jint x, jint y, jint w, jint h, 72 jint synth_state, jint dir) 73{ 74 gtk->gdk_threads_enter(); 75 gtk->paint_box(widget_type, state, shadow_type, getStrFor(env, detail), 76 x, y, w, h, synth_state, dir); 77 gtk->gdk_threads_leave(); 78} 79 80/* 81 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 82 * Method: native_paint_box_gap 83 * Signature: (IIILjava/lang/String;IIIIIII)V 84 */ 85JNIEXPORT void JNICALL 86Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1box_1gap( 87 JNIEnv *env, jobject this, 88 jint widget_type, jint state, jint shadow_type, jstring detail, 89 jint x, jint y, jint w, jint h, 90 jint gap_side, jint gap_x, jint gap_w) 91{ 92 gtk->gdk_threads_enter(); 93 gtk->paint_box_gap(widget_type, state, shadow_type, getStrFor(env, detail), 94 x, y, w, h, gap_side, gap_x, gap_w); 95 gtk->gdk_threads_leave(); 96} 97 98/* 99 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 100 * Method: native_paint_check 101 * Signature: (IILjava/lang/String;IIII)V 102 */ 103JNIEXPORT void JNICALL 104Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1check( 105 JNIEnv *env, jobject this, 106 jint widget_type, jint synth_state, jstring detail, 107 jint x, jint y, jint w, jint h) 108{ 109 gtk->gdk_threads_enter(); 110 gtk->paint_check(widget_type, synth_state, getStrFor(env, detail), 111 x, y, w, h); 112 gtk->gdk_threads_leave(); 113} 114 115/* 116 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 117 * Method: native_paint_expander 118 * Signature: (IILjava/lang/String;IIIII)V 119 */ 120JNIEXPORT void JNICALL 121Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1expander( 122 JNIEnv *env, jobject this, 123 jint widget_type, jint state, jstring detail, 124 jint x, jint y, jint w, jint h, jint expander_style) 125{ 126 gtk->gdk_threads_enter(); 127 gtk->paint_expander(widget_type, state, getStrFor(env, detail), 128 x, y, w, h, expander_style); 129 gtk->gdk_threads_leave(); 130} 131 132/* 133 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 134 * Method: native_paint_extension 135 * Signature: (IIILjava/lang/String;IIIII)V 136 */ 137JNIEXPORT void JNICALL 138Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1extension( 139 JNIEnv *env, jobject this, 140 jint widget_type, jint state, jint shadow_type, jstring detail, 141 jint x, jint y, jint w, jint h, jint placement) 142{ 143 gtk->gdk_threads_enter(); 144 gtk->paint_extension(widget_type, state, shadow_type, 145 getStrFor(env, detail), x, y, w, h, placement); 146 gtk->gdk_threads_leave(); 147} 148 149/* 150 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 151 * Method: native_paint_flat_box 152 * Signature: (IIILjava/lang/String;IIII)V 153 */ 154JNIEXPORT void JNICALL 155Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1flat_1box( 156 JNIEnv *env, jobject this, 157 jint widget_type, jint state, jint shadow_type, jstring detail, 158 jint x, jint y, jint w, jint h, jboolean has_focus) 159{ 160 gtk->gdk_threads_enter(); 161 gtk->paint_flat_box(widget_type, state, shadow_type, 162 getStrFor(env, detail), x, y, w, h, has_focus); 163 gtk->gdk_threads_leave(); 164} 165 166/* 167 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 168 * Method: native_paint_focus 169 * Signature: (IILjava/lang/String;IIII)V 170 */ 171JNIEXPORT void JNICALL 172Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1focus( 173 JNIEnv *env, jobject this, 174 jint widget_type, jint state, jstring detail, 175 jint x, jint y, jint w, jint h) 176{ 177 gtk->gdk_threads_enter(); 178 gtk->paint_focus(widget_type, state, getStrFor(env, detail), 179 x, y, w, h); 180 gtk->gdk_threads_leave(); 181} 182 183/* 184 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 185 * Method: native_paint_handle 186 * Signature: (IIILjava/lang/String;IIIII)V 187 */ 188JNIEXPORT void JNICALL 189Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1handle( 190 JNIEnv *env, jobject this, 191 jint widget_type, jint state, jint shadow_type, jstring detail, 192 jint x, jint y, jint w, jint h, jint orientation) 193{ 194 gtk->gdk_threads_enter(); 195 gtk->paint_handle(widget_type, state, shadow_type, getStrFor(env, detail), 196 x, y, w, h, orientation); 197 gtk->gdk_threads_leave(); 198} 199 200/* 201 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 202 * Method: native_paint_hline 203 * Signature: (IILjava/lang/String;IIII)V 204 */ 205JNIEXPORT void JNICALL 206Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1hline( 207 JNIEnv *env, jobject this, 208 jint widget_type, jint state, jstring detail, 209 jint x, jint y, jint w, jint h) 210{ 211 gtk->gdk_threads_enter(); 212 gtk->paint_hline(widget_type, state, getStrFor(env, detail), 213 x, y, w, h); 214 gtk->gdk_threads_leave(); 215} 216 217/* 218 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 219 * Method: native_paint_option 220 * Signature: (IILjava/lang/String;IIII)V 221 */ 222JNIEXPORT void JNICALL 223Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1option( 224 JNIEnv *env, jobject this, 225 jint widget_type, jint synth_state, jstring detail, 226 jint x, jint y, jint w, jint h) 227{ 228 gtk->gdk_threads_enter(); 229 gtk->paint_option(widget_type, synth_state, getStrFor(env, detail), 230 x, y, w, h); 231 gtk->gdk_threads_leave(); 232} 233 234/* 235 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 236 * Method: native_paint_shadow 237 * Signature: (IIILjava/lang/String;IIIIII)V 238 */ 239JNIEXPORT void JNICALL 240Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1shadow( 241 JNIEnv *env, jobject this, 242 jint widget_type, jint state, jint shadow_type, jstring detail, 243 jint x, jint y, jint w, jint h, 244 jint synth_state, jint dir) 245{ 246 gtk->gdk_threads_enter(); 247 gtk->paint_shadow(widget_type, state, shadow_type, getStrFor(env, detail), 248 x, y, w, h, synth_state, dir); 249 gtk->gdk_threads_leave(); 250} 251 252/* 253 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 254 * Method: native_paint_slider 255 * Signature: (IIILjava/lang/String;IIIII)V 256 */ 257JNIEXPORT void JNICALL 258Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1slider( 259 JNIEnv *env, jobject this, 260 jint widget_type, jint state, jint shadow_type, jstring detail, 261 jint x, jint y, jint w, jint h, jint orientation, jboolean has_focus) 262{ 263 gtk->gdk_threads_enter(); 264 gtk->paint_slider(widget_type, state, shadow_type, getStrFor(env, detail), 265 x, y, w, h, orientation, has_focus); 266 gtk->gdk_threads_leave(); 267} 268 269/* 270 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 271 * Method: native_paint_vline 272 * Signature: (IILjava/lang/String;IIII)V 273 */ 274JNIEXPORT void JNICALL 275Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1vline( 276 JNIEnv *env, jobject this, 277 jint widget_type, jint state, jstring detail, 278 jint x, jint y, jint w, jint h) 279{ 280 gtk->gdk_threads_enter(); 281 gtk->paint_vline(widget_type, state, getStrFor(env, detail), 282 x, y, w, h); 283 gtk->gdk_threads_leave(); 284} 285 286/* 287 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 288 * Method: native_paint_background 289 * Signature: (IIIIII)V 290 */ 291JNIEXPORT void JNICALL 292Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1background( 293 JNIEnv *env, jobject this, jint widget_type, jint state, 294 jint x, jint y, jint w, jint h) 295{ 296 gtk->gdk_threads_enter(); 297 gtk->paint_background(widget_type, state, x, y, w, h); 298 gtk->gdk_threads_leave(); 299} 300 301/* 302 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 303 * Method: nativeStartPainting 304 * Signature: (II)V 305 */ 306JNIEXPORT void JNICALL 307Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeStartPainting( 308 JNIEnv *env, jobject this, jint w, jint h) 309{ 310 gtk->gdk_threads_enter(); 311 gtk->init_painting(env, w, h); 312 gtk->gdk_threads_leave(); 313} 314 315/* 316 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 317 * Method: nativeFinishPainting 318 * Signature: ([III)I 319 */ 320JNIEXPORT jint JNICALL 321Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeFinishPainting( 322 JNIEnv *env, jobject this, jintArray dest, jint width, jint height) 323{ 324 jint transparency; 325 gint *buffer = (gint*) (*env)->GetPrimitiveArrayCritical(env, dest, 0); 326 gtk->gdk_threads_enter(); 327 transparency = gtk->copy_image(buffer, width, height); 328 gtk->gdk_threads_leave(); 329 (*env)->ReleasePrimitiveArrayCritical(env, dest, buffer, 0); 330 return transparency; 331} 332 333/* 334 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 335 * Method: native_switch_theme 336 * Signature: ()V 337 */ 338JNIEXPORT void JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1switch_1theme( 339 JNIEnv *env, jobject this) 340{ 341 // Note that flush_gtk_event_loop takes care of locks (7053002) 342 gtk->gdk_threads_enter(); 343 gtk->flush_event_loop(); 344 gtk->gdk_threads_leave(); 345} 346 347/* 348 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 349 * Method: native_get_gtk_setting 350 * Signature: (I)Ljava/lang/Object; 351 */ 352JNIEXPORT jobject JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1get_1gtk_1setting( 353 JNIEnv *env, jobject this, jint property) 354{ 355 jobject obj; 356 gtk->gdk_threads_enter(); 357 obj = gtk->get_setting(env, property); 358 gtk->gdk_threads_leave(); 359 return obj; 360} 361 362/* 363 * Class: com_sun_java_swing_plaf_gtk_GTKEngine 364 * Method: nativeSetRangeValue 365 * Signature: (IDDDD)V 366 */ 367JNIEXPORT void JNICALL 368Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeSetRangeValue( 369 JNIEnv *env, jobject this, jint widget_type, 370 jdouble value, jdouble min, jdouble max, jdouble visible) 371{ 372 gtk->gdk_threads_enter(); 373 gtk->set_range_value(widget_type, value, min, max, visible); 374 gtk->gdk_threads_leave(); 375} 376