diff options
Diffstat (limited to 'libjava/gnu/gcj/xlib')
66 files changed, 5077 insertions, 0 deletions
diff --git a/libjava/gnu/gcj/xlib/Clip.h b/libjava/gnu/gcj/xlib/Clip.h new file mode 100644 index 000000000..3fe491b14 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Clip.h @@ -0,0 +1,50 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_Clip__ +#define __gnu_gcj_xlib_Clip__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class Clip; + } + } + } + namespace java + { + namespace awt + { + class Rectangle; + } + } +} + +class gnu::gcj::xlib::Clip : public ::java::lang::Object +{ + +public: + Clip(JArray< ::java::awt::Rectangle * > *); +private: + void init(JArray< ::java::awt::Rectangle * > *); +public: + void finalize(); + void dispose(); +public: // actually package-private + ::gnu::gcj::RawData * __attribute__((aligned(__alignof__( ::java::lang::Object)))) xrects; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_Clip__ diff --git a/libjava/gnu/gcj/xlib/Clip.java b/libjava/gnu/gcj/xlib/Clip.java new file mode 100644 index 000000000..311dfa6fe --- /dev/null +++ b/libjava/gnu/gcj/xlib/Clip.java @@ -0,0 +1,40 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; +import java.awt.Rectangle; + +/** + * Describes a clip that is used to constrain drawing using a GC + * within a specific region. Currently it supports clip regions + * consisting of the union of multiple rectangles. Other clip forms + * may be implented later. This class is used internally by the GC + * class, and wraps a native XRectVector[]. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +final class Clip +{ + public Clip(Rectangle[] rects) + { + init(rects); + } + + private native void init(Rectangle[] rects); + + public void finalize() + { + dispose (); + } + + public native void dispose(); + + RawData xrects; +} diff --git a/libjava/gnu/gcj/xlib/Colormap.h b/libjava/gnu/gcj/xlib/Colormap.h new file mode 100644 index 000000000..440766eb8 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Colormap.h @@ -0,0 +1,47 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_Colormap__ +#define __gnu_gcj_xlib_Colormap__ + +#pragma interface + +#include <gnu/gcj/xlib/XID.h> +#include <gcj/array.h> + +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class Colormap; + class Screen; + class XColor; + } + } + } +} + +class gnu::gcj::xlib::Colormap : public ::gnu::gcj::xlib::XID +{ + +public: + Colormap(::gnu::gcj::xlib::Screen *, jint); + jlong allocateColorPixel(::gnu::gcj::xlib::XColor *); + ::gnu::gcj::xlib::XColor * allocateColor(jint, jint, jint); + JArray< ::gnu::gcj::xlib::XColor * > * getSharedColors(); + JArray< ::gnu::gcj::xlib::XColor * > * getXColors(); +private: + JArray< ::gnu::gcj::xlib::XColor * > * newXColorArray(jint); +public: // actually package-private + ::gnu::gcj::xlib::Screen * __attribute__((aligned(__alignof__( ::gnu::gcj::xlib::XID)))) screen; +public: + static const jbyte FLAG_SHARED = 1; + static const jbyte FLAG_NOT_SHARED = 2; + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_Colormap__ diff --git a/libjava/gnu/gcj/xlib/Colormap.java b/libjava/gnu/gcj/xlib/Colormap.java new file mode 100644 index 000000000..538782e7e --- /dev/null +++ b/libjava/gnu/gcj/xlib/Colormap.java @@ -0,0 +1,84 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; + +/** + * An X11 color map resource. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public final class Colormap extends XID +{ + Screen screen; + + public static final byte FLAG_SHARED = 1; + public static final byte FLAG_NOT_SHARED = 2; + + public Colormap(Screen screen, int xid) + { + super(screen.getDisplay(), xid); + this.screen = screen; + } + + /** + * Allocate color pixel. + * + * @param color The color to be allocated. If allocation is + * successful, this object will be modified to reflect the actual + * color that was allocated. + * + * @return the pixel value of the allocated color. + */ + public native long allocateColorPixel(XColor color); + + /** + * Allocate a color consisting of the given RGB-triplet. + * + * @return a color object describing the allocated color. + */ + public XColor allocateColor(int r, int g, int b) + { + XColor color = new XColor(r, g, b); + allocateColorPixel(color); + + return color; + } + + /** + * Get an array of all colors that currently resides in shared (read + * only) color-cells in this color map. + */ + public native XColor[] getSharedColors(); + + + /** + * Get all colors currently residing in this color map. Colors that + * are shared (read only) are marked as such by the color flags. + * The indexes of the returned array will correspond to the + * colorcells of the color map. Given a color <code>XColor + * color</code> from a given color-cell, the expression + * <code>color.getFlags() == Colormap.FLAG_SHARED</code> will check + * whether the color-cell is shared. + */ + public native XColor[] getXColors(); + + /** + * Convenience method used by native code to create fully + * initialized arrays of XColor objects. + */ + private XColor[] newXColorArray(int n) + { + XColor[] array = new XColor[n]; + for (int i=0; i<n; i++) + array[i] = new XColor(); + return array; + } +} diff --git a/libjava/gnu/gcj/xlib/Display.h b/libjava/gnu/gcj/xlib/Display.h new file mode 100644 index 000000000..78bc41d2d --- /dev/null +++ b/libjava/gnu/gcj/xlib/Display.h @@ -0,0 +1,64 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_Display__ +#define __gnu_gcj_xlib_Display__ + +#pragma interface + +#include <java/lang/Object.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class Display; + class Screen; + class Window; + class XID; + } + } + } +} + +class gnu::gcj::xlib::Display : public ::java::lang::Object +{ + +public: + Display(); +private: + static void staticInit(); + void init(); +public: // actually protected + virtual void finalize(); + virtual void addXID(jint, ::gnu::gcj::xlib::XID *); + virtual void removeXID(jint); +public: + virtual ::gnu::gcj::xlib::Window * getDefaultRootWindow(); + virtual ::gnu::gcj::xlib::XID * getXID(jint); + virtual ::gnu::gcj::xlib::Window * getWindow(jint); + virtual ::gnu::gcj::xlib::Screen * getDefaultScreen(); + virtual jint getDefaultScreenNumber(); +private: + jint getDefaultRootWindowXID(); +public: + virtual jint getAtom(::java::lang::String *); + virtual ::java::lang::String * getAtomName(jint); +private: + jint internAtom(::java::lang::String *); +public: + virtual void flush(); +public: // actually package-private + ::gnu::gcj::RawData * __attribute__((aligned(__alignof__( ::java::lang::Object)))) display; +private: + ::java::util::Dictionary * xids; + ::java::util::Dictionary * atoms; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_Display__ diff --git a/libjava/gnu/gcj/xlib/Display.java b/libjava/gnu/gcj/xlib/Display.java new file mode 100644 index 000000000..50ff1291b --- /dev/null +++ b/libjava/gnu/gcj/xlib/Display.java @@ -0,0 +1,105 @@ +/* Copyright (C) 1999, 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.Vector; +import java.util.Enumeration; + +import gnu.gcj.RawData; + +/** + * A connection to an X11 display. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ + +public class Display +{ + static + { + staticInit(); + } + + public Display() + { + init(); + } + + private static native void staticInit(); + private native void init(); + protected native void finalize(); + + RawData display = null; + + /* TODO?: Rather than storing such data here, we might consider + using the context manager facilities provided by Xlib... */ + private Dictionary xids = new Hashtable(); + + protected final void addXID(int xid, XID window) + { + xids.put(new Integer(xid), window); + } + + protected final void removeXID(int xid) + { + xids.remove(new Integer(xid)); + } + + public final Window getDefaultRootWindow() + { + int rootXID = getDefaultRootWindowXID(); + return getWindow(rootXID); + } + + public final XID getXID(int xid) + { + return (XID) xids.get(new Integer(xid)); + } + + public final Window getWindow(int xid) + { + Window window = (Window) getXID(xid); + if (window == null) + { + window = new Window(this, xid); + addXID(xid, window); + } + return window; + } + + public final Screen getDefaultScreen() + { + /* Screens objects are not cached since they are lightweight. + We just create a new object when requested. */ + return new Screen(this, getDefaultScreenNumber()); + } + + public final native int getDefaultScreenNumber(); + + private final native int getDefaultRootWindowXID(); + + private Dictionary atoms = new Hashtable(); + + public final int getAtom(String name) + { + Integer atomInt = (Integer) atoms.get(name); + if (atomInt == null) + return internAtom(name); + return atomInt.intValue(); + } + + // TODO?: cache reverse lookup too? + public final native String getAtomName(int atom); + + private final native int internAtom(String name); + + public native void flush(); +} diff --git a/libjava/gnu/gcj/xlib/Drawable.h b/libjava/gnu/gcj/xlib/Drawable.h new file mode 100644 index 000000000..213c36183 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Drawable.h @@ -0,0 +1,60 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_Drawable__ +#define __gnu_gcj_xlib_Drawable__ + +#pragma interface + +#include <gnu/gcj/xlib/XID.h> +#include <gcj/array.h> + +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class Display; + class Drawable; + class GC; + class XImage; + } + } + } + namespace java + { + namespace awt + { + class Rectangle; + } + } +} + +class gnu::gcj::xlib::Drawable : public ::gnu::gcj::xlib::XID +{ + +public: + Drawable(::gnu::gcj::xlib::Display *, jint); + virtual ::java::awt::Rectangle * copyIntoXImage(::gnu::gcj::xlib::XImage *, ::java::awt::Rectangle *, jint, jint); +private: + jboolean copyIntoXImageImpl(::gnu::gcj::xlib::XImage *, jint, jint, jint, jint, jint, jint); +public: + virtual ::java::awt::Rectangle * getBounds(::java::awt::Rectangle *); + virtual jint getDepth(); +public: // actually protected + virtual void finalize(); +public: // actually package-private + virtual void putGCInCache(::gnu::gcj::xlib::GC *); + virtual ::gnu::gcj::xlib::GC * getGCFromCache(); +private: + JArray< ::gnu::gcj::xlib::GC * > * __attribute__((aligned(__alignof__( ::gnu::gcj::xlib::XID)))) gcCache; + jint gcCachedCount; + static ::java::lang::String * MSG_XGETSUBIMAGE_FAILED; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_Drawable__ diff --git a/libjava/gnu/gcj/xlib/Drawable.java b/libjava/gnu/gcj/xlib/Drawable.java new file mode 100644 index 000000000..fa12ba2b3 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Drawable.java @@ -0,0 +1,118 @@ +/* Copyright (C) 1999, 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import java.awt.Rectangle; + +/** An X11 drawable. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class Drawable extends XID +{ + private GC[] gcCache = new GC[10]; + private int gcCachedCount = 0; + + public Drawable(Display display, int xid) + { + super(display, xid); + } + + /** + * Gets as much as possible of the image data within the requested + * region. Data from obscured parts of windows may not be + * retrievable. + * + * @param dest where to place the image data. + * + * @return the actual region of image data that was retrieved. + */ + public Rectangle copyIntoXImage(XImage dest, Rectangle bounds, + int destX, int destY) + { + Rectangle newBounds = null; + int tries = 5; + while (!bounds.isEmpty()) + { + if (copyIntoXImageImpl(dest, bounds.x, bounds.y, + bounds.width, bounds.height, + destX, destY)) + return bounds; + + // failed, likely due to wrong bounds... + + newBounds = getBounds(newBounds); + + bounds = newBounds.intersection(bounds); + + tries--; + + if (tries < 0) + throw new RuntimeException("copyIntoXImage is buggy"); + + } + + return bounds; // always empty + } + + + + /** + * Performs an XGetSubImage. This method will fail if the X server + * does not possess the requested image data. This might occur when + * requesting the image date of a window that is partially obscured. + * + * @param desitantionImage where to place the image data + * + * @return false if method was unable to read the requested region. + */ + private native boolean copyIntoXImageImpl(XImage destinationImage, + int x, int y, + int width, int height, + int destX, int destY); + + public native Rectangle getBounds(Rectangle rv); + + public native int getDepth (); + + private static final String MSG_XGETSUBIMAGE_FAILED = + "XGetSubImage() failed."; + + protected void finalize() throws Throwable + { + // Dispose all the cached GCs, to reduce X server resource usage + for (int i=0; i<gcCachedCount; i++) + gcCache[i].disposeImpl (); + gcCachedCount = 0; + super.finalize(); + } + + /** Put a GC in the cache for this drawable, so it can be retrieved later. + * @param gc The GC to put + */ + void putGCInCache (GC gc) + { + if (gcCachedCount >= gcCache.length) + { + // List full - extend it to double its present size + GC[] oldList = gcCache; + gcCache = new GC[oldList.length*2]; + System.arraycopy (oldList,0,gcCache,0,oldList.length); + } + gcCache[gcCachedCount++] = gc; + } + + /** Get a GC from the cache, if available + * @return A GC from the cache, or null if the cache is empty + */ + GC getGCFromCache () + { + return (gcCachedCount>0) ? gcCache[--gcCachedCount] : null; + } +} diff --git a/libjava/gnu/gcj/xlib/Font.h b/libjava/gnu/gcj/xlib/Font.h new file mode 100644 index 000000000..7cf50d364 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Font.h @@ -0,0 +1,50 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_Font__ +#define __gnu_gcj_xlib_Font__ + +#pragma interface + +#include <gnu/gcj/xlib/XID.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class Display; + class Font; + } + } + } +} + +class gnu::gcj::xlib::Font : public ::gnu::gcj::xlib::XID +{ + +public: + Font(::gnu::gcj::xlib::Display *, ::java::lang::String *); +public: // actually package-private + Font(::gnu::gcj::xlib::Display *, ::gnu::gcj::RawData *); + static ::gnu::gcj::RawData * loadFont(::gnu::gcj::xlib::Display *, ::java::lang::String *); + static ::gnu::gcj::RawData * loadFontImpl(::gnu::gcj::xlib::Display *, ::java::lang::String *); + static jint getXIDFromStruct(::gnu::gcj::RawData *); +public: + jint getAscent(); + jint getDescent(); + jint getMaxAscent(); + jint getMaxDescent(); + jint getStringWidth(::java::lang::String *); +public: // actually protected + void finalize(); +public: // actually package-private + ::gnu::gcj::RawData * __attribute__((aligned(__alignof__( ::gnu::gcj::xlib::XID)))) structure; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_Font__ diff --git a/libjava/gnu/gcj/xlib/Font.java b/libjava/gnu/gcj/xlib/Font.java new file mode 100644 index 000000000..74985b938 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Font.java @@ -0,0 +1,65 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; + +/** + * An X11 Font, implemented as a wrapper around an X11 Font XID and + * the associated Xlib XFontStruct structure. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public final class Font extends XID +{ + + /** + * @param lfdNamePattern a font name pattern following the + * <em>X Logical Font Description Conventions</em>. + */ + public Font(Display display, String lfdNamePattern) + { + this(display, loadFont(display, lfdNamePattern)); + } + + Font(Display display, RawData struct) + { + super(display, getXIDFromStruct(struct)); + structure = struct; + } + + static RawData loadFont(Display display, String lfdNamePattern) + { + RawData returnValue = null; + try + { + returnValue = loadFontImpl (display,lfdNamePattern); + } + catch (XException e) + { + // Throw a descriptive exception, including the font pattern + throw new XException ("Font not found: " + lfdNamePattern); + } + return returnValue; + } + static native RawData loadFontImpl(Display display, String lfdNamePattern); + + static native int getXIDFromStruct(RawData structure); + + public native int getAscent(); + public native int getDescent(); + public native int getMaxAscent(); + public native int getMaxDescent(); + + public native int getStringWidth(String str); + + protected native void finalize(); + + RawData structure; +} diff --git a/libjava/gnu/gcj/xlib/GC.h b/libjava/gnu/gcj/xlib/GC.h new file mode 100644 index 000000000..cb8bf3912 --- /dev/null +++ b/libjava/gnu/gcj/xlib/GC.h @@ -0,0 +1,76 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_GC__ +#define __gnu_gcj_xlib_GC__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class Drawable; + class Font; + class GC; + class XImage; + } + } + } + namespace java + { + namespace awt + { + class Rectangle; + } + } +} + +class gnu::gcj::xlib::GC : public ::java::lang::Object +{ + +public: // actually protected + GC(::gnu::gcj::xlib::Drawable *); +public: + virtual ::java::lang::Object * clone(); +private: + void initStructure(::gnu::gcj::xlib::GC *); +public: + virtual ::gnu::gcj::xlib::GC * create(); + static ::gnu::gcj::xlib::GC * create(::gnu::gcj::xlib::Drawable *); + virtual void finalize(); + virtual void dispose(); + virtual void disposeImpl(); + virtual void setForeground(jlong); + virtual void setFont(::gnu::gcj::xlib::Font *); + virtual void setClipRectangles(JArray< ::java::awt::Rectangle * > *); + virtual void drawString(::java::lang::String *, jint, jint); + virtual void drawLine(jint, jint, jint, jint); + virtual void drawRectangle(jint, jint, jint, jint); + virtual void fillRectangle(jint, jint, jint, jint); + virtual void fillPolygon(JArray< jint > *, JArray< jint > *, jint, jint, jint); + virtual void drawArc(jint, jint, jint, jint, jint, jint); + virtual void fillArc(jint, jint, jint, jint, jint, jint); + virtual void clearArea(jint, jint, jint, jint, jboolean); + virtual void drawPoint(jint, jint); + virtual void putImage(::gnu::gcj::xlib::XImage *, jint, jint, jint, jint, jint, jint); + virtual void copyArea(::gnu::gcj::xlib::Drawable *, jint, jint, jint, jint, jint, jint); + virtual ::gnu::gcj::xlib::Drawable * getDrawable(); +private: + void updateClip(JArray< ::java::awt::Rectangle * > *); + ::gnu::gcj::xlib::Drawable * __attribute__((aligned(__alignof__( ::java::lang::Object)))) target; + ::gnu::gcj::RawData * structure; + JArray< ::java::awt::Rectangle * > * clipRectangles; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_GC__ diff --git a/libjava/gnu/gcj/xlib/GC.java b/libjava/gnu/gcj/xlib/GC.java new file mode 100644 index 000000000..1a47cf66d --- /dev/null +++ b/libjava/gnu/gcj/xlib/GC.java @@ -0,0 +1,162 @@ +/* Copyright (C) 2000, 2003 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; +import java.awt.Rectangle; + +/** + * An X11 graphics context. Unlike a traditional X11 graphics + * context, the target drawable is part of the GC state. + * + * Implementation notes: There is no need to do coalescing of changes + * since Xlib will do this for us. The implementation relies on the + * Xlib GC cache and will not try to be clever. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class GC implements Cloneable +{ + /** Protected constructor, because GC.create(target) should be used instead. + */ + protected GC(Drawable target) + { + this.target = target; + initStructure(null); + } + + /** Try to get a suitable GC from the drawable's cache. + * If there isn't one, create one. + */ + public Object clone() + { + try + { + GC gcClone = target.getGCFromCache (); + if (gcClone==null) + { + gcClone = (GC) super.clone(); + gcClone.structure = null; + } + gcClone.initStructure(this); + gcClone.updateClip(clipRectangles); + return gcClone; + } + catch (CloneNotSupportedException ex) + { + // This should never happen. + throw new InternalError (); + } + } + + private native void initStructure(GC copyFrom); + + public GC create() + { + return (GC) clone(); + } + + /** Create a GC, or if one is already cached for target, return that. + * @param target The Drawable for which a GC is needed + * @return The new or retrieved GC + */ + static public GC create (Drawable target) + { + GC returnValue = target.getGCFromCache (); + if (returnValue == null) + returnValue = new GC (target); + return returnValue; + } + + public void finalize() + { + disposeImpl(); + } + + /** Save this GC in the drawable's cache. + * The "real" dispose (disposeImpl) is called when the + * drawable is finialized, to free X server resources. + */ + public void dispose() + { + target.putGCInCache (this); + } + + public synchronized native void disposeImpl(); + + public native void setForeground(long pixel); + public native void setFont(gnu.gcj.xlib.Font font); + + /** + * Set the clip region for the graphics operations performed by the + * GC. + * + * This is one of the few costly operations of this class. It is + * suggested that the clip is only set or changed if really + * necessary. Higher level APIs can make such optimizations + * transparent. + * + * @param rectangles the union of these rectangles describe the clip + * region. + */ + public void setClipRectangles(Rectangle[] rectangles) + { + clipRectangles = rectangles; + updateClip(clipRectangles); + } + + public native void drawString(String text, int x, int y); + public native void drawLine(int x1, int y1, int x2, int y2); + public native void drawRectangle(int x, int y, int w, int h); + + public native void fillRectangle(int x, int y, int w, int h); + public native void fillPolygon(int[] xPoints, int[] yPoints, int nPoints, + int translateX, int translateY); + + public native void drawArc(int x, int y, int w, int h, + int startAngle, int arcAngle); + public native void fillArc(int x, int y, int w, int h, + int startAngle, int arcAngle); + + /** + * + * Clear area using the background pixel or pixmap of the drawable. + * Note that this operation does not adhere to the current clip. + */ + public native void clearArea(int x, int y, int w, int h, + boolean exposures); + + /** Draw a point using the current foreground color + * @param x The x coordinate at which to draw + * @param t The y coordinate at which to draw + */ + public native void drawPoint (int x, int y); + + public native void putImage(XImage image, + int srcX, int srcY, + int destX, int destY, + int width, int height); + + public native void copyArea (Drawable source, + int srcX, int srcY, + int destX, int destY, + int width, int height); + + public Drawable getDrawable() + { + return target; + } + + private native void updateClip(Rectangle[] rectangles); + + private Drawable target; + private RawData structure; + private Rectangle[] clipRectangles; +} + diff --git a/libjava/gnu/gcj/xlib/Pixmap.h b/libjava/gnu/gcj/xlib/Pixmap.h new file mode 100644 index 000000000..b73ee7063 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Pixmap.h @@ -0,0 +1,40 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_Pixmap__ +#define __gnu_gcj_xlib_Pixmap__ + +#pragma interface + +#include <gnu/gcj/xlib/Drawable.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class Drawable; + class Pixmap; + class Screen; + class XImage; + } + } + } +} + +class gnu::gcj::xlib::Pixmap : public ::gnu::gcj::xlib::Drawable +{ + +public: + Pixmap(::gnu::gcj::xlib::XImage *, ::gnu::gcj::xlib::Screen *); + Pixmap(::gnu::gcj::xlib::Drawable *, jint, jint, jint); +public: // actually protected + static jint createXID(::gnu::gcj::xlib::Drawable *, jint, jint, jint); + virtual void finalize(); +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_Pixmap__ diff --git a/libjava/gnu/gcj/xlib/Pixmap.java b/libjava/gnu/gcj/xlib/Pixmap.java new file mode 100644 index 000000000..7ba5a62f9 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Pixmap.java @@ -0,0 +1,43 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +/** + * An X11 Pixmap. A pixmap is an offscreen drawable that resides on + * the X server. A pixmap is bound to the screen it was created for. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class Pixmap extends Drawable +{ + public Pixmap(XImage image, Screen screen) + { + this(screen.getRootWindow(), + image.getWidth(), image.getHeight(), + image.getDepth()); + + /* FIXME: don't create a new GC all the time. This might actually + not be as bad as initially believed. The GC cache of Xlib makes + this operation less costly. */ + GC gc = GC.create (this); + + gc.putImage(image, 0, 0, 0, 0, image.getWidth(), image.getHeight()); + } + + public Pixmap(Drawable sameScreenAs, int width, int height, int depth) + { + super(sameScreenAs.getDisplay(), + createXID(sameScreenAs, width, height, depth)); + } + + protected static native int createXID(Drawable sameScreenAs, + int width, int height, int depth); + + protected native void finalize(); +} diff --git a/libjava/gnu/gcj/xlib/Screen.h b/libjava/gnu/gcj/xlib/Screen.h new file mode 100644 index 000000000..362c2e482 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Screen.h @@ -0,0 +1,61 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_Screen__ +#define __gnu_gcj_xlib_Screen__ + +#pragma interface + +#include <java/lang/Object.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class Colormap; + class Display; + class Screen; + class Visual; + class Window; + } + } + } +} + +class gnu::gcj::xlib::Screen : public ::java::lang::Object +{ + +public: // actually package-private + Screen(::gnu::gcj::xlib::Display *, ::gnu::gcj::RawData *); +public: + Screen(::gnu::gcj::xlib::Display *); + Screen(::gnu::gcj::xlib::Display *, jint); + ::gnu::gcj::xlib::Display * getDisplay(); + ::gnu::gcj::xlib::Window * getRootWindow(); + ::gnu::gcj::xlib::Visual * getRootVisual(); +private: + ::gnu::gcj::RawData * getRootVisualStructure(); +public: + jint getRootDepth(); + jint getRootWindowXID(); + jint getDefaultColormapXID(); +public: // actually package-private + void initStructure(); +public: + ::gnu::gcj::xlib::Colormap * getDefaultColormap(); + jint getScreenNumber(); + jint findScreenNumber(); +public: // actually package-private + static const jint UNKNOWN = -1; + ::gnu::gcj::xlib::Display * __attribute__((aligned(__alignof__( ::java::lang::Object)))) display; + jint screenNumber; + ::gnu::gcj::RawData * structure; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_Screen__ diff --git a/libjava/gnu/gcj/xlib/Screen.java b/libjava/gnu/gcj/xlib/Screen.java new file mode 100644 index 000000000..675ed1b9b --- /dev/null +++ b/libjava/gnu/gcj/xlib/Screen.java @@ -0,0 +1,86 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; + +/** + * A flyweight class that denotes an X11 screen. Display and screen + * number is the only data kept by this class. The real screen + * structure is stored in the display. There may exist several + * objects denoting the same screen. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public final class Screen +{ + static final int UNKNOWN = -1; + + Display display; + int screenNumber = UNKNOWN; + RawData structure; + + Screen(Display display, RawData screenStructure) + { + structure = screenStructure; + this.display = display; + } + + public Screen(Display display) + { + this(display, display.getDefaultScreenNumber()); + } + + public Screen(Display display, int screenNumber) + { + this.display = display; + this.screenNumber = screenNumber; + initStructure(); + } + + public final Display getDisplay() + { + return display; + } + + public Window getRootWindow() + { + int rootXID = getRootWindowXID(); + return display.getWindow(rootXID); + } + + public Visual getRootVisual() + { + RawData visualStructure = getRootVisualStructure(); + int depth = getRootDepth(); + return new Visual(visualStructure, this, depth); + } + + private native RawData getRootVisualStructure(); + + public native int getRootDepth(); + public native int getRootWindowXID(); + public native int getDefaultColormapXID(); + + native void initStructure(); + + public Colormap getDefaultColormap() + { + return new Colormap(this, getDefaultColormapXID()); + } + + public final int getScreenNumber() + { + if (screenNumber == UNKNOWN) + screenNumber = findScreenNumber(); + return screenNumber; + } + + public native int findScreenNumber(); +} diff --git a/libjava/gnu/gcj/xlib/Visual.h b/libjava/gnu/gcj/xlib/Visual.h new file mode 100644 index 000000000..de3e25e33 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Visual.h @@ -0,0 +1,79 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_Visual__ +#define __gnu_gcj_xlib_Visual__ + +#pragma interface + +#include <java/lang/Object.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class Display; + class Screen; + class Visual; + } + } + } +} + +class gnu::gcj::xlib::Visual : public ::java::lang::Object +{ + +public: // actually package-private + Visual(::gnu::gcj::RawData *, ::gnu::gcj::xlib::Screen *, jint); + Visual(::gnu::gcj::xlib::Display *, ::gnu::gcj::RawData *, jint); +public: // actually protected + void init(::gnu::gcj::RawData *, jint); + void finalize(); +public: // actually package-private + ::gnu::gcj::RawData * getVisualStructure(); +public: + jint getRedMask(); + jint getGreenMask(); + jint getBlueMask(); + jint getScreenNumber(); + jint getDepth(); + ::gnu::gcj::xlib::Screen * getScreen(); + jint getVisualClass(); + jboolean hasRGBSubfields(); +public: // actually protected + void ensureXVisualInfo(jint); +public: + ::java::lang::String * toString(); + static const jint VC_STATIC_GRAY = 0; + static const jint VC_GRAY_SCALE = 1; + static const jint VC_STATIC_COLOR = 2; + static const jint VC_PSEUDO_COLOR = 3; + static const jint VC_TRUE_COLOR = 4; + static const jint VC_DIRECT_COLOR = 5; +public: // actually protected + static const jint MASK_ID = 1; + static const jint MASK_SCREEN = 2; + static const jint MASK_DEPTH = 4; + static const jint MASK_CLASS = 8; + static const jint MASK_RED = 16; + static const jint MASK_GREEN = 32; + static const jint MASK_BLUE = 64; + static const jint MASK_COLORMAP_SIZE = 128; + static const jint MASK_BITS_PER_RGB = 256; + static const jint MASK_ALL = 511; +private: + static const jint MASK_VISUAL_STRUCTURE = -2147483647 - 1; +public: // actually package-private + ::gnu::gcj::xlib::Display * __attribute__((aligned(__alignof__( ::java::lang::Object)))) display; + ::gnu::gcj::RawData * xVisualInfo; + jint infoMask; + ::gnu::gcj::xlib::Screen * screen; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_Visual__ diff --git a/libjava/gnu/gcj/xlib/Visual.java b/libjava/gnu/gcj/xlib/Visual.java new file mode 100644 index 000000000..46fd3ee99 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Visual.java @@ -0,0 +1,152 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; + +/** + * A visual determines how a color is encoded into a pixel/bitfield + * value. It does not determine how the pixel/bitfield value is + * encoded into the image data. + * + * <p>This class encapsulates all three Xlib representations of a + * visual. + * + * <ul> + * + * <li>int: visual id. + * + * <li>Visual: opaque data structure used by a lot of Xlib functions. + * + * <li>VisualInfo: transparent data structure that binds the visual to + * a certain screen and depth. + * + * </ul> + * + * <p>Implementation note: This class does not examine nor manipulate + * the Visual structure, since the X manual says the structure is + * opaque, and that XVisualInfo should be used instead.</p> + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public final class Visual +{ + public static final int VC_STATIC_GRAY = 0, + VC_GRAY_SCALE = 1, + VC_STATIC_COLOR = 2, + VC_PSEUDO_COLOR = 3, + VC_TRUE_COLOR = 4, + VC_DIRECT_COLOR = 5; + + protected static final int MASK_ID = 1 << 0, + MASK_SCREEN = 1 << 1, + MASK_DEPTH = 1 << 2, + MASK_CLASS = 1 << 3, + MASK_RED = 1 << 4, + MASK_GREEN = 1 << 5, + MASK_BLUE = 1 << 6, + MASK_COLORMAP_SIZE = 1 << 7, + MASK_BITS_PER_RGB = 1 << 8; + + protected static final int MASK_ALL = MASK_ID + | MASK_SCREEN + | MASK_DEPTH + | MASK_CLASS + | MASK_RED + | MASK_GREEN + | MASK_BLUE + | MASK_COLORMAP_SIZE + | MASK_BITS_PER_RGB; + + private static final int MASK_VISUAL_STRUCTURE = 1 << 31; + + Display display; + RawData xVisualInfo; + int infoMask; + Screen screen; + + Visual(RawData structure, Screen screen, int depth ) + { + this.display = screen.getDisplay(); + this.screen = screen; + init(structure, depth); + } + + Visual(Display display, RawData structure, int depth ) + { + this.display = display; + init(structure, depth); + } + + protected native void init(RawData structure, int depth); + + protected native void finalize(); + + /** + * + * Returns the a reference to the visual structure. This method has + * package accessibility since the data visual structure is only + * useful for direct Xlib calls. + * + * @return a pointer to the visual structure. + */ + native RawData getVisualStructure(); + + + // These methods only make sense if the visual is decomposed: + + public native int getRedMask(); + public native int getGreenMask(); + public native int getBlueMask(); + + public native int getScreenNumber(); + public native int getDepth(); + + public Screen getScreen() + { + if (screen == null) + screen = new Screen(display, getScreenNumber()); + return screen; + } + + public native int getVisualClass(); + + public boolean hasRGBSubfields() + { + switch (getVisualClass()) + { + case VC_TRUE_COLOR: + case VC_DIRECT_COLOR: + return true; + default: + return false; + } + } + + protected native void ensureXVisualInfo(int requiredMask); + + + public String toString() + { + int missingInfo = ~infoMask; + boolean hasSubfieldInfo = + (missingInfo & (MASK_CLASS|MASK_RED|MASK_GREEN|MASK_BLUE)) == 0; + + boolean hasDepth = (missingInfo & MASK_DEPTH) == 0; + + return getClass().getName() + "[" + + (hasDepth ? "depth=" + getDepth() : "") + + (hasRGBSubfields() ? + (", redMask=" + Integer.toHexString(getRedMask()) + + ", greenMask=" + Integer.toHexString(getGreenMask()) + + ", blueMask=" + Integer.toHexString(getBlueMask())) : + ", no-subfields") + ", class=" + getVisualClass() + + "]"; + } +} diff --git a/libjava/gnu/gcj/xlib/WMSizeHints.h b/libjava/gnu/gcj/xlib/WMSizeHints.h new file mode 100644 index 000000000..2acd58c45 --- /dev/null +++ b/libjava/gnu/gcj/xlib/WMSizeHints.h @@ -0,0 +1,46 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_WMSizeHints__ +#define __gnu_gcj_xlib_WMSizeHints__ + +#pragma interface + +#include <java/lang/Object.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class WMSizeHints; + class Window; + } + } + } +} + +class gnu::gcj::xlib::WMSizeHints : public ::java::lang::Object +{ + +public: + WMSizeHints(); +private: + void init(::gnu::gcj::xlib::WMSizeHints *); +public: // actually protected + virtual void finalize(); +public: + virtual ::java::lang::Object * clone(); + virtual void applyNormalHints(::gnu::gcj::xlib::Window *); + virtual void setMinSize(jint, jint); + virtual void setMaxSize(jint, jint); +public: // actually package-private + ::gnu::gcj::RawData * __attribute__((aligned(__alignof__( ::java::lang::Object)))) structure; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_WMSizeHints__ diff --git a/libjava/gnu/gcj/xlib/WMSizeHints.java b/libjava/gnu/gcj/xlib/WMSizeHints.java new file mode 100644 index 000000000..c0b198c58 --- /dev/null +++ b/libjava/gnu/gcj/xlib/WMSizeHints.java @@ -0,0 +1,52 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; + +/** + * Size hints for an X11 window in its normal state. This class wraps + * the Xlib XSizeHints stucture. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class WMSizeHints implements Cloneable +{ + public WMSizeHints() + { + init(null); + } + + private native void init(WMSizeHints copyFrom); + protected native void finalize(); + + public Object clone() { + try + { + WMSizeHints hints = (WMSizeHints) super.clone(); + // In case of an exception before the stucture is copied. + hints.structure = null; + + hints.init(this); + return hints; + } + catch (CloneNotSupportedException ex) + { + // This should never happen. + throw new InternalError (); + } + } + + public native void applyNormalHints(Window window); + + public native void setMinSize(int width, int height); + public native void setMaxSize(int width, int height); + + RawData structure; +} diff --git a/libjava/gnu/gcj/xlib/Window.h b/libjava/gnu/gcj/xlib/Window.h new file mode 100644 index 000000000..03ece8aeb --- /dev/null +++ b/libjava/gnu/gcj/xlib/Window.h @@ -0,0 +1,69 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_Window__ +#define __gnu_gcj_xlib_Window__ + +#pragma interface + +#include <gnu/gcj/xlib/Drawable.h> +#include <gcj/array.h> + +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class Display; + class Visual; + class Window; + class WindowAttributes; + } + } + } + namespace java + { + namespace awt + { + class Rectangle; + } + } +} + +class gnu::gcj::xlib::Window : public ::gnu::gcj::xlib::Drawable +{ + +public: + Window(::gnu::gcj::xlib::Window *, ::java::awt::Rectangle *, ::gnu::gcj::xlib::WindowAttributes *); + Window(::gnu::gcj::xlib::Window *, ::java::awt::Rectangle *, ::gnu::gcj::xlib::WindowAttributes *, ::gnu::gcj::xlib::Visual *); + Window(::gnu::gcj::xlib::Window *, ::java::awt::Rectangle *, jint, ::gnu::gcj::xlib::WindowAttributes *, jint, ::gnu::gcj::xlib::Visual *); +public: // actually protected + Window(::gnu::gcj::xlib::Display *, jint); + virtual void finalize(); + virtual void destroy(); + virtual jint createChildXID(::java::awt::Rectangle *, jint, ::gnu::gcj::xlib::WindowAttributes *, jint, ::gnu::gcj::xlib::Visual *); +public: + virtual void setAttributes(::gnu::gcj::xlib::WindowAttributes *); + virtual void map(); + virtual void unmap(); + virtual void toFront(); + virtual void toBack(); + virtual void setProperty(jint, jint, JArray< jbyte > *); + virtual void setProperty(jint, jint, ::java::lang::String *); + virtual void setWMProtocols(JArray< jint > *); + virtual JArray< jint > * getWMProtocols(); + virtual void setProperty(::java::lang::String *, ::java::lang::String *, ::java::lang::String *); + virtual void setBounds(jint, jint, jint, jint); + static const jint COPY_FROM_PARENT = 0; + static const jint INPUT_OUTPUT = 1; + static const jint INPUT_ONLY = 2; +public: // actually protected + jboolean __attribute__((aligned(__alignof__( ::gnu::gcj::xlib::Drawable)))) owned; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_Window__ diff --git a/libjava/gnu/gcj/xlib/Window.java b/libjava/gnu/gcj/xlib/Window.java new file mode 100644 index 000000000..3ff3657c4 --- /dev/null +++ b/libjava/gnu/gcj/xlib/Window.java @@ -0,0 +1,106 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; +import java.awt.Rectangle; + +/** + * An X11 window. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class Window extends Drawable +{ + // Must correspond with X.h definitions: + public static final int COPY_FROM_PARENT = 0; + public static final int INPUT_OUTPUT = 1; + public static final int INPUT_ONLY = 2; + + public Window(Window parent, Rectangle bounds, + WindowAttributes attributes) + { + this(parent, bounds, attributes, null); + } + + public Window(Window parent, Rectangle bounds, + WindowAttributes attributes, Visual visual) + { + this(parent, bounds, 0, attributes, COPY_FROM_PARENT, visual); + } + + public Window(Window parent, Rectangle bounds, int borderWidth, + WindowAttributes attributes, int windowIOClass, + Visual visual) + { + this(parent.display, + parent.createChildXID(bounds, borderWidth, attributes, + windowIOClass, visual)); + this.owned = true; + } + + protected Window(Display display, int xid) + { + super(display, xid); + display.addXID(xid, this); + } + + protected void finalize() + { + display.removeXID(xid); + if (owned) + { + destroy(); + owned = false; + } + } + + protected native void destroy(); + + protected native int createChildXID(Rectangle bounds, + int borderWidth, + WindowAttributes attributes, + int windowIOClass, + Visual visual); + + public native void setAttributes(WindowAttributes attributes); + + public native void map(); + public native void unmap(); + public native void toFront(); + public native void toBack(); + + protected boolean owned = false; + + public native void setProperty(int nameAtom, int typeAtom, byte[] data); + + public void setProperty(int nameAtom, int typeAtom, String data) + { + int length = data.length(); + byte[] byteData = new byte[length]; + + for (int i=0; i<length; i++) + byteData[i] = (byte) data.charAt(i); + + setProperty(nameAtom, typeAtom, byteData); + } + + public native void setWMProtocols(int[] atoms); + public native int[] getWMProtocols(); + + public void setProperty(String nameAtom, String typeAtom, String data) + { + int xaName = display.getAtom(nameAtom); + int xaType = display.getAtom(typeAtom); + + setProperty(xaName, xaType, data); + } + + public native void setBounds(int x, int y, int width, int height); +} diff --git a/libjava/gnu/gcj/xlib/WindowAttributes.h b/libjava/gnu/gcj/xlib/WindowAttributes.h new file mode 100644 index 000000000..6c533033d --- /dev/null +++ b/libjava/gnu/gcj/xlib/WindowAttributes.h @@ -0,0 +1,66 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_WindowAttributes__ +#define __gnu_gcj_xlib_WindowAttributes__ + +#pragma interface + +#include <java/lang/Object.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class Display; + class Pixmap; + class Visual; + class Window; + class WindowAttributes; + } + } + } +} + +class gnu::gcj::xlib::WindowAttributes : public ::java::lang::Object +{ + +public: + WindowAttributes(); + WindowAttributes(::gnu::gcj::xlib::Window *); +private: + void initFromWindow(::gnu::gcj::xlib::Window *); + void init(::gnu::gcj::xlib::WindowAttributes *); +public: // actually protected + virtual void finalize(); +public: + virtual ::java::lang::Object * clone(); + virtual void setBackground(jlong); + virtual void setBackground(::gnu::gcj::xlib::Pixmap *); + virtual void setEventMask(jlong); + virtual void setVisual(::gnu::gcj::xlib::Visual *); + virtual ::gnu::gcj::xlib::Visual * getVisual(); + virtual void apply(::gnu::gcj::xlib::Window *); +public: // actually package-private + virtual ::gnu::gcj::RawData * getXSetWindowAttributesStructure(); + virtual void initOut(); +public: + static const jlong MASK_BUTTON_PRESS = 4LL; + static const jlong MASK_BUTTON_RELEASE = 8LL; + static const jlong MASK_EXPOSURE = 32768LL; + static const jlong MASK_STRUCTURE_NOTIFY = 131072LL; +public: // actually package-private + ::gnu::gcj::xlib::Display * __attribute__((aligned(__alignof__( ::java::lang::Object)))) display; + ::gnu::gcj::RawData * in; + ::gnu::gcj::RawData * out; + jlong mask; + ::gnu::gcj::xlib::Visual * visual; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_WindowAttributes__ diff --git a/libjava/gnu/gcj/xlib/WindowAttributes.java b/libjava/gnu/gcj/xlib/WindowAttributes.java new file mode 100644 index 000000000..23be37d63 --- /dev/null +++ b/libjava/gnu/gcj/xlib/WindowAttributes.java @@ -0,0 +1,114 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; +import gnu.gcj.RawData; + +/** + * + * Collection of attributes that can be applied to or read from an + * X11 window. + * + * <p>TODO: Split this class into two classes. One for the structure + * XSetWindowAttributes and one for the XWindowAttributes. However + * they should still share this common base class. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> */ +public class WindowAttributes +{ + // Must match definitions in X.h: + public final static long MASK_BUTTON_PRESS = 1L<< 2, + MASK_BUTTON_RELEASE = 1L<< 3, + MASK_EXPOSURE = 1L<<15, + MASK_STRUCTURE_NOTIFY = 1L<<17; + + public WindowAttributes() + { + init(null); + } + + public WindowAttributes(Window from) + { + initFromWindow(from); + } + + private native void initFromWindow(Window from); + private native void init(WindowAttributes copyFrom); + protected native void finalize(); + + public Object clone() + { + try + { + WindowAttributes attributes = (WindowAttributes) super.clone(); + // In case of an exception before the stucture is copied. + attributes.in = null; + attributes.out = null; + + // FIXME: do anything else? + + attributes.init(this); + return attributes; + } + catch (CloneNotSupportedException ex) + { + // This should never happen. + throw new InternalError (); + } + } + + public native void setBackground(long pixel); + public native void setBackground(Pixmap pixmap); + public native void setEventMask(long eventMask); + + public void setVisual(Visual visual) + { + this.visual = visual; + } + + /** + * Retrieve the visual. + * + * @return the visual that is or should be used by a window. null + * means CopyFormParent. + */ + public native Visual getVisual(); + + Display display; + + /** + * Reference to XWindowAttribute structure containing attributes + * read from a window. + */ + RawData in = null; + + /** + * Reference to XSetWindowAttribute structure containing attributes + * to be applied to a window. + */ + RawData out = null; + + long mask; + + /** null means CopyFromParent during window creation. */ + Visual visual = null; + + public native void apply(Window window); + + final RawData getXSetWindowAttributesStructure() + { + if (out == null) + initOut(); + return out; + } + + void initOut() + { + throw new UnsupportedOperationException("not implemented yet"); + } +} diff --git a/libjava/gnu/gcj/xlib/XAnyEvent.h b/libjava/gnu/gcj/xlib/XAnyEvent.h new file mode 100644 index 000000000..9a7096e35 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XAnyEvent.h @@ -0,0 +1,89 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XAnyEvent__ +#define __gnu_gcj_xlib_XAnyEvent__ + +#pragma interface + +#include <java/lang/Object.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class Display; + class Window; + class XAnyEvent; + } + } + } +} + +class gnu::gcj::xlib::XAnyEvent : public ::java::lang::Object +{ + +public: + XAnyEvent(::gnu::gcj::xlib::Display *); +private: + void init(); +public: // actually protected + void finalize(); +public: + jboolean loadNext(jboolean); + void interrupt(); + jint getType(); + void setType(jint); + ::gnu::gcj::xlib::Window * getWindow(); + void setWindow(::gnu::gcj::xlib::Window *); + jlong getSerial(); + void send(::gnu::gcj::xlib::Window *, jboolean, jlong); + ::java::lang::String * toString(); + static const jint TYPE_KEY_PRESS = 2; + static const jint TYPE_KEY_RELEASE = 3; + static const jint TYPE_BUTTON_PRESS = 4; + static const jint TYPE_BUTTON_RELEASE = 5; + static const jint TYPE_MOTION_NOTIFY = 6; + static const jint TYPE_ENTER_NOTIFY = 7; + static const jint TYPE_LEAVE_NOTIFY = 8; + static const jint TYPE_FOCUS_IN = 9; + static const jint TYPE_FOCUS_OUT = 10; + static const jint TYPE_KEYMAP_NOTIFY = 11; + static const jint TYPE_EXPOSE = 12; + static const jint TYPE_GRAPHICS_EXPOSE = 13; + static const jint TYPE_NO_EXPOSE = 14; + static const jint TYPE_VISIBILITY_NOTIFY = 15; + static const jint TYPE_CREATE_NOTIFY = 16; + static const jint TYPE_DESTROY_NOTIFY = 17; + static const jint TYPE_UNMAP_NOTIFY = 18; + static const jint TYPE_MAP_NOTIFY = 19; + static const jint TYPE_MAP_REQUEST = 20; + static const jint TYPE_REPARENT_NOTIFY = 21; + static const jint TYPE_CONFIGURE_NOTIFY = 22; + static const jint TYPE_CONFIGURE_REQUEST = 23; + static const jint TYPE_GRAVITY_NOTIFY = 24; + static const jint TYPE_RESIZE_REQUEST = 25; + static const jint TYPE_CIRCULATE_NOTIFY = 26; + static const jint TYPE_CIRCULATE_REQUEST = 27; + static const jint TYPE_PROPERTY_NOTIFY = 28; + static const jint TYPE_SELECTION_CLEAR = 29; + static const jint TYPE_SELECTION_REQUEST = 30; + static const jint TYPE_SELECTION_NOTIFY = 31; + static const jint TYPE_COLORMAP_NOTIFY = 32; + static const jint TYPE_CLIENT_MESSAGE = 33; + static const jint TYPE_MAPPING_NOTIFY = 34; + static const jlong MASK_SUBSTRUCTURE_NOTIFY = 524288LL; + static const jlong MASK_SUBSTRUCTURE_REDIRECT = 1048576LL; +public: // actually package-private + ::gnu::gcj::RawData * __attribute__((aligned(__alignof__( ::java::lang::Object)))) pipefds; + ::gnu::gcj::RawData * structure; + ::gnu::gcj::xlib::Display * display; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XAnyEvent__ diff --git a/libjava/gnu/gcj/xlib/XAnyEvent.java b/libjava/gnu/gcj/xlib/XAnyEvent.java new file mode 100644 index 000000000..bce3a6150 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XAnyEvent.java @@ -0,0 +1,103 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; + +/** + * Mutable event structure that can contain any data from any event + * type. Events can be constructed or loaded from the event queue. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public final class XAnyEvent +{ + // Must match the definitions in X.h: + public static final int + TYPE_KEY_PRESS = 2, + TYPE_KEY_RELEASE = 3, + TYPE_BUTTON_PRESS = 4, + TYPE_BUTTON_RELEASE = 5, + TYPE_MOTION_NOTIFY = 6, + TYPE_ENTER_NOTIFY = 7, + TYPE_LEAVE_NOTIFY = 8, + TYPE_FOCUS_IN = 9, + TYPE_FOCUS_OUT = 10, + TYPE_KEYMAP_NOTIFY = 11, + TYPE_EXPOSE = 12, + TYPE_GRAPHICS_EXPOSE = 13, + TYPE_NO_EXPOSE = 14, + TYPE_VISIBILITY_NOTIFY = 15, + TYPE_CREATE_NOTIFY = 16, + TYPE_DESTROY_NOTIFY = 17, + TYPE_UNMAP_NOTIFY = 18, + TYPE_MAP_NOTIFY = 19, + TYPE_MAP_REQUEST = 20, + TYPE_REPARENT_NOTIFY = 21, + TYPE_CONFIGURE_NOTIFY = 22, + TYPE_CONFIGURE_REQUEST = 23, + TYPE_GRAVITY_NOTIFY = 24, + TYPE_RESIZE_REQUEST = 25, + TYPE_CIRCULATE_NOTIFY = 26, + TYPE_CIRCULATE_REQUEST = 27, + TYPE_PROPERTY_NOTIFY = 28, + TYPE_SELECTION_CLEAR = 29, + TYPE_SELECTION_REQUEST = 30, + TYPE_SELECTION_NOTIFY = 31, + TYPE_COLORMAP_NOTIFY = 32, + TYPE_CLIENT_MESSAGE = 33, + TYPE_MAPPING_NOTIFY = 34; + + // Must match the definitions in X.h: + public final static long MASK_SUBSTRUCTURE_NOTIFY = 1L<<19, + MASK_SUBSTRUCTURE_REDIRECT = 1L<<20; + + public XAnyEvent(Display display) + { + this.display = display; + init(); + } + + private native void init(); + protected native void finalize(); + + /** + * Load next event into the event structure. + */ + public native boolean loadNext(boolean block); + public native void interrupt(); + + public native int getType(); + public native void setType(int type); + + public native Window getWindow(); + public native void setWindow(Window window); + + /** + * @returns the number of the last request processed by the server. + */ + public native long getSerial(); + + public native void send(Window destination, boolean propagate, + long mask); + + RawData pipefds; + RawData structure; + Display display; + + public String toString() + { + if (structure == null) + return getClass().getName() + "[no-structure]"; + + return getClass().getName() + + "[type=" + getType() + + ",window=" + getWindow() + "]"; + } +} diff --git a/libjava/gnu/gcj/xlib/XButtonEvent.h b/libjava/gnu/gcj/xlib/XButtonEvent.h new file mode 100644 index 000000000..7b482c44f --- /dev/null +++ b/libjava/gnu/gcj/xlib/XButtonEvent.h @@ -0,0 +1,49 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XButtonEvent__ +#define __gnu_gcj_xlib_XButtonEvent__ + +#pragma interface + +#include <gnu/gcj/xlib/XEvent.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class XAnyEvent; + class XButtonEvent; + } + } + } +} + +class gnu::gcj::xlib::XButtonEvent : public ::gnu::gcj::xlib::XEvent +{ + +public: + XButtonEvent(::gnu::gcj::xlib::XAnyEvent *); +public: // actually package-private + virtual void init(); +public: + static const jint MASK_SHIFT = 1; + static const jint MASK_LOCK = 2; + static const jint MASK_CONTROL = 4; + static const jint MASK_MOD1 = 8; + static const jint MASK_MOD2 = 16; + static const jint MASK_MOD3 = 32; + static const jint MASK_MOD4 = 64; + static const jint MASK_MOD5 = 128; + jlong __attribute__((aligned(__alignof__( ::gnu::gcj::xlib::XEvent)))) time; + jint x; + jint y; + jint state; + jint button; + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XButtonEvent__ diff --git a/libjava/gnu/gcj/xlib/XButtonEvent.java b/libjava/gnu/gcj/xlib/XButtonEvent.java new file mode 100644 index 000000000..032830b2c --- /dev/null +++ b/libjava/gnu/gcj/xlib/XButtonEvent.java @@ -0,0 +1,53 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +/** + * Interprets data from an Xlib XButtonEvent into members of java + * primitive types. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class XButtonEvent extends XEvent +{ + + // Must match the definition in X.h: + public static final int MASK_SHIFT = 1<<0, + MASK_LOCK = 1<<1, + MASK_CONTROL = 1<<2, + MASK_MOD1 = 1<<3, + MASK_MOD2 = 1<<4, + MASK_MOD3 = 1<<5, + MASK_MOD4 = 1<<6, + MASK_MOD5 = 1<<7; + + public XButtonEvent(XAnyEvent event) + { + super(event); + + // FIXME: Avoid double checking? + if ((event.getType() != XAnyEvent.TYPE_BUTTON_PRESS) && + (event.getType() != XAnyEvent.TYPE_BUTTON_RELEASE)) + { + throw new IllegalArgumentException("Wrong event type"); + } + init(); + } + + native void init(); + + public long time; + public int x; + public int y; + public int state; + public int button; +} + + + diff --git a/libjava/gnu/gcj/xlib/XColor.h b/libjava/gnu/gcj/xlib/XColor.h new file mode 100644 index 000000000..fa2ea6958 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XColor.h @@ -0,0 +1,48 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XColor__ +#define __gnu_gcj_xlib_XColor__ + +#pragma interface + +#include <java/lang/Object.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class XColor; + } + } + } +} + +class gnu::gcj::xlib::XColor : public ::java::lang::Object +{ + +public: + XColor(jint, jint, jint); + XColor(); +private: + void init(); +public: // actually protected + void finalize(); +public: + void setRGB(jint, jint, jint); + jint getRed(); + jint getGreen(); + jint getBlue(); + jbyte getFlags(); + jlong getPixelValue(); +public: // actually package-private + ::gnu::gcj::RawData * __attribute__((aligned(__alignof__( ::java::lang::Object)))) structure; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XColor__ diff --git a/libjava/gnu/gcj/xlib/XColor.java b/libjava/gnu/gcj/xlib/XColor.java new file mode 100644 index 000000000..74ad6d707 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XColor.java @@ -0,0 +1,42 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; + +/** + * A color or color-cell on the X server. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public final class XColor +{ + public XColor(int r, int g, int b) + { + this(); + setRGB(r, g, b); + } + + public XColor() + { + init(); + } + + private native void init(); + protected native void finalize(); + + public final native void setRGB(int r, int g, int b); + public final native int getRed(); + public final native int getGreen(); + public final native int getBlue(); + public final native byte getFlags(); + public final native long getPixelValue(); + + RawData structure = null; +} diff --git a/libjava/gnu/gcj/xlib/XConfigureEvent.h b/libjava/gnu/gcj/xlib/XConfigureEvent.h new file mode 100644 index 000000000..cbc402d6c --- /dev/null +++ b/libjava/gnu/gcj/xlib/XConfigureEvent.h @@ -0,0 +1,41 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XConfigureEvent__ +#define __gnu_gcj_xlib_XConfigureEvent__ + +#pragma interface + +#include <gnu/gcj/xlib/XEvent.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class XAnyEvent; + class XConfigureEvent; + } + } + } + namespace java + { + namespace awt + { + class Rectangle; + } + } +} + +class gnu::gcj::xlib::XConfigureEvent : public ::gnu::gcj::xlib::XEvent +{ + +public: + XConfigureEvent(::gnu::gcj::xlib::XAnyEvent *); + virtual ::java::awt::Rectangle * getBounds(); + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XConfigureEvent__ diff --git a/libjava/gnu/gcj/xlib/XConfigureEvent.java b/libjava/gnu/gcj/xlib/XConfigureEvent.java new file mode 100644 index 000000000..0d069ea03 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XConfigureEvent.java @@ -0,0 +1,32 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import java.awt.Rectangle; + +/** + * Interprets and retrieves data from an Xlib XConfigureEvent. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class XConfigureEvent extends XEvent +{ + public XConfigureEvent(XAnyEvent event) + { + super(event); + // FIXME: Avoid double checking? + if (event.getType() != XAnyEvent.TYPE_CONFIGURE_NOTIFY) + throw new IllegalArgumentException("Wrong event type"); + } + + public native Rectangle getBounds(); +} + + + diff --git a/libjava/gnu/gcj/xlib/XConnectException.h b/libjava/gnu/gcj/xlib/XConnectException.h new file mode 100644 index 000000000..a234ec90e --- /dev/null +++ b/libjava/gnu/gcj/xlib/XConnectException.h @@ -0,0 +1,33 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XConnectException__ +#define __gnu_gcj_xlib_XConnectException__ + +#pragma interface + +#include <java/io/IOException.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class XConnectException; + } + } + } +} + +class gnu::gcj::xlib::XConnectException : public ::java::io::IOException +{ + +public: + XConnectException(); + XConnectException(::java::lang::String *); + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XConnectException__ diff --git a/libjava/gnu/gcj/xlib/XConnectException.java b/libjava/gnu/gcj/xlib/XConnectException.java new file mode 100644 index 000000000..829da660c --- /dev/null +++ b/libjava/gnu/gcj/xlib/XConnectException.java @@ -0,0 +1,30 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import java.io.IOException; + +/** + * Indicates that something went wrong with the connection to an X11 + * display. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class XConnectException extends IOException +{ + public XConnectException() + { + super(); + } + + public XConnectException(String message) + { + super(message); + } +} diff --git a/libjava/gnu/gcj/xlib/XEvent.h b/libjava/gnu/gcj/xlib/XEvent.h new file mode 100644 index 000000000..d74a31c3e --- /dev/null +++ b/libjava/gnu/gcj/xlib/XEvent.h @@ -0,0 +1,40 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XEvent__ +#define __gnu_gcj_xlib_XEvent__ + +#pragma interface + +#include <java/lang/Object.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class Display; + class XAnyEvent; + class XEvent; + } + } + } +} + +class gnu::gcj::xlib::XEvent : public ::java::lang::Object +{ + +public: + XEvent(::gnu::gcj::xlib::XAnyEvent *); + XEvent(jint, ::gnu::gcj::xlib::Display *); + virtual ::gnu::gcj::xlib::XAnyEvent * getXAnyEvent(); + virtual ::java::lang::String * toString(); +public: // actually package-private + ::gnu::gcj::xlib::XAnyEvent * __attribute__((aligned(__alignof__( ::java::lang::Object)))) event; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XEvent__ diff --git a/libjava/gnu/gcj/xlib/XEvent.java b/libjava/gnu/gcj/xlib/XEvent.java new file mode 100644 index 000000000..75f602a82 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XEvent.java @@ -0,0 +1,45 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; + +/** + * Base class for interpreters of specific X event types. For methods + * concerning all X events, see XAnyEvent. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class XEvent +{ + public XEvent(XAnyEvent event) + { + this.event = event; + } + + public XEvent(int type, Display display) + { + this(new XAnyEvent(display)); + event.setType(type); + } + + XAnyEvent event; + + public XAnyEvent getXAnyEvent() + { + return event; + } + + public String toString() + { + if (event == null) + return super.toString(); + return event.toString(); + } +} diff --git a/libjava/gnu/gcj/xlib/XException.h b/libjava/gnu/gcj/xlib/XException.h new file mode 100644 index 000000000..de1eff0f4 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XException.h @@ -0,0 +1,38 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XException__ +#define __gnu_gcj_xlib_XException__ + +#pragma interface + +#include <java/lang/RuntimeException.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class Display; + class XException; + } + } + } +} + +class gnu::gcj::xlib::XException : public ::java::lang::RuntimeException +{ + +public: + XException(); + XException(::java::lang::String *); + XException(::gnu::gcj::xlib::Display *, jint); +public: // actually package-private + static ::java::lang::String * toString(::gnu::gcj::xlib::Display *, jint); +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XException__ diff --git a/libjava/gnu/gcj/xlib/XException.java b/libjava/gnu/gcj/xlib/XException.java new file mode 100644 index 000000000..32adfc146 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XException.java @@ -0,0 +1,27 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +/** + * Runtime exception that occurred during an Xlib operation. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class XException extends RuntimeException +{ + public XException() {} + public XException(String msg) { super(msg); } + + public XException(Display display, int status) + { + super(toString(display, status)); + } + + static native String toString(Display display, int status); +} diff --git a/libjava/gnu/gcj/xlib/XExposeEvent.h b/libjava/gnu/gcj/xlib/XExposeEvent.h new file mode 100644 index 000000000..ac8715bd6 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XExposeEvent.h @@ -0,0 +1,41 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XExposeEvent__ +#define __gnu_gcj_xlib_XExposeEvent__ + +#pragma interface + +#include <gnu/gcj/xlib/XEvent.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class XAnyEvent; + class XExposeEvent; + } + } + } + namespace java + { + namespace awt + { + class Rectangle; + } + } +} + +class gnu::gcj::xlib::XExposeEvent : public ::gnu::gcj::xlib::XEvent +{ + +public: + XExposeEvent(::gnu::gcj::xlib::XAnyEvent *); + virtual ::java::awt::Rectangle * getBounds(); + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XExposeEvent__ diff --git a/libjava/gnu/gcj/xlib/XExposeEvent.java b/libjava/gnu/gcj/xlib/XExposeEvent.java new file mode 100644 index 000000000..2c29cf131 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XExposeEvent.java @@ -0,0 +1,33 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import java.awt.Rectangle; + +/** + * Interprets data from an Xlib XExposeEvent. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class XExposeEvent extends XEvent +{ + public XExposeEvent(XAnyEvent event) + { + super(event); + + // FIXME: Avoid double checking? + if (event.getType() != XAnyEvent.TYPE_EXPOSE) + throw new IllegalArgumentException("Wrong event type"); + } + + public native Rectangle getBounds(); +} + + + diff --git a/libjava/gnu/gcj/xlib/XID.h b/libjava/gnu/gcj/xlib/XID.h new file mode 100644 index 000000000..d216df65e --- /dev/null +++ b/libjava/gnu/gcj/xlib/XID.h @@ -0,0 +1,47 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XID__ +#define __gnu_gcj_xlib_XID__ + +#pragma interface + +#include <java/lang/Object.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class Display; + class XID; + } + } + } +} + +class gnu::gcj::xlib::XID : public ::java::lang::Object +{ + +public: + XID(::gnu::gcj::xlib::Display *, jint); + virtual jint getXID(); + virtual ::gnu::gcj::xlib::Display * getDisplay(); + virtual ::java::lang::Object * getClientData(); + virtual void setClientData(::java::lang::Object *); +public: // actually protected + virtual ::java::lang::String * params(); +public: + virtual ::java::lang::String * toString(); +public: // actually protected + ::gnu::gcj::xlib::Display * __attribute__((aligned(__alignof__( ::java::lang::Object)))) display; + jint xid; +private: + ::java::lang::Object * clientData; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XID__ diff --git a/libjava/gnu/gcj/xlib/XID.java b/libjava/gnu/gcj/xlib/XID.java new file mode 100644 index 000000000..f7bb9cfc9 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XID.java @@ -0,0 +1,58 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +/** + * Common base class for all resources that are stored on the server + * and refered to on the client side using XIDs. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class XID +{ + public XID(Display display, int xid) + { + this.display = display; + this.xid = xid; + } + + public final int getXID() + { + return xid; + } + + public final Display getDisplay() + { + return display; + } + + protected Display display; + protected int xid; + + private Object clientData; + public final Object getClientData() + { + return clientData; + } + public final void setClientData(Object clientData) + { + this.clientData = clientData; + } + + protected String params() + { + return "display=" + display + ",xid=" + Integer.toHexString(xid); + } + + public String toString() + { + return getClass().getName() + + "[" + params() + "]"; + } +} diff --git a/libjava/gnu/gcj/xlib/XImage.h b/libjava/gnu/gcj/xlib/XImage.h new file mode 100644 index 000000000..679c60de6 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XImage.h @@ -0,0 +1,82 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XImage__ +#define __gnu_gcj_xlib_XImage__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + namespace xlib + { + class Visual; + class XImage; + } + } + } +} + +class gnu::gcj::xlib::XImage : public ::java::lang::Object +{ + +public: + XImage(::gnu::gcj::xlib::Visual *, jint, jint, jint, jint, jint, jint, jint); + XImage(::gnu::gcj::xlib::Visual *, jint, jint, jint, jint, jint, jint, jint, jint); + virtual void init(::gnu::gcj::xlib::Visual *, jint, jint, jint, jint, jint, jint, jint, jint); +private: + void init(::gnu::gcj::xlib::Visual *, jint, jint); +public: + XImage(::gnu::gcj::xlib::Visual *, jint, jint); + XImage(::gnu::gcj::xlib::Visual *, jint, jint, jboolean); + virtual void setData(JArray< jbyte > *, jint); + virtual void setData(JArray< jshort > *, jint); + virtual void setData(JArray< jint > *, jint); +private: + void internalSetData(JArray< jbyte > *, jint); + void internalSetData(JArray< jshort > *, jint); + void internalSetData(JArray< jint > *, jint); +public: // actually protected + virtual void finalize(); +public: + virtual jint getWidth(); + virtual jint getHeight(); + virtual jint getDepth(); + virtual jint getFormat(); + virtual jboolean isZPixmapFormat(); + virtual jint getXOffset(); + virtual jint getBytesPerLine(); + virtual jint getBitsPerPixel(); + virtual jint getImageByteOrder(); + virtual jint getBitmapBitOrder(); + virtual jint getBitmapUnit(); + virtual jint getBitmapPad(); + virtual jint getRedMask(); + virtual jint getGreenMask(); + virtual jint getBlueMask(); + virtual void setPixel(jint, jint, jint); + virtual ::java::lang::String * toString(); +public: // actually package-private + ::java::lang::Object * __attribute__((aligned(__alignof__( ::java::lang::Object)))) dataRef; +public: + static const jint XYBITMAP_FORMAT = 0; + static const jint XYPIXMAP_FORMAT = 1; + static const jint ZPIXMAP_FORMAT = 2; + static const jint LEAST_SIGNIFICANT_B_FIRST_ORDER = 0; + static const jint MOST_SIGNIFICANT_B_FIRST_ORDER = 1; +public: // actually package-private + jboolean ownsData; + ::gnu::gcj::RawData * structure; +public: + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XImage__ diff --git a/libjava/gnu/gcj/xlib/XImage.java b/libjava/gnu/gcj/xlib/XImage.java new file mode 100644 index 000000000..5460549e0 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XImage.java @@ -0,0 +1,235 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; + +/** + * Structure containing image data that resides on the client side. + * The format, depth and offset attributes of an XImage determines how + * bitfields are encoded in a raster image. However, it does not + * determine how a color is encoded into a bitfield. I.e. the XImage + * pixel values in a specific structure, but does not determine what + * colors that will be used to represent these pixel values on the + * screen. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class XImage +{ + /** This object reference points to the data, hindering garbage + collection of the data. */ + Object dataRef; + + // Must match definitions in X.h: + public static final int XYBITMAP_FORMAT = 0, + XYPIXMAP_FORMAT = 1, + ZPIXMAP_FORMAT = 2; + + // Must match definitions in X.h: + public static final int LEAST_SIGNIFICANT_B_FIRST_ORDER = 0, + MOST_SIGNIFICANT_B_FIRST_ORDER = 1; + + public XImage(Visual visual, int depth, int format, int xoffset, + int width, int height, int bitmapPad, + int bytesPerLine) + { + this(visual, depth, format, xoffset, width, height, bitmapPad, + bytesPerLine, + 0 // bitsPerPixel + ); + } + + public XImage(Visual visual, int depth, int format, int xoffset, + int width, int height, int bitmapPad, + int bytesPerLine, int bitsPerPixel) + { + if (visual == null) throw new + NullPointerException("a visual must be specified"); + + init(visual, depth, format, xoffset, width, height, + bitmapPad, bytesPerLine, bitsPerPixel); + } + + public native void init(Visual visual, int depth, int format, int xoffset, + int width, int height, int bitmapPad, + int bytesPerLine, int bitsPerPixel); + + private native void init(Visual visual, int width, int height); + + + public XImage(Visual visual, int width, int height) + { + this(visual, width, height, + true // Automatically allocate memory + ); + } + + /** + * Create a new XImage. + * + * @param allocate specifies whether to automatically allocate + * memory for the image. It is possible to create the data array + * elsewhere, so that we can for instance use a DataBufferUShort as + * data. Ie. not limit ourself to byte arrays. This is done by + * passing false and calling a setData() method manually after + * creation. + */ + public XImage(Visual visual, int width, int height, boolean allocate) + { + if (visual == null) + throw new NullPointerException("a visual must be specified"); + + init(visual, width, height); + + if (allocate) + { + /* Now that Xlib has figured out the appropriate bytes per + line, we can allocate memory for the image. */ + // FIXME: What about formats with several layers/bands? + byte[] data = new byte[getBytesPerLine()*height]; + + setData(data, 0); + } + } + + /** + * Attach image data to this XImage. + * + * @param offset the index of the first actual data element in the array. + */ + public void setData(byte[] data, int offset) + { + dataRef = data; + internalSetData(data, offset); + } + + /** + * Attach image data to this XImage. + * + * @param offset the index of the first actual data element in the + * array. Note: this is short offset, not a byte offset. + */ + public void setData(short[] data, int offset) + { + dataRef = data; + internalSetData(data, offset); + } + + /** + * Attach image data to this XImage + * + * @param offset the index of the first actual data element in the array. + * Note: this is not a byte offset. + */ + public void setData(int[] data, int offset) + { + dataRef = data; + internalSetData(data, offset); + } + + private native void internalSetData(byte[] data, int offset); + private native void internalSetData(short[] data, int offset); + private native void internalSetData(int[] data, int offset); + + protected native void finalize(); + + boolean ownsData = false; + RawData structure = null; + + public final native int getWidth(); + public final native int getHeight(); + public final native int getDepth(); + public final native int getFormat(); + + public final boolean isZPixmapFormat() + { + return getFormat() == ZPIXMAP_FORMAT; + } + + + /** + * Get the xoffset. The xoffset avoids the need of shifting the + * scanlines into place. + */ + public final native int getXOffset(); + + public native final int getBytesPerLine(); + public native final int getBitsPerPixel(); + + public native final int getImageByteOrder(); + public native final int getBitmapBitOrder(); + public native final int getBitmapUnit(); + public native final int getBitmapPad(); + + + // True/Direct Color specific: + public native int getRedMask(); + public native int getGreenMask(); + public native int getBlueMask(); + + + /** + * Set a pixel value at a given position in the image. This method + * is slow. Don't use it, except as a fall-back. + */ + public native final void setPixel(int x, int y, int pixel); + + public String toString() + { + String format; + switch(getFormat()) + { + case ZPIXMAP_FORMAT: + format = "ZPixmapFormat"; + break; + default: + format = "unknown"; + } + + String imageByteOrder; + switch(getImageByteOrder()) + { + case LEAST_SIGNIFICANT_B_FIRST_ORDER: + imageByteOrder = "leastSignificantByteFirst"; + break; + case MOST_SIGNIFICANT_B_FIRST_ORDER: + imageByteOrder = "mostSignificantByteFirst"; + break; + default: + imageByteOrder = "unknwon"; + } + + String bitmapBitOrder; + switch(getBitmapBitOrder()) + { + case LEAST_SIGNIFICANT_B_FIRST_ORDER: + bitmapBitOrder = "leastSignificantBitFirst"; + break; + case MOST_SIGNIFICANT_B_FIRST_ORDER: + bitmapBitOrder = "mostSignificantBitFirst"; + break; + default: + bitmapBitOrder = "unknown"; + } + + return getClass().getName() + "[" + format + + ", width=" + getWidth() + + ", height=" + getHeight() + + ", bytesPerLine=" + getBytesPerLine() + + ", xoffset=" + getXOffset() + + ", depth=" + getDepth() + + ", bitsPerPixel=" + getBitsPerPixel() + + ", bitmapUnit=" + getBitmapUnit() + + ", bitmapPad=" + getBitmapPad() + + ", byteOrder=" + imageByteOrder + + ", bitOrder=" + bitmapBitOrder + + "]"; + } +} diff --git a/libjava/gnu/gcj/xlib/XUnmapEvent.h b/libjava/gnu/gcj/xlib/XUnmapEvent.h new file mode 100644 index 000000000..a42695259 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XUnmapEvent.h @@ -0,0 +1,36 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __gnu_gcj_xlib_XUnmapEvent__ +#define __gnu_gcj_xlib_XUnmapEvent__ + +#pragma interface + +#include <gnu/gcj/xlib/XEvent.h> +extern "Java" +{ + namespace gnu + { + namespace gcj + { + namespace xlib + { + class Display; + class Window; + class XUnmapEvent; + } + } + } +} + +class gnu::gcj::xlib::XUnmapEvent : public ::gnu::gcj::xlib::XEvent +{ + +public: + XUnmapEvent(::gnu::gcj::xlib::Display *, ::gnu::gcj::xlib::Window *, ::gnu::gcj::xlib::Window *, jboolean); + virtual void setUnmappedWindow(::gnu::gcj::xlib::Window *); + virtual void setFromConfigure(jboolean); + static ::java::lang::Class class$; +}; + +#endif // __gnu_gcj_xlib_XUnmapEvent__ diff --git a/libjava/gnu/gcj/xlib/XUnmapEvent.java b/libjava/gnu/gcj/xlib/XUnmapEvent.java new file mode 100644 index 000000000..803bdba77 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XUnmapEvent.java @@ -0,0 +1,33 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +/** + * Interprets data from an Xlib XUnmapEvent. + * + * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> + */ +public class XUnmapEvent extends XEvent +{ + public XUnmapEvent(Display display, Window eventWindow, + Window unmappedWindow, + boolean fromConfigure) + { + super(XAnyEvent.TYPE_UNMAP_NOTIFY, display); + getXAnyEvent().setWindow(eventWindow); + setUnmappedWindow(unmappedWindow); + setFromConfigure(fromConfigure); + } + + public native void setUnmappedWindow(Window unmappedWindow); + public native void setFromConfigure(boolean fromConfigure); +} + + + diff --git a/libjava/gnu/gcj/xlib/natClip.cc b/libjava/gnu/gcj/xlib/natClip.cc new file mode 100644 index 000000000..a1f626dfe --- /dev/null +++ b/libjava/gnu/gcj/xlib/natClip.cc @@ -0,0 +1,56 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +// Needed to avoid linking in libstdc++ +#ifndef __STL_USE_EXCEPTIONS +# include <java/lang/OutOfMemoryError.h> +# define __THROW_BAD_ALLOC throw new java::lang::OutOfMemoryError() +#endif + +#include <vector> + +#include <X11/Xlib.h> +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> +#include <java/awt/Rectangle.h> + +#include "gnu/gcj/xlib/Clip.h" + +typedef java::awt::Rectangle AWTRect; +typedef JArray<AWTRect*> AWTRectArray; +typedef std::vector<XRectangle> XRectVector; + +void gnu::gcj::xlib::Clip::init(AWTRectArray* rectangles) +{ + // Prepare rectangles: + + int numRect = JvGetArrayLength(rectangles); + XRectVector* xrectvector = new XRectVector(numRect); + + for (int i=0; i<numRect; i++) + { + AWTRect* awtrect = elements(rectangles)[i]; + XRectangle& xrect = (*xrectvector)[i]; + + xrect.x = awtrect->x; + xrect.y = awtrect->y; + xrect.width = awtrect->width; + xrect.height = awtrect->height; + } + + xrects = reinterpret_cast<gnu::gcj::RawData*>(xrectvector); +} + +void gnu::gcj::xlib::Clip::dispose() +{ + if (xrects) + { + delete xrects; + xrects = 0; + } +} diff --git a/libjava/gnu/gcj/xlib/natColormap.cc b/libjava/gnu/gcj/xlib/natColormap.cc new file mode 100644 index 000000000..2f6a6c744 --- /dev/null +++ b/libjava/gnu/gcj/xlib/natColormap.cc @@ -0,0 +1,147 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +// Needed to avoid linking in libstdc++ +#ifndef __STL_USE_EXCEPTIONS +# include <java/lang/OutOfMemoryError.h> +# define __THROW_BAD_ALLOC throw new java::lang::OutOfMemoryError() +#endif + +#include <vector> + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <java/lang/RuntimeException.h> +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Screen.h> +#include <gnu/gcj/xlib/Colormap.h> +#include <gnu/gcj/xlib/XColor.h> +#include <gnu/gcj/RawData.h> + +jlong gnu::gcj::xlib::Colormap::allocateColorPixel(XColor* color) +{ + ::Display* dpy = (::Display*) (screen->getDisplay()->display); + ::XColor* col = (::XColor*) (color->structure); + Status result = XAllocColor(dpy, xid, col); + if (result == 0) + throw new ::java::lang::RuntimeException( + JvNewStringLatin1("Unable to allocate color pixel.")); + + return col->pixel; +} + +typedef JArray<gnu::gcj::xlib::XColor*>* xcolorarray; + +xcolorarray gnu::gcj::xlib::Colormap::getSharedColors() +{ + ::Display* dpy = (::Display*) (screen->getDisplay()->display); + unsigned int nCells = CellsOfScreen(ScreenOfDisplay(dpy, screen->screenNumber)); + + typedef ::XColor xcolor; + std::vector<xcolor> colors(nCells); + for (unsigned int i=0; i<nCells; i++) + colors[i].pixel = i; + ::XColor* cols = colors.get_allocator().address(colors.front()); + XQueryColors(dpy, xid, cols, + nCells); + + int nShared = 0; + for (unsigned int i=0; i<nCells; i++) + { + ::XColor color = colors[i]; + + if (!XAllocColor(dpy, xid, &color)) + continue; + + /* FIXME: In some cases this algorithm may identify a free + color cell as a shared one. */ + if (color.pixel != i) + { + // Oops, the color wasn't shared. Free it. + XFreeColors(dpy, xid, &(color.pixel), 1, 0); + colors[i].flags = FLAG_NOT_SHARED; + continue; + } + + // FIXME: Shared or free? + + nShared++; + colors[i].flags = FLAG_SHARED; + } + + JArray<XColor*>* shared = newXColorArray(nShared); + int si=0; + for (unsigned int i=0; i<nCells; i++) + { + if (colors[i].flags != FLAG_SHARED) + continue; + + XColor* col = elements(shared)[si++]; + gnu::gcj::RawData* colorData = col->structure; + ::XColor* colStruct = reinterpret_cast<xcolor*>(colorData); + *colStruct = colors[i]; + } + + return shared; +} + +xcolorarray gnu::gcj::xlib::Colormap::getXColors() +{ + ::Display* dpy = (::Display*) (screen->getDisplay()->display); + unsigned int nCells = + CellsOfScreen(ScreenOfDisplay(dpy, screen->screenNumber)); + + typedef ::XColor xcolor; + std::vector<xcolor> colors(nCells); + + JArray<XColor*>* colArray = newXColorArray(nCells); + + for (unsigned int i=0; i<nCells; i++) + colors[i].pixel = i; + + XQueryColors(dpy, xid, &(colors.front()), nCells); + + /* TODO: The current problem with this code is that it relies on + (color.pixel == i) as an indicator that the color is + shared. However, (color.pixel == i), may also occur simply + because color cell i simply was the next free in the list of + unallocated color cells. IDEA: run through the list both + backwards and forwards, and only pick out the colorcells that + have been identified as shared during both passes. Reversing the + traversal direction might prevent i from corresponding to the + next free colorcell, atleast in one of the passes. */ + for (unsigned int i=0; i<nCells; i++) + { + ::XColor color = colors[i]; + + char flag = FLAG_NOT_SHARED; + if (XAllocColor(dpy, xid, &color)) + { + if (color.pixel == i) + { + flag = FLAG_SHARED; + } + else + { + // Oops, the color wasn't shared. Free it. + XFreeColors(dpy, xid, &(color.pixel), 1, 0); + } + } + + // Copy color data into object in array + XColor* col = elements(colArray)[i]; + gnu::gcj::RawData* colorData = col->structure; + ::XColor* colStruct = reinterpret_cast<xcolor*>(colorData); + *colStruct = colors[i]; + colStruct->flags = flag; + } + + return colArray; +} + diff --git a/libjava/gnu/gcj/xlib/natDisplay.cc b/libjava/gnu/gcj/xlib/natDisplay.cc new file mode 100644 index 000000000..f89cb740c --- /dev/null +++ b/libjava/gnu/gcj/xlib/natDisplay.cc @@ -0,0 +1,132 @@ +/* Copyright (C) 1999, 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xproto.h> +#include <X11/Xlib.h> +#include <stdio.h> + +#include <java/lang/System.h> +#include <java/lang/RuntimeException.h> +#include <java/io/PrintStream.h> +#include <gcj/cni.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/XConnectException.h> +#include <gnu/gcj/xlib/XException.h> + +void gnu::gcj::xlib::Display::init() +{ + ::Display* openedDisplay = XOpenDisplay(0); // default display + + if (openedDisplay == 0) { + jstring msg = JvNewStringLatin1("Unable to open display"); + throw new gnu::gcj::xlib::XConnectException(msg); + } + + display = reinterpret_cast<gnu::gcj::RawData*>(openedDisplay); +} + +void gnu::gcj::xlib::Display::finalize() +{ + if (display == 0) return; + ::Display* dpy = (::Display*) display; + XCloseDisplay(dpy); +} + +jint gnu::gcj::xlib::Display::getDefaultScreenNumber() +{ + ::Display* dpy = (::Display*) display; + return DefaultScreen(dpy); +} + +jint gnu::gcj::xlib::Display::getDefaultRootWindowXID() +{ + ::Display* dpy = (::Display*) display; + return DefaultRootWindow(dpy); +} + +jint gnu::gcj::xlib::Display::internAtom(jstring name) +{ + ::Display* dpy = (::Display*) display; + int len = JvGetStringUTFLength(name); + char cName[len+1]; + JvGetStringUTFRegion(name, 0, name->length(), cName); + cName[len] = '\0'; + bool onlyIfExists = false; + return XInternAtom(dpy, cName, onlyIfExists); +} + +jstring gnu::gcj::xlib::Display::getAtomName(jint atom) +{ + ::Display* dpy = (::Display*) display; + char* cName = XGetAtomName(dpy, atom); + jstring name = JvNewStringLatin1(cName); + XFree(cName); + return name; +} + +static int handleXError(Display* dpy, XErrorEvent* xee) +{ + const int ERROR_TEXT_LENGTH = 256; + char errorText[ERROR_TEXT_LENGTH]; + XGetErrorText(dpy, xee->error_code, errorText, ERROR_TEXT_LENGTH); + int requestCode = xee->request_code; + + if (requestCode == X_GetImage) + { + /* The current implementation of Drawable.copyIntoXImage() + will generate harmless X_GetImage errors if the initially + requested area is not completly within the drawable. Until + we find a better solution, simply ignore these errors. */ + return 0; + } + + java::lang::System::err->print(JvNewStringLatin1("X error: ")); + java::lang::System::err->print(JvNewStringLatin1(errorText)); + java::lang::System::err->print(JvNewStringLatin1(", serial=")); + java::lang::System::err->print((jlong) xee->serial); + java::lang::System::err->print(JvNewStringLatin1(", requestCode=")); + java::lang::System::err->print((jint) requestCode); + + if (requestCode < 128) + { + char number[8]; + snprintf(number, 8, "%d", requestCode); + number[7] = '\0'; + + XGetErrorDatabaseText(dpy, "XRequest", number, + "", errorText, ERROR_TEXT_LENGTH); + java::lang::System::err->print(JvNewStringLatin1(" (")); + java::lang::System::err->print(JvNewStringLatin1(errorText)); + java::lang::System::err->print(JvNewStringLatin1(")")); + } + + java::lang::System::err->print(JvNewStringLatin1(", minorCode=")); + java::lang::System::err->print((jint) xee->minor_code); + java::lang::System::err->print(JvNewStringLatin1(", XID=")); + java::lang::System::err->println((jlong) xee->resourceid); + + return 0; +} + +void gnu::gcj::xlib::Display::staticInit() +{ + if (XInitThreads() == 0) + { + char msg[] = "threads are not supported on this platform"; + throw new ::java::lang::RuntimeException(JvNewStringLatin1(msg)); + } + + XSetErrorHandler(&handleXError); +} + +void gnu::gcj::xlib::Display::flush() +{ + ::Display* dpy = (::Display*) display; + XFlush(dpy); +} diff --git a/libjava/gnu/gcj/xlib/natDrawable.cc b/libjava/gnu/gcj/xlib/natDrawable.cc new file mode 100644 index 000000000..371a92bfe --- /dev/null +++ b/libjava/gnu/gcj/xlib/natDrawable.cc @@ -0,0 +1,99 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> + +#include <gnu/gcj/xlib/XException.h> +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Drawable.h> +#include <gnu/gcj/xlib/XImage.h> + +#include <java/awt/Rectangle.h> + +jboolean gnu::gcj::xlib::Drawable::copyIntoXImageImpl(XImage* image, + jint x, jint y, + jint width, jint height, + jint destX, jint destY) +{ + ::Display* dpy = (::Display*) (getDisplay()->display); + ::XImage* ximage = (::XImage*) image->structure; + int format = image->getFormat(); + int xid = getXID(); + + ::XImage* result = XGetSubImage(dpy, xid, + x, y, width, height, + ~0, // plane mask + format, + ximage, + destX, destY); + if (result == 0) + return false; + + if (result != ximage) + throw new XException(MSG_XGETSUBIMAGE_FAILED); + + return true; +} + +jint gnu::gcj::xlib::Drawable::getDepth () +{ + ::Display* dpy = (::Display*) (getDisplay ()->display); + ::Window root; + int x, y; + unsigned int w, h, bw, depth; + + Status status = XGetGeometry (dpy, getXID(), &root, + &x, &y, &w, &h, + &bw, &depth); + switch (status) + { + case BadDrawable: + throw new XException (display, status); + default: + ; // All OK, NOP. + } + return (jint)depth; +} + +java::awt::Rectangle* +gnu::gcj::xlib::Drawable::getBounds(::java::awt::Rectangle* rv) +{ + ::Display* dpy = (::Display*) (getDisplay()->display); + + ::Window root; + int x, y; + unsigned int w, h, bw, depth; + + Status status = XGetGeometry(dpy, getXID(), &root, + &x, &y, &w, &h, + &bw, &depth); + + switch (status) + { + case BadDrawable: + throw new XException(display, status); + default: + ; // All OK, NOP. + } + + if (rv == 0) + { + rv = new ::java::awt::Rectangle(x, y, w, h); + } + else + { + rv->x = x; + rv->y = y; + rv->width = w; + rv->height = h; + } + return rv; +} diff --git a/libjava/gnu/gcj/xlib/natFont.cc b/libjava/gnu/gcj/xlib/natFont.cc new file mode 100644 index 000000000..be842d0a9 --- /dev/null +++ b/libjava/gnu/gcj/xlib/natFont.cc @@ -0,0 +1,113 @@ +/* Copyright (C) 2000, 2003 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> +#include <java/lang/String.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Font.h> +#include <gnu/gcj/xlib/XException.h> + +gnu::gcj::RawData* gnu::gcj::xlib::Font::loadFontImpl(Display* display, + jstring lfdNamePattern) +{ + ::Display* dpy = (::Display*) display->display; + int len = JvGetStringUTFLength(lfdNamePattern); + char cName[len+1]; + JvGetStringUTFRegion(lfdNamePattern, 0, lfdNamePattern->length(), + cName); + cName[len] = '\0'; + + XFontStruct* fontStruct = XLoadQueryFont(dpy, cName); + if (fontStruct == 0) + { + throw new XException(JvNewStringLatin1("font not found")); + } + + return reinterpret_cast<gnu::gcj::RawData*>(fontStruct); +} + +jint gnu::gcj::xlib::Font::getXIDFromStruct(gnu::gcj::RawData* structure) +{ + XFontStruct* fontStruct = (XFontStruct*) structure; + return fontStruct->fid; +} + +jint gnu::gcj::xlib::Font::getMaxAscent() +{ + XFontStruct* fontStruct = (XFontStruct*) structure; + return fontStruct->max_bounds.ascent+1; // +1 to include the baseline +} + +jint gnu::gcj::xlib::Font::getMaxDescent() +{ + XFontStruct* fontStruct = (XFontStruct*) structure; + return fontStruct->max_bounds.descent-1; // -1 to exclude the baseline +} + +jint gnu::gcj::xlib::Font::getAscent() +{ + XFontStruct* fontStruct = (XFontStruct*) structure; + jint returnValue = fontStruct->ascent; + if (fontStruct->min_byte1==0 && fontStruct->min_char_or_byte2<=(unsigned)'O') + returnValue = fontStruct + ->per_char[(unsigned)'O'-fontStruct->min_char_or_byte2] + .ascent; + return returnValue+1; // +1 to include the baseline +} + +jint gnu::gcj::xlib::Font::getDescent() +{ + XFontStruct* fontStruct = (XFontStruct*) structure; + jint returnValue = fontStruct->descent; + if (fontStruct->min_byte1==0 && fontStruct->min_char_or_byte2<=(unsigned)'y') + returnValue = fontStruct + ->per_char[(unsigned)'y'-fontStruct->min_char_or_byte2] + .descent; + return returnValue-1; // -1 to exclude the baseline +} + +jint gnu::gcj::xlib::Font::getStringWidth(::java::lang::String* text) +{ + XFontStruct* fontStruct = (XFontStruct*) structure; + + // FIXME: Convert to the character set used in the font, which may + // or may not be unicode. For now, treat everything as 16-bit and + // use character codes directly, which should be OK for unicode or + // 8-bit ascii fonts. + jint length = text->length(); + jchar* txt = JvGetStringChars(text); + XChar2b xwchars[length]; + for (int i=0; i<length; i++) + { + XChar2b* xc = &(xwchars[i]); + jchar jc = txt[i]; + xc->byte1 = (jc >> 8) & 0xff; + xc->byte2 = jc & 0xff; + } + return XTextWidth16(fontStruct, xwchars, length); +} + +void gnu::gcj::xlib::Font::finalize() +{ + if (structure != 0) + { + ::Display* dpy = (::Display*) display->display; + XFontStruct* fontStruct = (XFontStruct*) structure; + int result = XFreeFont(dpy, fontStruct); + + if (result == BadFont) + throw new XException(display, result); + + structure = 0; xid = 0; + } +} + diff --git a/libjava/gnu/gcj/xlib/natGC.cc b/libjava/gnu/gcj/xlib/natGC.cc new file mode 100644 index 000000000..4529ebb60 --- /dev/null +++ b/libjava/gnu/gcj/xlib/natGC.cc @@ -0,0 +1,271 @@ +/* Copyright (C) 2000, 2003 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <vector> + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gcj/array.h> +#include <gnu/gcj/RawData.h> +#include <java/lang/String.h> +#include <java/awt/Rectangle.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/XID.h> +#include <gnu/gcj/xlib/Drawable.h> +#include <gnu/gcj/xlib/Font.h> +#include <gnu/gcj/xlib/XImage.h> +#include <gnu/gcj/xlib/XException.h> +#include <gnu/gcj/xlib/Clip.h> +#include <gnu/gcj/xlib/GC.h> +#include <gnu/gcj/xlib/XException.h> + +typedef java::awt::Rectangle AWTRect; +typedef JArray<AWTRect*> AWTRectArray; +typedef std::vector<XRectangle> XRectVector; + +void gnu::gcj::xlib::GC::initStructure(GC* copyFrom) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::GC gc = (::GC) structure; + if (gc == 0) + { + // If we haven't already created a GC, create one now + ::Drawable drawableXID = target->getXID(); + gc = XCreateGC(dpy, drawableXID, 0, 0); + structure = reinterpret_cast<gnu::gcj::RawData*>(gc); + if (gc == 0) + throw new XException(JvNewStringLatin1("GC creation failed")); + } + + if (copyFrom != 0) + { + ::GC fromGC = (::GC) copyFrom->structure; + XCopyGC(dpy, fromGC, ~0, gc); + // no fast fail + } +} + +void gnu::gcj::xlib::GC::disposeImpl() +{ + gnu::gcj::RawData* lStructure = structure; + Drawable* lTargetType = target; + + if ((lStructure == 0) || (lTargetType == 0)) + return; + + structure = 0; + target = 0; + + Display* display = lTargetType->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::GC gc = (::GC) lStructure; + + XFreeGC(dpy, gc); + // no fast fail +} + +void gnu::gcj::xlib::GC::setForeground(jlong pixel) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::GC gc = (::GC) structure; + XSetForeground(dpy, gc, pixel); + // no fast fail +} + +void gnu::gcj::xlib::GC::setFont(Font* font) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::GC gc = (::GC) structure; + XSetFont(dpy, gc, font->getXID()); + // no fast fail +} + +void gnu::gcj::xlib::GC::drawString(jstring text, jint x, jint y) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID(); + ::GC gc = (::GC) structure; + + jint length = text->length(); + jchar* txt = JvGetStringChars(text); + + XChar2b xwchars[length]; + + // FIXME: Convert to the character set used in the font, which may + // or may not be unicode. For now, treat everything as 16-bit and + // use character codes directly, which should be OK for unicode or + // 8-bit ascii fonts. + + for (int i=0; i<length; i++) + { + XChar2b* xc = &(xwchars[i]); + jchar jc = txt[i]; + xc->byte1 = (jc >> 8) & 0xff; + xc->byte2 = jc & 0xff; + } + XDrawString16(dpy, drawableXID, gc, x, y, xwchars, length); +} + +void gnu::gcj::xlib::GC::drawPoint(jint x, jint y) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID(); + ::GC gc = (::GC) structure; + XDrawPoint (dpy, drawableXID, gc, x, y); +} + +void gnu::gcj::xlib::GC::drawLine(jint x1, jint y1, jint x2, jint y2) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID(); + ::GC gc = (::GC) structure; + XDrawLine(dpy, drawableXID, gc, x1, y1, x2, y2); + // no fast fail +} + +void gnu::gcj::xlib::GC::drawRectangle(jint x, jint y, jint w, jint h) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID(); + ::GC gc = (::GC) structure; + XDrawRectangle(dpy, drawableXID, gc, x, y, w, h); + // no fast fail +} + +void gnu::gcj::xlib::GC::fillRectangle(jint x, jint y, jint w, jint h) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID(); + ::GC gc = (::GC) structure; + XFillRectangle(dpy, drawableXID, gc, x, y, w, h); + // no fast fail +} + +void gnu::gcj::xlib::GC::drawArc(jint x, jint y, jint w, jint h,jint startAngle, jint arcAngle) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID(); + ::GC gc = (::GC) structure; + XDrawArc(dpy, drawableXID, gc, x, y, w, h, startAngle * 64, arcAngle * 64); +} + +void gnu::gcj::xlib::GC::fillArc(jint x, jint y, jint w, jint h,jint startAngle, jint arcAngle) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID(); + ::GC gc = (::GC) structure; + XFillArc(dpy, drawableXID, gc, x, y, w, h, startAngle * 64, arcAngle * 64); +} + +void gnu::gcj::xlib::GC::fillPolygon(jintArray xPoints, jintArray yPoints, + jint nPoints, + jint translateX, jint translateY) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID(); + ::GC gc = (::GC) structure; + typedef ::XPoint xpoint; + std::vector<xpoint> points(nPoints+1); + for (int i=0; i<nPoints; i++) + { + points[i].x = elements(xPoints)[i] + translateX; + points[i].y = elements(yPoints)[i] + translateY; + } + points[nPoints] = points[0]; + XFillPolygon(dpy, drawableXID, gc, &(points.front()), nPoints, + Complex, CoordModeOrigin); + // no fast fail +} + +void gnu::gcj::xlib::GC::clearArea(jint x, jint y, jint w, jint h, + jboolean exposures) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID(); + + XClearArea(dpy, drawableXID, x, y, w, h, + exposures ? True : False); + // no fast fail +} + + +void gnu::gcj::xlib::GC::putImage(XImage* image, + jint srcX, jint srcY, + jint destX, jint destY, + jint width, jint height) +{ + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID(); + ::GC gc = (::GC) structure; + ::XImage* ximage = (::XImage*) (image->structure); + + XPutImage(dpy, drawableXID, gc, ximage, + srcX, srcY, + destX, destY, + width, height); + // no fast fail +} + +void gnu::gcj::xlib::GC::updateClip(AWTRectArray* rectangles) +{ + int numRect = JvGetArrayLength(rectangles); + XRectVector* xrectvector = new XRectVector(numRect); + + for (int i=0; i<numRect; i++) + { + AWTRect* awtrect = elements(rectangles)[i]; + XRectangle& xrect = (*xrectvector)[i]; + + xrect.x = awtrect->x; + xrect.y = awtrect->y; + xrect.width = awtrect->width; + xrect.height = awtrect->height; + } + + Display* display = target->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + ::GC gc = (::GC) structure; + + int originX = 0; + int originY = 0; + int ordering = Unsorted; + XSetClipRectangles(dpy, gc, originX, originY, + &(xrectvector->front()), numRect, + ordering); + delete xrectvector; +} + +void gnu::gcj::xlib::GC::copyArea (gnu::gcj::xlib::Drawable * source, + jint srcX, jint srcY, + jint destX, jint destY, + jint width, jint height) +{ + Display* display = target->getDisplay (); + ::Display* dpy = (::Display*) (display->display); + ::Drawable drawableXID = target->getXID (); + ::GC gc = (::GC) structure; + ::Drawable srcXID = source->getXID (); + + XCopyArea (dpy, srcXID, drawableXID, gc, srcX, srcY, width, height, + destX, destY); +} diff --git a/libjava/gnu/gcj/xlib/natPixmap.cc b/libjava/gnu/gcj/xlib/natPixmap.cc new file mode 100644 index 000000000..459f5bf3b --- /dev/null +++ b/libjava/gnu/gcj/xlib/natPixmap.cc @@ -0,0 +1,39 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> + +#include <java/lang/OutOfMemoryError.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Screen.h> +#include <gnu/gcj/xlib/Visual.h> +#include <gnu/gcj/xlib/Drawable.h> +#include <gnu/gcj/xlib/XImage.h> +#include <gnu/gcj/xlib/Pixmap.h> + +jint gnu::gcj::xlib::Pixmap::createXID(Drawable* drawable, + jint width, jint height, + jint depth) +{ + Display* display = drawable->getDisplay(); + ::Display* dpy = (::Display*) (display->display); + jint xid = drawable->getXID(); + + return XCreatePixmap(dpy, xid, width, height, depth); +} + +void gnu::gcj::xlib::Pixmap::finalize() +{ + ::Display* dpy = (::Display*) (getDisplay()->display); + XFreePixmap(dpy, getXID()); +} diff --git a/libjava/gnu/gcj/xlib/natScreen.cc b/libjava/gnu/gcj/xlib/natScreen.cc new file mode 100644 index 000000000..9459c1f42 --- /dev/null +++ b/libjava/gnu/gcj/xlib/natScreen.cc @@ -0,0 +1,53 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Screen.h> + +void gnu::gcj::xlib::Screen::initStructure() +{ + ::Display* dpy = (::Display*) (display->display); + ::Screen* screen = ScreenOfDisplay(dpy, screenNumber); + + structure = reinterpret_cast<gnu::gcj::RawData*>(screen); +} + + +jint gnu::gcj::xlib::Screen::getRootDepth() +{ + ::Screen* screen = (::Screen*) structure; + return screen->root_depth; +} + +jint gnu::gcj::xlib::Screen::getRootWindowXID() +{ + ::Screen* screen = (::Screen*) structure; + return RootWindowOfScreen(screen); +} + +jint gnu::gcj::xlib::Screen::getDefaultColormapXID() +{ + ::Screen* screen = (::Screen*) structure; + return DefaultColormapOfScreen(screen); +} + +jint gnu::gcj::xlib::Screen::findScreenNumber() +{ + ::Screen* screen = (::Screen*) structure; + return XScreenNumberOfScreen(screen); +} + +gnu::gcj::RawData* gnu::gcj::xlib::Screen::getRootVisualStructure() +{ + ::Screen* screen = (::Screen*) structure; + ::Visual* visual = DefaultVisualOfScreen(screen); + return reinterpret_cast<gnu::gcj::RawData*>(visual); +} diff --git a/libjava/gnu/gcj/xlib/natVisual.cc b/libjava/gnu/gcj/xlib/natVisual.cc new file mode 100644 index 000000000..56e03b5ab --- /dev/null +++ b/libjava/gnu/gcj/xlib/natVisual.cc @@ -0,0 +1,146 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +#include <gcj/cni.h> +#include <gnu/gcj/xlib/Visual.h> +#include <gnu/gcj/xlib/Screen.h> +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/XException.h> +#include <gnu/gcj/RawData.h> + +using namespace gnu::gcj; + +void gnu::gcj::xlib::Visual::init(RawData* visual, jint depth) +{ + XVisualInfo* info = new XVisualInfo; + xVisualInfo = reinterpret_cast<gnu::gcj::RawData*>(info); + infoMask = 0; + + if (visual != 0) + { + ::Visual* visualStructure = (::Visual*) visual; + info->visual = visualStructure; + info->visualid = XVisualIDFromVisual(visualStructure); + infoMask |= MASK_ID | MASK_VISUAL_STRUCTURE; + } + + if (depth != 0) + { + info->depth = depth; + infoMask |= MASK_DEPTH; + } +} + +void gnu::gcj::xlib::Visual::finalize() +{ + if (xVisualInfo != 0) + { + delete xVisualInfo; + xVisualInfo = 0; + } +} + +RawData* gnu::gcj::xlib::Visual::getVisualStructure() +{ + ensureXVisualInfo(MASK_ALL); // Make sure structure is set + XVisualInfo* info = (XVisualInfo*) xVisualInfo; + return reinterpret_cast<gnu::gcj::RawData*>(info->visual); +} + +jint gnu::gcj::xlib::Visual::getRedMask() +{ + ensureXVisualInfo(MASK_RED); + XVisualInfo* info = (XVisualInfo*) xVisualInfo; + return info->red_mask; +} + +jint gnu::gcj::xlib::Visual::getGreenMask() +{ + ensureXVisualInfo(MASK_GREEN); + XVisualInfo* info = (XVisualInfo*) xVisualInfo; + return info->green_mask; +} + +jint gnu::gcj::xlib::Visual::getBlueMask() +{ + ensureXVisualInfo(MASK_BLUE); + XVisualInfo* info = (XVisualInfo*) xVisualInfo; + return info->blue_mask; +} + +jint gnu::gcj::xlib::Visual::getScreenNumber() +{ + if (screen != 0) + return screen->getScreenNumber(); + + ensureXVisualInfo(MASK_SCREEN); + XVisualInfo* info = (XVisualInfo*) xVisualInfo; + return info->screen; +} + +jint gnu::gcj::xlib::Visual::getDepth() +{ + ensureXVisualInfo(MASK_DEPTH); + + XVisualInfo* info = (XVisualInfo*) xVisualInfo; + return info->depth; +} + +jint gnu::gcj::xlib::Visual::getVisualClass() +{ + ensureXVisualInfo(MASK_CLASS); + ::XVisualInfo* info = (::XVisualInfo*) xVisualInfo; + return info->c_class; +} + +void gnu::gcj::xlib::Visual::ensureXVisualInfo(jint requiredMask) +{ + int missingInformation = ~infoMask; + if ((missingInformation & requiredMask) == 0) + return; + + // We need more info... + + XVisualInfo* info = (XVisualInfo*) xVisualInfo; + + // Store everything we know into template + if (screen != 0) + { + info->screen = screen->getScreenNumber(); + infoMask |= MASK_SCREEN; + } + + // Aquire info using the current info as template for matching + ::Display* dpy = (::Display*) display->display; + int visualInfoCount; + + long mask = infoMask & MASK_ALL & (~MASK_VISUAL_STRUCTURE); + XVisualInfo* matches = XGetVisualInfo(dpy, mask, + info, &visualInfoCount); + if (matches != 0) + { + (*info) = matches[0]; + + // redundant? + xVisualInfo = reinterpret_cast<gnu::gcj::RawData*>(info); + + infoMask = ~0; // ALL + XFree(matches); + } + else + { + char msg[] = + "XGetVisualInfo failed to find any matching visuals. The template " + "describes a combination of properties that does not exist on " + "this X server."; + throw new XException(JvNewStringLatin1(msg)); + } +} diff --git a/libjava/gnu/gcj/xlib/natWMSizeHints.cc b/libjava/gnu/gcj/xlib/natWMSizeHints.cc new file mode 100644 index 000000000..fd546997f --- /dev/null +++ b/libjava/gnu/gcj/xlib/natWMSizeHints.cc @@ -0,0 +1,75 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> +#include <java/lang/OutOfMemoryError.h> + +#include <gnu/gcj/xlib/Window.h> +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/WMSizeHints.h> + +void gnu::gcj::xlib::WMSizeHints::init(WMSizeHints* copyFrom) +{ + XSizeHints* hints = XAllocSizeHints(); + if (hints == 0) + { + jstring errorMessage = JvNewStringLatin1("XAllocSizeHints failed"); + throw new ::java::lang::OutOfMemoryError(errorMessage); + } + + if (copyFrom != 0) + { + XSizeHints* from = (XSizeHints*) copyFrom->structure; + (*hints) = (*from); + } + else + { + // Is this necessary? + hints->flags = 0; + } + structure = reinterpret_cast<gnu::gcj::RawData*>(hints); +} + +void gnu::gcj::xlib::WMSizeHints::finalize() +{ + delete structure; +} + +void gnu::gcj::xlib::WMSizeHints::applyNormalHints(gnu::gcj::xlib::Window* window) +{ + Display* display = window->display; + ::Display* dpy = (::Display*) display->display; + ::Window win = window->getXID(); + XSizeHints* hints = (XSizeHints*) structure; + + XSetWMNormalHints(dpy, win, hints); + /* FIXME, alternative? + // X11 source reports XSetWMNormalHints() as an old routine. (?) + XSetWMSizeHints(dpy, win, hints, display->getAtom("WM_NORMAL_HINTS")); + */ +} + +void gnu::gcj::xlib::WMSizeHints::setMinSize(jint width, jint height) +{ + XSizeHints* hints = (XSizeHints*) structure; + hints->min_width = width; + hints->min_height = height; + hints->flags = hints->flags | PMinSize; +} + +void gnu::gcj::xlib::WMSizeHints::setMaxSize(jint width, jint height) +{ + XSizeHints* hints = (XSizeHints*) structure; + hints->max_width = width; + hints->max_height = height; + hints->flags = hints->flags | PMaxSize; +} diff --git a/libjava/gnu/gcj/xlib/natWindow.cc b/libjava/gnu/gcj/xlib/natWindow.cc new file mode 100644 index 000000000..42ef649c5 --- /dev/null +++ b/libjava/gnu/gcj/xlib/natWindow.cc @@ -0,0 +1,185 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +// Needed to avoid linking in libstdc++ +#ifndef __STL_USE_EXCEPTIONS +# include <java/lang/OutOfMemoryError.h> +# define __THROW_BAD_ALLOC throw new java::lang::OutOfMemoryError() +#endif + +#include <vector> + +#include <X11/Xlib.h> +#include <gcj/cni.h> +#include <java/awt/Rectangle.h> +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Window.h> +#include <gnu/gcj/xlib/WindowAttributes.h> +#include <gnu/gcj/xlib/Visual.h> +#include <gnu/gcj/xlib/XException.h> + +jint gnu::gcj::xlib::Window::createChildXID(::java::awt::Rectangle* bounds, + jint borderWidth, + WindowAttributes* attributes, + jint windowIOClass, + Visual* visual) +{ + ::Window parentXID = xid; + + int x = bounds->x; + int y = bounds->y; + int width = bounds->width; + int height = bounds->height; + + long mask = attributes->mask; + XSetWindowAttributes* attr = (XSetWindowAttributes*) + attributes->getXSetWindowAttributesStructure(); + + ::Visual* vis = CopyFromParent; + int depth = CopyFromParent; + if (visual != 0) + { + vis = (::Visual*) visual->getVisualStructure(); + depth = visual->getDepth(); + } + + ::Window childXID = XCreateWindow((::Display*) (display->display), + parentXID, + x, y, width, height, + borderWidth, depth, windowIOClass, + vis, + mask, attr); + // no fast fail + return childXID; +} + +void gnu::gcj::xlib::Window::destroy() +{ + ::Display* dpy = (::Display*) (display->display); + ::Window window = xid; + XDestroyWindow(dpy, window); + // no fast fail +} + +void gnu::gcj::xlib::Window::setAttributes(WindowAttributes* attributes) +{ + ::Display* dpy = (::Display*) (display->display); + ::Window window = xid; + ::XSetWindowAttributes* attr = (::XSetWindowAttributes*) + attributes->getXSetWindowAttributesStructure(); + + XChangeWindowAttributes(dpy, window, attributes->mask, attr); + // no fast fail +} + +void gnu::gcj::xlib::Window::toBack() +{ + ::Display* dpy = (::Display*) (display->display); + ::Window window = xid; + XLowerWindow(dpy, window); +} + +void gnu::gcj::xlib::Window::toFront() +{ + ::Display* dpy = (::Display*) (display->display); + ::Window window = xid; + XRaiseWindow(dpy, window); +} + +void gnu::gcj::xlib::Window::map() +{ + ::Display* dpy = (::Display*) (display->display); + ::Window window = xid; + XMapWindow(dpy, window); + // no fast fail +} + +void gnu::gcj::xlib::Window::unmap() +{ + ::Display* dpy = (::Display*) (display->display); + ::Window window = xid; + XUnmapWindow(dpy, window); + // no fast fail +} + +void gnu::gcj::xlib::Window::setProperty(jint nameAtom, jint typeAtom, + jbyteArray data) +{ + ::Display* dpy = (::Display*) (display->display); + int format = 8; + int mode = PropModeReplace; + unsigned char* pData = (unsigned char*) elements(data); + int len = data->length; + + XChangeProperty(dpy, xid, nameAtom, typeAtom, format, mode, + pData, len); + // no fast fail +} + +void gnu::gcj::xlib::Window::setWMProtocols(jintArray atoms) +{ + ::Display* dpy = (::Display*) (display->display); + + size_t length = atoms->length; + jint* atomsBegin = elements(atoms); + jint* atomsEnd = atomsBegin + length; + + // Avoid confusion between Xlib.h and Atom.java "Atom" types. + typedef ::Atom XLibAtom; + + std::vector<XLibAtom> atomVector(atomsBegin, atomsEnd); + XLibAtom* atomsArray = &(atomVector.front()); + + XSetWMProtocols(dpy, xid, atomsArray, length); + // no fail fast +} + +jintArray gnu::gcj::xlib::Window::getWMProtocols() +{ + ::Display* dpy = (::Display*) (display->display); + + ::Atom* protocolsReturn; + int countReturn; + + Status success = XGetWMProtocols(dpy, xid, &protocolsReturn, + &countReturn); + + if (!success) + throw new XException(JvNewStringLatin1("cannot get " + "WM protocols ")); + + jintArray atoms; + try + { + ::Atom* protocolsBegin = protocolsReturn; + ::Atom* protocolsEnd = protocolsBegin + countReturn; + + atoms = JvNewIntArray(countReturn); + jint* atomsBegin = elements(atoms); + + std::copy(protocolsBegin, protocolsEnd, atomsBegin); + + } + catch (...) + { + XFree(protocolsReturn); + throw; + } + XFree(protocolsReturn); + + return atoms; +} + +void gnu::gcj::xlib::Window::setBounds(jint x, jint y, + jint width, jint height) +{ + ::Display* dpy = (::Display*) (display->display); + + XMoveResizeWindow(dpy, xid, x, y, width, height); + // no fast fail +} diff --git a/libjava/gnu/gcj/xlib/natWindowAttributes.cc b/libjava/gnu/gcj/xlib/natWindowAttributes.cc new file mode 100644 index 000000000..b61934818 --- /dev/null +++ b/libjava/gnu/gcj/xlib/natWindowAttributes.cc @@ -0,0 +1,109 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Window.h> +#include <gnu/gcj/xlib/WindowAttributes.h> +#include <gnu/gcj/xlib/Pixmap.h> +#include <gnu/gcj/xlib/XException.h> +#include <gnu/gcj/xlib/Screen.h> +#include <gnu/gcj/xlib/Visual.h> + + +void gnu::gcj::xlib::WindowAttributes::initFromWindow(Window* from) +{ + display = from->getDisplay(); + ::Display* dpy = (::Display*) display->display; + ::Window win = from->getXID(); + + XWindowAttributes* attributesIn = new XWindowAttributes; + in = reinterpret_cast<gnu::gcj::RawData*>(attributesIn); + + Status status = XGetWindowAttributes(dpy, win, attributesIn); + if ((status == BadDrawable) | (status == BadWindow)) + throw new XException(display, status); +} + + +void gnu::gcj::xlib::WindowAttributes::init(WindowAttributes* copyFrom) +{ + XSetWindowAttributes* attributes = new XSetWindowAttributes; + + if (copyFrom != 0) + { + XSetWindowAttributes* from = + (XSetWindowAttributes*) copyFrom->out; + (*attributes) = (*from); + } + + out = reinterpret_cast<gnu::gcj::RawData*>(attributes); +} + +void gnu::gcj::xlib::WindowAttributes::finalize() +{ + delete in; in = 0; + delete out; out = 0; +} + +void gnu::gcj::xlib::WindowAttributes::setBackground(jlong pixel) +{ + XSetWindowAttributes* attributes = (XSetWindowAttributes*) out; + + attributes->background_pixel = pixel; + mask = mask | CWBackPixel; +} + +void gnu::gcj::xlib::WindowAttributes::setBackground(Pixmap* pixmap) +{ + XSetWindowAttributes* attributes = (XSetWindowAttributes*) out; + + attributes->background_pixmap = pixmap->getXID(); + mask = mask | CWBackPixmap; +} + +void gnu::gcj::xlib::WindowAttributes::setEventMask(jlong eventMask) +{ + XSetWindowAttributes* attributes = (XSetWindowAttributes*) out; + + attributes->event_mask = eventMask; + mask = mask | CWEventMask; +} + +gnu::gcj::xlib::Visual* gnu::gcj::xlib::WindowAttributes::getVisual() +{ + if (in == 0) + return 0; + + XWindowAttributes* attributesIn = (XWindowAttributes*) in; + + gnu::gcj::RawData* screenRef = + reinterpret_cast<gnu::gcj::RawData*>(attributesIn->screen); + + Screen* screen = new Screen(display, screenRef); + + gnu::gcj::RawData* visualRef = + reinterpret_cast<gnu::gcj::RawData*>(attributesIn->visual); + + return new gnu::gcj::xlib::Visual(visualRef, screen, attributesIn->depth); +} + + +void gnu::gcj::xlib::WindowAttributes::apply(Window* window) +{ + ::Display* dpy = (::Display*) window->getDisplay()->display; + ::Window win = window->getXID(); + XSetWindowAttributes* attributes = (XSetWindowAttributes*) out; + + XChangeWindowAttributes(dpy, win, mask, attributes); +} + diff --git a/libjava/gnu/gcj/xlib/natXAnyEvent.cc b/libjava/gnu/gcj/xlib/natXAnyEvent.cc new file mode 100644 index 000000000..0bef563ed --- /dev/null +++ b/libjava/gnu/gcj/xlib/natXAnyEvent.cc @@ -0,0 +1,153 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <config.h> +#include <platform.h> + +#include <gcj/javaprims.h> +#include <jvm.h> + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> + +#include <java/lang/RuntimeException.h> + +#include <java/lang/System.h> +#include <java/io/PrintStream.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Window.h> +#include <gnu/gcj/xlib/XAnyEvent.h> +#include <gnu/gcj/xlib/XExposeEvent.h> +#include <gnu/gcj/xlib/XException.h> + +#include <unistd.h> +#include <posix.h> + +void gnu::gcj::xlib::XAnyEvent::init() +{ + ::XEvent* event = new ::XEvent; + int *pipes = new int[2]; + pipe(pipes); + structure = reinterpret_cast<gnu::gcj::RawData*>(event); + pipefds = reinterpret_cast<gnu::gcj::RawData*>(pipes); +} + +void gnu::gcj::xlib::XAnyEvent::finalize() +{ + delete structure; + int *pipe = reinterpret_cast<int *>(pipefds); + close(pipe[0]); + close(pipe[1]); + delete [] pipefds; + pipefds = 0; + structure = 0; +} + +jboolean gnu::gcj::xlib::XAnyEvent::loadNext(jboolean block) +{ + ::Display* dpy = (::Display*) display->display; + ::XEvent* evt = (::XEvent*) structure; + + if (XPending(dpy)) + { + XNextEvent(dpy, evt); + return true; + } + + if (!block) + return false; + + int *pipe = reinterpret_cast<int *>(pipefds); + int xfd = XConnectionNumber(dpy); + int pipefd = pipe[0]; + int n = (xfd > pipefd ? xfd : pipefd) + 1; + fd_set rfds; + FD_ZERO(&rfds); + FD_SET(xfd, &rfds); + FD_SET(pipefd, &rfds); + int sel = _Jv_select (n, &rfds, NULL, NULL, NULL); + if (sel > 0) + { + if (FD_ISSET(xfd, &rfds)) + { + XNextEvent(dpy, evt); + return true; + } + if (FD_ISSET(pipefd, &rfds)) + { + char c; + read(pipefd, &c, 1); + } + } + return false; +} + +void gnu::gcj::xlib::XAnyEvent::interrupt() +{ + int *pipe = reinterpret_cast<int *>(pipefds); + write(pipe[1], "W", 1); +} + +jint gnu::gcj::xlib::XAnyEvent::getType() +{ + ::XEvent* event = (::XEvent*) structure; + return event->type; +} + +void gnu::gcj::xlib::XAnyEvent::setType(jint type) +{ + ::XEvent* event = (::XEvent*) structure; + event->type = type; +} + +gnu::gcj::xlib::Window* gnu::gcj::xlib::XAnyEvent::getWindow() +{ + ::XEvent* event = (::XEvent*) structure; + return display->getWindow(event->xany.window); +} + +void gnu::gcj::xlib::XAnyEvent::setWindow(gnu::gcj::xlib::Window* window) +{ + ::XEvent* event = (::XEvent*) structure; + event->xany.window = window->getXID(); +} + +jlong gnu::gcj::xlib::XAnyEvent::getSerial() +{ + ::XEvent* event = (::XEvent*) structure; + return event->xany.serial; +} + +void gnu::gcj::xlib::XAnyEvent::send(gnu::gcj::xlib::Window* destination, + jboolean propagate, jlong mask) +{ + ::Display* dpy = (::Display*) display->display; + ::XEvent* event = (::XEvent*) structure; + + Status status = + XSendEvent(dpy, destination->getXID(), propagate ? True : False, + mask, event); + + switch (status) + { + case 0: + throw new XException(JvNewStringLatin1("conversion to wire " + "protocol failed")); + case BadWindow: + case BadValue: + throw new XException(display, status); + + default: + /* All other return values indicate success. Ie. (status == + 1) indicates success, not BadRequest. */ + ; // NOP + } +} diff --git a/libjava/gnu/gcj/xlib/natXButtonEvent.cc b/libjava/gnu/gcj/xlib/natXButtonEvent.cc new file mode 100644 index 000000000..fa02df833 --- /dev/null +++ b/libjava/gnu/gcj/xlib/natXButtonEvent.cc @@ -0,0 +1,30 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Window.h> +#include <gnu/gcj/xlib/XAnyEvent.h> +#include <gnu/gcj/xlib/XEvent.h> +#include <gnu/gcj/xlib/XButtonEvent.h> + +void gnu::gcj::xlib::XButtonEvent::init() +{ + ::XButtonEvent* evt = (::XButtonEvent*) event->structure; + + time = evt->time; + x = evt->x; + y = evt->y; + state = evt->state; + button = evt->button; +} + diff --git a/libjava/gnu/gcj/xlib/natXColor.cc b/libjava/gnu/gcj/xlib/natXColor.cc new file mode 100644 index 000000000..4e76cf91f --- /dev/null +++ b/libjava/gnu/gcj/xlib/natXColor.cc @@ -0,0 +1,61 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> +#include <gnu/gcj/xlib/XColor.h> + +void gnu::gcj::xlib::XColor::init() +{ + structure = reinterpret_cast<gnu::gcj::RawData*>(new ::XColor); +} + +void gnu::gcj::xlib::XColor::finalize() +{ + delete structure; +} + +void gnu::gcj::xlib::XColor::setRGB(jint r, jint g, jint b) +{ + ::XColor* color = (::XColor*) structure; + color->red = r; + color->green = g; + color->blue = b; +} + +jint gnu::gcj::xlib::XColor::getRed() +{ + ::XColor* color = (::XColor*) structure; + return color->red; +} + +jint gnu::gcj::xlib::XColor::getGreen() +{ + ::XColor* color = (::XColor*) structure; + return color->green; +} + +jint gnu::gcj::xlib::XColor::getBlue() +{ + ::XColor* color = (::XColor*) structure; + return color->blue; +} + +jbyte gnu::gcj::xlib::XColor::getFlags() +{ + ::XColor* color = (::XColor*) structure; + return color->flags; +} + +jlong gnu::gcj::xlib::XColor::getPixelValue() +{ + ::XColor* color = (::XColor*) structure; + return color->pixel; +} diff --git a/libjava/gnu/gcj/xlib/natXConfigureEvent.cc b/libjava/gnu/gcj/xlib/natXConfigureEvent.cc new file mode 100644 index 000000000..a65c0b351 --- /dev/null +++ b/libjava/gnu/gcj/xlib/natXConfigureEvent.cc @@ -0,0 +1,31 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Window.h> +#include <gnu/gcj/xlib/XAnyEvent.h> +#include <gnu/gcj/xlib/XEvent.h> +#include <gnu/gcj/xlib/XConfigureEvent.h> +#include <java/awt/Rectangle.h> + +using java::awt::Rectangle; + +java::awt::Rectangle* gnu::gcj::xlib::XConfigureEvent::getBounds() +{ + ::XConfigureEvent* evt = (::XConfigureEvent*) event->structure; + Rectangle* rectangle = new Rectangle(evt->x, evt->y, + evt->width, evt->height); + + return rectangle; +} + diff --git a/libjava/gnu/gcj/xlib/natXException.cc b/libjava/gnu/gcj/xlib/natXException.cc new file mode 100644 index 000000000..4bf7197fb --- /dev/null +++ b/libjava/gnu/gcj/xlib/natXException.cc @@ -0,0 +1,24 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/XException.h> + +jstring gnu::gcj::xlib::XException::toString(Display* display, jint status) +{ + ::Display* dpy = (::Display*) (display->display); + + const int ERROR_TEXT_LENGTH = 256; + char errorText[ERROR_TEXT_LENGTH]; + + XGetErrorText(dpy, status, errorText, ERROR_TEXT_LENGTH); + return JvNewStringLatin1(errorText); +} diff --git a/libjava/gnu/gcj/xlib/natXExposeEvent.cc b/libjava/gnu/gcj/xlib/natXExposeEvent.cc new file mode 100644 index 000000000..6dad170e4 --- /dev/null +++ b/libjava/gnu/gcj/xlib/natXExposeEvent.cc @@ -0,0 +1,31 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Window.h> +#include <gnu/gcj/xlib/XAnyEvent.h> +#include <gnu/gcj/xlib/XEvent.h> +#include <gnu/gcj/xlib/XExposeEvent.h> +#include <java/awt/Rectangle.h> + +using java::awt::Rectangle; + +java::awt::Rectangle* gnu::gcj::xlib::XExposeEvent::getBounds() +{ + ::XExposeEvent* evt = (::XExposeEvent*) event->structure; + Rectangle* rectangle = new Rectangle(evt->x, evt->y, + evt->width, evt->height); + + return rectangle; +} + diff --git a/libjava/gnu/gcj/xlib/natXImage.cc b/libjava/gnu/gcj/xlib/natXImage.cc new file mode 100644 index 000000000..81022227d --- /dev/null +++ b/libjava/gnu/gcj/xlib/natXImage.cc @@ -0,0 +1,220 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> + +#include <java/lang/OutOfMemoryError.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Screen.h> +#include <gnu/gcj/xlib/Visual.h> +#include <gnu/gcj/xlib/XImage.h> +#include <java/lang/System.h> +#include <java/io/PrintStream.h> + +void gnu::gcj::xlib::XImage::init(Visual* visual, jint depth, + jint format, jint xoffset, + jint width, jint height, + jint bitmapPad, jint bytesPerLine, + jint bitsPerPixel) +{ + ::Display* dpy = (::Display*) visual->display->display; + ::Visual* vis = (::Visual*) visual->getVisualStructure(); + + char* data = 0; // no preallocated data + ::XImage* ximage = XCreateImage(dpy, vis, depth, format, xoffset, + data, + width, height, + bitmapPad, + bytesPerLine + ); + if (ximage == 0) + { + jstring errorMessage = JvNewStringLatin1("XCreateImage failed"); + throw new ::java::lang::OutOfMemoryError(errorMessage); + } + + bool reinitialize = false; + + if ((bitsPerPixel != 0) && (ximage->bits_per_pixel != bitsPerPixel)) + { + ximage->bits_per_pixel = bitsPerPixel; + reinitialize = true; + } + + // FIXME: make autoconf test? + jshort endianTestShort[] = { 1 }; + jbyte* endianTestByte = reinterpret_cast<jbyte*>(endianTestShort); + + jint byteOrder; + if (endianTestByte[0] == 1) + { + // little endian machine + byteOrder = LEAST_SIGNIFICANT_B_FIRST_ORDER; + } + else + { + // big endian machine + byteOrder = MOST_SIGNIFICANT_B_FIRST_ORDER; + } + /* NB: This doesn't consider those weird machines out there with + middle-endian byte order. */ + + if (byteOrder != ximage->byte_order) + { + ximage->byte_order = byteOrder; + reinitialize = true; + } + + if (reinitialize) + XInitImage(ximage); + + structure = reinterpret_cast<gnu::gcj::RawData*>(ximage); + // Notice that no image data has been allocated at this point +} + +void gnu::gcj::xlib::XImage::init(Visual* visual, + jint width, + jint height) +{ + int depth = visual->getDepth(); + + int format = ZPixmap; // Chunky, not planar. + int offset = 0; + int bitmapPad = 32; // FIXME, don't hardcode this + int bytesPerLine = 0; // Let the server figure it out + + init(visual, depth, format, offset, width, height, bitmapPad, + bytesPerLine, 0); +} + +void gnu::gcj::xlib::XImage::internalSetData(jbyteArray data, jint offset) +{ + ::XImage* ximage = (::XImage*) structure; + ximage->data = reinterpret_cast<char*>(elements(data)+offset); +} + +void gnu::gcj::xlib::XImage::internalSetData(jshortArray data, jint offset) +{ + ::XImage* ximage = (::XImage*) structure; + ximage->data = reinterpret_cast<char*>(elements(data)+offset); +} + +void gnu::gcj::xlib::XImage::internalSetData(jintArray data, jint offset) +{ + ::XImage* ximage = (::XImage*) structure; + ximage->data = reinterpret_cast<char*>(elements(data)+offset); +} + +void gnu::gcj::xlib::XImage::finalize() +{ + ::XImage* ximage = (::XImage*) structure; + if (ownsData) + delete ximage->data; + + ximage->data = 0; // Never allow XLib to free the data allocation. + dataRef = 0; + XDestroyImage(ximage); +} + +jint gnu::gcj::xlib::XImage::getWidth() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->width; +} + +jint gnu::gcj::xlib::XImage::getHeight() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->height; +} + +jint gnu::gcj::xlib::XImage::getDepth() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->depth; +} + +jint gnu::gcj::xlib::XImage::getFormat() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->format; +} + +jint gnu::gcj::xlib::XImage::getXOffset() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->xoffset; +} + +jint gnu::gcj::xlib::XImage::getImageByteOrder() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->byte_order; +} + +jint gnu::gcj::xlib::XImage::getBitmapBitOrder() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->bitmap_bit_order; +} + +jint gnu::gcj::xlib::XImage::getBitmapUnit() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->bitmap_unit; +} + +jint gnu::gcj::xlib::XImage::getBitmapPad() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->bitmap_pad; +} + +jint gnu::gcj::xlib::XImage::getBytesPerLine() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->bytes_per_line; +} + +jint gnu::gcj::xlib::XImage::getBitsPerPixel() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->bits_per_pixel; +} + + +// True/Direct Color specific: + +jint gnu::gcj::xlib::XImage::getRedMask() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->red_mask; +} + +jint gnu::gcj::xlib::XImage::getGreenMask() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->green_mask; +} + +jint gnu::gcj::xlib::XImage::getBlueMask() +{ + ::XImage* ximage = (::XImage*) structure; + return ximage->blue_mask; +} + +void gnu::gcj::xlib::XImage::setPixel(jint x, jint y, jint pixel) +{ + ::XImage* ximage = (::XImage*) structure; + XPutPixel(ximage, x, y, pixel); +} diff --git a/libjava/gnu/gcj/xlib/natXUnmapEvent.cc b/libjava/gnu/gcj/xlib/natXUnmapEvent.cc new file mode 100644 index 000000000..d91a77872 --- /dev/null +++ b/libjava/gnu/gcj/xlib/natXUnmapEvent.cc @@ -0,0 +1,32 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +#include <X11/Xlib.h> + +#include <gcj/cni.h> +#include <gnu/gcj/RawData.h> + +#include <gnu/gcj/xlib/Display.h> +#include <gnu/gcj/xlib/Window.h> +#include <gnu/gcj/xlib/XAnyEvent.h> +#include <gnu/gcj/xlib/XEvent.h> +#include <gnu/gcj/xlib/XUnmapEvent.h> + +void gnu::gcj::xlib::XUnmapEvent::setUnmappedWindow(gnu::gcj::xlib::Window* + unmappedWindow) +{ + ::XUnmapEvent* evt = (::XUnmapEvent*) event->structure; + evt->window = unmappedWindow->getXID(); +} + +void gnu::gcj::xlib::XUnmapEvent::setFromConfigure(jboolean fromConfigure) +{ + ::XUnmapEvent* evt = (::XUnmapEvent*) event->structure; + evt->from_configure = fromConfigure ? True : False; +} + |