X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FX11.java;h=d84aa85f72380d59d3848df1dc55af769ac2fe33;hb=6ef77f074f6f6260a05e8017d0bdf8c9ef524cd3;hp=a65c41b6b12d0c2dd5721d1a9459359e390e907c;hpb=fa437b8b1bdf01b3bbdabec990b60833cd6c68f0;p=org.ibex.core.git diff --git a/src/org/xwt/plat/X11.java b/src/org/xwt/plat/X11.java index a65c41b..d84aa85 100644 --- a/src/org/xwt/plat/X11.java +++ b/src/org/xwt/plat/X11.java @@ -1,14 +1,12 @@ -// Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL] +// Copyright 2004 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.js.*; import org.xwt.util.*; import org.xwt.*; @@ -35,33 +33,29 @@ public class X11 extends POSIX { // General Methods /////////////////////////////////////////////////////// protected String _getAltKeyName() { return System.getProperty("os.name", "").indexOf("SunOS") != -1 ? "Meta" : "Alt"; } - protected String[] _listFonts() { return fontList; } - 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 Picture _createPicture(JS r) { return new X11Picture(r); } + protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new X11PixelBuffer(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(); - public void init() { - super.init(); + public X11() { } + public void postInit() { + natInit(); (new Thread() { public void run() { eventThread(); } }).start(); - initFonts(); } // X11Surface ///////////////////////////////////////////////////// /** Implements a Surface as an X11 Window */ - public static class X11Surface extends Surface { + public static class X11Surface extends Surface.DoubleBufferedSurface { gnu.gcj.RawData window; gnu.gcj.RawData gc; @@ -69,21 +63,23 @@ public class X11 extends POSIX { 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 void _setMaximized(boolean m) { if (Log.on) Log.warn(this, "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 _setSize(int w, int h); + public native void setLocation(); 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 blit(PixelBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2); public native void dispatchEvent(gnu.gcj.RawData ev); - + public void setMinimumSize(int minx, int miny, boolean resizable) { + setLimits(minx, miny, resizable ? Short.MAX_VALUE : minx, resizable ? Short.MAX_VALUE : miny); + } public X11Surface(Box root, boolean framed) { super(root); this.framed = framed; @@ -98,64 +94,61 @@ public class X11 extends POSIX { /** * 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 + * non-shared-pixmap PixelBuffer is created), or all-or-nothing + * alpha (in which case a non-shared-pixmap PixelBuffer with a * stipple bitmap is created). */ public static class X11Picture extends Picture { - int width; - int height; - int[] data = null; - public X11DoubleBuffer doublebuf = null; + public X11PixelBuffer 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 initialized = false; + public X11Picture(JS r) { super(r); } + public void init() { + if (initialized) return; + initialized = true; boolean needsStipple = false; // if we have any non-0x00, non-0xFF alphas, we can't double buffer ourselves - for(int i=0; i= cx2 || cy1 >= cy2) return; + X11Picture pic = (X11Picture)((Platform.DefaultGlyph)source).getPicture(); + pic.init(); + slowDrawPicture(pic, dx, dy, cx1, cy1, cx2, cy2, rgb, true); } - - public void drawPicture(Picture source, int x, int y) { - drawPicture(source, x, y, x + source.getWidth(), y + source.getHeight(), 0, 0, source.getWidth(), source.getHeight()); - } - - public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) { - if (!(dx2 - dx1 != sx2 - sx1 || dy2 - dy1 != sy2 - sy1) && ((X11Picture)source).doublebuf != null) - fastDrawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); + public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) { + cx1 = Math.max(dx, cx1); + cy1 = Math.max(dy, cy1); + cx2 = Math.min(dx + source.width, cx2); + cy2 = Math.min(dy + source.height, cy2); + if (cx1 >= cx2 || cy1 >= cy2) return; + ((X11Picture)source).init(); + if (((X11Picture)source).doublebuf != null) + fastDrawPicture(source, dx, dy, cx1, cy1, cx2, cy2); else - slowDrawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); + slowDrawPicture(source, dx, dy, cx1, cy1, cx2, cy2, 0, false); } /** fast path for image drawing (no scaling, all-or-nothing alpha) */ - public native void fastDrawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2); + public native void fastDrawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2); /** slow path for image drawing */ - public native void slowDrawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2); + public native void slowDrawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb, boolean alphaOnly); public int getWidth() { return width; } public int getHeight() { return height; } public native void natInit(); public native void fillRect(int x, int y, int x2, int y2, int color); - public native void drawString(String font, String text, int x, int y, int color); public native void finalize(); - } - - - // Font Handling //////////////////////////////////////////////////////////////////// - - static String[] fontList = null; - - /** hashtable of all built in X11 fonts; key is XWT font spec, value is X11 font string */ - static Hashtable nativeFontList = new Hashtable(); - - /** cache of all already-looked-up X11 fonts; key is XWT font name, value is a WrappedRawData */ - static Hashtable xwtFontToFontStruct = new Hashtable(); - - /** dumps a list of X11 font strings */ - private native String[] listNativeFonts(); - - /** load native font list */ - public void initFonts() { - // use the font list to build nativeFontList - String[] fonts = listNativeFonts(); - - Vector v = new Vector(); - for(int k=0; k 12) { - if (!font[12].equals("iso8859") && !font[12].equals("")) continue; - if (font.length < 14 || !font[13].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 = s2.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, s2); - - } - } catch (ArrayIndexOutOfBoundsException e) { - if (Log.on) Log.log(this, "skipping incomplete font string " + s2); - continue; + // FIXME: try to use os acceleration + public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) { + if (x1 == x3 && x2 == x4) { + fillRect(x1, y1, x4, y2, argb); + } else for(int y=y1; y _x2) { int _x0 = _x1; _x1 = _x2; _x2 = _x0; } + fillRect(_x1, _y1, _x2, _y2, argb); } } - 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)); - } - if (Log.on) Log.log(POSIX.class, "mapping font \"" + s + "\" to \"" + target + "\""); - RawData ret = fontStringToStruct(target); - if (ret == null) ret = fontStringToStruct("fixed"); - xwtFontToFontStruct.put(s, new WrappedRawData(ret)); - return ret; } }