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 [tabView setAllowsDragging:YES];
24 statusWindow = [ITTransientStatusWindow sharedWindow];
25 // [tabView setAllowsDragging:YES];
28 /*************************************************************************/
30 #pragma mark ITStatusItem SUPPORT
31 /*************************************************************************/
33 - (void)createStatusItem
35 statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar]
36 withLength:NSVariableStatusItemLength];
38 if ( [showImageCheckBox state] == NSOnState ) {
39 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
42 if ( [useInvertedCheckBox state] == NSOnState ) {
43 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
46 if ( [showTitleCheckBox state] == NSOnState ) {
47 [statusItem setTitle:@"ITStatusItem"];
50 [statusItem setMenu:statusItemMenu];
53 - (void)removeStatusItem
55 [[statusItem statusBar] removeStatusItem:statusItem];
56 [statusItem autorelease];
60 - (IBAction)toggleStatusItem:(id)sender
62 if ( [sender state] == NSOnState ) {
63 [self createStatusItem];
64 [showImageCheckBox setEnabled:YES];
65 [showTitleCheckBox setEnabled:YES];
66 [useInvertedCheckBox setEnabled:YES];
68 [self removeStatusItem];
69 [showImageCheckBox setEnabled:NO];
70 [useInvertedCheckBox setEnabled:NO];
71 [showTitleCheckBox setEnabled:NO];
75 - (IBAction)toggleImage:(id)sender
77 if ( [sender state] == NSOnState ) {
78 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
79 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
80 [useInvertedCheckBox setEnabled:YES];
81 [useInvertedCheckBox setState:NSOnState];
83 [statusItem setImage:nil];
84 [statusItem setAlternateImage:nil];
85 [useInvertedCheckBox setEnabled:NO];
86 [useInvertedCheckBox setState:NSOffState];
90 - (IBAction)toggleInvertedImage:(id)sender
92 if ( [sender state] == NSOnState ) {
93 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
95 [statusItem setAlternateImage:nil];
99 - (IBAction)toggleTitle:(id)sender
101 if ( [sender state] == NSOnState ) {
102 [statusItem setTitle:@"ITStatusItem"];
104 [statusItem setTitle:nil];
109 /*************************************************************************/
111 #pragma mark ITTextView SUPPORT
112 /*************************************************************************/
114 - (IBAction)toggleCastsShadow:(id)sender
116 [testTextField setCastsShadow:([sender state] == NSOnState)];
120 /*************************************************************************/
122 #pragma mark ITTransientStatusWindow SUPPORT
123 /*************************************************************************/
125 - (IBAction)buildStatusWindow:(id)sender
127 NSImageView *imageView = nil;
128 ITTextField *textField = nil;
129 NSImage *image = [NSImage imageNamed:SW_IMAGE];
133 float imageWidth = 0.0;
134 float imageHeight = 0.0;
135 float textWidth = 0.0;
136 float textHeight = 0.0;
137 float contentHeight = 0.0;
138 float windowWidth = 0.0;
139 float windowHeight = 0.0;
141 NSString *text = [swSampleTextView string];
142 NSArray *lines = [text componentsSeparatedByString:@"\n"];
144 NSEnumerator *lineEnum = [lines objectEnumerator];
146 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
147 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
149 // Get image width and height.
150 imageWidth = [image size].width;
151 imageHeight = [image size].height;
153 // Iterate over each line to get text width and height
154 while ( oneLine = [lineEnum nextObject] ) {
155 // Get the width of one line, adding 8.0 because Apple sucks donkey rectum.
156 float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 );
157 // Add the height of this line to the total text height
158 textHeight += [oneLine sizeWithAttributes:attr].height;
159 // If this line wider than the last one, set it as the text width.
160 textWidth = ( ( textWidth > oneLineWidth ) ? textWidth : oneLineWidth );
163 // Add 4.0 to the final textHeight to accomodate the shadow.
166 // Set the content height to the greater of the text and image heights.
167 contentHeight = ( ( imageHeight > textHeight ) ? imageHeight : textHeight );
169 // Setup the Window, and remove all its contentview's subviews.
170 windowWidth = ( SW_PAD + imageWidth + SW_SPACE + textWidth + SW_PAD );
171 windowHeight = ( SW_PAD + contentHeight + SW_PAD );
172 [statusWindow setFrame:NSMakeRect(SW_BORDER, SW_BORDER, windowWidth, windowHeight) display:YES];
173 [[[statusWindow contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
175 // Setup, position, fill, and add the image view to the content view.
176 imageRect = NSMakeRect( SW_PAD,
177 (SW_PAD + ((contentHeight - imageHeight) / 2)),
180 imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease];
181 [imageView setImage:image];
182 [[statusWindow contentView] addSubview:imageView];
184 // Setup, position, fill, and add the text view to the content view.
185 textRect = NSMakeRect( (SW_PAD + imageWidth + SW_SPACE),
186 (SW_PAD + ((contentHeight - textHeight) / 2)),
189 textField = [[[ITTextField alloc] initWithFrame:textRect] autorelease];
190 [textField setEditable:NO];
191 [textField setSelectable:NO];
192 [textField setBordered:NO];
193 [textField setDrawsBackground:NO];
194 [textField setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:18]];
195 [textField setTextColor:[NSColor whiteColor]];
196 [textField setCastsShadow:YES];
197 [textField setStringValue:text];
198 [[statusWindow contentView] addSubview:textField];
200 [[statusWindow contentView] setNeedsDisplay:YES];
203 - (IBAction)showStatusWindow:(id)sender
205 // [[statusWindow contentView] setNeedsDisplay:YES];
206 [statusWindow setFrame:NSMakeRect( (0.0 - NSWidth([statusWindow frame])),
208 NSWidth([statusWindow frame]),
209 NSHeight([statusWindow frame]) )
211 [statusWindow orderFront:self];
212 [statusWindow setFrame:NSMakeRect( SW_BORDER,
214 NSWidth([statusWindow frame]),
215 NSHeight([statusWindow frame]) )
220 - (IBAction)hideStatusWindow:(id)sender
222 [statusWindow orderOut:self];
225 - (IBAction)setRotation:(id)sender
227 [statusWindow setRotation:([sender floatValue] * (pi / 180))];
230 /*************************************************************************/
232 #pragma mark ITTransientStatusWindow SUPPORT
233 /*************************************************************************/
235 - (IBAction)toggleTabDragging:(id)sender
237 if ([sender state] == NSOnState) {
238 [tabView setAllowsDragging:YES];
240 [tabView setAllowsDragging:NO];
244 - (IBAction)toggleCommandDragging:(id)sender
246 if ([sender state] == NSOnState) {
247 [tabView setRequiredModifiers:NSCommandKeyMask];
249 [tabView setRequiredModifiers:0];
253 - (IBAction)toggleControlDragging:(id)sender
257 - (IBAction)toggleOptionDragging:(id)sender
261 - (IBAction)toggleShiftDragging:(id)sender
265 /*************************************************************************/
267 #pragma mark NSWindow DELEGATE METHODS
268 /*************************************************************************/
270 - (void)windowWillMiniaturize:(NSNotification *)note
272 [[note object] setMiniwindowImage:[NSImage imageNamed:@"ITStatusItem"]];