diff --git a/ChangeLog b/ChangeLog index 89201ebe8..1797db068 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-09-24 Fred Kiefer + + * Headers/AppKit/NSControl.h + Added new MacOSX delegate methods. + * Source/NSControl.m (-validateEditing, -currentEditor, + -abortEditing, -calcSize): Implemented these methods. + (-mouseDown:): Use method to check if mouse is inside cell. + 2004-09-24 Fred Kiefer * Source/NSMenuView.m (-setMenu:): Only call update when the new diff --git a/Headers/AppKit/NSControl.h b/Headers/AppKit/NSControl.h index 32f8b7c7d..a1ab6900a 100644 --- a/Headers/AppKit/NSControl.h +++ b/Headers/AppKit/NSControl.h @@ -38,6 +38,7 @@ @class NSCell; @class NSFont; @class NSEvent; +@class NSTextView; @interface NSControl : NSView { @@ -186,6 +187,8 @@ APPKIT_EXPORT NSString *NSControlTextDidChangeNotification; // Methods Implemented by the Delegate // @interface NSObject (NSControlDelegate) +- (BOOL) control: (NSControl *)control isValidObject:(id)object; + - (BOOL) control: (NSControl *)control textShouldBeginEditing: (NSText *)fieldEditor; @@ -206,7 +209,18 @@ APPKIT_EXPORT NSString *NSControlTextDidChangeNotification; didFailToValidatePartialString: (NSString *)string errorDescription: (NSString *)error; -- (BOOL) control: (NSControl *)control isValidObject:(id)object; +#ifndef STRICT_OPENSTEP +- (BOOL) control: (NSControl *)control + textView: (NSTextView *)textView + doCommandBySelector: (SEL)command; + +- (NSArray *) control: (NSControl *)control + textView: (NSTextView *)textView + completions: (NSArray *)words + forPartialWordRange: (NSRange)charRange + indexOfSelectedItem: (int *)index; +#endif + @end diff --git a/Source/NSControl.m b/Source/NSControl.m index a083db7c5..7980ca23e 100644 --- a/Source/NSControl.m +++ b/Source/NSControl.m @@ -31,13 +31,15 @@ #include #include +#include "AppKit/NSActionCell.h" +#include "AppKit/NSApplication.h" +#include "AppKit/NSCell.h" #include "AppKit/NSControl.h" #include "AppKit/NSColor.h" #include "AppKit/NSEvent.h" +#include "AppKit/NSTextStorage.h" +#include "AppKit/NSTextView.h" #include "AppKit/NSWindow.h" -#include "AppKit/NSApplication.h" -#include "AppKit/NSCell.h" -#include "AppKit/NSActionCell.h" /* * Class variables @@ -344,23 +346,71 @@ static Class actionCellClass; */ - (BOOL) abortEditing { - return NO; + NSText *t; + + t = [self currentEditor]; + if (t == nil) + { + return NO; + } + + [t setString: @""]; + [[self selectedCell] endEditing: t]; + return YES; } - (NSText *) currentEditor { + if (_cell != nil) + { + NSText *t; + + t = [_window fieldEditor: NO forObject: self]; + if (([t delegate] == self) && ([_window firstResponder] == t)) + { + return t; + } + } + return nil; } - (void) validateEditing { -} + NSText *t; + + t = [self currentEditor]; + if (t == nil) + { + return; + } + + if ([t isRichText]) + { + NSAttributedString *attr; + NSTextStorage *storage; + int len; + + storage = [(NSTextView*)t textStorage]; + len = [storage length]; + attr = [storage attributedSubstringFromRange: NSMakeRange(0, len)]; + [[self selectedCell] setAttributedStringValue: attr]; + } + else + { + NSString *string; + + string = AUTORELEASE([[t string] copy]); + [[self selectedCell] setStringValue: string]; + } +} /* * Resizing the Control */ - (void) calcSize { + [_cell calcDrawInfo: [self bounds]]; } - (void) sizeToFit @@ -570,14 +620,14 @@ static Class actionCellClass; [_window _captureMouse: self]; e = theEvent; - while (!done) // loop until mouse goes up + // loop until mouse goes up + while (!done) { location = [e locationInWindow]; location = [self convertPoint: location fromView: nil]; // ask the cell to track the mouse only // if the mouse is within the cell - if ((location.x >= 0) && (location.x < _bounds.size.width) && - (location.y >= 0 && location.y < _bounds.size.height)) + if ([self mouse: location inRect: _bounds]) { [_cell setHighlighted: YES]; [self setNeedsDisplay: YES];