Skip to content

Commit bf0c317

Browse files
committed
WIP - [GTK4] support Clipboard
1 parent 43f54cc commit bf0c317

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3027
-398
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:aea877ec9eff47e0fff89de92ef3383f62e188590e7a037b981631c92aaea752
3-
size 39168
2+
oid sha256:d3e710c0f50693f9912c38324a13b70b0d473fbd5e0c82a14d8799a4844b628e
3+
size 43408
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:616e9e63473d7281ac7b995c423cf44f8665fbcbbba0b1048170a0cf7eb8541b
3-
size 14112
2+
oid sha256:83f2ee183e227a072fa1994d35eab37c8d70b18d9ee65abafb62d67f7b9328e8
3+
size 14408
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:f79f0ab0bbecd950624dc6c37e242073aa284cec62ffa310b336912b111991b5
3-
size 47952
2+
oid sha256:81b3d20a387e9bfd04a6730540be0667087602b095b508f410d99d2a8de69fec
3+
size 48096
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:998ff6f410ef05b30b8e57a05cfea2514730febba0e0114348a284d36965976c
3-
size 14352
2+
oid sha256:c3576356f9bacd31240de1514a181b5f8c02681c343bf116a31dad74818076e8
3+
size 14496
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:da7a80e2c4da658f6e3e1495dbcc39a96d3a1a903ce826b9d187d4b5fc0f7c39
3-
size 610344
2+
oid sha256:af39a1153d68fbc8b47114f0d2d47f39263a3e63b4d96c04f1cef01c500b8c98
3+
size 626888
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:a254c32294752ffe3d29a8423fa6d1ebb1b15a85572af78d738b2ef71b9d6648
3-
size 458536
2+
oid sha256:35b2f1b3ff7bef4242e418d89acd2074ccfc9f538bc6570b850d7b9aa235870b
3+
size 491560
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:6dc6f3da6a4beaf4b5dcc2bc84fd732b974d649499ff51d1eaad0065c2c78758
3-
size 399904
2+
oid sha256:0a816c10969b8171abcc21499ad7b8459bc2375c10b47d4f22b4e43a0fc005e8
3+
size 437320
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:31eb921f147c298be57a61f1df2b92a5116be425d774f0a0b2a3b2ff1dba3b3a
3-
size 59344
2+
oid sha256:473ec7b9c8a932279774704b90f8330f7ef389e5ac78691207908916578d057a
3+
size 59496

bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/ASTType.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ public String getTypeSignature2() {
148148
if (name.equals("Ljava/lang/String;")) return "jstring";
149149
if (name.equals("Ljava/lang/Class;")) return "jclass";
150150
if (isArray()) {
151-
return getComponentType().getTypeSignature2() + "Array";
151+
if (getComponentType().isPrimitive()) {
152+
return getComponentType().getTypeSignature2() + "Array";
153+
}
154+
return "jobjectArray";
152155
}
153156
return "jobject";
154157
}

bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/NativesGenerator.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,57 @@ public void generate(JNIClass clazz) {
7777
sort(methods);
7878
generateNativeMacro(clazz);
7979
generateWarningSettings();
80+
generateStaticMethods();
8081
generateExcludes(methods);
8182
generate(methods);
8283
}
84+
private void generateStaticMethods() {
85+
if (!getOutputName().equals("gtk4")) {
86+
return;
87+
}
88+
89+
outputln("""
90+
static char **
91+
getArrayOfStringsUTF(JNIEnv *env, jobjectArray javaArray) {
92+
jsize length = (*env)->GetArrayLength(env, javaArray);
93+
94+
char **cStrings = (char **)malloc((length + 1) * sizeof(char*));
95+
if (!cStrings) {
96+
return NULL;
97+
}
98+
99+
for (jsize i = 0; i < length; i++) {
100+
jstring jstr = (jstring)(*env)->GetObjectArrayElement(env, javaArray, i);
101+
if (jstr) {
102+
const char *utfStr = (*env)->GetStringUTFChars(env, jstr, 0);
103+
104+
cStrings[i] = strdup(utfStr);
105+
106+
(*env)->ReleaseStringUTFChars(env, jstr, utfStr);
107+
(*env)->DeleteLocalRef(env, jstr);
108+
} else {
109+
cStrings[i] = NULL;
110+
}
111+
}
112+
113+
cStrings[length] = NULL;
114+
return cStrings;
115+
}
116+
117+
static void
118+
releaseArrayOfStringsUTF(JNIEnv *env, jobjectArray javaArray, char **cStrings) {
119+
jsize length = (*env)->GetArrayLength(env, javaArray);
120+
121+
for (jsize i = 0; i < length; i++) {
122+
if (cStrings[i]) {
123+
free(cStrings[i]);
124+
}
125+
}
126+
free(cStrings);
127+
}
128+
129+
""");
130+
}
83131

84132
public void generate(JNIMethod[] methods) {
85133
sort(methods);
@@ -299,6 +347,14 @@ boolean generateGetParameter(JNIParameter param, boolean critical, int indent) {
299347
output(iStr);
300348
output(", NULL)");
301349
}
350+
} else if (componentType.isType("java.lang.String")) {
351+
if (param.getFlag(FLAG_UNICODE)) {
352+
throw new Error("not done");
353+
}
354+
355+
output("getArrayOfStringsUTF(env, arg");
356+
output(iStr);
357+
output(")");
302358
} else {
303359
throw new Error("not done");
304360
}
@@ -381,6 +437,16 @@ void generateSetParameter(JNIParameter param, boolean critical) {
381437
output("0");
382438
}
383439
output(");");
440+
} else if (componentType.isType("java.lang.String")) {
441+
if (param.getFlag(FLAG_UNICODE)) {
442+
throw new Error("not done");
443+
}
444+
445+
output("releaseArrayOfStringsUTF(env, arg");
446+
output(iStr);
447+
output(", lparg");
448+
output(iStr);
449+
output(");");
384450
} else {
385451
throw new Error("not done");
386452
}
@@ -452,6 +518,12 @@ boolean generateLocalVars(JNIParameter[] params, JNIType returnType) {
452518
output(componentType.getTypeSignature2());
453519
output(" *lparg" + i);
454520
output("=NULL;");
521+
} else if (componentType.isType("java.lang.String")) {
522+
if (param.getFlag(FLAG_UNICODE)) {
523+
output("jchar **lparg" + i + "=NULL");
524+
} else {
525+
output("char **lparg" + i+ "=NULL");
526+
}
455527
} else {
456528
throw new Error("not done");
457529
}

0 commit comments

Comments
 (0)