mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-29 14:52:52 +00:00
7124553: [macosx] Need minimum size for titled Frames and JFrames
Forward-port the fix from 7u4 and also eliminate the grow box since we only support OS X 10.7+ that doesn't require it. Reviewed-by: art, swingler
This commit is contained in:
parent
1862aaa218
commit
654920cc5b
@ -661,11 +661,19 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
|
||||
@Override
|
||||
public void setResizable(boolean resizable) {
|
||||
setStyleBits(RESIZABLE, resizable);
|
||||
|
||||
// Re-apply the size constraints and the size to ensure the space
|
||||
// occupied by the grow box is counted properly
|
||||
setMinimumSize(1, 1); // the method ignores its arguments
|
||||
|
||||
Rectangle bounds = peer.getBounds();
|
||||
setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMinimumSize(int width, int height) {
|
||||
//TODO width, height should be used
|
||||
//NOTE: setResizable() calls setMinimumSize(1,1) relaying on the logic below
|
||||
final long nsWindowPtr = getNSWindowPtr();
|
||||
final Dimension min = target.getMinimumSize();
|
||||
final Dimension max = target.getMaximumSize();
|
||||
|
||||
@ -39,7 +39,6 @@
|
||||
@private
|
||||
JNFWeakJObjectWrapper *javaPlatformWindow;
|
||||
CMenuBar *javaMenuBar;
|
||||
NSWindow *growBoxWindow;
|
||||
NSSize javaMinSize;
|
||||
NSSize javaMaxSize;
|
||||
jint styleBits;
|
||||
@ -47,7 +46,6 @@
|
||||
|
||||
@property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
|
||||
@property (nonatomic, retain) CMenuBar *javaMenuBar;
|
||||
@property (nonatomic, retain) NSWindow *growBoxWindow;
|
||||
@property (nonatomic) NSSize javaMinSize;
|
||||
@property (nonatomic) NSSize javaMaxSize;
|
||||
@property (nonatomic) jint styleBits;
|
||||
|
||||
@ -40,7 +40,6 @@
|
||||
#import "ThreadUtilities.h"
|
||||
#import "OSVersion.h"
|
||||
|
||||
|
||||
#define MASK(KEY) \
|
||||
(sun_lwawt_macosx_CPlatformWindow_ ## KEY)
|
||||
|
||||
@ -50,31 +49,12 @@
|
||||
#define SET(BITS, KEY, VALUE) \
|
||||
BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
|
||||
|
||||
|
||||
static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
|
||||
|
||||
@interface JavaResizeGrowBoxOverlayWindow : NSWindow { }
|
||||
|
||||
@end
|
||||
|
||||
@implementation JavaResizeGrowBoxOverlayWindow
|
||||
|
||||
- (BOOL) accessibilityIsIgnored
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSArray *)accessibilityChildrenAttribute
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation AWTWindow
|
||||
|
||||
@synthesize javaPlatformWindow;
|
||||
@synthesize javaMenuBar;
|
||||
@synthesize growBoxWindow;
|
||||
@synthesize javaMinSize;
|
||||
@synthesize javaMaxSize;
|
||||
@synthesize styleBits;
|
||||
@ -154,24 +134,6 @@ static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
|
||||
|
||||
}
|
||||
|
||||
- (BOOL) shouldShowGrowBox {
|
||||
return isSnowLeopardOrLower() && IS(self.styleBits, RESIZABLE);
|
||||
}
|
||||
|
||||
- (NSImage *) createGrowBoxImage {
|
||||
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(12, 12)];
|
||||
JRSUIControlRef growBoxWidget = JRSUIControlCreate(FALSE);
|
||||
JRSUIControlSetWidget(growBoxWidget, kJRSUI_Widget_growBoxTextured);
|
||||
JRSUIControlSetWindowType(growBoxWidget, kJRSUI_WindowType_utility);
|
||||
JRSUIRendererRef renderer = JRSUIRendererCreate();
|
||||
[image lockFocus]; // sets current graphics context to that of the image
|
||||
JRSUIControlDraw(renderer, growBoxWidget, [[NSGraphicsContext currentContext] graphicsPort], CGRectMake(0, 1, 11, 11));
|
||||
[image unlockFocus];
|
||||
JRSUIRendererRelease(renderer);
|
||||
JRSUIControlRelease(growBoxWidget);
|
||||
return image;
|
||||
}
|
||||
|
||||
- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
|
||||
styleBits:(jint)bits
|
||||
frameRect:(NSRect)rect
|
||||
@ -205,28 +167,6 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
[self setReleasedWhenClosed:NO];
|
||||
[self setPreservesContentDuringLiveResize:YES];
|
||||
|
||||
if ([self shouldShowGrowBox]) {
|
||||
NSImage *growBoxImage = [self createGrowBoxImage];
|
||||
growBoxWindow = [[JavaResizeGrowBoxOverlayWindow alloc] initWithContentRect:NSMakeRect(0, 0, [growBoxImage size].width, [growBoxImage size].height) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
|
||||
[self.growBoxWindow setIgnoresMouseEvents:YES];
|
||||
[self.growBoxWindow setOpaque:NO];
|
||||
[self.growBoxWindow setBackgroundColor:[NSColor clearColor]];
|
||||
[self.growBoxWindow setHasShadow:NO];
|
||||
[self.growBoxWindow setReleasedWhenClosed:NO];
|
||||
|
||||
NSImageView *imageView = [[NSImageView alloc] initWithFrame:[self.growBoxWindow frame]];
|
||||
[imageView setEditable:NO];
|
||||
[imageView setAnimates:NO];
|
||||
[imageView setAllowsCutCopyPaste:NO];
|
||||
[self.growBoxWindow setContentView:imageView];
|
||||
[imageView setImage:growBoxImage];
|
||||
[growBoxImage release];
|
||||
[imageView release];
|
||||
|
||||
[self addChildWindow:self.growBoxWindow ordered:NSWindowAbove];
|
||||
[self adjustGrowBoxWindow];
|
||||
} else growBoxWindow = nil;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -235,7 +175,6 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
|
||||
JNIEnv *env = [ThreadUtilities getJNIEnv];
|
||||
[self.javaPlatformWindow setJObject:nil withEnv:env];
|
||||
self.growBoxWindow = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
@ -321,14 +260,6 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
|
||||
// NSWindowDelegate methods
|
||||
|
||||
- (void) adjustGrowBoxWindow {
|
||||
if (self.growBoxWindow != nil) {
|
||||
NSRect parentRect = [self frame];
|
||||
parentRect.origin.x += (parentRect.size.width - [self.growBoxWindow frame].size.width);
|
||||
[self.growBoxWindow setFrameOrigin:parentRect.origin];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) _deliverMoveResizeEvent {
|
||||
AWT_ASSERT_APPKIT_THREAD;
|
||||
|
||||
@ -342,8 +273,6 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
// TODO: create generic AWT assert
|
||||
}
|
||||
|
||||
[self adjustGrowBoxWindow];
|
||||
|
||||
NSRect frame = ConvertNSScreenRect(env, [self frame]);
|
||||
|
||||
static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIII)V");
|
||||
@ -548,6 +477,31 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
}
|
||||
[super sendEvent:event];
|
||||
}
|
||||
|
||||
- (void)constrainSize:(NSSize*)size {
|
||||
float minWidth = 0.f, minHeight = 0.f;
|
||||
|
||||
if (IS(self.styleBits, DECORATED)) {
|
||||
NSRect frame = [self frame];
|
||||
NSRect contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[self styleMask]];
|
||||
|
||||
float top = frame.size.height - contentRect.size.height;
|
||||
float left = contentRect.origin.x - frame.origin.x;
|
||||
float bottom = contentRect.origin.y - frame.origin.y;
|
||||
float right = frame.size.width - (contentRect.size.width + left);
|
||||
|
||||
// Speculative estimation: 80 - enough for window decorations controls
|
||||
minWidth += left + right + 80;
|
||||
minHeight += top + bottom;
|
||||
}
|
||||
|
||||
minWidth = MAX(1.f, minWidth);
|
||||
minHeight = MAX(1.f, minHeight);
|
||||
|
||||
size->width = MAX(size->width, minWidth);
|
||||
size->height = MAX(size->height, minHeight);
|
||||
}
|
||||
|
||||
@end // AWTWindow
|
||||
|
||||
|
||||
@ -703,6 +657,8 @@ AWT_ASSERT_NOT_APPKIT_THREAD;
|
||||
AWT_ASSERT_APPKIT_THREAD;
|
||||
|
||||
NSRect rect = ConvertNSScreenRect(NULL, jrect);
|
||||
[window constrainSize:&rect.size];
|
||||
|
||||
[window setFrame:rect display:YES];
|
||||
|
||||
// only start tracking events if pointer is above the toplevel
|
||||
@ -734,13 +690,16 @@ AWT_ASSERT_NOT_APPKIT_THREAD;
|
||||
if (maxW < 1) maxW = 1;
|
||||
if (maxH < 1) maxH = 1;
|
||||
|
||||
NSSize min = { minW, minH };
|
||||
NSSize max = { maxW, maxH };
|
||||
|
||||
AWTWindow *window = OBJC(windowPtr);
|
||||
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
|
||||
AWT_ASSERT_APPKIT_THREAD;
|
||||
|
||||
NSSize min = { minW, minH };
|
||||
NSSize max = { maxW, maxH };
|
||||
|
||||
[window constrainSize:&min];
|
||||
[window constrainSize:&max];
|
||||
|
||||
window.javaMinSize = min;
|
||||
window.javaMaxSize = max;
|
||||
[window updateMinMaxSize:IS(window.styleBits, RESIZABLE)];
|
||||
@ -830,7 +789,6 @@ AWT_ASSERT_NOT_APPKIT_THREAD;
|
||||
AWT_ASSERT_APPKIT_THREAD;
|
||||
|
||||
[window setAlphaValue:alpha];
|
||||
[window.growBoxWindow setAlphaValue:alpha];
|
||||
}];
|
||||
|
||||
JNF_COCOA_EXIT(env);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user