mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 20:11:55 +00:00
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:
parent
7e1492f50b
commit
dba0576537
3 changed files with 81 additions and 9 deletions
|
@ -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>
|
2004-09-24 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSMenuView.m (-setMenu:): Only call update when the new
|
* Source/NSMenuView.m (-setMenu:): Only call update when the new
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
@class NSCell;
|
@class NSCell;
|
||||||
@class NSFont;
|
@class NSFont;
|
||||||
@class NSEvent;
|
@class NSEvent;
|
||||||
|
@class NSTextView;
|
||||||
|
|
||||||
@interface NSControl : NSView
|
@interface NSControl : NSView
|
||||||
{
|
{
|
||||||
|
@ -186,6 +187,8 @@ APPKIT_EXPORT NSString *NSControlTextDidChangeNotification;
|
||||||
// Methods Implemented by the Delegate
|
// Methods Implemented by the Delegate
|
||||||
//
|
//
|
||||||
@interface NSObject (NSControlDelegate)
|
@interface NSObject (NSControlDelegate)
|
||||||
|
- (BOOL) control: (NSControl *)control isValidObject:(id)object;
|
||||||
|
|
||||||
- (BOOL) control: (NSControl *)control
|
- (BOOL) control: (NSControl *)control
|
||||||
textShouldBeginEditing: (NSText *)fieldEditor;
|
textShouldBeginEditing: (NSText *)fieldEditor;
|
||||||
|
|
||||||
|
@ -206,7 +209,18 @@ APPKIT_EXPORT NSString *NSControlTextDidChangeNotification;
|
||||||
didFailToValidatePartialString: (NSString *)string
|
didFailToValidatePartialString: (NSString *)string
|
||||||
errorDescription: (NSString *)error;
|
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
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,15 @@
|
||||||
|
|
||||||
#include <Foundation/NSDebug.h>
|
#include <Foundation/NSDebug.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
|
#include "AppKit/NSActionCell.h"
|
||||||
|
#include "AppKit/NSApplication.h"
|
||||||
|
#include "AppKit/NSCell.h"
|
||||||
#include "AppKit/NSControl.h"
|
#include "AppKit/NSControl.h"
|
||||||
#include "AppKit/NSColor.h"
|
#include "AppKit/NSColor.h"
|
||||||
#include "AppKit/NSEvent.h"
|
#include "AppKit/NSEvent.h"
|
||||||
|
#include "AppKit/NSTextStorage.h"
|
||||||
|
#include "AppKit/NSTextView.h"
|
||||||
#include "AppKit/NSWindow.h"
|
#include "AppKit/NSWindow.h"
|
||||||
#include "AppKit/NSApplication.h"
|
|
||||||
#include "AppKit/NSCell.h"
|
|
||||||
#include "AppKit/NSActionCell.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class variables
|
* Class variables
|
||||||
|
@ -344,23 +346,71 @@ static Class actionCellClass;
|
||||||
*/
|
*/
|
||||||
- (BOOL) abortEditing
|
- (BOOL) abortEditing
|
||||||
{
|
{
|
||||||
return NO;
|
NSText *t;
|
||||||
|
|
||||||
|
t = [self currentEditor];
|
||||||
|
if (t == nil)
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
[t setString: @""];
|
||||||
|
[[self selectedCell] endEditing: t];
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSText *) currentEditor
|
- (NSText *) currentEditor
|
||||||
{
|
{
|
||||||
|
if (_cell != nil)
|
||||||
|
{
|
||||||
|
NSText *t;
|
||||||
|
|
||||||
|
t = [_window fieldEditor: NO forObject: self];
|
||||||
|
if (([t delegate] == self) && ([_window firstResponder] == t))
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) validateEditing
|
- (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
|
* Resizing the Control
|
||||||
*/
|
*/
|
||||||
- (void) calcSize
|
- (void) calcSize
|
||||||
{
|
{
|
||||||
|
[_cell calcDrawInfo: [self bounds]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) sizeToFit
|
- (void) sizeToFit
|
||||||
|
@ -570,14 +620,14 @@ static Class actionCellClass;
|
||||||
[_window _captureMouse: self];
|
[_window _captureMouse: self];
|
||||||
|
|
||||||
e = theEvent;
|
e = theEvent;
|
||||||
while (!done) // loop until mouse goes up
|
// loop until mouse goes up
|
||||||
|
while (!done)
|
||||||
{
|
{
|
||||||
location = [e locationInWindow];
|
location = [e locationInWindow];
|
||||||
location = [self convertPoint: location fromView: nil];
|
location = [self convertPoint: location fromView: nil];
|
||||||
// ask the cell to track the mouse only
|
// ask the cell to track the mouse only
|
||||||
// if the mouse is within the cell
|
// if the mouse is within the cell
|
||||||
if ((location.x >= 0) && (location.x < _bounds.size.width) &&
|
if ([self mouse: location inRect: _bounds])
|
||||||
(location.y >= 0 && location.y < _bounds.size.height))
|
|
||||||
{
|
{
|
||||||
[_cell setHighlighted: YES];
|
[_cell setHighlighted: YES];
|
||||||
[self setNeedsDisplay: YES];
|
[self setNeedsDisplay: YES];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue