aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/views/mac/SkTextFieldCell.m
blob: c5efc46406e01497b1652771616bf1d6879ccf2e (plain)
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

/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
 
#import "SkTextFieldCell.h"
@implementation SkTextFieldCell
- (NSRect)drawingRectForBounds:(NSRect)theRect {
    NSRect newRect = [super drawingRectForBounds:theRect];
    if (selectingOrEditing == NO) {
        NSSize textSize = [self cellSizeForBounds:theRect];
        float heightDelta = newRect.size.height - textSize.height;      
        if (heightDelta > 0) {
            newRect.size.height -= heightDelta;
            newRect.origin.y += (heightDelta / 2);
        }
    }
    return newRect;
}

- (void)selectWithFrame:(NSRect)aRect 
                 inView:(NSView *)controlView 
                 editor:(NSText *)textObj 
               delegate:(id)anObject 
                  start:(NSInteger)selStart 
                 length:(NSInteger)selLength {
	aRect = [self drawingRectForBounds:aRect];
	selectingOrEditing = YES;	
	[super selectWithFrame:aRect 
                    inView:controlView 
                    editor:textObj 
                  delegate:anObject 
                     start:selStart 
                    length:selLength];
	selectingOrEditing = NO;
}

- (void)editWithFrame:(NSRect)aRect 
               inView:(NSView *)controlView 
               editor:(NSText *)textObj 
             delegate:(id)anObject 
                event:(NSEvent *)theEvent {	
	aRect = [self drawingRectForBounds:aRect];
	selectingOrEditing = YES;
	[super editWithFrame:aRect 
                  inView:controlView 
                  editor:textObj 
                delegate:anObject 
                   event:theEvent];
	selectingOrEditing = NO;
}

@end