forked from martinhewitson/TeXnicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MHHighlightingView.m
71 lines (59 loc) · 1.77 KB
/
MHHighlightingView.m
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
//
// MHHighlightingView.m
// TeXnicle
//
// Created by Martin Hewitson on 02/02/12.
// Copyright (c) 2012 bobsoft. All rights reserved.
//
#import "MHHighlightingView.h"
#import "MHPDFView.h"
#import "NSView+Subview.h"
@implementation MHHighlightingView
@synthesize isFocused;
- (void) awakeFromNib
{
self.isFocused = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handlePDFViewGainedFocusNotification:)
name:MHPDFViewDidGainFocusNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handlePDFViewLostFocusNotification:)
name:MHPDFViewDidLoseFocusNotification
object:nil];
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void) handlePDFViewGainedFocusNotification:(NSNotification*)aNote
{
NSView *v = [aNote object];
if ([v isSubviewOf:self]) {
self.isFocused = YES;
[self setNeedsDisplay:YES];
}
}
- (void) handlePDFViewLostFocusNotification:(NSNotification*)aNote
{
NSView *v = [aNote object];
if ([v isSubviewOf:self]) {
self.isFocused = NO;
[self setNeedsDisplay:YES];
}
}
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
if (self.isFocused) {
[[NSColor keyboardFocusIndicatorColor] set];
[NSBezierPath setDefaultLineWidth:1.0];
[NSBezierPath strokeRect:[self bounds]];
} else {
[[NSColor darkGrayColor] set];
[NSBezierPath setDefaultLineWidth:1.0];
[NSBezierPath strokeRect:[self bounds]];
}
}
@end