27-Apr megacz JSObject.java: added extra debugging info
+27-Apr megacz XWT.java, Platform.java, Main.java, Java2.java,
+ Win32.java, Win32.cc, faq.html: added support for
+ xwt.newBrowserWindow()
public void paint(Graphics g) { } // do-nothing method to avoid repaints
public void update(Graphics g) { } // do-nothing method, to avoid repaints
+ public static Applet applet = null;
+
/** applet entry point */
public void init() {
if ("true".equals(getParameter("showRenders"))) showRenders = true;
if ("true".equals(getParameter("verbose"))) Log.verbose = true;
- main(new String[] { getParameter("xwar-url"), "main" });
+ applet = this;
+ main(new String[] { getParameter("initial-xwar-url"), "main" });
}
/** common entry point */
protected boolean _needsAutoClick() { return false; }
+ protected void _newBrowserWindow(String url) {
+ if (Log.on) Log.log(this, "Platform " + platform.getClass().getName() + " cannot open browser windows");
+ return;
+ }
+
// Static methods -- thunk to the instance /////////////////////////////////////////////////////////////////////////
/** if true, org.xwt.Surface should generate Click messages automatically when a Release happens after a Press and the mouse has not moved much */
/** creates and returns a picture */
public static Picture createPicture(ImageDecoder i) { return platform._createPicture(i.getData(), i.getWidth(), i.getHeight()); }
+ /** creates and returns a picture */
+ public static void newBrowserWindow(String url) {
+ if (!(url.startsWith("https://") || url.startsWith("http://") || url.startsWith("ftp://") || url.startsWith("mailto:"))) {
+ if (Log.on) Log.log(Platform.class, "xwt.newBrowserWindow() only supports http and https urls");
+ return;
+ }
+ platform._newBrowserWindow(url);
+ }
+
/** quits XWT */
public static void exit() {
Log.log(Platform.class, "exiting via Platform.exit()");
else if (name.equals("regexp")) return regexp;
else if (name.equals("sleep")) return sleep;
else if (name.equals("yield")) return yield;
+ else if (name.equals("newBrowserWindow")) return newBrowserWindow;
else if (name.equals("textwidth")) return textwidth;
else if (name.equals("textheight")) return textheight;
else if (name.equals("newBox")) return newBox;
public Scriptable construct(Context cx, Scriptable scope, java.lang.Object[] args) { return null; }
}
+ private static final JSFunction newBrowserWindow = new JSFunction() {
+ public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+ if (args.length != 1 || args[0] == null) return null;
+ Platform.newBrowserWindow(args[0].toString());
+ return null;
+ }
+ };
+
private static final JSFunction yield = new JSFunction() {
public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
sleep.call(cx, null, null, null);
}
protected String getDescriptiveName() { return "Java 1.2+ JVM"; }
+
+ protected void _newBrowserWindow(String url) {
+ if (Main.applet == null) {
+ if (Log.on) Log.log(this, "Main.applet is null; cannot invoke showDocument()");
+ return;
+ }
+ if (Log.on) Log.log(this, "asking browser to show URL " + url);
+ try {
+ Main.applet.getAppletContext().showDocument(new URL(url), "_blank");
+ } catch (MalformedURLException e) {
+ if (Log.on) Log.log(this, e);
+ }
+ }
+
+ /** used to notify the user of very serious failures; usually used when logging is not working or unavailable */
+ protected void _criticalAbort(String message) {
+ if (Log.on) Log.log(this, message);
+ new Semaphore().block();
+ }
+
}
return size.cx;
}
+jboolean org::xwt::plat::Win32::_newBrowserWindow_(jstring url) {
+
+ int len = min(2048, JvGetStringUTFLength(url));
+ char buf[len + 1];
+ JvGetStringUTFRegion(url, 0, len, buf);
+ buf[len] = '\0';
+
+ SHELLEXECUTEINFO ei;
+ memset(&ei, 0, sizeof(ei));
+ ei.cbSize = sizeof(ei);
+ ei.lpVerb = "open";
+ ei.lpFile = buf;
+ ei.fMask = SEE_MASK_NOCLOSEPROCESS;
+ ei.nShow = SW_SHOWDEFAULT;
+ return (ShellExecuteEx(&ei) == 0);
+
+}
// Win32DoubleBuffer /////////////////////////////////////////////////////////////////////////
protected native String _getClipBoard();
protected native void _setClipBoard(String s);
+ protected native boolean _newBrowserWindow_(String url);
+ protected void _newBrowserWindow(String url) {
+ if (!_newBrowserWindow_(url))
+ if (Log.on) Log.log(this, "ShellExecuteEx() failed trying to open url " + url);
+ }
// Win32Surface ////////////////////////////////////////////////////////////////////////////