This fixes two more issues with java.awt.Window:
- when calling show() we posted a WINDOW_OPENED twice, once from the
show() method itself, once from the peer. IMO the event should be posted
from the Window.show() method.
- dispose() also posted WINDOW_OPENED. This was a copy+paste mistake
when I copied this part over from show(). It should of course be a
WINDOW_CLOSED.
2006-10-18 Roman Kennke <[EMAIL PROTECTED]>
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
(AWT_WINDOW_OPENED): Remove unnecessary macro.
(window_show_cb): Removed unnecessary function.
(connect_signals): Don't connect signal for show.
* gnu/java/awt/peer/gtk/GtkWindowPeer.java
(hasBeenShown): Removed. This is handled in java.awt.Window.
(postWindowEvent): Removed handling of WINDOW_OPENED. This
is done in java.awt.Window.
* java/awt/Window.java
(dispose): Post WINDOW_CLOSED here, not WINDOW_OPENED.
/Roman
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c,v
retrieving revision 1.69
diff -u -1 -5 -r1.69 gnu_java_awt_peer_gtk_GtkWindowPeer.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c 25 Jul 2006 22:41:46 -0000 1.69
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c 18 Oct 2006 19:13:27 -0000
@@ -32,31 +32,30 @@
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
#include "gtkpeer.h"
#include "gnu_java_awt_peer_gtk_GtkWindowPeer.h"
#include <gdk/gdkprivate.h>
#include <gdk/gdkx.h>
#include <X11/Xatom.h>
#include <gdk/gdkkeysyms.h>
-#define AWT_WINDOW_OPENED 200
#define AWT_WINDOW_CLOSING 201
#define AWT_WINDOW_CLOSED 202
#define AWT_WINDOW_ICONIFIED 203
#define AWT_WINDOW_DEICONIFIED 204
#define AWT_WINDOW_ACTIVATED 205
#define AWT_WINDOW_DEACTIVATED 206
#define AWT_WINDOW_GAINED_FOCUS 207
#define AWT_WINDOW_LOST_FOCUS 208
#define AWT_WINDOW_STATE_CHANGED 209
/* Virtual Keys */
/* This list should be kept in the same order as the VK_ field
declarations in KeyEvent.java. */
#define VK_ENTER '\n'
#define VK_BACK_SPACE '\b'
@@ -1034,31 +1033,30 @@
static void window_get_frame_extents (GtkWidget *window,
int *top, int *left,
int *bottom, int *right);
static void request_frame_extents (GtkWidget *window);
static Bool property_notify_predicate (Display *display,
XEvent *xevent,
XPointer arg);
static gboolean window_delete_cb (GtkWidget *widget, GdkEvent *event,
jobject peer);
static void window_destroy_cb (GtkWidget *widget, GdkEvent *event,
jobject peer);
-static void window_show_cb (GtkWidget *widget, jobject peer);
static void window_focus_state_change_cb (GtkWidget *widget,
GParamSpec *pspec,
jobject peer);
static gboolean window_focus_in_cb (GtkWidget * widget,
GdkEventFocus *event,
jobject peer);
static gboolean window_focus_out_cb (GtkWidget * widget,
GdkEventFocus *event,
jobject peer);
static gboolean window_window_state_cb (GtkWidget *widget,
GdkEvent *event,
jobject peer);
static gboolean window_property_changed_cb (GtkWidget *widget,
GdkEventProperty *event,
jobject peer);
@@ -1310,33 +1308,30 @@
{
void *ptr;
jobject *gref;
gdk_threads_enter ();
ptr = NSA_GET_PTR (env, obj);
gref = NSA_GET_GLOBAL_REF (env, obj);
g_signal_connect (G_OBJECT (ptr), "delete-event",
G_CALLBACK (window_delete_cb), *gref);
g_signal_connect (G_OBJECT (ptr), "destroy-event",
G_CALLBACK (window_destroy_cb), *gref);
- g_signal_connect (G_OBJECT (ptr), "show",
- G_CALLBACK (window_show_cb), *gref);
-
g_signal_connect (G_OBJECT (ptr), "notify::has-toplevel-focus",
G_CALLBACK (window_focus_state_change_cb), *gref);
g_signal_connect (G_OBJECT (ptr), "focus-in-event",
G_CALLBACK (window_focus_in_cb), *gref);
g_signal_connect (G_OBJECT (ptr), "focus-out-event",
G_CALLBACK (window_focus_out_cb), *gref);
g_signal_connect (G_OBJECT (ptr), "window-state-event",
G_CALLBACK (window_window_state_cb), *gref);
g_signal_connect (G_OBJECT (ptr), "property-notify-event",
G_CALLBACK (window_property_changed_cb), *gref);
@@ -1649,40 +1644,30 @@
return TRUE;
}
static void
window_destroy_cb (GtkWidget *widget __attribute__((unused)),
GdkEvent *event __attribute__((unused)),
jobject peer)
{
(*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
postWindowEventID,
(jint) AWT_WINDOW_CLOSED,
(jobject) NULL, (jint) 0);
}
static void
-window_show_cb (GtkWidget *widget __attribute__((unused)),
- jobject peer)
-{
- (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
- postWindowEventID,
- (jint) AWT_WINDOW_OPENED,
- (jobject) NULL, (jint) 0);
-}
-
-static void
window_focus_state_change_cb (GtkWidget *widget,
GParamSpec *pspec __attribute__((unused)),
jobject peer)
{
if (GTK_WINDOW (widget)->has_toplevel_focus)
(*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
postWindowEventID,
(jint) AWT_WINDOW_ACTIVATED,
(jobject) NULL, (jint) 0);
else
(*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
postWindowEventID,
(jint) AWT_WINDOW_DEACTIVATED,
(jobject) NULL, (jint) 0);
}
Index: java/awt/Window.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Window.java,v
retrieving revision 1.77
diff -u -1 -5 -r1.77 Window.java
--- java/awt/Window.java 18 Oct 2006 16:19:54 -0000 1.77
+++ java/awt/Window.java 18 Oct 2006 19:13:27 -0000
@@ -344,39 +344,39 @@
Iterator e = ownedWindows.iterator();
while(e.hasNext())
{
Window w = (Window)(((Reference) e.next()).get());
if (w != null)
w.dispose();
else
// Remove null weak reference from ownedWindows.
e.remove();
}
for (int i = 0; i < ncomponents; ++i)
component[i].removeNotify();
this.removeNotify();
- // Post WINDOW_CLOSED from here.
- if (windowListener != null
- || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0)
- {
- WindowEvent ev = new WindowEvent(this,
- WindowEvent.WINDOW_OPENED);
- Toolkit tk = Toolkit.getDefaultToolkit();
- tk.getSystemEventQueue().postEvent(ev);
- }
+ // Post WINDOW_CLOSED from here.
+ if (windowListener != null
+ || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0)
+ {
+ WindowEvent ev = new WindowEvent(this,
+ WindowEvent.WINDOW_CLOSED);
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ tk.getSystemEventQueue().postEvent(ev);
+ }
}
}
/**
* Sends this window to the back so that all other windows display in
* front of it.
*
* If the window is set to be always-on-top, this will remove its
* always-on-top status.
*/
public void toBack()
{
if (peer != null)
{
if( alwaysOnTop )
Index: gnu/java/awt/peer/gtk/GtkWindowPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java,v
retrieving revision 1.55
diff -u -1 -5 -r1.55 GtkWindowPeer.java
--- gnu/java/awt/peer/gtk/GtkWindowPeer.java 18 Oct 2006 16:19:54 -0000 1.55
+++ gnu/java/awt/peer/gtk/GtkWindowPeer.java 18 Oct 2006 19:13:27 -0000
@@ -52,31 +52,30 @@
import java.awt.event.WindowEvent;
import java.awt.peer.WindowPeer;
public class GtkWindowPeer extends GtkContainerPeer
implements WindowPeer
{
protected static final int GDK_WINDOW_TYPE_HINT_NORMAL = 0;
protected static final int GDK_WINDOW_TYPE_HINT_DIALOG = 1;
protected static final int GDK_WINDOW_TYPE_HINT_MENU = 2;
protected static final int GDK_WINDOW_TYPE_HINT_TOOLBAR = 3;
protected static final int GDK_WINDOW_TYPE_HINT_SPLASHSCREEN = 4;
protected static final int GDK_WINDOW_TYPE_HINT_UTILITY = 5;
protected static final int GDK_WINDOW_TYPE_HINT_DOCK = 6;
protected static final int GDK_WINDOW_TYPE_HINT_DESKTOP = 7;
- private boolean hasBeenShown = false;
private int oldState = Frame.NORMAL;
// Cached awt window component location, width and height.
private int x, y, width, height;
native void gtkWindowSetTitle (String title);
native void gtkWindowSetResizable (boolean resizable);
native void gtkWindowSetModal (boolean modal);
native void gtkWindowSetAlwaysOnTop ( boolean alwaysOnTop );
native boolean gtkWindowHasFocus();
native void realize ();
public void dispose()
{
super.dispose();
@@ -271,41 +270,31 @@
}
public void show ()
{
x = awtComponent.getX();
y = awtComponent.getY();
width = awtComponent.getWidth();
height = awtComponent.getHeight();
setLocation(x, y);
setVisible (true);
}
void postWindowEvent (int id, Window opposite, int newState)
{
- if (id == WindowEvent.WINDOW_OPENED)
- {
- // Post a WINDOW_OPENED event the first time this window is shown.
- if (!hasBeenShown)
- {
- q().postEvent (new WindowEvent ((Window) awtComponent, id,
- opposite));
- hasBeenShown = true;
- }
- }
- else if (id == WindowEvent.WINDOW_STATE_CHANGED)
+ if (id == WindowEvent.WINDOW_STATE_CHANGED)
{
if (oldState != newState)
{
q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite,
oldState, newState));
oldState = newState;
}
}
else
q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite));
}
/**
* Update the always-on-top status of the native window.
*/