2 #import "ITTransientStatusWindow.h"
3 #import "ITTSWBackgroundView.h"
4 #import "ITTextField.h"
5 #import "ITBevelView.h"
6 #import "ITCutWindowEffect.h"
7 #import "ITDissolveWindowEffect.h"
8 #import "ITSlideHorizontallyWindowEffect.h"
9 #import "ITSlideVerticallyWindowEffect.h"
10 #import "ITPivotWindowEffect.h"
16 #define SW_BORDER 32.0
17 #define SW_IMAGE @"Library"
20 @interface Controller (ITStatusItemSupport)
21 - (void)createStatusItem;
22 - (void)removeStatusItem;
26 @implementation Controller
30 [self createStatusItem];
31 [button setBezelStyle:1001];
32 [button setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:14]];
33 [button setTitle:@"Launch Manually"];
35 [button setFrameSize:NSMakeSize([button frame].size.width + 8, 24)];
36 [testTextField setCastsShadow:YES];
37 [tabView setAllowsDragging:YES];
38 [bevelView setBevelDepth:10];
39 statusWindow = [ITTransientStatusWindow sharedWindow];
40 [statusWindow setEntryEffect:[[ITCutWindowEffect alloc] initWithWindow:statusWindow]];
41 [statusWindow setExitEffect:[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow]];
42 [[statusWindow entryEffect] setEffectTime:[swEntrySpeedSlider floatValue]];
43 [[statusWindow exitEffect] setEffectTime:[swExitSpeedSlider floatValue]];
44 // [tabView setAllowsDragging:YES];
45 [[NSColorPanel sharedColorPanel] setShowsAlpha:YES];
48 /*************************************************************************/
50 #pragma mark ITStatusItem SUPPORT
51 /*************************************************************************/
53 - (void)createStatusItem
55 statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar]
56 withLength:NSVariableStatusItemLength];
58 if ( [showImageCheckBox state] == NSOnState ) {
59 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
62 if ( [useInvertedCheckBox state] == NSOnState ) {
63 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
66 if ( [showTitleCheckBox state] == NSOnState ) {
67 [statusItem setTitle:@"ITStatusItem"];
70 [statusItem setMenu:statusItemMenu];
72 [statusItemMenu addItemWithTitle:[NSString stringWithUTF8String:"★★★★★"]
77 - (void)removeStatusItem
79 [[statusItem statusBar] removeStatusItem:statusItem];
80 [statusItem autorelease];
84 - (IBAction)toggleStatusItem:(id)sender
86 if ( [sender state] == NSOnState ) {
87 [self createStatusItem];
88 [showImageCheckBox setEnabled:YES];
89 [showTitleCheckBox setEnabled:YES];
90 [useInvertedCheckBox setEnabled:YES];
92 [self removeStatusItem];
93 [showImageCheckBox setEnabled:NO];
94 [useInvertedCheckBox setEnabled:NO];
95 [showTitleCheckBox setEnabled:NO];
99 - (IBAction)toggleImage:(id)sender
101 if ( [sender state] == NSOnState ) {
102 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
103 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
104 [useInvertedCheckBox setEnabled:YES];
105 [useInvertedCheckBox setState:NSOnState];
107 [statusItem setImage:nil];
108 [statusItem setAlternateImage:nil];
109 [useInvertedCheckBox setEnabled:NO];
110 [useInvertedCheckBox setState:NSOffState];
114 - (IBAction)toggleInvertedImage:(id)sender
116 if ( [sender state] == NSOnState ) {
117 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
119 [statusItem setAlternateImage:nil];
123 - (IBAction)toggleTitle:(id)sender
125 if ( [sender state] == NSOnState ) {
126 [statusItem setTitle:@"ITStatusItem"];
128 [statusItem setTitle:nil];
133 /*************************************************************************/
135 #pragma mark ITTextView SUPPORT
136 /*************************************************************************/
138 - (IBAction)toggleCastsShadow:(id)sender
140 [testTextField setCastsShadow:([sender state] == NSOnState)];
144 /*************************************************************************/
146 #pragma mark ITTransientStatusWindow SUPPORT
147 /*************************************************************************/
149 - (IBAction)buildStatusWindow:(id)sender
151 NSImageView *imageView = nil;
152 ITTextField *textField = nil;
153 NSImage *image = [NSImage imageNamed:SW_IMAGE];
157 float imageWidth = 0.0;
158 float imageHeight = 0.0;
159 float textWidth = 0.0;
160 float textHeight = 0.0;
161 float contentHeight = 0.0;
162 float windowWidth = 0.0;
163 float windowHeight = 0.0;
165 NSString *text = [swSampleTextView string];
166 NSArray *lines = [text componentsSeparatedByString:@"\n"];
168 NSEnumerator *lineEnum = [lines objectEnumerator];
170 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
171 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
173 // Get image width and height.
174 imageWidth = [image size].width;
175 imageHeight = [image size].height;
177 // Iterate over each line to get text width and height
178 while ( oneLine = [lineEnum nextObject] ) {
179 // Get the width of one line, adding 8.0 because Apple sucks donkey rectum.
180 float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 );
181 // Add the height of this line to the total text height
182 textHeight += [oneLine sizeWithAttributes:attr].height;
183 // If this line wider than the last one, set it as the text width.
184 textWidth = ( ( textWidth > oneLineWidth ) ? textWidth : oneLineWidth );
187 // Add 4.0 to the final textHeight to accomodate the shadow.
189 NSLog(@"%f", textHeight);
190 // Set the content height to the greater of the text and image heights.
191 contentHeight = ( ( imageHeight > textHeight ) ? imageHeight : textHeight );
193 // Setup the Window, and remove all its contentview's subviews.
194 windowWidth = ( SW_PAD + imageWidth + SW_SPACE + textWidth + SW_PAD );
195 windowHeight = ( SW_PAD + contentHeight + SW_PAD );
196 [statusWindow setFrame:NSMakeRect(SW_BORDER, SW_BORDER, windowWidth, windowHeight) display:YES animate:YES];
197 [[[statusWindow contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
199 // Setup, position, fill, and add the image view to the content view.
200 imageRect = NSMakeRect( SW_PAD,
201 (SW_PAD + ((contentHeight - imageHeight) / 2)),
204 imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease];
205 [imageView setImage:image];
206 [[statusWindow contentView] addSubview:imageView];
208 // Setup, position, fill, and add the text view to the content view.
209 textRect = NSMakeRect( (SW_PAD + imageWidth + SW_SPACE),
210 (SW_PAD + ((contentHeight - textHeight) / 2)),
213 textField = [[[ITTextField alloc] initWithFrame:textRect] autorelease];
214 [textField setEditable:NO];
215 [textField setSelectable:NO];
216 [textField setBordered:NO];
217 [textField setDrawsBackground:NO];
218 [textField setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:18]];
219 [textField setTextColor:[NSColor whiteColor]];
220 [textField setCastsShadow:YES];
221 [textField setStringValue:text];
222 [[statusWindow contentView] addSubview:textField];
224 [[statusWindow contentView] setNeedsDisplay:YES];
227 - (IBAction)toggleStatusWindow:(id)sender
229 if ( ([statusWindow visibilityState] == ITWindowHiddenState) ||
230 ([statusWindow visibilityState] == ITWindowVanishingState) ) {
231 [[statusWindow contentView] setNeedsDisplay:YES];
232 [statusWindow appear:self];
234 [statusWindow vanish:self];
238 - (IBAction)changeWindowSetting:(id)sender
240 if ( [sender tag] == 3010 ) {
242 if ( [sender indexOfSelectedItem] == 0) {
243 [statusWindow setExitMode:ITTransientStatusWindowExitAfterDelay];
244 } else if ( [sender indexOfSelectedItem] == 1) {
245 [statusWindow setExitMode:ITTransientStatusWindowExitOnCommand];
248 } else if ( [sender tag] == 3020 ) {
250 } else if ( [sender tag] == 3030 ) {
251 [statusWindow setExitDelay:[sender floatValue]];
252 } else if ( [sender tag] == 3040 ) {
253 [statusWindow setVerticalPosition:[sender indexOfSelectedItem]];
254 } else if ( [sender tag] == 3050 ) {
255 [statusWindow setHorizontalPosition:[sender indexOfSelectedItem]];
256 } else if ( [sender tag] == 3060 ) {
257 [[statusWindow entryEffect] setEffectTime:[sender floatValue]];
258 } else if ( [sender tag] == 3061 ) {
259 [[statusWindow exitEffect] setEffectTime:[sender floatValue]];
260 } else if ( [sender tag] == 3070 ) {
262 if ( [sender indexOfSelectedItem] == 0 ) {
263 [statusWindow setEntryEffect:[[[ITCutWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
264 } else if ( [sender indexOfSelectedItem] == 1 ) {
265 [statusWindow setEntryEffect:[[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
266 } else if ( [sender indexOfSelectedItem] == 2 ) {
267 [statusWindow setEntryEffect:[[[ITSlideVerticallyWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
268 } else if ( [sender indexOfSelectedItem] == 3 ) {
269 [statusWindow setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
270 } else if ( [sender indexOfSelectedItem] == 4 ) {
271 [statusWindow setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
274 [[statusWindow entryEffect] setEffectTime:[swEntrySpeedSlider floatValue]];
276 } else if ( [sender tag] == 3080 ) {
278 if ( [sender indexOfSelectedItem] == 0 ) {
279 [statusWindow setExitEffect:[[ITCutWindowEffect alloc] initWithWindow:statusWindow]];
280 } else if ( [sender indexOfSelectedItem] == 1 ) {
281 [statusWindow setExitEffect:[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow]];
282 } else if ( [sender indexOfSelectedItem] == 2 ) {
283 [statusWindow setExitEffect:[[ITSlideVerticallyWindowEffect alloc] initWithWindow:statusWindow]];
284 } else if ( [sender indexOfSelectedItem] == 3 ) {
285 [statusWindow setExitEffect:[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:statusWindow]];
286 } else if ( [sender indexOfSelectedItem] == 4 ) {
287 [statusWindow setExitEffect:[[ITPivotWindowEffect alloc] initWithWindow:statusWindow]];
290 [[statusWindow exitEffect] setEffectTime:[swExitSpeedSlider floatValue]];
292 } else if ( [sender tag] == 3090 ) {
294 if ( [sender indexOfSelectedItem] == 0 ) {
295 [(ITTSWBackgroundView *)[statusWindow contentView] setBackgroundMode:ITTSWBackgroundApple];
296 } else if ( [sender indexOfSelectedItem] == 1 ) {
297 [(ITTSWBackgroundView *)[statusWindow contentView] setBackgroundMode:ITTSWBackgroundReadable];
298 } else if ( [sender indexOfSelectedItem] == 2 ) {
299 [(ITTSWBackgroundView *)[statusWindow contentView] setBackgroundMode:ITTSWBackgroundColored];
302 } else if ( [sender tag] == 3100 ) {
303 [(ITTSWBackgroundView *)[statusWindow contentView] setBackgroundColor:[sender color]];
308 /*************************************************************************/
310 #pragma mark ITTabView SUPPORT
311 /*************************************************************************/
313 - (IBAction)toggleTabDragging:(id)sender
315 if ([sender state] == NSOnState) {
316 [tabView setAllowsDragging:YES];
318 [tabView setAllowsDragging:NO];
322 - (IBAction)toggleCommandDragging:(id)sender
324 if ([sender state] == NSOnState) {
325 [tabView setRequiredModifiers:NSCommandKeyMask];
327 [tabView setRequiredModifiers:0];
331 - (IBAction)toggleControlDragging:(id)sender
335 - (IBAction)toggleOptionDragging:(id)sender
339 - (IBAction)toggleShiftDragging:(id)sender
344 /*************************************************************************/
346 #pragma mark ITBevelView SUPPORT
347 /*************************************************************************/
349 - (IBAction)changeBevelViewSetting:(id)sender
351 [bevelView setBevelDepth:[sender intValue]];
355 /*************************************************************************/
357 #pragma mark ITButton SUPPORT
358 /*************************************************************************/
361 /*************************************************************************/
363 #pragma mark NSWindow DELEGATE METHODS
364 /*************************************************************************/
366 - (void)windowWillMiniaturize:(NSNotification *)note
368 [[note object] setMiniwindowImage:[NSImage imageNamed:@"ITStatusItem"]];