* 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>
* 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
{
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
//
@ -50,15 +52,9 @@
+ (void)initialize
{
if (self == [NSCell class])
{
// Initial version
[self setVersion:1];
}
}
//
// Tracking the Mouse
//
+ (BOOL)prefersTrackingUntilMouseUp
{
return NO;
@ -67,10 +63,6 @@
//
// Instance methods
//
//
// Initializing an NSCell
//
- _init
{
cell_type = NSNullCellType;
@ -105,9 +97,8 @@
[self _init];
// Not an image class --then forget it
if (![anImage isKindOfClass:[NSImage class]])
return nil;
if (![anImage isKindOfClass:[NSImage class]]) // image must be an
return nil; // NSImage
cell_type = NSImageCellType;
cell_image = [anImage retain];
@ -180,49 +171,30 @@
//
// 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
{
@ -236,25 +208,10 @@
//
// 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
{
@ -315,43 +272,20 @@ NSString* _string;
//
// 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;
}
if (flag) // If cell is not
cell_selectable = flag; // selectable then it's
} // not editable
- (void)setFont:(NSFont *)fontObject
{
@ -364,38 +298,62 @@ NSString* _string;
- (void)setSelectable:(BOOL)flag
{
cell_selectable = flag;
// If its not selectable then its not editable
if (!flag)
cell_editable = NO;
}
- (void)setScrollable:(BOOL)flag
{
cell_scrollable = flag;
}
if (!flag) // If cell is not
cell_editable = NO; // selectable then it's
} // not editable
- (void)setScrollable:(BOOL)flag { cell_scrollable = flag; }
- (void)setWraps:(BOOL)flag {}
- (BOOL)wraps { return NO; }
//
// Editing Text
//
- (NSText *)setUpFieldEditorAttributes:(NSText *)textObject
{
return nil;
}
- (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
{
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];
@ -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,8 +388,11 @@ id nextResponder;
return YES;
}
- (BOOL)textShouldEndEditing:(NSText *)textObject
{
- (BOOL)textShouldEndEditing:(NSText *)aTextObject // NSText(field editor)
{ // delegate method
[cell endEditing:aTextObject];
fprintf(stderr, " TextField textShouldEndEditing --- ");
return YES;
}

View file

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