2004/01/17 07:30:32
[org.ibex.core.git] / src / org / xwt / plat / X11.java
index 6d94727..d84aa85 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2003 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 gnu.gcj.RawData;
@@ -6,6 +6,7 @@ import java.net.*;
 import java.lang.reflect.*;
 import java.io.*;
 import java.util.*;
+import org.xwt.js.*;
 import org.xwt.util.*;
 import org.xwt.*;
 
@@ -33,7 +34,7 @@ public class X11 extends POSIX {
 
     protected String _getAltKeyName() { return System.getProperty("os.name", "").indexOf("SunOS") != -1 ? "Meta" : "Alt"; }
 
-    protected Picture _createPicture(int[] data, int w, int h) { return new X11Picture(data, 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; }
@@ -46,7 +47,7 @@ public class X11 extends POSIX {
     private native void natInit();
 
     public X11() { }
-    public void init() {
+    public void postInit() {
         natInit();
         (new Thread() { public void run() { eventThread(); } }).start();
     }
@@ -62,11 +63,11 @@ 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, "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 _setSize(int w, int h);
         public native void setLocation();
         public native void natInit();
         public native void toFront();
@@ -76,7 +77,9 @@ public class X11 extends POSIX {
         public native void setLimits(int minw, int minh, int maxw, int maxh);
         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;
@@ -97,22 +100,20 @@ public class X11 extends POSIX {
      */
     public static class X11Picture extends Picture {
         
-        int width;
-        int height;
-        int[] data = 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<w*h; i++)
+            for(int i=0; i<width*height; i++)
                 if ((data[i] & 0xFF000000) == 0xFF000000)
                     needsStipple = true;
                 else if ((data[i] & 0xFF000000) != 0x00)
@@ -125,7 +126,7 @@ public class X11 extends POSIX {
             if (doublebuf != null) return;
             // no point in using a shared pixmap since we'll only write to this image once
             X11PixelBuffer b = new X11PixelBuffer(width, height, false);
-            b.drawPicture(this, 0, 0, width, height, 0, 0, width, height);
+            b.drawPicture(this, 0, 0, 0, 0, width, height);
             if (needsStipple) b.createStipple(this);
             doublebuf = b;
         }
@@ -155,8 +156,8 @@ public class X11 extends POSIX {
         RawData fake_ximage = null;    // a 'fake' XImage corresponding to the shared pixmap; gives us the address and depth parameters
         RawData shm_segment = null;    // XShmSegmentInfo
 
-        RawData gc;                    // Graphics Context on pm (never changes, so it's fast)
-        RawData clipped_gc;            // Graphics Context on pm, use this one if you need a clip/stipple
+        RawData gc;                    // Graphics Interpreter on pm (never changes, so it's fast)
+        RawData clipped_gc;            // Graphics Interpreter on pm, use this one if you need a clip/stipple
 
         /** PixelBuffer mode */
         public X11PixelBuffer(int w, int h) { this(w, h, true); }
@@ -168,30 +169,34 @@ public class X11 extends POSIX {
             natInit();
         }
 
-        public void setClip(int x, int y, int x2, int y2) {
-            clipx = x; if (clipx < 0) clipx = 0;
-            clipy = y; if (clipy < 0) clipy = 0;
-            clipw = x2 - x; if (clipw < 0) clipw = 0;
-            cliph = y2 - y; if (cliph < 0) cliph = 0;
+        public void drawGlyph(Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {        
+           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 pic = (X11Picture)((Platform.DefaultGlyph)source).getPicture();
+            pic.init();
+            slowDrawPicture(pic, dx, dy, cx1, cy1, cx2, cy2, rgb, true);
         }
-        
-        //public native void drawPictureAlphaOnly(Picture source, int dx1, int dy1, int dx2, int dy2,
-        //int sx1, int sy1, int sx2, int sy2, int rgb);
-        public void drawPictureAlphaOnly(Picture source, int dx1, int dy1, int dx2, int dy2,
-            int sx1, int sy1, int sx2, int sy2, int rgb) { }
-
-        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; }