- Various very small optimizations.

- Tells the user about unhandled exceptions.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@7605 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
humasect 2000-09-26 11:45:32 +00:00
parent c3ed7f5004
commit bbcdf8dd1a
3 changed files with 99 additions and 55 deletions

View file

@ -1,7 +1,34 @@
2000-09-26 Lyndon Tremblay <humasect@home.com> 2000-09-26 Lyndon Tremblay <humasect@home.com>
* Source/NSMenu.m ([NSMenu -itemWithTitle:]): Use -isEqualToString:
instead of -isEqual:
([NSMenu -performKeyEquivalent:]): Likewise.
([NSMenu -performActionForItemAtIndex:]): Use NSApp instead
of sharedApplication.
([NSMenu -display]): Avoids calling NSMakePoint()
([NSMenu -displayTransient]): Cache contentView.
([NSMenu -closeTransient]): Likewise.
* Source/NSApplication.m ([NSAppIconView -mouseDown:]): Use
NSApp instead of [NSApplication sharedApplication].
([NSApplication -init]): Avoid variables getting set twice.
([NSApplication -sendEvent:]): Cache NSEvent type.
* Source/NSMenu.m ([NSMenu -initWithTitle:]): Also removed
a bunch of message calls. Also removed variables getting set
twice.
([NSMenu -insertItemWithTitle:action:keyEquivalent:atIndex:]):
Message cleanup.
* Source/NSApplication.m ([NSApplication +initialize]): Override * Source/NSApplication.m ([NSApplication +initialize]): Override
Foundation's uncaught exception handler. Foundation's uncaught exception handler.
([NSApplication -init]): Save a few objc message calls.
([NSApplication -run]): Likewise. Also cache [NSDate distantFuture].
Also using GC macros.
([NSApplication -runModalSession:]): Also save message calls,
and GC support. Also eliminates creating an ARP each loop,
only once.
* Headers/AppKit/NSPanel.h (NSAlert*): #defines to comply * Headers/AppKit/NSPanel.h (NSAlert*): #defines to comply
with MacOS X [apparently]. with MacOS X [apparently].

View file

@ -197,7 +197,6 @@ static NSCell* tileCell = nil;
unsigned eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask unsigned eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
| NSPeriodicMask | NSMiddleMouseUpMask | NSRightMouseUpMask; | NSPeriodicMask | NSMiddleMouseUpMask | NSRightMouseUpMask;
NSDate *theDistantFuture = [NSDate distantFuture]; NSDate *theDistantFuture = [NSDate distantFuture];
NSApplication *theApp = [NSApplication sharedApplication];
BOOL done = NO; BOOL done = NO;
lastLocation = [theEvent locationInWindow]; lastLocation = [theEvent locationInWindow];
@ -205,7 +204,7 @@ static NSCell* tileCell = nil;
while (!done) while (!done)
{ {
theEvent = [theApp nextEventMatchingMask: eventMask theEvent = [NSApp nextEventMatchingMask: eventMask
untilDate: theDistantFuture untilDate: theDistantFuture
inMode: NSEventTrackingRunLoopMode inMode: NSEventTrackingRunLoopMode
dequeue: YES]; dequeue: YES];
@ -559,18 +558,20 @@ static NSCell* tileCell = nil;
NSDebugLog(@"Begin of NSApplication -init\n"); NSDebugLog(@"Begin of NSApplication -init\n");
_hidden = [NSMutableArray new]; _hidden = [[NSMutableArray alloc] init];
_inactive = [NSMutableArray new]; _inactive = [[NSMutableArray alloc] init];
unhide_on_activation = YES; unhide_on_activation = YES;
app_is_hidden = YES; app_is_hidden = YES;
app_is_active = NO; //app_is_active = NO;
listener = [GSServicesManager newWithApplication: self]; listener = [GSServicesManager newWithApplication: self];
main_menu = nil; //main_menu = nil;
windows_need_update = YES; windows_need_update = YES;
current_event = [NSEvent new]; // no current event /* We shouldn't be so generous, NSEvent doesn't use -init */
null_event = [NSEvent new]; // create dummy event
current_event = [NSEvent alloc]; // no current event
null_event = [NSEvent alloc]; // create dummy event
/* We are the end of responder chain */ /* We are the end of responder chain */
[self setNextResponder: nil]; [self setNextResponder: nil];
@ -880,12 +881,14 @@ static NSCell* tileCell = nil;
- (void) run - (void) run
{ {
NSEvent *e; NSEvent *e;
Class arpClass = [NSAutoreleasePool class]; /* Cache the class */ //Class arpClass = [NSAutoreleasePool class]; /* Cache the class */
NSAutoreleasePool* pool; NSAutoreleasePool *pool = nil;
id distantFuture = [NSDate distantFuture]; /* Cache this, safe */
NSDebugLog(@"NSApplication -run\n"); NSDebugLog(@"NSApplication -run\n");
pool = [arpClass new]; RECREATE_AUTORELEASE_POOL(pool);
/* /*
* Set this flag here in case the application is actually terminated * Set this flag here in case the application is actually terminated
* inside -finishLaunching. * inside -finishLaunching.
@ -899,13 +902,14 @@ static NSCell* tileCell = nil;
[listener updateServicesMenu]; [listener updateServicesMenu];
[main_menu update]; [main_menu update];
RELEASE(pool); DESTROY(pool);
while (app_should_quit == NO) while (app_should_quit == NO)
{ {
pool = [arpClass new]; RECREATE_AUTORELEASE_POOL(pool);
e = [self nextEventMatchingMask: NSAnyEventMask e = [self nextEventMatchingMask: NSAnyEventMask
untilDate: [NSDate distantFuture] untilDate: distantFuture
inMode: NSDefaultRunLoopMode inMode: NSDefaultRunLoopMode
dequeue: YES]; dequeue: YES];
if (e != nil) if (e != nil)
@ -928,7 +932,7 @@ static NSCell* tileCell = nil;
[self updateWindows]; [self updateWindows];
} }
RELEASE(pool); DESTROY(pool);
} }
[GSCurrentContext() destroyContext]; [GSCurrentContext() destroyContext];
@ -1065,11 +1069,12 @@ static NSCell* tileCell = nil;
- (int) runModalSession: (NSModalSession)theSession - (int) runModalSession: (NSModalSession)theSession
{ {
NSAutoreleasePool *pool; NSAutoreleasePool *pool = nil;
NSGraphicsContext *ctxt; NSGraphicsContext *ctxt;
BOOL found = NO; BOOL found = NO;
NSEvent *event; NSEvent *event;
NSDate *limit; NSDate *limit;
if (theSession != session) if (theSession != session)
{ {
@ -1077,7 +1082,7 @@ static NSCell* tileCell = nil;
format: @"runModalSession: with wrong session"]; format: @"runModalSession: with wrong session"];
} }
pool = [NSAutoreleasePool new]; RECREATE_AUTORELEASE_POOL(pool);
[theSession->window orderFrontRegardless]; [theSession->window orderFrontRegardless];
if ([theSession->window canBecomeKeyWindow] == YES) if ([theSession->window canBecomeKeyWindow] == YES)
@ -1113,14 +1118,14 @@ static NSCell* tileCell = nil;
} }
while (found == NO && theSession->runState == NSRunContinuesResponse); while (found == NO && theSession->runState == NSRunContinuesResponse);
RELEASE(pool);
/* /*
* Deal with the events in the queue. * Deal with the events in the queue.
*/ */
DESTROY(pool);
RECREATE_AUTORELEASE_POOL(pool);
while (found == YES && theSession->runState == NSRunContinuesResponse) while (found == YES && theSession->runState == NSRunContinuesResponse)
{ {
pool = [NSAutoreleasePool new];
event = DPSGetEvent(ctxt, NSAnyEventMask, limit, NSDefaultRunLoopMode); event = DPSGetEvent(ctxt, NSAnyEventMask, limit, NSDefaultRunLoopMode);
if (event != nil) if (event != nil)
{ {
@ -1157,10 +1162,10 @@ static NSCell* tileCell = nil;
[self updateWindows]; [self updateWindows];
} }
} }
RELEASE(pool);
} }
NSAssert(session == theSession, @"Session was changed while running"); NSAssert(session == theSession, @"Session was changed while running");
RELEASE(pool);
return theSession->runState; return theSession->runState;
} }
@ -1206,13 +1211,17 @@ static NSCell* tileCell = nil;
*/ */
- (void) sendEvent: (NSEvent *)theEvent - (void) sendEvent: (NSEvent *)theEvent
{ {
NSEventType type;
if (theEvent == null_event) if (theEvent == null_event)
{ {
NSDebugLLog(@"NSEvent", @"Not sending the Null Event\n"); NSDebugLLog(@"NSEvent", @"Not sending the Null Event\n");
return; return;
} }
switch ([theEvent type]) type = [theEvent type];
switch (type)
{ {
case NSPeriodic: /* NSApplication traps the periodic events */ case NSPeriodic: /* NSApplication traps the periodic events */
break; break;
@ -1252,12 +1261,12 @@ static NSCell* tileCell = nil;
if (!theEvent) if (!theEvent)
NSDebugLLog(@"NSEvent", @"NSEvent is nil!\n"); NSDebugLLog(@"NSEvent", @"NSEvent is nil!\n");
NSDebugLLog(@"NSEvent", @"NSEvent type: %d", [theEvent type]); NSDebugLLog(@"NSEvent", @"NSEvent type: %d", type);
NSDebugLLog(@"NSEvent", @"send event to window"); NSDebugLLog(@"NSEvent", @"send event to window");
NSDebugLLog(@"NSEvent", [window description]); NSDebugLLog(@"NSEvent", [window description]);
if (window) if (window)
[window sendEvent: theEvent]; [window sendEvent: theEvent];
else if ([theEvent type] == NSRightMouseDown) else if (type == NSRightMouseDown)
[self rightMouseDown: theEvent]; [self rightMouseDown: theEvent];
else else
NSDebugLLog(@"NSEvent", @"no window"); NSDebugLLog(@"NSEvent", @"no window");

View file

@ -158,8 +158,8 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
- (id) initWithTitle: (NSString*)aTitle - (id) initWithTitle: (NSString*)aTitle
{ {
NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter];
NSRect winRect = {{0,0},{20,23}}; NSRect winRect = {{0,0},{20,23}};
NSView *contentView;
[super init]; [super init];
@ -167,7 +167,7 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
ASSIGN(menu_title, aTitle); ASSIGN(menu_title, aTitle);
// Create an array to store out menu items. // Create an array to store out menu items.
menu_items = [NSMutableArray new]; menu_items = [[NSMutableArray alloc] init];
// Create a NSMenuView to draw our menu items. // Create a NSMenuView to draw our menu items.
menu_view = [[NSMenuView alloc] initWithFrame: NSMakeRect(0,0,50,50)]; menu_view = [[NSMenuView alloc] initWithFrame: NSMakeRect(0,0,50,50)];
@ -176,34 +176,38 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
[menu_view setMenu: self]; [menu_view setMenu: self];
// We have no supermenu. // We have no supermenu.
menu_supermenu = nil; // menu_supermenu = nil;
menu_is_tornoff = NO; // menu_is_tornoff = NO;
menu_is_visible = NO; // menu_is_visible = NO;
menu_follow_transient = NO; // menu_follow_transient = NO;
// menu_is_beholdenToPopUpButton = NO;
menu_changedMessagesEnabled = YES; menu_changedMessagesEnabled = YES;
menu_notifications = [NSMutableArray new]; menu_notifications = [[NSMutableArray alloc] init];
menu_is_beholdenToPopUpButton = NO;
menu_changed = YES; menu_changed = YES;
// According to the spec, menus do autoenable by default. // According to the spec, menus do autoenable by default.
menu_autoenable = YES; menu_autoenable = YES;
// Transient windows private stuff. // Transient windows private stuff.
_oldAttachedMenu = nil; // _oldAttachedMenu = nil;
// Create the windows that will display the menu. // Create the windows that will display the menu.
aWindow = [[NSMenuWindow alloc] init]; aWindow = [[NSMenuWindow alloc] init];
bWindow = [[NSMenuWindow alloc] init]; bWindow = [[NSMenuWindow alloc] init];
titleView = [NSMenuWindowTitleView new]; titleView = [[NSMenuWindowTitleView alloc] init];
[titleView setFrameOrigin: NSMakePoint(0, winRect.size.height - 23)]; [titleView setFrameOrigin: NSMakePoint(0, winRect.size.height - 23)];
[titleView setFrameSize: NSMakeSize (winRect.size.width, 23)]; [titleView setFrameSize: NSMakeSize (winRect.size.width, 23)];
[[aWindow contentView] addSubview: menu_view];
[[aWindow contentView] addSubview: titleView]; contentView = [aWindow contentView];
[contentView addSubview: menu_view];
[contentView addSubview: titleView];
[titleView setMenu: self]; [titleView setMenu: self];
// Set up the notification to start the process of redisplaying // Set up the notification to start the process of redisplaying
// the menus where the user left them the last time. // the menus where the user left them the last time.
[theCenter addObserver: self [[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(_showTornOffMenuIfAny:) selector: @selector(_showTornOffMenuIfAny:)
name: NSApplicationWillFinishLaunchingNotification name: NSApplicationWillFinishLaunchingNotification
object: NSApp]; object: NSApp];
@ -268,7 +272,7 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
keyEquivalent: (NSString*)charCode keyEquivalent: (NSString*)charCode
atIndex: (unsigned int)index atIndex: (unsigned int)index
{ {
id anItem = [NSMenuItem new]; id anItem = [[NSMenuItem alloc] init];
[anItem setTitle: aString]; [anItem setTitle: aString];
[anItem setAction: aSelector]; [anItem setAction: aSelector];
@ -389,7 +393,7 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
{ {
id menuItem = [menu_items objectAtIndex: i]; id menuItem = [menu_items objectAtIndex: i];
if ([[menuItem title] isEqual: aString]) if ([[menuItem title] isEqualToString: aString])
return menuItem; return menuItem;
} }
return nil; return nil;
@ -552,14 +556,14 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
if (![self isFollowTransient]) if (![self isFollowTransient])
{ {
frame = [aWindow frame];
win_link = aWindow; win_link = aWindow;
} }
else else
{ {
frame = [bWindow frame];
win_link = bWindow; win_link = bWindow;
} }
frame = [win_link frame];
if (aSubmenu) if (aSubmenu)
{ {
@ -711,7 +715,7 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
} }
else else
{ {
if ([[item keyEquivalent] isEqual: if ([[item keyEquivalent] isEqualToString:
[theEvent charactersIgnoringModifiers]]) [theEvent charactersIgnoringModifiers]])
{ {
[menu_view performActionWithHighlightingForItemAtIndex: i]; [menu_view performActionWithHighlightingForItemAtIndex: i];
@ -742,7 +746,7 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
userInfo: d]; userInfo: d];
if ([item action]) if ([item action])
{ {
[[NSApplication sharedApplication] sendAction: [item action] [NSApp sendAction: [item action]
to: [item target] to: [item target]
from: item]; from: item];
} }
@ -1054,11 +1058,11 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
} }
else else
{ {
float aPoint = [[NSScreen mainScreen] frame].size.height NSPoint aPoint = {0, [[NSScreen mainScreen] frame].size.height
- [aWindow frame].size.height; - [aWindow frame].size.height};
[aWindow setFrameOrigin: NSMakePoint(0,aPoint)]; [aWindow setFrameOrigin: aPoint];
[bWindow setFrameOrigin: NSMakePoint(0,aPoint)]; [bWindow setFrameOrigin: aPoint];
} }
} }
} }
@ -1079,6 +1083,7 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
- (void) displayTransient - (void) displayTransient
{ {
NSPoint location; NSPoint location;
NSView *contentView;
menu_follow_transient = YES; menu_follow_transient = YES;
@ -1112,8 +1117,9 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
if (menu_is_tornoff) if (menu_is_tornoff)
[titleView _releaseCloseButton]; [titleView _releaseCloseButton];
[[bWindow contentView] addSubview: menu_view]; contentView = [bWindow contentView];
[[bWindow contentView] addSubview: titleView]; [contentView addSubview: menu_view];
[contentView addSubview: titleView];
[bWindow orderFront: self]; [bWindow orderFront: self];
@ -1143,18 +1149,20 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
- (void) closeTransient - (void) closeTransient
{ {
NSView *contentView;
[bWindow orderOut: self]; [bWindow orderOut: self];
[menu_view removeFromSuperviewWithoutNeedingDisplay]; [menu_view removeFromSuperviewWithoutNeedingDisplay];
[titleView removeFromSuperviewWithoutNeedingDisplay]; [titleView removeFromSuperviewWithoutNeedingDisplay];
[[aWindow contentView] addSubview: menu_view]; contentView = [aWindow contentView];
[contentView addSubview: menu_view];
if (menu_is_tornoff) if (menu_is_tornoff)
[titleView _addCloseButton]; [titleView _addCloseButton];
[[aWindow contentView] addSubview: titleView]; [contentView addSubview: titleView];
[contentView setNeedsDisplay: YES];
[[aWindow contentView] setNeedsDisplay: YES];
// Restore the old submenu (if any). // Restore the old submenu (if any).
if (menu_supermenu != nil) if (menu_supermenu != nil)
@ -1367,9 +1375,9 @@ static NSString *NSMenuLocationsKey = @"NSMenuLocations";
// Draw the title. // Draw the title.
[[NSColor windowFrameTextColor] set]; [[NSColor windowFrameTextColor] set];
[[NSFont boldSystemFontOfSize: 0] set]; [[NSFont boldSystemFontOfSize: 0] set];
PSmoveto(rect.origin.x + 7, rect.origin.y + 7); PSmoveto(rect.origin.x + 7, rect.origin.y + 7);
PSshow([[menu title] cString]); PSshow([[menu title] cString]);
} }
- (void) mouseDown: (NSEvent*)theEvent - (void) mouseDown: (NSEvent*)theEvent