@Override protected void closeNativeImpl() { try { if (DEBUG_IMPLEMENTATION) { System.err.println("MacWindow.CloseAction " + Thread.currentThread().getName()); } final long handle = getWindowHandle(); visibleChanged(true, false); setWindowHandle(0); surfaceHandle = 0; sscSurfaceHandle = 0; isOffscreenInstance = false; if (0 != handle) { OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { close0(handle); } }); } } catch (Throwable t) { if (DEBUG_IMPLEMENTATION) { Exception e = new Exception("Warning: closeNative failed - " + Thread.currentThread().getName(), t); e.printStackTrace(); } } }
@Override public void setSurfaceHandle(long surfaceHandle) { if (DEBUG_IMPLEMENTATION) { System.err.println("MacWindow.setSurfaceHandle(): 0x" + Long.toHexString(surfaceHandle)); } sscSurfaceHandle = surfaceHandle; if (isNativeValid()) { if (0 != sscSurfaceHandle) { OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { orderOut0( 0 != getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle()); } }); } /** * this is done by recreation! else if (isVisible()){ OSXUtil.RunOnMainThread(false, new * Runnable() { public void run() { orderFront0( 0!=getParentWindowHandle() ? * getParentWindowHandle() : getWindowHandle() ); } } ); } */ } }
@Override protected void setTitleImpl(final String title) { OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { setTitle0(getWindowHandle(), title); } }); }
private Point getLocationOnScreenImpl( final int x, final int y, final NativeWindow parent, final boolean useParent) { if (!useParent && !isOffscreenInstance && 0 != surfaceHandle) { return OSXUtil.GetLocationOnScreen(surfaceHandle, true, x, y); } final Point p = new Point(x, y); if (useParent) { p.translate(parent.getLocationOnScreen(null)); } return p; }
@Override public final void clearFocus() { if (DEBUG_IMPLEMENTATION) { System.err.println("MacWindow: clearFocus(), isOffscreenInstance " + isOffscreenInstance); } if (!isOffscreenInstance) { OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { resignFocus0(getWindowHandle()); } }); } else { focusChanged(false, false); } }
@Override protected void requestFocusImpl(final boolean force) { if (DEBUG_IMPLEMENTATION) { System.err.println( "MacWindow: requestFocusImpl(), isOffscreenInstance " + isOffscreenInstance); } if (!isOffscreenInstance) { OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { requestFocus0(getWindowHandle(), force); } }); } else { focusChanged(false, true); } }
@Override protected void sizeChanged(boolean defer, int newWidth, int newHeight, boolean force) { final long handle = getWindowHandle(); if (0 != handle && !isOffscreenInstance) { final NativeWindow parent = getParent(); final boolean useParent = useParent(parent); if (useParent && (getWidth() != newWidth || getHeight() != newHeight)) { final int x = getX(), y = getY(); final Point p0S = getLocationOnScreenImpl(x, y, parent, useParent); if (DEBUG_IMPLEMENTATION) { System.err.println( "MacWindow: sizeChanged() parent[" + useParent + " " + x + "/" + y + "] " + getX() + "/" + getY() + " " + newWidth + "x" + newHeight + " -> " + p0S + " screen-client-pos"); } OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { setWindowClientTopLeftPoint0( getWindowHandle(), p0S.getX(), p0S.getY(), isVisible()); } }); } } super.sizeChanged(defer, newWidth, newHeight, force); }
@Override public void updatePosition(int x, int y) { final long handle = getWindowHandle(); if (0 != handle && !isOffscreenInstance) { final NativeWindow parent = getParent(); final boolean useParent = useParent(parent); final int pX = parent.getX(), pY = parent.getY(); final Point p0S = getLocationOnScreenImpl(x, y, parent, useParent); if (DEBUG_IMPLEMENTATION) { System.err.println( "MacWindow: updatePosition() parent[" + useParent + " " + pX + "/" + pY + "] " + x + "/" + y + " -> " + x + "/" + y + " rel-client-pos, " + p0S + " screen-client-pos"); } OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { setWindowClientTopLeftPoint0(handle, p0S.getX(), p0S.getY(), isVisible()); } }); // no native event (fullscreen, some reparenting) positionChanged(true, x, y); } }
private void createWindow( final boolean offscreenInstance, final boolean recreate, final PointImmutable pS, final int width, final int height, final boolean fullscreen, final boolean visible, final boolean alwaysOnTop) { final long parentWinHandle = getParentWindowHandle(); final long preWinHandle = getWindowHandle(); if (DEBUG_IMPLEMENTATION) { System.err.println( "MacWindow.createWindow on thread " + Thread.currentThread().getName() + ": offscreen " + offscreenInstance + ", recreate " + recreate + ", pS " + pS + ", " + width + "x" + height + ", fullscreen " + fullscreen + ", visible " + visible + ", alwaysOnTop " + alwaysOnTop + ", preWinHandle " + toHexString(preWinHandle) + ", parentWin " + toHexString(parentWinHandle) + ", surfaceHandle " + toHexString(surfaceHandle)); // Thread.dumpStack(); } try { if (0 != preWinHandle) { setWindowHandle(0); if (0 == surfaceHandle) { throw new NativeWindowException("Internal Error - create w/ window, but no Newt NSView"); } OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { changeContentView0(parentWinHandle, preWinHandle, 0); close0(preWinHandle); } }); } else { if (0 != surfaceHandle) { throw new NativeWindowException( "Internal Error - create w/o window, but has Newt NSView"); } surfaceHandle = createView0(pS.getX(), pS.getY(), width, height, fullscreen); if (0 == surfaceHandle) { throw new NativeWindowException( "Could not create native view " + Thread.currentThread().getName() + " " + this); } } final long newWin = createWindow0( pS.getX(), pS.getY(), width, height, fullscreen, (isUndecorated() || offscreenInstance) ? NSBorderlessWindowMask : NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, NSBackingStoreBuffered, surfaceHandle); if (newWin == 0) { throw new NativeWindowException( "Could not create native window " + Thread.currentThread().getName() + " " + this); } setWindowHandle(newWin); final boolean isOpaque = getGraphicsConfiguration().getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance; // Blocking initialization on main-thread! OSXUtil.RunOnMainThread( true, new Runnable() { @Override public void run() { initWindow0( parentWinHandle, newWin, pS.getX(), pS.getY(), width, height, isOpaque, fullscreen, visible && !offscreenInstance, surfaceHandle); if (offscreenInstance) { orderOut0(0 != parentWinHandle ? parentWinHandle : newWin); } else { setTitle0(newWin, getTitle()); setAlwaysOnTop0(getWindowHandle(), alwaysOnTop); } visibleChanged(true, visible); } }); } catch (Exception ie) { ie.printStackTrace(); } }
@Override protected boolean reconfigureWindowImpl( final int x, final int y, final int width, final int height, int flags) { final boolean _isOffscreenInstance = isOffscreenInstance(this, this.getParent()); isOffscreenInstance = 0 != sscSurfaceHandle || _isOffscreenInstance; final PointImmutable pClientLevelOnSreen; if (isOffscreenInstance) { pClientLevelOnSreen = new Point(0, 0); } else { final NativeWindow parent = getParent(); final boolean useParent = useParent(parent); if (useParent) { pClientLevelOnSreen = getLocationOnScreenImpl(x, y, parent, useParent); } else { pClientLevelOnSreen = new Point(x, y); } } if (DEBUG_IMPLEMENTATION) { final AbstractGraphicsConfiguration cWinCfg = this.getGraphicsConfiguration(); final NativeWindow pWin = getParent(); final AbstractGraphicsConfiguration pWinCfg = null != pWin ? pWin.getGraphicsConfiguration() : null; System.err.println( "MacWindow reconfig.0: " + x + "/" + y + " -> clientPos " + pClientLevelOnSreen + " - " + width + "x" + height + ",\n\t parent type " + (null != pWin ? pWin.getClass().getName() : null) + ",\n\t this-chosenCaps " + (null != cWinCfg ? cWinCfg.getChosenCapabilities() : null) + ",\n\t parent-chosenCaps " + (null != pWinCfg ? pWinCfg.getChosenCapabilities() : null) + ", isOffscreenInstance(sscSurfaceHandle " + toHexString(sscSurfaceHandle) + ", ioi: " + _isOffscreenInstance + ") -> " + isOffscreenInstance + "\n\t, " + getReconfigureFlagsAsString(null, flags)); // Thread.dumpStack(); } final boolean setVisible = 0 != (FLAG_IS_VISIBLE & flags); if (0 != (FLAG_CHANGE_VISIBILITY & flags) && !setVisible) { if (!isOffscreenInstance) { OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { orderOut0(getWindowHandle()); visibleChanged(true, false); } }); } else { visibleChanged(true, false); } } if (0 == getWindowHandle() && setVisible || 0 != (FLAG_CHANGE_DECORATION & flags) || 0 != (FLAG_CHANGE_PARENTING & flags) || 0 != (FLAG_CHANGE_FULLSCREEN & flags)) { if (isOffscreenInstance) { createWindow( true, 0 != getWindowHandle(), pClientLevelOnSreen, 64, 64, false, setVisible, false); } else { createWindow( false, 0 != getWindowHandle(), pClientLevelOnSreen, width, height, 0 != (FLAG_IS_FULLSCREEN & flags), setVisible, 0 != (FLAG_IS_ALWAYSONTOP & flags)); } } else { if (width > 0 && height > 0) { if (!isOffscreenInstance) { OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { setWindowClientTopLeftPointAndSize0( getWindowHandle(), pClientLevelOnSreen.getX(), pClientLevelOnSreen.getY(), width, height, setVisible); } }); } // else offscreen size is realized via recreation // no native event (fullscreen, some reparenting) positionChanged(true, x, y); sizeChanged(true, width, height, false); } if (0 != (FLAG_CHANGE_VISIBILITY & flags) && setVisible) { if (!isOffscreenInstance) { OSXUtil.RunOnMainThread( false, new Runnable() { @Override public void run() { orderFront0(getWindowHandle()); visibleChanged(true, true); } }); } else { visibleChanged(true, true); } } if (!isOffscreenInstance) { setAlwaysOnTop0(getWindowHandle(), 0 != (FLAG_IS_ALWAYSONTOP & flags)); } } if (DEBUG_IMPLEMENTATION) { System.err.println( "MacWindow reconfig.X: clientPos " + pClientLevelOnSreen + ", " + width + "x" + height + " -> clientPos " + getLocationOnScreenImpl(0, 0) + ", insets: " + getInsets()); } return true; }