Skip to content

Commit e5414eb

Browse files
committed
Embed AWT into SWT for Windows (GTK)
Fix to generate swt-awt-gtk-4966r2.dll on Windows, which allows to run SWT snippets 154, 155, 300, and 361 that use the SWT.EMBEDDED flag. The approach followed includes creating a Windows-specific swt_awt_win32.c file, and the respective object file is used in make_win32.mak to build the SWT-AWT binaries.
1 parent 3d33164 commit e5414eb

3 files changed

Lines changed: 109 additions & 5 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2000, 2016 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
15+
#include "swt.h"
16+
#include "jawt_md.h"
17+
#include <windows.h>
18+
19+
#define SWT_AWT_NATIVE(func) Java_org_eclipse_swt_awt_SWT_1AWT_##func
20+
21+
#ifndef NO_getAWTHandle
22+
JNIEXPORT jlong JNICALL SWT_AWT_NATIVE(getAWTHandle)
23+
(JNIEnv *env, jclass that, jobject canvas) {
24+
JAWT awt;
25+
JAWT_DrawingSurface* ds;
26+
JAWT_DrawingSurfaceInfo* dsi;
27+
JAWT_Win32DrawingSurfaceInfo* dsi_win;
28+
jlong result = 0;
29+
jint lock;
30+
31+
awt.version = JAWT_VERSION_1_4;
32+
if (JAWT_GetAWT(env, &awt) != 0) {
33+
ds = awt.GetDrawingSurface(env, canvas);
34+
if (ds != NULL) {
35+
lock = ds->Lock(ds);
36+
if ((lock & JAWT_LOCK_ERROR) == 0) {
37+
dsi = ds->GetDrawingSurfaceInfo(ds);
38+
dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
39+
result = (jlong)dsi_win->hwnd;
40+
ds->FreeDrawingSurfaceInfo(dsi);
41+
ds->Unlock(ds);
42+
}
43+
}
44+
awt.FreeDrawingSurface(ds);
45+
}
46+
return result;
47+
}
48+
#endif
49+
50+
#ifndef NO_setDebug
51+
JNIEXPORT void JNICALL SWT_AWT_NATIVE(setDebug)
52+
(JNIEnv *env, jclass that, jobject frame, jboolean debug) {
53+
// Debug function not applicable on Windows, can be left empty or implement logging
54+
}
55+
#endif
56+
57+
#ifndef NO_initFrame
58+
JNIEXPORT jobject JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_initFrame
59+
(JNIEnv *env, jclass that, jlong handle) {
60+
jobject object;
61+
jmethodID constructor;
62+
63+
jclass cls = (*env)->FindClass(env, "sun/awt/windows/WEmbeddedFrame");
64+
if (NULL == cls) return NULL;
65+
constructor = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
66+
object = (*env)->NewObject(env, cls, constructor, handle, JNI_TRUE);
67+
return object;
68+
}
69+
#endif
70+
71+
#ifndef NO_validateWithBounds
72+
JNIEXPORT void JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_validateWithBounds
73+
(JNIEnv *env, jclass that, jobject frame, jint x, jint y, jint w, jint h) {
74+
jclass cls = (*env)->FindClass(env, "sun/awt/windows/WEmbeddedFrame");
75+
if (NULL == cls) return;
76+
jmethodID midInit = (*env)->GetMethodID(env, cls, "validateWithBounds", "(IIII)V");
77+
(*env)->CallVoidMethod(env, frame, midInit, x, y, w, h);
78+
}
79+
#endif
80+
81+
#ifndef NO_synthesizeWindowActivation
82+
JNIEXPORT void JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_synthesizeWindowActivation
83+
(JNIEnv *env, jclass that, jobject frame, jboolean doActivate) {
84+
jclass cls = (*env)->FindClass(env, "sun/awt/windows/WEmbeddedFrame");
85+
if (NULL == cls) return;
86+
jmethodID midInit = (*env)->GetMethodID(env, cls, "synthesizeWindowActivation", "(Z)V");
87+
(*env)->CallVoidMethod(env, frame, midInit, doActivate);
88+
}
89+
#endif
90+
91+
#ifndef NO_registerListeners
92+
JNIEXPORT void JNICALL Java_org_eclipse_swt_awt_SWT_1AWT_registerListeners
93+
(JNIEnv *env, jclass that, jobject frame) {
94+
jclass cls = (*env)->FindClass(env, "sun/awt/windows/WEmbeddedFrame");
95+
if (NULL == cls) return;
96+
jmethodID midInit = (*env)->GetMethodID(env, cls, "registerListeners", "()V");
97+
(*env)->CallVoidMethod(env, frame, midInit);
98+
}
99+
#endif

bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ public static Frame getFrame (Composite parent) {
145145
* @since 3.0
146146
*/
147147
public static Frame new_Frame (final Composite parent) {
148-
if (OS.IsWin32) SWT.error (SWT.ERROR_NOT_IMPLEMENTED);
149148
if (parent == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
150149
if ((parent.getStyle () & SWT.EMBEDDED) == 0) {
151150
SWT.error (SWT.ERROR_INVALID_ARGUMENT);
@@ -156,7 +155,13 @@ public static Frame new_Frame (final Composite parent) {
156155
* and other JREs take a long. To handle this binary incompatibility, use
157156
* reflection to create the embedded frame.
158157
*/
159-
String className = embeddedFrameClass != null ? embeddedFrameClass : "sun.awt.X11.XEmbeddedFrame";
158+
String osName = System.getProperty ("os.name");
159+
String className=null;
160+
if (osName.equals ("Linux")) {
161+
className = embeddedFrameClass != null ? embeddedFrameClass : "sun.awt.X11.XEmbeddedFrame";
162+
}else if (osName.startsWith("Windows")) {
163+
className=embeddedFrameClass != null ? embeddedFrameClass : "sun.awt.windows.WEmbeddedFrame";
164+
}
160165
try {
161166
if (embeddedFrameClass != null) {
162167
Class.forName(className);

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_win32.mak

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ ATKCFLAGS = `pkg-config --cflags atk gtk+-$(GTK_VERSION)`
7575
endif
7676

7777
AWT_LFLAGS = -shared ${SWT_LFLAGS}
78-
AWT_LIBS = -L$(AWT_LIB_PATH) -ljawt
78+
AWT_LIBS = -L"$(AWT_LIB_PATH)" -ljawt
7979

8080
ATKLIBS = `pkg-config --libs atk` -latk-1.0
8181

@@ -91,7 +91,7 @@ GLXLIBS = -lGL -lGLU -lm
9191
# endif
9292

9393
SWT_OBJECTS = swt.o c.o c_stats.o callback.o
94-
AWT_OBJECTS = swt_awt.o
94+
AWT_OBJECTS = swt_awt_win32.o
9595
ifeq ($(GTK_VERSION), 4.0)
9696
GTKX_OBJECTS = gtk4.o gtk4_stats.o gtk4_structs.o
9797
else
@@ -186,7 +186,7 @@ cairo_stats.o: cairo_stats.c cairo_structs.h cairo.h cairo_stats.h swt.h
186186
#
187187
# AWT lib
188188
#
189-
# make_awt:$(AWT_LIB) # TODO [win32] solve gtk/x11 vs gtk/win32 native integration
189+
make_awt:$(AWT_LIB)
190190
make_awt:
191191

192192
$(AWT_LIB): $(AWT_OBJECTS)

0 commit comments

Comments
 (0)