8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.lwawt.macosx;
27
28 import com.apple.eawt.FullScreenAdapter;
29 import com.apple.eawt.FullScreenUtilities;
30 import com.apple.eawt.event.FullScreenEvent;
31 import java.awt.*;
32 import java.awt.Dialog.ModalityType;
33 import java.awt.event.*;
34 import java.beans.*;
35 import java.lang.reflect.InvocationTargetException;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.concurrent.atomic.AtomicBoolean;
39 import java.util.concurrent.atomic.AtomicLong;
40 import java.util.concurrent.atomic.AtomicReference;
41
42 import javax.swing.*;
43
44 import sun.awt.*;
45 import sun.awt.AWTAccessor.ComponentAccessor;
46 import sun.awt.AWTAccessor.WindowAccessor;
47 import sun.java2d.SurfaceData;
48 import sun.java2d.opengl.CGLSurfaceData;
49 import sun.lwawt.*;
50 import sun.util.logging.PlatformLogger;
51
52 import com.apple.laf.*;
53 import com.apple.laf.ClientPropertyApplicator.Property;
54 import com.sun.awt.AWTUtilities;
55 import sun.lwawt.LWWindowPeer.PeerType;
56
57 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
58 private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
59 private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
60 private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
61 private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
62 private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
63 private static native void nativeSetNSWindowLocationByPlatform(long nsWindowPtr);
64 private static native void nativeSetNSWindowStandardFrame(long nsWindowPtr,
65 double x, double y, double w, double h);
66 private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
67 private static native void nativePushNSWindowToBack(long nsWindowPtr);
68 private static native void nativePushNSWindowToFront(long nsWindowPtr);
69 private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
70 private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
71 private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
72 private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
73 private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
74 private static native void nativeSynthesizeMouseEnteredExitedEvents();
75 private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr, int eventType);
155 static final int _CALLBACK_PROP_BITMASK = SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN | MODAL_EXCLUDED;
156
157 static int SET(final int bits, final int mask, final boolean value) {
158 if (value) return (bits | mask);
159 return bits & ~mask;
160 }
161
162 static boolean IS(final int bits, final int mask) {
163 return (bits & mask) != 0;
164 }
165
166 @SuppressWarnings({"unchecked", "rawtypes"})
167 static ClientPropertyApplicator<JRootPane, CPlatformWindow> CLIENT_PROPERTY_APPLICATOR = new ClientPropertyApplicator<JRootPane, CPlatformWindow>(new Property[] {
168 new Property<CPlatformWindow>(WINDOW_DOCUMENT_MODIFIED) { public void applyProperty(final CPlatformWindow c, final Object value) {
169 c.setStyleBits(DOCUMENT_MODIFIED, value == null ? false : Boolean.parseBoolean(value.toString()));
170 }},
171 new Property<CPlatformWindow>(WINDOW_BRUSH_METAL_LOOK) { public void applyProperty(final CPlatformWindow c, final Object value) {
172 c.setStyleBits(TEXTURED, Boolean.parseBoolean(value.toString()));
173 }},
174 new Property<CPlatformWindow>(WINDOW_ALPHA) { public void applyProperty(final CPlatformWindow c, final Object value) {
175 AWTUtilities.setWindowOpacity(c.target, value == null ? 1.0f : Float.parseFloat(value.toString()));
176 }},
177 new Property<CPlatformWindow>(WINDOW_SHADOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
178 c.setStyleBits(HAS_SHADOW, value == null ? true : Boolean.parseBoolean(value.toString()));
179 }},
180 new Property<CPlatformWindow>(WINDOW_MINIMIZABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
181 c.setStyleBits(MINIMIZABLE, Boolean.parseBoolean(value.toString()));
182 }},
183 new Property<CPlatformWindow>(WINDOW_CLOSEABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
184 c.setStyleBits(CLOSEABLE, Boolean.parseBoolean(value.toString()));
185 }},
186 new Property<CPlatformWindow>(WINDOW_ZOOMABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
187 boolean zoomable = Boolean.parseBoolean(value.toString());
188 if (c.target instanceof RootPaneContainer
189 && c.getPeer().getPeerType() == PeerType.FRAME) {
190 if (c.isInFullScreen && !zoomable) {
191 c.toggleFullScreen();
192 }
193 }
194 c.setStyleBits(ZOOMABLE, zoomable);
195 }},
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.lwawt.macosx;
27
28 import java.awt.Color;
29 import java.awt.Component;
30 import java.awt.DefaultKeyboardFocusManager;
31 import java.awt.Dialog;
32 import java.awt.Dialog.ModalityType;
33 import java.awt.Font;
34 import java.awt.FontMetrics;
35 import java.awt.Frame;
36 import java.awt.GraphicsDevice;
37 import java.awt.Insets;
38 import java.awt.MenuBar;
39 import java.awt.Point;
40 import java.awt.Rectangle;
41 import java.awt.Toolkit;
42 import java.awt.Window;
43 import java.awt.event.FocusEvent;
44 import java.awt.event.WindowEvent;
45 import java.beans.PropertyChangeEvent;
46 import java.beans.PropertyChangeListener;
47 import java.lang.reflect.InvocationTargetException;
48 import java.util.ArrayList;
49 import java.util.Arrays;
50 import java.util.concurrent.atomic.AtomicBoolean;
51 import java.util.concurrent.atomic.AtomicLong;
52 import java.util.concurrent.atomic.AtomicReference;
53
54 import javax.swing.JRootPane;
55 import javax.swing.RootPaneContainer;
56 import javax.swing.SwingUtilities;
57
58 import com.apple.laf.ClientPropertyApplicator;
59 import com.apple.laf.ClientPropertyApplicator.Property;
60 import sun.awt.AWTAccessor;
61 import sun.awt.AWTAccessor.ComponentAccessor;
62 import sun.awt.AWTAccessor.WindowAccessor;
63 import sun.java2d.SurfaceData;
64 import sun.java2d.opengl.CGLSurfaceData;
65 import sun.lwawt.LWToolkit;
66 import sun.lwawt.LWWindowPeer;
67 import sun.lwawt.LWWindowPeer.PeerType;
68 import sun.lwawt.PlatformWindow;
69 import sun.util.logging.PlatformLogger;
70
71 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
72 private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
73 private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
74 private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
75 private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
76 private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
77 private static native void nativeSetNSWindowLocationByPlatform(long nsWindowPtr);
78 private static native void nativeSetNSWindowStandardFrame(long nsWindowPtr,
79 double x, double y, double w, double h);
80 private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
81 private static native void nativePushNSWindowToBack(long nsWindowPtr);
82 private static native void nativePushNSWindowToFront(long nsWindowPtr);
83 private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
84 private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
85 private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
86 private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
87 private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
88 private static native void nativeSynthesizeMouseEnteredExitedEvents();
89 private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr, int eventType);
169 static final int _CALLBACK_PROP_BITMASK = SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN | MODAL_EXCLUDED;
170
171 static int SET(final int bits, final int mask, final boolean value) {
172 if (value) return (bits | mask);
173 return bits & ~mask;
174 }
175
176 static boolean IS(final int bits, final int mask) {
177 return (bits & mask) != 0;
178 }
179
180 @SuppressWarnings({"unchecked", "rawtypes"})
181 static ClientPropertyApplicator<JRootPane, CPlatformWindow> CLIENT_PROPERTY_APPLICATOR = new ClientPropertyApplicator<JRootPane, CPlatformWindow>(new Property[] {
182 new Property<CPlatformWindow>(WINDOW_DOCUMENT_MODIFIED) { public void applyProperty(final CPlatformWindow c, final Object value) {
183 c.setStyleBits(DOCUMENT_MODIFIED, value == null ? false : Boolean.parseBoolean(value.toString()));
184 }},
185 new Property<CPlatformWindow>(WINDOW_BRUSH_METAL_LOOK) { public void applyProperty(final CPlatformWindow c, final Object value) {
186 c.setStyleBits(TEXTURED, Boolean.parseBoolean(value.toString()));
187 }},
188 new Property<CPlatformWindow>(WINDOW_ALPHA) { public void applyProperty(final CPlatformWindow c, final Object value) {
189 c.target.setOpacity(value == null ? 1.0f : Float.parseFloat(value.toString()));
190 }},
191 new Property<CPlatformWindow>(WINDOW_SHADOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
192 c.setStyleBits(HAS_SHADOW, value == null ? true : Boolean.parseBoolean(value.toString()));
193 }},
194 new Property<CPlatformWindow>(WINDOW_MINIMIZABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
195 c.setStyleBits(MINIMIZABLE, Boolean.parseBoolean(value.toString()));
196 }},
197 new Property<CPlatformWindow>(WINDOW_CLOSEABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
198 c.setStyleBits(CLOSEABLE, Boolean.parseBoolean(value.toString()));
199 }},
200 new Property<CPlatformWindow>(WINDOW_ZOOMABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
201 boolean zoomable = Boolean.parseBoolean(value.toString());
202 if (c.target instanceof RootPaneContainer
203 && c.getPeer().getPeerType() == PeerType.FRAME) {
204 if (c.isInFullScreen && !zoomable) {
205 c.toggleFullScreen();
206 }
207 }
208 c.setStyleBits(ZOOMABLE, zoomable);
209 }},
|