diff options
Diffstat (limited to 'libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java')
-rw-r--r-- | libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java | 114 |
1 files changed, 68 insertions, 46 deletions
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java index f746a47479f..df18d39c9d2 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java @@ -1,5 +1,5 @@ /* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers - Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005, 2006 + Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,6 +39,7 @@ exception statement from your version. */ package gnu.java.awt.peer.gtk; +import gnu.java.awt.AWTUtilities; import gnu.java.awt.EmbeddedWindow; import gnu.java.awt.dnd.GtkMouseDragGestureRecognizer; import gnu.java.awt.dnd.peer.gtk.GtkDragSourceContextPeer; @@ -86,6 +87,7 @@ import java.awt.dnd.DragGestureRecognizer; import java.awt.dnd.DragSource; import java.awt.dnd.InvalidDnDOperationException; import java.awt.dnd.peer.DragSourceContextPeer; +import java.awt.font.TextAttribute; import java.awt.im.InputMethodHighlight; import java.awt.image.ColorModel; import java.awt.image.DirectColorModel; @@ -104,8 +106,8 @@ import java.awt.peer.LabelPeer; import java.awt.peer.ListPeer; import java.awt.peer.MenuBarPeer; import java.awt.peer.MenuItemPeer; -import java.awt.peer.MouseInfoPeer; import java.awt.peer.MenuPeer; +import java.awt.peer.MouseInfoPeer; import java.awt.peer.PanelPeer; import java.awt.peer.PopupMenuPeer; import java.awt.peer.RobotPeer; @@ -132,9 +134,11 @@ import javax.imageio.spi.IIORegistry; public class GtkToolkit extends gnu.java.awt.ClasspathToolkit { + static final Object GTK_LOCK; + private static EventQueue q; - static native void gtkInit(int portableNativeSync); + static native void gtkInit(int portableNativeSync, Object lock); static native void gtkMain(); @@ -154,8 +158,9 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit portableNativeSync = 1; // true else portableNativeSync = 0; // false - - gtkInit(portableNativeSync); + + GTK_LOCK = new String("GTK LOCK"); + gtkInit(portableNativeSync, GTK_LOCK); } public GtkToolkit () @@ -167,14 +172,14 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit private native void getScreenSizeDimensions(int[] xy); public int checkImage (Image image, int width, int height, - ImageObserver observer) + ImageObserver observer) { int status = ImageObserver.ALLBITS | ImageObserver.WIDTH | ImageObserver.HEIGHT; if (image instanceof GtkImage) - return ((GtkImage) image).checkImage (observer); + return ((GtkImage) image).checkImage (observer); if (image instanceof AsyncImage) return ((AsyncImage) image).checkImage(observer); @@ -208,11 +213,11 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit Image image; try { - image = CairoSurface.getBufferedImage( new GtkImage( filename ) ); + image = CairoSurface.getBufferedImage( new GtkImage( filename ) ); } catch (IllegalArgumentException iae) { - image = null; + image = null; } return imageOrError(image); } @@ -230,11 +235,11 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit Image image; try { - image = CairoSurface.getBufferedImage( new GtkImage( producer ) ); + image = CairoSurface.getBufferedImage( new GtkImage( producer ) ); } catch (IllegalArgumentException iae) { - image = null; + image = null; } return imageOrError(image); } @@ -245,13 +250,13 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit Image image; try { - byte[] data = new byte[ imagelength ]; - System.arraycopy(imagedata, imageoffset, data, 0, imagelength); - image = CairoSurface.getBufferedImage( new GtkImage( data ) ); + byte[] data = new byte[ imagelength ]; + System.arraycopy(imagedata, imageoffset, data, 0, imagelength); + image = CairoSurface.getBufferedImage( new GtkImage( data ) ); } catch (IllegalArgumentException iae) { - image = null; + image = null; } return imageOrError(image); } @@ -275,22 +280,22 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit { /* Return the GDK-native ABGR format */ return new DirectColorModel(32, - 0x000000FF, - 0x0000FF00, - 0x00FF0000, - 0xFF000000); + 0x000000FF, + 0x0000FF00, + 0x00FF0000, + 0xFF000000); } public String[] getFontList () { return (new String[] { "Dialog", - "DialogInput", - "Monospaced", - "Serif", - "SansSerif" }); + "DialogInput", + "Monospaced", + "Serif", + "SansSerif" }); } - static class LRUCache extends LinkedHashMap + static class LRUCache<K,V> extends LinkedHashMap<K,V> { int max_entries; public LRUCache(int max) @@ -304,8 +309,9 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit } } - private LRUCache fontCache = new LRUCache(50); - private LRUCache imageCache = new LRUCache(50); + private LRUCache<Map,ClasspathFontPeer> fontCache = + new LRUCache<Map,ClasspathFontPeer>(50); + private LRUCache<Object,Image> imageCache = new LRUCache<Object,Image>(50); public FontMetrics getFontMetrics (Font font) { @@ -315,7 +321,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit public Image getImage (String filename) { if (imageCache.containsKey(filename)) - return (Image) imageCache.get(filename); + return imageCache.get(filename); else { Image im = createImage(filename); @@ -327,7 +333,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit public Image getImage (URL url) { if (imageCache.containsKey(url)) - return (Image) imageCache.get(url); + return imageCache.get(url); else { Image im = createImage(url); @@ -378,12 +384,12 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit * assumes the image is already prepared for rendering. */ public boolean prepareImage (Image image, int width, int height, - ImageObserver observer) + ImageObserver observer) { /* GtkImages are always prepared, as long as they're loaded. */ if (image instanceof GtkImage) - return ((((GtkImage)image).checkImage (observer) & - ImageObserver.ALLBITS) != 0); + return ((((GtkImage)image).checkImage (observer) + & ImageObserver.ALLBITS) != 0); if (image instanceof AsyncImage) { @@ -411,11 +417,11 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit /* Make the Peer reflect the state of the Component */ if (! (c instanceof Window)) { - cp.setCursor (c.getCursor ()); + cp.setCursor (c.getCursor ()); - Rectangle bounds = c.getBounds (); - cp.setBounds (bounds.x, bounds.y, bounds.width, bounds.height); - cp.setVisible (c.isVisible ()); + Rectangle bounds = c.getBounds (); + cp.setBounds (bounds.x, bounds.y, bounds.width, bounds.height); + cp.setVisible (c.isVisible ()); } } @@ -563,7 +569,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit */ private FontPeer getFontPeer (String name, int style, int size) { - Map attrs = new HashMap (); + Map<TextAttribute,Object> attrs = new HashMap<TextAttribute,Object>(); ClasspathFontPeer.copyStyleToAttrs (style, attrs); ClasspathFontPeer.copySizeToAttrs (size, attrs); return getClasspathFontPeer (name, attrs); @@ -575,16 +581,17 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit * model, hence "ClasspathFontPeer". */ - public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs) + public ClasspathFontPeer getClasspathFontPeer (String name, + Map<?,?> attrs) { - Map keyMap = new HashMap (attrs); + Map<Object,Object> keyMap = new HashMap<Object,Object>(attrs); // We don't know what kind of "name" the user requested (logical, face, // family), and we don't actually *need* to know here. The worst case // involves failure to consolidate fonts with the same backend in our // cache. This is harmless. keyMap.put ("GtkToolkit.RequestedFontName", name); if (fontCache.containsKey (keyMap)) - return (ClasspathFontPeer) fontCache.get (keyMap); + return fontCache.get (keyMap); else { ClasspathFontPeer newPeer = new GdkFontPeer (name, attrs); @@ -619,11 +626,10 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit return new GtkDragSourceContextPeer(e); } - public DragGestureRecognizer createDragGestureRecognizer(Class recognizer, - DragSource ds, - Component comp, - int actions, - DragGestureListener l) + public <T extends DragGestureRecognizer> T + createDragGestureRecognizer(Class<T> recognizer, DragSource ds, + Component comp, int actions, + DragGestureListener l) { if (recognizer.getName().equals("java.awt.dnd.MouseDragGestureRecognizer") && ! GraphicsEnvironment.isHeadless()) @@ -631,7 +637,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit GtkMouseDragGestureRecognizer gestureRecognizer = new GtkMouseDragGestureRecognizer(ds, comp, actions, l); gestureRecognizer.registerListeners(); - return gestureRecognizer; + return recognizer.cast(gestureRecognizer); } else { @@ -639,7 +645,7 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit } } - public Map mapInputMethodHighlight(InputMethodHighlight highlight) + public Map<TextAttribute,?> mapInputMethodHighlight(InputMethodHighlight highlight) { throw new Error("not implemented"); } @@ -668,6 +674,22 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit return new GdkRobotPeer (screen); } + public boolean getLockingKeyState(int keyCode) + { + int state = getLockState(keyCode); + + if (state != -1) + return state == 1; + + if (AWTUtilities.isValidKey(keyCode)) + throw new UnsupportedOperationException + ("cannot get locking state of key code " + keyCode); + + throw new IllegalArgumentException("invalid key code " + keyCode); + } + + protected native int getLockState(int keyCode); + public void registerImageIOSpis(IIORegistry reg) { GdkPixbufDecoder.registerSpis(reg); |