* 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,11 +284,11 @@ 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
// //
@ -50,15 +52,9 @@
+ (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;
@ -67,10 +63,6 @@
// //
// Instance methods // Instance methods
// //
//
// Initializing an NSCell
//
- _init - _init
{ {
cell_type = NSNullCellType; cell_type = NSNullCellType;
@ -105,9 +97,8 @@
[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];
@ -180,49 +171,30 @@
// //
// 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
{ {
@ -236,25 +208,10 @@
// //
// 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
{ {
@ -315,43 +272,20 @@ NSString* _string;
// //
// 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
{ {
@ -364,38 +298,62 @@ NSString* _string;
- (void)setSelectable:(BOOL)flag - (void)setSelectable:(BOOL)flag
{ {
cell_selectable = flag; cell_selectable = flag;
// If its not selectable then its not editable
if (!flag)
cell_editable = NO;
}
- (void)setScrollable:(BOOL)flag if (!flag) // If cell is not
{ cell_editable = NO; // selectable then it's
cell_scrollable = flag; } // not editable
}
- (void)setScrollable:(BOOL)flag { cell_scrollable = flag; }
- (void)setWraps:(BOOL)flag {}
- (BOOL)wraps { return NO; }
//
// Editing Text
//
- (NSText *)setUpFieldEditorAttributes:(NSText *)textObject - (NSText *)setUpFieldEditorAttributes:(NSText *)textObject
{ {
return nil; return nil;
} }
- (void)setWraps:(BOOL)flag
{}
- (BOOL)wraps
{
return NO;
}
//
// Editing Text
//
- (void)editWithFrame:(NSRect)aRect - (void)editWithFrame:(NSRect)aRect
inView:(NSView *)controlView inView:(NSView *)controlView
editor:(NSText *)textObject editor:(NSText *)textObject
delegate:(id)anObject delegate:(id)anObject
event:(NSEvent *)theEvent 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];
@ -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,8 +388,11 @@ id nextResponder;
return YES; return YES;
} }
- (BOOL)textShouldEndEditing:(NSText *)textObject - (BOOL)textShouldEndEditing:(NSText *)aTextObject // NSText(field editor)
{ { // delegate method
[cell endEditing:aTextObject];
fprintf(stderr, " TextField textShouldEndEditing --- ");
return YES; 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;