27
28 import java.awt.*;
29 import java.awt.Dialog.ModalityType;
30 import java.awt.event.*;
31 import java.awt.peer.WindowPeer;
32 import java.beans.*;
33 import java.util.List;
34
35 import javax.swing.*;
36
37 import sun.awt.*;
38 import sun.java2d.SurfaceData;
39 import sun.java2d.opengl.CGLSurfaceData;
40 import sun.lwawt.*;
41 import sun.util.logging.PlatformLogger;
42
43 import com.apple.laf.*;
44 import com.apple.laf.ClientPropertyApplicator.Property;
45 import com.sun.awt.AWTUtilities;
46
47 public final class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
48 private native long nativeCreateNSWindow(long nsViewPtr, long styleBits, double x, double y, double w, double h);
49 private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
50 private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
51 private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
52 private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
53 private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
54 private static native void nativePushNSWindowToBack(long nsWindowPtr);
55 private static native void nativePushNSWindowToFront(long nsWindowPtr);
56 private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
57 private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
58 private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
59 private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
60 private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
61 private static native void nativeSynthesizeMouseEnteredExitedEvents();
62 private static native void nativeDispose(long nsWindowPtr);
63 private static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
64
65 // Loger to report issues happened during execution but that do not affect functionality
66 private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
67 private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
201 private Window target;
202 private LWWindowPeer peer;
203 private CPlatformView contentView;
204 private CPlatformWindow owner;
205 private boolean visible = false; // visibility status from native perspective
206 private boolean undecorated; // initialized in getInitialStyleBits()
207 private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
208 private CPlatformResponder responder;
209 private volatile boolean zoomed = false; // from native perspective
210
211 public CPlatformWindow() {
212 super(0, true);
213 }
214
215 /*
216 * Delegate initialization (create native window and all the
217 * related resources).
218 */
219 @Override // PlatformWindow
220 public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
221 this.peer = _peer;
222 this.target = _target;
223 if (_owner instanceof CPlatformWindow) {
224 this.owner = (CPlatformWindow)_owner;
225 }
226
227 final int styleBits = getInitialStyleBits();
228
229 // TODO: handle these misc properties
230 final long parentNSWindowPtr = (owner != null ? owner.getNSWindowPtr() : 0);
231 String warningString = target.getWarningString();
232
233 responder = new CPlatformResponder(peer, false);
234 contentView = new CPlatformView();
235 contentView.initialize(peer, responder);
236
237 final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(), styleBits, 0, 0, 0, 0);
238 setPtr(nativeWindowPtr);
239
240 // TODO: implement on top of JObjC bridged class
241 // NSWindow window = JObjC.getInstance().AppKit().NSWindow().getInstance(nativeWindowPtr, JObjCRuntime.getInstance());
242
243 if (target instanceof javax.swing.RootPaneContainer) {
244 final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
245 if (rootpane != null) rootpane.addPropertyChangeListener("ancestor", new PropertyChangeListener() {
246 public void propertyChange(final PropertyChangeEvent evt) {
247 CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
248 rootpane.removePropertyChangeListener("ancestor", this);
249 }
250 });
251 }
252
253 validateSurface();
254 }
255
256 private int getInitialStyleBits() {
257 // defaults style bits
258 int styleBits = DECORATED | HAS_SHADOW | CLOSEABLE | MINIMIZABLE | ZOOMABLE | RESIZABLE;
259
260 if (isNativelyFocusableWindow()) {
261 styleBits = SET(styleBits, SHOULD_BECOME_KEY, true);
262 styleBits = SET(styleBits, SHOULD_BECOME_MAIN, true);
263 }
264
265 final boolean isFrame = (target instanceof Frame);
266 final boolean isDialog = (target instanceof Dialog);
267 final boolean isPopup = (target.getType() == Window.Type.POPUP);
268 if (isDialog) {
269 styleBits = SET(styleBits, MINIMIZABLE, false);
270 }
271
272 // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always is undecorated.
273 {
274 this.undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true);
275 if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
|
27
28 import java.awt.*;
29 import java.awt.Dialog.ModalityType;
30 import java.awt.event.*;
31 import java.awt.peer.WindowPeer;
32 import java.beans.*;
33 import java.util.List;
34
35 import javax.swing.*;
36
37 import sun.awt.*;
38 import sun.java2d.SurfaceData;
39 import sun.java2d.opengl.CGLSurfaceData;
40 import sun.lwawt.*;
41 import sun.util.logging.PlatformLogger;
42
43 import com.apple.laf.*;
44 import com.apple.laf.ClientPropertyApplicator.Property;
45 import com.sun.awt.AWTUtilities;
46
47 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
48 private native long nativeCreateNSWindow(long nsViewPtr, long styleBits, double x, double y, double w, double h);
49 private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
50 private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
51 private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
52 private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
53 private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
54 private static native void nativePushNSWindowToBack(long nsWindowPtr);
55 private static native void nativePushNSWindowToFront(long nsWindowPtr);
56 private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
57 private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
58 private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
59 private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
60 private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
61 private static native void nativeSynthesizeMouseEnteredExitedEvents();
62 private static native void nativeDispose(long nsWindowPtr);
63 private static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
64
65 // Loger to report issues happened during execution but that do not affect functionality
66 private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
67 private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
201 private Window target;
202 private LWWindowPeer peer;
203 private CPlatformView contentView;
204 private CPlatformWindow owner;
205 private boolean visible = false; // visibility status from native perspective
206 private boolean undecorated; // initialized in getInitialStyleBits()
207 private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
208 private CPlatformResponder responder;
209 private volatile boolean zoomed = false; // from native perspective
210
211 public CPlatformWindow() {
212 super(0, true);
213 }
214
215 /*
216 * Delegate initialization (create native window and all the
217 * related resources).
218 */
219 @Override // PlatformWindow
220 public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
221 initializeBase(_target, _peer, _owner, new CPlatformView());
222
223 final int styleBits = getInitialStyleBits();
224
225 // TODO: handle these misc properties
226 final long parentNSWindowPtr = (owner != null ? owner.getNSWindowPtr() : 0);
227 String warningString = target.getWarningString();
228
229 responder = new CPlatformResponder(peer, false);
230 contentView.initialize(peer, responder);
231
232 final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(), styleBits, 0, 0, 0, 0);
233 setPtr(nativeWindowPtr);
234
235 // TODO: implement on top of JObjC bridged class
236 // NSWindow window = JObjC.getInstance().AppKit().NSWindow().getInstance(nativeWindowPtr, JObjCRuntime.getInstance());
237
238 if (target instanceof javax.swing.RootPaneContainer) {
239 final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
240 if (rootpane != null) rootpane.addPropertyChangeListener("ancestor", new PropertyChangeListener() {
241 public void propertyChange(final PropertyChangeEvent evt) {
242 CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
243 rootpane.removePropertyChangeListener("ancestor", this);
244 }
245 });
246 }
247
248 validateSurface();
249 }
250
251 protected void initializeBase(Window target, LWWindowPeer peer, PlatformWindow owner, CPlatformView view) {
252 this.peer = peer;
253 this.target = target;
254 if (owner instanceof CPlatformWindow) {
255 this.owner = (CPlatformWindow)owner;
256 }
257 this.contentView = view;
258 }
259
260 private int getInitialStyleBits() {
261 // defaults style bits
262 int styleBits = DECORATED | HAS_SHADOW | CLOSEABLE | MINIMIZABLE | ZOOMABLE | RESIZABLE;
263
264 if (isNativelyFocusableWindow()) {
265 styleBits = SET(styleBits, SHOULD_BECOME_KEY, true);
266 styleBits = SET(styleBits, SHOULD_BECOME_MAIN, true);
267 }
268
269 final boolean isFrame = (target instanceof Frame);
270 final boolean isDialog = (target instanceof Dialog);
271 final boolean isPopup = (target.getType() == Window.Type.POPUP);
272 if (isDialog) {
273 styleBits = SET(styleBits, MINIMIZABLE, false);
274 }
275
276 // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always is undecorated.
277 {
278 this.undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true);
279 if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
|