diff --git a/ChangeLog b/ChangeLog index cde37c054..1a6f5eb7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,70 @@ +Sun Aug 30 1998 Felipe A. Rodriguez + + * NSApplication.h added windows_need_update as autodisplay ivar. + * NSApplication.m in init set default for main_menu, windows_need_update. + * NSApplication.m in run added support for OPENSTEP autodisplay mechanism. + * NSApplication.m _eventMatchingMask: reformat. + * NSApplication.m nextEventMatchingMask:untilDate:inMode:dequeue: + move calls to _flushWindows to XDPS backend. + * NSApplication.m implemented updateWindows. + * NSApplication.m implemented setWindowsNeedUpdate:. + * NSApplication.m setMainMenu: test for menu prior to release. + * NSActionCell.m removed setState: method. + * NSActionCell.m copyWithZone: optimized ivar copying. + * NSButtonCell.m added _init and moved common defaults to this method. + * NSButtonCell.m initImageCell: and initTextCell: minor optimizations. + * NSButtonCell.m setAlternateTitle: optimize and use ASSIGN macro. + * NSButtonCell.m setKeyEquivalent: remove [copy release]. + * NSButtonCell.m setKeyEquivalentFont:size: optimize. + * NSButtonCell.m copyWithZone: optimized ivar copying where possible. + * NSCell.m _init removed call to [super init]. + * NSCell.m initTextCell: removed duplicate default initializers. + * NSCell.m setImage: rewrote to use ASSIGN macro. + * NSCell.m setDoubleValue: rewrote to use ASSIGN macro. + * NSCell.m setFloatValue: rewrote to use ASSIGN macro. + * NSCell.m setIntValue: rewrote to use ASSIGN macro. + * NSCell.m setStringValue: rewrote to use ASSIGN macro. + * NSCell.m setFont: rewrote to use ASSIGN macro. + * NSCell.m setRepresentedObject: rewrote to use ASSIGN macro. + * NSCell.m copyWithZone: optimized ivar copying where possible. + * NSClipView.m viewBoundsChanged: minor optimization. + * NSClipView.m viewFrameChanged: minor optimization. + * NSClipView.m scaleUnitSquareToSize: minor optimization. + * NSClipView.m setBoundsOrigin: minor optimization. + * NSClipView.m setBoundsSize: minor optimization. + * NSClipView.m setFrameSize: minor optimization. + * NSClipView.m setFrameOrigin: minor optimization. + * NSClipView.m setFrame: minor optimization. + * NSClipView.m translateOriginToPoint: minor optimization. + * NSMatrix.m eliminate retain/release of selected cell via ASSIGN. + * NSMatrix.m initWithFrame: remove duplicate setting of selected row and + column. + * NSMatrix.m removeColumn: rewrite so that col is removed before new + selection is attempted (needed because selected cell is not retained). + * NSMatrix.m removeRow: rewrite so that row is removed before new + selection is attempted (needed because selected cell is not retained). + * NSMatrix.m deselectAllCells per OS spec try to select a cell at end + if empty selection is not allowed. + * NSMatrix.m deselectSelectedCell set default selected row/col to 0. + * NSMatrix.m mouseDown: optimize for new drawing behaviour. + * NSMenu.m setSelectedCell: eliminate use of retain/release of selected + cell via ASSIGN. + * NSMenuItem.m copyWithZone: optimized ivar copying where possible. + * NSMenuItem.m dealloc minor optimization. + * NSMenuItem.m setTarget: minor optimization. + * NSScroller.m trackScrollButtons: heavily optimized. + * NSScroller.m sendAction: reimplemented to use sendAction: per spec also + optimized. + * NSText.m implemented init method. + * NSText.m initWithFrame: fixed initialization of ivars which are released + to retain. + * NSText.m dealloc add release of retained ivars. + * NSView.m dealloc add release of retained ivars. + * NSView.m displayRect: and _addSubviewForNeedingDisplay reformatted code + and rewrote comments. + * NSWindow.m setFrame:display: rewrote for clarity. + * NSWindow.m implemented update method per OPENSTEP spec. + Thurs Aug 20 1998 Felipe A. Rodriguez * NSTextView.m commented out references to defaultTypingAttributes diff --git a/Headers/gnustep/gui/NSApplication.h b/Headers/gnustep/gui/NSApplication.h index 0b91d3295..6f91c771f 100644 --- a/Headers/gnustep/gui/NSApplication.h +++ b/Headers/gnustep/gui/NSApplication.h @@ -75,6 +75,7 @@ extern NSString *NSEventTrackingRunLoopMode; BOOL app_should_quit; BOOL app_is_active; BOOL app_is_hidden; + BOOL windows_need_update; NSImage *app_icon; // Reserved for back-end use diff --git a/Source/NSActionCell.m b/Source/NSActionCell.m index f535bf4ba..8ae1f22bf 100644 --- a/Source/NSActionCell.m +++ b/Source/NSActionCell.m @@ -138,17 +138,6 @@ [(NSControl *)control_view updateCell: self]; } -// -// Setting the NSCell's State -// -- (void)setState:(int)value -{ - [super setState: value]; - if (control_view) - if ([control_view isKindOfClass: [NSControl class]]) - [(NSControl *)control_view updateCell: self]; -} - // // Manipulating NSActionCell Values // @@ -225,9 +214,9 @@ { NSActionCell* c = [super copyWithZone:zone]; - [c setTag:tag]; - [c setTarget:target]; - [c setAction:action]; + c->tag = tag; + c->target = target; + c->action = action; return c; } diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 17db01fc4..ffc6ce363 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -7,7 +7,9 @@ Author: Scott Christley Date: 1996 - + Author: Felipe A. Rodriguez + Date: August 1998 + This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or @@ -116,6 +118,8 @@ static id NSApp; window_list = [NSMutableArray new]; window_count = 1; + main_menu = nil; + windows_need_update = YES; // // Event handling setup // @@ -222,36 +226,36 @@ static id NSApp; - (void)run { - NSEvent *e; - NSAutoreleasePool* pool; +NSEvent *e; +NSAutoreleasePool* pool; - NSDebugLog(@"NSApplication -run\n"); + NSDebugLog(@"NSApplication -run\n"); - [self finishLaunching]; + [self finishLaunching]; - app_should_quit = NO; - app_is_running = YES; + app_should_quit = NO; + app_is_running = YES; - do - { - pool = [NSAutoreleasePool new]; + do { + pool = [NSAutoreleasePool new]; - e = [self nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantFuture] - inMode:NSDefaultRunLoopMode dequeue:YES]; - if (e) - [self sendEvent: e]; - else - { - // Null event - // Call the back-end method to handle it - [self handleNullEvent]; - } - [pool release]; - } while (!app_should_quit); - app_is_running = YES; + e = [self nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantFuture] + inMode:NSDefaultRunLoopMode + dequeue:YES]; + if (e) + [self sendEvent: e]; + else // if Null event call back + [self handleNullEvent]; // end method to handle it - NSDebugLog(@"NSApplication end of run loop\n"); + if(windows_need_update) // send an update message + [self updateWindows]; // to all visible windows + + [pool release]; + } + while (!app_should_quit); + + NSDebugLog(@"NSApplication end of run loop\n"); } - (int)runModalForWindow:(NSWindow *)theWindow @@ -410,98 +414,90 @@ static id NSApp; - (NSEvent*)_eventMatchingMask:(unsigned int)mask { - NSEvent* event; - int i, count = [event_queue count]; +NSEvent* event; +int i, count = [event_queue count]; - [self getNextEvent]; + [self getNextEvent]; - /* Get an event from the events queue */ - if ((count = [event_queue count])) { - for (i = 0; i < count; i++) { - event = [event_queue objectAtIndex:i]; - if ([self event:event matchMask:mask]) { - [event retain]; - [event_queue removeObjectAtIndex:i]; - [self setCurrentEvent:event]; - return [event autorelease]; - } - } - } + if ((count = [event_queue count])) // Get an event from + { // the events queue + for (i = 0; i < count; i++) + { + event = [event_queue objectAtIndex:i]; + if ([self event:event matchMask:mask]) + { + [event retain]; + [event_queue removeObjectAtIndex:i]; + [self setCurrentEvent:event]; - return nil; + return [event autorelease]; + } + } + } + + return nil; } - (NSEvent *)nextEventMatchingMask:(unsigned int)mask - untilDate:(NSDate *)expiration - inMode:(NSString *)mode - dequeue:(BOOL)flag + untilDate:(NSDate *)expiration + inMode:(NSString *)mode + dequeue:(BOOL)flag { - NSRunLoop* currentLoop = [NSRunLoop currentRunLoop]; - NSEventType type; - NSEvent *event; - BOOL done = NO; +NSRunLoop* currentLoop = [NSRunLoop currentRunLoop]; +NSEventType type; +NSEvent *event; +BOOL done = NO; - event = [self _eventMatchingMask:mask]; - if (event) - done = YES; - else if (!expiration) - expiration = [NSDate distantFuture]; + event = [self _eventMatchingMask:mask]; + if (event) + done = YES; + else if (!expiration) + expiration = [NSDate distantFuture]; + + while (!done) // Not in queue so wait + { // for next event + NSDate *limitDate, *originalLimitDate; + // Retain the limitDate so it doesn't get + // release accidentally by runMode:beforeDate: + // if a timer which has this date as fire date + // gets released. + limitDate = [[currentLoop limitDateForMode:mode] retain]; + originalLimitDate = limitDate; - // Not in queue so wait for next event - while (!done) { - NSDate *limitDate, *originalLimitDate; + event = [self _eventMatchingMask:mask]; + if (event) + { + [limitDate release]; + break; + } - // flush any windows that need it - [NSWindow _flushWindows]; - [self _flushCommunicationChannels]; + if (limitDate) + limitDate = [expiration earlierDate:limitDate]; + else + limitDate = expiration; - /* Retain the limitDate so it doesn't get release accidentally by - runMode:beforeDate: if a timer which has this date as fire date gets - released. */ - limitDate = [[currentLoop limitDateForMode:mode] retain]; - originalLimitDate = limitDate; + [currentLoop runMode:mode beforeDate:limitDate]; + [originalLimitDate release]; - event = [self _eventMatchingMask:mask]; - if (event) { - [limitDate release]; - break; - } + event = [self _eventMatchingMask:mask]; + if (event) + break; + } - if (limitDate) - limitDate = [expiration earlierDate:limitDate]; - else - limitDate = expiration; + type = [event type]; + // Unhide the cursor if necessary + if (event != gnustep_gui_null_event) // and event is not a null event + { // do so only if we should + if ([NSCursor isHiddenUntilMouseMoves]) // unhide when mouse moves + { // and event is mouse event + if ((type == NSLeftMouseDown) || (type == NSLeftMouseUp) + || (type == NSRightMouseDown) || (type == NSRightMouseUp) + || (type == NSMouseMoved)) + [NSCursor unhide]; + } + } - [currentLoop runMode:mode beforeDate:limitDate]; - [originalLimitDate release]; - - event = [self _eventMatchingMask:mask]; - if (event) - break; - } - - // flush any windows that need it - [NSWindow _flushWindows]; - [self _flushCommunicationChannels]; - - type = [event type]; - - // Unhide the cursor if necessary - // but only if its not a null event - if (event != gnustep_gui_null_event) - { - // Only if we should unhide when mouse moves - if ([NSCursor isHiddenUntilMouseMoves]) - { - // Make sure the event is a mouse event before unhiding - if ((type == NSLeftMouseDown) || (type == NSLeftMouseUp) - || (type == NSRightMouseDown) || (type == NSRightMouseUp) - || (type == NSMouseMoved)) - [NSCursor unhide]; - } - } - - return event; + return event; } - (NSEvent *)peekEventMatchingMask:(unsigned int)mask @@ -712,23 +708,25 @@ static id NSApp; - (void)setWindowsNeedUpdate:(BOOL)flag { + windows_need_update = flag; } -- (void)updateWindows -{ - int i, count; - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; +- (void)updateWindows // send an update message to +{ // all visible windows +int i, count; +NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - // notify that we will update - [nc postNotificationName: NSApplicationWillUpdateNotification - object: self]; + // notify that we will update + [nc postNotificationName:NSApplicationWillUpdateNotification object:self]; - for (i = 0, count = [window_list count]; i < count; i++) - [[window_list objectAtIndex:i] update]; - - // notify that we did update - [nc postNotificationName: NSApplicationDidUpdateNotification - object: self]; + for (i = 0, count = [window_list count]; i < count; i++) + { + NSWindow *win = [window_list objectAtIndex:i]; + if([win isVisible]) // send update only if + [win update]; // window is visible + } + // notify that we did update + [nc postNotificationName:NSApplicationDidUpdateNotification object:self]; } - (NSArray *)windows @@ -785,7 +783,8 @@ static id NSApp; // Release old and retain new [aMenu retain]; - [main_menu release]; + if(main_menu) + [main_menu release]; main_menu = aMenu; // Search for a menucell with the name Windows diff --git a/Source/NSButtonCell.m b/Source/NSButtonCell.m index 0e6b86e4c..d4712208b 100644 --- a/Source/NSButtonCell.m +++ b/Source/NSButtonCell.m @@ -8,6 +8,8 @@ Author: Scott Christley Ovidiu Predescu Date: 1996 + Author: Felipe A. Rodriguez + Date: August 1998 This file is part of the GNUstep GUI Library. @@ -40,10 +42,9 @@ #include #include -#define ASSIGN(a, b) \ - [b retain]; \ - [a release]; \ - a = b; +#define ASSIGN(a, b) [b retain]; \ + [a release]; \ + a = b; // // NSButtonCell implementation @@ -56,45 +57,47 @@ + (void)initialize { if (self == [NSButtonCell class]) - { - // Initial version - [self setVersion:1]; - } + [self setVersion:1]; // Initial version } // // Instance methods // +- _init +{ + cell_enabled = YES; + transparent = NO; + cell_bordered = YES; + showAltStateMask = NSNoCellMask; // configure as a NSMomentaryPushButton + highlightsByMask = NSPushInCellMask | NSChangeGrayCellMask; + delayInterval = 0.4; + repeatInterval = 0.075; + altContents = nil; + + return self; +} + - init { [self initTextCell:@"Button"]; + return self; } - initImageCell:(NSImage *)anImage { [super initImageCell:anImage]; - [self setStringValue:@"Button"]; - [self setButtonType:NSMomentaryPushButton]; - [self setEnabled:YES]; - [self setTransparent:NO]; - [self setBordered:YES]; - delayInterval = 0.4; - repeatInterval = 0.075; - return self; + + contents = nil; + + return [self _init]; } - initTextCell:(NSString *)aString { [super initTextCell:aString]; - altContents = nil; - [self setButtonType:NSMomentaryPushButton]; - [self setEnabled:YES]; - [self setTransparent:NO]; - [self setBordered:YES]; - delayInterval = 0.4; - repeatInterval = 0.075; - return self; + + return [self _init]; } - (void)dealloc @@ -103,6 +106,7 @@ [altImage release]; [keyEquivalent release]; [keyEquivalentFont release]; + [super dealloc]; } @@ -116,9 +120,10 @@ - (void)setAlternateTitle:(NSString *)aString { - altContents = [aString copy]; - // update our state - [self setState:[self state]]; +NSString* _string = [aString copy]; + + ASSIGN(altContents, _string); + [self setState:[self state]]; // update our state } - (void)setFont:(NSFont *)fontObject @@ -129,8 +134,7 @@ - (void)setTitle:(NSString *)aString { [self setStringValue:aString]; - // update our state - [self setState:[self state]]; + [self setState:[self state]]; // update our state } - (NSString *)title @@ -165,14 +169,14 @@ // Setting the Repeat Interval // - (void)getPeriodicDelay:(float *)delay - interval:(float *)interval + interval:(float *)interval { *delay = delayInterval; *interval = repeatInterval; } - (void)setPeriodicDelay:(float)delay - interval:(float)interval + interval:(float)interval { delayInterval = delay; repeatInterval = interval; @@ -197,11 +201,11 @@ return keyEquivalentModifierMask; } -- (void)setKeyEquivalent:(NSString *)key -{ - id copy = [key copy]; - ASSIGN(keyEquivalent, copy); - [copy release]; +- (void)setKeyEquivalent:(NSString *)key +{ +NSString* _string = [key copy]; + + ASSIGN(keyEquivalent, _string); } - (void)setKeyEquivalentModifierMask:(unsigned int)mask @@ -215,9 +219,11 @@ } - (void)setKeyEquivalentFont:(NSString *)fontName - size:(float)fontSize + size:(float)fontSize { - ASSIGN(keyEquivalentFont, [NSFont fontWithName:fontName size:fontSize]); +NSFont* font = [NSFont fontWithName:fontName size:fontSize]; + + ASSIGN(keyEquivalentFont, font); } // @@ -327,18 +333,17 @@ [self setState:(aDouble != 0)]; } -- (int)intValue { return [self state]; } -- (float)floatValue { return [self state]; } +- (int)intValue { return [self state]; } +- (float)floatValue { return [self state]; } - (double)doubleValue { return [self state]; } // // Displaying // - (void)drawWithFrame:(NSRect)cellFrame - inView:(NSView *)controlView + inView:(NSView *)controlView { - // Save last view drawn to - control_view = controlView; + control_view = controlView; // Save last view cell was drawn to } // @@ -352,12 +357,12 @@ { NSButtonCell* c = [super copyWithZone:zone]; - [c setAlternateTitle:altContents]; - [c setAlternateImage:altImage]; - [c setKeyEquivalent:keyEquivalent]; - [c setKeyEquivalentFont:keyEquivalentFont]; - [c setKeyEquivalentModifierMask:keyEquivalentModifierMask]; - [c setTransparent:transparent]; + c->altContents = [[altContents copy] retain]; + ASSIGN(c->altImage, altImage); + c->keyEquivalent = [[keyEquivalent copy] retain]; + ASSIGN(c->keyEquivalentFont, keyEquivalentFont); + c->keyEquivalentModifierMask = keyEquivalentModifierMask; + c->transparent = transparent; c->highlightsByMask = highlightsByMask; c->showAltStateMask = showAltStateMask; @@ -387,6 +392,7 @@ altImage = [aDecoder decodeObject]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &transparent]; NSDebugLog(@"NSButtonCell: finish decoding\n"); + return self; } diff --git a/Source/NSCell.m b/Source/NSCell.m index 151e8d044..5c973b2a4 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -7,6 +7,8 @@ Author: Scott Christley Date: 1996 + Author: Felipe A. Rodriguez + Date: August 1998 This file is part of the GNUstep GUI Library. @@ -39,6 +41,10 @@ #include #include +#define ASSIGN(a, b) [b retain]; \ + [a release]; \ + a = b; + @implementation NSCell // @@ -70,7 +76,6 @@ // - _init { - self = [super init]; cell_type = NSNullCellType; cell_image = nil; cell_font = nil; @@ -88,6 +93,7 @@ cell_float_left = 0; cell_float_right = 0; action_mask = NSLeftMouseUpMask; + return self; } @@ -110,6 +116,7 @@ cell_image = [anImage retain]; image_position = NSImageOnly; cell_font = [[NSFont userFontOfSize:0] retain]; + return self; } @@ -123,11 +130,9 @@ contents = [aString retain]; cell_type = NSTextCellType; text_align = NSCenterTextAlignment; - cell_image = nil; - image_position = NSNoImage; cell_float_autorange = YES; - cell_float_left = 0; cell_float_right = 6; + return self; } @@ -219,15 +224,11 @@ } - (void)setImage:(NSImage *)anImage -{ - // Not an image class --then forget it - if (![anImage isKindOfClass:[NSImage class]]) - return; +{ + if (![anImage isKindOfClass:[NSImage class]]) // set the image only + return; // if it's an NSImage - // Only set the image if we are an image cell - [anImage retain]; - [cell_image release]; - cell_image = anImage; + ASSIGN(cell_image, anImage); [self setType:NSImageCellType]; } @@ -256,36 +257,35 @@ - (void)setDoubleValue:(double)aDouble { - NSNumber* number = [NSNumber numberWithDouble:aDouble]; +NSString* number_string = [[NSNumber numberWithDouble:aDouble] stringValue]; - [contents release]; - contents = [[number stringValue] retain]; + ASSIGN(contents, number_string); } - (void)setFloatValue:(float)aFloat { - NSNumber* number = [NSNumber numberWithFloat:aFloat]; +NSString* number_string = [[NSNumber numberWithFloat:aFloat] stringValue]; - [contents release]; - contents = [[number stringValue] retain]; + ASSIGN(contents, number_string); } - (void)setIntValue:(int)anInt { - NSNumber* number = [NSNumber numberWithInt:anInt]; +NSString* number_string = [[NSNumber numberWithInt:anInt] stringValue]; - [contents release]; - contents = [[number stringValue] retain]; + ASSIGN(contents, number_string); } - (void)setStringValue:(NSString *)aString { - aString = [aString copy]; - [contents release]; - if (!aString) - contents = @""; - else - contents = aString; +NSString* _string; + + if (!aString) + _string = @""; + else + _string = [aString copy]; + + ASSIGN(contents, _string); } // @@ -354,13 +354,10 @@ - (void)setFont:(NSFont *)fontObject { - // Not a font --then forget it - if (![fontObject isKindOfClass:[NSFont class]]) - return; + if (![fontObject isKindOfClass:[NSFont class]]) // set the font only + return; // if it's an NSFont - [fontObject retain]; - [cell_font release]; - cell_font = fontObject; + ASSIGN(cell_font, fontObject); } - (void)setSelectable:(BOOL)flag @@ -505,8 +502,8 @@ } - (void)highlight:(BOOL)lit - withFrame:(NSRect)cellFrame - inView:(NSView *)controlView + withFrame:(NSRect)cellFrame + inView:(NSView *)controlView { cell_highlighted = lit; @@ -769,36 +766,32 @@ - (void)setRepresentedObject:(id)anObject { - [anObject retain]; - [represented_object release]; - represented_object = anObject; + ASSIGN(represented_object, anObject); } - (id)copyWithZone:(NSZone*)zone { - NSCell* c; + NSCell* c = [[isa allocWithZone: zone] init]; - c = [[isa allocWithZone: zone] init]; - - [c setStringValue:contents]; - [c setImage:cell_image]; - [c setFont:cell_font]; - [c setState:cell_state]; + c->contents = [[contents copy] retain]; + ASSIGN(c->cell_image, cell_image); + ASSIGN(c->cell_font, cell_font); + c->cell_state = cell_state; c->cell_highlighted = cell_highlighted; - [c setEnabled:cell_enabled]; - [c setEditable:cell_editable]; - [c setBordered:cell_bordered]; - [c setBezeled:cell_bezeled]; - [c setScrollable:cell_scrollable]; - [c setSelectable:cell_selectable]; + c->cell_enabled = cell_enabled; + c->cell_editable = cell_editable; + c->cell_bordered = cell_bordered; + c->cell_bezeled = cell_bezeled; + c->cell_scrollable = cell_scrollable; + c->cell_selectable = cell_selectable; [c setContinuous:cell_continuous]; - [c setFloatingPointFormat:cell_float_autorange - left:cell_float_left - right:cell_float_right]; + c->cell_float_autorange = cell_float_autorange; + c->cell_float_left = cell_float_left; + c->cell_float_right = cell_float_right; c->image_position = image_position; - [c setType:cell_type]; - [c setAlignment:text_align]; - [c setEntryType:entry_type]; + c->cell_type = cell_type; + c->text_align = text_align; + c->entry_type = entry_type; c->control_view = control_view; c->cell_size = cell_size; [c setRepresentedObject:represented_object]; diff --git a/Source/NSClipView.m b/Source/NSClipView.m index a9ca22f9f..1de3f967a 100644 --- a/Source/NSClipView.m +++ b/Source/NSClipView.m @@ -167,55 +167,55 @@ - (void)viewBoundsChanged:(NSNotification*)aNotification { - [[self superview] reflectScrolledClipView:self]; + [super_view reflectScrolledClipView:self]; } - (void)viewFrameChanged:(NSNotification*)aNotification { [self setBoundsOrigin:[self constrainScrollPoint:bounds.origin]]; - [[self superview] reflectScrolledClipView:self]; + [super_view reflectScrolledClipView:self]; } - (void)scaleUnitSquareToSize:(NSSize)newUnitSize { [super scaleUnitSquareToSize:newUnitSize]; - [[self superview] reflectScrolledClipView:self]; + [super_view reflectScrolledClipView:self]; } - (void)setBoundsOrigin:(NSPoint)aPoint { [super setBoundsOrigin:aPoint]; - [[self superview] reflectScrolledClipView:self]; + [super_view reflectScrolledClipView:self]; } - (void)setBoundsSize:(NSSize)aSize { [super setBoundsSize:aSize]; - [[self superview] reflectScrolledClipView:self]; + [super_view reflectScrolledClipView:self]; } - (void)setFrameSize:(NSSize)aSize { [super setFrameSize:aSize]; - [[self superview] reflectScrolledClipView:self]; + [super_view reflectScrolledClipView:self]; } - (void)setFrameOrigin:(NSPoint)aPoint { [super setFrameOrigin:aPoint]; - [[self superview] reflectScrolledClipView:self]; + [super_view reflectScrolledClipView:self]; } - (void)setFrame:(NSRect)rect { [super setFrame:rect]; - [[self superview] reflectScrolledClipView:self]; + [super_view reflectScrolledClipView:self]; } - (void)translateOriginToPoint:(NSPoint)aPoint { [super translateOriginToPoint:aPoint]; - [[self superview] reflectScrolledClipView:self]; + [super_view reflectScrolledClipView:self]; } - (id)documentView { return _documentView; } diff --git a/Source/NSMatrix.m b/Source/NSMatrix.m index dc6bc012a..ea4f4709f 100644 --- a/Source/NSMatrix.m +++ b/Source/NSMatrix.m @@ -381,7 +381,6 @@ static int mouseDownFlags = 0; [self setSelectionByRect:YES]; [self setAutosizesCells:YES]; if (mode == NSRadioModeMatrix && numRows && numCols) { - selectedRow = selectedColumn = 0; [self selectCellAtRow:0 column:0]; } else @@ -557,14 +556,17 @@ static int mouseDownFlags = 0; if (column >= numCols) return; - if (column == selectedColumn) - [self selectCellAtRow:0 column:0]; - for (i = 0; i < numRows; i++) [[cells objectAtIndex:i] removeObjectAtIndex:column]; removeColumn (selectedCells, column); numCols--; + + if (column == selectedColumn) + { + selectedCell = nil; + [self selectCellAtRow:0 column:0]; + } } - (void)removeRow:(int)row @@ -572,12 +574,15 @@ static int mouseDownFlags = 0; if (row >= numRows) return; - if (row == selectedRow) - [self selectCellAtRow:0 column:0]; - [cells removeObjectAtIndex:row]; removeRow (selectedCells, row); numRows--; + + if (row == selectedRow) + { + selectedCell = nil; + [self selectCellAtRow:0 column:0]; + } } - (void)renewRows:(int)newRows @@ -712,7 +717,7 @@ static int mouseDownFlags = 0; if (mode == NSRadioModeMatrix) { if (value) { - ASSIGN(selectedCell, aCell); + selectedCell = aCell; // select current cell selectedRow = row; selectedColumn = column; [selectedCell setState:1]; @@ -745,14 +750,17 @@ static int mouseDownFlags = 0; ((tMatrix)selectedCells)->matrix[i][j] = NO; } } + + if(!allowsEmptySelection) // if we don't allow an + [self selectCellAtRow:0 column:0]; // empty selection } - (void)deselectSelectedCell { [selectedCell setState:0]; selectedCell = nil; - selectedRow = -1; - selectedColumn = -1; + selectedRow = 0; + selectedColumn = 0; } - (void)selectAll:(id)sender @@ -761,7 +769,7 @@ static int mouseDownFlags = 0; NSArray* row; /* Make the selected cell the cell at (0, 0) */ - ASSIGN(selectedCell, [self cellAtRow:0 column:0]); + selectedCell = [self cellAtRow:0 column:0]; // select current cell selectedRow = 0; selectedColumn = 0; @@ -792,7 +800,7 @@ static int mouseDownFlags = 0; else if (!aCell) return; - ASSIGN(selectedCell, aCell); + selectedCell = aCell; // select current cell selectedRow = row; selectedColumn = column; [selectedCell setState:1]; @@ -1147,6 +1155,7 @@ BOOL done = NO; NSRect rect; id aCell, previousCell = nil, selectedCellTarget; NSRect previousCellRect; +NSApplication *app = [NSApplication sharedApplication]; static MPoint anchor = {0, 0}; mouseDownFlags = [theEvent modifierFlags]; @@ -1174,58 +1183,60 @@ static MPoint anchor = {0, 0}; switch (mode) { - case NSTrackModeMatrix: // in Track mode - ASSIGN(selectedCell, aCell); // the cell should - selectedRow = row; // track the mouse - selectedColumn = column; // until the cursor - // either leaves - if([aCell trackMouse:lastEvent // the cellframe or - inRect:rect // NSLeftMouseUp + case NSTrackModeMatrix: // in Track mode the cell + selectedCell = aCell; // should track the mouse + selectedRow = row; // until the cursor either + selectedColumn = column; // leaves the cellframe or + // NSLeftMouseUp occurs + if([aCell trackMouse:lastEvent + inRect:rect ofView:self untilMouseUp:YES]) // YES if mouse done = YES; // went up in cell break; - case NSHighlightModeMatrix: - [aCell setState:1]; + case NSHighlightModeMatrix: // Highlight mode is like + [aCell setState:1]; // Track mode except that + selectedCell = aCell; // the cell is lit before + selectedRow = row; // it begins tracking and + selectedColumn = column; // unlit afterwards [aCell highlight: YES withFrame: rect inView: self]; - [self setNeedsDisplayInRect:rect]; // Highlight mode - ASSIGN(selectedCell, aCell); // is like Track - selectedRow = row; // mode except that - selectedColumn = column; // the cell is lit - // before it begins - if([aCell trackMouse:lastEvent // tracking and - inRect:rect // unlit afterwards + [window flushWindow]; + + if([aCell trackMouse:lastEvent + inRect:rect ofView:self untilMouseUp:YES]) // YES if mouse done = YES; // went up in cell + [aCell setState:0]; [aCell highlight: NO withFrame: rect inView: self]; - [self setNeedsDisplayInRect:rect]; + [window flushWindow]; break; case NSRadioModeMatrix: // Radio mode allows no if (previousCell == aCell) // more than one cell break; // to be selected - - [selectedCell setState:0]; // deselect previously - if (!previousCell) // selected cell - previousCellRect = [self cellFrameAtRow:selectedRow - column:selectedColumn]; - [selectedCell highlight:NO - withFrame:previousCellRect - inView:self]; - ((tMatrix)selectedCells)->matrix[selectedRow] - [selectedColumn] = NO; - [self setNeedsDisplayInRect:previousCellRect]; - - ASSIGN(selectedCell, aCell); // select current cell + + if(selectedCell) + { + [selectedCell setState:0]; // deselect previously + if (!previousCell) // selected cell + previousCellRect = [self cellFrameAtRow:selectedRow + column:selectedColumn]; + [selectedCell highlight:NO + withFrame:previousCellRect + inView:self]; + ((tMatrix)selectedCells)->matrix[selectedRow] + [selectedColumn] = NO; + } + selectedCell = aCell; // select current cell selectedRow = row; selectedColumn = column; - [aCell setState:1]; + [aCell setState:1]; [aCell highlight:YES withFrame:rect inView:self]; ((tMatrix)selectedCells)->matrix[row][column] = YES; - [self setNeedsDisplayInRect:rect]; + [window flushWindow]; break; // List mode allows case NSListModeMatrix: // multiple cells to be @@ -1247,7 +1258,7 @@ static MPoint anchor = {0, 0}; // selection to the current cell if (!(modifiers & NSAlternateKeyMask)) { - ASSIGN(selectedCell, aCell); + selectedCell = aCell; // select current cell selectedRow = row; selectedColumn = column; @@ -1256,7 +1267,7 @@ static MPoint anchor = {0, 0}; withFrame:rect inView:self]; ((tMatrix)selectedCells)->matrix[row][column] =YES; - [self setNeedsDisplayInRect:rect]; + [window flushWindow]; break; } } @@ -1269,7 +1280,8 @@ static MPoint anchor = {0, 0}; last:MakePoint (selectedColumn, selectedRow) current:MakePoint (column, row)]; - ASSIGN(selectedCell, aCell); + [window flushWindow]; + selectedCell = aCell; // select current cell selectedRow = row; selectedColumn = column; break; @@ -1285,22 +1297,20 @@ static MPoint anchor = {0, 0}; while (!shouldProceedEvent) { // Get the next event - theEvent = [[NSApplication sharedApplication] - nextEventMatchingMask:eventMask - untilDate:[NSDate distantFuture] - inMode:NSEventTrackingRunLoopMode - dequeue:YES]; + theEvent = [app nextEventMatchingMask:eventMask + untilDate:[NSDate distantFuture] + inMode:NSEventTrackingRunLoopMode + dequeue:YES]; switch ([theEvent type]) { case NSPeriodic: NSDebugLog(@"NSMatrix: got NSPeriodic event\n"); - shouldProceedEvent = YES; - break; + shouldProceedEvent = YES; // it's time to cycle + break; // thru the loop again case NSLeftMouseUp: - done = YES; - case NSLeftMouseDown: - default: // if in Track or Highlight modes break - // out and check if mouse is in a cell + done = YES; // Track and Highlight modes do not use + case NSLeftMouseDown: // periodic events so we must break out + default: // and check if the mouse is in a cell if ((mode == NSTrackModeMatrix) || (mode == NSHighlightModeMatrix)) shouldProceedEvent = YES; @@ -1318,25 +1328,30 @@ static MPoint anchor = {0, 0}; switch (mode) // Finish the selection { // process - case NSTrackModeMatrix: - case NSHighlightModeMatrix: - [selectedCell setState:![selectedCell state]]; - case NSRadioModeMatrix: - [selectedCell highlight:NO withFrame:rect inView:self]; + case NSRadioModeMatrix: + if(selectedCell) + [selectedCell highlight:NO withFrame:rect inView:self]; case NSListModeMatrix: - [self setNeedsDisplayInRect:rect]; + [self setNeedsDisplayInRect:rect]; // not needed by XRAW + [window flushWindow]; + case NSHighlightModeMatrix: + case NSTrackModeMatrix: break; - } // in Track and Highlight modes the single - // click action has already been sent by the - // cell to it's target (if it has one) - if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix) && - (selectedCellTarget = [selectedCell target])) - [selectedCellTarget performSelector:[selectedCell action] - withObject:self]; - else // selected cell has no target - { // so send single click action - if (target) // to matrix's (self's) target - [target performSelector:action withObject:self]; + } + + if(selectedCell) + { // send single click action + if(!(selectedCellTarget = [selectedCell target])) + { // selected cell has no target so send single + if (target) // click action to matrix's (self's) target + [target performSelector:action withObject:self]; + } // in Track and Highlight modes the single + else // click action has already been sent by the + { // cell to it's target (if it has one) + if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) + [selectedCellTarget performSelector:[selectedCell action] + withObject:self]; + } } // click count > 1 indicates a double click if (target && doubleAction && ([lastEvent clickCount] > 1)) @@ -1344,7 +1359,7 @@ static MPoint anchor = {0, 0}; [self unlockFocus]; - if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) + if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) [NSEvent stopPeriodicEvents]; [lastEvent release]; @@ -1405,48 +1420,48 @@ static MPoint anchor = {0, 0}; return self; } -- (void)setMode:(NSMatrixMode)aMode { mode = aMode; } -- (NSMatrixMode)mode { return mode; } -- (void)setCellClass:(Class)class { cellClass = class; } -- (Class)cellClass { return cellClass; } -- (void)setPrototype:(NSCell*)aCell { ASSIGN(cellPrototype, aCell) } -- (id)prototype { return cellPrototype; } -- (NSSize)cellSize { return cellSize; } -- (NSSize)intercellSpacing { return intercell; } -- (void)setBackgroundColor:(NSColor*)c { ASSIGN(backgroundColor, c) } -- (NSColor*)backgroundColor { return backgroundColor; } -- (void)setCellBackgroundColor:(NSColor*)c { ASSIGN(cellBackgroundColor, c) } -- (NSColor*)cellBackgroundColor { return cellBackgroundColor; } -- (void)setDelegate:(id)object { ASSIGN(delegate, object) } -- (id)delegate { return delegate; } -- (void)setTarget:anObject { ASSIGN(target, anObject) } -- (id)target { return target; } -- (void)setAction:(SEL)sel { action = sel; } -- (SEL)action { return action; } -- (void)setDoubleAction:(SEL)sel { doubleAction = sel; } -- (SEL)doubleAction { return doubleAction; } -- (void)setErrorAction:(SEL)sel { errorAction = sel; } -- (SEL)errorAction { return errorAction; } -- (void)setAllowsEmptySelection:(BOOL)f { allowsEmptySelection = f; } -- (BOOL)allowsEmptySelection { return allowsEmptySelection; } -- (void)setSelectionByRect:(BOOL)flag { selectionByRect = flag; } -- (BOOL)isSelectionByRect { return selectionByRect; } -- (void)setDrawsBackground:(BOOL)flag { drawsBackground = flag; } -- (BOOL)drawsBackground { return drawsBackground; } -- (void)setDrawsCellBackground:(BOOL)f { drawsCellBackground = f; } -- (BOOL)drawsCellBackground { return drawsCellBackground; } -- (void)setAutosizesCells:(BOOL)flag { autosizesCells = flag; } -- (BOOL)autosizesCells { return autosizesCells; } -- (BOOL)isAutoscroll { return autoscroll; } -- (int)numberOfRows { return numRows; } -- (int)numberOfColumns { return numCols; } -- (id)selectedCell { return selectedCell; } -- (int)selectedColumn { return selectedColumn; } -- (int)selectedRow { return selectedRow; } -- (int)mouseDownFlags { return mouseDownFlags; } +- (void)setMode:(NSMatrixMode)aMode { mode = aMode; } +- (NSMatrixMode)mode { return mode; } +- (void)setCellClass:(Class)class { cellClass = class; } +- (Class)cellClass { return cellClass; } +- (void)setPrototype:(NSCell*)aCell { ASSIGN(cellPrototype, aCell) } +- (id)prototype { return cellPrototype; } +- (NSSize)cellSize { return cellSize; } +- (NSSize)intercellSpacing { return intercell; } +- (void)setBackgroundColor:(NSColor*)c { ASSIGN(backgroundColor, c) } +- (NSColor*)backgroundColor { return backgroundColor; } +- (void)setCellBackgroundColor:(NSColor*)c { ASSIGN(cellBackgroundColor, c) } +- (NSColor*)cellBackgroundColor { return cellBackgroundColor; } +- (void)setDelegate:(id)object { ASSIGN(delegate, object) } +- (id)delegate { return delegate; } +- (void)setTarget:anObject { ASSIGN(target, anObject) } +- (id)target { return target; } +- (void)setAction:(SEL)sel { action = sel; } +- (SEL)action { return action; } +- (void)setDoubleAction:(SEL)sel { doubleAction = sel; } +- (SEL)doubleAction { return doubleAction; } +- (void)setErrorAction:(SEL)sel { errorAction = sel; } +- (SEL)errorAction { return errorAction; } +- (void)setAllowsEmptySelection:(BOOL)f { allowsEmptySelection = f; } +- (BOOL)allowsEmptySelection { return allowsEmptySelection; } +- (void)setSelectionByRect:(BOOL)flag { selectionByRect = flag; } +- (BOOL)isSelectionByRect { return selectionByRect; } +- (void)setDrawsBackground:(BOOL)flag { drawsBackground = flag; } +- (BOOL)drawsBackground { return drawsBackground; } +- (void)setDrawsCellBackground:(BOOL)f { drawsCellBackground = f; } +- (BOOL)drawsCellBackground { return drawsCellBackground; } +- (void)setAutosizesCells:(BOOL)flag { autosizesCells = flag; } +- (BOOL)autosizesCells { return autosizesCells; } +- (BOOL)isAutoscroll { return autoscroll; } +- (int)numberOfRows { return numRows; } +- (int)numberOfColumns { return numCols; } +- (id)selectedCell { return selectedCell; } +- (int)selectedColumn { return selectedColumn; } +- (int)selectedRow { return selectedRow; } +- (int)mouseDownFlags { return mouseDownFlags; } #if HAS_FLIPPED_VIEWS -- (BOOL)isFlipped { return YES; } +- (BOOL)isFlipped { return YES; } #endif @end diff --git a/Source/NSMenu.m b/Source/NSMenu.m index ba5c8d194..eade071a9 100644 --- a/Source/NSMenu.m +++ b/Source/NSMenu.m @@ -60,6 +60,11 @@ - (void)_resizeMenuForCellSize; @end +//***************************************************************************** +// +// NSMenuMatrix +// +//***************************************************************************** @implementation NSMenuMatrix @@ -227,15 +232,21 @@ static NSFont* menuFont = nil; } } -- (NSSize)cellSize { return cellSize; } +- (NSSize)cellSize { return cellSize; } - (void)setMenu:(NSMenu*)anObject { menu = anObject; } -- (void)setSelectedCell:(id)aCell { ASSIGN(selectedCell, aCell); } -- (id)selectedCell { return selectedCell; } -- (NSRect)selectedCellRect { return selectedCellRect; } +- (void)setSelectedCell:(id)aCell { selectedCell = aCell; } +- (id)selectedCell { return selectedCell; } +- (NSRect)selectedCellRect { return selectedCellRect; } @end /* NSMenuMatrix */ +//***************************************************************************** +// +// NSMenu +// +//***************************************************************************** + @implementation NSMenu // Class variables diff --git a/Source/NSMenuItem.m b/Source/NSMenuItem.m index f84acacc1..19cbc91cd 100644 --- a/Source/NSMenuItem.m +++ b/Source/NSMenuItem.m @@ -73,7 +73,7 @@ static BOOL usesUserKeyEquivalents = YES; [representedObject release]; if (hasSubmenu) - [[self target] release]; + [target release]; [super dealloc]; } @@ -86,8 +86,8 @@ static BOOL usesUserKeyEquivalents = YES; copy->hasSubmenu = hasSubmenu; if (hasSubmenu) { id submenu = [[target copyWithZone:zone] autorelease]; - [copy setTarget:submenu]; - } + copy->target = [submenu retain]; + } return copy; } @@ -97,7 +97,7 @@ static BOOL usesUserKeyEquivalents = YES; hasSubmenu = anObject && [anObject isKindOfClass:[NSMenu class]]; if (hasSubmenu) { [anObject retain]; - [[self target] release]; + [target release]; } [super setTarget:anObject]; } diff --git a/Source/NSScroller.m b/Source/NSScroller.m index 037c8020c..8f087868f 100644 --- a/Source/NSScroller.m +++ b/Source/NSScroller.m @@ -6,6 +6,8 @@ Author: Ovidiu Predescu A completely rewritten version of the original source by Scott Christley. Date: July 1997 + Author: Felipe A. Rodriguez + Date: August 1998 This file is part of the GNUstep GUI Library. @@ -207,14 +209,15 @@ static NSButtonCell* knobCell = nil; - (void)setFloatValue:(float)aFloat { - if (aFloat < 0) - _floatValue = 0; - else if (aFloat > 1) - _floatValue = 1; - else - _floatValue = aFloat; - - [self setNeedsDisplayInRect:[self rectForPart:NSScrollerKnobSlot]]; + if (aFloat < 0) + _floatValue = 0; + else + if (aFloat > 1) + _floatValue = 1; + else + _floatValue = aFloat; + + [self setNeedsDisplayInRect:[self rectForPart:NSScrollerKnobSlot]]; } - (void)setFloatValue:(float)aFloat @@ -435,74 +438,77 @@ static NSButtonCell* knobCell = nil; - (void)trackScrollButtons:(NSEvent*)theEvent { - unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask - | NSLeftMouseDraggedMask | NSMouseMovedMask; - NSPoint location; - NSEventType eventType; - BOOL shouldReturn = NO; - id theCell = nil; +NSApplication *theApp = [NSApplication sharedApplication]; +unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask | + NSLeftMouseDraggedMask | NSMouseMovedMask; +NSPoint location; +BOOL shouldReturn = NO; +id theCell = nil; +NSRect rect; - NSDebugLog (@"trackScrollButtons"); - do { - NSRect rect = [self rectForPart:_hitPart]; + NSDebugLog (@"trackScrollButtons"); + do { + location = [self convertPoint:[theEvent locationInWindow]fromView:nil]; + _hitPart = [self testPart:location]; + rect = [self rectForPart:_hitPart]; - switch (_hitPart) { - case NSScrollerIncrementLine: - case NSScrollerIncrementPage: - theCell = (_isHorizontal ? rightCell : upCell); - break; + switch (_hitPart) // determine which cell + { // was hit + case NSScrollerIncrementLine: + case NSScrollerIncrementPage: + theCell = (_isHorizontal ? rightCell : upCell); + break; - case NSScrollerDecrementLine: - case NSScrollerDecrementPage: - theCell = (_isHorizontal ? leftCell : downCell); - break; + case NSScrollerDecrementLine: + case NSScrollerDecrementPage: + theCell = (_isHorizontal ? leftCell : downCell); + break; - default: - theCell = nil; - break; - } + default: + theCell = nil; + break; + } - if (theCell) { - [theCell highlight:YES withFrame:rect inView:self]; // highlight cell - [self setNeedsDisplayInRect:rect]; - NSDebugLog (@"tracking cell %x", theCell); - /* Track the mouse until mouse goes up */ - shouldReturn = [theCell trackMouse:theEvent - inRect:rect - ofView:self - untilMouseUp:NO]; + if (theCell) + { // highlight the cell + [theCell highlight:YES withFrame:rect inView:self]; + [self setNeedsDisplayInRect:rect]; // not needed by XRAW + [window flushWindow]; + NSDebugLog (@"tracking cell %x", theCell); + // Track the mouse until mouse goes up + shouldReturn = [theCell trackMouse:theEvent + inRect:rect + ofView:self + untilMouseUp:YES]; + // unhighlight the cell + [theCell highlight:NO withFrame:rect inView:self]; + [self setNeedsDisplayInRect:rect]; // not needed by XRAW + [window flushWindow]; + } - /* Now unhighlight the cell */ - [theCell highlight:NO withFrame:rect inView:self]; -#if 1 - [self setNeedsDisplayInRect:rect]; -#else - [theCell drawWithFrame:rect inView:self]; - [self setNeedsDisplayInRect:rect]; - [[self window] flushWindow]; -#endif - } + if (shouldReturn) + break; - if (shouldReturn) - break; + theEvent = [theApp nextEventMatchingMask:eventMask + untilDate:[NSDate distantFuture] + inMode:NSEventTrackingRunLoopMode + dequeue:YES]; + } + while ([theEvent type] != NSLeftMouseUp); - theEvent = [[NSApplication sharedApplication] - nextEventMatchingMask:eventMask - untilDate:[NSDate distantFuture] - inMode:NSEventTrackingRunLoopMode - dequeue:YES]; - eventType = [theEvent type]; - location = [self convertPoint:[theEvent locationInWindow] fromView:nil]; - _hitPart = [self testPart:location]; - } while (eventType != NSLeftMouseUp); - NSDebugLog (@"return from trackScrollButtons"); + NSDebugLog (@"return from trackScrollButtons"); } -- (BOOL)sendAction:(SEL)action to:(id)target -{ - [target performSelector:action withObject:self]; - return YES; -} +- (BOOL)sendAction:(SEL)theAction to:(id)theTarget +{ // send action to +BOOL ret = [super sendAction:theAction to:theTarget]; // the target on + // behalf of cell + [self drawKnobSlot]; // lockFocus set in mouseDown method is + [self drawKnob]; // active so we simply redraw the knob and + [window flushWindow]; // slot to reflect the hit scroll button + + return ret; +} - (void)encodeWithCoder:aCoder {} @@ -514,18 +520,15 @@ static NSButtonCell* knobCell = nil; - (void)drawRect:(NSRect)rect { - NSDebugLog (@"NSScroller drawRect: ((%f, %f), (%f, %f))", - rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); + NSDebugLog (@"NSScroller drawRect: ((%f, %f), (%f, %f))", + rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); - /* Draw the scroller buttons */ - [self drawArrow:NSScrollerDecrementArrow highlight:NO]; - [self drawArrow:NSScrollerIncrementArrow highlight:NO]; + // Draw the scroller buttons + [self drawArrow:NSScrollerDecrementArrow highlight:NO]; + [self drawArrow:NSScrollerIncrementArrow highlight:NO]; - /* Draw the knob slot */ - [self drawKnobSlot]; - - /* Draw the knob */ - [self drawKnob]; + [self drawKnobSlot]; // Draw knob slot + [self drawKnob]; // Draw the knob } - (void)drawArrow:(NSScrollerArrow)whichButton @@ -554,8 +557,7 @@ static NSButtonCell* knobCell = nil; - (void)drawKnob { - NSRect rect = [self rectForPart:NSScrollerKnob]; - [knobCell drawWithFrame:rect inView:self]; + [knobCell drawWithFrame:[self rectForPart:NSScrollerKnob] inView:self]; } /* The following methods should be implemented in the backend */ diff --git a/Source/NSText.m b/Source/NSText.m index 19a1c774a..e6fe3ac69 100644 --- a/Source/NSText.m +++ b/Source/NSText.m @@ -70,6 +70,11 @@ // // Initialization // +- init +{ + return [self initWithFrame:NSZeroRect]; +} + - initWithFrame:(NSRect)frameRect { [super initWithFrame:frameRect]; @@ -86,15 +91,17 @@ is_ruler_visible = NO; is_field_editor = NO; draws_background = YES; - background_color = [NSColor whiteColor]; - text_color = [NSColor blackColor]; - default_font = [NSFont userFontOfSize:12]; + background_color = [[NSColor whiteColor] retain]; + text_color = [[NSColor blackColor] retain]; + default_font = [[NSFont userFontOfSize:12] retain]; return self; } - (void)dealloc { + [default_font release]; + [text_color release]; [background_color release]; [plainContent release]; [rtfContent release]; diff --git a/Source/NSView.m b/Source/NSView.m index 2dc6f0a04..1f8af00b4 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -715,6 +715,7 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil; { // preliminary implementation FIX ME if(autoresizingMask == NSViewNotSizable) // view is not resizable return; + if(autoresizingMask & NSViewWidthSizable) // width resizable? { frame.size.width = [super_view frame].size.width; @@ -724,6 +725,7 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil; if(autoresizingMask & NSViewMinXMargin) frame.origin.x += [super_view frame].size.width - oldSize.width; } + if(autoresizingMask & NSViewHeightSizable) // height resizable? { frame.size.height = [super_view frame].size.height; @@ -815,41 +817,44 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil; - (void)displayRect:(NSRect)rect { - int i, count; +int i, count; - if (!boundsMatrix || !frameMatrix) - NSLog (@"warning: %@ %p has not have the PS matrices setup!", - NSStringFromClass(isa), self); + if (!boundsMatrix || !frameMatrix) + NSLog (@"warning: %@ %p has not have the PS matrices setup!", + NSStringFromClass(isa), self); - needs_display = NO; + needs_display = NO; - [self lockFocus]; - [self drawRect:rect]; - [window _setNeedsFlush]; + [self lockFocus]; + [self drawRect:rect]; + [window _setNeedsFlush]; // [window _view:self needsFlushInRect:rect]; - [self unlockFocus]; + [self unlockFocus]; + // Tell subviews to display + for (i = 0, count = [sub_views count]; i < count; ++i) + { + NSView* subview = [sub_views objectAtIndex:i]; + NSRect subviewFrame = subview->frame; + NSRect intersection; + // If the subview is rotated compute its + // bounding rectangle and use this one + // instead of the subview's frame. + if ([subview->frameMatrix isRotated]) + [subview->frameMatrix boundingRectFor:subviewFrame + result:&subviewFrame]; - // Tell subviews to display - for (i = 0, count = [sub_views count]; i < count; ++i) { - NSView* subview = [sub_views objectAtIndex:i]; - NSRect subviewFrame = subview->frame; - NSRect intersection; - - /* If the subview is rotated compute its bounding rectangle and use this - one instead of the subview's frame. */ - if ([subview->frameMatrix isRotated]) - [subview->frameMatrix boundingRectFor:subviewFrame result:&subviewFrame]; - - /* Determine if the subview's frame intersects "rect" - so that we can display the subview. */ - intersection = NSIntersectionRect (rect, subviewFrame); - if (intersection.origin.x || intersection.origin.y - || intersection.size.width || intersection.size.height) { - /* Convert the intersection rectangle to the subview's coordinates */ - intersection = [subview convertRect:intersection fromView:self]; - [subview displayRect:intersection]; - } - } + // Determine if the subview's frame + // intersects "rect" so that we can display + // the subview. + intersection = NSIntersectionRect (rect, subviewFrame); + if (intersection.origin.x || intersection.origin.y || + intersection.size.width || intersection.size.height) + { // Convert the intersection rectangle to + // the subview's coordinates + intersection = [subview convertRect:intersection fromView:self]; + [subview displayRect:intersection]; + } + } } - (void)displayRectIgnoringOpacity:(NSRect)aRect @@ -871,35 +876,35 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil; } - (void)_addSubviewForNeedingDisplay:(NSView*)view -{ - NSView* currentView; +{ // Add view to the list of +NSView* currentView; // sibling subviews that + // need display. + currentView = _subviewsThatNeedDisplay; + while (currentView) // do nothing if the view + { // is already in self's + if (currentView == view) // list. + return; + currentView = currentView->_nextSiblingSubviewThatNeedsDisplay; + } + // view is not in the list of subviews that need display. + // Concatenate self's list of subviews that need display to + // the view's list of siblings subviews that need display. - /* Add view in the list of sibling subviews that need display. First - check if view is not already there. */ - currentView = _subviewsThatNeedDisplay; - while (currentView) { - if (currentView == view) - return; - currentView = currentView->_nextSiblingSubviewThatNeedsDisplay; - } + // find the last element in the view's + currentView = view; // list of siblings that need display + while (currentView->_nextSiblingSubviewThatNeedsDisplay) + currentView = currentView->_nextSiblingSubviewThatNeedsDisplay; - /* view is not in the list of subviews that need display; add it. - To do this concatenate the "view"'s list of siblings to the list of - subviews. Find the last element in the "view"'s list of siblings and - assign to its _nextSiblingSubviewThatNeedsDisplay ivar the first element - of the subviews that need display list in self. - */ - currentView = view; - while (currentView->_nextSiblingSubviewThatNeedsDisplay) - currentView = currentView->_nextSiblingSubviewThatNeedsDisplay; + // link the lists by assigning to view's + // _nextSiblingSubviewThatNeedsDisplay ivar + // self's _subviewsThatNeedDisplay ivar. + currentView->_nextSiblingSubviewThatNeedsDisplay =_subviewsThatNeedDisplay; + _subviewsThatNeedDisplay = view; - currentView->_nextSiblingSubviewThatNeedsDisplay = _subviewsThatNeedDisplay; - _subviewsThatNeedDisplay = view; - - /* Now add recursively do the same algorithm with self. This way we'll create - a subtree of views that need display inside the views hierarchy. */ - if (super_view) - [super_view _addSubviewForNeedingDisplay:self]; + // Add recursively using the same algorithm with + needs_display = YES; // self. This way we'll create a subtree of views + if (super_view) // that need display inside the views hierarchy. + [super_view _addSubviewForNeedingDisplay:self]; } - (void)_removeSubviewFromViewsThatNeedDisplay:(NSView*)view @@ -935,7 +940,7 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil; { needs_display = flag; if (needs_display) { -// NSLog (@"NSView setNeedsDisplay:"); + invalidatedRectangle = bounds; [window _setNeedsDisplay]; @@ -946,7 +951,6 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil; - (void)setNeedsDisplayInRect:(NSRect)rect { -// NSLog (@"NSView setNeedsDisplayInRect:"); needs_display = YES; invalidatedRectangle = NSUnionRect (invalidatedRectangle, rect); [window _setNeedsDisplay]; diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 4963fe83f..25998cc08 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -583,19 +583,16 @@ static BOOL _needsFlushWindows = YES; { } -- (void)setFrame:(NSRect)frameRect - display:(BOOL)flag +- (void)setFrame:(NSRect)frameRect display:(BOOL)flag { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - - frame = frameRect; - - // post notification +NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + + frame = frameRect; + // post notification [nc postNotificationName: NSWindowDidResizeNotification object: self]; - // display if requested - if (!flag) return; - [self display]; + if (flag) // display if requested + [self display]; } - (void)setFrameOrigin:(NSPoint)aPoint @@ -730,9 +727,16 @@ static BOOL _needsFlushWindows = YES; - (void)update { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; +NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - [nc postNotificationName: NSWindowDidUpdateNotification object: self]; + if(is_autodisplay && needs_display) // if autodisplay is + { // enabled + [self _collectFlushRectangles]; + [self displayIfNeeded]; + [self flushWindowIfNeeded]; + } + + [nc postNotificationName: NSWindowDidUpdateNotification object: self]; } - (void)useOptimizedDrawing:(BOOL)flag @@ -1587,15 +1591,17 @@ static BOOL _needsFlushWindows = YES; // NSLog (@"_flushWindows"); windowList = [[NSApplication sharedApplication] windows]; - - for (i = 0, count = [windowList count]; i < count; i++) { + + 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]; - } + if (window->needs_display || window->needs_flush) + { + [window _collectFlushRectangles]; + [window displayIfNeeded]; + [window flushWindowIfNeeded]; + } } _needsFlushWindows = NO;