Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/Classes/MyPopUpButtonCell.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 146 - (show annotations) (download)
Sun Dec 17 04:05:28 2017 UTC (6 years, 5 months ago) by toshinagata1964
File size: 2702 byte(s)
Xcode project is updated so that ppc/i386 universal binary can be built (as before)
1 //
2 // MyPopUpButtonCell.m
3 // Alchemusica
4 //
5 // Created by Toshi Nagata on 06/05/07.
6 //
7 /*
8 Copyright (c) 2006-2011 Toshi Nagata. All rights reserved.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation version 2 of the License.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 */
19
20 #import "MyPopUpButtonCell.h"
21 #import "MyPopUpButton.h"
22
23 @implementation MyPopUpButtonCell
24
25 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
26 {
27 NSRect theRect, r;
28 NSPoint center;
29 NSSize size;
30 NSImage *theImage;
31 NSString *theString;
32 float fraction;
33 theRect = cellFrame;
34 center.x = theRect.origin.x + theRect.size.width / 2;
35 center.y = theRect.origin.y + theRect.size.height / 2;
36
37 if ([self isEnabled])
38 fraction = 1.0f;
39 else fraction = 0.5f;
40 switch ([self type]) {
41 case NSTextCellType:
42 theString = [[self selectedItem] title];
43 if (theString != nil) {
44 NSMutableParagraphStyle *par = [[[NSMutableParagraphStyle alloc] init] autorelease];
45 NSFont *font = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
46 float lineHeight = [font ascender] - [font descender];
47 NSRect rect = NSMakeRect(theRect.origin.x, theRect.origin.y + (theRect.size.height - lineHeight - 2), theRect.size.width, lineHeight + 2);
48 [par setAlignment: NSCenterTextAlignment];
49 [theString drawInRect: rect withAttributes:
50 [NSDictionary dictionaryWithObjectsAndKeys:
51 font,
52 NSFontAttributeName,
53 par,
54 NSParagraphStyleAttributeName, nil]];
55 }
56 break;
57 case NSImageCellType:
58 theImage = [[self selectedItem] image];
59 if (theImage != nil) {
60 size = [theImage size];
61 r.origin.x = center.x - size.width / 2;
62 r.origin.y = center.y - size.height / 2;
63 r.size = size;
64 [theImage drawInRect:r fromRect:NSZeroRect operation:NSCompositeSourceAtop fraction:fraction respectFlipped:YES hints:nil];
65 }
66 break;
67 default:
68 break;
69 }
70 // theRect = NSMakeRect(theRect.origin.x + theRect.size.width - 7, theRect.origin.y + theRect.size.height - 7, 5, 5);
71 r.origin.x = theRect.origin.x + theRect.size.width - 7;
72 r.origin.y = theRect.origin.y + theRect.size.height - 7;
73 r.size.width = 5;
74 r.size.height = 5;
75 [[MyPopUpButton triangleImage] drawInRect:r fromRect:NSZeroRect operation:NSCompositeSourceAtop fraction:fraction respectFlipped:YES hints:nil];
76 }
77
78 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26