< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m

Print this page


   1 /*
   2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


  38 
  39 #define MASK(KEY) \
  40     (sun_lwawt_macosx_CPlatformWindow_ ## KEY)
  41 
  42 #define IS(BITS, KEY) \
  43     ((BITS & MASK(KEY)) != 0)
  44 
  45 #define SET(BITS, KEY, VALUE) \
  46     BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
  47 
  48 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
  49 
  50 // Cocoa windowDidBecomeKey/windowDidResignKey notifications
  51 // doesn't provide information about "opposite" window, so we
  52 // have to do a bit of tracking. This variable points to a window
  53 // which had been the key window just before a new key window
  54 // was set. It would be nil if the new key window isn't an AWT
  55 // window or the app currently has no key window.
  56 static AWTWindow* lastKeyWindow = nil;
  57 





  58 // --------------------------------------------------------------
  59 // NSWindow/NSPanel descendants implementation
  60 #define AWT_NS_WINDOW_IMPLEMENTATION                            \
  61 - (id) initWithDelegate:(AWTWindow *)delegate                   \
  62               frameRect:(NSRect)contectRect                     \
  63               styleMask:(NSUInteger)styleMask                   \
  64             contentView:(NSView *)view                          \
  65 {                                                               \
  66     self = [super initWithContentRect:contectRect               \
  67                             styleMask:styleMask                 \
  68                               backing:NSBackingStoreBuffered    \
  69                                 defer:NO];                      \
  70                                                                 \
  71     if (self == nil) return nil;                                \
  72                                                                 \
  73     [self setDelegate:delegate];                                \
  74     [self setContentView:view];                                 \
  75     [self setInitialFirstResponder:view];                       \
  76     [self setReleasedWhenClosed:NO];                            \
  77     [self setPreservesContentDuringLiveResize:YES];             \


1067 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY,
1068      jdouble width, jdouble height)
1069 {
1070     JNF_COCOA_ENTER(env);
1071     
1072     NSRect jrect = NSMakeRect(originX, originY, width, height);
1073     
1074     NSWindow *nsWindow = OBJC(windowPtr);
1075     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1076         
1077         NSRect rect = ConvertNSScreenRect(NULL, jrect);
1078         AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1079         window.standardFrame = rect;
1080     }];
1081     
1082     JNF_COCOA_EXIT(env);
1083 }
1084 
1085 /*
1086  * Class:     sun_lwawt_macosx_CPlatformWindow

























1087  * Method:    nativeSetNSWindowMinMax
1088  * Signature: (JDDDD)V
1089  */
1090 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax
1091 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH)
1092 {
1093 JNF_COCOA_ENTER(env);
1094 
1095     if (minW < 1) minW = 1;
1096     if (minH < 1) minH = 1;
1097     if (maxW < 1) maxW = 1;
1098     if (maxH < 1) maxH = 1;
1099 
1100     NSWindow *nsWindow = OBJC(windowPtr);
1101     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1102 
1103         AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1104 
1105         NSSize min = { minW, minH };
1106         NSSize max = { maxW, maxH };


   1 /*
   2  * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


  38 
  39 #define MASK(KEY) \
  40     (sun_lwawt_macosx_CPlatformWindow_ ## KEY)
  41 
  42 #define IS(BITS, KEY) \
  43     ((BITS & MASK(KEY)) != 0)
  44 
  45 #define SET(BITS, KEY, VALUE) \
  46     BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
  47 
  48 static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
  49 
  50 // Cocoa windowDidBecomeKey/windowDidResignKey notifications
  51 // doesn't provide information about "opposite" window, so we
  52 // have to do a bit of tracking. This variable points to a window
  53 // which had been the key window just before a new key window
  54 // was set. It would be nil if the new key window isn't an AWT
  55 // window or the app currently has no key window.
  56 static AWTWindow* lastKeyWindow = nil;
  57 
  58 // This variable contains coordinates of a window's top left
  59 // which was positioned via java.awt.Window.setLocationByPlatform.
  60 // It would be NSZeroPoint if 'Location by Platform' is not used.
  61 static NSPoint lastTopLeftPoint;
  62 
  63 // --------------------------------------------------------------
  64 // NSWindow/NSPanel descendants implementation
  65 #define AWT_NS_WINDOW_IMPLEMENTATION                            \
  66 - (id) initWithDelegate:(AWTWindow *)delegate                   \
  67               frameRect:(NSRect)contectRect                     \
  68               styleMask:(NSUInteger)styleMask                   \
  69             contentView:(NSView *)view                          \
  70 {                                                               \
  71     self = [super initWithContentRect:contectRect               \
  72                             styleMask:styleMask                 \
  73                               backing:NSBackingStoreBuffered    \
  74                                 defer:NO];                      \
  75                                                                 \
  76     if (self == nil) return nil;                                \
  77                                                                 \
  78     [self setDelegate:delegate];                                \
  79     [self setContentView:view];                                 \
  80     [self setInitialFirstResponder:view];                       \
  81     [self setReleasedWhenClosed:NO];                            \
  82     [self setPreservesContentDuringLiveResize:YES];             \


1072 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY,
1073      jdouble width, jdouble height)
1074 {
1075     JNF_COCOA_ENTER(env);
1076     
1077     NSRect jrect = NSMakeRect(originX, originY, width, height);
1078     
1079     NSWindow *nsWindow = OBJC(windowPtr);
1080     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1081         
1082         NSRect rect = ConvertNSScreenRect(NULL, jrect);
1083         AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1084         window.standardFrame = rect;
1085     }];
1086     
1087     JNF_COCOA_EXIT(env);
1088 }
1089 
1090 /*
1091  * Class:     sun_lwawt_macosx_CPlatformWindow
1092  * Method:    nativeSetNSWindowLocationByPlatform
1093  * Signature: (J)V
1094  */
1095 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowLocationByPlatform
1096 (JNIEnv *env, jclass clazz, jlong windowPtr)
1097 {
1098     JNF_COCOA_ENTER(env);
1099     
1100     NSWindow *nsWindow = OBJC(windowPtr);
1101     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1102         
1103         if (NSEqualPoints(lastTopLeftPoint, NSZeroPoint)) {
1104             // This is the first usage of lastTopLeftPoint. So invoke cascadeTopLeftFromPoint
1105             // twice to avoid positioning the window's top left to zero-point, since it may
1106             // cause negative user experience.
1107             lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint];
1108         }
1109         lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint];
1110     }];
1111     
1112     JNF_COCOA_EXIT(env);
1113 }
1114 
1115 /*
1116  * Class:     sun_lwawt_macosx_CPlatformWindow
1117  * Method:    nativeSetNSWindowMinMax
1118  * Signature: (JDDDD)V
1119  */
1120 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax
1121 (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH)
1122 {
1123 JNF_COCOA_ENTER(env);
1124 
1125     if (minW < 1) minW = 1;
1126     if (minH < 1) minH = 1;
1127     if (maxW < 1) maxW = 1;
1128     if (maxH < 1) maxH = 1;
1129 
1130     NSWindow *nsWindow = OBJC(windowPtr);
1131     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1132 
1133         AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1134 
1135         NSSize min = { minW, minH };
1136         NSSize max = { maxW, maxH };


< prev index next >