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