From ccfc67f353c5f20a5bc2bd31bf703f44fb7e2c53 Mon Sep 17 00:00:00 2001 From: far Date: Thu, 12 Nov 1998 10:49:00 +0000 Subject: [PATCH] gui changes git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3208 72102866-910b-0410-8b05-ffd578937521 --- GNUmakefile | 2 +- Headers/gnustep/gui/NSMenu.h | 3 + Headers/gnustep/gui/NSWindow.h | 11 +- Source/NSApplication.m | 189 +++- Source/NSCell.m | 21 +- Source/NSDPSContext.m | 1 + Source/NSMenu.m | 7 + Source/NSView.m | 34 +- Source/NSWindow.m | 1698 ++++++++++++-------------------- 9 files changed, 815 insertions(+), 1151 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index ee57bf428..8ecc03813 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -34,7 +34,7 @@ include $(GNUSTEP_MAKEFILES)/common.make # # The list of subproject directories # -SUBPROJECTS = Model Source Images Tools +SUBPROJECTS = Source Images Model Tools -include GNUmakefile.preamble diff --git a/Headers/gnustep/gui/NSMenu.h b/Headers/gnustep/gui/NSMenu.h index 7d78767c9..24bd770fe 100644 --- a/Headers/gnustep/gui/NSMenu.h +++ b/Headers/gnustep/gui/NSMenu.h @@ -109,6 +109,9 @@ /* Getting the menu cells matrix */ - (NSMenuMatrix*)menuCells; +// non OS spec methods +- (void)_rightMouseDisplay; + @end diff --git a/Headers/gnustep/gui/NSWindow.h b/Headers/gnustep/gui/NSWindow.h index 8deda76b5..2adebec0a 100644 --- a/Headers/gnustep/gui/NSWindow.h +++ b/Headers/gnustep/gui/NSWindow.h @@ -400,15 +400,10 @@ extern NSSize NSTokenSize; - (void)encodeWithCoder:aCoder; - initWithCoder:aDecoder; -/* Private methods */ -- (void)_view:(NSView*)view needsFlushInRect:(NSRect)rect; -- (void)_setNeedsDisplay; -- (void)_setNeedsFlush; -- (BOOL)_needsFlush; +// +// Private methods +// - (void)_collectFlushRectangles; -+ (BOOL)_flushWindows; -+ (void)_setNeedsFlushWindows:(BOOL)flag; -+ (BOOL)_needsFlushWindows; @end diff --git a/Source/NSApplication.m b/Source/NSApplication.m index dbec66d2f..3469d0dd1 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -285,6 +285,21 @@ NSAutoreleasePool* pool; break; } + case NSRightMouseDown: // Right mouse down + { + static NSMenu *copyOfMainMenu = nil; + NSWindow *copyMenuWindow; + + if(!copyOfMainMenu) // display the menu + copyOfMainMenu = [main_menu copy]; // under the mouse + copyMenuWindow = [copyOfMainMenu menuWindow]; + [copyOfMainMenu _rightMouseDisplay]; + [copyMenuWindow captureMouse:self]; + [[copyOfMainMenu menuCells] mouseDown:theEvent]; + [copyMenuWindow releaseMouse:self]; + } + break; + default: // pass all other events to { // the event's window NSWindow* window = [theEvent window]; @@ -326,28 +341,132 @@ NSAutoreleasePool* pool; - (void)discardEventsMatchingMask:(unsigned int)mask beforeEvent:(NSEvent *)lastEvent { +int i = 0, count; +NSEvent* event = nil; +BOOL match = NO; + + count = [event_queue count]; + event = [event_queue objectAtIndex:i]; + while((event != lastEvent) && (i < count)) + { + if (mask == NSAnyEventMask) // any event is a match + match = YES; + else + { + if (event == null_event) + match = YES; // dump all null events + else + { + switch([event type]) + { + case NSLeftMouseDown: + if (mask & NSLeftMouseDownMask) + match = YES; + break; + + case NSLeftMouseUp: + if (mask & NSLeftMouseUpMask) + match = YES; + break; + + case NSRightMouseDown: + if (mask & NSRightMouseDownMask) + match = YES; + break; + + case NSRightMouseUp: + if (mask & NSRightMouseUpMask) + match = YES; + break; + + case NSMouseMoved: + if (mask & NSMouseMovedMask) + match = YES; + break; + + case NSMouseEntered: + if (mask & NSMouseEnteredMask) + match = YES; + break; + + case NSMouseExited: + if (mask & NSMouseExitedMask) + match = YES; + break; + + case NSLeftMouseDragged: + if (mask & NSLeftMouseDraggedMask) + match = YES; + break; + + case NSRightMouseDragged: + if (mask & NSRightMouseDraggedMask) + match = YES; + break; + + case NSKeyDown: + if (mask & NSKeyDownMask) + match = YES; + break; + + case NSKeyUp: + if (mask & NSKeyUpMask) + match = YES; + break; + + case NSFlagsChanged: + if (mask & NSFlagsChangedMask) + match = YES; + break; + + case NSPeriodic: + if (mask & NSPeriodicMask) + match = YES; + break; + + case NSCursorUpdate: + if (mask & NSCursorUpdateMask) + match = YES; + break; + + default: + match = NO; + break; + } } } // remove event from + // the queue if it + if (match) // matched the mask + [event_queue removeObjectAtIndex:i]; + event = [event_queue objectAtIndex:++i]; // get the next event + }; // in the queue } -- (NSEvent*)_eventMatchingMask:(unsigned int)mask // return the next -{ // event in the queue -NSEvent* event; // which matches mask -int i, count; -BOOL match = NO; +- (NSEvent*)_eventMatchingMask:(unsigned int)mask dequeue:(BOOL)flag +{ +NSEvent* event; // return the next +int i, count; // event in the queue +BOOL match = NO; // which matches mask [self _nextEvent]; - if ((count = [event_queue count])) // Get an event from - { // the events queue + if ((count = [event_queue count])) // if queue contains + { // events check them for (i = 0; i < count; i++) - { - event = [event_queue objectAtIndex:i]; + { // Get next event from + event = [event_queue objectAtIndex:i]; // the events queue - if (mask == NSAnyEventMask) // any event is a match - match = YES; + if (mask == NSAnyEventMask) // the any event mask + match = YES; // matches all events else { - if (event == null_event) // do nothing if null - match = NO; // event + if (event == null_event) // do not send the null + { // event + match = NO; + if(flag) // dequeue null event + { // if flag is set + [event retain]; + [event_queue removeObjectAtIndex:i]; + } + } else { switch([event type]) @@ -425,30 +544,30 @@ BOOL match = NO; default: match = NO; break; - } - } - } - + } } } + if (match) { - [event retain]; - [event_queue removeObjectAtIndex:i]; - ASSIGN(current_event, event); - - return [event autorelease]; // return an event from + if(flag) // dequeue the event if + { // flag is set + [event retain]; + [event_queue removeObjectAtIndex:i]; + } + ASSIGN(current_event, event); + + return event; // return an event from } // the queue which } // matches the mask } - - return nil; // no event in the -} // queue matches mask + // no event in the + return nil; // queue matches mask +} - (NSEvent *)nextEventMatchingMask:(unsigned int)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)flag { -NSEventType type; NSEvent *event; BOOL done = NO; @@ -457,7 +576,7 @@ BOOL done = NO; else // of X motion events inTrackingLoop = NO; // while not in a // tracking loop - if ((event = [self _eventMatchingMask:mask])) + if ((event = [self _eventMatchingMask:mask dequeue:flag])) done = YES; else if (!expiration) @@ -473,7 +592,7 @@ BOOL done = NO; limitDate = [[currentLoop limitDateForMode:mode] retain]; originalLimitDate = limitDate; - if ((event = [self _eventMatchingMask:mask])) + if ((event = [self _eventMatchingMask:mask dequeue:flag])) { [limitDate release]; break; @@ -487,15 +606,15 @@ BOOL done = NO; [currentLoop runMode:mode beforeDate:limitDate]; [originalLimitDate release]; - if ((event = [self _eventMatchingMask:mask])) + if ((event = [self _eventMatchingMask:mask dequeue:flag])) break; - } // no need to unhide cursor - // while in a tracking loop - if (event != null_event && (!inTrackingLoop)) // or if null event + } + // no need to unhide cursor + if (!inTrackingLoop) // while in a tracking loop { if ([NSCursor isHiddenUntilMouseMoves]) // do so only if we should { // unhide when mouse moves - type = [event type]; // and event is mouse event + NSEventType type = [event type]; // and event is mouse event if ((type == NSLeftMouseDown) || (type == NSLeftMouseUp) || (type == NSRightMouseDown) || (type == NSRightMouseUp) || (type == NSMouseMoved)) @@ -761,8 +880,8 @@ NSArray *mi; // Managing the Windows menu // - (void)addWindowsItem:aWindow - title:(NSString *)aString - filename:(BOOL)isFilename + title:(NSString *)aString + filename:(BOOL)isFilename { int i; diff --git a/Source/NSCell.m b/Source/NSCell.m index 5c973b2a4..2f55e001a 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -491,25 +491,20 @@ NSString* _string; } - (void)drawInteriorWithFrame:(NSRect)cellFrame - inView:(NSView *)controlView -{} + inView:(NSView *)controlView +{ // implemented in back end +} - (void)drawWithFrame:(NSRect)cellFrame - inView:(NSView *)controlView -{ - /* Mark the cell's frame rectangle as needing flush */ - [[controlView window] _view:controlView needsFlushInRect:cellFrame]; -} + inView:(NSView *)controlView +{ // implemented in back end +} - (void)highlight:(BOOL)lit withFrame:(NSRect)cellFrame inView:(NSView *)controlView -{ - cell_highlighted = lit; - - /* Mark the cell's frame rectangle as needing flush */ - [[controlView window] _view:controlView needsFlushInRect:cellFrame]; -} +{ // implemented in back end +} - (BOOL)isHighlighted { diff --git a/Source/NSDPSContext.m b/Source/NSDPSContext.m index 8988d3521..31cb1b6cc 100644 --- a/Source/NSDPSContext.m +++ b/Source/NSDPSContext.m @@ -147,6 +147,7 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO; // Get current context for current thread +//if(current_thread) current_context = [[current_thread threadDictionary] objectForKey: GNU_CONTEXT_THREAD_KEY]; // If not in dictionary then create one diff --git a/Source/NSMenu.m b/Source/NSMenu.m index 229cd0248..af2fb7878 100644 --- a/Source/NSMenu.m +++ b/Source/NSMenu.m @@ -753,14 +753,21 @@ static Class menuCellClass = nil; { } +// non OS spec methods +- (void)_rightMouseDisplay +{ +} + @end /* NSMenu */ @implementation NSMenu (PrivateMethods2) + - (void)_menuChanged { menuHasChanged = YES; if (menuChangedMessagesEnabled) [self sizeToFit]; } + @end diff --git a/Source/NSView.m b/Source/NSView.m index 5342c2d8c..a5eacf83e 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -796,11 +796,6 @@ NSView *current_view = nil; return YES; } -- (void)_setNeedsFlush -{ - [window _setNeedsFlush]; -} - - (void)display { if(!window) // do nothing if not in @@ -835,14 +830,13 @@ NSView *current_view = nil; int i, count; if (!boundsMatrix || !frameMatrix) - NSLog (@"warning: %@ %p has not have the PS matrices setup!", + NSLog (@"warning: %@ %p does not have it's PS matrices configured!", NSStringFromClass(isa), self); needs_display = NO; [self lockFocus]; [self drawRect:rect]; - [window _setNeedsFlush]; [self unlockFocus]; // Tell subviews to display for (i = 0, count = [sub_views count]; i < count; ++i) @@ -955,25 +949,25 @@ NSView* currentView; // of sibling subviews - (void)setNeedsDisplay:(BOOL)flag { - needs_display = flag; - if (needs_display) { + needs_display = flag; + if (needs_display) + { + invalidatedRectangle = bounds; + [window setViewsNeedDisplay:YES]; - invalidatedRectangle = bounds; - [window _setNeedsDisplay]; - - if (super_view) - [super_view _addSubviewForNeedingDisplay:self]; - } + if (super_view) + [super_view _addSubviewForNeedingDisplay:self]; + } } - (void)setNeedsDisplayInRect:(NSRect)rect { - needs_display = YES; - invalidatedRectangle = NSUnionRect (invalidatedRectangle, rect); - [window _setNeedsDisplay]; + needs_display = YES; + invalidatedRectangle = NSUnionRect (invalidatedRectangle, rect); + [window setViewsNeedDisplay:YES]; - if (super_view) - [super_view _addSubviewForNeedingDisplay:self]; + if (super_view) + [super_view _addSubviewForNeedingDisplay:self]; } - (void)_recursivelyResetNeedsDisplayInAllViews diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 83c2f7288..addb737a1 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -30,6 +30,7 @@ */ #include + #include #include #include @@ -55,64 +56,53 @@ a = b; +//***************************************************************************** // -// NSWindow implementation +// NSWindow // -@implementation NSWindow +//***************************************************************************** -static BOOL _needsFlushWindows = YES; +@implementation NSWindow // // Class methods // + (void)initialize { - if (self == [NSWindow class]) - { - NSDebugLog(@"Initialize NSWindow class\n"); - - // Initial version - [self setVersion:2]; - } + if (self == [NSWindow class]) + { + NSDebugLog(@"Initialize NSWindow class\n"); + [self setVersion:2]; // Initial version + } } -// Saving and restoring the frame -+ (void)removeFrameUsingName:(NSString *)name -{ -} ++ (void)removeFrameUsingName:(NSString *)name +{ // Saving and restoring +} // the frame -// Computing frame and content rectangles + (NSRect)contentRectForFrameRect:(NSRect)aRect - styleMask:(unsigned int)aStyle -{ - return aRect; + styleMask:(unsigned int)aStyle +{ // Computing frame and + return aRect; // content rectangles } + (NSRect)frameRectForContentRect:(NSRect)aRect - styleMask:(unsigned int)aStyle + styleMask:(unsigned int)aStyle { - return aRect; + return aRect; } + (NSRect)minFrameWidthWithTitle:(NSString *)aTitle - styleMask:(unsigned int)aStyle + styleMask:(unsigned int)aStyle { - return NSZeroRect; + return NSZeroRect; } -// Screens and window depths -+ (NSWindowDepth)defaultDepthLimit -{ - return 8; ++ (NSWindowDepth)defaultDepthLimit // default Screen and +{ // window depth + return 8; } -+ (void)_setNeedsFlushWindows:(BOOL)flag -{ - _needsFlushWindows = flag; -} - -+ (BOOL)_needsFlushWindows { return _needsFlushWindows; } - // // Instance methods // @@ -136,21 +126,20 @@ int style; - (void)dealloc { - // Release the content view - if (content_view) { - // Release the window view - [[content_view superview] release]; - [content_view release]; - } + if (content_view) + { + [[content_view superview] release]; // Release the window view + [content_view release]; // Release the content view + } - [background_color release]; - [represented_filename release]; - [miniaturized_title release]; - [miniaturized_image release]; - [window_title release]; - [_flushRectangles release]; - - [super dealloc]; + [background_color release]; + [represented_filename release]; + [miniaturized_title release]; + [miniaturized_image release]; + [window_title release]; + [_flushRectangles release]; + + [super dealloc]; } // @@ -176,203 +165,148 @@ int style; defer:(BOOL)flag screen:aScreen { - NSApplication *theApp = [NSApplication sharedApplication]; - NSRect r = [[NSScreen mainScreen] frame]; - NSRect cframe; +NSApplication *theApp = [NSApplication sharedApplication]; +NSRect r = [[NSScreen mainScreen] frame]; +NSRect cframe; - NSDebugLog(@"NSWindow default initializer\n"); - if (!theApp) - NSLog(@"No application!\n"); + NSDebugLog(@"NSWindow default initializer\n"); + if (!theApp) + NSLog(@"No application!\n"); - NSDebugLog(@"NSWindow start of init\n"); + NSDebugLog(@"NSWindow start of init\n"); + // Initialize attributes + [self cleanInit]; // and flags - // Initialize attributes and flags - [self cleanInit]; + backing_type = bufferingType; + style_mask = aStyle; + // Size the attributes + frame = [NSWindow frameRectForContentRect: contentRect styleMask: aStyle]; + minimum_size = NSZeroSize; + maximum_size = r.size; + // Next responder is the + [self setNextResponder:theApp]; // application - backing_type = bufferingType; - style_mask = aStyle; + cursor_rects_enabled = YES; // Cursor management + cursor_rects_valid = NO; - // Size attributes - frame = [NSWindow frameRectForContentRect: contentRect styleMask: aStyle]; - minimum_size = NSZeroSize; - maximum_size = r.size; + cframe.origin = NSZeroPoint; // Create the content view + cframe.size = frame.size; + [self setContentView:[[[NSView alloc] initWithFrame:cframe] autorelease]]; + // Register ourselves with + // the Application object + [theApp addWindowsItem:self title:window_title filename:NO]; - // Next responder is the application - [self setNextResponder:theApp]; + _flushRectangles = [[NSMutableArray alloc] initWithCapacity:10]; - // Cursor management - cursor_rects_enabled = YES; - cursor_rects_valid = NO; + NSDebugLog(@"NSWindow end of init\n"); - // Create our content view - cframe.origin = NSZeroPoint; - cframe.size = frame.size; - [self setContentView:[[[NSView alloc] initWithFrame:cframe] autorelease]]; - - // Register ourselves with the Application object - [theApp addWindowsItem:self title:window_title filename:NO]; - - _flushRectangles = [[NSMutableArray alloc] initWithCapacity:10]; - - NSDebugLog(@"NSWindow end of init\n"); - return self; + return self; } // // Accessing the content view // -- contentView -{ - return content_view; -} +- contentView { return content_view; } - (void)setContentView:(NSView *)aView { - NSView *wv; +NSView *wv; - // Cannot have a nil content view - if (!aView) - aView = [[[NSView alloc] initWithFrame: frame] autorelease]; + if (!aView) // contentview can't be nil + aView = [[[NSView alloc] initWithFrame: frame] autorelease]; + // If window view has not + // been created, create it + if ((!content_view) || ([content_view superview] == nil)) + { + wv = [[NSWindowView alloc] initWithFrame: frame]; + [wv viewWillMoveToWindow: self]; + } + else + wv = [content_view superview]; - // If the window view hasn't been created yet - // then create it - if ((!content_view) || ([content_view superview] == nil)) { - wv = [[NSWindowView alloc] initWithFrame: frame]; - [wv viewWillMoveToWindow: self]; - } - else - wv = [content_view superview]; + if (content_view) + [content_view removeFromSuperview]; - if (content_view) - [content_view removeFromSuperview]; + ASSIGN(content_view, aView); - ASSIGN(content_view, aView); - - // Add to our window view - [wv addSubview: content_view]; - NSAssert1 ([[wv subviews] count] == 1, - @"window's view has %d subviews!", - [[wv subviews] count]); - - // Make us the view's next responder - [content_view setNextResponder:self]; + [wv addSubview: content_view]; // Add to our window view + NSAssert1 ([[wv subviews] count] == 1, @"window's view has %d subviews!", + [[wv subviews] count]); + // Make self the view's + [content_view setNextResponder:self]; // next responder } // // Window graphics // -- (NSColor *)backgroundColor -{ - return background_color; -} - -- (NSString *)representedFilename -{ - return represented_filename; -} +- (NSColor *)backgroundColor { return background_color; } +- (NSString *)representedFilename { return represented_filename; } - (void)setBackgroundColor:(NSColor *)color { - ASSIGN(background_color, color); + ASSIGN(background_color, color); } - (void)setRepresentedFilename:(NSString *)aString { - ASSIGN(represented_filename, aString); + ASSIGN(represented_filename, aString); } -- (void)setTitle:(NSString *)aString -{ - ASSIGN(window_title, aString); -} +- (void)setTitle:(NSString *)aString { ASSIGN(window_title,aString); } - (void)setTitleWithRepresentedFilename:(NSString *)aString { - [self setRepresentedFilename:aString]; - [self setTitle:aString]; + [self setRepresentedFilename:aString]; + [self setTitle:aString]; } -- (unsigned int)styleMask -{ - return style_mask; -} - -- (NSString *)title -{ - return window_title; -} +- (unsigned int)styleMask { return style_mask; } +- (NSString *)title { return window_title; } // // Window device attributes // -- (NSBackingStoreType)backingType -{ - return backing_type; -} +- (NSBackingStoreType)backingType { return backing_type; } - (NSDictionary *)deviceDescription { - return nil; + return nil; } -- (int)gState -{ - return 0; +- (int)gState { return 0; } +- (BOOL)isOneShot { return is_one_shot; } + +- (void)setBackingType:(NSBackingStoreType)type +{ + backing_type = type; } -- (BOOL)isOneShot -{ - return is_one_shot; -} - -- (void)setBackingType:(NSBackingStoreType)type -{ - backing_type = type; -} - -- (void)setOneShot:(BOOL)flag -{ - is_one_shot = flag; -} - -- (int)windowNumber -{ - return window_num; -} - -- (void)setWindowNumber:(int)windowNum -{ - window_num = windowNum; -} +- (void)setOneShot:(BOOL)flag { is_one_shot = flag; } +- (int)windowNumber { return window_num; } +- (void)setWindowNumber:(int)windowNum { window_num = windowNum; } // // The miniwindow // -- (NSImage *)miniwindowImage -{ - return miniaturized_image; -} - -- (NSString *)miniwindowTitle -{ - return miniaturized_title; -} +- (NSImage *)miniwindowImage { return miniaturized_image; } +- (NSString *)miniwindowTitle { return miniaturized_title; } - (void)setMiniwindowImage:(NSImage *)image { - ASSIGN(miniaturized_image, image); + ASSIGN(miniaturized_image, image); } - (void)setMiniwindowTitle:(NSString *)title; { - ASSIGN(miniaturized_title, title); + ASSIGN(miniaturized_title, title); } // // The field editor // - (void)endEditingFor:anObject -{} +{ +} - (NSText *)fieldEditor:(BOOL)createFlag forObject:anObject { @@ -387,351 +321,235 @@ int style; // - (void)becomeKeyWindow { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; +NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - // We are the key window - is_key = YES; - - // Reset the cursor rects - [self resetCursorRects]; - - // Post notification - [nc postNotificationName: NSWindowDidBecomeKeyNotification object: self]; + is_key = YES; // We are the key window + + [self resetCursorRects]; // Reset the cursor rects + // Post notification + [nc postNotificationName: NSWindowDidBecomeKeyNotification object: self]; } - (void)becomeMainWindow { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - - // We are the main window - is_main = YES; - - // Post notification - [nc postNotificationName: NSWindowDidBecomeMainNotification object: self]; +NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + + is_main = YES; // We are the main window + // Post notification + [nc postNotificationName: NSWindowDidBecomeMainNotification object: self]; } -- (BOOL)canBecomeKeyWindow -{ - return YES; -} - -- (BOOL)canBecomeMainWindow -{ - return YES; -} - -- (BOOL)hidesOnDeactivate -{ - return hides_on_deactivate; -} - -- (BOOL)isKeyWindow -{ - return is_key; -} - -- (BOOL)isMainWindow -{ - return is_main; -} - -- (BOOL)isMiniaturized -{ - return is_miniaturized; -} - -- (BOOL)isVisible -{ - return visible; -} - -- (int)level -{ - return window_level; -} +- (BOOL)canBecomeKeyWindow { return YES; } +- (BOOL)canBecomeMainWindow { return YES; } +- (BOOL)hidesOnDeactivate { return hides_on_deactivate; } +- (BOOL)isKeyWindow { return is_key; } +- (BOOL)isMainWindow { return is_main; } +- (BOOL)isMiniaturized { return is_miniaturized; } +- (BOOL)isVisible { return visible; } +- (int)level { return window_level; } - (void)makeKeyAndOrderFront:sender -{ - // Make ourself the key window - [self makeKeyWindow]; - - // Now order to the front - [self orderFront:sender]; +{ + [self makeKeyWindow]; // Make self the key window + [self orderFront:sender]; // order self to the front } - (void)makeKeyWindow { - NSApplication *theApp = [NSApplication sharedApplication]; - - // Can we become the key window - if (![self canBecomeKeyWindow]) return; - - // Make the current key window resign - [[theApp keyWindow] resignKeyWindow]; - - // Make ourself become the key window - [self becomeKeyWindow]; -} - +NSApplication *theApp = [NSApplication sharedApplication]; + // Can we become the key + if (![self canBecomeKeyWindow]) // window? + return; + // ask the current key + [[theApp keyWindow] resignKeyWindow]; // window to resign status + + [self becomeKeyWindow]; // become the key window +} + - (void)makeMainWindow { - NSApplication *theApp = [NSApplication sharedApplication]; +NSApplication *theApp = [NSApplication sharedApplication]; + // Can we become the main + if (![self canBecomeMainWindow]) // window? + return; + // ask the current main + [[theApp mainWindow] resignMainWindow]; // window to resign status + + [self becomeMainWindow]; // become the main window +} - // Can we become the main window - if (![self canBecomeMainWindow]) return; - - // Make the current main window resign - [[theApp mainWindow] resignMainWindow]; - - // Make ourself become the main window - [self becomeMainWindow]; -} - -- (void)orderBack:sender -{ - visible = YES; -} - -- (void)orderFront:sender -{ - visible = YES; -} - -- (void)orderFrontRegardless -{ - visible = YES; -} - -- (void)orderOut:sender -{ - visible = NO; -} +- (void)orderBack:sender {} // implemented in back end +- (void)orderFront:sender {} +- (void)orderFrontRegardless {} +- (void)orderOut:sender {} - (void)orderWindow:(NSWindowOrderingMode)place - relativeTo:(int)otherWin -{} + relativeTo:(int)otherWin +{ +} - (void)resignKeyWindow { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; +NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - is_key = NO; - - // Discard the cursor rects - [self discardCursorRects]; - - // Post notification - [nc postNotificationName: NSWindowDidResignKeyNotification object: self]; + is_key = NO; + // Discard the cursor rects + [self discardCursorRects]; + // Post notification + [nc postNotificationName: NSWindowDidResignKeyNotification object: self]; } - (void)resignMainWindow { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; +NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - is_main = NO; - - // Post notification - [nc postNotificationName: NSWindowDidResignMainNotification object: self]; + is_main = NO; + // Post notification + [nc postNotificationName: NSWindowDidResignMainNotification object: self]; } -- (void)setHidesOnDeactivate:(BOOL)flag -{ - hides_on_deactivate = flag; -} - -- (void)setLevel:(int)newLevel -{ - window_level = newLevel; -} +- (void)setHidesOnDeactivate:(BOOL)flag { hides_on_deactivate = flag; } +- (void)setLevel:(int)newLevel { window_level = newLevel; } // // Moving and resizing the window // - (NSPoint)cascadeTopLeftFromPoint:(NSPoint)topLeftPoint { - return NSZeroPoint; + return NSZeroPoint; } - (void)center { - float w, h; - NSRect n; - - // Should use MBScreen - //w = MB_SCREEN_MAXWIDTH(); - //h = MB_SCREEN_MAXHEIGHT(); - n = frame; - n.origin.x = (w - frame.size.width) / 2; - n.origin.y = (h - frame.size.height) / 2; - [self setFrame:n display:YES]; +NSSize screenSize = [[NSScreen mainScreen] frame].size; +NSRect n = frame; // center the window + // within it's screen + n.origin.x = (screenSize.width - frame.size.width) / 2; + n.origin.y = (screenSize.height - frame.size.height) / 2; + [self setFrame:n display:YES]; } - (NSRect)constrainFrameRect:(NSRect)frameRect - toScreen:screen + toScreen:screen { - return NSZeroRect; + return NSZeroRect; } -- (NSRect)frame -{ - return frame; -} - -- (NSSize)minSize -{ - return minimum_size; -} - -- (NSSize)maxSize -{ - return maximum_size; -} - -- (void)setContentSize:(NSSize)aSize -{ -} +- (NSRect)frame { return frame; } +- (NSSize)minSize { return minimum_size; } +- (NSSize)maxSize { return maximum_size; } +- (void)setContentSize:(NSSize)aSize {} - (void)setFrame:(NSRect)frameRect display:(BOOL)flag { NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - frame = frameRect; + frame = frameRect; // post notification - [nc postNotificationName: NSWindowDidResizeNotification object: self]; + [nc postNotificationName: NSWindowDidResizeNotification object: self]; - if (flag) // display if requested - [self display]; -} - -- (void)setFrameOrigin:(NSPoint)aPoint -{ - frame.origin = aPoint; + if (flag) // display if requested + [self display]; } - (void)setFrameTopLeftPoint:(NSPoint)aPoint -{} - -- (void)setMinSize:(NSSize)aSize { - minimum_size = aSize; } -- (void)setMaxSize:(NSSize)aSize -{ - maximum_size = aSize; -} +- (void)setFrameOrigin:(NSPoint)aPoint { frame.origin = aPoint; } +- (void)setMinSize:(NSSize)aSize { minimum_size = aSize; } +- (void)setMaxSize:(NSSize)aSize { maximum_size = aSize; } // // Converting coordinates // -- (NSPoint)convertBaseToScreen:(NSPoint)aPoint +- (NSPoint)convertBaseToScreen:(NSPoint)basePoint { - return NSZeroPoint; +NSPoint screenPoint; + + screenPoint.x = frame.origin.x + basePoint.x; + screenPoint.y = frame.origin.y + basePoint.y; + + return screenPoint; } -- (NSPoint)convertScreenToBase:(NSPoint)aPoint +- (NSPoint)convertScreenToBase:(NSPoint)screenPoint { - return NSZeroPoint; -} +NSPoint basePoint; + basePoint.x = screenPoint.x - frame.origin.x; + basePoint.y = screenPoint.y - frame.origin.y; + + return basePoint; +} // // Managing the display // -- (void)disableFlushWindow -{ - disable_flush_window = YES; -} +- (void)disableFlushWindow { disable_flush_window = YES; } - (void)display { - visible = YES; - needs_display = NO; + visible = YES; + needs_display = NO; // inform first responder + // of it's status so it can + [first_responder becomeFirstResponder]; // set the focus to itself - // Tell the first responder that it is the first responder - // So it can set the focus to itself - [first_responder becomeFirstResponder]; + [self disableFlushWindow]; // tmp disable display - /* Temporary disable displaying */ - [self disableFlushWindow]; - - // Draw the window view - [[content_view superview] display]; - - /* Reenable displaying and flush the window */ - [self enableFlushWindow]; -} + [[content_view superview] display]; // Draw the window view + + [self enableFlushWindow]; // Reenable displaying and +} // flush the window - (void)displayIfNeeded { - if (needs_display) { - [[content_view superview] _displayNeededViews]; - needs_display = NO; - } + if (needs_display) + { + [[content_view superview] _displayNeededViews]; + needs_display = NO; + } } -- (void)enableFlushWindow -{ - disable_flush_window = NO; -} - -- (void)flushWindow -{ - needs_flush = NO; - [_flushRectangles removeAllObjects]; - [[content_view superview] _recursivelyResetNeedsDisplayInAllViews]; -} +- (void)enableFlushWindow { disable_flush_window = NO; } +- (void)flushWindow {} // implemented in back end - (void)flushWindowIfNeeded { - if (!disable_flush_window && needs_flush) { - needs_flush = NO; - [self flushWindow]; - } + if (!disable_flush_window && needs_flush) + { + needs_flush = NO; + [self flushWindow]; + } } - (void)_collectFlushRectangles { - PSMatrix* originMatrix; - PSMatrix* sizeMatrix; +PSMatrix* originMatrix; +PSMatrix* sizeMatrix; - if (disable_flush_window || backing_type == NSBackingStoreNonretained) - return; + if (disable_flush_window || backing_type == NSBackingStoreNonretained) + return; -// NSLog (@"_collectFlushRectangles"); - [_flushRectangles removeAllObjects]; + NSDebugLog (@"_collectFlushRectangles"); + [_flushRectangles removeAllObjects]; - originMatrix = [PSMatrix new]; - sizeMatrix = [PSMatrix new]; + originMatrix = [PSMatrix new]; + sizeMatrix = [PSMatrix new]; - [[content_view superview] - _collectInvalidatedRectanglesInArray:_flushRectangles - originMatrix:originMatrix - sizeMatrix:sizeMatrix]; + [[content_view superview] + _collectInvalidatedRectanglesInArray:_flushRectangles + originMatrix:originMatrix + sizeMatrix:sizeMatrix]; - [originMatrix release]; - [sizeMatrix release]; + [originMatrix release]; + [sizeMatrix release]; } -- (BOOL)isAutodisplay -{ - return is_autodisplay; -} - -- (BOOL)isFlushWindowDisabled -{ - return disable_flush_window; -} - -- (void)setAutodisplay:(BOOL)flag -{ - is_autodisplay = flag; -} - -- (void)setViewsNeedDisplay:(BOOL)flag -{ - views_need_display = flag; -} +- (BOOL)isAutodisplay { return is_autodisplay; } +- (BOOL)isFlushWindowDisabled { return disable_flush_window; } +- (void)setAutodisplay:(BOOL)flag { is_autodisplay = flag; } +- (void)setViewsNeedDisplay:(BOOL)flag { needs_display = flag; } - (void)update { @@ -747,123 +565,78 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc postNotificationName: NSWindowDidUpdateNotification object: self]; } -- (void)useOptimizedDrawing:(BOOL)flag -{ - optimize_drawing = flag; -} +- (void)useOptimizedDrawing:(BOOL)flag { optimize_drawing = flag; } +- (BOOL)viewsNeedDisplay { return needs_display; } -- (BOOL)viewsNeedDisplay -{ - return views_need_display; -} - -// Screens and window depths - (BOOL)canStoreColor { - // If the depth is greater than a single bit - if (depth_limit > 1) - return YES; - else - return NO; + if (depth_limit > 1) // If the depth is greater + return YES; // than a single bit + else + return NO; } -- (NSScreen *)deepestScreen -{ - return [NSScreen deepestScreen]; +- (NSScreen *)deepestScreen +{ + return [NSScreen deepestScreen]; } -- (NSWindowDepth)depthLimit -{ - return depth_limit; -} - -- (BOOL)hasDynamicDepthLimit -{ - return dynamic_depth_limit; -} - -- (NSScreen *)screen -{ - return [NSScreen mainScreen]; -} - -- (void)setDepthLimit:(NSWindowDepth)limit -{ - depth_limit = limit; -} - -- (void)setDynamicDepthLimit:(BOOL)flag -{ - dynamic_depth_limit = flag; -} +- (NSWindowDepth)depthLimit { return depth_limit; } +- (BOOL)hasDynamicDepthLimit { return dynamic_depth_limit; } +- (NSScreen *)screen { return [NSScreen mainScreen]; } +- (void)setDepthLimit:(NSWindowDepth)limit { depth_limit = limit; } +- (void)setDynamicDepthLimit:(BOOL)flag { dynamic_depth_limit = flag; } // // Cursor management // -- (BOOL)areCursorRectsEnabled -{ - return cursor_rects_enabled; -} - -- (void)disableCursorRects -{ - cursor_rects_enabled = NO; -} +- (BOOL)areCursorRectsEnabled { return cursor_rects_enabled; } +- (void)disableCursorRects { cursor_rects_enabled = NO; } - (void)discardCursorRectsForView:(NSView *)theView { - NSArray *s; - id e; - NSView *v; +NSArray *s; +id e; +NSView *v; + // Discard cursor rects + [theView discardCursorRects]; // for the view - // Discard for the view - [theView discardCursorRects]; - - // Discard for the view's subviews - s = [theView subviews]; - e = [s objectEnumerator]; - while ((v = [e nextObject])) - [self discardCursorRectsForView: v]; + s = [theView subviews]; // Discard cursor rects + e = [s objectEnumerator]; // for view's subviews + while ((v = [e nextObject])) + [self discardCursorRectsForView: v]; } - (void)discardCursorRects { - [self discardCursorRectsForView: [content_view superview]]; + [self discardCursorRectsForView: [content_view superview]]; } -- (void)enableCursorRects -{ - cursor_rects_enabled = YES; -} +- (void)enableCursorRects { cursor_rects_enabled = YES; } - (void)invalidateCursorRectsForView:(NSView *)aView { - cursor_rects_valid = NO; + cursor_rects_valid = NO; } - (void)resetCursorRectsForView:(NSView *)theView { - NSArray *s; - id e; - NSView *v; +NSArray *s; +id e; +NSView *v; + + [theView resetCursorRects]; // Reset cursor rects for view - // Reset the view - [theView resetCursorRects]; - - // Reset the view's subviews - s = [theView subviews]; - e = [s objectEnumerator]; - while ((v = [e nextObject])) - [self resetCursorRectsForView: v]; + s = [theView subviews]; // Reset cursor rects for the + e = [s objectEnumerator]; // view's subviews + while ((v = [e nextObject])) + [self resetCursorRectsForView: v]; } -- (void)resetCursorRects -{ - // Tell all the views to reset their cursor rects - [self resetCursorRectsForView: [content_view superview]]; - - // Cursor rects are now valid - cursor_rects_valid = YES; +- (void)resetCursorRects // Tell all the views to reset +{ // their cursor rects + [self resetCursorRectsForView: [content_view superview]]; + cursor_rects_valid = YES; // Cursor rects are now valid } // @@ -885,39 +658,28 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - (void)deminiaturize:sender { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; +NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + // Set ivar flag to say we + is_miniaturized = NO; // are not miniaturized + visible = YES; - // Set our flag to say we are not miniaturized - is_miniaturized = NO; - visible = YES; - - [self performDeminiaturize:self]; - - // Notify our delegate - [nc postNotificationName: NSWindowDidDeminiaturizeNotification object: self]; + [self performDeminiaturize:self]; + // Notify window's delegate + [nc postNotificationName:NSWindowDidDeminiaturizeNotification object:self]; } -- (BOOL)isDocumentEdited -{ - return is_edited; -} - -- (BOOL)isReleasedWhenClosed -{ - return is_released_when_closed; -} +- (BOOL)isDocumentEdited { return is_edited; } +- (BOOL)isReleasedWhenClosed { return is_released_when_closed; } - (void)miniaturize:sender { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; +NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + // Notify window's delegate + [nc postNotificationName:NSWindowWillMiniaturizeNotification object: self]; - // Notify our delegate - [nc postNotificationName: NSWindowWillMiniaturizeNotification object: self]; - - [self performMiniaturize:self]; - - // Notify our delegate - [nc postNotificationName: NSWindowDidMiniaturizeNotification object: self]; + [self performMiniaturize:self]; + // Notify window's delegate + [nc postNotificationName: NSWindowDidMiniaturizeNotification object: self]; } - (void)performClose:sender @@ -944,479 +706,361 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; { // self to see if it's ok NSBeep(); // to close self return; - } - } - } + } } } [self close]; // it's ok to close self } -- (void)performMiniaturize:sender -{ - // Set our flag to say we are miniaturized - is_miniaturized = YES; -} - -- (int)resizeFlags -{ - return 0; -} - -- (void)setDocumentEdited:(BOOL)flag -{ - is_edited = flag; -} - -- (void)setReleasedWhenClosed:(BOOL)flag -{ - is_released_when_closed = flag; -} +- (void)performMiniaturize:sender { is_miniaturized = YES; } - (int)resizeFlags { return 0; } +- (void)setDocumentEdited:(BOOL)flag { is_edited = flag; } +- (void)setReleasedWhenClosed:(BOOL)flag { is_released_when_closed = flag; } // // Aiding event handling // -- (BOOL)acceptsMouseMovedEvents -{ - return accepts_mouse_moved; -} +- (BOOL)acceptsMouseMovedEvents { return accepts_mouse_moved; } - (NSEvent *)currentEvent { - NSApplication *theApp = [NSApplication sharedApplication]; - - return [theApp currentEvent]; + return [[NSApplication sharedApplication] currentEvent]; } - (void)discardEventsMatchingMask:(unsigned int)mask - beforeEvent:(NSEvent *)lastEvent + beforeEvent:(NSEvent *)lastEvent { - NSApplication *theApp = [NSApplication sharedApplication]; +NSApplication *theApp = [NSApplication sharedApplication]; - [theApp discardEventsMatchingMask: mask beforeEvent: lastEvent]; + [theApp discardEventsMatchingMask:mask beforeEvent:lastEvent]; } -- (NSResponder *)firstResponder -{ - return first_responder; -} +- (NSResponder *)firstResponder { return first_responder; } -- (void)keyDown:(NSEvent *)theEvent -{ - // save the first responder so that the key up - // goes to it and not a possible new first responder - original_responder = first_responder; - - // Send the first responder the key down - [first_responder keyDown:theEvent]; -} +- (void)keyDown:(NSEvent *)theEvent // save the first responder +{ // so that the key up goes + original_responder = first_responder; // to it and not a possible + // new first responder + [first_responder keyDown:theEvent]; // Send the first responder +} // the key down - (BOOL)makeFirstResponder:(NSResponder *)aResponder { - // If already the first responder then return - if (first_responder == aResponder) - return YES; + if (first_responder == aResponder) // if responder is already + return YES; // first responder return Y - // If not a NSResponder then forget it - if (![aResponder isKindOfClass:[NSResponder class]]) - return NO; + if (![aResponder isKindOfClass:[NSResponder class]]) + return NO; // not a responder return N - // Does it accept the first responder? - if (![aResponder acceptsFirstResponder]) - return NO; + if (![aResponder acceptsFirstResponder]) // does not accept status + return NO; // of first responder ret N + // Notify current first responder that it + // should resign. If it says NO then no + // change. But make sure that there even + // is a first responder + if ((first_responder) && (![first_responder resignFirstResponder])) + return NO; + // Make responder the first + first_responder = aResponder; // responder - // Notify current first responder that it should resign - // If it says NO then no change - // But make sure that there even is a first responder - if ((first_responder) && (![first_responder resignFirstResponder])) - return NO; - - // Make it the first responder - first_responder = aResponder; - - // Notify it that it just became the first responder - [first_responder becomeFirstResponder]; - - return YES; + // Notify responder that it + [first_responder becomeFirstResponder]; // has become the first + // responder + return YES; } - (NSPoint)mouseLocationOutsideOfEventStream { - return NSZeroPoint; + return NSZeroPoint; } - (NSEvent *)nextEventMatchingMask:(unsigned int)mask { - NSApplication *theApp = [NSApplication sharedApplication]; - return [theApp nextEventMatchingMask: mask untilDate: nil - inMode:NSEventTrackingRunLoopMode dequeue: YES]; + return [[NSApplication sharedApplication] nextEventMatchingMask:mask + untilDate:nil + inMode:NSEventTrackingRunLoopMode + dequeue:YES]; } - (NSEvent *)nextEventMatchingMask:(unsigned int)mask - untilDate:(NSDate *)expiration - inMode:(NSString *)mode - dequeue:(BOOL)deqFlag + untilDate:(NSDate *)expiration + inMode:(NSString *)mode + dequeue:(BOOL)deqFlag { - NSApplication *theApp = [NSApplication sharedApplication]; - return [theApp nextEventMatchingMask: mask untilDate: expiration - inMode: mode dequeue: deqFlag]; + return [[NSApplication sharedApplication] nextEventMatchingMask:mask + untilDate:expiration + inMode:mode + dequeue:deqFlag]; } - (void)postEvent:(NSEvent *)event - atStart:(BOOL)flag + atStart:(BOOL)flag { - NSApplication *theApp = [NSApplication sharedApplication]; - - [theApp postEvent:event atStart:flag]; + [[NSApplication sharedApplication] postEvent:event atStart:flag]; } - (void)setAcceptsMouseMovedEvents:(BOOL)flag { - accepts_mouse_moved = flag; + accepts_mouse_moved = flag; } - (void)checkTrackingRectangles:(NSView *)theView forEvent:(NSEvent *)theEvent { - NSArray *tr = [theView trackingRectangles]; - NSArray *sb = [theView subviews]; - TrackingRectangle *r; - int i, j; - BOOL last, now; - NSEvent *e; +NSArray *tr = [theView trackingRectangles]; +NSArray *sb = [theView subviews]; +TrackingRectangle *r; +int i, j; +BOOL last, now; +NSEvent *e; - // Loop through tracking rectangles - j = [tr count]; - for (i = 0;i < j; ++i) - { - r = (TrackingRectangle *)[tr objectAtIndex:i]; - // Check mouse at last point - last = [theView mouse:last_point inRect:[r rectangle]]; - // Check mouse at current point - now = [theView mouse:[theEvent locationInWindow] inRect:[r rectangle]]; + j = [tr count]; // Loop through the tracking + for (i = 0;i < j; ++i) // rectangles + { + r = (TrackingRectangle *)[tr objectAtIndex:i]; + // Check mouse at last point + last = [theView mouse:last_point inRect:[r rectangle]]; + // Check mouse at current point + now = [theView mouse:[theEvent locationInWindow] inRect:[r rectangle]]; - // Mouse entered event - if ((!last) && (now)) - { - id owner = [r owner]; - e = [NSEvent enterExitEventWithType:NSMouseEntered - location:[theEvent locationInWindow] - modifierFlags:[theEvent modifierFlags] - timestamp:0 windowNumber:[theEvent windowNumber] - context:NULL eventNumber:0 - trackingNumber:[r tag] userData:[r userData]]; - // Send the event to the owner - if ([owner respondsToSelector:@selector(mouseEntered:)]) - [owner mouseEntered:e]; - } + if ((!last) && (now)) // Mouse entered event + { + id owner = [r owner]; + e = [NSEvent enterExitEventWithType:NSMouseEntered + location:[theEvent locationInWindow] + modifierFlags:[theEvent modifierFlags] + timestamp:0 + windowNumber:[theEvent windowNumber] + context:NULL eventNumber:0 + trackingNumber:[r tag] + userData:[r userData]]; + // Send the event to the owner + if ([owner respondsToSelector:@selector(mouseEntered:)]) + [owner mouseEntered:e]; + } - // Mouse exited event - if ((last) && (!now)) - { - id owner = [r owner]; - e = [NSEvent enterExitEventWithType:NSMouseExited - location:[theEvent locationInWindow] - modifierFlags:[theEvent modifierFlags] - timestamp:0 windowNumber:[theEvent windowNumber] - context:NULL eventNumber:0 - trackingNumber:[r tag] userData:[r userData]]; - // Send the event to the owner - if ([owner respondsToSelector:@selector(mouseExited:)]) - [owner mouseExited:e]; - } - } - - // Check the tracking rectangles for the subviews - j = [sb count]; - for (i = 0;i < j; ++i) - [self checkTrackingRectangles:[sb objectAtIndex:i] forEvent:theEvent]; + if ((last) && (!now)) // Mouse exited event + { + id owner = [r owner]; + e = [NSEvent enterExitEventWithType:NSMouseExited + location:[theEvent locationInWindow] + modifierFlags:[theEvent modifierFlags] + timestamp:0 + windowNumber:[theEvent windowNumber] + context:NULL + eventNumber:0 + trackingNumber:[r tag] + userData:[r userData]]; + // Send the event to the owner + if ([owner respondsToSelector:@selector(mouseExited:)]) + [owner mouseExited:e]; + } + } + + j = [sb count]; // Check tracking rectangles + for (i = 0;i < j; ++i) // for the subviews + [self checkTrackingRectangles:[sb objectAtIndex:i] forEvent:theEvent]; } - (void)checkCursorRectangles:(NSView *)theView forEvent:(NSEvent *)theEvent { - NSArray *tr = [theView cursorRectangles]; - NSArray *sb = [theView subviews]; - TrackingRectangle *r; - int i, j; - BOOL last, now; - NSEvent *e; - NSPoint loc = [theEvent locationInWindow]; - NSPoint lastPointConverted; - NSPoint locationConverted; - NSRect rect; +NSArray *tr = [theView cursorRectangles]; +NSArray *sb = [theView subviews]; +TrackingRectangle *r; +int i, j; +BOOL last, now; +NSEvent *e; +NSPoint loc = [theEvent locationInWindow]; +NSPoint lastPointConverted; +NSPoint locationConverted; +NSRect rect; + // Loop through cursor rectangles + j = [tr count]; + for (i = 0;i < j; ++i) // Convert cursor rectangle + { // to window coordinates + r = (TrackingRectangle *)[tr objectAtIndex:i]; - // Loop through cursor rectangles - j = [tr count]; - for (i = 0;i < j; ++i) - { - // Convert cursor rectangle to window coordinates - r = (TrackingRectangle *)[tr objectAtIndex:i]; - - lastPointConverted = [theView convertPoint:last_point fromView:nil]; - locationConverted = [theView convertPoint:loc fromView:nil]; - - // Check mouse at last point - rect = [r rectangle]; - last = [theView mouse:lastPointConverted inRect:rect]; - now = [theView mouse:locationConverted inRect:rect]; - - // Mouse entered - if ((!last) && (now)) - { - // Post cursor update event - e = [NSEvent enterExitEventWithType: NSCursorUpdate - location: loc - modifierFlags: [theEvent modifierFlags] - timestamp: 0 - windowNumber: [theEvent windowNumber] - context: [theEvent context] - eventNumber: 0 - trackingNumber: (int)YES - userData: (void *)r]; - [self postEvent: e atStart: YES]; - } - - // Mouse exited event - if ((last) && (!now)) - { - // Post cursor update event - e = [NSEvent enterExitEventWithType: NSCursorUpdate - location: loc - modifierFlags: [theEvent modifierFlags] - timestamp: 0 - windowNumber: [theEvent windowNumber] - context: [theEvent context] - eventNumber: 0 - trackingNumber: (int)NO - userData: (void *)r]; - [self postEvent: e atStart: YES]; - } - } - - // Check the cursor rectangles for the subviews - j = [sb count]; - for (i = 0;i < j; ++i) - [self checkCursorRectangles:[sb objectAtIndex:i] forEvent:theEvent]; + lastPointConverted = [theView convertPoint:last_point fromView:nil]; + locationConverted = [theView convertPoint:loc fromView:nil]; + + rect = [r rectangle]; // Check mouse's last point + last = [theView mouse:lastPointConverted inRect:rect]; + now = [theView mouse:locationConverted inRect:rect]; + // Mouse entered + if ((!last) && (now)) + { // Post cursor update event + e = [NSEvent enterExitEventWithType: NSCursorUpdate + location: loc + modifierFlags: [theEvent modifierFlags] + timestamp: 0 + windowNumber: [theEvent windowNumber] + context: [theEvent context] + eventNumber: 0 + trackingNumber: (int)YES + userData: (void *)r]; + [self postEvent: e atStart: YES]; + } + // Mouse exited + if ((last) && (!now)) + { // Post cursor update event + e = [NSEvent enterExitEventWithType: NSCursorUpdate + location: loc + modifierFlags: [theEvent modifierFlags] + timestamp: 0 + windowNumber: [theEvent windowNumber] + context: [theEvent context] + eventNumber: 0 + trackingNumber: (int)NO + userData: (void *)r]; + [self postEvent: e atStart: YES]; + } + } + // Check cursor rectangles + j = [sb count]; // for the subviews + for (i = 0;i < j; ++i) + [self checkCursorRectangles:[sb objectAtIndex:i] forEvent:theEvent]; } - (void)sendEvent:(NSEvent *)theEvent { - // If the cursor rects are invalid - // Then discard and reset - if (!cursor_rects_valid) - { - [self discardCursorRects]; - [self resetCursorRects]; - } +NSView *v; - switch ([theEvent type]) - { - // - // Mouse events - // - // - // Left mouse down - // - case NSLeftMouseDown: - { - NSView *v = [content_view hitTest:[theEvent locationInWindow]]; - NSDebugLog([v description]); - NSDebugLog(@"\n"); - [v mouseDown:theEvent]; - last_point = [theEvent locationInWindow]; - break; - } - // - // Left mouse up - // - case NSLeftMouseUp: - { - NSView *v = [content_view hitTest:[theEvent locationInWindow]]; - [v mouseUp:theEvent]; - last_point = [theEvent locationInWindow]; - break; - } - // - // Right mouse down - // - case NSRightMouseDown: - { - NSView *v = [content_view hitTest:[theEvent locationInWindow]]; - [v rightMouseDown:theEvent]; - last_point = [theEvent locationInWindow]; - break; - } - // - // Right mouse up - // - case NSRightMouseUp: - { - NSView *v = [content_view hitTest:[theEvent locationInWindow]]; - [v rightMouseUp:theEvent]; - last_point = [theEvent locationInWindow]; - break; - } - // - // Mouse moved - // - case NSMouseMoved: - { - NSView *v = [content_view hitTest:[theEvent locationInWindow]]; + if (!cursor_rects_valid) // If the cursor rects are invalid + { // Then discard and reset + [self discardCursorRects]; + [self resetCursorRects]; + } - // First send the NSMouseMoved event - [v mouseMoved:theEvent]; + switch ([theEvent type]) + { + case NSLeftMouseDown: // Left mouse down + v = [content_view hitTest:[theEvent locationInWindow]]; + NSDebugLog([v description]); + NSDebugLog(@"\n"); + [v mouseDown:theEvent]; + last_point = [theEvent locationInWindow]; + break; - // We need to go through all of the views, and any with - // a tracking rectangle then we need to determine if we - // should send a NSMouseEntered or NSMouseExited event - [self checkTrackingRectangles:content_view forEvent:theEvent]; + case NSLeftMouseUp: // Left mouse up + v = [content_view hitTest:[theEvent locationInWindow]]; + [v mouseUp:theEvent]; + last_point = [theEvent locationInWindow]; + break; - // We need to go through all of the views, and any with - // a cursor rectangle then we need to determine if we - // should send a cursor update event - // We only do this if we are the key window - if ([self isKeyWindow]) - [self checkCursorRectangles: content_view forEvent: theEvent]; + case NSRightMouseDown: // Right mouse down + v = [content_view hitTest:[theEvent locationInWindow]]; + [v rightMouseDown:theEvent]; + last_point = [theEvent locationInWindow]; + break; - last_point = [theEvent locationInWindow]; - break; - } - // - // Left mouse dragged - // - case NSLeftMouseDragged: - { - last_point = [theEvent locationInWindow]; - break; - } - // - // Right mouse dragged - // - case NSRightMouseDragged: - { - last_point = [theEvent locationInWindow]; - break; - } - // - // Mouse entered - // - case NSMouseEntered: - { - break; - } - // - // Mouse exited - // - case NSMouseExited: - { - break; - } + case NSRightMouseUp: // Right mouse up + v = [content_view hitTest:[theEvent locationInWindow]]; + [v rightMouseUp:theEvent]; + last_point = [theEvent locationInWindow]; + break; - // - // Keyboard events - // - // - // Key down - // - case NSKeyDown: - { - [self keyDown:theEvent]; - break; - } - // - // Key up - // - case NSKeyUp: - { - // send message to object that got the key down - if (original_responder) - [original_responder keyUp:theEvent]; - break; - } + case NSMouseMoved: // Mouse moved + v = [content_view hitTest:[theEvent locationInWindow]]; + [v mouseMoved:theEvent]; // First send the NSMouseMoved event + // We need to go through all of the views, and any with + // a tracking rectangle then we need to determine if we + // should send a NSMouseEntered or NSMouseExited event + [self checkTrackingRectangles:content_view forEvent:theEvent]; + // We need to go through all of the views, and any with + // a cursor rectangle then we need to determine if we + // should send a cursor update event + // We only do this if we are the key window + if (is_key) + [self checkCursorRectangles: content_view forEvent: theEvent]; - // - // Miscellaneous events - // - // - // Flags changed - // - case NSFlagsChanged: - { - break; - } - // - // Cursor update - // - case NSCursorUpdate: - { - // Is it a mouse entered - if ([theEvent trackingNumber]) - { - // push the cursor - TrackingRectangle *r = (TrackingRectangle *)[theEvent userData]; - NSCursor *c = (NSCursor *)[r owner]; - [c push]; - } - else - { - // it is a mouse exited - // so pop the cursor - [NSCursor pop]; - } - break; - } - case NSPeriodic: - { - break; - } - } + last_point = [theEvent locationInWindow]; + break; - [NSWindow _flushWindows]; + case NSLeftMouseDragged: // Left mouse dragged + last_point = [theEvent locationInWindow]; + break; + + case NSRightMouseDragged: // Right mouse dragged + last_point = [theEvent locationInWindow]; + break; + + case NSMouseEntered: // Mouse entered + case NSMouseExited: // Mouse exited + break; + + case NSKeyDown: // Key down + [self keyDown:theEvent]; + break; + + case NSKeyUp: // Key up + if (original_responder) // send message to the + [original_responder keyUp:theEvent]; // object that got the + break; // key down + + case NSFlagsChanged: // Flags changed + break; + + case NSCursorUpdate: // Cursor update + if ([theEvent trackingNumber]) // if it's a mouse entered + { // push the cursor + TrackingRectangle *r =(TrackingRectangle *)[theEvent userData]; + NSCursor *c = (NSCursor *)[r owner]; + [c push]; + } // it is a mouse exited + else // so pop the cursor + [NSCursor pop]; + break; + + case NSPeriodic: + break; + } } - (BOOL)tryToPerform:(SEL)anAction with:anObject { - return ([super tryToPerform:anAction with:anObject]); + return ([super tryToPerform:anAction with:anObject]); } - (BOOL)worksWhenModal { - return NO; + return NO; } // // Dragging // - (void)dragImage:(NSImage *)anImage - at:(NSPoint)baseLocation - offset:(NSSize)initialOffset - event:(NSEvent *)event - pasteboard:(NSPasteboard *)pboard - source:sourceObject - slideBack:(BOOL)slideFlag -{} + at:(NSPoint)baseLocation + offset:(NSSize)initialOffset + event:(NSEvent *)event + pasteboard:(NSPasteboard *)pboard + source:sourceObject + slideBack:(BOOL)slideFlag +{ +} - (void)registerForDraggedTypes:(NSArray *)newTypes -{} +{ +} - (void)unregisterDraggedTypes -{} +{ +} // // Services and windows menu support // - (BOOL)isExcludedFromWindowsMenu { - return menu_exclude; + return menu_exclude; } - (void)setExcludedFromWindowsMenu:(BOOL)flag { - menu_exclude = flag; + menu_exclude = flag; } - validRequestorForSendType:(NSString *)sendType - returnType:(NSString *)returnType + returnType:(NSString *)returnType { - return nil; + return nil; } // @@ -1424,81 +1068,69 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; // - (NSString *)frameAutosaveName { - return nil; + return nil; } - (void)saveFrameUsingName:(NSString *)name -{} +{ +} - (BOOL)setFrameAutosaveName:(NSString *)name { - return NO; + return NO; } - (void)setFrameFromString:(NSString *)string -{} - -- (BOOL)setFrameUsingName:(NSString *)name { - return NO; } -- (NSString *)stringWithSavedFrame +- (BOOL)setFrameUsingName:(NSString *)name { - return nil; + return NO; +} + +- (NSString *)stringWithSavedFrame +{ + return nil; } // // Printing and postscript // -- (NSData *)dataWithEPSInsideRect:(NSRect)rect -{ - return nil; -} - -- (void)fax:sender -{} - -- (void)print:sender -{} +- (NSData *)dataWithEPSInsideRect:(NSRect)rect { return nil; } +- (void)fax:sender {} +- (void)print:sender {} // // Assigning a delegate // -- delegate -{ - return delegate; -} - -- (void)setDelegate:anObject -{ - delegate = anObject; -} +- delegate { return delegate; } +- (void)setDelegate:anObject { delegate = anObject; } // // Implemented by the delegate // - (BOOL)windowShouldClose:sender { - if ([delegate respondsToSelector:@selector(windowShouldClose:)]) - return [delegate windowShouldClose:sender]; - else - return YES; + if ([delegate respondsToSelector:@selector(windowShouldClose:)]) + return [delegate windowShouldClose:sender]; + else + return YES; } - (NSSize)windowWillResize:(NSWindow *)sender - toSize:(NSSize)frameSize + toSize:(NSSize)frameSize { - if ([delegate respondsToSelector:@selector(windowWillResize:toSize:)]) - return [delegate windowWillResize:sender toSize:frameSize]; - else - return frameSize; + if ([delegate respondsToSelector:@selector(windowWillResize:toSize:)]) + return [delegate windowWillResize:sender toSize:frameSize]; + else + return frameSize; } - windowWillReturnFieldEditor:(NSWindow *)sender - toObject:client + toObject:client { - return nil; + return nil; } - (void)windowDidBecomeKey:(NSNotification *)aNotification @@ -1585,67 +1217,6 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; return [delegate windowWillMove:aNotification]; } -- (void)_setNeedsFlush -{ -// NSLog (@"NSWindow _setNeedsFlush"); - needs_flush = YES; - _needsFlushWindows = YES; -} - -- (void)_view:(NSView*)view needsFlushInRect:(NSRect)rect -{ - [self _setNeedsFlush]; - - /* Convert the rectangle to the window coordinates */ - rect = [view convertRect:rect toView:nil]; - - /* If the view is rotated then compute the bounding box of the rectangle in - the window's coordinates */ - if ([view isRotatedFromBase]) - rect = [view _boundingRectFor:rect]; - - /* TODO: Optimize adding rect to the already existing arrays */ - - [_flushRectangles addObject:[NSValue valueWithRect:rect]]; -} - -- (void)_setNeedsDisplay -{ -// NSLog (@"NSWindow setNeedsDisplay"); - needs_display = YES; - [self _setNeedsFlush]; -} - -- (BOOL)_needsFlush { return needs_flush; } - -+ (BOOL)_flushWindows -{ - int i, count; - NSArray* windowList; - - if (!_needsFlushWindows) - return NO; - -// NSLog (@"_flushWindows"); - - windowList = [[NSApplication sharedApplication] windows]; - - for (i = 0, count = [windowList count]; i < count; i++) - { - NSWindow* window = [windowList objectAtIndex:i]; - - if (window->needs_display || window->needs_flush) - { - [window _collectFlushRectangles]; - [window displayIfNeeded]; - [window flushWindowIfNeeded]; - } - } - - _needsFlushWindows = NO; - return YES; -} - // // NSCoding protocol // @@ -1758,79 +1329,58 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + (NSWindow*)windowWithNumber:(int)windowNumber { - return nil; + return nil; } // // Mouse capture/release // -- (void)captureMouse: sender -{ - // Do nothing, should be overridden by back-end -} +- (void)captureMouse: sender {} // Do nothing, should be +- (void)releaseMouse: sender {} // implemented by back-end +- (void)performDeminiaturize:sender {} +- (void)performHide:sender {} +- (void)performUnhide:sender {} + +- (void)initDefaults // Allow subclasses to init +{ // without the backend + first_responder = nil; // class attempting to + original_responder = nil; // create an actual window + delegate = nil; + window_num = 0; + background_color = [[NSColor lightGrayColor] retain]; + represented_filename = @"Window"; + miniaturized_title = @"Window"; + miniaturized_image = nil; + window_title = @"Window"; + last_point = NSZeroPoint; + window_level = NSNormalWindowLevel; -- (void)releaseMouse: sender -{ - // Do nothing, should be overridden by back-end -} - -// Allow subclasses to init without the backend class -// attempting to create an actual window -- (void)initDefaults -{ - first_responder = nil; - original_responder = nil; - delegate = nil; - window_num = 0; - background_color = [[NSColor lightGrayColor] retain]; - represented_filename = @"Window"; - miniaturized_title = @"Window"; - miniaturized_image = nil; - window_title = @"Window"; - last_point = NSZeroPoint; - window_level = NSNormalWindowLevel; - - is_one_shot = NO; - needs_display = NO; - is_autodisplay = YES; - optimize_drawing = YES; - views_need_display = NO; - depth_limit = 8; - dynamic_depth_limit = YES; - cursor_rects_enabled = NO; - visible = NO; - is_key = NO; - is_main = NO; - is_edited = NO; - is_released_when_closed = NO; - is_miniaturized = NO; - disable_flush_window = NO; - menu_exclude = NO; - hides_on_deactivate = NO; - accepts_mouse_moved = YES; + is_one_shot = NO; + needs_display = NO; + is_autodisplay = YES; + optimize_drawing = YES; + views_need_display = NO; + depth_limit = 8; + dynamic_depth_limit = YES; + cursor_rects_enabled = NO; + visible = NO; + is_key = NO; + is_main = NO; + is_edited = NO; + is_released_when_closed = NO; + is_miniaturized = NO; + disable_flush_window = NO; + menu_exclude = NO; + hides_on_deactivate = NO; + accepts_mouse_moved = YES; } - cleanInit { - [super init]; - - [self initDefaults]; - return self; -} - -- (void)performDeminiaturize:sender -{ - // Do nothing, should be overridden by back-end -} - -- (void)performHide:sender -{ - // Do nothing, should be overridden by back-end -} - -- (void)performUnhide:sender -{ - // Do nothing, should be overridden by back-end + [super init]; + + [self initDefaults]; + return self; } @end