Added editing methods.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20125 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2004-09-24 16:35:41 +00:00
parent 54da49bd72
commit e13699f905
3 changed files with 81 additions and 9 deletions

View file

@ -1,3 +1,11 @@
2004-09-24 Fred Kiefer <FredKiefer@gmx.de>
* 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 <FredKiefer@gmx.de>
* Source/NSMenuView.m (-setMenu:): Only call update when the new

View file

@ -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

View file

@ -31,13 +31,15 @@
#include <Foundation/NSDebug.h>
#include <Foundation/NSException.h>
#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];