darling-cocotron/AppKit/NSWindow.m

2801 lines
76 KiB
Mathematica
Raw Normal View History

/* Copyright (c) 2006-2007 Christopher J. W. Lloyd <cjwl@objc.net>
2009 Markus Hitter <mah@jump-ing.de>
2006-12-22 04:41:44 +00:00
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <AppKit/NSWindow.h>
#import <AppKit/NSWindow-Private.h>
#import <AppKit/NSWindowBackgroundView.h>
#import <AppKit/NSMainMenuView.h>
#import <AppKit/NSSheetContext.h>
#import <AppKit/NSApplication.h>
#import <AppKit/NSScreen.h>
#import <AppKit/NSEvent.h>
#import <AppKit/NSEvent_CoreGraphics.h>
#import <AppKit/NSColor.h>
#import <CoreGraphics/CGWindow.h>
#import <ApplicationServices/ApplicationServices.h>
2006-12-22 04:41:44 +00:00
#import <AppKit/NSGraphics.h>
#import <AppKit/NSMenu.h>
#import <AppKit/NSMenuItem.h>
#import <AppKit/NSPanel.h>
#import <AppKit/NSView.h>
#import <AppKit/NSImage.h>
#import <AppKit/NSDraggingManager.h>
#import <AppKit/NSCursor.h>
#import <AppKit/NSTextView.h>
#import <AppKit/NSTrackingArea.h>
2006-12-22 04:41:44 +00:00
#import <AppKit/NSToolbar.h>
#import <AppKit/NSWindowAnimationContext.h>
#import <AppKit/NSToolTipWindow.h>
#import <AppKit/NSDisplay.h>
#import <AppKit/NSRaise.h>
2006-12-22 04:41:44 +00:00
NSString * const NSWindowDidBecomeKeyNotification=@"NSWindowDidBecomeKeyNotification";
NSString * const NSWindowDidResignKeyNotification=@"NSWindowDidResignKeyNotification";
NSString * const NSWindowDidBecomeMainNotification=@"NSWindowDidBecomeMainNotification";
NSString * const NSWindowDidResignMainNotification=@"NSWindowDidResignMainNotification";
NSString * const NSWindowWillMiniaturizeNotification=@"NSWindowWillMiniaturizeNotification";
NSString * const NSWindowDidMiniaturizeNotification=@"NSWindowDidMiniaturizeNotification";
NSString * const NSWindowDidDeminiaturizeNotification=@"NSWindowDidDeminiaturizeNotification";
NSString * const NSWindowDidMoveNotification=@"NSWindowDidMoveNotification";
NSString * const NSWindowDidResizeNotification=@"NSWindowDidResizeNotification";
NSString * const NSWindowDidUpdateNotification=@"NSWindowDidUpdateNotification";
NSString * const NSWindowWillCloseNotification=@"NSWindowWillCloseNotification";
NSString * const NSWindowWillMoveNotification=@"NSWindowWillMoveNotification";
NSString * const NSWindowWillStartLiveResizeNotification=@"NSWindowWillStartLiveResizeNotification";
NSString * const NSWindowDidEndLiveResizeNotification=@"NSWindowDidEndLiveResizeNotification";
2006-12-22 04:41:44 +00:00
NSString * const NSWindowWillAnimateNotification=@"NSWindowWillAnimateNotification";
NSString * const NSWindowAnimatingNotification=@"NSWindowAnimatingNotification";
NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification";
2006-12-22 04:41:44 +00:00
@interface NSToolbar (NSToolbar_privateForWindow)
- (void)_setWindow:(NSWindow *)window;
- (NSView *)_view;
-(CGFloat)visibleHeight;
-(void)layoutFrameSizeWithWidth:(CGFloat)width;
2006-12-22 04:41:44 +00:00
@end
2010-03-29 19:48:09 +00:00
@interface NSWindow ()
- (NSRect) zoomedFrame;
@end
2006-12-22 04:41:44 +00:00
@implementation NSWindow
+(NSWindowDepth)defaultDepthLimit {
return 0;
}
2006-12-22 04:41:44 +00:00
+(NSRect)frameRectForContentRect:(NSRect)contentRect styleMask:(unsigned)styleMask {
NSRect result=CGOutsetRectForNativeWindowBorder(contentRect,styleMask);
if(styleMask!=0)
result.size.height+=[NSMainMenuView menuHeight];
return result;
2006-12-22 04:41:44 +00:00
}
+(NSRect)contentRectForFrameRect:(NSRect)frameRect styleMask:(unsigned)styleMask {
NSRect result=CGInsetRectForNativeWindowBorder(frameRect,styleMask);
if(styleMask!=0)
result.size.height-=[NSMainMenuView menuHeight];
return result;
2006-12-22 04:41:44 +00:00
}
+(float)minFrameWidthWithTitle:(NSString *)title styleMask:(unsigned)styleMask {
NSUnimplementedMethod();
return 0;
}
+(NSInteger)windowNumberAtPoint:(NSPoint)point belowWindowWithWindowNumber:(NSInteger)window {
NSUnimplementedMethod();
return 0;
}
+(NSArray *)windowNumbersWithOptions:(NSWindowNumberListOptions)options {
NSUnimplementedMethod();
return nil;
}
+(void)removeFrameUsingName:(NSString *)name {
NSUnimplementedMethod();
}
+(NSButton *)standardWindowButton:(NSWindowButton)button forStyleMask:(unsigned)styleMask {
NSUnimplementedMethod();
return nil;
}
+(void)menuChanged:(NSMenu *)menu {
NSUnimplementedMethod();
}
2006-12-22 04:41:44 +00:00
-(void)encodeWithCoder:(NSCoder *)coder {
NSUnimplementedMethod();
}
-initWithCoder:(NSCoder *)coder {
[NSException raise:NSInvalidArgumentException format:@"-[%@ %s] is not implemented for coder %@",isa,sel_getName(_cmd),coder];
2006-12-22 04:41:44 +00:00
return self;
}
-initWithContentRect:(NSRect)contentRect styleMask:(unsigned)styleMask backing:(unsigned)backing defer:(BOOL)defer {
NSRect backgroundFrame;
NSRect contentViewFrame;
2006-12-22 04:41:44 +00:00
_frame=[isa frameRectForContentRect:contentRect styleMask:styleMask];
backgroundFrame.origin=NSMakePoint(0,0);
backgroundFrame.size=_frame.size;
contentViewFrame=[isa contentRectForFrameRect:backgroundFrame styleMask:styleMask];
2010-03-29 19:48:09 +00:00
_savedFrame = _frame;
2006-12-22 04:41:44 +00:00
_styleMask=styleMask;
_backingType=backing;
_level=NSNormalWindowLevel;
2006-12-22 04:41:44 +00:00
_minSize=NSMakeSize(0,0);
_maxSize=NSMakeSize(0,0);
_title=@"";
_miniwindowTitle=@"";
_menu=nil;
if(![self isKindOfClass:[NSPanel class]] && styleMask!=0){
NSRect frame=NSMakeRect(contentViewFrame.origin.x,NSMaxY(contentViewFrame),contentViewFrame.size.width,[NSMainMenuView menuHeight]);
2006-12-22 04:41:44 +00:00
_menu=[[NSApp mainMenu] copy];
_menuView=[[NSMainMenuView alloc] initWithFrame:frame menu:_menu];
[_menuView setAutoresizingMask:NSViewWidthSizable|NSViewMinYMargin];
}
_backgroundView=[[NSWindowBackgroundView alloc] initWithFrame:backgroundFrame];
[_backgroundView setAutoresizesSubviews:YES];
[_backgroundView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[_backgroundView _setWindow:self];
[_backgroundView setNextResponder:self];
_contentView=[[NSView alloc] initWithFrame:contentViewFrame];
[_contentView setAutoresizesSubviews:YES];
[_contentView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
_backgroundColor=[[NSColor windowBackgroundColor] copy];
_delegate=nil;
_firstResponder=self;
_fieldEditor=nil;
_draggedTypes=nil;
_trackingAreas=nil;
_allowsToolTipsWhenApplicationIsInactive=NO;
2006-12-22 04:41:44 +00:00
_sheetContext=nil;
_isVisible=NO;
_isDocumentEdited=NO;
_makeSureIsOnAScreen=YES;
_excludedFromWindowsMenu=NO;
2006-12-22 04:41:44 +00:00
_acceptsMouseMovedEvents=NO;
_excludedFromWindowsMenu=NO;
2006-12-22 04:41:44 +00:00
_isDeferred=defer;
_isOneShot=NO;
_useOptimizedDrawing=NO;
_releaseWhenClosed=YES;
_hidesOnDeactivate=NO;
_viewsNeedDisplay=YES;
_flushNeeded=YES;
_resizeIncrements=NSMakeSize(1,1);
_contentResizeIncrements=NSMakeSize(1,1);
2006-12-22 04:41:44 +00:00
_autosaveFrameName=nil;
_platformWindow=nil;
if(_menuView!=nil)
[_backgroundView addSubview:_menuView];
[_backgroundView addSubview:_contentView];
[_backgroundView setNeedsDisplay:YES];
2006-12-22 04:41:44 +00:00
[[NSApplication sharedApplication] _addWindow:self];
return self;
}
-initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(unsigned)backing defer:(BOOL)defer screen:(NSScreen *)screen {
// FIX, relocate contentRect
return [self initWithContentRect:contentRect styleMask:styleMask backing:backing defer:defer];
}
-(NSWindow *)initWithWindowRef:(void *)carbonRef {
NSUnimplementedMethod();
return nil;
}
2006-12-22 04:41:44 +00:00
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_childWindows release];
2006-12-22 04:41:44 +00:00
[_title release];
[_miniwindowTitle release];
[_miniwindowImage release];
[_backgroundView _setWindow:nil];
[_backgroundView release];
[_menu release];
[_menuView release];
[_contentView release];
[_backgroundColor release];
[_fieldEditor release];
[_draggedTypes release];
[_trackingAreas release];
2006-12-22 04:41:44 +00:00
[_autosaveFrameName release];
[_platformWindow invalidate];
[_platformWindow release];
_platformWindow=nil;
[_graphicsContext release];
_graphicsContext=nil;
2006-12-22 04:41:44 +00:00
[_undoManager release];
[super dealloc];
}
-(void)_updatePlatformWindowTitle {
NSString *title;
if([self isMiniaturized])
title=[self miniwindowTitle];
else
title=[self title];
if(_isDocumentEdited)
title=[@"* " stringByAppendingString:title];
[_platformWindow setTitle:title];
}
-(CGWindow *)platformWindow {
if(_platformWindow==nil){
if([self isKindOfClass:[NSPanel class]])
_platformWindow=[[[NSDisplay currentDisplay] panelWithFrame: _frame styleMask:_styleMask backingType:_backingType] retain];
else
_platformWindow=[[[NSDisplay currentDisplay] windowWithFrame: _frame styleMask:_styleMask backingType:_backingType] retain];
[_platformWindow setDelegate:self];
[_platformWindow setLevel:_level];
2006-12-22 04:41:44 +00:00
[self _updatePlatformWindowTitle];
[[NSDraggingManager draggingManager] registerWindow:self dragTypes:nil];
}
return _platformWindow;
}
-(CGContextRef)cgContext {
return [[self platformWindow] cgContext];
2006-12-22 04:41:44 +00:00
}
-(void)setStyleMask:(unsigned)mask {
_styleMask=mask;
[_platformWindow setStyleMask:_styleMask];
[self _hideMenuViewIfNeeded];
[_backgroundView resizeSubviewsWithOldSize:[_backgroundView frame].size];
[_backgroundView setNeedsDisplay:YES]; // FIXME: verify this is done
2006-12-22 04:41:44 +00:00
}
-(void)postNotificationName:(NSString *)name {
[[NSNotificationCenter defaultCenter] postNotificationName:name
object:self];
}
-(NSGraphicsContext *)graphicsContext {
if(_graphicsContext==nil)
_graphicsContext=[[NSGraphicsContext graphicsContextWithWindow:self] retain];
return _graphicsContext;
}
-(void)platformWindowDidInvalidateCGContext:(CGWindow *)window {
[_graphicsContext release];
_graphicsContext=nil;
}
-(NSDictionary *)deviceDescription {
NSValue *resolution=[NSValue valueWithSize:NSMakeSize(72.0,72.0)];
NSValue *size=[NSValue valueWithSize:[self frame].size];
return [NSDictionary dictionaryWithObjectsAndKeys:
resolution,NSDeviceResolution,
NSDeviceRGBColorSpace,NSDeviceColorSpaceName,
[NSNumber numberWithInt:8],NSDeviceBitsPerSample,
[NSNumber numberWithBool:YES],NSDeviceIsScreen,
size,NSDeviceSize,
nil];
2006-12-22 04:41:44 +00:00
}
-(void *)windowRef {
NSUnimplementedMethod();
return NULL;
}
-(BOOL)allowsConcurrentViewDrawing {
NSUnimplementedMethod();
return NO;
}
-(void)setAllowsConcurrentViewDrawing:(BOOL)allows {
NSUnimplementedMethod();
}
-(NSView *)contentView {
2006-12-22 04:41:44 +00:00
return _contentView;
}
-(id)delegate {
2006-12-22 04:41:44 +00:00
return _delegate;
}
-(NSString *)title {
return _title;
2006-12-22 04:41:44 +00:00
}
-(NSString *)representedFilename {
return _representedFilename;
2006-12-22 04:41:44 +00:00
}
-(NSURL *)representedURL {
NSUnimplementedMethod();
return nil;
}
-(int)level {
return _level;
}
-(NSRect)frame {
return _frame;
2006-12-22 04:41:44 +00:00
}
-(unsigned)styleMask {
return _styleMask;
}
-(NSBackingStoreType)backingType {
return _backingType;
}
-(NSWindowBackingLocation)preferredBackingLocation {
NSUnimplementedMethod();
return 0;
}
-(void)setPreferredBackingLocation:(NSWindowBackingLocation)location {
NSUnimplementedMethod();
}
-(NSWindowBackingLocation)backingLocation {
NSUnimplementedMethod();
return 0;
}
-(NSSize)minSize {
return _minSize;
}
-(NSSize)maxSize {
return _maxSize;
}
-(NSSize)contentMinSize {
return _contentMinSize;
}
-(NSSize)contentMaxSize {
return _contentMaxSize;
}
2006-12-22 04:41:44 +00:00
-(BOOL)isOneShot {
return _isOneShot;
}
-(BOOL)isOpaque {
return _isOpaque;
}
-(BOOL)hasDynamicDepthLimit {
return _dynamicDepthLimit;
}
2006-12-22 04:41:44 +00:00
-(BOOL)isReleasedWhenClosed {
return _releaseWhenClosed;
}
-(BOOL)preventsApplicationTerminationWhenModal {
NSUnimplementedMethod();
return NO;
}
-(void)setPreventsApplicationTerminationWhenModal:(BOOL)prevents {
NSUnimplementedMethod();
}
2006-12-22 04:41:44 +00:00
-(BOOL)hidesOnDeactivate {
return _hidesOnDeactivate;
}
-(BOOL)worksWhenModal {
return NO;
}
-(BOOL)isSheet {
return (_styleMask&NSDocModalWindowMask)?YES:NO;
}
-(BOOL)acceptsMouseMovedEvents {
return _acceptsMouseMovedEvents;
}
-(BOOL)isExcludedFromWindowsMenu {
return _excludedFromWindowsMenu;
}
-(BOOL)isAutodisplay {
return _isAutodisplay;
}
-(BOOL)isFlushWindowDisabled {
return _isFlushWindowDisabled;
}
-(NSString *)frameAutosaveName {
return _autosaveFrameName;
2006-12-22 04:41:44 +00:00
}
-(BOOL)hasShadow {
return _hasShadow;
2006-12-22 04:41:44 +00:00
}
-(BOOL)ignoresMouseEvents {
return _ignoresMouseEvents;
2006-12-22 04:41:44 +00:00
}
-(NSSize)aspectRatio {
return NSMakeSize(1.0,_resizeIncrements.height/_resizeIncrements.width);
2006-12-22 04:41:44 +00:00
}
-(NSSize)contentAspectRatio {
return NSMakeSize(1.0,_contentResizeIncrements.height/_contentResizeIncrements.width);
2006-12-22 04:41:44 +00:00
}
-(BOOL)autorecalculatesKeyViewLoop {
return _autorecalculatesKeyViewLoop;
2006-12-22 04:41:44 +00:00
}
-(BOOL)canHide {
return _canHide;
2006-12-22 04:41:44 +00:00
}
-(BOOL)canStoreColor {
return _canStoreColor;
}
-(BOOL)showsResizeIndicator {
return _showsResizeIndicator;
2006-12-22 04:41:44 +00:00
}
-(BOOL)showsToolbarButton {
return _showsToolbarButton;
}
-(BOOL)displaysWhenScreenProfileChanges {
return _displaysWhenScreenProfileChanges;
2006-12-22 04:41:44 +00:00
}
-(BOOL)isMovableByWindowBackground {
return _isMovableByWindowBackground;
2006-12-22 04:41:44 +00:00
}
-(BOOL)allowsToolTipsWhenApplicationIsInactive {
return _allowsToolTipsWhenApplicationIsInactive;
2006-12-22 04:41:44 +00:00
}
-(NSImage *)miniwindowImage {
return _miniwindowImage;
2006-12-22 04:41:44 +00:00
}
-(NSString *)miniwindowTitle {
return _miniwindowTitle;
2006-12-22 04:41:44 +00:00
}
-(NSDockTile *)dockTile {
NSUnimplementedMethod();
return nil;
}
-(NSColor *)backgroundColor {
return _backgroundColor;
2006-12-22 04:41:44 +00:00
}
-(CGFloat)alphaValue {
return _alphaValue;
2006-12-22 04:41:44 +00:00
}
-(NSWindowDepth)depthLimit {
return 0;
2006-12-22 04:41:44 +00:00
}
-(NSSize)resizeIncrements {
return _resizeIncrements;
2006-12-22 04:41:44 +00:00
}
-(NSSize)contentResizeIncrements {
return _contentResizeIncrements;
2006-12-22 04:41:44 +00:00
}
-(BOOL)preservesContentDuringLiveResize {
return _preservesContentDuringLiveResize;
2006-12-22 04:41:44 +00:00
}
-(NSToolbar *)toolbar {
return _toolbar;
2006-12-22 04:41:44 +00:00
}
-(NSView *)initialFirstResponder {
return _initialFirstResponder;
2006-12-22 04:41:44 +00:00
}
-(void)removeObserver:(NSString *)name selector:(SEL)selector {
if([_delegate respondsToSelector:selector]){
[[NSNotificationCenter defaultCenter] removeObserver:_delegate
name:name object:self];
}
}
-(void)addObserver:(NSString *)name selector:(SEL)selector {
if([_delegate respondsToSelector:selector]){
[[NSNotificationCenter defaultCenter] addObserver:_delegate
selector:selector name:name object:self];
}
}
-(void)setDelegate:delegate {
struct {
NSString *name;
SEL selector;
} notes[]={
{ NSWindowDidBecomeKeyNotification,@selector(windowDidBecomeKey:) },
{ NSWindowDidBecomeMainNotification,@selector(windowDidBecomeMain:) },
{ NSWindowDidDeminiaturizeNotification,@selector(windowDidDeminiaturize:) },
{ NSWindowDidMiniaturizeNotification,@selector(windowDidMiniaturize:) },
{ NSWindowDidMoveNotification,@selector(windowDidMove:) },
{ NSWindowDidResignKeyNotification,@selector(windowDidResignKey:) },
{ NSWindowDidResignMainNotification,@selector(windowDidResignMain:) },
{ NSWindowDidResizeNotification,@selector(windowDidResize:) },
{ NSWindowDidUpdateNotification,@selector(windowDidUpdate:) },
{ NSWindowWillCloseNotification,@selector(windowWillClose:) },
{ NSWindowWillMiniaturizeNotification,@selector(windowWillMiniaturize:) },
{ NSWindowWillMoveNotification,@selector(windowWillMove:) },
{ nil, NULL }
};
int i;
if(_delegate!=nil)
for(i=0;notes[i].name!=nil;i++)
[self removeObserver:notes[i].name selector:notes[i].selector];
_delegate=delegate;
for(i=0;notes[i].name!=nil;i++)
[self addObserver:notes[i].name selector:notes[i].selector];
}
-(void)_makeSureIsOnAScreen {
#if 1
if(_makeSureIsOnAScreen && [self isVisible] && ![self isMiniaturized]){
NSRect frame=_frame;
NSArray *screens=[NSScreen screens];
int i,count=[screens count];
BOOL changed=NO;
BOOL tooFarLeft=YES,tooFarRight=YES,tooFarUp=YES,tooFarDown=YES;
float leastX=0,maxX=0,leastY=0,maxY=0;
for(i=0;i<count;i++){
NSRect check=[[screens objectAtIndex:i] frame];
if(NSMaxX(frame)>check.origin.x+20)
tooFarLeft=NO;
if(frame.origin.x<NSMaxX(check)-20)
tooFarRight=NO;
if(frame.origin.y<NSMaxY(check)-20)
2006-12-22 04:41:44 +00:00
tooFarUp=NO;
if(NSMaxY(frame)>check.origin.y+20)
tooFarDown=NO;
if(check.origin.x<leastX)
leastX=check.origin.x;
if(check.origin.y<leastY)
leastY=check.origin.y;
if(NSMaxX(check)>maxX)
maxX=NSMaxX(check);
if(NSMaxY(check)>maxY)
maxY=NSMaxY(check);
}
if(tooFarLeft){
frame.origin.x=(leastX+20)-frame.size.width;
changed=YES;
}
if(tooFarRight){
frame.origin.x=maxX-20;
changed=YES;
}
if(tooFarUp){
frame.origin.y=(maxY-20)-frame.size.height;
changed=YES;
}
if(tooFarDown){
changed=YES;
frame.origin.y=(leastY+20)-frame.size.height;
}
if(changed)
[self setFrame:frame display:YES];
_makeSureIsOnAScreen=NO;
}
#else
if(_makeSureIsOnAScreen && [self isVisible] && ![self isMiniaturized]){
NSRect frame=_frame;
NSArray *screens=[NSScreen screens];
int i,count=[screens count];
NSRect virtual=NSZeroRect;
BOOL changed=NO;
for(i=0;i<count;i++){
NSRect screen=[[screens objectAtIndex:i] frame];
virtual=NSUnionRect(virtual,screen);
}
virtual=NSInsetRect(virtual,20,20);
if(NSMaxX(frame)<virtual.origin.x){
frame.origin.x=virtual.origin.x-frame.size.width;
changed=YES;
}
if(frame.origin.x>NSMaxX(virtual)){
frame.origin.x=NSMaxX(virtual);
changed=YES;
}
if(NSMaxY(frame)>NSMaxY(virtual)){
frame.origin.y=NSMaxY(virtual)-frame.size.height;
changed=YES;
}
if(NSMaxY(frame)<virtual.origin.y){
changed=YES;
frame.origin.y=virtual.origin.y-frame.size.height;
}
if(changed)
[self setFrame:frame display:YES];
_makeSureIsOnAScreen=NO;
}
#endif
}
-(void)setFrame:(NSRect)frame display:(BOOL)display {
[self setFrame:frame display:display animate:NO];
2006-12-22 04:41:44 +00:00
}
- (void)_animateWithContext:(NSWindowAnimationContext *)context
{
NSRect frame = [self frame];
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:context, @"NSWindowAnimationContext", nil];
if (_animationContext == nil)
_animationContext = [context retain];
if (_animationContext != context)
[NSException raise:NSInvalidArgumentException
format:@"-[%@ %@]: attempt to animate frame while animation still in progress",
[self class], NSStringFromSelector(_cmd)];
[[NSNotificationCenter defaultCenter] postNotificationName:NSWindowWillAnimateNotification object:self userInfo:userInfo];
[context decrement];
if ([context stepCount] > 0) {
frame.origin.x += [context stepRect].origin.x;
frame.origin.y += [context stepRect].origin.y;
frame.size.width += [context stepRect].size.width;
frame.size.height += [context stepRect].size.height;
}
else
frame = [context targetRect];
[self setFrame:frame display:[context display]];
[[NSNotificationCenter defaultCenter] postNotificationName:NSWindowAnimatingNotification object:self userInfo:userInfo];
if ([context stepCount] > 0) {
[self performSelector:_cmd withObject:context afterDelay:[context stepInterval]];
}
else {
[[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidAnimateNotification object:self userInfo:userInfo];
[_animationContext release];
_animationContext = nil;
#if 0
if ([_backgroundView cachesImageForAnimation])
[_backgroundView invalidateCachedImage];
#endif
}
}
- (NSWindowAnimationContext *)_animationContext
{
return _animationContext;
}
-(void)setFrame:(NSRect)newFrame display:(BOOL)display animate:(BOOL)animate {
_frame=newFrame;
_makeSureIsOnAScreen=YES;
2006-12-22 04:41:44 +00:00
[_backgroundView setFrameSize:_frame.size];
[[self platformWindow] setFrame:_frame];
2006-12-22 04:41:44 +00:00
[self _invalidateTrackingAreas];
if(display)
[self display];
if(animate){
NSWindowAnimationContext *context;
context = [NSWindowAnimationContext contextToTransformWindow:self startRect:[self frame] targetRect:newFrame resizeTime: [self animationResizeTime:newFrame] display:display];
2006-12-22 04:41:44 +00:00
[self _animateWithContext:context];
}
2006-12-22 04:41:44 +00:00
}
-(void)setContentSize:(NSSize)size {
NSRect frame,content=[self contentRectForFrameRect:[self frame]];
2006-12-22 04:41:44 +00:00
content.size=size;
frame=[self frameRectForContentRect:content];
2006-12-22 04:41:44 +00:00
[self setFrame:frame display:YES];
}
-(void)setFrameOrigin:(NSPoint)point {
NSRect frame=[self frame];
frame.origin=point;
[self setFrame:frame display:YES];
}
-(void)setFrameTopLeftPoint:(NSPoint)point {
NSRect frame=[self frame];
frame.origin.x=point.x;
frame.origin.y=point.y-frame.size.height;
[self setFrame:frame display:YES];
}
-(void)setMinSize:(NSSize)size {
_minSize=size;
}
-(void)setMaxSize:(NSSize)size {
_maxSize=size;
}
-(void)setContentMinSize:(NSSize)value {
_contentMinSize=value;
NSUnimplementedMethod();
}
-(void)setContentMaxSize:(NSSize)value {
_contentMaxSize=value;
}
-(void)setContentBorderThickness:(CGFloat)thickness forEdge:(NSRectEdge)edge {
// FIXME: should warn, but low priority cosmetic, so we dont, still needs to be implemented
// NSUnimplementedMethod();
}
-(void)setMovable:(BOOL)movable {
NSUnimplementedMethod();
}
-(void)setBackingType:(NSBackingStoreType)value {
_backingType=value;
NSUnimplementedMethod();
}
-(void)setDynamicDepthLimit:(BOOL)value {
_dynamicDepthLimit=value;
}
2006-12-22 04:41:44 +00:00
-(void)setOneShot:(BOOL)flag {
_isOneShot=flag;
}
-(void)setReleasedWhenClosed:(BOOL)flag {
_releaseWhenClosed=flag;
}
-(void)setHidesOnDeactivate:(BOOL)flag {
_hidesOnDeactivate=flag;
}
-(void)setAcceptsMouseMovedEvents:(BOOL)flag {
_acceptsMouseMovedEvents=flag;
}
-(void)setExcludedFromWindowsMenu:(BOOL)value {
_excludedFromWindowsMenu=value;
}
-(void)setAutodisplay:(BOOL)value {
_isAutodisplay=value;
}
-(void)setAutorecalculatesContentBorderThickness:(BOOL)automatic forEdge:(NSRectEdge)edge {
// FIXME: should warn, but low priority cosmetic, so we dont, still needs to be implemented
// NSUnimplementedMethod();
}
-(BOOL)_isApplicationWindow {
return (![self isKindOfClass:[NSPanel class]] && [self isVisible] && ![self isExcludedFromWindowsMenu])?YES:NO;
}
-(void)setTitle:(NSString *)title {
title=[title copy];
[_title release];
_title=title;
[_miniwindowTitle release];
_miniwindowTitle=[title copy];
[self _updatePlatformWindowTitle];
if ([self _isApplicationWindow])
[NSApp changeWindowsItem:self title:title filename:NO];
}
-(void)setTitleWithRepresentedFilename:(NSString *)filename {
[self setTitle:[NSString stringWithFormat:@"%@ -- %@",
[filename lastPathComponent],
[filename stringByDeletingLastPathComponent]]];
if ([self _isApplicationWindow])
[NSApp changeWindowsItem:self title:filename filename:YES];
}
-(void)setContentView:(NSView *)view {
view=[view retain];
[view setFrame:[_contentView frame]];
[_contentView removeFromSuperview];
[_contentView release];
_contentView=view;
[_backgroundView addSubview:_contentView];
}
-(void)setInitialFirstResponder:(NSView *)view {
_initialFirstResponder = view;
}
-(void)setMiniwindowImage:(NSImage *)image {
image=[image retain];
[_miniwindowImage release];
_miniwindowImage=image;
}
-(void)setMiniwindowTitle:(NSString *)title {
title=[title copy];
[_miniwindowTitle release];
_miniwindowTitle=title;
[self _updatePlatformWindowTitle];
}
-(void)setBackgroundColor:(NSColor *)color {
color=[color copy];
[_backgroundColor release];
_backgroundColor=color;
[_backgroundView setNeedsDisplay:YES];
}
-(void)setAlphaValue:(CGFloat)value {
_alphaValue=value;
[[self platformWindow] setAlphaValue:value];
}
-(void)_toolbarSizeDidChangeFromOldHeight:(CGFloat)oldHeight {
CGFloat newHeight,contentHeightDelta;
NSView *toolbarView=[_toolbar _view];
NSUInteger mask=[[self contentView] autoresizingMask];
NSRect frame=[self frame];
[_toolbar layoutFrameSizeWithWidth:NSWidth([[self _backgroundView] bounds])];
newHeight=(_toolbar==nil)?0:[_toolbar visibleHeight];
contentHeightDelta=newHeight-oldHeight;
frame.size.height+=contentHeightDelta;
frame.origin.y-=contentHeightDelta;
NSPoint toolbarOrigin;
NSRect backgroundBounds=[self _backgroundView].bounds;
toolbarOrigin.x=backgroundBounds.origin.x;
toolbarOrigin.y=NSMaxY([[self contentView] frame])-contentHeightDelta;
[toolbarView setFrameOrigin:toolbarOrigin];
[[self contentView] setAutoresizingMask:NSViewNotSizable];
[self setFrame:frame display:NO animate:NO];
[[self contentView] setAutoresizingMask:mask];
}
-(void)setToolbar:(NSToolbar *)toolbar {
if(toolbar!=_toolbar){
CGFloat oldHeight=0;
toolbar=[toolbar retain];
if(_toolbar!=nil){
oldHeight=[_toolbar visibleHeight];
[_toolbar _setWindow:nil];
[[_toolbar _view] removeFromSuperview];
[_toolbar release];
[[self _backgroundView] setNeedsDisplay:YES];
}
_toolbar = toolbar;
if(_toolbar!=nil){
[_toolbar _setWindow:self];
[[self _backgroundView] addSubview:[_toolbar _view]];
[[self _backgroundView] setNeedsDisplay:YES];
}
[self _toolbarSizeDidChangeFromOldHeight:oldHeight];
}
}
- (void)setDefaultButtonCell:(NSButtonCell *)buttonCell {
[_defaultButtonCell autorelease];
_defaultButtonCell = [buttonCell retain];
[_defaultButtonCell setKeyEquivalent:@"\r"];
[[_defaultButtonCell controlView] setNeedsDisplay:YES];
}
-(void)setWindowController:(NSWindowController *)value {
_windowController=value;
}
-(void)setDocumentEdited:(BOOL)flag {
_isDocumentEdited=flag;
[self _updatePlatformWindowTitle];
}
-(void)setContentAspectRatio:(NSSize)value {
_resizeIncrements.width=1.0;
_resizeIncrements.height=value.height/value.width;
}
-(void)setHasShadow:(BOOL)value {
_hasShadow=value;
[[self platformWindow] setHasShadow:value];
}
-(void)setIgnoresMouseEvents:(BOOL)value {
_ignoresMouseEvents=value;
}
-(void)setAspectRatio:(NSSize)value {
_resizeIncrements.width=1.0;
_resizeIncrements.height=value.height/value.width;
}
-(void)setAutorecalculatesKeyViewLoop:(BOOL)value {
_autorecalculatesKeyViewLoop=value;
}
-(void)setCanHide:(BOOL)value {
_canHide=value;
}
-(void)setCanBecomeVisibleWithoutLogin:(BOOL)flag {
// NSUnimplementedMethod();
}
-(void)setCollectionBehavior:(NSWindowCollectionBehavior)behavior {
NSUnimplementedMethod();
}
-(void)setLevel:(int)value {
_level=value;
[[self platformWindow] setLevel:_level];
}
-(void)setOpaque:(BOOL)value {
_isOpaque=value;
[[self platformWindow] setOpaque:_isOpaque];
}
-(void)setParentWindow:(NSWindow *)value {
_parentWindow=value;
}
-(void)setPreservesContentDuringLiveResize:(BOOL)value {
_preservesContentDuringLiveResize=value;
}
-(void)setRepresentedFilename:(NSString *)value {
value=[value copy];
[_representedFilename release];
_representedFilename=value;
}
-(void)setRepresentedURL:(NSURL *)newURL {
NSUnimplementedMethod();
}
-(void)setResizeIncrements:(NSSize)value {
_resizeIncrements=value;
}
-(void)setShowsResizeIndicator:(BOOL)value {
_showsResizeIndicator=value;
NSUnimplementedMethod();
}
-(void)setShowsToolbarButton:(BOOL)value {
_showsToolbarButton=value;
NSUnimplementedMethod();
}
-(void)setContentResizeIncrements:(NSSize)value {
_contentResizeIncrements=value;
}
-(void)setDepthLimit:(NSWindowDepth)value {
NSUnimplementedMethod();
}
-(void)setDisplaysWhenScreenProfileChanges:(BOOL)value {
_displaysWhenScreenProfileChanges=value;
}
-(void)setMovableByWindowBackground:(BOOL)value {
_isMovableByWindowBackground=value;
}
-(void)setAllowsToolTipsWhenApplicationIsInactive:(BOOL)value {
_allowsToolTipsWhenApplicationIsInactive=value;
}
-(BOOL)autorecalculatesContentBorderThicknessForEdge:(NSRectEdge)edge {
NSUnimplementedMethod();
return NO;
}
-(CGFloat)contentBorderThicknessForEdge:(NSRectEdge)edge {
NSUnimplementedMethod();
return 0.;
}
-(NSString *)_autosaveFrameKeyWithName:(NSString *)name {
return [NSString stringWithFormat:@"NSWindow frame %@ %@",name, NSStringFromRect([[self screen] frame])];
}
-(BOOL)setFrameUsingName:(NSString *)name {
return [self setFrameUsingName:name force:NO];
}
-(BOOL)setFrameUsingName:(NSString *)name force:(BOOL)force {
NSString *key=[self _autosaveFrameKeyWithName:name];
NSString *value=[[NSUserDefaults standardUserDefaults] objectForKey:key];
if([value length]==0)
return NO;
[self setFrameFromString:value];
return YES;
}
-(void)_setFrameAutosaveNameNoIO:(NSString *)name {
name=[name copy];
[_autosaveFrameName release];
_autosaveFrameName=name;
}
-(BOOL)setFrameAutosaveName:(NSString *)name {
[self _setFrameAutosaveNameNoIO:name];
[self setFrameUsingName:_autosaveFrameName];
[self saveFrameUsingName:_autosaveFrameName];
return YES;
}
-(void)postAwakeFromNib {
/*
We do this after awakeFromNib because a saved frame is also post awakeFromNib. If awakeFromNib modifies
the windows adornments we need to wait until here to actually set it.
*/
if([_autosaveFrameName length]>0){
[self setFrameUsingName:_autosaveFrameName];
[self saveFrameUsingName:_autosaveFrameName];
}
}
-(void)saveFrameUsingName:(NSString *)name {
if([name length]>0){
NSString *key=[self _autosaveFrameKeyWithName:name];
NSString *value=[self stringWithSavedFrame];
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
}
}
-(void)setFrameFromString:(NSString *)value {
NSRect rect=NSRectFromString(value);
if(!NSIsEmptyRect(rect)){
[self setFrame:rect display:YES];
}
}
-(NSString *)stringWithSavedFrame {
return NSStringFromRect([self frame]);
}
-(int)resizeFlags {
NSUnimplementedMethod();
return 0;
}
-(float)userSpaceScaleFactor {
return 1.0;
}
-(NSResponder *)firstResponder {
return _firstResponder;
}
-(NSButton *)standardWindowButton:(NSWindowButton)value {
NSUnimplementedMethod();
return nil;
}
-(NSButtonCell *)defaultButtonCell {
return _defaultButtonCell;
}
-(NSWindow *)attachedSheet {
return [_sheetContext sheet];
}
-(NSWindowController *)windowController {
return _windowController;
}
-(NSArray *)drawers {
return _drawers;
2006-12-22 04:41:44 +00:00
}
-(int)windowNumber {
return [[self platformWindow] windowNumber];
2006-12-22 04:41:44 +00:00
}
-(int)gState {
NSUnimplementedMethod();
return 0;
2006-12-22 04:41:44 +00:00
}
-(NSScreen *)screen {
NSArray *screens=[NSScreen screens];
int i,count=[screens count];
NSRect mostRect=NSZeroRect;
NSScreen *mostScreen=nil;
for(i=0;i<count;i++){
NSScreen *check=[screens objectAtIndex:i];
NSRect intersect=NSIntersectionRect([check frame],_frame);
if(intersect.size.width*intersect.size.height>mostRect.size.width*mostRect.size.height){
mostRect=intersect;
mostScreen=check;
}
}
return mostScreen;
}
-(NSScreen *)deepestScreen {
NSUnimplementedMethod();
return 0;
2006-12-22 04:41:44 +00:00
}
-(NSColorSpace *)colorSpace {
NSUnimplementedMethod();
return nil;
}
-(void)setColorSpace:(NSColorSpace *)newColorSpace {
NSUnimplementedMethod();
}
-(BOOL)isOnActiveSpace {
NSUnimplementedMethod();
return YES;
}
-(NSWindowSharingType)sharingType {
NSUnimplementedMethod();
return 0;
}
-(void)setSharingType:(NSWindowSharingType)type {
NSUnimplementedMethod();
}
-(BOOL)isDocumentEdited {
return _isDocumentEdited;
2006-12-22 04:41:44 +00:00
}
-(BOOL)isZoomed {
2010-03-29 19:48:09 +00:00
NSRect zoomedFrame = [self zoomedFrame];
return NSEqualRects( _frame, zoomedFrame );
}
2006-12-22 04:41:44 +00:00
-(BOOL)isVisible {
return _isVisible;
2006-12-22 04:41:44 +00:00
}
-(BOOL)isKeyWindow {
return _isKeyWindow;
2006-12-22 04:41:44 +00:00
}
-(BOOL)isMainWindow {
return _isMainWindow;
}
-(BOOL)isMiniaturized {
return [_platformWindow isMiniaturized];
}
-(BOOL)isMovable {
NSUnimplementedMethod();
return NO;
}
-(BOOL)inLiveResize {
NSUnimplementedMethod();
return NO;
}
-(BOOL)canBecomeKeyWindow {
return YES;
2006-12-22 04:41:44 +00:00
}
-(BOOL)canBecomeMainWindow {
return YES;
2006-12-22 04:41:44 +00:00
}
-(BOOL)canBecomeVisibleWithoutLogin {
NSUnimplementedMethod();
return NO;
}
-(NSWindowCollectionBehavior)collectionBehavior {
NSUnimplementedMethod();
return 0;
}
-(NSPoint)convertBaseToScreen:(NSPoint)point {
NSRect frame=[self frame];
point.x+=frame.origin.x;
point.y+=frame.origin.y;
return point;
}
-(NSPoint)convertScreenToBase:(NSPoint)point {
NSRect frame=[self frame];
point.x-=frame.origin.x;
point.y-=frame.origin.y;
return point;
2006-12-22 04:41:44 +00:00
}
-(NSRect)frameRectForContentRect:(NSRect)rect {
return [isa frameRectForContentRect:rect styleMask:[self styleMask]];
}
-(NSRect)contentRectForFrameRect:(NSRect)rect {
NSRect result=[isa contentRectForFrameRect:rect styleMask:[self styleMask]];
if([_toolbar _view]!=nil && ![[_toolbar _view] isHidden])
result.size.height-=[[_toolbar _view] frame].size.height;
return result;
2006-12-22 04:41:44 +00:00
}
-(NSRect)constrainFrameRect:(NSRect)rect toScreen:(NSScreen *)screen {
NSUnimplementedMethod();
return NSMakeRect(0,0,0,0);
}
2006-12-22 04:41:44 +00:00
-(NSWindow *)parentWindow {
return _parentWindow;
}
2006-12-22 04:41:44 +00:00
-(NSArray *)childWindows {
return _childWindows;
2006-12-22 04:41:44 +00:00
}
-(void)addChildWindow:(NSWindow *)child ordered:(NSWindowOrderingMode)ordered {
if(_childWindows==nil)
_childWindows=[NSMutableArray new];
[_childWindows addObject:child];
[child setParentWindow:self];
[child makeKeyAndOrderFront:nil];
2006-12-22 04:41:44 +00:00
}
-(void)removeChildWindow:(NSWindow *)child {
[child orderOut:nil];
[child setParentWindow:nil];
[_childWindows removeObjectIdenticalTo:child];
}
-(void)_parentWindowDidClose:(NSWindow *)parent {
[self orderOut:nil];
}
-(void)_parentWindowDidActivate:(NSWindow *)parent {
[self orderWindow:NSWindowAbove relativeTo:[_parentWindow windowNumber]];
}
-(void)_parentWindowDidDeactivate:(NSWindow *)parent {
[self orderWindow:NSWindowAbove relativeTo:[_parentWindow windowNumber]];
}
-(void)_parentWindowDidMiniaturize:(NSWindow *)parent {
[self orderOut:nil];
}
-(void)_parentWindowDidChangeFrame:(NSWindow *)parent {
}
-(void)_parentWindowDidExitMove:(NSWindow *)parent {
[self orderWindow:NSWindowAbove relativeTo:[_parentWindow windowNumber]];
2006-12-22 04:41:44 +00:00
}
-(BOOL)acceptsFirstResponder {
return YES;
}
-(BOOL)makeFirstResponder:(NSResponder *)responder {
NSResponder *previous=_firstResponder;
if(responder==nil)
responder=self;
if(_firstResponder==responder)
return YES;
if(![responder acceptsFirstResponder])
return NO;
/* the firstResponder needs to be set here because
resignFirstResponder may nest makeFirstResponder's e.g.
field editor <tab>
makeFirstResponder:[self window]
field editor resignFirstResponder
textDidEnd:
field editor assigned to nextKeyView
makeFirstResponder:field editor */
_firstResponder=responder;
if(previous!=nil){
if(![previous resignFirstResponder]){
_firstResponder=previous;
return NO;
}
}
if([_firstResponder becomeFirstResponder])
return YES;
_firstResponder=self;
return NO;
}
-(void)makeKeyWindow {
[[self platformWindow] makeKey];
[self makeFirstResponder:[self initialFirstResponder]];
2006-12-22 04:41:44 +00:00
}
-(void)makeMainWindow {
[self becomeMainWindow];
}
-(void)becomeKeyWindow {
[[NSApp keyWindow] resignKeyWindow];
_isKeyWindow=YES;
if(_firstResponder!=self && [_firstResponder respondsToSelector:_cmd])
[_firstResponder performSelector:_cmd];
[self postNotificationName:NSWindowDidBecomeKeyNotification];
}
-(void)resignKeyWindow {
_isKeyWindow=NO;
if(_firstResponder!=self && [_firstResponder respondsToSelector:_cmd])
[_firstResponder performSelector:_cmd];
[self postNotificationName:NSWindowDidResignKeyNotification];
}
-(void)becomeMainWindow {
[[NSApp mainWindow] resignMainWindow];
_isMainWindow=YES;
[self postNotificationName:NSWindowDidBecomeMainNotification];
}
-(void)resignMainWindow {
_isMainWindow=NO;
[self postNotificationName:NSWindowDidResignMainNotification];
}
- (NSTimeInterval)animationResizeTime:(NSRect)frame {
return 0.20;
}
-(void)selectNextKeyView:sender {
if([_firstResponder isKindOfClass:[NSView class]]){
NSView *view=(NSView *)_firstResponder;
[self selectKeyViewFollowingView:view];
}
}
-(void)selectPreviousKeyView:sender {
if([_firstResponder isKindOfClass:[NSView class]]){
NSView *view=(NSView *)_firstResponder;
[self selectKeyViewPrecedingView:view];
}
}
-(void)selectKeyViewFollowingView:(NSView *)view {
NSView *next=[view nextValidKeyView];
[self makeFirstResponder:next];
}
-(void)selectKeyViewPrecedingView:(NSView *)view {
NSView *next=[view previousValidKeyView];
[self makeFirstResponder:next];
}
-(void)recalculateKeyViewLoop {
// NSUnimplementedMethod();
}
-(NSSelectionDirection)keyViewSelectionDirection {
NSUnimplementedMethod();
return 0;
}
2006-12-22 04:41:44 +00:00
- (void)disableKeyEquivalentForDefaultButtonCell {
_defaultButtonCellKeyEquivalentDisabled = YES;
}
- (void)enableKeyEquivalentForDefaultButtonCell {
_defaultButtonCellKeyEquivalentDisabled = NO;
}
-(NSText *)fieldEditor:(BOOL)create forObject:object {
if(create && _fieldEditor==nil){
_fieldEditor=[[NSTextView alloc] init];
}
[_fieldEditor setHorizontallyResizable:NO];
[_fieldEditor setVerticallyResizable:NO];
[_fieldEditor setFieldEditor:YES];
[_fieldEditor setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
return _fieldEditor;
}
-(void)endEditingFor:object {
if((NSResponder *)_fieldEditor==_firstResponder){
_firstResponder=self;
[_fieldEditor resignFirstResponder];
}
[_fieldEditor setDelegate:nil];
[_fieldEditor removeFromSuperview];
[_fieldEditor setString:@""];
}
-(void)disableScreenUpdatesUntilFlush {
NSUnimplementedMethod();
}
2006-12-22 04:41:44 +00:00
-(void)useOptimizedDrawing:(BOOL)flag {
// do nothing
}
-(BOOL)viewsNeedDisplay {
return _viewsNeedDisplay;
}
-(void)setViewsNeedDisplay:(BOOL)flag {
_viewsNeedDisplay=flag;
}
-(void)disableFlushWindow {
_flushDisabled++;
}
-(void)enableFlushWindow {
_flushDisabled--;
}
-(void)flushWindow {
if(_flushDisabled>0)
_flushNeeded=YES;
else {
_flushNeeded=NO;
BOOL doFlush=YES;
if([self isOpaque] && [_contentView isKindOfClass:[NSOpenGLView class]] && [_contentView isOpaque])
doFlush=NO;
if(doFlush)
[[self platformWindow] flushBuffer];
2006-12-22 04:41:44 +00:00
}
}
-(void)flushWindowIfNeeded {
if(_flushNeeded)
[self flushWindow];
}
-(void)displayIfNeeded {
if([self isVisible] && ![self isMiniaturized] && [self viewsNeedDisplay]){
NSAutoreleasePool *pool=[NSAutoreleasePool new];
2006-12-22 04:41:44 +00:00
[self disableFlushWindow];
[_backgroundView displayIfNeeded];
[self enableFlushWindow];
[self flushWindowIfNeeded];
[self setViewsNeedDisplay:NO];
[pool release];
}
}
-(void)display {
/* FIXME: See Issue #405, display when the window is not visible causes layout problems (maybe the underlying Win32 window doesnt exist and we're not getting resize feedback messages?), so there is a problem. The fix is to not display when we aren't visible, displayIfNeeded does this already so it makes sense. The underlying problem should be fixed too though.
*/
if([self isVisible]){
NSAutoreleasePool *pool=[NSAutoreleasePool new];
[self disableFlushWindow];
[_backgroundView display];
[self enableFlushWindow];
[self flushWindowIfNeeded];
[pool release];
}
else {
// If we were asked to display and weren't visible, mark it for display
[_backgroundView setNeedsDisplay:YES];
}
2006-12-22 04:41:44 +00:00
}
-(void)invalidateShadow {
// Do nothing
}
-(void)cacheImageInRect:(NSRect)rect {
NSUnimplementedMethod();
}
-(void)restoreCachedImage {
NSUnimplementedMethod();
}
-(void)discardCachedImage {
NSUnimplementedMethod();
}
2006-12-22 04:41:44 +00:00
-(BOOL)areCursorRectsEnabled {
return (_cursorRectsDisabled<=0)?YES:NO;
}
-(void)disableCursorRects {
_cursorRectsDisabled++;
if(_cursorRectsDisabled==1)
[self _invalidateTrackingAreas];
2006-12-22 04:41:44 +00:00
}
-(void)enableCursorRects {
_cursorRectsDisabled--;
if(_cursorRectsDisabled==0)
[self _invalidateTrackingAreas];
2006-12-22 04:41:44 +00:00
}
-(void)discardCursorRects {
[[self _backgroundView] discardCursorRects];
[self _invalidateTrackingAreas];
2006-12-22 04:41:44 +00:00
}
// Apple docs say: "sends -resetCursorRects to every NSView object in the [...] hierarchy",
// and it means that. No [[self _backgroundView] resetCursorRects] and trusting in
// recursion through the view hierarchy.
-(void)_resetCursorRectsInView:(NSView *)view {
2006-12-22 04:41:44 +00:00
NSArray *subviews=[view subviews];
int i,count=[subviews count];
for(i=0;i<count;i++)
[self _resetCursorRectsInView:[subviews objectAtIndex:i]];
2006-12-22 04:41:44 +00:00
[view resetCursorRects];
}
-(void)resetCursorRects {
[self discardCursorRects];
[self _resetCursorRectsInView:_backgroundView];
[self _invalidateTrackingAreas];
2006-12-22 04:41:44 +00:00
}
-(void)invalidateCursorRectsForView:(NSView *)view {
[view discardCursorRects];
[view resetCursorRects];
[self _invalidateTrackingAreas];
}
// This shall be received in case of
// - -[NSWindows areCursorRectsEnabled] changes
// - -[NSApplication isActive] changes
// - the number or TrackingAreas has changed
// - a property of one of the TrackingAreas has changed
// - a frame of this window or one the relevant views has changed.
-(void)_invalidateTrackingAreas {
// Rebuild it on demand.
[_trackingAreas release];
_trackingAreas=nil;
}
// Never send this directly, except you actually need _trackingAreas.
-(void)_resetTrackingAreas {
if(_trackingAreas==nil){
NSInteger count;
BOOL toolTipsAllowed=[[NSApplication sharedApplication] isActive] ||
[self allowsToolTipsWhenApplicationIsInactive];
NSMutableArray *collectedAreas=[[NSMutableArray alloc] init];
[[self _backgroundView] _collectTrackingAreasForWindowInto:collectedAreas];
_trackingAreas=collectedAreas;
count=[_trackingAreas count];
while(--count>=0){
NSTrackingArea *area=[_trackingAreas objectAtIndex:count];
if((_cursorRectsDisabled>0 && [area options]&NSTrackingCursorUpdate) ||
([area _isToolTip] && !toolTipsAllowed))
[_trackingAreas removeObjectAtIndex:count];
}
if(!toolTipsAllowed){
// We have to do this here as Area handling won't even recignize ToolTips now.
NSToolTipWindow *toolTipWindow=[NSToolTipWindow sharedToolTipWindow];
[NSObject cancelPreviousPerformRequestsWithTarget:toolTipWindow selector:@selector(orderFront:) object:nil];
[toolTipWindow orderOut:nil];
}
}
2006-12-22 04:41:44 +00:00
}
-(void)close {
2006-12-22 04:41:44 +00:00
/*
I am not sure if orderOut comes before the notification or not.
If we order out after the notification, Windows sends the window a bunch of messages from the HIDE, and we
end up potentially drawing, updating a window when it is not supposed to be, especially if the delegate has
already released objects that will be messaged during a draw/update.
We either orderOut: before the notification, or have an _isClosed flag which causes
some platformWindow messages to be ignored. Ones that would crash the app.
*/
[self orderOut:nil];
[_childWindows makeObjectsPerformSelector:@selector(_parentWindowDidClose:) withObject:self];
[_drawers makeObjectsPerformSelector:@selector(parentWindowDidClose:) withObject:self];
2006-12-22 04:41:44 +00:00
[self postNotificationName:NSWindowWillCloseNotification];
if(_releaseWhenClosed)
[self autorelease];
}
-(void)center {
NSRect frame=[self frame];
NSScreen *screen=[self screen];
NSRect screenFrame;
if(screen==nil)
screen=[[NSScreen screens] objectAtIndex:0];
screenFrame=[screen frame];
frame.origin.x=floor(screenFrame.origin.x+screenFrame.size.width/2-frame.size.width/2);
frame.origin.y=floor(screenFrame.origin.y+screenFrame.size.height/2-frame.size.height/2);
[self setFrame:frame display:YES];
}
-(void)orderWindow:(NSWindowOrderingMode)place relativeTo:(int)relativeTo {
// The move notifications are sent under unknown conditions around orderFront: in the Apple AppKit, we do them all the time here until it's figured out. I suspect it is a side effect of off-screen windows being at off-screen coordinates (as opposed to just being hidden)
[self postNotificationName:NSWindowWillMoveNotification];
switch(place){
case NSWindowAbove:
[self update];
_isVisible=YES;
[[self platformWindow] placeAboveWindow:relativeTo];
2006-12-22 04:41:44 +00:00
/* In some instances when a COMMAND is issued from a menu item to bring a
window front, the window is not displayed right (black, incomplete). This
may be the right place to do this, maybe not, further investigation is
required
*/
[self displayIfNeeded];
// this is here since it would seem that doing this any earlier will not work.
if(![self isKindOfClass:[NSPanel class]] && ![self isExcludedFromWindowsMenu]) {
2006-12-22 04:41:44 +00:00
[NSApp changeWindowsItem:self title:_title filename:NO];
[NSApp _windowOrderingChange: NSWindowAbove forWindow: self relativeTo: [NSApp windowWithWindowNumber:relativeTo]];
}
2006-12-22 04:41:44 +00:00
break;
case NSWindowBelow:
[self update];
_isVisible=YES;
[[self platformWindow] placeBelowWindow:relativeTo];
2006-12-22 04:41:44 +00:00
/* In some instances when a COMMAND is issued from a menu item to bring a
window front, the window is not displayed right (black, incomplete). This
may be the right place to do this, maybe not, further investigation is
required
*/
[self displayIfNeeded];
// this is here since it would seem that doing this any earlier will not work.
if(![self isKindOfClass:[NSPanel class]] && ![self isExcludedFromWindowsMenu]) {
[NSApp changeWindowsItem:self title:_title filename:NO];
[NSApp _windowOrderingChange: NSWindowBelow forWindow: self relativeTo: [NSApp windowWithWindowNumber:relativeTo]];
}
2006-12-22 04:41:44 +00:00
break;
case NSWindowOut:
2006-12-22 04:41:44 +00:00
_isVisible=NO;
[[self platformWindow] hideWindow];
if (![self isKindOfClass:[NSPanel class]]) {
[NSApp removeWindowsItem:self];
[NSApp _windowOrderingChange: NSWindowOut forWindow: self relativeTo: nil];
}
2006-12-22 04:41:44 +00:00
break;
}
[self postNotificationName:NSWindowDidMoveNotification];
}
-(void)orderFrontRegardless {
NSUnimplementedMethod();
}
-(NSPoint)mouseLocationOutsideOfEventStream {
NSPoint point=[_platformWindow mouseLocationOutsideOfEventStream];
return [self convertScreenToBase:point];
}
2006-12-22 04:41:44 +00:00
-(NSEvent *)currentEvent {
return [NSApp currentEvent];
}
-(NSEvent *)nextEventMatchingMask:(unsigned int)mask {
return [self nextEventMatchingMask:mask untilDate:[NSDate distantFuture]
inMode:NSEventTrackingRunLoopMode dequeue:YES];
}
-(NSEvent *)nextEventMatchingMask:(unsigned int)mask untilDate:(NSDate *)untilDate inMode:(NSString *)mode dequeue:(BOOL)dequeue {
NSEvent *event;
// this should get migrated down into event queue
[[self platformWindow] captureEvents];
do {
event=[NSApp nextEventMatchingMask:mask untilDate:untilDate inMode:mode dequeue:dequeue];
}while(!(mask&NSEventMaskFromType([event type])));
return event;
}
-(void)discardEventsMatchingMask:(unsigned)mask beforeEvent:(NSEvent *)event {
NSUnimplementedMethod();
}
2006-12-22 04:41:44 +00:00
-(void)sendEvent:(NSEvent *)event {
if (_sheetContext != nil) {
NSView *view = [_backgroundView hitTest:[event locationInWindow]];
// Pretend that the event goes to the toolbar's view, no matter where it really is.
// Could cause problems if custom views wanted to do something while the palette is running;
// however they shouldn't be doing that!
if ([[self toolbar] customizationPaletteIsRunning] &&
(view == [[self toolbar] _view] || [[[[self toolbar] _view] subviews] containsObject:view])) {
switch ([event type]) {
case NSLeftMouseDown:
[[[self toolbar] _view] mouseDown:event];
break;
case NSLeftMouseUp:
[[[self toolbar] _view] mouseUp:event];
break;
case NSLeftMouseDragged:
[[[self toolbar] _view] mouseDragged:event];
break;
default:
break;
}
}
else if ([event type] == NSPlatformSpecific){
//[self _setSheetOriginAndFront];
[_platformWindow sendEvent:[(NSEvent_CoreGraphics *)event coreGraphicsEvent]];
}
return;
}
switch([event type]){
case NSLeftMouseDown:{
NSView *view=[_backgroundView hitTest:[event locationInWindow]];
[self makeFirstResponder:view];
// Doing this again seems correct for control cells which put a field editor up when they become first responder but I'm not sure
view=[_backgroundView hitTest:[event locationInWindow]];
_mouseDownLocationInWindow=[event locationInWindow];
2006-12-22 04:41:44 +00:00
[view mouseDown:event];
}
break;
case NSLeftMouseUp:
[[_backgroundView hitTest:_mouseDownLocationInWindow] mouseUp:event];
2010-09-03 18:44:12 +00:00
_mouseDownLocationInWindow=NSMakePoint(NAN,NAN);
2006-12-22 04:41:44 +00:00
break;
case NSRightMouseDown:
_mouseDownLocationInWindow=[event locationInWindow];
2006-12-22 04:41:44 +00:00
[[_backgroundView hitTest:[event locationInWindow]] rightMouseDown:event];
break;
case NSRightMouseUp:
[[_backgroundView hitTest:_mouseDownLocationInWindow] rightMouseUp:event];
2010-09-03 18:44:12 +00:00
_mouseDownLocationInWindow=NSMakePoint(NAN,NAN);
2006-12-22 04:41:44 +00:00
break;
case NSMouseMoved:
[[_backgroundView hitTest:[event locationInWindow]] mouseMoved:event];
break;
case NSLeftMouseDragged:
[[_backgroundView hitTest:_mouseDownLocationInWindow] mouseDragged:event];
2006-12-22 04:41:44 +00:00
break;
case NSRightMouseDragged:
[[_backgroundView hitTest:_mouseDownLocationInWindow] rightMouseDragged:event];
2006-12-22 04:41:44 +00:00
break;
case NSMouseEntered:
[[_backgroundView hitTest:[event locationInWindow]] mouseEntered:event];
break;
case NSMouseExited:
[[_backgroundView hitTest:[event locationInWindow]] mouseExited:event];
break;
case NSKeyDown:
[_firstResponder keyDown:event];
break;
case NSKeyUp:
[_firstResponder keyUp:event];
break;
case NSFlagsChanged:
[_firstResponder flagsChanged:event];
break;
case NSPlatformSpecific:
[_platformWindow sendEvent:[(NSEvent_CoreGraphics *)event coreGraphicsEvent]];
break;
case NSScrollWheel:
[_firstResponder scrollWheel:event];
break;
default:
NSUnimplementedMethod();
break;
}
}
-(void)postEvent:(NSEvent *)event atStart:(BOOL)atStart {
[NSApp postEvent:event atStart:atStart];
}
-(BOOL)tryToPerform:(SEL)selector with:object {
if([super tryToPerform:selector with:object])
return YES;
if([_delegate respondsToSelector:selector]){
[_delegate performSelector:selector withObject:object];
return YES;
}
return NO;
}
2006-12-22 04:41:44 +00:00
-(NSPoint)cascadeTopLeftFromPoint:(NSPoint)topLeftPoint {
BOOL reposition = NO;
NSSize screenSize = [[self screen] frame].size;
NSRect frame = [self frame];
if (frame.origin.x < 0.0 || screenSize.width <= frame.origin.x + frame.size.width)
{
frame.origin.x = 2.0;
reposition = YES;
}
if (frame.origin.y < 0.0 || screenSize.height <= frame.origin.y + frame.size.height)
{
frame.origin.y = 2.0;
reposition = YES;
}
if (topLeftPoint.x != 0.0 && topLeftPoint.x + frame.size.width + 20.0 < screenSize.width)
{
topLeftPoint.x += 18.0;
frame.origin.x = topLeftPoint.x;
reposition = YES;
}
else
topLeftPoint.x = frame.origin.x;
if (topLeftPoint.y != 0.0 && topLeftPoint.y - frame.size.height - 23.0 >= 0.0)
{
topLeftPoint.y -= 21.0;
frame.origin.y = topLeftPoint.y - frame.size.height;
reposition = YES;
}
else
topLeftPoint.y = frame.origin.y + frame.size.height;
if (reposition)
[self setFrame:frame display:YES];
return topLeftPoint;
}
-(NSData *)dataWithEPSInsideRect:(NSRect)rect {
return [_backgroundView dataWithEPSInsideRect:rect];
}
-(NSData *)dataWithPDFInsideRect:(NSRect)rect {
return [_backgroundView dataWithPDFInsideRect:rect];
2006-12-22 04:41:44 +00:00
}
-(void)registerForDraggedTypes:(NSArray *)types {
_draggedTypes=[types copy];
}
-(void)unregisterDraggedTypes {
[_draggedTypes release];
_draggedTypes=nil;
}
-(void)dragImage:(NSImage *)image at:(NSPoint)location offset:(NSSize)offset event:(NSEvent *)event pasteboard:(NSPasteboard *)pasteboard source:source slideBack:(BOOL)slideBack {
[[NSDraggingManager draggingManager] dragImage:image at:location offset:offset event:event pasteboard:pasteboard source:source slideBack:slideBack];
}
-validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType {
NSUnimplementedMethod();
return nil;
}
2006-12-22 04:41:44 +00:00
-(void)update {
[[NSNotificationCenter defaultCenter]
postNotificationName:NSWindowDidUpdateNotification
object:self];
}
-(void)makeKeyAndOrderFront:sender {
if ([self isMiniaturized])
[_platformWindow deminiaturize];
[self makeKeyWindow];
if(![self isKindOfClass:[NSPanel class]])
[self makeMainWindow];
[self orderWindow:NSWindowAbove relativeTo:0];
}
-(void)orderFront:sender {
[self orderWindow:NSWindowAbove relativeTo:0];
}
-(void)orderBack:sender {
[self orderWindow:NSWindowBelow relativeTo:0];
}
-(void)orderOut:sender {
[self orderWindow:NSWindowOut relativeTo:0];
}
-(void)performClose:sender
{
if([_delegate respondsToSelector:@selector(windowShouldClose:)])
{
if(![_delegate windowShouldClose:self])
return;
}
else if ([self respondsToSelector:@selector(windowShouldClose:)])
{
if (![self windowShouldClose:self])
return;
}
NSDocument * document = [_windowController document];
if (document)
{
[document shouldCloseWindowController:_windowController
delegate:self
shouldCloseSelector:@selector(_document:shouldClose:contextInfo:)
contextInfo:NULL];
}
else
{
[self close];
}
}
2006-12-22 04:41:44 +00:00
-(void)_document:(NSDocument *)document shouldClose:(BOOL)shouldClose contextInfo:(void *)context
{
// Callback used by performClose:
if (shouldClose)
{
[self close];
}
2006-12-22 04:41:44 +00:00
}
-(void)performMiniaturize:sender {
[self miniaturize:sender];
}
-(void)performZoom:sender {
2010-03-29 19:48:09 +00:00
[self zoom: sender];
}
- (NSRect) zoomedFrame;
{
NSScreen *screen = [self screen];
NSRect zoomedFrame = [screen visibleFrame];
if (_delegate && [_delegate respondsToSelector: @selector(windowWillUseStandardFrame:defaultFrame:)]) {
zoomedFrame = [_delegate windowWillUseStandardFrame: self defaultFrame: zoomedFrame];
} else if ([self respondsToSelector: @selector( windowWillUseStandardFrame:defaultFrame: )]) {
zoomedFrame = [self windowWillUseStandardFrame: self defaultFrame: zoomedFrame];
}
// zoomedFrame = [self constrainFrameRect: zoomedFrame toScreen: screen];
return zoomedFrame;
}
-(void)zoom:sender {
2010-03-29 19:48:09 +00:00
NSRect zoomedFrame = [self zoomedFrame];
if (NSEqualRects( _frame, zoomedFrame )) zoomedFrame = _savedFrame;
BOOL shouldZoom = YES;
if (_delegate && [_delegate respondsToSelector: @selector( windowShouldZoom:toFrame: )]) {
shouldZoom = [_delegate windowShouldZoom: self toFrame: zoomedFrame];
} else if ([self respondsToSelector: @selector( windowShouldZoom:toFrame: )]) {
shouldZoom = [self windowShouldZoom: self toFrame: zoomedFrame];
}
if (shouldZoom) {
_savedFrame = [self frame];
[self setFrame: zoomedFrame display: YES];
}
}
2006-12-22 04:41:44 +00:00
-(void)miniaturize:sender {
[[self platformWindow] miniaturize];
}
-(void)deminiaturize:sender {
[[self platformWindow] deminiaturize];
}
-(void)print:sender {
[_backgroundView print:sender];
}
2006-12-22 04:41:44 +00:00
-(void)toggleToolbarShown:sender {
[_toolbar setVisible:![_toolbar isVisible]];
[sender setTitle:[NSString stringWithFormat:@"%@ Toolbar", [_toolbar isVisible] ? @"Hide" : @"Show"]];
}
-(void)runToolbarCustomizationPalette:sender {
[_toolbar runCustomizationPalette:sender];
}
- (void)keyDown:(NSEvent *)event {
if ([self performKeyEquivalent:event] == NO)
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
}
- (void)doCommandBySelector:(SEL)selector {
if ([_delegate respondsToSelector:selector])
[_delegate performSelector:selector withObject:nil];
else
[super doCommandBySelector:selector];
}
- (void)insertTab:sender {
[self selectNextKeyView:nil];
}
- (void)insertBacktab:sender {
[self selectPreviousKeyView:nil];
}
- (void)insertNewline:sender {
if (_defaultButtonCell != nil)
[(NSControl *)[_defaultButtonCell controlView] performClick:nil];
}
-(void)_showForActivation {
if(_hiddenForDeactivate){
_hiddenForDeactivate=NO;
[[self platformWindow] showWindowForAppActivation:_frame];
}
}
-(void)_hideForDeactivation {
if([self hidesOnDeactivate] && [self isVisible] && ![self isMiniaturized]){
_hiddenForDeactivate=YES;
[[self platformWindow] hideWindowForAppDeactivation:_frame];
}
}
-(void)_forcedHideForDeactivation {
if([self isVisible]){
_hiddenForDeactivate=YES;
//_hiddenKeyWindow=[self isKeyWindow];
[[self platformWindow] hideWindowForAppDeactivation:_frame];
}
}
2006-12-22 04:41:44 +00:00
-(BOOL)performKeyEquivalent:(NSEvent *)event {
return [_backgroundView performKeyEquivalent:event];
}
#if 0
-(void)keyDown:(NSEvent *)event {
if(![self performKeyEquivalent:event]){
NSString *characters=[event charactersIgnoringModifiers];
if([characters isEqualToString:@" "])
[_firstResponder tryToPerform:@selector(performClick:) with:nil];
else if([characters isEqualToString:@"\t"]){
if([event modifierFlags]&NSShiftKeyMask)
[self selectPreviousKeyView:nil];
else
[self selectNextKeyView:nil];
}
}
}
#endif
-(void)_resizeWithOldMenuViewSize:(NSSize)oldSize {
2006-12-22 04:41:44 +00:00
NSSize backSize=[_backgroundView frame].size;
NSSize newSize;
2006-12-22 04:41:44 +00:00
NSRect frame;
newSize=[_menuView frame].size;
if([_menuView isHidden])
newSize.height=0;
2006-12-22 04:41:44 +00:00
backSize.height+=(newSize.height-oldSize.height);
[_backgroundView setAutoresizesSubviews:NO];
[_backgroundView setFrameSize:backSize];
[_backgroundView setAutoresizesSubviews:YES];
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]){
[_menuView setHidden:YES];
[self _resizeWithOldMenuViewSize:[_menuView frame].size];
}
}
-(void)_showMenuViewIfNeeded {
if(_menuView!=nil && [_menuView isHidden]){
[_menuView setHidden:NO];
[self _resizeWithOldMenuViewSize:NSMakeSize(0,0)];
}
}
-(void)setMenu:(NSMenu *)menu {
if(_menuView!=nil){
NSSize oldSize=[_menuView frame].size;
[_menuView setMenu:menu];
[self _resizeWithOldMenuViewSize:oldSize];
2006-12-22 04:41:44 +00:00
}
_menu=[menu copy];
}
-(NSMenu *)menu {
return _menu;
}
-(BOOL)_isActive {
return _isActive;
}
// default NSDraggingDestination
-(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
return NSDragOperationNone;
}
-(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender {
return [sender draggingSourceOperationMask];
}
-(void)draggingExited:(id <NSDraggingInfo>)sender {
// do nothing
}
-(BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
return NO;
}
-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
return NO;
}
-(void)concludeDragOperation:(id <NSDraggingInfo>)sender {
// do nothing
}
-(NSArray *)_draggedTypes {
return _draggedTypes;
}
-(void)_setSheetOrigin {
NSWindow *sheet=[_sheetContext sheet];
NSRect sheetFrame=[sheet frame];
NSRect frame=[self frame];
NSPoint origin;
origin.y=frame.origin.y+(frame.size.height-sheetFrame.size.height);
origin.x=frame.origin.x+floor((frame.size.width-sheetFrame.size.width)/2);
if ([self toolbar] != nil) {
if (_menuView != nil)
origin.y -= [_menuView frame].size.height;
origin.y -= [[[self toolbar] _view] frame].size.height;
// Depending on the final border types used on the toolbar and the sheets, the sheet placement
// sometimes looks better with a little "adjustment"....
origin.y++;
}
[sheet setFrameOrigin:origin];
}
-(void)_setSheetOriginAndFront {
if(_sheetContext!=nil){
[self _setSheetOrigin];
[[_sheetContext sheet] orderFront:nil];
}
}
-(void)_attachSheetContextOrderFrontAndAnimate:(NSSheetContext *)sheetContext {
NSWindow *sheet = [sheetContext sheet];
NSRect sheetFrame;
if ([sheet styleMask] != NSDocModalWindowMask)
[sheet setStyleMask:NSDocModalWindowMask];
2006-12-22 04:41:44 +00:00
[_sheetContext autorelease];
2006-12-22 04:41:44 +00:00
_sheetContext=[sheetContext retain];
[(NSWindowBackgroundView *)[sheet _backgroundView] setWindowBorderType:NSWindowSheetBorderType];
2006-12-22 04:41:44 +00:00
[self _setSheetOrigin];
sheetFrame = [sheet frame];
2006-12-22 04:41:44 +00:00
sheet->_isVisible=YES;
[sheet display];
[[sheet platformWindow] sheetOrderFrontFromFrame:NSMakeRect(sheetFrame.origin.x,NSMaxY(sheetFrame),sheetFrame.size.width,0) aboveWindow:[self platformWindow]];
[[sheet platformWindow] makeKey];
2006-12-22 04:41:44 +00:00
}
-(NSSheetContext *)_sheetContext {
return _sheetContext;
}
-(void)_detachSheetContextAnimateAndOrderOut {
2006-12-22 04:41:44 +00:00
NSWindow *sheet = [_sheetContext sheet];
NSRect sheetFrame = [sheet frame];
2006-12-22 04:41:44 +00:00
sheet->_isVisible=NO;
[[sheet platformWindow] sheetOrderOutToFrame:NSMakeRect(sheetFrame.origin.x,NSMaxY(sheetFrame),sheetFrame.size.width,0)];
2006-12-22 04:41:44 +00:00
[_sheetContext release];
_sheetContext=nil;
}
-(void)_flashWindow {
if([self _isApplicationWindow])
[[self platformWindow] flashWindow];
}
2006-12-22 04:41:44 +00:00
-(void)platformWindowActivated:(CGWindow *)window displayIfNeeded:(BOOL)displayIfNeeded {
[NSApp _windowWillBecomeActive:self];
2006-12-22 04:41:44 +00:00
[self _setSheetOriginAndFront];
[_childWindows makeObjectsPerformSelector:@selector(_parentWindowDidActivate:) withObject:self];
[_drawers makeObjectsPerformSelector:@selector(parentWindowDidActivate:) withObject:self];
2006-12-22 04:41:44 +00:00
_isActive=YES;
if([self canBecomeKeyWindow] && ![self isKeyWindow])
[self becomeKeyWindow];
if([self canBecomeMainWindow] && ![self isMainWindow])
[self becomeMainWindow];
[_menuView setNeedsDisplay:YES];
if(displayIfNeeded)
[self displayIfNeeded];
2006-12-22 04:41:44 +00:00
[NSApp _windowDidBecomeActive:self];
2006-12-22 04:41:44 +00:00
[NSApp updateWindows];
}
-(void)platformWindowDeactivated:(CGWindow *)window checkForAppDeactivation:(BOOL)checkForAppDeactivation {
[NSApp _windowWillBecomeDeactive:self];
[_childWindows makeObjectsPerformSelector:@selector(_parentWindowDidDeactivate:) withObject:self];
[_drawers makeObjectsPerformSelector:@selector(parentWindowDidDeactivate:) withObject:self];
2006-12-22 04:41:44 +00:00
_isActive=NO;
if([self isMainWindow])
[self resignMainWindow];
2006-12-22 04:41:44 +00:00
if([self isKeyWindow])
[self resignKeyWindow];
[_menuView setNeedsDisplay:YES];
[self displayIfNeeded];
if(checkForAppDeactivation)
[NSApp performSelector:@selector(_checkForAppActivation)];
[NSApp _windowDidBecomeDeactive:self];
2006-12-22 04:41:44 +00:00
[NSApp updateWindows];
}
-(void)platformWindowDeminiaturized:(CGWindow *)window {
[self _updatePlatformWindowTitle];
if(_sheetContext!=nil){
[[_sheetContext sheet] orderWindow:NSWindowAbove relativeTo:[self windowNumber]];
}
2006-12-22 04:41:44 +00:00
[self postNotificationName:NSWindowDidDeminiaturizeNotification];
[NSApp updateWindows];
}
-(void)platformWindowMiniaturized:(CGWindow *)window {
_isActive=NO;
[self _updatePlatformWindowTitle];
if(_sheetContext!=nil){
[[_sheetContext sheet] orderWindow:NSWindowOut relativeTo:0];
}
2006-12-22 04:41:44 +00:00
[self postNotificationName:NSWindowDidMiniaturizeNotification];
if([self isKeyWindow])
[self resignKeyWindow];
if([self isMainWindow])
[self resignMainWindow];
[_childWindows makeObjectsPerformSelector:@selector(_parentWindowDidMiniaturize:) withObject:self];
[_drawers makeObjectsPerformSelector:@selector(parentWindowDidMiniaturize:) withObject:self];
2006-12-22 04:41:44 +00:00
[NSApp updateWindows];
}
-(void)platformWindow:(CGWindow *)window frameChanged:(NSRect)frame didSize:(BOOL)didSize {
2006-12-22 04:41:44 +00:00
_frame=frame;
2006-12-22 04:41:44 +00:00
_makeSureIsOnAScreen=YES;
[self _setSheetOriginAndFront];
[_childWindows makeObjectsPerformSelector:@selector(_parentWindowDidChangeFrame:) withObject:self];
[_drawers makeObjectsPerformSelector:@selector(parentWindowDidChangeFrame:) withObject:self];
2006-12-22 04:41:44 +00:00
[_backgroundView setFrameSize:_frame.size];
[_backgroundView setNeedsDisplay:YES];
[self saveFrameUsingName:_autosaveFrameName];
2006-12-22 04:41:44 +00:00
[self resetCursorRects];
if(didSize)
[self postNotificationName:NSWindowDidResizeNotification];
else
[self postNotificationName:NSWindowDidMoveNotification];
2006-12-22 04:41:44 +00:00
}
-(void)platformWindowExitMove:(CGWindow *)window {
[self _setSheetOriginAndFront];
[_childWindows makeObjectsPerformSelector:@selector(_parentWindowDidExitMove:) withObject:self];
[_drawers makeObjectsPerformSelector:@selector(parentWindowDidExitMove:) withObject:self];
2006-12-22 04:41:44 +00:00
}
-(NSSize)platformWindow:(CGWindow *)window frameSizeWillChange:(NSSize)size {
if(_resizeIncrements.width!=1 || _resizeIncrements.height!=1){
NSSize vertical=size;
NSSize horizontal=size;
vertical.width=vertical.height*(_resizeIncrements.width/_resizeIncrements.height);
horizontal.height=horizontal.width*(_resizeIncrements.height/_resizeIncrements.width);
if(vertical.width*vertical.height>horizontal.width*horizontal.height)
size=vertical;
else
size=horizontal;
}
2006-12-22 04:41:44 +00:00
if([_delegate respondsToSelector:@selector(windowWillResize:toSize:)])
size=[_delegate windowWillResize:self toSize:size];
return size;
}
-(void)platformWindowWillBeginSizing:(CGWindow *)window {
[self postNotificationName:NSWindowWillStartLiveResizeNotification];
2006-12-22 04:41:44 +00:00
[_backgroundView viewWillStartLiveResize];
}
-(void)platformWindowDidEndSizing:(CGWindow *)window {
[_backgroundView viewDidEndLiveResize];
[self postNotificationName:NSWindowDidEndLiveResizeNotification];
2006-12-22 04:41:44 +00:00
}
-(void)platformWindow:(CGWindow *)window needsDisplayInRect:(NSRect)rect {
[self display];
}
-(void)platformWindowStyleChanged:(CGWindow *)window {
[self display];
}
-(void)platformWindowWillClose:(CGWindow *)window {
if([NSApp modalWindow]==self)
[NSApp stopModalWithCode:NSRunAbortedResponse];
[self performClose:nil];
}
-(void)platformWindowWillMove:(CGWindow *)window {
[self postNotificationName:NSWindowWillMoveNotification];
}
-(void)platformWindowDidMove:(CGWindow *)window {
[self postNotificationName:NSWindowDidMoveNotification];
}
-(BOOL)platformWindowIgnoreModalMessages:(CGWindow *)window {
if([NSApp modalWindow]==nil)
return NO;
if([self worksWhenModal])
return NO;
return ([NSApp modalWindow]==self)?NO:YES;
}
-(BOOL)platformWindowSetCursorEvent:(CGWindow *)window {
NSMutableArray *exited=[NSMutableArray array];
NSMutableArray *entered=[NSMutableArray array];
NSMutableArray *moved=[NSMutableArray array];
NSMutableArray *update=[NSMutableArray array];
NSPoint mousePoint={-1,-1};
BOOL cursorIsSet=NO;
BOOL raiseToolTipWindow=NO;
NSUInteger i,count;
2006-12-22 04:41:44 +00:00
mousePoint=[self mouseLocationOutsideOfEventStream];
2006-12-22 04:41:44 +00:00
// This collects only the active ones.
[self _resetTrackingAreas];
2006-12-22 04:41:44 +00:00
count=[_trackingAreas count];
for(i=0;i<count;i++){
NSTrackingArea *area=[_trackingAreas objectAtIndex:i];
BOOL mouseWasInside=[area _mouseInside];
BOOL mouseIsInside=NSPointInRect(mousePoint,[area _rectInWindow]);
id owner=[area owner];
2006-12-22 04:41:44 +00:00
if([area _isToolTip]==YES){
NSToolTipWindow *toolTipWindow=[NSToolTipWindow sharedToolTipWindow];
if([self isKeyWindow]==NO || [self _sheetContext]!=nil)
mouseIsInside=NO;
if(mouseWasInside==YES && mouseIsInside==NO && [toolTipWindow _trackingArea]==area){
[NSObject cancelPreviousPerformRequestsWithTarget:toolTipWindow selector:@selector(orderFront:) object:nil];
[toolTipWindow orderOut:nil];
2006-12-22 04:41:44 +00:00
}
if(mouseWasInside==NO && mouseIsInside==YES){ // AllowsToolTipsWhenApplicationIsInactive
// is handled when rebuilding areas.
[NSObject cancelPreviousPerformRequestsWithTarget:toolTipWindow selector:@selector(orderFront:) object:nil];
[toolTipWindow orderOut:nil];
if([owner respondsToSelector:@selector(view:stringForToolTip:point:userData:)]==YES)
[toolTipWindow setToolTip:[owner view:[area _view] stringForToolTip:area point:mousePoint userData:[area userInfo]]];
else
[toolTipWindow setToolTip:[owner description]];
// This gives us some protection when ToolTip areas overlap:
[toolTipWindow _setTrackingArea:area];
raiseToolTipWindow=YES;
}
}
else{ // not ToolTip
NSTrackingAreaOptions options=[area options];
2006-12-22 04:41:44 +00:00
// Options by view activation.
if(options&NSTrackingActiveAlways){
}
else if(options&NSTrackingActiveInActiveApp && [NSApp isActive]==NO){
mouseIsInside=NO;
}
else if(options&NSTrackingActiveInKeyWindow && ([self isKeyWindow]==NO || [self _sheetContext]!=nil)){
mouseIsInside=NO;
}
else if(options&NSTrackingActiveWhenFirstResponder && [area _view]!=[self firstResponder]){
mouseIsInside=NO;
}
if(options&NSTrackingInVisibleRect){
// This does not do hit testing, it just checks if it's inside the visible rect,
// child views will cause the test to fail if they aren't tracking anything
NSPoint check=[[area _view] convertPoint:mousePoint fromView:nil];
if(!NSMouseInRect(check,[[area _view] visibleRect],[[area _view] isFlipped]))
mouseIsInside=NO;
}
//FIXME:
if(options&NSTrackingEnabledDuringMouseDrag){
// NSLog(@"NSTrackingEnabledDuringMouseDrag handling unimplemented.");
}
2006-12-22 04:41:44 +00:00
// Send appropriate events.
if(options&NSTrackingMouseEnteredAndExited && mouseWasInside==NO && mouseIsInside==YES){
[entered addObject:area];
}
if(options&NSTrackingMouseEnteredAndExited && mouseWasInside==YES && mouseIsInside==NO){
[exited addObject:area];
}
if(options&NSTrackingMouseMoved && [self acceptsMouseMovedEvents]==YES){
[moved addObject:area];
}
if(options&NSTrackingCursorUpdate && mouseWasInside==NO && mouseIsInside==YES && !(options&NSTrackingActiveAlways)){
[update addObject:area];
}
if(options&NSTrackingCursorUpdate && mouseIsInside==YES)
cursorIsSet=YES;
} // (not) ToolTip
[area _setMouseInside:mouseIsInside];
}
// Exited events need to be sent before entered events
// The order of the other two is not specific at this time
for(NSTrackingArea *check in exited){
id owner=[check owner];
if([owner respondsToSelector:@selector(mouseExited:)]){
NSEvent *event=[NSEvent enterExitEventWithType:NSMouseExited
location:mousePoint
modifierFlags:[NSEvent modifierFlags]
timestamp:[NSDate timeIntervalSinceReferenceDate]
windowNumber:[self windowNumber]
context:[self graphicsContext]
eventNumber:0 // NSEvent currently ignores this.
trackingNumber:(NSInteger)check
userData:[check userInfo]];
[owner mouseExited:event];
2006-12-22 04:41:44 +00:00
}
}
for(NSTrackingArea *check in entered){
id owner=[check owner];
if([owner respondsToSelector:@selector(mouseEntered:)]){
NSEvent *event=[NSEvent enterExitEventWithType:NSMouseEntered
location:mousePoint
modifierFlags:[NSEvent modifierFlags]
timestamp:[NSDate timeIntervalSinceReferenceDate]
windowNumber:[self windowNumber]
context:[self graphicsContext]
eventNumber:0 // NSEvent currently ignores this.
trackingNumber:(NSInteger)check
userData:[check userInfo]];
[owner mouseEntered:event];
}
}
for(NSTrackingArea *check in moved){
id owner=[check owner];
if([owner respondsToSelector:@selector(mouseMoved:)]){
NSEvent *event=[NSEvent mouseEventWithType:NSMouseMoved
location:mousePoint
modifierFlags:[NSEvent modifierFlags]
timestamp:[NSDate timeIntervalSinceReferenceDate]
windowNumber:[self windowNumber]
context:[self graphicsContext]
eventNumber:0 // NSEvent currently ignores this.
clickCount:0
pressure:0.];
[owner mouseMoved:event];
}
}
for(NSTrackingArea *check in update){
id owner=[check owner];
if([owner respondsToSelector:@selector(cursorUpdate:)]){
NSEvent *event=[NSEvent enterExitEventWithType:NSCursorUpdate
location:mousePoint
modifierFlags:[NSEvent modifierFlags]
timestamp:[NSDate timeIntervalSinceReferenceDate]
windowNumber:[self windowNumber]
context:[self graphicsContext]
eventNumber:0 // NSEvent currently ignores this.
trackingNumber:(NSInteger)check
userData:[check userInfo]];
[owner cursorUpdate:event];
}
2006-12-22 04:41:44 +00:00
}
if(raiseToolTipWindow==YES){
NSTimeInterval delay=((NSTimeInterval)[[NSUserDefaults standardUserDefaults] integerForKey:@"NSInitialToolTipDelay"])/1000.;
if(delay<=0.)
delay=2.;
[[NSToolTipWindow sharedToolTipWindow] performSelector:@selector(orderFront:) withObject:nil afterDelay:delay];
}
return cursorIsSet;
2006-12-22 04:41:44 +00:00
}
-(NSUndoManager *)undoManager {
if ([_delegate respondsToSelector:@selector(windowWillReturnUndoManager:)])
return [_delegate windowWillReturnUndoManager:self];
// If this window is associated with a document, return the document's undo manager.
// Apple's documentation says this is the delegate's responsibility, but that's not how it works in real life.
if (_undoManager == nil) {
_undoManager = [[[[self windowController] document] undoManager] retain];
}
2006-12-22 04:41:44 +00:00
// If the delegate does not implement this method, the NSWindow creates an NSUndoManager for the window and all its views. -- seems like some duplication vs. NSDocument, but oh well..
if (_undoManager == nil){
_undoManager = [[NSUndoManager alloc] init];
[_undoManager setRunLoopModes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSEventTrackingRunLoopMode,nil]];
}
return _undoManager;
}
-(void)undo:sender {
[[self undoManager] undo];
}
-(void)redo:sender {
[[self undoManager] redo];
}
-(BOOL)validateMenuItem:(NSMenuItem *)item {
if ([item action] == @selector(undo:))
return [[self undoManager] canUndo];
if ([item action] == @selector(redo:))
return [[self undoManager] canRedo];
return YES;
}
2006-12-22 04:41:44 +00:00
-(void)_attachDrawer:(NSDrawer *)drawer {
if (_drawers == nil)
_drawers = [[NSMutableArray alloc] init];
[_drawers addObject:drawer];
}
-(void)_detachDrawer:(NSDrawer *)drawer {
[_drawers removeObject:drawer];
}
-(NSView *)_backgroundView {
return _backgroundView;
}
@end