2 #import "ITTransientStatusWindow.h"
3 #import "ITTextField.h"
9 #define SW_IMAGE @"Library"
11 @interface Controller (ITStatusItemSupport)
12 - (void)createStatusItem;
13 - (void)removeStatusItem;
17 @implementation Controller
21 [self createStatusItem];
22 [testTextField setCastsShadow:YES];
23 statusWindow = [ITTransientStatusWindow sharedWindow];
24 // [tabView setAllowsDragging:YES];
27 /*************************************************************************/
29 #pragma mark ITStatusItem SUPPORT
30 /*************************************************************************/
32 - (void)createStatusItem
34 statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar]
35 withLength:NSVariableStatusItemLength];
37 if ( [showImageCheckBox state] == NSOnState ) {
38 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
41 if ( [useInvertedCheckBox state] == NSOnState ) {
42 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
45 if ( [showTitleCheckBox state] == NSOnState ) {
46 [statusItem setTitle:@"ITStatusItem"];
49 [statusItem setMenu:statusItemMenu];
52 - (void)removeStatusItem
54 [[statusItem statusBar] removeStatusItem:statusItem];
55 [statusItem autorelease];
59 - (IBAction)toggleStatusItem:(id)sender
61 if ( [sender state] == NSOnState ) {
62 [self createStatusItem];
63 [showImageCheckBox setEnabled:YES];
64 [showTitleCheckBox setEnabled:YES];
65 [useInvertedCheckBox setEnabled:YES];
67 [self removeStatusItem];
68 [showImageCheckBox setEnabled:NO];
69 [useInvertedCheckBox setEnabled:NO];
70 [showTitleCheckBox setEnabled:NO];
74 - (IBAction)toggleImage:(id)sender
76 if ( [sender state] == NSOnState ) {
77 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
78 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
79 [useInvertedCheckBox setEnabled:YES];
80 [useInvertedCheckBox setState:NSOnState];
82 [statusItem setImage:nil];
83 [statusItem setAlternateImage:nil];
84 [useInvertedCheckBox setEnabled:NO];
85 [useInvertedCheckBox setState:NSOffState];
89 - (IBAction)toggleInvertedImage:(id)sender
91 if ( [sender state] == NSOnState ) {
92 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
94 [statusItem setAlternateImage:nil];
98 - (IBAction)toggleTitle:(id)sender
100 if ( [sender state] == NSOnState ) {
101 [statusItem setTitle:@"ITStatusItem"];
103 [statusItem setTitle:nil];
108 /*************************************************************************/
110 #pragma mark ITTextView SUPPORT
111 /*************************************************************************/
113 - (IBAction)toggleCastsShadow:(id)sender
115 [testTextField setCastsShadow:([sender state] == NSOnState)];
119 /*************************************************************************/
121 #pragma mark ITTransientStatusWindow SUPPORT
122 /*************************************************************************/
124 - (IBAction)buildStatusWindow:(id)sender
126 NSImageView *imageView = nil;
127 ITTextField *textField = nil;
128 NSImage *image = [NSImage imageNamed:SW_IMAGE];
132 float imageWidth = 0.0;
133 float imageHeight = 0.0;
134 float textWidth = 0.0;
135 float textHeight = 0.0;
136 float contentHeight = 0.0;
137 float windowWidth = 0.0;
138 float windowHeight = 0.0;
140 NSString *text = [swSampleTextView string];
141 NSArray *lines = [text componentsSeparatedByString:@"\n"];
143 NSEnumerator *lineEnum = [lines objectEnumerator];
145 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
146 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
148 // Get image width and height.
149 imageWidth = [image size].width;
150 imageHeight = [image size].height;
152 // Iterate over each line to get text width and height
153 while ( oneLine = [lineEnum nextObject] ) {
154 // Get the width of one line, adding 8.0 because Apple sucks donkey rectum.
155 float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 );
156 // Add the height of this line to the total text height
157 textHeight += [oneLine sizeWithAttributes:attr].height;
158 // If this line wider than the last one, set it as the text width.
159 textWidth = ( ( textWidth > oneLineWidth ) ? textWidth : oneLineWidth );
162 // Add 4.0 to the final textHeight to accomodate the shadow.
165 // Set the content height to the greater of the text and image heights.
166 contentHeight = ( ( imageHeight > textHeight ) ? imageHeight : textHeight );
168 // Setup the Window, and remove all its contentview's subviews.
169 windowWidth = ( SW_PAD + imageWidth + SW_SPACE + textWidth + SW_PAD );
170 windowHeight = ( SW_PAD + contentHeight + SW_PAD );
171 [statusWindow setFrame:NSMakeRect(SW_BORDER, SW_BORDER, windowWidth, windowHeight) display:YES];
172 [[[statusWindow contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
174 // Setup, position, fill, and add the image view to the content view.
175 imageRect = NSMakeRect( SW_PAD,
176 (SW_PAD + ((contentHeight - imageHeight) / 2)),
179 imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease];
180 [imageView setImage:image];
181 [[statusWindow contentView] addSubview:imageView];
183 // Setup, position, fill, and add the text view to the content view.
184 textRect = NSMakeRect( (SW_PAD + imageWidth + SW_SPACE),
185 (SW_PAD + ((contentHeight - textHeight) / 2)),
188 textField = [[[ITTextField alloc] initWithFrame:textRect] autorelease];
189 [textField setEditable:NO];
190 [textField setSelectable:NO];
191 [textField setBordered:NO];
192 [textField setDrawsBackground:NO];
193 [textField setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:18]];
194 [textField setTextColor:[NSColor whiteColor]];
195 [textField setCastsShadow:YES];
196 [textField setStringValue:text];
197 [[statusWindow contentView] addSubview:textField];
199 [[statusWindow contentView] setNeedsDisplay:YES];
202 - (IBAction)showStatusWindow:(id)sender
204 // [[statusWindow contentView] setNeedsDisplay:YES];
205 [statusWindow setFrame:NSMakeRect( (0.0 - NSWidth([statusWindow frame])),
207 NSWidth([statusWindow frame]),
208 NSHeight([statusWindow frame]) )
210 [statusWindow orderFront:self];
211 [statusWindow setFrame:NSMakeRect( SW_BORDER,
213 NSWidth([statusWindow frame]),
214 NSHeight([statusWindow frame]) )
219 - (IBAction)hideStatusWindow:(id)sender
221 [statusWindow orderOut:self];
224 - (IBAction)setRotation:(id)sender
226 [statusWindow setRotation:([sender floatValue] * (pi / 180))];
230 /*************************************************************************/
232 #pragma mark NSWindow DELEGATE METHODS
233 /*************************************************************************/
235 - (void)windowWillMiniaturize:(NSNotification *)note
237 [[note object] setMiniwindowImage:[NSImage imageNamed:@"ITStatusItem"]];