5 // Created by Matt L. Judy on Sat Feb 22 2003.
6 // Copyright (c) 2003 NibFile.com. All rights reserved.
9 #import "StatusWindow.h"
12 @interface StatusWindow (Private)
13 - (void)buildStatusWindow;
17 @implementation StatusWindow
19 - (id)initWithContentView:(NSView *)contentView
20 exitMode:(ITTransientStatusWindowExitMode)exitMode
21 backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType
23 if ( ( self = [super initWithContentView:contentView
25 backgroundType:backgroundType]) ) {
26 // Default images and text.
27 image = [NSImage imageNamed:@"NSApplicationIcon"];
28 text = @"No string set yet.";
29 [self buildStatusWindow];
34 - (void)buildStatusWindow
38 float imageWidth = 0.0;
39 float imageHeight = 0.0;
40 float textWidth = 0.0;
41 float textHeight = 0.0;
42 float contentHeight = 0.0;
43 float windowWidth = 0.0;
44 float windowHeight = 0.0;
45 NSArray *lines = [text componentsSeparatedByString:@"\n"];
47 NSEnumerator *lineEnum = [lines objectEnumerator];
48 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
49 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
51 // Get image width and height.
52 imageWidth = [image size].width;
53 imageHeight = [image size].height;
55 // Iterate over each line to get text width and height
56 while ( oneLine = [lineEnum nextObject] ) {
57 // Get the width of one line, adding 8.0 because Apple sucks donkey rectum.
58 float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 );
59 // Add the height of this line to the total text height
60 textHeight += [oneLine sizeWithAttributes:attr].height;
61 // If this line wider than the last one, set it as the text width.
62 textWidth = ( ( textWidth > oneLineWidth ) ? textWidth : oneLineWidth );
65 // Add 4.0 to the final textHeight to accomodate the shadow.
68 // Set the content height to the greater of the text and image heights.
69 contentHeight = ( ( imageHeight > textHeight ) ? imageHeight : textHeight );
71 // Setup the Window, and remove all its contentview's subviews.
72 windowWidth = ( SW_PAD + imageWidth + SW_SPACE + textWidth + SW_PAD );
73 windowHeight = ( SW_PAD + contentHeight + SW_PAD );
74 [self setFrame:NSMakeRect(SW_BORDER, SW_BORDER, windowWidth, windowHeight) display:YES];
75 [[[self contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
77 // Setup, position, fill, and add the image view to the content view.
78 imageRect = NSMakeRect( SW_PAD,
79 (SW_PAD + ((contentHeight - imageHeight) / 2)),
82 imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease];
83 [imageView setImage:image];
84 [[self contentView] addSubview:imageView];
86 // Setup, position, fill, and add the text view to the content view.
87 textRect = NSMakeRect( (SW_PAD + imageWidth + SW_SPACE),
88 (SW_PAD + ((contentHeight - textHeight) / 2)),
91 textField = [[[ITTextField alloc] initWithFrame:textRect] autorelease];
92 [textField setEditable:NO];
93 [textField setSelectable:NO];
94 [textField setBordered:NO];
95 [textField setDrawsBackground:NO];
96 [textField setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:18]];
97 [textField setTextColor:[NSColor whiteColor]];
98 [textField setCastsShadow:YES];
99 [textField setStringValue:text];
100 [[self contentView] addSubview:textField];
102 [[self contentView] setNeedsDisplay:YES];
106 - (void)setImage:(NSImage *)newImage
109 image = [newImage copy];
110 [self buildStatusWindow];
113 - (void)setText:(NSString *)newText
116 text = [newText copy];
117 [self buildStatusWindow];