* NSCell.m acceptsFirstResponder implement, editWithFrame: adjust further,

selectWithFrame: preliminary implementation.
	* NSButton.m: acceptsFirstResponder implement.
	* NSText.m: shouldDrawInsertionPoint test for field editor status.
	* NSTextField.m: mouseDown: use field editor instead of previous non OS
	text field cell editor code, textShouldEndEditing: implement.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3466 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
far 1998-12-16 11:48:33 +00:00
parent bf5137b858
commit cb3439381e
7 changed files with 238 additions and 247 deletions

View file

@ -1,3 +1,12 @@
Wed Dec 16 1998 Felipe A. Rodriguez <far@ix.netcom.com>
* NSCell.m acceptsFirstResponder implement, editWithFrame: adjust further,
selectWithFrame: preliminary implementation.
* NSButton.m: acceptsFirstResponder implement.
* NSText.m: shouldDrawInsertionPoint test for field editor status.
* NSTextField.m: mouseDown: use field editor instead of previous non OS
text field cell editor code, textShouldEndEditing: implement.
Tue Dec 15 16:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk> Tue Dec 15 16:30:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* NSApplication.m: Terminate modal loop if the window goes away. * NSApplication.m: Terminate modal loop if the window goes away.

View file

@ -284,12 +284,12 @@ id gnustep_gui_nsbutton_class = nil;
} }
// //
// Handling Events and Action Messages // Determining the first responder
// //
- (BOOL)acceptsFirstResponder - (BOOL)acceptsFirstResponder
{ {
return [self keyEquivalent] != nil;; return [cell acceptsFirstResponder] && ([self keyEquivalent] != nil);
} }
- (void) keyDown: (NSEvent*)theEvent - (void) keyDown: (NSEvent*)theEvent
{ {
@ -297,6 +297,10 @@ id gnustep_gui_nsbutton_class = nil;
[super keyDown: theEvent]; [super keyDown: theEvent];
} }
//
// Handling Events and Action Messages
//
- (void) performClick: (id)sender - (void) performClick: (id)sender
{ {
[cell performClick: sender]; [cell performClick: sender];

View file

@ -42,6 +42,8 @@
#include <AppKit/NSCell.h> #include <AppKit/NSCell.h>
#include <AppKit/NSEvent.h> #include <AppKit/NSEvent.h>
@implementation NSCell @implementation NSCell
// //
@ -49,101 +51,90 @@
// //
+ (void)initialize + (void)initialize
{ {
if (self == [NSCell class]) if (self == [NSCell class])
{
// Initial version
[self setVersion:1]; [self setVersion:1];
}
} }
//
// Tracking the Mouse
//
+ (BOOL)prefersTrackingUntilMouseUp + (BOOL)prefersTrackingUntilMouseUp
{ {
return NO; return NO;
} }
// //
// Instance methods // Instance methods
// //
//
// Initializing an NSCell
//
- _init - _init
{ {
cell_type = NSNullCellType; cell_type = NSNullCellType;
cell_image = nil; cell_image = nil;
cell_font = nil; cell_font = nil;
image_position = NSNoImage; image_position = NSNoImage;
cell_state = NO; cell_state = NO;
cell_highlighted = NO; cell_highlighted = NO;
cell_enabled = YES; cell_enabled = YES;
cell_editable = NO; cell_editable = NO;
cell_bordered = NO; cell_bordered = NO;
cell_bezeled = NO; cell_bezeled = NO;
cell_scrollable = NO; cell_scrollable = NO;
cell_selectable = NO; cell_selectable = NO;
cell_continuous = NO; cell_continuous = NO;
cell_float_autorange = NO; cell_float_autorange = NO;
cell_float_left = 0; cell_float_left = 0;
cell_float_right = 0; cell_float_right = 0;
action_mask = NSLeftMouseUpMask; action_mask = NSLeftMouseUpMask;
return self; return self;
} }
- init - init
{ {
return [self initTextCell:@""]; return [self initTextCell:@""];
} }
- (id)initImageCell:(NSImage *)anImage - (id)initImageCell:(NSImage *)anImage
{ {
[super init]; [super init];
[self _init]; [self _init];
// Not an image class --then forget it if (![anImage isKindOfClass:[NSImage class]]) // image must be an
if (![anImage isKindOfClass:[NSImage class]]) return nil; // NSImage
return nil;
cell_type = NSImageCellType;
cell_type = NSImageCellType; cell_image = [anImage retain];
cell_image = [anImage retain]; image_position = NSImageOnly;
image_position = NSImageOnly; cell_font = [[NSFont userFontOfSize:0] retain];
cell_font = [[NSFont userFontOfSize:0] retain];
return self;
return self;
} }
- (id)initTextCell:(NSString *)aString - (id)initTextCell:(NSString *)aString
{ {
[super init]; [super init];
[self _init]; [self _init];
cell_font = [[NSFont userFontOfSize:0] retain]; cell_font = [[NSFont userFontOfSize:0] retain];
contents = [aString retain]; contents = [aString retain];
cell_type = NSTextCellType; cell_type = NSTextCellType;
text_align = NSCenterTextAlignment; text_align = NSCenterTextAlignment;
cell_float_autorange = YES; cell_float_autorange = YES;
cell_float_right = 6; cell_float_right = 6;
return self; return self;
} }
- (void)dealloc - (void)dealloc
{ {
if(contents) if(contents)
[contents release]; [contents release];
if(cell_image) if(cell_image)
[cell_image release]; [cell_image release];
[cell_font release]; [cell_font release];
if(represented_object) if(represented_object)
[represented_object release]; [represented_object release];
[super dealloc]; [super dealloc];
} }
// //
@ -154,127 +145,93 @@
- (NSSize)cellSize - (NSSize)cellSize
{ {
return NSZeroSize; return NSZeroSize;
} }
- (NSSize)cellSizeForBounds:(NSRect)aRect - (NSSize)cellSizeForBounds:(NSRect)aRect
{ {
return NSZeroSize; return NSZeroSize;
} }
- (NSRect)drawingRectForBounds:(NSRect)theRect - (NSRect)drawingRectForBounds:(NSRect)theRect
{ {
return NSZeroRect; return NSZeroRect;
} }
- (NSRect)imageRectForBounds:(NSRect)theRect - (NSRect)imageRectForBounds:(NSRect)theRect
{ {
return NSZeroRect; return NSZeroRect;
} }
- (NSRect)titleRectForBounds:(NSRect)theRect - (NSRect)titleRectForBounds:(NSRect)theRect
{ {
return NSZeroRect; return NSZeroRect;
} }
// //
// Setting the NSCell's Type // Setting the NSCell's Type
// //
- (void)setType:(NSCellType)aType - (void)setType:(NSCellType)aType { cell_type = aType; }
{ - (NSCellType)type { return cell_type; }
cell_type = aType;
}
- (NSCellType)type
{
return cell_type;
}
// //
// Setting the NSCell's State // Setting the NSCell's State
// //
- (void)setState:(int)value - (void)setState:(int)value { cell_state = value; }
{ - (int)state { return cell_state; }
cell_state = value;
}
- (int)state
{
return cell_state;
}
// //
// Enabling and Disabling the NSCell // Enabling and Disabling the NSCell
// //
- (BOOL)isEnabled - (BOOL)isEnabled { return cell_enabled; }
{ - (void)setEnabled:(BOOL)flag { cell_enabled = flag; }
return cell_enabled;
}
- (void)setEnabled:(BOOL)flag //
{ // Determining the first responder
cell_enabled = flag; //
} - (BOOL)acceptsFirstResponder { return cell_enabled; }
// //
// Setting the Image // Setting the Image
// //
- (NSImage *)image - (NSImage *)image { return cell_image; }
{
return cell_image;
}
- (void)setImage:(NSImage *)anImage - (void)setImage:(NSImage *)anImage
{ {
if (![anImage isKindOfClass:[NSImage class]]) // set the image only if (![anImage isKindOfClass:[NSImage class]]) // set the image only
return; // if it's an NSImage return; // if it's an NSImage
ASSIGN(cell_image, anImage); ASSIGN(cell_image, anImage);
[self setType:NSImageCellType]; [self setType:NSImageCellType];
} }
// //
// Setting the NSCell's Value // Setting the NSCell's Value
// //
- (double)doubleValue - (double)doubleValue { return [contents doubleValue]; }
{ - (float)floatValue; { return [contents floatValue]; }
return [contents doubleValue]; - (int)intValue { return [contents intValue]; }
} - (NSString *)stringValue { return contents; }
- (float)floatValue;
{
return [contents floatValue];
}
- (int)intValue
{
return [contents intValue];
}
- (NSString *)stringValue
{
return contents;
}
- (void)setDoubleValue:(double)aDouble - (void)setDoubleValue:(double)aDouble
{ {
NSString* number_string = [[NSNumber numberWithDouble:aDouble] stringValue]; NSString* number_string = [[NSNumber numberWithDouble:aDouble] stringValue];
ASSIGN(contents, number_string); ASSIGN(contents, number_string);
} }
- (void)setFloatValue:(float)aFloat - (void)setFloatValue:(float)aFloat
{ {
NSString* number_string = [[NSNumber numberWithFloat:aFloat] stringValue]; NSString* number_string = [[NSNumber numberWithFloat:aFloat] stringValue];
ASSIGN(contents, number_string); ASSIGN(contents, number_string);
} }
- (void)setIntValue:(int)anInt - (void)setIntValue:(int)anInt
{ {
NSString* number_string = [[NSNumber numberWithInt:anInt] stringValue]; NSString* number_string = [[NSNumber numberWithInt:anInt] stringValue];
ASSIGN(contents, number_string); ASSIGN(contents, number_string);
} }
- (void)setStringValue:(NSString *)aString - (void)setStringValue:(NSString *)aString
@ -294,108 +251,109 @@ NSString* _string;
// //
- (void)takeDoubleValueFrom:(id)sender - (void)takeDoubleValueFrom:(id)sender
{ {
[self setDoubleValue:[sender doubleValue]]; [self setDoubleValue:[sender doubleValue]];
} }
- (void)takeFloatValueFrom:(id)sender - (void)takeFloatValueFrom:(id)sender
{ {
[self setFloatValue:[sender floatValue]]; [self setFloatValue:[sender floatValue]];
} }
- (void)takeIntValueFrom:(id)sender - (void)takeIntValueFrom:(id)sender
{ {
[self setIntValue:[sender intValue]]; [self setIntValue:[sender intValue]];
} }
- (void)takeStringValueFrom:(id)sender - (void)takeStringValueFrom:(id)sender
{ {
[self setStringValue:[sender stringValue]]; [self setStringValue:[sender stringValue]];
} }
// //
// Modifying Text Attributes // Modifying Text Attributes
// //
- (NSTextAlignment)alignment - (NSTextAlignment)alignment { return text_align; }
{ - (NSFont *)font { return cell_font; }
return text_align; - (BOOL)isEditable { return cell_editable; }
} - (BOOL)isSelectable { return cell_selectable; }
- (BOOL)isScrollable { return cell_scrollable; }
- (NSFont *)font - (void)setAlignment:(NSTextAlignment)mode { text_align = mode; }
{
return cell_font;
}
- (BOOL)isEditable
{
return cell_editable;
}
- (BOOL)isSelectable
{
return cell_selectable;
}
- (BOOL)isScrollable
{
return cell_scrollable;
}
- (void)setAlignment:(NSTextAlignment)mode
{
text_align = mode;
}
- (void)setEditable:(BOOL)flag - (void)setEditable:(BOOL)flag
{ {
cell_editable = flag; cell_editable = flag;
// If its editable then its selectable
if (flag) if (flag) // If cell is not
cell_selectable = flag; cell_selectable = flag; // selectable then it's
} } // not editable
- (void)setFont:(NSFont *)fontObject - (void)setFont:(NSFont *)fontObject
{ {
if (![fontObject isKindOfClass:[NSFont class]]) // set the font only if (![fontObject isKindOfClass:[NSFont class]]) // set the font only
return; // if it's an NSFont return; // if it's an NSFont
ASSIGN(cell_font, fontObject); ASSIGN(cell_font, fontObject);
} }
- (void)setSelectable:(BOOL)flag - (void)setSelectable:(BOOL)flag
{ {
cell_selectable = flag; cell_selectable = flag;
// If its not selectable then its not editable
if (!flag) if (!flag) // If cell is not
cell_editable = NO; cell_editable = NO; // selectable then it's
} } // not editable
- (void)setScrollable:(BOOL)flag - (void)setScrollable:(BOOL)flag { cell_scrollable = flag; }
{ - (void)setWraps:(BOOL)flag {}
cell_scrollable = flag; - (BOOL)wraps { return NO; }
}
- (NSText *)setUpFieldEditorAttributes:(NSText *)textObject
{
return nil;
}
- (void)setWraps:(BOOL)flag
{}
- (BOOL)wraps
{
return NO;
}
// //
// Editing Text // Editing Text
// //
- (void)editWithFrame:(NSRect)aRect - (NSText *)setUpFieldEditorAttributes:(NSText *)textObject
inView:(NSView *)controlView
editor:(NSText *)textObject
delegate:(id)anObject
event:(NSEvent *)theEvent
{ {
return nil;
}
- (void)editWithFrame:(NSRect)aRect
inView:(NSView *)controlView
editor:(NSText *)textObject
delegate:(id)anObject
event:(NSEvent *)theEvent
{
if(cell_type != NSTextCellType)
return;
[[controlView window] makeFirstResponder:textObject];
[textObject setFrame:aRect];
[textObject setText:[self stringValue]];
[textObject setDelegate:anObject];
[controlView addSubview:textObject];
[controlView lockFocus];
NSEraseRect(aRect);
[controlView unlockFocus];
[textObject display];
}
- (void)endEditing:(NSText *)textObject // editing is complete,
{ // remove the text obj
[textObject removeFromSuperview]; // acting as the field
[self setStringValue: [textObject text]]; // editor from window's
[textObject setDelegate:nil]; // view heirarchy, set
} // our contents from it
- (void)selectWithFrame:(NSRect)aRect
inView:(NSView *)controlView
editor:(NSText *)textObject
delegate:(id)anObject
start:(int)selStart
length:(int)selLength
{ // preliminary FIX ME
if(!controlView || !textObject || !cell_font ||
(cell_type != NSTextCellType))
return;
[[controlView window] makeFirstResponder:textObject]; [[controlView window] makeFirstResponder:textObject];
[textObject setFrame:aRect]; [textObject setFrame:aRect];
@ -406,21 +364,6 @@ NSString* _string;
[textObject display]; [textObject display];
} }
- (void)endEditing:(NSText *)textObject
{
[textObject removeFromSuperview];
[self setStringValue: [textObject text]];
[textObject setDelegate:nil];
}
- (void)selectWithFrame:(NSRect)aRect
inView:(NSView *)controlView
editor:(NSText *)textObject
delegate:(id)anObject
start:(int)selStart
length:(int)selLength
{}
// //
// Validating Input // Validating Input
// //

View file

@ -41,8 +41,9 @@
@implementation NSSplitView @implementation NSSplitView
/* API Methods */ //
// Instance methods
//
- (void)mouseDown:(NSEvent *)theEvent - (void)mouseDown:(NSEvent *)theEvent
{ {
NSApplication *app = [NSApplication sharedApplication]; NSApplication *app = [NSApplication sharedApplication];

View file

@ -794,7 +794,7 @@ typedef enum
-(BOOL) shouldDrawInsertionPoint -(BOOL) shouldDrawInsertionPoint
{ return ([self selectedRange].length==0) && [self isEditable]; { return ([self selectedRange].length==0) && [self isEditable] && (![self isFieldEditor]);
} }
-(void) drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag -(void) drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag
{ if(flag) { if(flag)

View file

@ -45,7 +45,7 @@
// //
// class variables // class variables
// //
id gnustep_gui_nstextfield_cell_class = nil; id _nsTextfieldCellClass = nil;
// //
// Class methods // Class methods
@ -62,15 +62,8 @@ id gnustep_gui_nstextfield_cell_class = nil;
// //
// Initializing the NSTextField Factory // Initializing the NSTextField Factory
// //
+ (Class)cellClass + (Class)cellClass { return _nsTextfieldCellClass; }
{ + (void)setCellClass:(Class)classId { _nsTextfieldCellClass = classId; }
return gnustep_gui_nstextfield_cell_class;
}
+ (void)setCellClass:(Class)classId
{
gnustep_gui_nstextfield_cell_class = classId;
}
// //
// Instance methods // Instance methods
@ -84,7 +77,7 @@ id gnustep_gui_nstextfield_cell_class = nil;
{ {
[super initWithFrame:frameRect]; [super initWithFrame:frameRect];
// set our cell // set our cell
[self setCell:[[gnustep_gui_nstextfield_cell_class new] autorelease]]; [self setCell:[[_nsTextfieldCellClass new] autorelease]];
[cell setState:1]; [cell setState:1];
text_cursor = [[NSCursor IBeamCursor] retain]; text_cursor = [[NSCursor IBeamCursor] retain];
@ -120,7 +113,7 @@ id c;
// //
// Setting User Access to Text // Setting User Access to Text
// //
- (BOOL)isEditable { return [cell isEditable]; } - (BOOL)isEditable { return [cell isEditable]; }
- (BOOL)isSelectable { return [cell isSelectable]; } - (BOOL)isSelectable { return [cell isSelectable]; }
- (void)setEditable:(BOOL)flag { [cell setEditable:flag]; } - (void)setEditable:(BOOL)flag { [cell setEditable:flag]; }
- (void)setSelectable:(BOOL)flag { [cell setSelectable:flag]; } - (void)setSelectable:(BOOL)flag { [cell setSelectable:flag]; }
@ -219,22 +212,60 @@ id t;
// //
- (void)mouseDown:(NSEvent *)theEvent - (void)mouseDown:(NSEvent *)theEvent
{ {
NSPoint location; NSRect cellFrame = bounds;
// If not selectable then // If not selectable then
if (![self isSelectable]) // don't recognize the if (![self isSelectable]) // don't recognize the
return; // mouse down return; // mouse down
fprintf(stderr, " TextField mouseDown --- "); fprintf(stderr, " TextField mouseDown --- ");
location = [self convertPoint:[theEvent locationInWindow] fromView:nil]; // location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
[self lockFocus]; // [self lockFocus];
[[self cell] _setCursorLocation:location]; // cellFrame = [self convertRect:frame toView:nil];
[[self cell] _setCursorVisibility: YES]; // cellFrame.origin = [super_view convertPoint:frame.origin
[cell drawWithFrame:bounds inView:self]; // toView:[window contentView]];
[window flushWindow];
[self unlockFocus]; if ([cell isBordered]) // draw the border if
if ([[self window] makeFirstResponder:self]) { // needed.
[self setNeedsDisplay:YES]; if ([cell isBezeled])
{
cellFrame.origin.x += 4;
cellFrame.origin.y += 2;
cellFrame.size.width -= 6;
cellFrame.size.height -= 4;
}
else
{
cellFrame.origin.x += 1;
cellFrame.origin.y += 1;
cellFrame.size.width -= 2;
cellFrame.size.height -= 2;
}
}
// set field editor to
fprintf (stderr,
"XRTextField 0: rect origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
frame.origin.x, frame.origin.y,
frame.size.width, frame.size.height);
fprintf (stderr,
"XRTextField 1: rect origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
cellFrame.origin.x, cellFrame.origin.y,
cellFrame.size.width, cellFrame.size.height);
[cell editWithFrame:cellFrame
inView:self
editor:[window fieldEditor:YES forObject:cell]
delegate:self
event:theEvent];
// [[self cell] _setCursorLocation:location];
// [[self cell] _setCursorVisibility: YES];
// [cell drawWithFrame:bounds inView:self];
// [window flushWindow];
// [self unlockFocus];
// if ([[self window] makeFirstResponder:self])
// [self setNeedsDisplay:YES];
} }
- (void)mouseUp:(NSEvent *)theEvent - (void)mouseUp:(NSEvent *)theEvent
@ -357,9 +388,12 @@ id nextResponder;
return YES; return YES;
} }
- (BOOL)textShouldEndEditing:(NSText *)textObject - (BOOL)textShouldEndEditing:(NSText *)aTextObject // NSText(field editor)
{ { // delegate method
return YES; [cell endEditing:aTextObject];
fprintf(stderr, " TextField textShouldEndEditing --- ");
return YES;
} }
// //

View file

@ -309,10 +309,10 @@ NSView *wv;
@selector(windowWillReturnFieldEditor:toObject:)]) @selector(windowWillReturnFieldEditor:toObject:)])
return [delegate windowWillReturnFieldEditor:self toObject:anObject]; return [delegate windowWillReturnFieldEditor:self toObject:anObject];
if (!_fieldEditor && createFlag) // each window has a global if(!_fieldEditor && createFlag) // each window has a global
{ // text field editor { // text field editor, if it
_fieldEditor = [[NSText new] retain]; _fieldEditor = [[NSText new] retain]; // doesn't exist create it
[_fieldEditor setFieldEditor:YES]; [_fieldEditor setFieldEditor:YES]; // if create flag is set
} }
return _fieldEditor; return _fieldEditor;