-
Notifications
You must be signed in to change notification settings - Fork 0
/
IconedCell.m
69 lines (56 loc) · 1.79 KB
/
IconedCell.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
//
// IconedCell.m
// Switchee
//
// Created by 伊藤 洋也 on 09/01/07.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "IconedCell.h"
@implementation IconedCell
/* Source via */
/* http://homepage.mac.com/mkino2/cocoaProg/AppKit/NSCell/NSCell.html#iconedCell */
/* */
- (void)drawInteriorWithFrame:(NSRect)cellFrame
inView:(NSView*)controlView
{
#define ICON_SIZE_WIDTH 20
#define ICON_SIZE_HEIGHT 20
#define MARGIN_X 10
NSString* path;
NSRect pathRect;
NSImage* iconImage;
NSSize iconSize;
NSPoint iconPoint;
// 画像を描く
iconImage = [self image];
iconSize = NSZeroSize;
iconPoint.x = cellFrame.origin.x;
iconPoint.y = cellFrame.origin.y;
if(iconImage)
{
iconSize.width = ICON_SIZE_WIDTH;
iconSize.height = ICON_SIZE_HEIGHT;
iconPoint.x += MARGIN_X;
if([controlView isFlipped]) {
iconPoint.y += iconSize.height;
}
[iconImage setSize:iconSize];
[iconImage compositeToPoint:iconPoint
operation:NSCompositeSourceOver];
}
// テキストを描く
path = [self stringValue];
pathRect.origin.x = cellFrame.origin.x + MARGIN_X;
if(iconSize.width > 0)
{
pathRect.origin.x += iconSize.width + MARGIN_X;
}
pathRect.origin.y = cellFrame.origin.y;
pathRect.size.width = cellFrame.size.width - (pathRect.origin.x - cellFrame.origin.x);
pathRect.size.height = cellFrame.size.height;
if(path)
{
[path drawInRect:pathRect withAttributes:nil];
}
}
@end