forked from nongio-zz/rik.theme
-
Notifications
You must be signed in to change notification settings - Fork 7
/
NSTextFieldCell+Rik.m
114 lines (95 loc) · 3.3 KB
/
NSTextFieldCell+Rik.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
/**
* Copyright (C) 2013 Alessandro Sangiuliano
* Author: Alessandro Sangiuliano <[email protected]>
* Date: 31 December 2013
*/
#import "Rik.h"
#import "NSTextFieldCell+Rik.h"
/* Problems just with the first click in the textbox
* then all works as should works.
* The Cell and the text box are not aligned on the first click.
*/
@implementation NSTextFieldCell (RikTheme)
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
NSRect titleRect;
cellFrame.origin.y -= 1;
cellFrame.size.height += 2;
//cellFrame.size.width -= 1;
[self _drawEditorWithFrame: cellFrame inView: controlView];
if (_cell.in_editing)
{
cellFrame.origin.y -= 1;
cellFrame.size.height += 2;
//cellFrame.size.width -=10 ;
[self _drawEditorWithFrame: cellFrame inView: controlView];
//titleRect = [self titleRectForBounds: cellFrame];
//titleRect.origin.y -= 10;
}
else
{
//NSRect titleRect;
cellFrame.origin.y-= 1;
cellFrame.size.height += 2;
//cellFrame.size.width -= 10;
//[self _drawEditorWithFrame: cellFrame inView: controlView];
/*Make sure we are a text cell; titleRect might return an incorrect
rectangle otherwise. Note that the type could be different if the
user has set an image on us, which we just ignore (OS X does so as
well).*/
_cell.type = NSTextCellType;
titleRect = [self titleRectForBounds: cellFrame];
//titleRect.origin.y -= 1;
//titleRect.size.height += 2;
[[self _drawAttributedString] drawInRect: titleRect];
//[self _drawEditorWithFrame: cellFrame inView: controlView];
}
/*_cell.type = NSTextCellType;
titleRect = [self titleRectForBounds: cellFrame];
titleRect.origin.y -= 1;
titleRect.size.height += 2;
[[self _drawAttributedString] drawInRect: titleRect];*/
}
// The cell needs to be asjusted also when is selected or edited
- (void) selectWithFrame: (NSRect)aRect
inView: (NSView*)controlView
editor: (NSText*)textObject
delegate: (id)anObject
start: (NSInteger)selStart
length: (NSInteger)selLength
{
if (![self isMemberOfClass:[NSSearchFieldCell class]])
{
NSRect drawingRect = [self drawingRectForBounds: aRect];
drawingRect.origin.x -= 4;
drawingRect.size.width -= 0;
drawingRect.origin.y -= 6;
drawingRect.size.height += 11;
[super selectWithFrame:drawingRect inView:controlView editor:textObject delegate:anObject start:selStart length:selLength];
}
else
{
[super selectWithFrame:aRect inView:controlView editor:textObject delegate:anObject start:selStart length:selLength];
}
}
- (void) editWithFrame: (NSRect)aRect
inView: (NSView*)controlView
editor: (NSText*)textObject
delegate: (id)anObject
event: (NSEvent*)theEvent
{
if (![self isMemberOfClass:[NSSearchFieldCell class]])
{
NSRect drawingRect = [self drawingRectForBounds: aRect];
drawingRect.origin.x += 4;
drawingRect.size.width -= 0; //it was 6. Same in the selectWithFrame:::::: method
drawingRect.origin.y -= 6;
drawingRect.size.height += 11;
[super editWithFrame:drawingRect inView:controlView editor:textObject delegate:anObject event:theEvent];
}
else
{
[super editWithFrame:aRect inView:controlView editor:textObject delegate:anObject event:theEvent];
}
}
@end