diff options
Diffstat (limited to 'src/newt')
12 files changed, 115 insertions, 225 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 17a562d61..4bdcd67a4 100644 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -28,15 +28,15 @@ package com.jogamp.newt; -import com.jogamp.newt.util.Insets; import com.jogamp.newt.event.WindowListener; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.MouseListener; -import com.jogamp.newt.event.NEWTEventConsumer; import com.jogamp.newt.impl.Debug; import javax.media.nativewindow.Capabilities; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.SurfaceUpdatedListener; +import javax.media.nativewindow.util.Insets; +import javax.media.nativewindow.util.Point; /** * Specifying the public Window functionality for the @@ -76,12 +76,6 @@ public interface Window extends NativeWindow { Screen getScreen(); /** - * @return The NativeWindow representation of the parent Window, - * or null if this Window is top level - */ - NativeWindow getParentNativeWindow(); - - /** * @return The requested capabilities */ Capabilities getRequestedCapabilities(); @@ -239,7 +233,7 @@ public interface Window extends NativeWindow { * @param y coord of the top left corner */ void setPosition(int x, int y); - + int getX(); int getY(); diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 01593b2d9..223b4193a 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -49,7 +49,7 @@ import com.jogamp.newt.impl.Debug; public class NewtCanvasAWT extends java.awt.Canvas { public static final boolean DEBUG = Debug.debug("Window"); - NativeWindow parent = null; + NativeWindow nativeWindow = null; Window newtChild = null; AWTAdapter awtAdapter = null; @@ -101,7 +101,7 @@ public class NewtCanvasAWT extends java.awt.Canvas { public NewtCanvasAWT setNEWTChild(Window child) { if(newtChild!=child) { newtChild = child; - if(null!=parent) { + if(null!=nativeWindow) { java.awt.Container cont = getContainer(this); // reparent right away, addNotify has been called already reparentWindow( (null!=newtChild) ? true : false, cont ); @@ -117,7 +117,7 @@ public class NewtCanvasAWT extends java.awt.Canvas { /** @return this AWT Canvas NativeWindow representation, may be null in case {@link #removeNotify()} has been called, * or {@link #addNotify()} hasn't been called yet.*/ - public NativeWindow getNativeWindow() { return parent; } + public NativeWindow getNativeWindow() { return nativeWindow; } void setWindowAdapter(boolean attach) { if(null!=awtAdapter) { @@ -168,14 +168,14 @@ public class NewtCanvasAWT extends java.awt.Canvas { newtChild.setFocusAction(null); // no AWT focus traversal .. if(add) { - parent = NewtFactoryAWT.getNativeWindow(this, newtChild.getRequestedCapabilities()); - if(null!=parent) { + nativeWindow = NewtFactoryAWT.getNativeWindow(this, newtChild.getRequestedCapabilities()); + if(null!=nativeWindow) { if(DEBUG) { System.err.println("NewtCanvasAWT.reparentWindow: "+newtChild); } setSize(cont.getWidth(), cont.getHeight()); newtChild.setSize(cont.getWidth(), cont.getHeight()); - newtChild.reparentWindow(parent); + newtChild.reparentWindow(nativeWindow); newtChild.setVisible(true); setWindowAdapter(true); newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener @@ -184,7 +184,7 @@ public class NewtCanvasAWT extends java.awt.Canvas { } } else { setWindowAdapter(false); - parent = null; + nativeWindow = null; newtChild.setVisible(false); newtChild.reparentWindow(null); } @@ -215,7 +215,7 @@ public class NewtCanvasAWT extends java.awt.Canvas { if(DEBUG) { System.err.println("NewtCanvasAWT.destroy("+unrecoverable+"): "+newtChild+", from "+cont); } - parent = null; + nativeWindow = null; newtChild.setVisible(false); newtChild.reparentWindow(null); newtChild.destroy(unrecoverable); diff --git a/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java b/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java index 829ffe9c0..7cd6ee370 100644 --- a/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java @@ -28,8 +28,7 @@ package com.jogamp.newt.event; -import com.jogamp.newt.*; -import com.jogamp.nativewindow.util.Rectangle; +import javax.media.nativewindow.util.Rectangle; public class WindowUpdateEvent extends WindowEvent { Rectangle bounds; diff --git a/src/newt/classes/com/jogamp/newt/impl/OffscreenWindow.java b/src/newt/classes/com/jogamp/newt/impl/OffscreenWindow.java index 217d9d293..95c326ce4 100644 --- a/src/newt/classes/com/jogamp/newt/impl/OffscreenWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/OffscreenWindow.java @@ -35,6 +35,7 @@ package com.jogamp.newt.impl; import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Point; public class OffscreenWindow extends WindowImpl implements SurfaceChangeable { @@ -115,5 +116,14 @@ public class OffscreenWindow extends WindowImpl implements SurfaceChangeable { protected void reconfigureWindowImpl(int x, int y, int width, int height) { shouldNotCallThis(); } + + public Point getLocationOnScreen(Point storage) { + if(null!=storage) { + storage.setX(0); + storage.setY(0); + return storage; + } + return new Point(0,0); + } } diff --git a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java index c10d9a491..0e9114145 100644 --- a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java +++ b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java @@ -39,17 +39,17 @@ import com.jogamp.newt.Display; import com.jogamp.newt.Screen; import com.jogamp.newt.Window; import com.jogamp.newt.event.*; -import com.jogamp.newt.util.*; import com.jogamp.common.util.*; import javax.media.nativewindow.*; -import com.jogamp.nativewindow.util.Rectangle; import com.jogamp.nativewindow.impl.RecursiveToolkitLock; -import com.jogamp.newt.impl.OffscreenWindow; import java.util.ArrayList; import java.util.Iterator; import java.lang.reflect.Method; +import javax.media.nativewindow.util.Insets; +import javax.media.nativewindow.util.Point; +import javax.media.nativewindow.util.Rectangle; public abstract class WindowImpl implements Window, NEWTEventConsumer { @@ -263,7 +263,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer //---------------------------------------------------------------------- - // NativeWindow: Native implementation + // NativeSurface: Native implementation // protected int lockSurfaceImpl() { return LOCK_SUCCESS; } @@ -291,7 +291,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer protected void setTitleImpl(String title) {} //---------------------------------------------------------------------- - // NativeWindow + // NativeSurface // public final int lockSurface() { @@ -336,6 +336,18 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer return windowLock.getLockedStack(); } + public long getSurfaceHandle() { + return windowHandle; // default: return window handle + } + + public boolean surfaceSwap() { + return false; + } + + public AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; + } + public final long getDisplayHandle() { return getScreen().getDisplay().getHandle(); } @@ -344,20 +356,32 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer return getScreen().getIndex(); } - public AbstractGraphicsConfiguration getGraphicsConfiguration() { - return config; + //---------------------------------------------------------------------- + // NativeWindow + // + + public final void destroy() { + destroy(false); } - public final long getWindowHandle() { - return windowHandle; + public final NativeWindow getParent() { + return parentWindow; } - public long getSurfaceHandle() { - return windowHandle; // default: return window handle + public final long getWindowHandle() { + return windowHandle; } - public boolean surfaceSwap() { - return false; + public Point getLocationOnScreen(Point storage) { + if(null!=storage) { + storage.translate(getX(),getY()); + } else { + storage = new Point(getX(),getY()); + } + if(null!=parentWindow) { + parentWindow.getLocationOnScreen(storage); + } + return storage; } //---------------------------------------------------------------------- @@ -372,10 +396,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer return null != getScreen() ; } - public final NativeWindow getParentNativeWindow() { - return parentWindow; - } - public final Screen getScreen() { return screen; } @@ -508,10 +528,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } - public final void destroy() { - destroy(false); - } - public void destroy(boolean unrecoverable) { if( isValid() ) { if(DEBUG_IMPLEMENTATION) { @@ -689,7 +705,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer setScreen( (ScreenImpl) newParentWindowNEWT.getScreen() ); displayChanged = true; reparentAction = ACTION_NATIVE_CREATION_PENDING; - } else if(newParentWindow != getParentNativeWindow()) { + } else if(newParentWindow != getParent()) { // Case: Parent's native window realized and changed if( !isNativeValid() ) { // May create a new compatible Screen/Display and @@ -812,6 +828,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer visible = true; setVisibleImpl(true); display.dispatchMessages(); // status up2date + requestFocusImpl(true); + display.dispatchMessages(); // status up2date } } else { // native reparent failed -> try creation @@ -921,7 +939,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } public void requestFocus() { - enqueueRequestFocus(false); // FIXME: or shall we wait ? + // enqueueRequestFocus(false); // FIXME: or shall we wait ? + enqueueRequestFocus(true); } public boolean hasFocus() { @@ -1114,6 +1133,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } public boolean setFullscreen(boolean fullscreen) { + boolean action = false; windowLock.lock(); try{ if(0!=windowHandle && this.fullscreen!=fullscreen) { @@ -1138,11 +1158,14 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } this.fullscreen = fullscreen; reconfigureWindowImpl(x, y, w, h); - requestFocus(); + action = true; } } finally { windowLock.unlock(); } + if(action) { + requestFocus(); + } if( isVisible() ) { sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout and repaint to listener } @@ -1297,11 +1320,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } - public void surfaceUpdated(Object updater, NativeWindow window, long when) { + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { synchronized(surfaceUpdatedListenersLock) { for(Iterator i = surfaceUpdatedListeners.iterator(); i.hasNext(); ) { SurfaceUpdatedListener l = (SurfaceUpdatedListener) i.next(); - l.surfaceUpdated(updater, window, when); + l.surfaceUpdated(updater, ns, when); } } } diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java index e4452d2c8..1f481e28b 100644 --- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -37,19 +38,10 @@ import com.jogamp.newt.event.awt.*; import com.jogamp.newt.util.EDTUtil; import java.awt.BorderLayout; -import java.awt.Canvas; import java.awt.Container; import java.awt.DisplayMode; import java.awt.EventQueue; import java.awt.Frame; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.*; -import com.jogamp.newt.Window; import com.jogamp.newt.impl.WindowImpl; import java.awt.Insets; import javax.media.nativewindow.*; @@ -224,7 +216,7 @@ public class AWTWindow extends WindowImpl { } } - public com.jogamp.newt.util.Insets getInsets() { + public javax.media.nativewindow.util.Insets getInsets() { final int insets[] = new int[] { 0, 0, 0, 0 }; runOnEDT(true, new Runnable() { public void run() { @@ -235,8 +227,7 @@ public class AWTWindow extends WindowImpl { insets[3] = contInsets.right; } }); - return new com.jogamp.newt.util. - Insets(insets[0],insets[1],insets[2],insets[3]); + return new javax.media.nativewindow.util.Insets(insets[0],insets[1],insets[2],insets[3]); } protected void setPositionImpl(final int x, final int y) { diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java index 5043be918..a114417f0 100644 --- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -36,10 +37,9 @@ package com.jogamp.newt.impl.macosx; import javax.media.nativewindow.*; import com.jogamp.nativewindow.impl.RecursiveToolkitLock; -import com.jogamp.newt.*; import com.jogamp.newt.event.*; import com.jogamp.newt.impl.*; -import com.jogamp.newt.util.*; +import javax.media.nativewindow.util.Insets; public class MacWindow extends WindowImpl { diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java index ee3c8e197..3c922b9e7 100644 --- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -34,9 +35,8 @@ package com.jogamp.newt.impl.windows; import javax.media.nativewindow.*; -import com.jogamp.newt.*; -import com.jogamp.newt.util.*; import com.jogamp.newt.impl.WindowImpl; +import javax.media.nativewindow.util.Insets; public class WindowsWindow extends WindowImpl { diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 028f809f0..a7104bf1a 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -36,11 +36,12 @@ package com.jogamp.newt.opengl; import com.jogamp.newt.*; import com.jogamp.newt.event.*; -import com.jogamp.newt.util.Insets; import com.jogamp.newt.impl.WindowImpl; import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Point; import javax.media.opengl.*; import com.jogamp.opengl.impl.GLDrawableHelper; +import javax.media.nativewindow.util.Insets; /** * An implementation of {@link javax.media.opengl.GLAutoDrawable} interface, @@ -62,7 +63,7 @@ public class GLWindow implements GLAutoDrawable, Window { * Constructor. Do not call this directly -- use {@link #create()} instead. */ protected GLWindow(Window window) { - resetPerfCounter(); + resetCounter(); this.window = (WindowImpl) window; ((WindowImpl)this.window).setHandleDestroyNotify(false); window.addWindowListener(new WindowAdapter() { @@ -152,8 +153,8 @@ public class GLWindow implements GLAutoDrawable, Window { return window; } - public final NativeWindow getParentNativeWindow() { - return window.getParentNativeWindow(); + public final NativeWindow getParent() { + return window.getParent(); } public final Screen getScreen() { @@ -253,6 +254,10 @@ public class GLWindow implements GLAutoDrawable, Window { return window.isNativeValid(); } + public Point getLocationOnScreen(Point storage) { + return window.getLocationOnScreen(storage); + } + // Hide methods here .. protected class GLLifecycleHook implements WindowImpl.LifecycleHook { @@ -326,9 +331,9 @@ public class GLWindow implements GLAutoDrawable, Window { } drawable.setRealized(true); context = drawable.createContext(null); - resetPerfCounter(); + resetCounter(); } else if(!visible) { - resetPerfCounter(); + resetCounter(); } if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { String msg = new String("GLWindow.setVisibleAction("+visible+", "+nativeWindowCreated+") "+Thread.currentThread()+", fin"); @@ -349,7 +354,7 @@ public class GLWindow implements GLAutoDrawable, Window { } public synchronized void reparentActionPost(int reparentActionType) { - resetPerfCounter(); + resetCounter(); GLAnimatorControl ctrl = GLWindow.this.getAnimator(); if ( null!=ctrl && animatorPaused ) { animatorPaused = false; @@ -372,14 +377,6 @@ public class GLWindow implements GLAutoDrawable, Window { private long startTime, curTime, lastCheck; private int totalFrames, lastFrames; - /** Reset all performance counter (startTime, currentTime, frame number) */ - public void resetPerfCounter() { - startTime = System.currentTimeMillis(); // overwrite startTime to real init one - curTime = startTime; - lastCheck = startTime; - totalFrames = 0; lastFrames = 0; - } - public GLDrawableFactory getFactory() { return factory; } @@ -450,7 +447,7 @@ public class GLWindow implements GLAutoDrawable, Window { return; } - if( null == context && window.isVisible() ) { + if( null == context && isVisible() ) { // retry native window and drawable/context creation setVisible(true); } @@ -494,7 +491,7 @@ public class GLWindow implements GLAutoDrawable, Window { public void run() { // Lock: Locked Surface/Window by MakeCurrent/Release helper.init(GLWindow.this); - resetPerfCounter(); + resetCounter(); } } private InitAction initAction = new InitAction(); @@ -531,37 +528,17 @@ public class GLWindow implements GLAutoDrawable, Window { /** * @return Time of the first display call in milliseconds. * This value is reset if becoming visible again or reparenting. - * In case an animator is used, - * the corresponding {@link javax.media.opengl.GLAnimatorControl} value is returned. - * - * @see javax.media.opengl.GLAnimatorControl#getStartTime() */ public final long getStartTime() { - GLAnimatorControl animator = getAnimator(); - if ( null == animator || null == animator.getThread() ) { - // no animator, or not started -> use local time - return startTime; - } else { - return animator.getStartTime(); - } + return startTime; } /** * @return Time of the last display call in milliseconds. * This value is reset if becoming visible again or reparenting. - * In case an animator is used, - * the corresponding {@link javax.media.opengl.GLAnimatorControl} value is returned. - * - * @see javax.media.opengl.GLAnimatorControl#getCurrentTime() */ public final long getCurrentTime() { - GLAnimatorControl animator = getAnimator(); - if ( null == animator || null == animator.getThread() ) { - // no animator, or not started -> use local time - return curTime; - } else { - return animator.getCurrentTime(); - } + return curTime; } /** @@ -577,19 +554,17 @@ public class GLWindow implements GLAutoDrawable, Window { /** * @return Number of frames displayed since the first display call, ie <code>getStartTime()</code>. * This value is reset if becoming visible again or reparenting. - * In case an animator is used, - * the corresponding {@link javax.media.opengl.GLAnimatorControl} value is returned. - * - * @see javax.media.opengl.GLAnimatorControl#getTotalFrames() */ - public final int getTotalFrames() { - GLAnimatorControl animator = getAnimator(); - if ( null == animator || null == animator.getThread() ) { - // no animator, or not started -> use local value - return totalFrames; - } else { - return animator.getTotalFrames(); - } + public final int getTotalFrames() { + return totalFrames; + } + + /** Reset all counter (startTime, currentTime, frame number) */ + public synchronized void resetCounter() { + startTime = System.currentTimeMillis(); // overwrite startTime to real init one + curTime = startTime; + lastCheck = startTime; + totalFrames = 0; lastFrames = 0; } class SwapBuffersAction implements Runnable { @@ -603,8 +578,8 @@ public class GLWindow implements GLAutoDrawable, Window { // GLDrawable methods // - public final NativeWindow getNativeWindow() { - return null!=drawable ? drawable.getNativeWindow() : null; + public final NativeSurface getNativeSurface() { + return null!=drawable ? drawable.getNativeSurface() : null; } public final long getHandle() { @@ -824,7 +799,7 @@ public class GLWindow implements GLAutoDrawable, Window { return window.getScreenIndex(); } - public final void surfaceUpdated(Object updater, NativeWindow window, long when) { - window.surfaceUpdated(updater, window, when); + public final void surfaceUpdated(Object updater, NativeSurface ns, long when) { + window.surfaceUpdated(updater, ns, when); } } diff --git a/src/newt/classes/com/jogamp/newt/util/Insets.java b/src/newt/classes/com/jogamp/newt/util/Insets.java deleted file mode 100644 index 068cc1dfb..000000000 --- a/src/newt/classes/com/jogamp/newt/util/Insets.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ -package com.jogamp.newt.util; - -/** - * Simple class representing insets. - * - * @author tdv - */ -public class Insets implements Cloneable { - public int top; - public int left; - public int bottom; - public int right; - - /** - * Creates and initializes a new <code>Insets</code> object with the - * specified top, left, bottom, and right insets. - * @param top the inset from the top. - * @param left the inset from the left. - * @param bottom the inset from the bottom. - * @param right the inset from the right. - */ - public Insets(int top, int left, int bottom, int right) { - this.top = top; - this.left = left; - this.bottom = bottom; - this.right = right; - } - - /** - * Checks whether two insets objects are equal. Two instances - * of <code>Insets</code> are equal if the four integer values - * of the fields <code>top</code>, <code>left</code>, - * <code>bottom</code>, and <code>right</code> are all equal. - * @return <code>true</code> if the two insets are equal; - * otherwise <code>false</code>. - */ - public boolean equals(Object obj) { - if (obj instanceof Insets) { - Insets insets = (Insets)obj; - return ((top == insets.top) && (left == insets.left) && - (bottom == insets.bottom) && (right == insets.right)); - } - return false; - } - - /** - * Returns the hash code for this Insets. - * - * @return a hash code for this Insets. - */ - public int hashCode() { - int sum1 = left + bottom; - int sum2 = right + top; - int val1 = sum1 * (sum1 + 1)/2 + left; - int val2 = sum2 * (sum2 + 1)/2 + top; - int sum3 = val1 + val2; - return sum3 * (sum3 + 1)/2 + val2; - } - - public String toString() { - return getClass().getName() + "[top=" + top + ",left=" + left + - ",bottom=" + bottom + ",right=" + right + "]"; - } - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException ex) { - throw new InternalError(); - } - } - -} diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 4bf2545ab..e1250811c 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -606,7 +607,7 @@ static void NewtWindows_requestFocus (JNIEnv *env, jobject window, HWND hwnd, BO DBG_PRINT("*** WindowsWindow: requestFocus.S parent %p, window %p, isCurrent %d, reparented %d\n", (void*) pHwnd, (void*)hwnd, current==hwnd, (int) reparented); if(reparented || current!=hwnd) { - if( JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { + if( reparented || JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE; if(reparented) { flags |= SWP_FRAMECHANGED; diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 350a0a704..8a07067b7 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -399,11 +400,12 @@ static void NewtWindows_requestFocus (JNIEnv *env, jobject window, Display *dpy, Window focus_return; int revert_to_return; - XGetWindowAttributes(dpy, w, &xwa); XGetInputFocus(dpy, &focus_return, &revert_to_return); if(reparented || focus_return!=w) { - // Avoid 'BadMatch' errors from XSetInputFocus, ie if window is not viewable - if( JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { + if( reparented || JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { + XRaiseWindow(dpy, w); + // Avoid 'BadMatch' errors from XSetInputFocus, ie if window is not viewable + XGetWindowAttributes(dpy, w, &xwa); if(xwa.map_state == IsViewable) { XSetInputFocus(dpy, w, RevertToParent, CurrentTime); } |