mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 17:52:42 +00:00
Added
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5025 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e8599e3b13
commit
8344db0adf
2 changed files with 274 additions and 0 deletions
53
Headers/gnustep/gui/NSSecureTextField.h
Normal file
53
Headers/gnustep/gui/NSSecureTextField.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
NSSecureTextField.h
|
||||
|
||||
Secure text field control class for hidden text entry
|
||||
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
Author: Lyndon Tremblay <humasect@coolmail.com>
|
||||
Date: 1999
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _GNUstep_H_NSSecureTextField
|
||||
#define _GNUstep_H_NSSecureTextField
|
||||
|
||||
#include <AppKit/NSTextField.h>
|
||||
#include <AppKit/NSTextFieldCell.h>
|
||||
|
||||
@class NSNotification;
|
||||
@class NSColor;
|
||||
@class NSText;
|
||||
@class NSCursor;
|
||||
|
||||
@interface NSSecureTextField : NSTextField
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSSecureTextFieldCell : NSTextFieldCell
|
||||
{
|
||||
BOOL i_echosBullets;
|
||||
}
|
||||
- (void)setEchosBullets:(BOOL)flag;
|
||||
- (BOOL)echosBullets;
|
||||
@end
|
||||
|
||||
#endif /* _GNUstep_H_NSSecureTextField */
|
221
Source/NSSecureTextField.m
Normal file
221
Source/NSSecureTextField.m
Normal file
|
@ -0,0 +1,221 @@
|
|||
/* -*- C++ -*-
|
||||
NSSecureTextField.m
|
||||
|
||||
Secure Text field control class for hidden text entry
|
||||
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
Author: Lyndon Tremblay <humasect@coolmail.com>
|
||||
Date: 1999
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
//
|
||||
// NOTE:
|
||||
//
|
||||
// All selecting methods have been overriden to do nothing, I don't know if this
|
||||
// will hinder overall behavior of the specs, as I have never used the real thing.
|
||||
//
|
||||
|
||||
#include <gnustep/gui/config.h>
|
||||
|
||||
#include <AppKit/NSSecureTextField.h>
|
||||
#include <AppKit/NSImage.h>
|
||||
#include <AppKit/NSFont.h>
|
||||
|
||||
@implementation NSSecureTextField
|
||||
|
||||
id _nsSecureTextFieldCellClass = nil;
|
||||
|
||||
/*
|
||||
==============
|
||||
+initialize
|
||||
==============
|
||||
*/
|
||||
+ (void)initialize
|
||||
{
|
||||
if (self == [NSSecureTextField class]) {
|
||||
[self setVersion:1];
|
||||
[self setCellClass:[NSSecureTextFieldCell class]];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
+cellClass
|
||||
============
|
||||
*/
|
||||
+ (Class)cellClass
|
||||
{
|
||||
return _nsSecureTextFieldCellClass;
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
+setCellClass:
|
||||
===============
|
||||
*/
|
||||
+ (void)setCellClass:(Class)classID
|
||||
{
|
||||
_nsSecureTextFieldCellClass = classID;
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
-initWithFrame:
|
||||
==============
|
||||
*/
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
if ((self = [super _initFieldWithFrame:frameRect
|
||||
cellClass:_nsSecureTextFieldCellClass])) {
|
||||
[cell setEchosBullets:YES];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
-isSelectable:
|
||||
==============
|
||||
*/
|
||||
- (BOOL)isSelectable
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
@end /* NSSecureTextField */
|
||||
|
||||
@implementation NSSecureTextFieldCell
|
||||
|
||||
/*
|
||||
==============
|
||||
+initialize
|
||||
==============
|
||||
*/
|
||||
+ (void)initialize
|
||||
{
|
||||
if (self == [NSSecureTextFieldCell class])
|
||||
[self setVersion:1];
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
-copyWithZone:
|
||||
==============
|
||||
*/
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
//Prevent the cell's text value from being copied.
|
||||
NSSecureTextFieldCell *c = [super copyWithZone:zone];
|
||||
[c setStringValue:@""];
|
||||
[c setEchosBullets:i_echosBullets];
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
-echosBullets
|
||||
===============
|
||||
*/
|
||||
- (BOOL)echosBullets
|
||||
{
|
||||
return i_echosBullets;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
+setEchosBullets:
|
||||
================
|
||||
*/
|
||||
- (void)setEchosBullets:(BOOL)flag
|
||||
{
|
||||
i_echosBullets = flag;
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
-setSelectable:
|
||||
===============
|
||||
*/
|
||||
- (void)setSelectable:(BOOL)flag
|
||||
{
|
||||
cell_selectable = NO;
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
-selectText:
|
||||
=============
|
||||
*/
|
||||
- (void)selectText:(id)sender
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
-drawInteriorWithFrame:
|
||||
===============
|
||||
*/
|
||||
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
||||
{
|
||||
NSString *string = [self stringValue];
|
||||
unsigned length = [string length];
|
||||
|
||||
|
||||
|
||||
[self setType:NSNullCellType];
|
||||
[super drawInteriorWithFrame:cellFrame inView:controlView];
|
||||
[self setType:NSTextCellType];
|
||||
|
||||
if (length && i_echosBullets) {
|
||||
NSImage *image = [NSImage imageNamed:@"common_Diamond"];
|
||||
NSSize size = [image size];
|
||||
NSPoint position;
|
||||
float stringWidth;
|
||||
|
||||
|
||||
stringWidth = [[self font] widthOfString:string];
|
||||
switch ([self alignment]) {
|
||||
case NSRightTextAlignment:
|
||||
position.x = (NSWidth(cellFrame) - (stringWidth)) - 1;
|
||||
break;
|
||||
case NSCenterTextAlignment:
|
||||
position.x = NSMidX(cellFrame) - (stringWidth/2);
|
||||
break;
|
||||
default:
|
||||
position.x = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
position.y = MAX(NSMidY(cellFrame) - (size.height/2), 0);
|
||||
if ([controlView isFlipped])
|
||||
position.y += size.height;
|
||||
|
||||
while (--length) {
|
||||
[image compositeToPoint:position operation:NSCompositeCopy];
|
||||
position.x += size.width+1;
|
||||
}
|
||||
}
|
||||
//[self _drawText:stars inFrame:cellFrame];
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in a new issue