- 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:
Lyndon Tremblay 2000-09-26 11:45:32 +00:00
parent 5f2683a975
commit 35e02eb955
3 changed files with 99 additions and 55 deletions

View file

@ -1,7 +1,34 @@
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
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
with MacOS X [apparently].

View file

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

View file

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