2 #import "ITTransientStatusWindow.h"
3 #import "ITTextField.h"
4 #import "ITPivotWindowEffect.h"
5 #import "ITDissolveWindowEffect.h"
6 #import "ITCutWindowEffect.h"
11 #define SW_BORDER 32.0
12 #define SW_IMAGE @"Library"
14 @interface Controller (ITStatusItemSupport)
15 - (void)createStatusItem;
16 - (void)removeStatusItem;
20 @implementation Controller
24 [self createStatusItem];
25 [testTextField setCastsShadow:YES];
26 [tabView setAllowsDragging:YES];
27 statusWindow = [ITTransientStatusWindow sharedWindow];
28 // [tabView setAllowsDragging:YES];
31 /*************************************************************************/
33 #pragma mark ITStatusItem SUPPORT
34 /*************************************************************************/
36 - (void)createStatusItem
38 statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar]
39 withLength:NSVariableStatusItemLength];
41 if ( [showImageCheckBox state] == NSOnState ) {
42 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
45 if ( [useInvertedCheckBox state] == NSOnState ) {
46 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
49 if ( [showTitleCheckBox state] == NSOnState ) {
50 [statusItem setTitle:@"ITStatusItem"];
53 [statusItem setMenu:statusItemMenu];
56 - (void)removeStatusItem
58 [[statusItem statusBar] removeStatusItem:statusItem];
59 [statusItem autorelease];
63 - (IBAction)toggleStatusItem:(id)sender
65 if ( [sender state] == NSOnState ) {
66 [self createStatusItem];
67 [showImageCheckBox setEnabled:YES];
68 [showTitleCheckBox setEnabled:YES];
69 [useInvertedCheckBox setEnabled:YES];
71 [self removeStatusItem];
72 [showImageCheckBox setEnabled:NO];
73 [useInvertedCheckBox setEnabled:NO];
74 [showTitleCheckBox setEnabled:NO];
78 - (IBAction)toggleImage:(id)sender
80 if ( [sender state] == NSOnState ) {
81 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
82 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
83 [useInvertedCheckBox setEnabled:YES];
84 [useInvertedCheckBox setState:NSOnState];
86 [statusItem setImage:nil];
87 [statusItem setAlternateImage:nil];
88 [useInvertedCheckBox setEnabled:NO];
89 [useInvertedCheckBox setState:NSOffState];
93 - (IBAction)toggleInvertedImage:(id)sender
95 if ( [sender state] == NSOnState ) {
96 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
98 [statusItem setAlternateImage:nil];
102 - (IBAction)toggleTitle:(id)sender
104 if ( [sender state] == NSOnState ) {
105 [statusItem setTitle:@"ITStatusItem"];
107 [statusItem setTitle:nil];
112 /*************************************************************************/
114 #pragma mark ITTextView SUPPORT
115 /*************************************************************************/
117 - (IBAction)toggleCastsShadow:(id)sender
119 [testTextField setCastsShadow:([sender state] == NSOnState)];
123 /*************************************************************************/
125 #pragma mark ITTransientStatusWindow SUPPORT
126 /*************************************************************************/
128 - (IBAction)buildStatusWindow:(id)sender
130 NSImageView *imageView = nil;
131 ITTextField *textField = nil;
132 NSImage *image = [NSImage imageNamed:SW_IMAGE];
136 float imageWidth = 0.0;
137 float imageHeight = 0.0;
138 float textWidth = 0.0;
139 float textHeight = 0.0;
140 float contentHeight = 0.0;
141 float windowWidth = 0.0;
142 float windowHeight = 0.0;
144 NSString *text = [swSampleTextView string];
145 NSArray *lines = [text componentsSeparatedByString:@"\n"];
147 NSEnumerator *lineEnum = [lines objectEnumerator];
149 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
150 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
152 // Get image width and height.
153 imageWidth = [image size].width;
154 imageHeight = [image size].height;
156 // Iterate over each line to get text width and height
157 while ( oneLine = [lineEnum nextObject] ) {
158 // Get the width of one line, adding 8.0 because Apple sucks donkey rectum.
159 float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 );
160 // Add the height of this line to the total text height
161 textHeight += [oneLine sizeWithAttributes:attr].height;
162 // If this line wider than the last one, set it as the text width.
163 textWidth = ( ( textWidth > oneLineWidth ) ? textWidth : oneLineWidth );
166 // Add 4.0 to the final textHeight to accomodate the shadow.
169 // Set the content height to the greater of the text and image heights.
170 contentHeight = ( ( imageHeight > textHeight ) ? imageHeight : textHeight );
172 // Setup the Window, and remove all its contentview's subviews.
173 windowWidth = ( SW_PAD + imageWidth + SW_SPACE + textWidth + SW_PAD );
174 windowHeight = ( SW_PAD + contentHeight + SW_PAD );
175 [statusWindow setFrame:NSMakeRect(SW_BORDER, SW_BORDER, windowWidth, windowHeight) display:YES];
176 [[[statusWindow contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
178 // Setup, position, fill, and add the image view to the content view.
179 imageRect = NSMakeRect( SW_PAD,
180 (SW_PAD + ((contentHeight - imageHeight) / 2)),
183 imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease];
184 [imageView setImage:image];
185 [[statusWindow contentView] addSubview:imageView];
187 // Setup, position, fill, and add the text view to the content view.
188 textRect = NSMakeRect( (SW_PAD + imageWidth + SW_SPACE),
189 (SW_PAD + ((contentHeight - textHeight) / 2)),
192 textField = [[[ITTextField alloc] initWithFrame:textRect] autorelease];
193 [textField setEditable:NO];
194 [textField setSelectable:NO];
195 [textField setBordered:NO];
196 [textField setDrawsBackground:NO];
197 [textField setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:18]];
198 [textField setTextColor:[NSColor whiteColor]];
199 [textField setCastsShadow:YES];
200 [textField setStringValue:text];
201 [[statusWindow contentView] addSubview:textField];
203 [[statusWindow contentView] setNeedsDisplay:YES];
205 // [statusWindow setEntryEffect:[[ITPivotWindowEffect alloc] initWithWindow:statusWindow]];
206 // [statusWindow setExitEffect:[[ITPivotWindowEffect alloc] initWithWindow:statusWindow]];
207 [statusWindow setEntryEffect:[[ITCutWindowEffect alloc] initWithWindow:statusWindow]];
208 [statusWindow setExitEffect: [[ITDissolveWindowEffect alloc] initWithWindow:statusWindow]];
211 - (IBAction)toggleStatusWindow:(id)sender
213 if ( ([statusWindow visibilityState] == ITTransientStatusWindowHiddenState) ||
214 ([statusWindow visibilityState] == ITTransientStatusWindowVanishingState) ) {
215 [[statusWindow contentView] setNeedsDisplay:YES];
216 [statusWindow appear:self];
218 [statusWindow vanish:self];
222 - (IBAction)changeWindowSetting:(id)sender
224 switch ( [sender tag] )
226 case 3010: // Not yet supported.
228 case 3020: // Not yet supported.
230 case 3030: // Change vanish delay
231 [statusWindow setExitDelay:[sender floatValue]];
233 case 3040: // Change vertical position
234 [statusWindow setVerticalPosition:[sender indexOfSelectedItem]];
236 case 3050: // Change horizontal position
237 [statusWindow setHorizontalPosition:[sender indexOfSelectedItem]];
239 case 3060: // Change effect speed
240 [[statusWindow entryEffect] setEffectTime:[sender floatValue]];
241 [[statusWindow exitEffect] setEffectTime:[sender floatValue]];
243 case 3070: // Change entry effect
245 case 3080: // Change exit effect
251 /*************************************************************************/
253 #pragma mark ITTabView SUPPORT
254 /*************************************************************************/
256 - (IBAction)toggleTabDragging:(id)sender
258 if ([sender state] == NSOnState) {
259 [tabView setAllowsDragging:YES];
261 [tabView setAllowsDragging:NO];
265 - (IBAction)toggleCommandDragging:(id)sender
267 if ([sender state] == NSOnState) {
268 [tabView setRequiredModifiers:NSCommandKeyMask];
270 [tabView setRequiredModifiers:0];
274 - (IBAction)toggleControlDragging:(id)sender
278 - (IBAction)toggleOptionDragging:(id)sender
282 - (IBAction)toggleShiftDragging:(id)sender
287 /*************************************************************************/
289 #pragma mark NSWindow DELEGATE METHODS
290 /*************************************************************************/
292 - (void)windowWillMiniaturize:(NSNotification *)note
294 [[note object] setMiniwindowImage:[NSImage imageNamed:@"ITStatusItem"]];