5 // Created by Matt L. Judy on Sat Feb 22 2003.
6 // Copyright (c) 2003 NibFile.com. All rights reserved.
9 #import "StatusWindow.h"
11 @interface StatusWindow (Private)
12 - (NSRect)setupWindowWithDataSize:(NSSize)dataSize;
15 @implementation StatusWindow
17 /*************************************************************************/
19 #pragma mark INITIALIZATION / DEALLOCATION METHODS
20 /*************************************************************************/
22 - (id)initWithContentView:(NSView *)contentView
23 exitMode:(ITTransientStatusWindowExitMode)exitMode
24 backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType
26 if ( ( self = [super initWithContentView:contentView
28 backgroundType:backgroundType] ) ) {
29 // Set default values.
30 _image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
31 _groupNoun = [@"Playlist" retain];
46 /*************************************************************************/
48 #pragma mark ACCESSOR METHODS
49 /*************************************************************************/
51 - (void)setImage:(NSImage *)newImage
54 _image = [newImage copy];
57 - (void)setGroupNoun:(NSString *)newNoun;
59 [_groupNoun autorelease];
60 _groupNoun = [newNoun copy];
63 - (void)setLocked:(BOOL)flag
69 /*************************************************************************/
71 #pragma mark INSTANCE METHODS
72 /*************************************************************************/
74 - (NSRect)setupWindowWithDataSize:(NSSize)dataSize
77 float imageWidth = 0.0;
78 float imageHeight = 0.0;
79 float dataWidth = dataSize.width;
80 float dataHeight = dataSize.height;
81 float contentHeight = 0.0;
82 float windowWidth = 0.0;
83 float windowHeight = 0.0;
84 NSImageView *imageView;
86 // Get image width and height.
87 imageWidth = [_image size].width;
88 imageHeight = [_image size].height;
90 // Set the content height to the greater of the text and image heights.
91 contentHeight = ( ( imageHeight > dataHeight ) ? imageHeight : dataHeight );
93 // Setup the Window, and remove all its contentview's subviews.
94 windowWidth = ( SW_PAD + imageWidth + SW_SPACE + dataWidth + SW_PAD );
95 windowHeight = ( SW_PAD + contentHeight + SW_PAD );
96 [self setFrame:NSMakeRect(SW_BORDER, SW_BORDER, windowWidth, windowHeight) display:YES];
97 [[[self contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
99 // Setup, position, fill, and add the image view to the content view.
100 imageRect = NSMakeRect( SW_PAD,
101 (SW_PAD + ((contentHeight - imageHeight) / 2)),
104 imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease];
105 [imageView setImage:_image];
106 [[self contentView] addSubview:imageView];
108 return NSMakeRect( (SW_PAD + imageWidth + SW_SPACE),
109 (SW_PAD + ((contentHeight - dataHeight) / 2)),
114 - (void)buildTextWindowWithString:(NSString *)text
116 float dataWidth = 0.0;
117 float dataHeight = 0.0;
119 NSArray *lines = [text componentsSeparatedByString:@"\n"];
121 NSEnumerator *lineEnum = [lines objectEnumerator];
122 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
123 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
124 ITTextField *textField;
126 // Iterate over each line to get text width and height
127 while ( (oneLine = [lineEnum nextObject]) ) {
128 // Get the width of one line, adding 8.0 because Apple sucks donkey rectum.
129 float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 );
130 // Add the height of this line to the total text height
131 dataHeight += [oneLine sizeWithAttributes:attr].height;
132 // If this line wider than the last one, set it as the text width.
133 dataWidth = ( ( dataWidth > oneLineWidth ) ? dataWidth : oneLineWidth );
136 // Add 4.0 to the final dataHeight to accomodate the shadow.
139 dataRect = [self setupWindowWithDataSize:NSMakeSize(dataWidth, dataHeight)];
141 // Create, position, setup, fill, and add the text view to the content view.
142 textField = [[[ITTextField alloc] initWithFrame:dataRect] autorelease];
143 [textField setEditable:NO];
144 [textField setSelectable:NO];
145 [textField setBordered:NO];
146 [textField setDrawsBackground:NO];
147 [textField setFont:font];
148 [textField setTextColor:[NSColor whiteColor]];
149 [textField setCastsShadow:YES];
150 [textField setStringValue:text];
151 [[self contentView] addSubview:textField];
153 // Display the window.
154 [[self contentView] setNeedsDisplay:YES];
157 - (void)buildMeterWindowWithCharacter:(NSString *)character
161 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
162 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
163 NSSize charSize = [character sizeWithAttributes:attr];
164 float cellHeight = ( charSize.height + 4.0 ); // Add 4.0 for shadow
165 float cellWidth = ( (charSize.width) + SW_METER_PAD ); // Add 8.0 for Apple suck
166 float dataWidth = ( cellWidth * count );
167 NSRect dataRect = [self setupWindowWithDataSize:NSMakeSize(dataWidth, cellHeight)];
168 NSEnumerator *cellEnum = nil;
171 NSMatrix *volMatrix = [[[NSMatrix alloc] initWithFrame:dataRect
172 mode:NSHighlightModeMatrix
173 cellClass:NSClassFromString(@"ITTextFieldCell")
175 numberOfColumns:count] autorelease];
177 [volMatrix setCellSize:NSMakeSize(cellWidth, cellHeight)];
178 [volMatrix setIntercellSpacing:NSMakeSize(0, 0)];
180 cellEnum = [[volMatrix cells] objectEnumerator];
182 while ( (aCell = [cellEnum nextObject]) ) {
183 [aCell setEditable:NO];
184 [aCell setSelectable:NO];
185 [aCell setBordered:NO];
186 [aCell setDrawsBackground:NO];
187 [aCell setAlignment:NSCenterTextAlignment];
188 [aCell setFont:font];
189 [aCell setStringValue:character];
193 if ( active >= activeCount ) {
194 [aCell setCastsShadow:YES];
195 [aCell setTextColor:[NSColor whiteColor]];
197 [aCell setCastsShadow:NO];
198 [aCell setTextColor:[NSColor darkGrayColor]];
203 [[self contentView] addSubview:volMatrix];
204 [[self contentView] setNeedsDisplay:YES];
207 - (void)buildDialogWindowWithMessage:(NSString *)message
208 defaultButton:(NSString *)defaultTitle
209 alternateButton:(NSString *)alternateTitle
211 defaultAction:(SEL)okAction
212 alternateAction:(SEL)alternateAction