mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 05:10:57 +00:00
Mostly rewritten - should no longer crash with new internals, and be quite
better git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14675 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5859fd473f
commit
67c953ddfe
1 changed files with 65 additions and 148 deletions
|
@ -7,6 +7,9 @@
|
||||||
Author: Gregory John Casamento <borgheron@yahoo.com>
|
Author: Gregory John Casamento <borgheron@yahoo.com>
|
||||||
Date: 2000
|
Date: 2000
|
||||||
|
|
||||||
|
Author: Nicola Pero <nicola@brainstorm.co.uk>
|
||||||
|
Date: October 2002
|
||||||
|
|
||||||
This file is part of the GNUstep GUI Library.
|
This file is part of the GNUstep GUI Library.
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
|
@ -35,243 +38,157 @@
|
||||||
#include <AppKit/NSEvent.h>
|
#include <AppKit/NSEvent.h>
|
||||||
#include "GSSimpleLayoutManager.h"
|
#include "GSSimpleLayoutManager.h"
|
||||||
|
|
||||||
/* Other secure subclasses */
|
/* 'Secure' subclasses */
|
||||||
@interface NSSecureTextView : NSTextView
|
@interface NSSecureTextView : NSTextView
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GSSimpleSecureLayoutManager : GSSimpleLayoutManager
|
@interface GSSimpleSecureLayoutManager : GSSimpleLayoutManager
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSSecureTextField
|
@implementation NSSecureTextField
|
||||||
|
|
||||||
/*
|
|
||||||
==============
|
|
||||||
+initialize
|
|
||||||
==============
|
|
||||||
*/
|
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self == [NSSecureTextField class]) {
|
if (self == [NSSecureTextField class])
|
||||||
[self setVersion:1];
|
{
|
||||||
|
[self setVersion:2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
============
|
|
||||||
+ cellClass
|
|
||||||
============
|
|
||||||
*/
|
|
||||||
+ (Class) cellClass
|
+ (Class) cellClass
|
||||||
{
|
{
|
||||||
// Hard code here to make sure no other class can be used.
|
/* Hard code here to make sure no other class is used. */
|
||||||
return [NSSecureTextFieldCell class];
|
return [NSSecureTextFieldCell class];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
============
|
|
||||||
+ setCellClass
|
|
||||||
============
|
|
||||||
*/
|
|
||||||
+ (void) setCellClass: (Class)factoryId
|
+ (void) setCellClass: (Class)factoryId
|
||||||
{
|
{
|
||||||
// Ward off interlopers with a stern message.
|
/* Ward off interlopers with a stern message. */
|
||||||
[NSException raise: NSInvalidArgumentException
|
[NSException raise: NSInvalidArgumentException
|
||||||
format: @"NSSecureTextField can only use NSSecureTextFieldCells in order to ensure security."];
|
format: @"NSSecureTextField only uses NSSecureTextFieldCells."];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
==============
|
|
||||||
-initWithFrame:
|
|
||||||
==============
|
|
||||||
*/
|
|
||||||
- (id) initWithFrame:(NSRect)frameRect
|
- (id) initWithFrame:(NSRect)frameRect
|
||||||
{
|
{
|
||||||
[super initWithFrame: frameRect];
|
self = [super initWithFrame: frameRect];
|
||||||
[_cell setEchosBullets: YES];
|
[self setEchosBullets: YES];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
- (void) setEchosBullets: (BOOL)flag
|
||||||
==============
|
|
||||||
-initWithCoder:
|
|
||||||
==============
|
|
||||||
*/
|
|
||||||
- (id) initWithCoder:(NSCoder *)decoder
|
|
||||||
{
|
{
|
||||||
BOOL echosBullets = YES;
|
[_cell setEchosBullets: flag];
|
||||||
|
|
||||||
[super initWithCoder: decoder];
|
|
||||||
[decoder decodeValueOfObjCType: @encode(BOOL) at: &echosBullets];
|
|
||||||
[_cell setEchosBullets: echosBullets];
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) textDidEndEditing: (NSNotification *)aNotification
|
- (BOOL) echosBullets
|
||||||
{
|
{
|
||||||
[_text_object setText: [[aNotification object] text]];
|
return [_cell echosBullets];
|
||||||
[super textDidEndEditing: aNotification];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end /* NSSecureTextField */
|
@end /* NSSecureTextField */
|
||||||
|
|
||||||
@implementation NSSecureTextFieldCell
|
@implementation NSSecureTextFieldCell
|
||||||
/*
|
|
||||||
==============
|
|
||||||
+initialize
|
|
||||||
==============
|
|
||||||
*/
|
|
||||||
+ (void)initialize
|
+ (void)initialize
|
||||||
{
|
{
|
||||||
if (self == [NSSecureTextFieldCell class])
|
if (self == [NSSecureTextFieldCell class])
|
||||||
[self setVersion:1];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
==================================
|
|
||||||
+_sharedSecureFieldEditorInstance
|
|
||||||
==================================
|
|
||||||
*/
|
|
||||||
+ (id)_sharedSecureFieldEditorInstance
|
|
||||||
{
|
|
||||||
static NSSecureTextView *secureView = nil;
|
|
||||||
|
|
||||||
if( secureView == nil )
|
|
||||||
{
|
{
|
||||||
secureView = [[NSSecureTextView alloc] init];
|
[self setVersion:2];
|
||||||
[secureView setFieldEditor: YES];
|
|
||||||
[secureView setText: @""];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return secureView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
- (BOOL) echosBullets
|
||||||
===============
|
|
||||||
-echosBullets
|
|
||||||
===============
|
|
||||||
*/
|
|
||||||
- (BOOL)echosBullets
|
|
||||||
{
|
{
|
||||||
return i_echosBullets;
|
return _echosBullets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Functionality not implemented. */
|
||||||
================
|
- (void) setEchosBullets: (BOOL)flag
|
||||||
+setEchosBullets:
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
- (void)setEchosBullets:(BOOL)flag
|
|
||||||
{
|
{
|
||||||
i_echosBullets = flag;
|
_echosBullets = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
- (void) drawInteriorWithFrame: (NSRect)cellFrame
|
||||||
===============
|
inView: (NSView *)controlView
|
||||||
-drawInteriorWithFrame:
|
|
||||||
===============
|
|
||||||
*/
|
|
||||||
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
|
||||||
{
|
{
|
||||||
// do nothing....
|
/* Do nothing. */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
- (NSText *) setUpFieldEditorAttributes: (NSText *)textObject
|
||||||
* Editing Text
|
|
||||||
*/
|
|
||||||
- (void) editWithFrame: (NSRect)aRect
|
|
||||||
inView: (NSView*)controlView
|
|
||||||
editor: (NSText*)textObject
|
|
||||||
delegate: (id)anObject
|
|
||||||
event: (NSEvent*)theEvent
|
|
||||||
{
|
{
|
||||||
id l_editor = [NSSecureTextFieldCell _sharedSecureFieldEditorInstance];
|
/* Replace the text object with a secure instance. It's not shared. */
|
||||||
|
textObject = [NSSecureTextView new];
|
||||||
|
AUTORELEASE (textObject);
|
||||||
|
|
||||||
[l_editor setText: [textObject text]];
|
return [super setUpFieldEditorAttributes: textObject];
|
||||||
[super editWithFrame: aRect
|
|
||||||
inView: controlView
|
|
||||||
editor: l_editor
|
|
||||||
delegate: anObject
|
|
||||||
event: theEvent];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) selectWithFrame: (NSRect)aRect
|
- (id) initWithCoder:(NSCoder *)decoder
|
||||||
inView: (NSView*)controlView
|
|
||||||
editor: (NSText*)textObject
|
|
||||||
delegate: (id)anObject
|
|
||||||
start: (int)selStart
|
|
||||||
length: (int)selLength
|
|
||||||
{
|
{
|
||||||
id l_editor = [NSSecureTextFieldCell _sharedSecureFieldEditorInstance];
|
[super initWithCoder: decoder];
|
||||||
|
[decoder decodeValueOfObjCType: @encode(BOOL) at: &_echosBullets];
|
||||||
|
|
||||||
[l_editor setText: [textObject text]];
|
return self;
|
||||||
[super selectWithFrame: aRect
|
|
||||||
inView: controlView
|
|
||||||
editor: l_editor
|
|
||||||
delegate: anObject
|
|
||||||
start: selStart
|
|
||||||
length: selLength];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) encodeWithCoder: (NSCoder *)aCoder
|
||||||
|
{
|
||||||
|
[super encodeWithCoder: aCoder];
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_echosBullets];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation GSSimpleSecureLayoutManager
|
@implementation GSSimpleSecureLayoutManager
|
||||||
- (void) drawGlyphsForGlyphRange: (NSRange)glyphRange
|
- (void) drawGlyphsForGlyphRange: (NSRange)glyphRange
|
||||||
atPoint: (NSPoint)containerOrigin
|
atPoint: (NSPoint)containerOrigin
|
||||||
{
|
{
|
||||||
// do nothing...
|
/* Do nothing. */
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSSecureTextView
|
@implementation NSSecureTextView
|
||||||
/* Class methods */
|
|
||||||
+ (void) initialize
|
|
||||||
{
|
|
||||||
if ([self class] == [NSSecureTextView class])
|
|
||||||
{
|
|
||||||
[self setVersion: 1];
|
|
||||||
[self registerForServices];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) initWithFrame: (NSRect)frameRect
|
- (id) initWithFrame: (NSRect)frameRect
|
||||||
|
textContainer: (NSTextContainer*)aTextContainer
|
||||||
{
|
{
|
||||||
NSTextContainer *aTextContainer =
|
GSSimpleSecureLayoutManager *m;
|
||||||
[[NSTextContainer alloc] initWithContainerSize: frameRect.size];
|
|
||||||
GSSimpleSecureLayoutManager *layoutManager = [[GSSimpleSecureLayoutManager alloc] init];
|
|
||||||
|
|
||||||
[super initWithFrame: frameRect];
|
/* Perform the normal init. */
|
||||||
[layoutManager addTextContainer: aTextContainer];
|
[super initWithFrame: frameRect textContainer: aTextContainer];
|
||||||
RELEASE(aTextContainer);
|
|
||||||
|
|
||||||
_textStorage = [[NSTextStorage alloc] init];
|
/* Then, replace the layout manager with a
|
||||||
[_textStorage addLayoutManager: layoutManager];
|
* GSSimpleSecureLayoutManager. */
|
||||||
RELEASE(layoutManager);
|
m = [[GSSimpleSecureLayoutManager alloc] init];
|
||||||
|
AUTORELEASE (m);
|
||||||
|
[[self textContainer] replaceLayoutManager: m];
|
||||||
|
|
||||||
return [self initWithFrame: frameRect textContainer: aTextContainer];
|
[self setFieldEditor: YES];
|
||||||
|
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) copy: (id)sender
|
- (void) copy: (id)sender
|
||||||
{
|
{
|
||||||
// Do nothing since copying from a NSSecureTextView is *not* permitted.
|
/* Do nothing since copying from a NSSecureTextView is not permitted. */
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) writeSelectionToPasteboard: (NSPasteboard*)pboard
|
- (BOOL) writeSelectionToPasteboard: (NSPasteboard*)pboard
|
||||||
types: (NSArray*)types
|
types: (NSArray*)types
|
||||||
{
|
{
|
||||||
/* Returns NO since the selection should never be
|
/* Return NO since the selection should never be written to the
|
||||||
written to the pasteboard */
|
* pasteboard */
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) validRequestorForSendType: (NSString*) sendType
|
- (id) validRequestorForSendType: (NSString*) sendType
|
||||||
returnType: (NSString*) returnType
|
returnType: (NSString*) returnType
|
||||||
{
|
{
|
||||||
/* return "nil" to indicate that no type can be sent to the pasteboard for
|
/* Return nil to indicate that no type can be sent to the pasteboard
|
||||||
an object of this class */
|
* for an object of this class. */
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in a new issue