-
Notifications
You must be signed in to change notification settings - Fork 0
/
WMURLTextField.m
101 lines (71 loc) · 1.87 KB
/
WMURLTextField.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
//
// WMURLTextField.m
// Widget Manager
//
// Created by Marc Charbonneau on 5/29/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import "WMURLTextField.h"
@interface WMURLTextField (Private)
- (NSRect)_visibleTextRect;
@end
@implementation WMURLTextField
#pragma mark API
- (void)setURLValue:(NSURL *)URL;
{
[self setObjectValue:URL];
}
#pragma mark NSTextField Overrides
- (void)setTextColor:(NSColor *)aColor;
{
// Text color is pre-defined.
if ( ![aColor isEqual:[NSColor blueColor]] )
return;
[super setTextColor:aColor];
}
#pragma mark NSControl Overrides
- (id)initWithFrame:(NSRect)frameRect
{
if ( ![super initWithFrame:frameRect] )
return nil;
[self setTextColor:[NSColor blueColor]];
return self;
}
- (id)initWithCoder:(NSCoder *)decoder;
{
if ( ![super initWithCoder:decoder] )
return nil;
[self setTextColor:[NSColor blueColor]];
return self;
}
- (void)setObjectValue:(id <NSCopying>)object;
{
if ( ![(id)object isKindOfClass:[NSURL class]] && object != nil )
[NSException raise:@"Invalid Class Expection" format:@"***Invalid object class for WMURLTextField: %@", NSStringFromClass( [(id)object class] )];
[super setObjectValue:object];
}
#pragma mark NSView Overrides
- (void)resetCursorRects;
{
[self addCursorRect:[self _visibleTextRect] cursor:[NSCursor pointingHandCursor]];
}
#pragma mark NSResponder Overrides
- (void)mouseDown:(NSEvent *)theEvent;
{
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
if ( NSMouseInRect( point, [self _visibleTextRect], [self isFlipped] ) )
{
NSURL *URL = [self objectValue];
[[NSWorkspace sharedWorkspace] openURL:URL];
}
}
@end
@implementation WMURLTextField (Private)
- (NSRect)_visibleTextRect;
{
NSSize size = [[self cell] cellSizeForBounds:[self bounds]];
NSRect textRect = [self bounds];
textRect.size = size;
return textRect;
}
@end