summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java')
-rw-r--r--libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java135
1 files changed, 91 insertions, 44 deletions
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java
index 821183927b0..1a85de5fe49 100644
--- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java
+++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java
@@ -63,6 +63,7 @@ import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
+import java.awt.event.MouseWheelEvent;
import java.awt.event.PaintEvent;
import java.awt.event.TextEvent;
import java.awt.image.BufferedImage;
@@ -86,8 +87,6 @@ public class GtkComponentPeer extends GtkGenericPeer
Insets insets;
- boolean isInRepaint;
-
/* this isEnabled differs from Component.isEnabled, in that it
knows if a parent is disabled. In that case Component.isEnabled
may return true, but our isEnabled will always return false */
@@ -100,8 +99,9 @@ public class GtkComponentPeer extends GtkGenericPeer
native void gtkWidgetGetPreferredDimensions (int[] dim);
native void gtkWindowGetLocationOnScreen (int[] point);
native void gtkWidgetGetLocationOnScreen (int[] point);
- native void gtkWidgetSetCursor (int type);
- native void gtkWidgetSetCursorUnlocked (int type);
+ native void gtkWidgetSetCursor (int type, GtkImage image, int x, int y);
+ native void gtkWidgetSetCursorUnlocked (int type, GtkImage image,
+ int x, int y);
native void gtkWidgetSetBackground (int red, int green, int blue);
native void gtkWidgetSetForeground (int red, int green, int blue);
native void gtkWidgetSetSensitive (boolean sensitive);
@@ -150,6 +150,9 @@ public class GtkComponentPeer extends GtkGenericPeer
setNativeEventMask ();
realize ();
+
+ if (awtComponent.isCursorSet())
+ setCursor ();
}
void setParentAndBounds ()
@@ -176,16 +179,6 @@ public class GtkComponentPeer extends GtkGenericPeer
gtkWidgetSetParent (p);
}
- void beginNativeRepaint ()
- {
- isInRepaint = true;
- }
-
- void endNativeRepaint ()
- {
- isInRepaint = false;
- }
-
/*
* Set the bounds of this peer's AWT Component based on dimensions
* returned by the native windowing system. Most Components impose
@@ -250,6 +243,8 @@ public class GtkComponentPeer extends GtkGenericPeer
return getToolkit().getFontMetrics(font);
}
+ // getGraphics may be overridden by derived classes but it should
+ // never return null.
public Graphics getGraphics ()
{
if (GtkToolkit.useGraphics2D ())
@@ -291,30 +286,10 @@ public class GtkComponentPeer extends GtkGenericPeer
switch (id)
{
case PaintEvent.PAINT:
+ paintComponent((PaintEvent) event);
+ break;
case PaintEvent.UPDATE:
- {
- try
- {
- Graphics g = getGraphics();
-
- if (!awtComponent.isShowing() || awtComponent.getWidth() < 1
- || awtComponent.getHeight() < 1 || g == null)
- break;
-
- g.setClip(((PaintEvent) event).getUpdateRect());
-
- if (id == PaintEvent.PAINT)
- awtComponent.paint(g);
- else
- awtComponent.update(g);
-
- g.dispose();
- }
- catch (InternalError e)
- {
- System.err.println(e);
- }
- }
+ updateComponent((PaintEvent) event);
break;
case KeyEvent.KEY_PRESSED:
ke = (KeyEvent) event;
@@ -328,7 +303,49 @@ public class GtkComponentPeer extends GtkGenericPeer
break;
}
}
-
+
+ // This method and its overrides are the only methods in the peers
+ // that should call awtComponent.paint.
+ protected void paintComponent (PaintEvent event)
+ {
+ // Do not call Component.paint if the component is not showing or
+ // if its bounds form a degenerate rectangle.
+ if (!awtComponent.isShowing()
+ || (awtComponent.getWidth() < 1 || awtComponent.getHeight() < 1))
+ return;
+
+ // Creating and disposing a GdkGraphics every time paint is called
+ // seems expensive. However, the graphics state does not carry
+ // over between calls to paint, and resetting the graphics object
+ // may even be more costly than simply creating a new one.
+ Graphics g = getGraphics();
+
+ g.setClip(event.getUpdateRect());
+
+ awtComponent.paint(g);
+
+ g.dispose();
+ }
+
+ // This method and its overrides are the only methods in the peers
+ // that should call awtComponent.update.
+ protected void updateComponent (PaintEvent event)
+ {
+ // Do not call Component.update if the component is not showing or
+ // if its bounds form a degenerate rectangle.
+ if (!awtComponent.isShowing()
+ || (awtComponent.getWidth() < 1 || awtComponent.getHeight() < 1))
+ return;
+
+ Graphics g = getGraphics();
+
+ g.setClip(event.getUpdateRect());
+
+ awtComponent.update(g);
+
+ g.dispose();
+ }
+
public boolean isFocusTraversable ()
{
return true;
@@ -369,7 +386,7 @@ public class GtkComponentPeer extends GtkGenericPeer
public void repaint (long tm, int x, int y, int width, int height)
{
- if (x == 0 && y == 0 && width == 0 && height == 0)
+ if (width < 1 || height < 1)
return;
if (tm <= 0)
@@ -490,10 +507,28 @@ public class GtkComponentPeer extends GtkGenericPeer
public void setCursor (Cursor cursor)
{
+ int x, y;
+ GtkImage image;
+ int type = cursor.getType();
+ if (cursor instanceof GtkCursor)
+ {
+ GtkCursor gtkCursor = (GtkCursor) cursor;
+ image = gtkCursor.getGtkImage();
+ Point hotspot = gtkCursor.getHotspot();
+ x = hotspot.x;
+ y = hotspot.y;
+ }
+ else
+ {
+ image = null;
+ x = 0;
+ y = 0;
+ }
+
if (Thread.currentThread() == GtkToolkit.mainThread)
- gtkWidgetSetCursorUnlocked (cursor.getType ());
+ gtkWidgetSetCursorUnlocked(cursor.getType(), image, x, y);
else
- gtkWidgetSetCursor (cursor.getType ());
+ gtkWidgetSetCursor(cursor.getType(), image, x, y);
}
public void setEnabled (boolean b)
@@ -532,7 +567,7 @@ public class GtkComponentPeer extends GtkGenericPeer
public void setVisible (boolean b)
{
// Only really set visible when component is bigger than zero pixels.
- if (b)
+ if (b && ! (awtComponent instanceof Window))
{
Rectangle bounds = awtComponent.getBounds();
b = (bounds.width > 0) && (bounds.height > 0);
@@ -561,10 +596,22 @@ public class GtkComponentPeer extends GtkGenericPeer
clickCount, popupTrigger));
}
+ /**
+ * Callback for component_scroll_cb.
+ */
+ protected void postMouseWheelEvent(int id, long when, int mods,
+ int x, int y, int clickCount,
+ boolean popupTrigger,
+ int type, int amount, int rotation)
+ {
+ q().postEvent(new MouseWheelEvent(awtComponent, id, when, mods,
+ x, y, clickCount, popupTrigger,
+ type, amount, rotation));
+ }
+
protected void postExposeEvent (int x, int y, int width, int height)
{
- if (!isInRepaint)
- q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
+ q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
new Rectangle (x, y, width, height)));
}