mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-15 23:30:57 +00:00
* Source/NSSecureTextField.m: Add GSSimpleSecureGlyphGenerator and
use this to generate the bullet glyphs. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@34622 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
dc3dead8c0
commit
1db386a9ad
2 changed files with 60 additions and 22 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2012-01-24 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/NSSecureTextField.m: Add GSSimpleSecureGlyphGenerator and
|
||||||
|
use this to generate the bullet glyphs.
|
||||||
|
|
||||||
2012-01-23 Eric Wasylishen <ewasylishen@gmail.com>
|
2012-01-23 Eric Wasylishen <ewasylishen@gmail.com>
|
||||||
|
|
||||||
* Source/NSClipView.m (-constrainScrollPoint:): Restore old code
|
* Source/NSClipView.m (-constrainScrollPoint:): Restore old code
|
||||||
|
|
|
@ -36,12 +36,14 @@
|
||||||
#import "AppKit/NSEvent.h"
|
#import "AppKit/NSEvent.h"
|
||||||
#import "AppKit/NSFont.h"
|
#import "AppKit/NSFont.h"
|
||||||
#import "AppKit/NSImage.h"
|
#import "AppKit/NSImage.h"
|
||||||
|
#import "AppKit/NSGlyphGenerator.h"
|
||||||
#import "AppKit/NSLayoutManager.h"
|
#import "AppKit/NSLayoutManager.h"
|
||||||
#import "AppKit/NSSecureTextField.h"
|
#import "AppKit/NSSecureTextField.h"
|
||||||
#import "AppKit/NSStringDrawing.h"
|
#import "AppKit/NSStringDrawing.h"
|
||||||
#import "AppKit/NSTextContainer.h"
|
#import "AppKit/NSTextContainer.h"
|
||||||
#import "AppKit/NSTextView.h"
|
#import "AppKit/NSTextView.h"
|
||||||
#import "AppKit/NSWindow.h"
|
#import "AppKit/NSWindow.h"
|
||||||
|
#import "GNUstepGUI/GSFontInfo.h"
|
||||||
|
|
||||||
// the Unicode code point for a bullet
|
// the Unicode code point for a bullet
|
||||||
#define BULLET 0x2022
|
#define BULLET 0x2022
|
||||||
|
@ -54,6 +56,13 @@
|
||||||
- (BOOL) echosBullets;
|
- (BOOL) echosBullets;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface GSSimpleSecureGlyphGenerator : NSGlyphGenerator
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSGlyphGenerator (Private)
|
||||||
|
- (NSFont *) fontForCharactersWithAttributes: (NSDictionary *)attributes;
|
||||||
|
@end
|
||||||
|
|
||||||
@interface GSSimpleSecureLayoutManager : NSLayoutManager
|
@interface GSSimpleSecureLayoutManager : NSLayoutManager
|
||||||
{
|
{
|
||||||
BOOL _echosBullets;
|
BOOL _echosBullets;
|
||||||
|
@ -248,6 +257,46 @@
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation GSSimpleSecureGlyphGenerator
|
||||||
|
- (void) generateGlyphsForGlyphStorage: (id <NSGlyphStorage>)storage
|
||||||
|
desiredNumberOfCharacters: (NSUInteger)num
|
||||||
|
glyphIndex: (NSUInteger*)glyph
|
||||||
|
characterIndex: (NSUInteger*)index
|
||||||
|
{
|
||||||
|
NSGlyph glyphs[num];
|
||||||
|
NSGlyph gl;
|
||||||
|
NSAttributedString *attrstr = [storage attributedString];
|
||||||
|
GSFontInfo *fi;
|
||||||
|
int i;
|
||||||
|
NSRange maxRange = NSMakeRange(*index, num);
|
||||||
|
NSRange curRange;
|
||||||
|
NSDictionary *attributes;
|
||||||
|
|
||||||
|
attributes = [attrstr attributesAtIndex: *index
|
||||||
|
longestEffectiveRange: &curRange
|
||||||
|
inRange: maxRange];
|
||||||
|
fi = [[self fontForCharactersWithAttributes: attributes] fontInfo];
|
||||||
|
if (!fi)
|
||||||
|
{
|
||||||
|
[NSException raise: NSGenericException
|
||||||
|
format: @"Glyph generation with no font."];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gl = [fi glyphForCharacter: BULLET];
|
||||||
|
for (i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
glyphs[i] = gl;
|
||||||
|
}
|
||||||
|
|
||||||
|
[storage insertGlyphs: glyphs
|
||||||
|
length: num
|
||||||
|
forStartingGlyphAtIndex: *glyph
|
||||||
|
characterIndex: *index];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation GSSimpleSecureLayoutManager
|
@implementation GSSimpleSecureLayoutManager
|
||||||
|
|
||||||
- (BOOL) echosBullets
|
- (BOOL) echosBullets
|
||||||
|
@ -265,28 +314,8 @@
|
||||||
{
|
{
|
||||||
if ([self echosBullets])
|
if ([self echosBullets])
|
||||||
{
|
{
|
||||||
/*
|
[super drawGlyphsForGlyphRange: glyphRange
|
||||||
* FIXME: Rather stupid way of drawing bullets, but better than nothing
|
atPoint: containerOrigin];
|
||||||
* at all. Works well enough for secure text fields.
|
|
||||||
* This also doesn't belong into this method, rather we should do
|
|
||||||
* the replacement during glyph generation. This gets currently done
|
|
||||||
* in [GSLayoutManager _generateGlyphsForRun:at:], but should be done
|
|
||||||
* in an NSTypesetter subclass. Only with this in place it seems
|
|
||||||
* possible to implement bullet echoing.
|
|
||||||
*/
|
|
||||||
unichar buf[] = {BULLET};
|
|
||||||
NSString *string = [NSString stringWithCharacters: buf length: 1];
|
|
||||||
NSFont *font = [_typingAttributes objectForKey: NSFontAttributeName];
|
|
||||||
double width = [font widthOfString: string];
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = glyphRange.location; i <= NSMaxRange (glyphRange); i++)
|
|
||||||
{
|
|
||||||
NSPoint p = NSMakePoint (containerOrigin.x + (i - 1) * width,
|
|
||||||
containerOrigin.y);
|
|
||||||
|
|
||||||
[string drawAtPoint: p withAttributes: _typingAttributes];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -302,6 +331,7 @@
|
||||||
textContainer: (NSTextContainer*)aTextContainer
|
textContainer: (NSTextContainer*)aTextContainer
|
||||||
{
|
{
|
||||||
GSSimpleSecureLayoutManager *m;
|
GSSimpleSecureLayoutManager *m;
|
||||||
|
GSSimpleSecureGlyphGenerator *g;
|
||||||
|
|
||||||
/* Perform the normal init. */
|
/* Perform the normal init. */
|
||||||
self = [super initWithFrame: frameRect textContainer: aTextContainer];
|
self = [super initWithFrame: frameRect textContainer: aTextContainer];
|
||||||
|
@ -311,6 +341,9 @@
|
||||||
/* Then, replace the layout manager with a
|
/* Then, replace the layout manager with a
|
||||||
* GSSimpleSecureLayoutManager. */
|
* GSSimpleSecureLayoutManager. */
|
||||||
m = [[GSSimpleSecureLayoutManager alloc] init];
|
m = [[GSSimpleSecureLayoutManager alloc] init];
|
||||||
|
g = [[GSSimpleSecureGlyphGenerator alloc] init];
|
||||||
|
[m setGlyphGenerator: g];
|
||||||
|
RELEASE(g);
|
||||||
[[self textContainer] replaceLayoutManager: m];
|
[[self textContainer] replaceLayoutManager: m];
|
||||||
RELEASE(m);
|
RELEASE(m);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue