1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
//
// MSourceTextView.m
// MySQLGUICommon
//
// Created by Alfredo Kojima on 5/19/05.
// Copyright 2005 MySQL AB. All rights reserved.
//
#import "MSourceTextView.h"
#import "MSyntaxColoring.h"
#import "MSourceLayoutManager.h"
#import "mxUtils.h"
@implementation MSourceTextView
- (id)initWithFrame:(NSRect)rect
{
self= [super initWithFrame:rect];
if (self)
{
[[self textContainer] replaceLayoutManager:[[[MSourceLayoutManager alloc] init] autorelease]];
_bpGutter= [MXGetImageFromBundle([NSBundle bundleForClass:[MSourceTextView class]],@"gutter_breakpoint.png") retain];
_pcGutter= [MXGetImageFromBundle([NSBundle bundleForClass:[MSourceTextView class]],@"gutter_current_pos.png") retain];
_stGutter= [MXGetImageFromBundle([NSBundle bundleForClass:[MSourceTextView class]],@"gutter_query_start.png") retain];
_breakpointsEnabled= YES;
[self setDelegate:self];
}
return self;
}
- (void)dealloc
{
[_bpGutter release];
[_pcGutter release];
[_stGutter release];
[_syntaxColor release];
[super dealloc];
}
- (void)setGutterView:(MTextGutterView*)gutter
{
_gutterView= gutter;
[gutter setDelegate:self];
[_gutterView setLineHeight:[[self layoutManager] defaultLineHeightForFont:[self font]]];
}
- (void)setFont:(NSFont*)font
{
[super setFont:font];
[_gutterView setLineHeight:[[self layoutManager] defaultLineHeightForFont:font]];
}
- (NSArray *)completionsForPartialWordRange:(NSRange)charRange
indexOfSelectedItem:(int *)index
{
return [_syntaxColor completionListForWord:[[self string] substringWithRange:charRange]];
}
- (void)setSyntaxColorer:(MSyntaxColoring*)colorer
{
if (_syntaxColor != colorer)
{
[_syntaxColor release];
_syntaxColor= [colorer retain];
}
[colorer setDelegate:self];
[(MSourceLayoutManager*)[self layoutManager] setSyntaxColorer:colorer];
}
- (MSyntaxColoring*)syntaxColorer
{
return _syntaxColor;
}
- (void)gutterView:(MTextGutterView*)gutter drawLine:(unsigned int)line rect:(NSRect)rect
{
if (_breakpointsEnabled && [_syntaxColor marker:@"breakpoint" atLine:line])
[_bpGutter compositeToPoint:rect.origin operation:NSCompositeSourceOver];
else if ([_syntaxColor marker:@"statement" atLine:line])
[_stGutter compositeToPoint:rect.origin operation:NSCompositeSourceOver];
if ([_syntaxColor marker:@"pc" atLine:line])
[_pcGutter compositeToPoint:NSMakePoint(NSMaxX(rect)-[_pcGutter size].width, NSMinY(rect))
operation:NSCompositeSourceOver];
}
- (void)gutterView:(MTextGutterView*)gutter clickedLine:(unsigned int)line
{
if (_breakpointsEnabled && [_syntaxColor marker:@"breakpoint" atLine:line])
[_syntaxColor removeMarker:@"breakpoint" atLine:line];
else if ([_syntaxColor marker:@"statement" atLine:line])
[_syntaxColor addMarker:@"breakpoint" atLine:line];
[_gutterView setNeedsDisplay:YES];
}
- (void)syntaxColoringDidFinish:(MSyntaxColoring*)colorer
{
[_gutterView setNumberOfLines:[colorer numberOfLines]];
}
- (void)enableBreakpoints:(BOOL)flag
{
_breakpointsEnabled= flag;
}
@end
|