mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-10-07 09:33:28 +00:00
size/move notification fixes, invalid window in NSEvent fix and addition of hasMainMenu private API
This commit is contained in:
parent
3d2dd5e5e2
commit
8c3d5bb8f0
@ -103,7 +103,7 @@ typedef enum {
|
||||
|
||||
-delegate;
|
||||
-(NSArray *)windows;
|
||||
-(NSWindow *)windowWithWindowNumber:(int)number;
|
||||
-(NSWindow *)windowWithWindowNumber:(NSInteger)number;
|
||||
|
||||
-(NSMenu *)mainMenu;
|
||||
-(NSMenu *)windowsMenu;
|
||||
|
@ -156,7 +156,7 @@ id NSApp=nil;
|
||||
return _windows;
|
||||
}
|
||||
|
||||
-(NSWindow *)windowWithWindowNumber:(int)number {
|
||||
-(NSWindow *)windowWithWindowNumber:(NSInteger)number {
|
||||
int i,count=[_windows count];
|
||||
|
||||
for(i=0;i<count;i++){
|
||||
|
@ -148,7 +148,7 @@ enum {
|
||||
NSTimeInterval _timestamp;
|
||||
NSPoint _locationInWindow;
|
||||
NSUInteger _modifierFlags;
|
||||
NSWindow *_window;
|
||||
NSInteger _windowNumber;
|
||||
}
|
||||
|
||||
+(NSPoint)mouseLocation;
|
||||
@ -176,6 +176,7 @@ enum {
|
||||
-(NSPoint)locationInWindow;
|
||||
-(unsigned)modifierFlags;
|
||||
-(NSWindow *)window;
|
||||
-(NSInteger)windowNumber;
|
||||
|
||||
-(int)clickCount;
|
||||
-(float)deltaX;
|
||||
|
@ -33,12 +33,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
_timestamp=[NSDate timeIntervalSinceReferenceDate];
|
||||
_locationInWindow=location;
|
||||
_modifierFlags=modifierFlags;
|
||||
_window=window;
|
||||
_windowNumber=[window windowNumber];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
_window=nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@ -88,7 +87,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
}
|
||||
|
||||
-(NSWindow *)window {
|
||||
return _window;
|
||||
return [NSApp windowWithWindowNumber:[self windowNumber]];
|
||||
}
|
||||
|
||||
-(NSInteger)windowNumber {
|
||||
return _windowNumber;
|
||||
}
|
||||
|
||||
-(int)clickCount {
|
||||
|
@ -15,7 +15,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
_locationInWindow=location;
|
||||
_modifierFlags=modifierFlags;
|
||||
_timestamp = time;
|
||||
_window = (NSWindow *)windowNum;
|
||||
_windowNumber = windowNum;
|
||||
_subtype = subtype;
|
||||
_data1 = data1;
|
||||
_data2 = data2;
|
||||
|
@ -12,14 +12,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
@implementation NSPanel
|
||||
|
||||
+(NSRect)frameRectForContentRect:(NSRect)contentRect styleMask:(unsigned)styleMask {
|
||||
NSRect result=CGOutsetRectForNativeWindowBorder(contentRect,styleMask);
|
||||
return result;
|
||||
}
|
||||
|
||||
+(NSRect)contentRectForFrameRect:(NSRect)frameRect styleMask:(unsigned)styleMask {
|
||||
NSRect result=CGInsetRectForNativeWindowBorder(frameRect,styleMask);
|
||||
return result;
|
||||
+(BOOL)hasMainMenuForStyleMask:(NSUInteger)styleMask {
|
||||
return NO;
|
||||
}
|
||||
|
||||
-initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(unsigned)backing defer:(BOOL)defer {
|
||||
|
@ -102,7 +102,7 @@ APPKIT_EXPORT NSString * const NSWindowDidEndLiveResizeNotification;
|
||||
|
||||
@interface NSWindow : NSResponder {
|
||||
NSRect _frame;
|
||||
unsigned _styleMask;
|
||||
NSUInteger _styleMask;
|
||||
NSBackingStoreType _backingType;
|
||||
NSInteger _level;
|
||||
|
||||
|
@ -79,11 +79,22 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
return 0;
|
||||
}
|
||||
|
||||
+(BOOL)hasMainMenuForStyleMask:(NSUInteger)styleMask {
|
||||
if(styleMask&NSTitledWindowMask)
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(BOOL)hasMainMenu {
|
||||
return [isa hasMainMenuForStyleMask:_styleMask];
|
||||
}
|
||||
|
||||
+(NSRect)frameRectForContentRect:(NSRect)contentRect styleMask:(unsigned)styleMask {
|
||||
NSRect result=CGOutsetRectForNativeWindowBorder(contentRect,styleMask);
|
||||
|
||||
if(styleMask!=0)
|
||||
result.size.height+=[NSMainMenuView menuHeight];
|
||||
if([self hasMainMenuForStyleMask:styleMask])
|
||||
result.size.height+=[NSMainMenuView menuHeight];
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -91,8 +102,8 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
+(NSRect)contentRectForFrameRect:(NSRect)frameRect styleMask:(unsigned)styleMask {
|
||||
NSRect result=CGInsetRectForNativeWindowBorder(frameRect,styleMask);
|
||||
|
||||
if(styleMask!=0)
|
||||
result.size.height-=[NSMainMenuView menuHeight];
|
||||
if([self hasMainMenuForStyleMask:styleMask])
|
||||
result.size.height-=[NSMainMenuView menuHeight];
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -161,7 +172,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
_miniwindowTitle=@"";
|
||||
|
||||
_menu=nil;
|
||||
if(![self isKindOfClass:[NSPanel class]] && styleMask!=0){
|
||||
if([self hasMainMenu]){
|
||||
NSRect frame=NSMakeRect(contentViewFrame.origin.x,NSMaxY(contentViewFrame),contentViewFrame.size.width,[NSMainMenuView menuHeight]);
|
||||
|
||||
_menu=[[NSApp mainMenu] copy];
|
||||
@ -662,9 +673,10 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
frame.origin.y=(leastY+20)-frame.size.height;
|
||||
}
|
||||
|
||||
if(changed)
|
||||
if(changed){
|
||||
[self setFrame:frame display:YES];
|
||||
|
||||
}
|
||||
|
||||
_makeSureIsOnAScreen=NO;
|
||||
}
|
||||
#else
|
||||
@ -701,9 +713,9 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
frame.origin.y=virtual.origin.y-frame.size.height;
|
||||
}
|
||||
|
||||
if(changed)
|
||||
if(changed){
|
||||
[self setFrame:frame display:YES];
|
||||
|
||||
}
|
||||
_makeSureIsOnAScreen=NO;
|
||||
}
|
||||
#endif
|
||||
@ -771,17 +783,20 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
_makeSureIsOnAScreen=YES;
|
||||
|
||||
[_backgroundView setFrameSize:_frame.size];
|
||||
[[self platformWindow] setFrame:_frame];
|
||||
|
||||
[[self platformWindow] setFrame:_frame];
|
||||
|
||||
if(didSize)
|
||||
[self resetCursorRects];
|
||||
|
||||
if(didSize)
|
||||
if(didSize){
|
||||
[self postNotificationName:NSWindowDidResizeNotification];
|
||||
}
|
||||
|
||||
if(didMove)
|
||||
if(didMove){
|
||||
[self postNotificationName:NSWindowDidMoveNotification];
|
||||
|
||||
}
|
||||
|
||||
// If you setFrame:display:YES before rearranging views with only setFrame: calls (which do not mark the view for display)
|
||||
// Cocoa will properly redisplay the views
|
||||
// So, doing a hard display right here is not the right thing to do, delay it
|
||||
@ -819,6 +834,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
|
||||
frame.origin.x=point.x;
|
||||
frame.origin.y=point.y-frame.size.height;
|
||||
|
||||
[self setFrame:frame display:YES];
|
||||
}
|
||||
|
||||
@ -975,6 +991,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
[toolbarView setFrameOrigin:toolbarOrigin];
|
||||
|
||||
[[self contentView] setAutoresizingMask:NSViewNotSizable];
|
||||
|
||||
[self setFrame:frame display:NO animate:NO];
|
||||
|
||||
[[self contentView] setAutoresizingMask:mask];
|
||||
@ -1324,7 +1341,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
}
|
||||
|
||||
-(BOOL)canBecomeMainWindow {
|
||||
return YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)canBecomeVisibleWithoutLogin {
|
||||
@ -2048,9 +2065,11 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
else
|
||||
topLeftPoint.y = frame.origin.y + frame.size.height;
|
||||
|
||||
if (reposition)
|
||||
if (reposition){
|
||||
[self setFrame:frame display:YES];
|
||||
|
||||
|
||||
}
|
||||
|
||||
return topLeftPoint;
|
||||
}
|
||||
|
||||
@ -2294,20 +2313,21 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
frame=[self frame];
|
||||
frame.size.height+=(newSize.height-oldSize.height);
|
||||
// no display because setMenu: is called before awakeFromNib
|
||||
|
||||
[self setFrame:frame display:NO];
|
||||
// do we even need this?
|
||||
[_backgroundView setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)_hideMenuViewIfNeeded {
|
||||
if(_menuView!=nil && ![_menuView isHidden]){
|
||||
if([self hasMainMenu] && _menuView!=nil && ![_menuView isHidden]){
|
||||
[_menuView setHidden:YES];
|
||||
[self _resizeWithOldMenuViewSize:[_menuView frame].size];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)_showMenuViewIfNeeded {
|
||||
if(_menuView!=nil && [_menuView isHidden]){
|
||||
if([self hasMainMenu] && _menuView!=nil && [_menuView isHidden]){
|
||||
[_menuView setHidden:NO];
|
||||
[self _resizeWithOldMenuViewSize:NSMakeSize(0,0)];
|
||||
}
|
||||
@ -2318,7 +2338,7 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
NSSize oldSize=[_menuView frame].size;
|
||||
|
||||
[_menuView setMenu:menu];
|
||||
|
||||
|
||||
[self _resizeWithOldMenuViewSize:oldSize];
|
||||
}
|
||||
|
||||
@ -2523,10 +2543,12 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
[self saveFrameUsingName:_autosaveFrameName];
|
||||
[self resetCursorRects];
|
||||
|
||||
if(didSize)
|
||||
if(didSize){
|
||||
[self postNotificationName:NSWindowDidResizeNotification];
|
||||
else
|
||||
}
|
||||
else{
|
||||
[self postNotificationName:NSWindowDidMoveNotification];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)platformWindowExitMove:(CGWindow *)window {
|
||||
|
@ -325,14 +325,17 @@ static const char *Win32ClassNameForStyleMask(unsigned styleMask,bool hasShadow)
|
||||
}
|
||||
|
||||
-(void)setFrame:(CGRect)frame {
|
||||
[self invalidateContextsWithNewSize:frame.size];
|
||||
|
||||
// _frame must be set before the MoveWindow as MoveWindow generates WM_SIZE and WM_MOVE messages
|
||||
// which need to check the size against the current to prevent erroneous resize/move notifications
|
||||
_frame=frame;
|
||||
|
||||
CGRect moveTo=convertFrameToWin32ScreenCoordinates(frame);
|
||||
|
||||
_ignoreMinMaxMessage=YES;
|
||||
MoveWindow(_handle, moveTo.origin.x, moveTo.origin.y,moveTo.size.width, moveTo.size.height,YES);
|
||||
_ignoreMinMaxMessage=NO;
|
||||
|
||||
[self invalidateContextsWithNewSize:frame.size];
|
||||
_frame=frame;
|
||||
}
|
||||
|
||||
-(void)setOpaque:(BOOL)value {
|
||||
@ -776,7 +779,12 @@ i=count;
|
||||
}
|
||||
|
||||
-(int)WM_MOVE_wParam:(WPARAM)wParam lParam:(LPARAM)lParam {
|
||||
[_delegate platformWindowWillMove:self];
|
||||
NSPoint checkOrigin=[self queryFrame].origin;
|
||||
|
||||
if(NSEqualPoints(checkOrigin,_frame.origin))
|
||||
return 0;
|
||||
|
||||
[_delegate platformWindowWillMove:self];
|
||||
[self _GetWindowRectDidSize:NO];
|
||||
[_delegate platformWindowDidMove:self];
|
||||
return 0;
|
||||
|
@ -12,6 +12,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import <AppKit/NSMainMenuView.h>
|
||||
#import <AppKit/NSWindow-Private.h>
|
||||
|
||||
@interface NSWindow(private)
|
||||
+(BOOL)hasMainMenuForStyleMask:(NSUInteger)styleMask;
|
||||
@end
|
||||
|
||||
@implementation NSWindowTemplate
|
||||
|
||||
-initWithCoder:(NSCoder *)coder {
|
||||
@ -32,7 +36,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
_windowAutosave=[[keyed decodeObjectForKey:@"NSFrameAutosaveName"] retain];
|
||||
|
||||
_windowRect.origin.y -= _screenRect.size.height - [[NSScreen mainScreen] frame].size.height;
|
||||
if (![_windowClass isEqualToString:@"NSPanel"])
|
||||
if ([_windowClass hasMainMenuForStyleMask:_windowStyleMask])
|
||||
_windowRect.origin.y -= [NSMainMenuView menuHeight]; // compensation for the additional menu bar
|
||||
}
|
||||
else {
|
||||
|
@ -13,8 +13,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#endif
|
||||
|
||||
BOOL NSZombieEnabled=NO;
|
||||
BOOL NSDebugEnabled=YES;
|
||||
BOOL NSCooperativeThreadsEnabled=YES;
|
||||
BOOL NSDebugEnabled=NO;
|
||||
BOOL NSCooperativeThreadsEnabled=NO;
|
||||
|
||||
const char* _NSPrintForDebugger(id object) {
|
||||
if(object && [object respondsToSelector:@selector(description)]) {
|
||||
|
Loading…
Reference in New Issue
Block a user