The R Project SVN R-packages

Rev

Rev 6137 | Rev 7824 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6137 Rev 6233
Line 32... Line 32...
32
 *
32
 *
33
 */
33
 */
34
 
34
 
35
#import "RScriptEditorGlyphGenerator.h"
35
#import "RScriptEditorGlyphGenerator.h"
36
#import "RScriptEditorTypesetter.h"
36
#import "RScriptEditorTypesetter.h"
-
 
37
#import "RScriptEditorTextStorage.h"
-
 
38
#import "RScriptEditorLayoutManager.h"
37
#import "PreferenceKeys.h"
39
#import "PreferenceKeys.h"
38
 
40
 
39
static SEL _attrStrSel;
41
static SEL _attrStrSel;
-
 
42
static SEL _foldSel;
-
 
43
static SEL _foldindSel;
40
 
44
 
41
@implementation RScriptEditorGlyphGenerator
45
@implementation RScriptEditorGlyphGenerator
42
 
46
 
43
 + (void)initialize
47
+ (void)initialize
44
 {
48
{
45
 	if ([self class] == [RScriptEditorGlyphGenerator class]) {
49
	if ([self class] == [RScriptEditorGlyphGenerator class]) {
46
 		_attrStrSel = @selector(attributedString);
50
		_attrStrSel = @selector(attributedString);
-
 
51
		_foldSel    = @selector(foldedRangeAtIndex:);
-
 
52
		_foldindSel = @selector(foldedForIndicatorAtIndex:);
47
 	}
53
	}
48
 }
54
}
49
 
-
 
50
 - (id)init
-
 
51
 {
-
 
52
 	self = [super init];
-
 
53
 
55
 
-
 
56
- (id)init
-
 
57
{
-
 
58
	self = [super init];
-
 
59
 
54
 	if (self != nil) {
60
	if (self != nil) {
55
		_attrStrImp = [self methodForSelector:_attrStrSel];
61
		_attrStrImp = [self methodForSelector:_attrStrSel];
56
		nullGlyph = NSNullGlyph;
62
		nullGlyph = NSNullGlyph;
57
 	}
63
	}
58
 
64
 
59
 	return self;
65
	return self;
-
 
66
}
-
 
67
 
-
 
68
- (void)dealloc{
-
 
69
	if(theTextStorage) [theTextStorage release];
-
 
70
	[super dealloc];
-
 
71
}
-
 
72
 
-
 
73
- (void)setTextStorage:(RScriptEditorTextStorage*)textStorage
-
 
74
{
-
 
75
	if(theTextStorage) [theTextStorage release];
-
 
76
	theTextStorage = [textStorage retain];
-
 
77
	_foldImp = [theTextStorage methodForSelector:_foldSel];
-
 
78
	_foldindImp = [theTextStorage methodForSelector:_foldindSel];
60
 }
79
}
61
 
80
 
62
- (void)generateGlyphsForGlyphStorage:(id <NSGlyphStorage>)glyphStorage desiredNumberOfCharacters:(NSUInteger)nChars glyphIndex:(NSUInteger *)glyphIndex characterIndex:(NSUInteger *)charIndex
81
- (void)generateGlyphsForGlyphStorage:(id <NSGlyphStorage>)glyphStorage desiredNumberOfCharacters:(NSUInteger)nChars glyphIndex:(NSUInteger *)glyphIndex characterIndex:(NSUInteger *)charIndex
63
{
82
{
64
	// Stash the original requester
83
	// Stash the original requester
65
	_destination = glyphStorage;
84
	_destination = glyphStorage;
Line 69... Line 88...
69
 
88
 
70
// NSGlyphStorage interface
89
// NSGlyphStorage interface
71
- (void)insertGlyphs:(const NSGlyph *)glyphs length:(NSUInteger)length forStartingGlyphAtIndex:(NSUInteger)glyphIndex characterIndex:(NSUInteger)charIndex
90
- (void)insertGlyphs:(const NSGlyph *)glyphs length:(NSUInteger)length forStartingGlyphAtIndex:(NSUInteger)glyphIndex characterIndex:(NSUInteger)charIndex
72
{
91
{
73
	NSGlyph *buffer = NULL;
92
	NSGlyph *buffer = NULL;
74
	id attribute;
93
	NSInteger folded = (NSInteger)(*_foldindImp)(theTextStorage, _foldSel, charIndex);
75
 
94
 
76
	// <SPEED>
95
	if (folded > -1) {
77
	attribute = [(*_attrStrImp)(self, _attrStrSel) attribute:foldingAttributeName atIndex:charIndex effectiveRange:NULL];
96
		NSRange effectiveRange = [theTextStorage foldedRangeAtIndex:folded];
78
	if (attribute && [attribute boolValue]) {
-
 
79
		NSRange effectiveRange;
97
		if(effectiveRange.length) {
80
		(void)[(*_attrStrImp)(self, _attrStrSel) attribute:foldingAttributeName atIndex:charIndex longestEffectiveRange:&effectiveRange inRange:NSMakeRange(0, charIndex + length)];
-
 
81
		NSInteger size = sizeof(NSGlyph) * length;
98
			NSInteger size = sizeof(NSGlyph) * length;
82
		buffer = NSZoneMalloc(NULL, size);
99
			buffer = NSZoneMalloc(NULL, size);
83
		memset_pattern4(buffer, &nullGlyph, size);
100
			memset_pattern4(buffer, &nullGlyph, size);
84
		if (effectiveRange.location == charIndex) buffer[0] = NSControlGlyph;
101
			if ((effectiveRange.location+1) == charIndex) buffer[0] = NSControlGlyph;
85
		glyphs = buffer;
102
			glyphs = buffer;
-
 
103
		} else {
-
 
104
			NSBeep();
-
 
105
		}
86
	}
106
	}
87
 
107
 
88
	[_destination insertGlyphs:glyphs length:length forStartingGlyphAtIndex:glyphIndex characterIndex:charIndex];
108
	[_destination insertGlyphs:glyphs length:length forStartingGlyphAtIndex:glyphIndex characterIndex:charIndex];
89
 
109
 
90
	if (buffer) NSZoneFree(NULL, buffer);
110
	if (buffer) NSZoneFree(NULL, buffer);