* 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:
Felipe A. Rodriguez 1998-12-16 11:48:33 +00:00
parent 9b25f83278
commit 1551c447ac
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>
* 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
{
return [self keyEquivalent] != nil;;
}
{
return [cell acceptsFirstResponder] && ([self keyEquivalent] != nil);
}
- (void) keyDown: (NSEvent*)theEvent
{
@ -297,6 +297,10 @@ id gnustep_gui_nsbutton_class = nil;
[super keyDown: theEvent];
}
//
// Handling Events and Action Messages
//
- (void) performClick: (id)sender
{
[cell performClick: sender];

View file

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

View file

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

View file

@ -794,7 +794,7 @@ typedef enum
-(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
{ if(flag)

View file

@ -45,7 +45,7 @@
//
// class variables
//
id gnustep_gui_nstextfield_cell_class = nil;
id _nsTextfieldCellClass = nil;
//
// Class methods
@ -62,15 +62,8 @@ id gnustep_gui_nstextfield_cell_class = nil;
//
// Initializing the NSTextField Factory
//
+ (Class)cellClass
{
return gnustep_gui_nstextfield_cell_class;
}
+ (void)setCellClass:(Class)classId
{
gnustep_gui_nstextfield_cell_class = classId;
}
+ (Class)cellClass { return _nsTextfieldCellClass; }
+ (void)setCellClass:(Class)classId { _nsTextfieldCellClass = classId; }
//
// Instance methods
@ -84,7 +77,7 @@ id gnustep_gui_nstextfield_cell_class = nil;
{
[super initWithFrame:frameRect];
// set our cell
[self setCell:[[gnustep_gui_nstextfield_cell_class new] autorelease]];
[self setCell:[[_nsTextfieldCellClass new] autorelease]];
[cell setState:1];
text_cursor = [[NSCursor IBeamCursor] retain];
@ -120,7 +113,7 @@ id c;
//
// Setting User Access to Text
//
- (BOOL)isEditable { return [cell isEditable]; }
- (BOOL)isEditable { return [cell isEditable]; }
- (BOOL)isSelectable { return [cell isSelectable]; }
- (void)setEditable:(BOOL)flag { [cell setEditable:flag]; }
- (void)setSelectable:(BOOL)flag { [cell setSelectable:flag]; }
@ -219,22 +212,60 @@ id t;
//
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint location;
NSRect cellFrame = bounds;
// If not selectable then
if (![self isSelectable]) // don't recognize the
return; // mouse down
fprintf(stderr, " TextField mouseDown --- ");
location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
[self lockFocus];
[[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];
// location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
// [self lockFocus];
// cellFrame = [self convertRect:frame toView:nil];
// cellFrame.origin = [super_view convertPoint:frame.origin
// toView:[window contentView]];
if ([cell isBordered]) // draw the border if
{ // needed.
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
@ -357,9 +388,12 @@ id nextResponder;
return YES;
}
- (BOOL)textShouldEndEditing:(NSText *)textObject
{
return YES;
- (BOOL)textShouldEndEditing:(NSText *)aTextObject // NSText(field editor)
{ // delegate method
[cell endEditing:aTextObject];
fprintf(stderr, " TextField textShouldEndEditing --- ");
return YES;
}
//

View file

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