Path: blob/master/src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c
41154 views
/*1* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#ifdef HEADLESS26#error This file should not be included in headless library27#endif2829#include "gtk_interface.h"30#include "com_sun_java_swing_plaf_gtk_GTKEngine.h"31#include <jni_util.h>32#include <stdlib.h>33#include <string.h>3435/* Static buffer for conversion from java.lang.String to UTF-8 */36static char conversionBuffer[(CONV_BUFFER_SIZE - 1) * 3 + 1];3738const char *getStrFor(JNIEnv *env, jstring val)39{40int length = (*env)->GetStringLength(env, val);41if (length > CONV_BUFFER_SIZE-1)42{43length = CONV_BUFFER_SIZE-1;44}4546memset(conversionBuffer, 0, sizeof(conversionBuffer));47(*env)->GetStringUTFRegion(env, val, 0, length, conversionBuffer);48return conversionBuffer;49}5051/*52* Class: com_sun_java_swing_plaf_gtk_GTKEngine53* Method: native_paint_arrow54* Signature: (IIILjava/lang/String;IIIII)V55*/56JNIEXPORT void JNICALL57Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1arrow(58JNIEnv *env, jobject this,59jint widget_type, jint state, jint shadow_type, jstring detail,60jint x, jint y, jint w, jint h, jint arrow_type)61{62gtk->gdk_threads_enter();63gtk->paint_arrow(widget_type, state, shadow_type, getStrFor(env, detail),64x, y, w, h, arrow_type, TRUE);65gtk->gdk_threads_leave();66}6768/*69* Class: com_sun_java_swing_plaf_gtk_GTKEngine70* Method: native_paint_box71* Signature: (IIILjava/lang/String;IIIIII)V72*/73JNIEXPORT void JNICALL74Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1box(75JNIEnv *env, jobject this,76jint widget_type, jint state, jint shadow_type, jstring detail,77jint x, jint y, jint w, jint h,78jint synth_state, jint dir)79{80gtk->gdk_threads_enter();81gtk->paint_box(widget_type, state, shadow_type, getStrFor(env, detail),82x, y, w, h, synth_state, dir);83gtk->gdk_threads_leave();84}8586/*87* Class: com_sun_java_swing_plaf_gtk_GTKEngine88* Method: native_paint_box_gap89* Signature: (IIILjava/lang/String;IIIIIII)V90*/91JNIEXPORT void JNICALL92Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1box_1gap(93JNIEnv *env, jobject this,94jint widget_type, jint state, jint shadow_type, jstring detail,95jint x, jint y, jint w, jint h,96jint gap_side, jint gap_x, jint gap_w)97{98gtk->gdk_threads_enter();99gtk->paint_box_gap(widget_type, state, shadow_type, getStrFor(env, detail),100x, y, w, h, gap_side, gap_x, gap_w);101gtk->gdk_threads_leave();102}103104/*105* Class: com_sun_java_swing_plaf_gtk_GTKEngine106* Method: native_paint_check107* Signature: (IILjava/lang/String;IIII)V108*/109JNIEXPORT void JNICALL110Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1check(111JNIEnv *env, jobject this,112jint widget_type, jint synth_state, jstring detail,113jint x, jint y, jint w, jint h)114{115gtk->gdk_threads_enter();116gtk->paint_check(widget_type, synth_state, getStrFor(env, detail),117x, y, w, h);118gtk->gdk_threads_leave();119}120121/*122* Class: com_sun_java_swing_plaf_gtk_GTKEngine123* Method: native_paint_expander124* Signature: (IILjava/lang/String;IIIII)V125*/126JNIEXPORT void JNICALL127Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1expander(128JNIEnv *env, jobject this,129jint widget_type, jint state, jstring detail,130jint x, jint y, jint w, jint h, jint expander_style)131{132gtk->gdk_threads_enter();133gtk->paint_expander(widget_type, state, getStrFor(env, detail),134x, y, w, h, expander_style);135gtk->gdk_threads_leave();136}137138/*139* Class: com_sun_java_swing_plaf_gtk_GTKEngine140* Method: native_paint_extension141* Signature: (IIILjava/lang/String;IIIII)V142*/143JNIEXPORT void JNICALL144Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1extension(145JNIEnv *env, jobject this,146jint widget_type, jint state, jint shadow_type, jstring detail,147jint x, jint y, jint w, jint h, jint placement)148{149gtk->gdk_threads_enter();150gtk->paint_extension(widget_type, state, shadow_type,151getStrFor(env, detail), x, y, w, h, placement);152gtk->gdk_threads_leave();153}154155/*156* Class: com_sun_java_swing_plaf_gtk_GTKEngine157* Method: native_paint_flat_box158* Signature: (IIILjava/lang/String;IIII)V159*/160JNIEXPORT void JNICALL161Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1flat_1box(162JNIEnv *env, jobject this,163jint widget_type, jint state, jint shadow_type, jstring detail,164jint x, jint y, jint w, jint h, jboolean has_focus)165{166gtk->gdk_threads_enter();167gtk->paint_flat_box(widget_type, state, shadow_type,168getStrFor(env, detail), x, y, w, h, has_focus);169gtk->gdk_threads_leave();170}171172/*173* Class: com_sun_java_swing_plaf_gtk_GTKEngine174* Method: native_paint_focus175* Signature: (IILjava/lang/String;IIII)V176*/177JNIEXPORT void JNICALL178Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1focus(179JNIEnv *env, jobject this,180jint widget_type, jint state, jstring detail,181jint x, jint y, jint w, jint h)182{183gtk->gdk_threads_enter();184gtk->paint_focus(widget_type, state, getStrFor(env, detail),185x, y, w, h);186gtk->gdk_threads_leave();187}188189/*190* Class: com_sun_java_swing_plaf_gtk_GTKEngine191* Method: native_paint_handle192* Signature: (IIILjava/lang/String;IIIII)V193*/194JNIEXPORT void JNICALL195Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1handle(196JNIEnv *env, jobject this,197jint widget_type, jint state, jint shadow_type, jstring detail,198jint x, jint y, jint w, jint h, jint orientation)199{200gtk->gdk_threads_enter();201gtk->paint_handle(widget_type, state, shadow_type, getStrFor(env, detail),202x, y, w, h, orientation);203gtk->gdk_threads_leave();204}205206/*207* Class: com_sun_java_swing_plaf_gtk_GTKEngine208* Method: native_paint_hline209* Signature: (IILjava/lang/String;IIII)V210*/211JNIEXPORT void JNICALL212Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1hline(213JNIEnv *env, jobject this,214jint widget_type, jint state, jstring detail,215jint x, jint y, jint w, jint h)216{217gtk->gdk_threads_enter();218gtk->paint_hline(widget_type, state, getStrFor(env, detail),219x, y, w, h);220gtk->gdk_threads_leave();221}222223/*224* Class: com_sun_java_swing_plaf_gtk_GTKEngine225* Method: native_paint_option226* Signature: (IILjava/lang/String;IIII)V227*/228JNIEXPORT void JNICALL229Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1option(230JNIEnv *env, jobject this,231jint widget_type, jint synth_state, jstring detail,232jint x, jint y, jint w, jint h)233{234gtk->gdk_threads_enter();235gtk->paint_option(widget_type, synth_state, getStrFor(env, detail),236x, y, w, h);237gtk->gdk_threads_leave();238}239240/*241* Class: com_sun_java_swing_plaf_gtk_GTKEngine242* Method: native_paint_shadow243* Signature: (IIILjava/lang/String;IIIIII)V244*/245JNIEXPORT void JNICALL246Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1shadow(247JNIEnv *env, jobject this,248jint widget_type, jint state, jint shadow_type, jstring detail,249jint x, jint y, jint w, jint h,250jint synth_state, jint dir)251{252gtk->gdk_threads_enter();253gtk->paint_shadow(widget_type, state, shadow_type, getStrFor(env, detail),254x, y, w, h, synth_state, dir);255gtk->gdk_threads_leave();256}257258/*259* Class: com_sun_java_swing_plaf_gtk_GTKEngine260* Method: native_paint_slider261* Signature: (IIILjava/lang/String;IIIII)V262*/263JNIEXPORT void JNICALL264Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1slider(265JNIEnv *env, jobject this,266jint widget_type, jint state, jint shadow_type, jstring detail,267jint x, jint y, jint w, jint h, jint orientation, jboolean has_focus)268{269gtk->gdk_threads_enter();270gtk->paint_slider(widget_type, state, shadow_type, getStrFor(env, detail),271x, y, w, h, orientation, has_focus);272gtk->gdk_threads_leave();273}274275/*276* Class: com_sun_java_swing_plaf_gtk_GTKEngine277* Method: native_paint_vline278* Signature: (IILjava/lang/String;IIII)V279*/280JNIEXPORT void JNICALL281Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1vline(282JNIEnv *env, jobject this,283jint widget_type, jint state, jstring detail,284jint x, jint y, jint w, jint h)285{286gtk->gdk_threads_enter();287gtk->paint_vline(widget_type, state, getStrFor(env, detail),288x, y, w, h);289gtk->gdk_threads_leave();290}291292/*293* Class: com_sun_java_swing_plaf_gtk_GTKEngine294* Method: native_paint_background295* Signature: (IIIIII)V296*/297JNIEXPORT void JNICALL298Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1paint_1background(299JNIEnv *env, jobject this, jint widget_type, jint state,300jint x, jint y, jint w, jint h)301{302gtk->gdk_threads_enter();303gtk->paint_background(widget_type, state, x, y, w, h);304gtk->gdk_threads_leave();305}306307/*308* Class: com_sun_java_swing_plaf_gtk_GTKEngine309* Method: nativeStartPainting310* Signature: (II)V311*/312JNIEXPORT void JNICALL313Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeStartPainting(314JNIEnv *env, jobject this, jint w, jint h)315{316if (w > 0x7FFF || h > 0x7FFF || (uintptr_t)4 * w * h > 0x7FFFFFFFL) {317// Same limitation as in X11SurfaceData.c318JNU_ThrowOutOfMemoryError(env, "Can't create offscreen surface");319return;320}321gtk->gdk_threads_enter();322gtk->init_painting(env, w, h);323gtk->gdk_threads_leave();324}325326/*327* Class: com_sun_java_swing_plaf_gtk_GTKEngine328* Method: nativeFinishPainting329* Signature: ([III)I330*/331JNIEXPORT jint JNICALL332Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeFinishPainting(333JNIEnv *env, jobject this, jintArray dest, jint width, jint height)334{335jint transparency;336gint *buffer = (gint*) (*env)->GetPrimitiveArrayCritical(env, dest, 0);337gtk->gdk_threads_enter();338transparency = gtk->copy_image(buffer, width, height);339gtk->gdk_threads_leave();340(*env)->ReleasePrimitiveArrayCritical(env, dest, buffer, 0);341return transparency;342}343344/*345* Class: com_sun_java_swing_plaf_gtk_GTKEngine346* Method: native_switch_theme347* Signature: ()V348*/349JNIEXPORT void JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1switch_1theme(350JNIEnv *env, jobject this)351{352// Note that gtk->flush_event_loop takes care of locks (7053002), gdk_threads_enter/gdk_threads_leave should not be used.353gtk->flush_event_loop();354}355356/*357* Class: com_sun_java_swing_plaf_gtk_GTKEngine358* Method: native_get_gtk_setting359* Signature: (I)Ljava/lang/Object;360*/361JNIEXPORT jobject JNICALL Java_com_sun_java_swing_plaf_gtk_GTKEngine_native_1get_1gtk_1setting(362JNIEnv *env, jobject this, jint property)363{364jobject obj;365gtk->gdk_threads_enter();366obj = gtk->get_setting(env, property);367gtk->gdk_threads_leave();368return obj;369}370371/*372* Class: com_sun_java_swing_plaf_gtk_GTKEngine373* Method: nativeSetRangeValue374* Signature: (IDDDD)V375*/376JNIEXPORT void JNICALL377Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeSetRangeValue(378JNIEnv *env, jobject this, jint widget_type,379jdouble value, jdouble min, jdouble max, jdouble visible)380{381gtk->gdk_threads_enter();382gtk->set_range_value(widget_type, value, min, max, visible);383gtk->gdk_threads_leave();384}385386387