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];
44 /*************************************************************************/
46 #pragma mark ACCESSOR METHODS
47 /*************************************************************************/
49 - (void)setImage:(NSImage *)newImage
52 _image = [newImage copy];
55 - (void)setLocked:(BOOL)flag
61 /*************************************************************************/
63 #pragma mark INSTANCE METHODS
64 /*************************************************************************/
66 - (NSRect)setupWindowWithDataSize:(NSSize)dataSize
69 float imageWidth = 0.0;
70 float imageHeight = 0.0;
71 float dataWidth = dataSize.width;
72 float dataHeight = dataSize.height;
73 float contentHeight = 0.0;
74 float windowWidth = 0.0;
75 float windowHeight = 0.0;
76 NSImageView *imageView;
78 // Get image width and height.
79 imageWidth = [_image size].width;
80 imageHeight = [_image size].height;
82 // Set the content height to the greater of the text and image heights.
83 contentHeight = ( ( imageHeight > dataHeight ) ? imageHeight : dataHeight );
85 // Setup the Window, and remove all its contentview's subviews.
86 windowWidth = ( SW_PAD + imageWidth + SW_SPACE + dataWidth + SW_PAD );
87 windowHeight = ( SW_PAD + contentHeight + SW_PAD );
88 [self setFrame:NSMakeRect(SW_BORDER, SW_BORDER, windowWidth, windowHeight) display:YES];
89 [[[self contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
91 // Setup, position, fill, and add the image view to the content view.
92 imageRect = NSMakeRect( SW_PAD,
93 (SW_PAD + ((contentHeight - imageHeight) / 2)),
96 imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease];
97 [imageView setImage:_image];
98 [[self contentView] addSubview:imageView];
100 return NSMakeRect( (SW_PAD + imageWidth + SW_SPACE),
101 (SW_PAD + ((contentHeight - dataHeight) / 2)),
106 - (void)buildTextWindowWithString:(NSString *)text
108 float dataWidth = 0.0;
109 float dataHeight = 0.0;
111 NSArray *lines = [text componentsSeparatedByString:@"\n"];
113 NSEnumerator *lineEnum = [lines objectEnumerator];
114 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
115 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
116 ITTextField *textField;
118 // Iterate over each line to get text width and height
119 while ( (oneLine = [lineEnum nextObject]) ) {
120 // Get the width of one line, adding 8.0 because Apple sucks donkey rectum.
121 float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 );
122 // Add the height of this line to the total text height
123 dataHeight += [oneLine sizeWithAttributes:attr].height;
124 // If this line wider than the last one, set it as the text width.
125 dataWidth = ( ( dataWidth > oneLineWidth ) ? dataWidth : oneLineWidth );
128 // Add 4.0 to the final dataHeight to accomodate the shadow.
131 dataRect = [self setupWindowWithDataSize:NSMakeSize(dataWidth, dataHeight)];
133 // Create, position, setup, fill, and add the text view to the content view.
134 textField = [[[ITTextField alloc] initWithFrame:dataRect] autorelease];
135 [textField setEditable:NO];
136 [textField setSelectable:NO];
137 [textField setBordered:NO];
138 [textField setDrawsBackground:NO];
139 [textField setFont:font];
140 [textField setTextColor:[NSColor whiteColor]];
141 [textField setCastsShadow:YES];
142 [textField setStringValue:text];
143 [[self contentView] addSubview:textField];
145 // Display the window.
146 [[self contentView] setNeedsDisplay:YES];
149 - (void)buildMeterWindowWithCharacter:(NSString *)character
153 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
154 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
155 NSSize charSize = [character sizeWithAttributes:attr];
156 float cellHeight = ( charSize.height + 4.0 ); // Add 4.0 for shadow
157 float cellWidth = ( (charSize.width) + SW_METER_PAD ); // Add 8.0 for Apple suck
158 float dataWidth = ( cellWidth * count );
159 NSRect dataRect = [self setupWindowWithDataSize:NSMakeSize(dataWidth, cellHeight)];
160 NSEnumerator *cellEnum = nil;
163 NSColor *onColor = [NSColor whiteColor];
164 NSColor *offColor = [NSColor colorWithCalibratedWhite:0.0 alpha:0.50];
165 NSMatrix *volMatrix = [[[NSMatrix alloc] initWithFrame:dataRect
166 mode:NSHighlightModeMatrix
167 cellClass:NSClassFromString(@"ITTextFieldCell")
169 numberOfColumns:count] autorelease];
171 [volMatrix setCellSize:NSMakeSize(cellWidth, cellHeight)];
172 [volMatrix setIntercellSpacing:NSMakeSize(0, 0)];
174 cellEnum = [[volMatrix cells] objectEnumerator];
176 while ( (aCell = [cellEnum nextObject]) ) {
177 [aCell setEditable:NO];
178 [aCell setSelectable:NO];
179 [aCell setBordered:NO];
180 [aCell setDrawsBackground:NO];
181 [aCell setAlignment:NSCenterTextAlignment];
182 [aCell setFont:font];
183 [aCell setStringValue:character];
187 if ( active >= activeCount ) {
188 [aCell setCastsShadow:YES];
189 [aCell setTextColor:onColor];
191 [aCell setCastsShadow:NO];
192 [aCell setTextColor:offColor];
197 [[self contentView] addSubview:volMatrix];
198 [[self contentView] setNeedsDisplay:YES];
201 - (void)buildDialogWindowWithMessage:(NSString *)message
202 defaultButton:(NSString *)defaultTitle
203 alternateButton:(NSString *)alternateTitle
205 defaultAction:(SEL)okAction
206 alternateAction:(SEL)alternateAction