X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FPOSIX.java;h=fd1ebef44858f77558bad0044432ac41aa07d2d3;hb=93224727752b3da9a70bacd473c5f961efb3a297;hp=f8766ba90f89194a646733fb9193b70e552607c6;hpb=8b473c168f56738abd57a883c353007fda6a24cf;p=org.ibex.core.git diff --git a/src/org/xwt/plat/POSIX.java b/src/org/xwt/plat/POSIX.java index f8766ba..fd1ebef 100644 --- a/src/org/xwt/plat/POSIX.java +++ b/src/org/xwt/plat/POSIX.java @@ -1,114 +1,27 @@ // Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL] package org.xwt.plat; -import java.awt.*; -import java.awt.image.*; import gnu.gcj.RawData; import java.net.*; import java.lang.reflect.*; import java.io.*; import java.util.*; -import java.awt.peer.*; import org.xwt.util.*; import org.xwt.*; -/** Platform implementation for POSIX compliant operating systems with an X11 Server */ +/** Platform implementation for POSIX compliant operating systems */ public class POSIX extends GCJ { - // Static Data /////////////////////////////////////////////////////////// - - /** - * When the user reads from the clipboard, the main thread blocks - * on this semaphore until we get an X11 SelectionNotify. Crude, - * but effective. We know that only one thread will ever block on - * this, since only one thread can ever be running JavaScript. - */ - public static Semaphore waiting_for_selection_event = new Semaphore(); - - /** our local (in-process) copy of the clipboard */ - public static String clipboard = null; - - /** map from Window's (casted to jlong, wrapped in java.lang.Long) to X11Surface objects */ - public static Hashtable windowToSurfaceMap = new Hashtable(); - - // General Methods /////////////////////////////////////////////////////// - protected String _getAltKeyName() { return System.getProperty("os.name", "").indexOf("SunOS") != -1 ? "Meta" : "Alt"; } - protected String[] _listFonts() { return fontList; } protected String getDescriptiveName() { return "GCJ Linux Binary"; } - protected Picture _createPicture(int[] data, int w, int h) { return new POSIX.X11Picture(data, w, h); } - protected DoubleBuffer _createDoubleBuffer(int w, int h, Surface owner) { return new POSIX.X11DoubleBuffer(w, h); } - protected Surface _createSurface(Box b, boolean framed) { return new X11Surface(b, framed); } - protected boolean _needsAutoClick() { return true; } - protected native int _getScreenWidth(); - protected native int _getScreenHeight(); - protected native String _getClipBoard(); - protected native void _setClipBoard(String s); - protected native int _stringWidth(String font, String text); - protected native int _getMaxAscent(String font); - protected native int _getMaxDescent(String font); - protected boolean _needsAutoDoubleClick() { return true; } - protected native void eventThread(); - private native void natInit(); - - /** returns the $BROWSER environment variable, since System.getEnv() is useless */ - private static native String getEnv(String key); + /** returns the value of the environment variable key, or null if no such key exists */ + protected native String _getEnv(String key); + /** spawns a process which is immune to SIGHUP */ private static native void spawnChildProcess(String[] command); - protected synchronized HTTP.ProxyInfo _detectProxy() { - - HTTP.ProxyInfo ret = new HTTP.ProxyInfo(); - - ret.httpProxyHost = getEnv("http_proxy"); - if (ret.httpProxyHost != null) { - if (ret.httpProxyHost.startsWith("http://")) ret.httpProxyHost = ret.httpProxyHost.substring(7); - if (ret.httpProxyHost.endsWith("/")) ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.length() - 1); - if (ret.httpProxyHost.indexOf(':') != -1) { - ret.httpProxyPort = Integer.parseInt(ret.httpProxyHost.substring(ret.httpProxyHost.indexOf(':') + 1)); - ret.httpProxyHost = ret.httpProxyHost.substring(0, ret.httpProxyHost.indexOf(':')); - } else { - ret.httpProxyPort = 80; - } - } - - ret.httpsProxyHost = getEnv("https_proxy"); - if (ret.httpsProxyHost != null) { - if (ret.httpsProxyHost.startsWith("https://")) ret.httpsProxyHost = ret.httpsProxyHost.substring(7); - if (ret.httpsProxyHost.endsWith("/")) ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.length() - 1); - if (ret.httpsProxyHost.indexOf(':') != -1) { - ret.httpsProxyPort = Integer.parseInt(ret.httpsProxyHost.substring(ret.httpsProxyHost.indexOf(':') + 1)); - ret.httpsProxyHost = ret.httpsProxyHost.substring(0, ret.httpsProxyHost.indexOf(':')); - } else { - ret.httpsProxyPort = 80; - } - } - - ret.socksProxyHost = getEnv("socks_proxy"); - if (ret.socksProxyHost != null) { - if (ret.socksProxyHost.startsWith("socks://")) ret.socksProxyHost = ret.socksProxyHost.substring(7); - if (ret.socksProxyHost.endsWith("/")) ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.length() - 1); - if (ret.socksProxyHost.indexOf(':') != -1) { - ret.socksProxyPort = Integer.parseInt(ret.socksProxyHost.substring(ret.socksProxyHost.indexOf(':') + 1)); - ret.socksProxyHost = ret.socksProxyHost.substring(0, ret.socksProxyHost.indexOf(':')); - } else { - ret.socksProxyPort = 80; - } - } - - String noproxy = getEnv("no_proxy"); - if (noproxy != null) { - StringTokenizer st = new StringTokenizer(noproxy, ","); - ret.excluded = new String[st.countTokens()]; - for(int i=0; st.hasMoreTokens(); i++) ret.excluded[i] = st.nextToken(); - } - - if (ret.httpProxyHost == null && ret.socksProxyHost == null) return null; - return ret; - } - protected void _newBrowserWindow(String url) { String browserString = getEnv("BROWSER"); if (browserString == null) { @@ -123,300 +36,13 @@ public class POSIX extends GCJ { StringTokenizer st = new StringTokenizer(browserString, " "); String[] cmd = new String[st.countTokens()]; - for(int i=0; st.hasMoreTokens(); i++) { - cmd[i] = st.nextToken(); - System.out.println(i + ":" + cmd[i]); - } + for(int i=0; st.hasMoreTokens(); i++) cmd[i] = st.nextToken(); spawnChildProcess(cmd); } public POSIX() { } - public void init() { - natInit(); - (new Thread() { public void run() { eventThread(); } }).start(); - initFonts(); - } - - // X11Surface ///////////////////////////////////////////////////// - - /** Implements a Surface as an X11 Window */ - public static class X11Surface extends Surface { - - gnu.gcj.RawData window; - gnu.gcj.RawData gc; - boolean framed = false; - Semaphore waitForCreation = new Semaphore(); - - public native void setInvisible(boolean i); - public void _setMaximized(boolean m) { if (Log.on) Log.log(this, "POSIX/X11 can't maximize windows"); } - public native void setIcon(Picture p); - public native void _setMinimized(boolean b); - public native void setTitleBarText(String s); - public native void setSize(int w, int h); - public native void setLocation(int x, int y); - public native void natInit(); - public native void toFront(); - public native void toBack(); - public native void syncCursor(); - public native void _dispose(); - public native void setLimits(int minw, int minh, int maxw, int maxh); - public native void blit(DoubleBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2); - public native void dispatchEvent(gnu.gcj.RawData ev); - - public X11Surface(Box root, boolean framed) { - super(root); - this.framed = framed; - natInit(); - } - - } - - - // Our Subclass of Picture /////////////////////////////////////////////// - - /** - * Implements a Picture. No special X11 structure is created - * unless the image has no alpha (in which case a - * non-shared-pixmap DoubleBuffer is created), or all-or-nothing - * alpha (in which case a non-shared-pixmap DoubleBuffer with a - * stipple bitmap is created). - */ - public static class X11Picture implements Picture { - - int width; - int height; - int[] data = null; - public X11DoubleBuffer doublebuf = null; - - public int getWidth() { return width; } - public int getHeight() { return height; } - - public X11Picture(int[] data, int w, int h) { - this.data = data; - this.width = w; - this.height = h; - boolean needsStipple = false; - - // if we have any non-0x00, non-0xFF alphas, we can't double buffer ourselves - for(int i=0; i 13) { - if (!font[13].equals("iso8559")) continue; - if (font.length < 15 || !font[14].equals("1")) continue; - } - - String name = font[1]; - String size = font[6]; - String slant = (font[3].equals("i") || font[3].equals("o")) ? "i" : ""; - String bold = font[2].equals("bold") ? "b" : ""; - String tail = s.substring(1 + font[0].length() + 1 + font[1].length() + 1 + font[2].length() + 1 + - font[3].length() + 1 + font[4].length() + 1); - - if (bold.equals("*") && slant.equals("*")) { - nativeFontList.put(name + size, font[0] + "-" + font[1] + "-regular-r-" + font[4] + "-" + tail); - nativeFontList.put(name + size + "b", font[0] + "-" + font[1] + "-bold-r-" + font[4] + "-" + tail); - nativeFontList.put(name + size + "i", font[0] + "-" + font[1] + "-regular-i-" + font[4] + "-" + tail); - nativeFontList.put(name + size + "bi", font[0] + "-" + font[1] + "-bold-i-" + font[4] + "-" + tail); - - } else if (bold.equals("*")) { - nativeFontList.put(name + size + slant, font[0] + "-" + font[1] + "-regular-" + font[3] + "-" + font[4] + "-" + tail); - nativeFontList.put(name + size + "b" + slant, font[0] + "-" + font[1] + "-bold-" + font[3] + "-" + font[4] + "-" + tail); - - } else if (slant.equals("*")) { - nativeFontList.put(name + size + bold, font[0] + "-" + font[1] + "-" + font[2] + "-r-" + font[4] + "-" + tail); - nativeFontList.put(name + size + bold + "i", font[0] + "-" + font[1] + "-" + font[2] + "-i-" + font[4] + "-" + tail); - - } else { - nativeFontList.put(name + size + bold + slant, s); - - } - } catch (ArrayIndexOutOfBoundsException e) { - if (Log.on) Log.log(this, "skipping incomplete font string " + s); - continue; - } - } - fontList = new String[nativeFontList.size()]; - Enumeration e = nativeFontList.keys(); - for(int i=0; e.hasMoreElements(); i++) fontList[i] = (String)e.nextElement(); - } - - /** so we can put XFontStruct's into Hashtables */ - private static class WrappedRawData { - public RawData wrapee = null; - public WrappedRawData(RawData r) { wrapee = r; } - } - - /** translates an X11 font string into an XFontStruct* */ - public static native gnu.gcj.RawData fontStringToStruct(String s); +} - /** translates an XWT font string into an XFontStruct*, performing caching as well */ - public static RawData fontToXFont(String s) { - if (s == null) s = "sansserif"; - s = s.toLowerCase(); - - WrappedRawData wrap = (WrappedRawData)xwtFontToFontStruct.get(s); - if (wrap != null) return wrap.wrapee; - String bestmatch = ""; - int metric = -1 * Integer.MAX_VALUE; - ParsedFont arg = new ParsedFont(s); - ParsedFont pf = new ParsedFont(); - if (arg.size == -1) arg.size = 10; - Enumeration e = nativeFontList.keys(); - while(e.hasMoreElements()) { - String jfont = (String)e.nextElement(); - pf.parse(jfont); - int thismetric = 0; - if (!pf.name.equals(arg.name)) { - if (pf.name.equals("lucidabright") && arg.name.equals("serif")) thismetric -= 1000; - else if (pf.name.equals("times") && arg.name.equals("serif")) thismetric -= 2000; - else if (pf.name.equals("helvetica") && arg.name.equals("sansserif")) thismetric -= 1000; - else if (pf.name.equals("courier") && arg.name.equals("monospaced")) thismetric -= 1000; - else if (pf.name.equals("lucida") && arg.name.equals("dialog")) thismetric -= 1000; - else if (pf.name.equals("helvetica") && arg.name.equals("dialog")) thismetric -= 2000; - else if (pf.name.equals("fixed") && arg.name.equals("tty")) thismetric -= 1000; - else if (pf.name.equals("sansserif")) thismetric -= 4000; - else thismetric -= 4004; - } - if (pf.size != 0) thismetric -= Math.abs(pf.size - arg.size) * 4; - if (pf.bold != arg.bold) thismetric -= 1; - if (pf.italic != arg.italic) thismetric -= 1; - if (thismetric > metric) { - metric = thismetric; - bestmatch = jfont; - } - } - - pf.parse(bestmatch); - String target = (String)nativeFontList.get(bestmatch); - if (pf.size == 0) { - int i = 0; - for(int j=0; j<6; j++) i = target.indexOf('-', i + 1); - target = target.substring(0, i + 1) + arg.size + target.substring(target.indexOf('-', i+1)); - } - RawData ret = fontStringToStruct(target); - if (ret == null) ret = fontStringToStruct("fixed"); - xwtFontToFontStruct.put(s, new WrappedRawData(ret)); - return ret; - } - - -}