summaryrefslogtreecommitdiff
path: root/gnu/java
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-07-25 22:41:45 +0000
committerRoman Kennke <roman@kennke.org>2006-07-25 22:41:45 +0000
commite2507b5b1f9039730ee41c5f47028bbf6688e663 (patch)
tree74ca45619d4aa9f11270aaf8539a75c17cf0d8ff /gnu/java
parentdfa439da706044e25a9446a2c952dce2275fb70a (diff)
downloadclasspath-e2507b5b1f9039730ee41c5f47028bbf6688e663.tar.gz
2006-07-25 Roman Kennke <kennke@aicas.com>
* java/awt/Component.java (requestFocus()): Reimplemented to use requestFocusImpl(). (requestFocus(boolean)): Reimplemented to use requestFocusImpl(). (requestFocusInWindow()): Reimplemented to use requestFocusImpl(). (requestFocusInWindow(boolean)): Reimplemented to use requestFocusImpl(). (requestFocusImpl): Reimplemented focus request to use new peer method. Also added some obvious additional checks for rejecting focus requests early. * java/awt/ComponentPeer.java (requestFocus(Component,boolean,boolean,long)): Documented this method. * gnu/java/awt/peer/gtk/GtkComponentPeer.java (requestFocus): New field. (gtkWidgetHasFocus): New native method. (gtkWidgetCanFocus): New native method. (requestFocus): Replaced with assert false to prevent usage of obsolete method. (postFocusEvent(int,boolean,Component)): New overloaded method for posting the focus event to a specific target. (postFocusEvent(int,boolean)): Post event to requestFocus component. (requestFocus(Component,boolean,boolean,long)): Implemented. (getWindowFor): New helper method. (isLightweightDescendant): New helper method. * gnu/java/awt/peer/gtk/GtkWindowPeer.java (gtkWindowHasFocus): New native method. (requestFocus(Component,boolean,boolean,long)): New method. Overrides GtkComponentPeer method to specially handly the case when a Window receives a focus request for a lightweight child. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c (gtkWidgetHasFocus): New native method. (gtkWidgetCanFocus): New native method. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c (gtkWindowHasFocus): New native method. * include/gnu_java_awt_peer_gtk_GtkComponentPeer.h, * include/gnu_java_awt_peer_gtk_GtkWindowPeer.h: Regenerated.
Diffstat (limited to 'gnu/java')
-rw-r--r--gnu/java/awt/peer/gtk/GtkComponentPeer.java97
-rw-r--r--gnu/java/awt/peer/gtk/GtkWindowPeer.java38
2 files changed, 128 insertions, 7 deletions
diff --git a/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/gnu/java/awt/peer/gtk/GtkComponentPeer.java
index 4686f12c1..0a6fddc3d 100644
--- a/gnu/java/awt/peer/gtk/GtkComponentPeer.java
+++ b/gnu/java/awt/peer/gtk/GtkComponentPeer.java
@@ -57,6 +57,7 @@ import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Insets;
import java.awt.ItemSelectable;
+import java.awt.KeyboardFocusManager;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
@@ -74,6 +75,7 @@ import java.awt.image.ImageProducer;
import java.awt.image.VolatileImage;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;
+import java.awt.peer.LightweightPeer;
import java.awt.peer.WindowPeer;
import java.util.Timer;
import java.util.TimerTask;
@@ -88,6 +90,13 @@ public class GtkComponentPeer extends GtkGenericPeer
Insets insets;
+ /**
+ * Stores the actually requested focus component. This is used in
+ * {@link #postFocusEvent(int, boolean)} to determine the actual component
+ * which received focus.
+ */
+ private Component focusRequest;
+
/* 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 */
@@ -110,6 +119,9 @@ public class GtkComponentPeer extends GtkGenericPeer
native void gtkWidgetRequestFocus ();
native void gtkWidgetDispatchKeyEvent (int id, long when, int mods,
int keyCode, int keyLocation);
+ native boolean gtkWidgetHasFocus();
+ native boolean gtkWidgetCanFocus();
+
native void realize();
native void setNativeEventMask ();
@@ -415,8 +427,7 @@ public class GtkComponentPeer extends GtkGenericPeer
public void requestFocus ()
{
- gtkWidgetRequestFocus();
- postFocusEvent(FocusEvent.FOCUS_GAINED, false);
+ assert false: "Call new requestFocus() method instead";
}
public void reshape (int x, int y, int width, int height)
@@ -629,9 +640,20 @@ public class GtkComponentPeer extends GtkGenericPeer
q.postEvent(keyEvent);
}
+ protected void postFocusEvent (int id, boolean temporary, Component target)
+ {
+ q().postEvent (new FocusEvent (target, id, temporary));
+ }
+
+ /**
+ * Referenced from native code.
+ *
+ * @param id
+ * @param temporary
+ */
protected void postFocusEvent (int id, boolean temporary)
{
- q().postEvent (new FocusEvent (awtComponent, id, temporary));
+ postFocusEvent(id, temporary, focusRequest);
}
protected void postItemEvent (Object item, int stateChange)
@@ -664,10 +686,73 @@ public class GtkComponentPeer extends GtkGenericPeer
return false;
}
- public boolean requestFocus (Component source, boolean b1,
- boolean b2, long x)
+ public boolean requestFocus (Component request, boolean temporary,
+ boolean allowWindowFocus, long time)
{
- return false;
+ assert request == awtComponent || isLightweightDescendant(request);
+ boolean retval = false;
+ if (gtkWidgetHasFocus())
+ {
+ KeyboardFocusManager kfm =
+ KeyboardFocusManager.getCurrentKeyboardFocusManager();
+ Component currentFocus = kfm.getFocusOwner();
+ if (currentFocus == request)
+ // Nothing to do in this trivial case.
+ retval = true;
+ else
+ {
+ // Requested component is a lightweight descendant of this one
+ // or the actual heavyweight.
+ // Since this (native) component is already focused, we simply
+ // change the actual focus and be done.
+ postFocusEvent(FocusEvent.FOCUS_GAINED, temporary, request);
+ retval = true;
+ }
+ }
+ else
+ {
+ if (gtkWidgetCanFocus())
+ {
+ if (allowWindowFocus)
+ {
+ Window window = getWindowFor(request);
+ GtkWindowPeer wPeer = (GtkWindowPeer) window.getPeer();
+ if (! wPeer.gtkWindowHasFocus())
+ wPeer.requestWindowFocus();
+ }
+ // Store requested focus component so that the corresponding
+ // event is dispatched correctly.
+ focusRequest = request;
+ gtkWidgetRequestFocus();
+ retval = true;
+ }
+ }
+ return retval;
+ }
+
+ private Window getWindowFor(Component c)
+ {
+ Component comp = c;
+ while (! (comp instanceof Window))
+ comp = comp.getParent();
+ return (Window) comp;
+ }
+
+ /**
+ * Returns <code>true</code> if the component is a direct (== no intermediate
+ * heavyweights) lightweight descendant of this peer's component.
+ *
+ * @param c the component to check
+ *
+ * @return <code>true</code> if the component is a direct (== no intermediate
+ * heavyweights) lightweight descendant of this peer's component
+ */
+ protected boolean isLightweightDescendant(Component c)
+ {
+ Component comp = c;
+ while (comp.getPeer() instanceof LightweightPeer)
+ comp = comp.getParent();
+ return comp == awtComponent;
}
public boolean isObscured ()
diff --git a/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/gnu/java/awt/peer/gtk/GtkWindowPeer.java
index 151094224..fbcf761b6 100644
--- a/gnu/java/awt/peer/gtk/GtkWindowPeer.java
+++ b/gnu/java/awt/peer/gtk/GtkWindowPeer.java
@@ -41,9 +41,11 @@ package gnu.java.awt.peer.gtk;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Graphics;
+import java.awt.KeyboardFocusManager;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.event.ComponentEvent;
+import java.awt.event.FocusEvent;
import java.awt.event.PaintEvent;
import java.awt.event.WindowEvent;
import java.awt.peer.WindowPeer;
@@ -70,6 +72,7 @@ public class GtkWindowPeer extends GtkContainerPeer
native void gtkWindowSetResizable (boolean resizable);
native void gtkWindowSetModal (boolean modal);
native void gtkWindowSetAlwaysOnTop ( boolean alwaysOnTop );
+ native boolean gtkWindowHasFocus();
native void realize ();
/** Returns the cached width of the AWT window component. */
@@ -301,7 +304,40 @@ public class GtkWindowPeer extends GtkContainerPeer
// TODO Auto-generated method stub
return false;
}
-
+
+ public boolean requestFocus (Component request, boolean temporary,
+ boolean allowWindowFocus, long time)
+ {
+ assert request == awtComponent || isLightweightDescendant(request);
+ boolean retval = false;
+ if (gtkWindowHasFocus())
+ {
+ KeyboardFocusManager kfm =
+ KeyboardFocusManager.getCurrentKeyboardFocusManager();
+ Component currentFocus = kfm.getFocusOwner();
+ if (currentFocus == request)
+ // Nothing to do in this trivial case.
+ retval = true;
+ else
+ {
+ // Requested component is a lightweight descendant of this one
+ // or the actual heavyweight.
+ // Since this (native) component is already focused, we simply
+ // change the actual focus and be done.
+ postFocusEvent(FocusEvent.FOCUS_GAINED, temporary, request);
+ retval = true;
+ }
+ }
+ else
+ {
+ if (allowWindowFocus)
+ {
+ retval = requestWindowFocus();
+ }
+ }
+ return retval;
+ }
+
public Graphics getGraphics ()
{
Graphics g = super.getGraphics ();