-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
TPLinkTextField.m
104 lines (83 loc) · 1.85 KB
/
TPLinkTextField.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
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
//
// TPLinkTextField.m
// teleport
//
// Created by JuL on 10/07/05.
// Copyright 2005 abyssoft. All rights reserved.
//
#import "TPLinkTextField.h"
static NSColor * _highlightedColor = nil;
static NSColor * _normalColor = nil;
@implementation TPLinkTextField
+ (void)initialize
{
if(self == [TPLinkTextField class]) {
_highlightedColor = [NSColor colorWithCalibratedRed:0.8 green:0.08 blue:0.1 alpha:1.0];
_normalColor = [NSColor blackColor];
}
}
- (instancetype) initWithCoder:(NSCoder*)coder
{
self = [super initWithCoder:coder];
_trackingRectTag = -1;
return self;
}
- (instancetype) initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
_trackingRectTag = -1;
return self;
}
- (void)dealloc
{
if(_trackingRectTag > 0)
[self removeTrackingRect:_trackingRectTag];
}
- (void)_resetTrackingRect
{
if(_trackingRectTag > 0)
[self removeTrackingRect:_trackingRectTag];
if([self window] != nil)
_trackingRectTag = [self addTrackingRect:[self bounds] owner:self userData:NULL assumeInside:NO];
}
- (void)awakeFromNib
{
[self _resetTrackingRect];
}
- (void)viewDidMoveToWindow
{
[self _resetTrackingRect];
}
- (void)viewDidMoveToSuperview
{
[self _resetTrackingRect];
}
- (void)setFrameSize:(NSSize)size
{
[super setFrameSize:size];
[self _resetTrackingRect];
}
- (void)setFrameOrigin:(NSPoint)origin
{
[super setFrameOrigin:origin];
[self _resetTrackingRect];
}
- (void)mouseEntered:(NSEvent*)event
{
[self setTextColor:_highlightedColor];
[[NSCursor pointingHandCursor] push];
[self setNeedsDisplay:YES];
}
- (void)mouseExited:(NSEvent*)event
{
[self setTextColor:_normalColor];
[NSCursor pop];
[self setNeedsDisplay:YES];
}
- (void)mouseDown:(NSEvent*)event
{
NSURL * url = [NSURL URLWithString:[(NSTextFieldCell*)[self cell] placeholderString]];
if(url != nil)
[[NSWorkspace sharedWorkspace] openURL:url];
}
@end