forked from nongio-zz/rik.theme
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Rik+FocusFrame.m
116 lines (107 loc) · 3.59 KB
/
Rik+FocusFrame.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
105
106
107
108
109
110
111
112
113
114
115
116
#import "Rik.h"
#import "Rik+Stepper.h"
@implementation Rik(RikFocusFrame)
- (void) drawFocusFrame: (NSRect) frame view: (NSView*) view
{
//NSLog(@"%@", [view className]);
NSBezierPath * path;
if([view class] == [NSButton class])
{
NSRect r = [view bounds];
NSImage * img = [(NSButton*) view image];
if(img != nil && ![(NSButton*)view isBordered])
{
NSSize s = [img size];
NSCellImagePosition cip = [(NSButton*) view imagePosition];
NSRect imageRect;
switch(cip)
{
case NSImageOnly:
imageRect = r;
break;
case NSImageLeft:
imageRect.origin = r.origin;
imageRect.size.width = s.width;
imageRect.size.height = r.size.height;
break;
case NSImageRight:
imageRect.origin.x = NSMaxX(r) - s.width;
imageRect.origin.y = r.origin.y;
imageRect.size.width = s.width;
imageRect.size.height = r.size.height;
break;
}
path = [NSBezierPath bezierPathWithRoundedRect: NSInsetRect(imageRect,2,1)
xRadius: 3
yRadius: 3];
}
else
{
int bezel_style = [(NSButton*)view bezelStyle];
path = [self buttonBezierPathWithRect: NSInsetRect([view bounds], 1, 1)
andStyle: bezel_style];
}
}
else if([view class] == [NSStepper class])
{
path = [self stepperBezierPathWithFrame: frame];
}
else if([view class] == [NSPopUpButton class])
{
frame.size.height += 1;
frame.size.width += 1;
path = [NSBezierPath bezierPathWithRoundedRect: frame
xRadius: 3
yRadius: 3];
}
else if([view class] == [NSMatrix class])
{
NSSize size = [(NSMatrix*) view cellSize];
NSCell* selectedCell = [(NSMatrix*) view selectedCell];
NSUInteger row = [(NSMatrix*)view selectedRow];
NSUInteger col = [(NSMatrix*)view selectedColumn];
NSRect r = [(NSMatrix*) view cellFrameAtRow:row column: col];
if([selectedCell class] == [NSButtonCell class])
{
NSImage * img = [selectedCell image];
if(img != nil && ![selectedCell isBordered])
{
NSSize s = [img size];
s.width -= 2;
s.height -= 2;
path = [NSBezierPath bezierPathWithRoundedRect: NSMakeRect(r.origin.x+1, r.origin.y+2, s.width, s.height)
xRadius: s.width/2.0
yRadius: s.height/2.0];
}else{
path = [NSBezierPath bezierPathWithRoundedRect: NSInsetRect(r, 1, 1)
xRadius: 3
yRadius: 3];
}
}else{
return;
}
}
else
{
path = [NSBezierPath bezierPathWithRect: frame];
}
NSColor * c = [NSColor selectedControlColor];
[c setStroke];
[path setLineWidth: 2];
[path stroke];
}
- (NSSize) sizeForBorderType: (NSBorderType)aType
{
switch (aType)
{
case NSLineBorder:
return NSMakeSize(4, 4);
case NSGrooveBorder:
case NSBezelBorder:
return NSMakeSize(1, 1);
case NSNoBorder:
default:
return NSZeroSize;
}
}
@end