diff options
author | Roman Kennke <roman@kennke.org> | 2006-10-18 22:09:15 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2006-10-18 22:09:15 +0000 |
commit | 3fb3b2dca64325b1e95376b22ee8b16dfdfafa6d (patch) | |
tree | 7f7959c0a20ae250b9a1ad8c8bfa4e3c897d5bee | |
parent | ed77968e223e822b5375f3e866abf2b998149faa (diff) | |
download | classpath-3fb3b2dca64325b1e95376b22ee8b16dfdfafa6d.tar.gz |
2006-10-18 Roman Kennke <kennke@aicas.com>
PR 27091
* gnu/java/awt/peer/gtk/GtkFramePeer.java
(maximize): New native method.
(unmaximize): New native method.
(iconify): New native method.
(deiconify): New native method.
(getState): Implemented.
(setState): Implemented.
* gnu/java/awt/peer/gtk/GtkWindowPeer.java
(oldState): Rename to windowState and made protected, so that
the FramePeer can access it.
(postWindowEvent): Handle state change events more gently and
correctly.
* java/awt/Frame.java
(getState): Fetch state from getExtendedState().
(setExtendedState): Update the peer. Check if the state change
is actually supported.
(getExtendedState): Update the state from the peer.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c
(maximize): New method.
(unmaximize): New method.
(iconify): New method.
(deiconify): New method.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
(AWT_FRAME_NORMAL): New macro.
(AWT_FRAME_ICONIFIED): New macro.
(AWT_FRAME_MAXIMIZED_BOTH): New macro.
(window_window_state_cb): Rewritten to handle window state changes
more gently (mostly on the java side of the world).
* include/gnu_java_awt_peer_gtk_GtkFramePeer.h: Regenerated.
-rw-r--r-- | ChangeLog | 33 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkFramePeer.java | 22 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkToolkit.java | 8 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkWindowPeer.java | 23 | ||||
-rw-r--r-- | include/gnu_java_awt_peer_gtk_GtkFramePeer.h | 4 | ||||
-rw-r--r-- | java/awt/Frame.java | 14 | ||||
-rw-r--r-- | native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c | 44 | ||||
-rw-r--r-- | native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c | 49 |
8 files changed, 156 insertions, 41 deletions
@@ -1,3 +1,36 @@ +2006-10-18 Roman Kennke <kennke@aicas.com> + + PR 27091 + * gnu/java/awt/peer/gtk/GtkFramePeer.java + (maximize): New native method. + (unmaximize): New native method. + (iconify): New native method. + (deiconify): New native method. + (getState): Implemented. + (setState): Implemented. + * gnu/java/awt/peer/gtk/GtkWindowPeer.java + (oldState): Rename to windowState and made protected, so that + the FramePeer can access it. + (postWindowEvent): Handle state change events more gently and + correctly. + * java/awt/Frame.java + (getState): Fetch state from getExtendedState(). + (setExtendedState): Update the peer. Check if the state change + is actually supported. + (getExtendedState): Update the state from the peer. + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c + (maximize): New method. + (unmaximize): New method. + (iconify): New method. + (deiconify): New method. + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c + (AWT_FRAME_NORMAL): New macro. + (AWT_FRAME_ICONIFIED): New macro. + (AWT_FRAME_MAXIMIZED_BOTH): New macro. + (window_window_state_cb): Rewritten to handle window state changes + more gently (mostly on the java side of the world). + * include/gnu_java_awt_peer_gtk_GtkFramePeer.h: Regenerated. + 2006-10-18 Tania Bento <tbento@redhat.com> * java/awt/CardLayout.java: diff --git a/gnu/java/awt/peer/gtk/GtkFramePeer.java b/gnu/java/awt/peer/gtk/GtkFramePeer.java index bb6f8b3bb..d113e92f5 100644 --- a/gnu/java/awt/peer/gtk/GtkFramePeer.java +++ b/gnu/java/awt/peer/gtk/GtkFramePeer.java @@ -57,6 +57,11 @@ public class GtkFramePeer extends GtkWindowPeer native void removeMenuBarPeer (); native void gtkFixedSetVisible (boolean visible); + private native void maximize(); + private native void unmaximize(); + private native void iconify(); + private native void deiconify(); + int getMenuBarHeight () { return menuBar == null ? 0 : getMenuBarHeight (menuBar); @@ -199,12 +204,25 @@ public class GtkFramePeer extends GtkWindowPeer public int getState () { - return 0; + return windowState; } public void setState (int state) { - + switch (state) + { + case Frame.NORMAL: + if ((windowState & Frame.ICONIFIED) != 0) + deiconify(); + if ((windowState & Frame.MAXIMIZED_BOTH) != 0) + unmaximize(); + break; + case Frame.ICONIFIED: + iconify(); + break; + case Frame.MAXIMIZED_BOTH: + maximize(); + } } public void setMaximizedBounds (Rectangle r) diff --git a/gnu/java/awt/peer/gtk/GtkToolkit.java b/gnu/java/awt/peer/gtk/GtkToolkit.java index 3f87ca6e6..d2721b43f 100644 --- a/gnu/java/awt/peer/gtk/GtkToolkit.java +++ b/gnu/java/awt/peer/gtk/GtkToolkit.java @@ -664,6 +664,14 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit return new GtkMouseInfoPeer(); } + public boolean isFrameStateSupported(int state) + { + // GTK supports ICONFIED, NORMAL and MAXIMIZE_BOTH, but + // not (yet?) MAXIMIZE_VERT and MAXIMIZE_HORIZ. + return state == Frame.NORMAL || state == Frame.ICONIFIED + || state == Frame.MAXIMIZED_BOTH; + } + public native int getMouseNumberOfButtons(); } // class GtkToolkit diff --git a/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/gnu/java/awt/peer/gtk/GtkWindowPeer.java index 84e967602..1abc5ca84 100644 --- a/gnu/java/awt/peer/gtk/GtkWindowPeer.java +++ b/gnu/java/awt/peer/gtk/GtkWindowPeer.java @@ -64,7 +64,7 @@ public class GtkWindowPeer extends GtkContainerPeer protected static final int GDK_WINDOW_TYPE_HINT_DOCK = 6; protected static final int GDK_WINDOW_TYPE_HINT_DESKTOP = 7; - private int oldState = Frame.NORMAL; + protected int windowState = Frame.NORMAL; // Cached awt window component location, width and height. private int x, y, width, height; @@ -284,11 +284,24 @@ public class GtkWindowPeer extends GtkContainerPeer { if (id == WindowEvent.WINDOW_STATE_CHANGED) { - if (oldState != newState) + if (windowState != newState) { - q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite, - oldState, newState)); - oldState = newState; + // Post old styleWindowEvent with WINDOW_ICONIFIED or + // WINDOW_DEICONIFIED if appropriate. + if ((windowState & Frame.ICONIFIED) != 0 + && (newState & Frame.ICONIFIED) == 0) + q().postEvent(new WindowEvent((Window) awtComponent, + WindowEvent.WINDOW_DEICONIFIED, + opposite, 0, 0)); + else if ((windowState & Frame.ICONIFIED) == 0 + && (newState & Frame.ICONIFIED) != 0) + q().postEvent(new WindowEvent((Window) awtComponent, + WindowEvent.WINDOW_ICONIFIED, + opposite, 0, 0)); + // Post new-style WindowStateEvent. + q().postEvent (new WindowEvent ((Window) awtComponent, id, + opposite, windowState, newState)); + windowState = newState; } } else diff --git a/include/gnu_java_awt_peer_gtk_GtkFramePeer.h b/include/gnu_java_awt_peer_gtk_GtkFramePeer.h index 2095d421c..63b881d2f 100644 --- a/include/gnu_java_awt_peer_gtk_GtkFramePeer.h +++ b/include/gnu_java_awt_peer_gtk_GtkFramePeer.h @@ -16,6 +16,10 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarWidth ( JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarPeer (JNIEnv *env, jobject, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkFramePeer_removeMenuBarPeer (JNIEnv *env, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkFramePeer_gtkFixedSetVisible (JNIEnv *env, jobject, jboolean); +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkFramePeer_maximize (JNIEnv *env, jobject); +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkFramePeer_unmaximize (JNIEnv *env, jobject); +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkFramePeer_iconify (JNIEnv *env, jobject); +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkFramePeer_deiconify (JNIEnv *env, jobject); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkFramePeer_nativeSetIconImage (JNIEnv *env, jobject, jobject); #ifdef __cplusplus diff --git a/java/awt/Frame.java b/java/awt/Frame.java index e0c0d1ff3..d45be1ca5 100644 --- a/java/awt/Frame.java +++ b/java/awt/Frame.java @@ -536,8 +536,7 @@ public class Frame extends Window implements MenuContainer public int getState() { - // FIXME: State might have changed in the peer... Must check. - return (state & ICONIFIED) != 0 ? ICONIFIED : NORMAL; + return (getExtendedState() & ICONIFIED) != 0 ? ICONIFIED : NORMAL; } /** @@ -545,7 +544,13 @@ public class Frame extends Window implements MenuContainer */ public void setExtendedState(int state) { - this.state = state; + if (getToolkit().isFrameStateSupported(state)) + { + this.state = state; + FramePeer p = (FramePeer) peer; + if (p != null) + p.setState(state); + } } /** @@ -553,6 +558,9 @@ public class Frame extends Window implements MenuContainer */ public int getExtendedState() { + FramePeer p = (FramePeer) peer; + if (p != null) + state = p.getState(); return state; } diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c index 766964314..144ca0e8a 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c @@ -188,3 +188,47 @@ Java_gnu_java_awt_peer_gtk_GtkFramePeer_nativeSetIconImage gdk_threads_leave (); } + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_maximize +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = NSA_GET_PTR (env, obj); + gtk_window_maximize (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_unmaximize +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = NSA_GET_PTR (env, obj); + gtk_window_unmaximize (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_iconify +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = NSA_GET_PTR (env, obj); + gtk_window_iconify (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} + +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFramePeer_deiconify +(JNIEnv *env, jobject obj) +{ + void *ptr; + gdk_threads_enter (); + ptr = NSA_GET_PTR (env, obj); + gtk_window_deiconify (GTK_WINDOW (ptr)); + gdk_threads_leave (); +} diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c index bcd6d5567..aa70b9d2d 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c @@ -54,6 +54,10 @@ exception statement from your version. */ #define AWT_WINDOW_LOST_FOCUS 208 #define AWT_WINDOW_STATE_CHANGED 209 +#define AWT_FRAME_NORMAL 0 +#define AWT_FRAME_ICONIFIED 1 +#define AWT_FRAME_MAXIMIZED_BOTH 6 + /* Virtual Keys */ /* This list should be kept in the same order as the VK_ field declarations in KeyEvent.java. */ @@ -1703,41 +1707,24 @@ window_window_state_cb (GtkWidget *widget __attribute__((unused)), GdkEvent *event, jobject peer) { - jint new_state; - - /* Handle WINDOW_ICONIFIED and WINDOW_DEICONIFIED events. */ - if (event->window_state.changed_mask & GDK_WINDOW_STATE_ICONIFIED) - { - /* We've either been iconified or deiconified. */ - if (event->window_state.new_window_state & GDK_WINDOW_STATE_ICONIFIED) - { - /* We've been iconified. */ - (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_ICONIFIED, - (jobject) NULL, (jint) 0); - } - else - { - /* We've been deiconified. */ - (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_DEICONIFIED, - (jobject) NULL, (jint) 0); - } - } - - /* Post a WINDOW_STATE_CHANGED event, passing the new frame state to - GtkWindowPeer. */ - new_state = AWT_FRAME_STATE_NORMAL; - - if (event->window_state.new_window_state & GDK_WINDOW_STATE_ICONIFIED) - new_state |= AWT_FRAME_STATE_ICONIFIED; + jint new_java_state = 0; + /* Put together the new state and let the java side figure out what + * to post */ + GdkWindowState new_state = event->window_state.new_window_state; + /* The window can be either iconfified, maximized, iconified + maximized + * or normal. */ + if ((new_state & GDK_WINDOW_STATE_ICONIFIED) != 0) + new_java_state |= AWT_FRAME_ICONIFIED; + if ((new_state & GDK_WINDOW_STATE_MAXIMIZED) != 0) + new_java_state |= AWT_FRAME_MAXIMIZED_BOTH; + if ((new_state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_ICONIFIED)) + == 0) + new_java_state = AWT_FRAME_NORMAL; (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postWindowEventID, (jint) AWT_WINDOW_STATE_CHANGED, - (jobject) NULL, new_state); + (jobject) NULL, new_java_state); return TRUE; } |