47 import com.sun.awt.AWTUtilities;
48
49 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
50 private native long nativeCreateNSWindow(long nsViewPtr, long styleBits, double x, double y, double w, double h);
51 private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
52 private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
53 private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
54 private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
55 private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
56 private static native void nativePushNSWindowToBack(long nsWindowPtr);
57 private static native void nativePushNSWindowToFront(long nsWindowPtr);
58 private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
59 private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
60 private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
61 private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
62 private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
63 private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
64 private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr);
65 private static native void nativeDispose(long nsWindowPtr);
66
67 private static native int nativeGetNSWindowDisplayID(long nsWindowPtr);
68
69 // Loger to report issues happened during execution but that do not affect functionality
70 private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
71 private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
72
73 // for client properties
74 public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";
75 public static final String WINDOW_DRAGGABLE_BACKGROUND = "apple.awt.draggableWindowBackground";
76
77 public static final String WINDOW_ALPHA = "Window.alpha";
78 public static final String WINDOW_SHADOW = "Window.shadow";
79
80 public static final String WINDOW_STYLE = "Window.style";
81 public static final String WINDOW_SHADOW_REVALIDATE_NOW = "apple.awt.windowShadow.revalidateNow";
82
83 public static final String WINDOW_DOCUMENT_MODIFIED = "Window.documentModified";
84 public static final String WINDOW_DOCUMENT_FILE = "Window.documentFile";
85
86 public static final String WINDOW_CLOSEABLE = "Window.closeable";
87 public static final String WINDOW_MINIMIZABLE = "Window.minimizable";
88 public static final String WINDOW_ZOOMABLE = "Window.zoomable";
194 }
195 };
196
197 // Bounds of the native widget but in the Java coordinate system.
198 // In order to keep it up-to-date we will update them on
199 // 1) setting native bounds via nativeSetBounds() call
200 // 2) getting notification from the native level via deliverMoveResizeEvent()
201 private Rectangle nativeBounds;
202 private volatile boolean isFullScreenMode = false;
203
204 private Window target;
205 private LWWindowPeer peer;
206 private CPlatformView contentView;
207 private CPlatformWindow owner;
208 private boolean visible = false; // visibility status from native perspective
209 private boolean undecorated; // initialized in getInitialStyleBits()
210 private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
211 private CPlatformResponder responder;
212 private volatile boolean zoomed = false; // from native perspective
213
214 public CPlatformWindow(final PeerType peerType) {
215 super(0, true);
216 assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME);
217 }
218
219 /*
220 * Delegate initialization (create native window and all the
221 * related resources).
222 */
223 @Override // PlatformWindow
224 public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
225 this.peer = _peer;
226 this.target = _target;
227 if (_owner instanceof CPlatformWindow) {
228 this.owner = (CPlatformWindow)_owner;
229 }
230
231 final int styleBits = getInitialStyleBits();
232
233 // TODO: handle these misc properties
234 final long parentNSWindowPtr = (owner != null ? owner.getNSWindowPtr() : 0);
235 String warningString = target.getWarningString();
236
424 @Override // PlatformWindow
425 public FontMetrics getFontMetrics(Font f) {
426 // TODO: not implemented
427 (new RuntimeException("unimplemented")).printStackTrace();
428 return null;
429 }
430
431 @Override // PlatformWindow
432 public Insets getInsets() {
433 final Insets insets = nativeGetNSWindowInsets(getNSWindowPtr());
434 return insets;
435 }
436
437 @Override // PlatformWindow
438 public Point getLocationOnScreen() {
439 return new Point(nativeBounds.x, nativeBounds.y);
440 }
441
442 @Override
443 public GraphicsDevice getGraphicsDevice() {
444 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
445 CGraphicsEnvironment cge = (CGraphicsEnvironment)ge;
446 int displayID = nativeGetNSWindowDisplayID(getNSWindowPtr());
447 GraphicsDevice gd = cge.getScreenDevice(displayID);
448 if (gd == null) {
449 // this could possibly happen during device removal
450 // use the default screen device in this case
451 gd = ge.getDefaultScreenDevice();
452 }
453 return gd;
454 }
455
456 @Override // PlatformWindow
457 public SurfaceData getScreenSurface() {
458 // TODO: not implemented
459 return null;
460 }
461
462 @Override // PlatformWindow
463 public SurfaceData replaceSurfaceData() {
464 return contentView.replaceSurfaceData();
465 }
466
467 @Override // PlatformWindow
468 public void setBounds(int x, int y, int w, int h) {
469 // assert CThreading.assertEventQueue();
470 nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
471 }
472
473 private boolean isVisible() {
844 // Assume images are square, so check their widths only
845 int width = image.getWidth(null);
846 for (Image img : icons) {
847 final int w = img.getWidth(null);
848 if (w > width) {
849 image = img;
850 width = w;
851 }
852 }
853 return CImage.getCreator().createFromImage(image);
854 }
855
856 /*
857 * Returns LWWindowPeer associated with this delegate.
858 */
859 @Override
860 public LWWindowPeer getPeer() {
861 return peer;
862 }
863
864 public CPlatformView getContentView() {
865 return contentView;
866 }
867
868 @Override
869 public long getLayerPtr() {
870 return contentView.getWindowLayerPtr();
871 }
872
873 private void validateSurface() {
874 SurfaceData surfaceData = getSurfaceData();
875 if (surfaceData instanceof CGLSurfaceData) {
876 ((CGLSurfaceData)surfaceData).validate();
877 }
878 }
879
880 /*************************************************************
881 * Callbacks from the AWTWindow and AWTView objc classes.
882 *************************************************************/
883 private void deliverWindowFocusEvent(boolean gained){
|
47 import com.sun.awt.AWTUtilities;
48
49 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
50 private native long nativeCreateNSWindow(long nsViewPtr, long styleBits, double x, double y, double w, double h);
51 private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
52 private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
53 private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
54 private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
55 private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
56 private static native void nativePushNSWindowToBack(long nsWindowPtr);
57 private static native void nativePushNSWindowToFront(long nsWindowPtr);
58 private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
59 private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
60 private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
61 private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
62 private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
63 private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
64 private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr);
65 private static native void nativeDispose(long nsWindowPtr);
66
67 // Loger to report issues happened during execution but that do not affect functionality
68 private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
69 private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
70
71 // for client properties
72 public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";
73 public static final String WINDOW_DRAGGABLE_BACKGROUND = "apple.awt.draggableWindowBackground";
74
75 public static final String WINDOW_ALPHA = "Window.alpha";
76 public static final String WINDOW_SHADOW = "Window.shadow";
77
78 public static final String WINDOW_STYLE = "Window.style";
79 public static final String WINDOW_SHADOW_REVALIDATE_NOW = "apple.awt.windowShadow.revalidateNow";
80
81 public static final String WINDOW_DOCUMENT_MODIFIED = "Window.documentModified";
82 public static final String WINDOW_DOCUMENT_FILE = "Window.documentFile";
83
84 public static final String WINDOW_CLOSEABLE = "Window.closeable";
85 public static final String WINDOW_MINIMIZABLE = "Window.minimizable";
86 public static final String WINDOW_ZOOMABLE = "Window.zoomable";
192 }
193 };
194
195 // Bounds of the native widget but in the Java coordinate system.
196 // In order to keep it up-to-date we will update them on
197 // 1) setting native bounds via nativeSetBounds() call
198 // 2) getting notification from the native level via deliverMoveResizeEvent()
199 private Rectangle nativeBounds;
200 private volatile boolean isFullScreenMode = false;
201
202 private Window target;
203 private LWWindowPeer peer;
204 private CPlatformView contentView;
205 private CPlatformWindow owner;
206 private boolean visible = false; // visibility status from native perspective
207 private boolean undecorated; // initialized in getInitialStyleBits()
208 private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
209 private CPlatformResponder responder;
210 private volatile boolean zoomed = false; // from native perspective
211
212 public CPlatformWindow() {
213 super(0, true);
214 }
215
216 /*
217 * Delegate initialization (create native window and all the
218 * related resources).
219 */
220 @Override // PlatformWindow
221 public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
222 this.peer = _peer;
223 this.target = _target;
224 if (_owner instanceof CPlatformWindow) {
225 this.owner = (CPlatformWindow)_owner;
226 }
227
228 final int styleBits = getInitialStyleBits();
229
230 // TODO: handle these misc properties
231 final long parentNSWindowPtr = (owner != null ? owner.getNSWindowPtr() : 0);
232 String warningString = target.getWarningString();
233
421 @Override // PlatformWindow
422 public FontMetrics getFontMetrics(Font f) {
423 // TODO: not implemented
424 (new RuntimeException("unimplemented")).printStackTrace();
425 return null;
426 }
427
428 @Override // PlatformWindow
429 public Insets getInsets() {
430 final Insets insets = nativeGetNSWindowInsets(getNSWindowPtr());
431 return insets;
432 }
433
434 @Override // PlatformWindow
435 public Point getLocationOnScreen() {
436 return new Point(nativeBounds.x, nativeBounds.y);
437 }
438
439 @Override
440 public GraphicsDevice getGraphicsDevice() {
441 return contentView.getGraphicsDevice();
442 }
443
444 @Override // PlatformWindow
445 public SurfaceData getScreenSurface() {
446 // TODO: not implemented
447 return null;
448 }
449
450 @Override // PlatformWindow
451 public SurfaceData replaceSurfaceData() {
452 return contentView.replaceSurfaceData();
453 }
454
455 @Override // PlatformWindow
456 public void setBounds(int x, int y, int w, int h) {
457 // assert CThreading.assertEventQueue();
458 nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
459 }
460
461 private boolean isVisible() {
832 // Assume images are square, so check their widths only
833 int width = image.getWidth(null);
834 for (Image img : icons) {
835 final int w = img.getWidth(null);
836 if (w > width) {
837 image = img;
838 width = w;
839 }
840 }
841 return CImage.getCreator().createFromImage(image);
842 }
843
844 /*
845 * Returns LWWindowPeer associated with this delegate.
846 */
847 @Override
848 public LWWindowPeer getPeer() {
849 return peer;
850 }
851
852 @Override
853 public boolean isUnderMouse() {
854 return contentView.isUnderMouse();
855 }
856
857 public CPlatformView getContentView() {
858 return contentView;
859 }
860
861 @Override
862 public long getLayerPtr() {
863 return contentView.getWindowLayerPtr();
864 }
865
866 private void validateSurface() {
867 SurfaceData surfaceData = getSurfaceData();
868 if (surfaceData instanceof CGLSurfaceData) {
869 ((CGLSurfaceData)surfaceData).validate();
870 }
871 }
872
873 /*************************************************************
874 * Callbacks from the AWTWindow and AWTView objc classes.
875 *************************************************************/
876 private void deliverWindowFocusEvent(boolean gained){
|