value = constructor.newInstance (new Object [] {new Long (handle), Boolean.TRUE});
} catch (Throwable e2) {
SWT.error (SWT.ERROR_NOT_IMPLEMENTED, e2);
}
}
final Frame frame = (Frame) value;
parent.setData(EMBEDDED_FRAME_KEY, frame);
if (Device.DEBUG) {
loadLibrary();
setDebug(frame, true);
}
try {
/* Call registerListeners() to make XEmbed focus traversal work */
Method method = clazz.getMethod("registerListeners", null);
if (method != null) method.invoke(value, null);
} catch (Throwable e) {}
final AWTEventListener awtListener = new AWTEventListener() {
public void eventDispatched(AWTEvent event) {
if (event.getID() == WindowEvent.WINDOW_OPENED) {
final Window window = (Window) event.getSource();
if (window.getParent() == frame) {
parent.getDisplay().asyncExec(new Runnable() {
public void run() {
if (parent.isDisposed()) return;
Shell shell = parent.getShell();
loadLibrary();
long /*int*/ awtHandle = getAWTHandle(window);
if (awtHandle == 0) return;
long /*int*/ xWindow = OS.gdk_x11_drawable_get_xid(OS.GTK_WIDGET_WINDOW(OS.gtk_widget_get_toplevel(shell.handle)));
OS.XSetTransientForHint(OS.gdk_x11_display_get_xdisplay(OS.gdk_display_get_default()), awtHandle, xWindow);
}
});
}
}
}
};
frame.getToolkit().addAWTEventListener(awtListener, AWTEvent.WINDOW_EVENT_MASK);
final Listener shellListener = new Listener () {
public void handleEvent (Event e) {
switch (e.type) {
case SWT.Deiconify:
EventQueue.invokeLater(new Runnable () {
public void run () {
frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_DEICONIFIED));
}
});
break;
case SWT.Iconify:
EventQueue.invokeLater(new Runnable () {
public void run () {
frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ICONIFIED));
}
});
break;
}
}
};
Shell shell = parent.getShell ();
shell.addListener (SWT.Deiconify, shellListener);
shell.addListener (SWT.Iconify, shellListener);
Listener listener = new Listener () {
public void handleEvent (Event e) {
switch (e.type) {
case SWT.Dispose:
Shell shell = parent.getShell ();
shell.removeListener (SWT.Deiconify, shellListener);
shell.removeListener (SWT.Iconify, shellListener);
parent.setVisible(false);
EventQueue.invokeLater(new Runnable () {
public void run () {
frame.getToolkit().removeAWTEventListener(awtListener);
frame.dispose ();
}
});
break;
case SWT.Resize:
if (Library.JAVA_VERSION >= Library.JAVA_VERSION(1, 6, 0)) {
final Rectangle clientArea = parent.getClientArea();
EventQueue.invokeLater(new Runnable () {
public void run () {
frame.setSize (clientArea.width, clientArea.height);
}
});
}
break;
}
}
};
parent.addListener (SWT.Dispose, listener);
parent.addListener (SWT.Resize, listener);
parent.getDisplay().asyncExec(new Runnable() {
public void run () {
if (parent.isDisposed()) return;
final Rectangle clientArea = parent.getClientArea();
EventQueue.invokeLater(new Runnable () {
public void run () {
frame.setSize (clientArea.width, clientArea.height);
frame.validate ();
}
});
}
});
return frame;