Incremental checkin. Updating the StatusWindow and WtatusWindowController objects...
[MenuTunes.git] / StatusWindow.m
1 //
2 //  StatusWindow.m
3 //  MenuTunes
4 //
5 //  Created by Matt L. Judy on Sat Feb 22 2003.
6 //  Copyright (c) 2003 NibFile.com. All rights reserved.
7 //
8
9 #import "StatusWindow.h"
10
11 @interface StatusWindow (Private)
12 - (NSRect)setupWindowWithDataSize:(NSSize)dataSize;
13 @end
14
15 @implementation StatusWindow
16
17 /*************************************************************************/
18 #pragma mark -
19 #pragma mark INITIALIZATION / DEALLOCATION METHODS
20 /*************************************************************************/
21
22 - (id)initWithContentView:(NSView *)contentView
23                  exitMode:(ITTransientStatusWindowExitMode)exitMode
24            backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType
25 {
26     if ( ( self = [super initWithContentView:contentView
27                                exitMode:exitMode
28                          backgroundType:backgroundType] ) ) {
29      // Set default values.
30         _image       = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
31         _groupNoun   = [@"Playlist" retain];
32         _locked      = NO;
33     }
34     
35     return self;
36 }
37
38 - (void)dealloc
39 {
40     [_image     release];
41     [_groupNoun release];
42     [super dealloc];
43 }
44
45
46 /*************************************************************************/
47 #pragma mark -
48 #pragma mark ACCESSOR METHODS
49 /*************************************************************************/
50
51 - (void)setImage:(NSImage *)newImage
52 {
53     [_image autorelease];
54     _image = [newImage copy];
55 }
56
57 - (void)setGroupNoun:(NSString *)newNoun;
58 {
59     [_groupNoun autorelease];
60     _groupNoun = [newNoun copy];
61 }
62
63 - (void)setLocked:(BOOL)flag
64 {
65     _locked = flag;
66 }
67
68
69 /*************************************************************************/
70 #pragma mark -
71 #pragma mark INSTANCE METHODS
72 /*************************************************************************/
73
74 - (NSRect)setupWindowWithDataSize:(NSSize)dataSize
75 {
76     NSRect       imageRect;
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;
85
86 //  Get image width and height.
87     imageWidth  = [_image size].width;
88     imageHeight = [_image size].height;
89     
90 //  Set the content height to the greater of the text and image heights.
91     contentHeight = ( ( imageHeight > dataHeight ) ? imageHeight : dataHeight );
92
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)];
98
99 //  Setup, position, fill, and add the image view to the content view.
100     imageRect = NSMakeRect( SW_PAD,
101                             (SW_PAD + ((contentHeight - imageHeight) / 2)),
102                             imageWidth,
103                             imageHeight );
104     imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease];
105     [imageView setImage:_image];
106     [[self contentView] addSubview:imageView];
107
108     return NSMakeRect( (SW_PAD + imageWidth + SW_SPACE),
109                        (SW_PAD + ((contentHeight - dataHeight) / 2)),
110                        dataWidth,
111                        dataHeight);
112 }
113
114 - (void)buildTextWindowWithString:(NSString *)text
115 {
116     float         dataWidth     = 0.0;
117     float         dataHeight    = 0.0;
118     NSRect        dataRect;
119     NSArray      *lines         = [text componentsSeparatedByString:@"\n"];
120     id                    oneLine       = nil;
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;
125     
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 );
134     }
135         
136 //  Add 4.0 to the final dataHeight to accomodate the shadow.
137     dataHeight += 4.0;
138     
139     dataRect = [self setupWindowWithDataSize:NSMakeSize(dataWidth, dataHeight)];
140     
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];
152     
153 //  Display the window.
154     [[self contentView] setNeedsDisplay:YES];
155 }
156
157 - (void)buildMeterWindowWithCharacter:(NSString *)character
158                                 count:(int)count
159                                active:(int)active
160 {
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;
169     id            aCell       = nil;
170     int           activeCount = 0;
171     NSMatrix     *volMatrix   = [[[NSMatrix alloc] initWithFrame:dataRect
172                                                             mode:NSHighlightModeMatrix
173                                                        cellClass:NSClassFromString(@"ITTextFieldCell")
174                                                     numberOfRows:1
175                                                  numberOfColumns:count] autorelease];
176
177     [volMatrix setCellSize:NSMakeSize(cellWidth, cellHeight)];
178     [volMatrix setIntercellSpacing:NSMakeSize(0, 0)];
179
180     cellEnum = [[volMatrix cells] objectEnumerator];
181
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];
190
191         activeCount ++;
192         
193         if ( active >= activeCount ) {
194             [aCell setCastsShadow:YES];
195             [aCell setTextColor:[NSColor whiteColor]];
196         } else {
197             [aCell setCastsShadow:NO];
198             [aCell setTextColor:[NSColor darkGrayColor]];
199         }
200         
201     }
202
203     [[self contentView] addSubview:volMatrix];
204     [[self contentView] setNeedsDisplay:YES];
205 }
206
207 - (void)buildDialogWindowWithMessage:(NSString *)message
208                        defaultButton:(NSString *)defaultTitle
209                      alternateButton:(NSString *)alternateTitle
210                               target:(id)target
211                        defaultAction:(SEL)okAction
212                      alternateAction:(SEL)alternateAction
213 {
214
215 }
216
217
218 @end