X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FCarbon.java;h=5dc019f05f5bef151f57de02405d56badc2abe23;hb=93224727752b3da9a70bacd473c5f961efb3a297;hp=e7a6125b57e8aa3e33319158538e68f7e311276b;hpb=c6689b39ad4b2af85e942933599ccbba1ef9990d;p=org.ibex.core.git diff --git a/src/org/xwt/plat/Carbon.java b/src/org/xwt/plat/Carbon.java index e7a6125..5dc019f 100644 --- a/src/org/xwt/plat/Carbon.java +++ b/src/org/xwt/plat/Carbon.java @@ -1,30 +1,27 @@ // Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL] package org.xwt.plat; -import java.awt.*; -import java.awt.image.*; import gnu.gcj.RawData; import java.net.*; import java.lang.reflect.*; import java.io.*; import java.util.*; -import java.awt.peer.*; import org.xwt.util.*; import org.xwt.*; /** Platform implementation for Carbon UI on a POSIX-compliant OS (ie Mac OS X) */ public class Carbon extends POSIX { - /** hashtable of all OS X fonts; key is an XWT font name, value is WrappedRawData which stores an ATSFontRef. - * Initialized by natInit(). */ - static Hashtable nativeFontCache = new Hashtable(); + /** hashtable of all OS X fonts; key is an XWT font name, value is WrappedRawData which stores an ATSFontRef. + * Initialized by natInit(). */ + static Hashtable nativeFontCache = new Hashtable(); - /** Cache of ATSUStyle objects; key is an XWT font spec, value is WrappedRawData which stores an ATSUStyle. - * According to an Apple technote, caching the style bjects can really increase performance. */ - static Hashtable atsuStyleCache = new Hashtable(); + /** Cache of ATSUStyle objects; key is an XWT font spec, value is WrappedRawData which stores an ATSUStyle. + * According to an Apple technote, caching the style bjects can really increase performance. */ + static Hashtable atsuStyleCache = new Hashtable(); - /** List of all XWT font specs. Initialized by init(). */ - static String[] fontList = null; + /** List of all XWT font specs. Initialized by init(). */ + static String[] fontList = null; // General Methods /////////////////////////////////////////////////////// @@ -38,81 +35,81 @@ public class Carbon extends POSIX { protected native int _getScreenHeight(); protected native String _getClipBoard(); protected native void _setClipBoard(String s); - static String defaultFontName = "lucida_grande"; + static String defaultFontName = "lucida_grande"; protected String _getDefaultFont() { return defaultFontName + "13"; } - protected native int _stringWidth(String fontSpec, String text); + protected native int _stringWidth(String fontSpec, String text); protected native int _getMaxAscent(String font); protected native int _getMaxDescent(String font); protected boolean _needsAutoDoubleClick() { return false; } - /** Returns the ATSUStyle associated with the given XWT font spec. - * This method first checks its internal cache before creating the - * ATSUStyle object from scratch. */ - protected RawData _getATSUStyle( String fontSpec ) { - WrappedRawData ret = null; - ret = (WrappedRawData) atsuStyleCache.get( fontSpec ); - if (ret != null) return ret.wrapee; - - Platform.ParsedFont pf = new Platform.ParsedFont( fontSpec ); - - // Find the font - if (pf.name.equals("serif")) pf.name = "lucida_grande"; - else if (pf.name.equals("sansserif")) pf.name = "helvetica"; - else if (pf.name.equals("monospace")) pf.name = "courier"; - else if (pf.name.equals("dialog")) pf.name = "lucida_grande"; - else if (pf.name.equals("tty")) pf.name = "courier"; - - // Find the ATSFontRef - WrappedRawData fontRef = (WrappedRawData) nativeFontCache.get( pf.name ); - // If we couldn't find the font, use the default font - if ( fontRef == null ) fontRef = (WrappedRawData) nativeFontCache.get( defaultFontName ); - if ( fontRef == null ) throw new Error( "Default font cannot be found" ); - - // Create the ATSUStyle object - ret = new WrappedRawData( _createATSUStyle( fontRef.wrapee, pf.size, pf.bold, pf.italic, pf.underline ) ); - - // Map this font spec to the ATSFontRef to optimize future requests - atsuStyleCache.put( fontSpec, ret ); + /** Returns the ATSUStyle associated with the given XWT font spec. + * This method first checks its internal cache before creating the + * ATSUStyle object from scratch. */ + protected RawData _getATSUStyle( String fontSpec ) { + WrappedRawData ret = null; + ret = (WrappedRawData) atsuStyleCache.get( fontSpec ); + if (ret != null) return ret.wrapee; + + Platform.ParsedFont pf = new Platform.ParsedFont( fontSpec ); + + // Find the font + if (pf.name.equals("serif")) pf.name = "lucida_grande"; + else if (pf.name.equals("sansserif")) pf.name = "helvetica"; + else if (pf.name.equals("monospace")) pf.name = "courier"; + else if (pf.name.equals("dialog")) pf.name = "lucida_grande"; + else if (pf.name.equals("tty")) pf.name = "courier"; + + // Find the ATSFontRef + WrappedRawData fontRef = (WrappedRawData) nativeFontCache.get( pf.name ); + // If we couldn't find the font, use the default font + if ( fontRef == null ) fontRef = (WrappedRawData) nativeFontCache.get( defaultFontName ); + if ( fontRef == null ) throw new Error( "Default font cannot be found" ); + + // Create the ATSUStyle object + ret = new WrappedRawData( _createATSUStyle( fontRef.wrapee, pf.size, pf.bold, pf.italic, pf.underline ) ); + + // Map this font spec to the ATSFontRef to optimize future requests + atsuStyleCache.put( fontSpec, ret ); return ret.wrapee; - } + } - /** Creates an ATSUStyle object with the specified attributes. */ - protected native RawData _createATSUStyle( RawData fontRef, int fontSize, boolean isBold, boolean isItalic, boolean isUnderline ); + /** Creates an ATSUStyle object with the specified attributes. */ + protected native RawData _createATSUStyle( RawData fontRef, int fontSize, boolean isBold, boolean isItalic, boolean isUnderline ); - /** Called once XWT is initialized and the application is running. On Mac OS X this calls - * RunApplicationEventLoop(). */ - protected native void _running(); - - /** dumps a list of Mac OS X font strings. TODO: Will this be sufficient? */ + /** Called once XWT is initialized and the application is running. On Mac OS X this calls + * RunApplicationEventLoop(). */ + protected native void _running(); + + /** dumps a list of Mac OS X font strings. TODO: Will this be sufficient? */ //private native String[] listNativeFonts(); - /** translates a font string into an ATSUFontRef? TODO: Will this be sufficient? */ + /** translates a font string into an ATSUFontRef? TODO: Will this be sufficient? */ //public static native gnu.gcj.RawData fontStringToStruct(String s); public Carbon() { } public void init() { - natInit(); + natInit(); - // nativeFontCache contains font NAMES. Each font exists as an outline font - // which can be any size, plus can have real or simulated bold or italic + // nativeFontCache contains font NAMES. Each font exists as an outline font + // which can be any size, plus can have real or simulated bold or italic fontList = new String[nativeFontCache.size()*4]; Enumeration e = nativeFontCache.keys(); for(int i=0; e.hasMoreElements(); i+=4) { - String fontName = (String)e.nextElement() + "0"; - - fontList[i] = fontName; - fontList[i+1] = fontName + "i"; - fontList[i+2] = fontName + "b"; - fontList[i+3] = fontName + "bi"; - } - - // Make sure that the default font exists - if ( _getATSUStyle( _getDefaultFont() ) == null ) throw new Error( "Default font does not exist" ); - } - private native void natInit(); - - /** so we can put ATSUStyles and ATSFontRefs into Hashtables */ + String fontName = (String)e.nextElement() + "0"; + + fontList[i] = fontName; + fontList[i+1] = fontName + "i"; + fontList[i+2] = fontName + "b"; + fontList[i+3] = fontName + "bi"; + } + + // Make sure that the default font exists + if ( _getATSUStyle( _getDefaultFont() ) == null ) throw new Error( "Default font does not exist" ); + } + private native void natInit(); + + /** so we can put ATSUStyles and ATSFontRefs into Hashtables */ private static class WrappedRawData { public RawData wrapee = null; public WrappedRawData(RawData r) { wrapee = r; } @@ -123,9 +120,9 @@ public class Carbon extends POSIX { /** Implements a Surface as an Carbon Window */ public static class CarbonSurface extends Surface { - /** The WindowRef that implements this Surface. */ - gnu.gcj.RawData window = null; - /** The CGContextRef. TODO: How do we get this??? */ + /** The WindowRef that implements this Surface. */ + gnu.gcj.RawData window = null; + /** The CGContextRef. TODO: How do we get this??? */ gnu.gcj.RawData gc = null; public native void setInvisible(boolean i); @@ -156,20 +153,20 @@ public class Carbon extends POSIX { int height; int[] data = null; - /** A CGImageRef of the picture. */ - RawData image = null; - + /** A CGImageRef of the picture. */ + RawData image = null; + public int getWidth() { return width; } public int getHeight() { return height; } - public native void natInit(); - public native void finalize(); - + public native void natInit(); + public native void finalize(); + public CarbonPicture(int[] data, int w, int h) { this.data = data; this.width = w; this.height = h; - natInit(); + natInit(); } } @@ -179,28 +176,28 @@ public class Carbon extends POSIX { int width; int height; - /** A pointer to the raw bitmap data. */ - RawData bitmapData; - /** A CGBitmapContextRef. */ - RawData gc; - /** A CGImageRef which represents the CGBitmapContext. */ - RawData image; - + /** A pointer to the raw bitmap data. */ + RawData bitmapData; + /** A CGBitmapContextRef. */ + RawData gc; + /** A CGImageRef which represents the CGBitmapContext. */ + RawData image; + public int getWidth() { return width; } public int getHeight() { return height; } public CarbonDoubleBuffer(int w, int h) { - this.width = w; - this.height = h; - natInit(); - } + this.width = w; + this.height = h; + natInit(); + } public native void setClip(int x, int y, int x2, int y2); public native void drawPicture(Picture source, int x, int y); public native void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2); public native void fillRect(int x, int y, int x2, int y2, int color); public native void drawString(String font, String text, int x, int y, int color); - public native void natInit(); + public native void natInit(); public native void finalize(); }