Various tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4357 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-06-04 14:43:24 +00:00
parent 145d4fba64
commit 3478a12b6d
3 changed files with 127 additions and 108 deletions

View file

@ -1285,7 +1285,7 @@
if (numberOfSubStrings == 2) if (numberOfSubStrings == 2)
{ {
/* select root path *. /* select root path */
if ([[subStrings objectAtIndex: 1] length] == 0) if ([[subStrings objectAtIndex: 1] length] == 0)
{ {
[self scrollColumnsLeftBy: [_browserColumns count]]; [self scrollColumnsLeftBy: [_browserColumns count]];

View file

@ -51,13 +51,18 @@
@implementation NSCell @implementation NSCell
static Class imageClass;
// //
// Class methods // Class methods
// //
+ (void) initialize + (void) initialize
{ {
if (self == [NSCell class]) if (self == [NSCell class])
[self setVersion:1]; {
[self setVersion: 1];
imageClass = [NSImage class];
}
} }
+ (BOOL) prefersTrackingUntilMouseUp + (BOOL) prefersTrackingUntilMouseUp
@ -102,7 +107,7 @@
[self _init]; [self _init];
NSAssert(anImage == nil || [anImage isKindOfClass: [NSImage class]], NSAssert(anImage == nil || [anImage isKindOfClass: imageClass],
NSInvalidArgumentException); NSInvalidArgumentException);
cell_type = NSImageCellType; cell_type = NSImageCellType;
@ -231,7 +236,7 @@
- (void) setImage: (NSImage*)anImage - (void) setImage: (NSImage*)anImage
{ {
NSAssert(anImage == nil || [anImage isKindOfClass: [NSImage class]], NSAssert(anImage == nil || [anImage isKindOfClass: imageClass],
NSInvalidArgumentException); NSInvalidArgumentException);
ASSIGN(cell_image, anImage); ASSIGN(cell_image, anImage);
@ -674,7 +679,7 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView - (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{ {
NSDebugLog (@"NSCell drawWithFrame: inView:"); NSDebugLog (@"NSCell drawWithFrame: inView: ");
// Save last view drawn to // Save last view drawn to
[self setControlView: controlView]; [self setControlView: controlView];
@ -817,8 +822,8 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
- (void) getPeriodicDelay: (float *)delay interval: (float *)interval - (void) getPeriodicDelay: (float *)delay interval: (float *)interval
{ {
*delay = 0.05; *delay = 0.1;
*interval = 0.05; *interval = 0.1;
} }
- (BOOL) startTrackingAt: (NSPoint)startPoint inView: (NSView *)controlView - (BOOL) startTrackingAt: (NSPoint)startPoint inView: (NSView *)controlView
@ -842,18 +847,19 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
ofView: (NSView *)controlView ofView: (NSView *)controlView
untilMouseUp: (BOOL)flag untilMouseUp: (BOOL)flag
{ {
NSApplication *theApp = [NSApplication sharedApplication]; NSApplication *theApp = [NSApplication sharedApplication];
unsigned int event_mask = NSLeftMouseDownMask | NSLeftMouseUpMask | unsigned event_mask = NSLeftMouseDownMask | NSLeftMouseUpMask
NSMouseMovedMask | NSLeftMouseDraggedMask | | NSMouseMovedMask | NSLeftMouseDraggedMask
NSRightMouseDraggedMask; | NSRightMouseDraggedMask;
NSPoint location = [theEvent locationInWindow]; NSPoint location = [theEvent locationInWindow];
NSPoint point = [controlView convertPoint: location fromView: nil]; NSPoint point = [controlView convertPoint: location fromView: nil];
float delay, interval; float delay;
id target = [self target]; float interval;
SEL action = [self action]; id target = [self target];
NSPoint last_point; SEL action = [self action];
BOOL done; NSPoint last_point = point;
BOOL mouseWentUp; BOOL done;
BOOL mouseWentUp;
NSDebugLog(@"NSCell start tracking\n"); NSDebugLog(@"NSCell start tracking\n");
NSDebugLog(@"NSCell tracking in rect %f %f %f %f\n", NSDebugLog(@"NSCell tracking in rect %f %f %f %f\n",
@ -867,14 +873,14 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
if (![controlView mouse: point inRect: cellFrame]) if (![controlView mouse: point inRect: cellFrame])
return NO; // point is not in cell return NO; // point is not in cell
if ([theEvent type] == NSLeftMouseDown && if ((action_mask & NSLeftMouseDownMask)
(action_mask & NSLeftMouseDownMask)) && [theEvent type] == NSLeftMouseDown)
[(NSControl*)controlView sendAction: action to:target]; [(NSControl*)controlView sendAction: action to: target];
if (cell_continuous) if (cell_continuous)
{ {
[self getPeriodicDelay: &delay interval:&interval]; [self getPeriodicDelay: &delay interval: &interval];
[NSEvent startPeriodicEventsAfterDelay: delay withPeriod:interval]; [NSEvent startPeriodicEventsAfterDelay: delay withPeriod: interval];
event_mask |= NSPeriodicMask; event_mask |= NSPeriodicMask;
} }
@ -883,25 +889,44 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
done = NO; done = NO;
while (!done) while (!done)
{ {
NSEventType eventType; NSEventType eventType;
BOOL pointIsInCell; BOOL pointIsInCell;
unsigned periodCount = 0;
last_point = point;
theEvent = [theApp nextEventMatchingMask: event_mask theEvent = [theApp nextEventMatchingMask: event_mask
untilDate: nil untilDate: nil
inMode: NSEventTrackingRunLoopMode inMode: NSEventTrackingRunLoopMode
dequeue: YES]; dequeue: YES];
eventType = [theEvent type]; eventType = [theEvent type];
if (eventType != NSPeriodic) if (eventType != NSPeriodic || periodCount == 4)
{ {
location = [theEvent locationInWindow]; last_point = point;
if (eventType == NSPeriodic)
{
NSWindow *w = [controlView window];
/*
* Too many periodic events in succession -
* update the mouse location and reset the counter.
*/
location = [w mouseLocationOutsideOfEventStream];
periodCount = 0;
}
else
{
location = [theEvent locationInWindow];
}
point = [controlView convertPoint: location fromView: nil]; point = [controlView convertPoint: location fromView: nil];
NSDebugLog(@"NSCell location %f %f\n", location.x, location.y); NSDebugLog(@"NSCell location %f %f\n", location.x, location.y);
NSDebugLog(@"NSCell point %f %f\n", point.x, point.y); NSDebugLog(@"NSCell point %f %f\n", point.x, point.y);
} }
else else
NSDebugLog (@"got a periodic event"); {
periodCount++;
NSDebugLog (@"got a periodic event");
}
if (![controlView mouse: point inRect: cellFrame]) if (![controlView mouse: point inRect: cellFrame])
{ {
NSDebugLog(@"NSCell point not in cell frame\n"); NSDebugLog(@"NSCell point not in cell frame\n");
@ -914,7 +939,9 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
} }
} }
else else
pointIsInCell = YES; {
pointIsInCell = YES;
}
if (!done && ![self continueTracking: last_point // should continue if (!done && ![self continueTracking: last_point // should continue
at: point // tracking? at: point // tracking?
@ -929,9 +956,9 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
NSDebugLog(@"NSCell mouse went up\n"); NSDebugLog(@"NSCell mouse went up\n");
mouseWentUp = YES; mouseWentUp = YES;
done = YES; done = YES;
[self setState:![self state]]; [self setState: ![self state]];
if ((action_mask & NSLeftMouseUpMask)) if ((action_mask & NSLeftMouseUpMask))
[(NSControl*)controlView sendAction: action to:target]; [(NSControl*)controlView sendAction: action to: target];
} }
else else
{ {
@ -939,7 +966,7 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
&& (action_mask & NSLeftMouseDraggedMask)) && (action_mask & NSLeftMouseDraggedMask))
|| ((eventType == NSPeriodic) || ((eventType == NSPeriodic)
&& (action_mask & NSPeriodicMask)))) && (action_mask & NSPeriodicMask))))
[(NSControl*)controlView sendAction: action to:target]; [(NSControl*)controlView sendAction: action to: target];
} }
} }
// Tell ourselves to stop tracking // Tell ourselves to stop tracking
@ -957,9 +984,7 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
return YES; return YES;
} }
#if 1
[controlView setNeedsDisplayInRect: cellFrame]; [controlView setNeedsDisplayInRect: cellFrame];
#endif
NSDebugLog(@"NSCell mouse did not go up in cell\n"); NSDebugLog(@"NSCell mouse did not go up in cell\n");
return NO; // Otherwise return NO return NO; // Otherwise return NO
@ -1089,7 +1114,7 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
// //
@implementation NSCell (GNUstepBackend) @implementation NSCell (GNUstepBackend)
+ (NSSize)sizeForBorderType: (NSBorderType)aType + (NSSize) sizeForBorderType: (NSBorderType)aType
{ {
// Returns the size of a border // Returns the size of a border
switch (aType) switch (aType)

View file

@ -38,50 +38,46 @@
#include <AppKit/NSApplication.h> #include <AppKit/NSApplication.h>
#include <AppKit/NSCell.h> #include <AppKit/NSCell.h>
// /*
// Class variables * Class variables
// */
static id _NSCONTROL_CELL_CLASS = nil; static Class cellClass;
@implementation NSControl @implementation NSControl
// /*
// Class methods * Class methods
// */
+ (void) initialize + (void) initialize
{ {
if (self == [NSControl class]) if (self == [NSControl class])
{ {
NSDebugLog(@"Initialize NSControl class\n"); NSDebugLog(@"Initialize NSControl class\n");
[self setVersion: 1]; [self setVersion: 1];
cellClass = [NSCell class];
} }
} }
// /*
// Setting the Control's Cell * Setting the Control's Cell
// */
+ (Class) cellClass + (Class) cellClass
{ {
return _NSCONTROL_CELL_CLASS; return cellClass;
} }
+ (void) setCellClass: (Class)factoryId + (void) setCellClass: (Class)factoryId
{ {
_NSCONTROL_CELL_CLASS = factoryId; cellClass = factoryId ? factoryId : [NSCell class];
} }
// /*
// Instance methods * Instance methods
// */
- (id) initWithFrame: (NSRect)frameRect - (id) initWithFrame: (NSRect)frameRect
{ {
[super initWithFrame: frameRect]; [super initWithFrame: frameRect];
if (_NSCONTROL_CELL_CLASS) [self setCell: AUTORELEASE([cellClass new])];
[self setCell: [[_NSCONTROL_CELL_CLASS new] autorelease]];
else
[self setCell: [[NSCell new] autorelease]];
tag = 0; tag = 0;
return self; return self;
@ -89,26 +85,26 @@ static id _NSCONTROL_CELL_CLASS = nil;
- (void) dealloc - (void) dealloc
{ {
[cell release]; RELEASE(cell);
[super dealloc]; [super dealloc];
} }
// /*
// Creating copies * Creating copies
// */
- (id) copyWithZone: (NSZone*)zone - (id) copyWithZone: (NSZone*)zone
{ {
id c = NSCopyObject(self, 0, zone); id c = NSCopyObject(self, 0, zone);
NSCell *o = [cell copy]; NSCell *o = [cell copy];
[c setCell: o]; [c setCell: o];
[o release]; RELEASE(o);
return c; return c;
} }
// /*
// Setting the Control's Cell * Setting the Control's Cell
// */
- (id) cell - (id) cell
{ {
return cell; return cell;
@ -123,14 +119,12 @@ static id _NSCONTROL_CELL_CLASS = nil;
[cell setControlView: nil]; [cell setControlView: nil];
[aCell setControlView: self]; [aCell setControlView: self];
[aCell retain]; ASSIGN(ell, aCell);
[cell release];
cell = aCell;
} }
// /*
// Enabling and Disabling the Control * Enabling and Disabling the Control
// */
- (BOOL) isEnabled - (BOOL) isEnabled
{ {
return [[self selectedCell] isEnabled]; return [[self selectedCell] isEnabled];
@ -141,9 +135,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
[[self selectedCell] setEnabled: flag]; [[self selectedCell] setEnabled: flag];
} }
// /*
// Identifying the Selected Cell * Identifying the Selected Cell
// */
- (id) selectedCell - (id) selectedCell
{ {
if ([cell state]) if ([cell state])
@ -157,9 +151,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
return [[self selectedCell] tag]; return [[self selectedCell] tag];
} }
// /*
// Setting the Control's Value * Setting the Control's Value
// */
- (double) doubleValue - (double) doubleValue
{ {
return [[self selectedCell] doubleValue]; return [[self selectedCell] doubleValue];
@ -209,9 +203,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
return [[self selectedCell] stringValue]; return [[self selectedCell] stringValue];
} }
// /*
// Interacting with Other Controls * Interacting with Other Controls
// */
- (void) takeDoubleValueFrom: (id)sender - (void) takeDoubleValueFrom: (id)sender
{ {
[[self selectedCell] takeDoubleValueFrom: sender]; [[self selectedCell] takeDoubleValueFrom: sender];
@ -236,9 +230,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
// /*
// Formatting Text * Formatting Text
// */
- (NSTextAlignment) alignment - (NSTextAlignment) alignment
{ {
if (cell) if (cell)
@ -276,9 +270,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
{ {
} }
// /*
// Managing the Field Editor * Managing the Field Editor
// */
- (BOOL) abortEditing - (BOOL) abortEditing
{ {
return NO; return NO;
@ -293,9 +287,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
{ {
} // FIX ME } // FIX ME
// /*
// Resizing the Control * Resizing the Control
// */
- (void) calcSize - (void) calcSize
{ {
} // FIX ME } // FIX ME
@ -304,9 +298,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
{ {
} }
// /*
// Displaying the Control and Cell * Displaying the Control and Cell
// */
- (void) drawRect: (NSRect)aRect - (void) drawRect: (NSRect)aRect
{ {
[self drawCell: cell]; [self drawCell: cell];
@ -344,9 +338,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
// /*
// Target and Action * Target and Action
// */
- (SEL) action - (SEL) action
{ {
return [cell action]; return [cell action];
@ -392,9 +386,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
return [cell target]; return [cell target];
} }
// /*
// Assigning a Tag * Assigning a Tag
// */
- (void) setTag: (int)anInt - (void) setTag: (int)anInt
{ {
tag = anInt; tag = anInt;
@ -405,9 +399,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
return tag; return tag;
} }
// /*
// Tracking the Mouse * Tracking the Mouse
// */
- (void) mouseDown: (NSEvent *)theEvent - (void) mouseDown: (NSEvent *)theEvent
{ {
NSApplication *theApp = [NSApplication sharedApplication]; NSApplication *theApp = [NSApplication sharedApplication];
@ -493,9 +487,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
{ {
} }
// /*
// Methods Implemented by the Delegate * Methods Implemented by the Delegate
// */
- (BOOL) control: (NSControl *)control - (BOOL) control: (NSControl *)control
textShouldBeginEditing: (NSText *)fieldEditor textShouldBeginEditing: (NSText *)fieldEditor
{ {
@ -520,9 +514,9 @@ static id _NSCONTROL_CELL_CLASS = nil;
{ {
} }
// /*
// NSCoding protocol * NSCoding protocol
// */
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];