2 #import "ITTransientStatusWindow.h"
3 #import "ITTextField.h"
4 #import "ITBevelView.h"
5 #import "ITCutWindowEffect.h"
6 #import "ITDissolveWindowEffect.h"
7 #import "ITSlideHorizontallyWindowEffect.h"
8 #import "ITSlideVerticallyWindowEffect.h"
9 #import "ITPivotWindowEffect.h"
15 #define SW_BORDER 32.0
16 #define SW_IMAGE @"Library"
19 @interface Controller (ITStatusItemSupport)
20 - (void)createStatusItem;
21 - (void)removeStatusItem;
25 @implementation Controller
29 [self createStatusItem];
30 [button setBezelStyle:1001];
31 [button setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:14]];
32 [button setTitle:@"Launch Manually"];
34 [button setFrameSize:NSMakeSize([button frame].size.width + 8, 24)];
35 [testTextField setCastsShadow:YES];
36 [tabView setAllowsDragging:YES];
37 [bevelView setBevelDepth:10];
38 statusWindow = [ITTransientStatusWindow sharedWindow];
39 [statusWindow setEntryEffect:[[ITCutWindowEffect alloc] initWithWindow:statusWindow]];
40 [statusWindow setExitEffect:[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow]];
41 [[statusWindow entryEffect] setEffectTime:[swSpeedSlider floatValue]];
42 [[statusWindow exitEffect] setEffectTime:[swSpeedSlider floatValue]];
43 // [tabView setAllowsDragging:YES];
47 /*************************************************************************/
49 #pragma mark ITStatusItem SUPPORT
50 /*************************************************************************/
52 - (void)createStatusItem
54 statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar]
55 withLength:NSVariableStatusItemLength];
57 if ( [showImageCheckBox state] == NSOnState ) {
58 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
61 if ( [useInvertedCheckBox state] == NSOnState ) {
62 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
65 if ( [showTitleCheckBox state] == NSOnState ) {
66 [statusItem setTitle:@"ITStatusItem"];
69 [statusItem setMenu:statusItemMenu];
71 [statusItemMenu addItemWithTitle:[NSString stringWithUTF8String:"★★★★★"]
76 - (void)removeStatusItem
78 [[statusItem statusBar] removeStatusItem:statusItem];
79 [statusItem autorelease];
83 - (IBAction)toggleStatusItem:(id)sender
85 if ( [sender state] == NSOnState ) {
86 [self createStatusItem];
87 [showImageCheckBox setEnabled:YES];
88 [showTitleCheckBox setEnabled:YES];
89 [useInvertedCheckBox setEnabled:YES];
91 [self removeStatusItem];
92 [showImageCheckBox setEnabled:NO];
93 [useInvertedCheckBox setEnabled:NO];
94 [showTitleCheckBox setEnabled:NO];
98 - (IBAction)toggleImage:(id)sender
100 if ( [sender state] == NSOnState ) {
101 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
102 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
103 [useInvertedCheckBox setEnabled:YES];
104 [useInvertedCheckBox setState:NSOnState];
106 [statusItem setImage:nil];
107 [statusItem setAlternateImage:nil];
108 [useInvertedCheckBox setEnabled:NO];
109 [useInvertedCheckBox setState:NSOffState];
113 - (IBAction)toggleInvertedImage:(id)sender
115 if ( [sender state] == NSOnState ) {
116 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
118 [statusItem setAlternateImage:nil];
122 - (IBAction)toggleTitle:(id)sender
124 if ( [sender state] == NSOnState ) {
125 [statusItem setTitle:@"ITStatusItem"];
127 [statusItem setTitle:nil];
132 /*************************************************************************/
134 #pragma mark ITTextView SUPPORT
135 /*************************************************************************/
137 - (IBAction)toggleCastsShadow:(id)sender
139 [testTextField setCastsShadow:([sender state] == NSOnState)];
143 /*************************************************************************/
145 #pragma mark ITTransientStatusWindow SUPPORT
146 /*************************************************************************/
148 - (IBAction)buildStatusWindow:(id)sender
150 NSImageView *imageView = nil;
151 ITTextField *textField = nil;
152 NSImage *image = [NSImage imageNamed:SW_IMAGE];
156 float imageWidth = 0.0;
157 float imageHeight = 0.0;
158 float textWidth = 0.0;
159 float textHeight = 0.0;
160 float contentHeight = 0.0;
161 float windowWidth = 0.0;
162 float windowHeight = 0.0;
164 NSString *text = [swSampleTextView string];
165 NSArray *lines = [text componentsSeparatedByString:@"\n"];
167 NSEnumerator *lineEnum = [lines objectEnumerator];
169 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
170 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
172 // Get image width and height.
173 imageWidth = [image size].width;
174 imageHeight = [image size].height;
176 // Iterate over each line to get text width and height
177 while ( oneLine = [lineEnum nextObject] ) {
178 // Get the width of one line, adding 8.0 because Apple sucks donkey rectum.
179 float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 );
180 // Add the height of this line to the total text height
181 textHeight += [oneLine sizeWithAttributes:attr].height;
182 // If this line wider than the last one, set it as the text width.
183 textWidth = ( ( textWidth > oneLineWidth ) ? textWidth : oneLineWidth );
186 // Add 4.0 to the final textHeight to accomodate the shadow.
188 NSLog(@"%f", textHeight);
189 // Set the content height to the greater of the text and image heights.
190 contentHeight = ( ( imageHeight > textHeight ) ? imageHeight : textHeight );
192 // Setup the Window, and remove all its contentview's subviews.
193 windowWidth = ( SW_PAD + imageWidth + SW_SPACE + textWidth + SW_PAD );
194 windowHeight = ( SW_PAD + contentHeight + SW_PAD );
195 [statusWindow setFrame:NSMakeRect(SW_BORDER, SW_BORDER, windowWidth, windowHeight) display:YES];
196 [[[statusWindow contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
198 // Setup, position, fill, and add the image view to the content view.
199 imageRect = NSMakeRect( SW_PAD,
200 (SW_PAD + ((contentHeight - imageHeight) / 2)),
203 imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease];
204 [imageView setImage:image];
205 [[statusWindow contentView] addSubview:imageView];
207 // Setup, position, fill, and add the text view to the content view.
208 textRect = NSMakeRect( (SW_PAD + imageWidth + SW_SPACE),
209 (SW_PAD + ((contentHeight - textHeight) / 2)),
212 textField = [[[ITTextField alloc] initWithFrame:textRect] autorelease];
213 [textField setEditable:NO];
214 [textField setSelectable:NO];
215 [textField setBordered:NO];
216 [textField setDrawsBackground:NO];
217 [textField setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:18]];
218 [textField setTextColor:[NSColor whiteColor]];
219 [textField setCastsShadow:YES];
220 [textField setStringValue:text];
221 [textField setShadowSaturation:[swShadowSaturation floatValue]];
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 [[statusWindow exitEffect] setEffectTime:[sender floatValue]];
259 } else if ( [sender tag] == 3070 ) {
261 if ( [sender indexOfSelectedItem] == 0 ) {
262 [statusWindow setEntryEffect:[[[ITCutWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
263 } else if ( [sender indexOfSelectedItem] == 1 ) {
264 [statusWindow setEntryEffect:[[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
265 } else if ( [sender indexOfSelectedItem] == 2 ) {
266 [statusWindow setEntryEffect:[[[ITSlideVerticallyWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
267 } else if ( [sender indexOfSelectedItem] == 3 ) {
268 [statusWindow setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
269 } else if ( [sender indexOfSelectedItem] == 4 ) {
270 [statusWindow setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
273 [[statusWindow entryEffect] setEffectTime:[swSpeedSlider floatValue]];
275 } else if ( [sender tag] == 3080 ) {
277 if ( [sender indexOfSelectedItem] == 0 ) {
278 [statusWindow setExitEffect:[[ITCutWindowEffect alloc] initWithWindow:statusWindow]];
279 } else if ( [sender indexOfSelectedItem] == 1 ) {
280 [statusWindow setExitEffect:[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow]];
281 } else if ( [sender indexOfSelectedItem] == 2 ) {
282 [statusWindow setExitEffect:[[ITSlideVerticallyWindowEffect alloc] initWithWindow:statusWindow]];
283 } else if ( [sender indexOfSelectedItem] == 3 ) {
284 [statusWindow setExitEffect:[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:statusWindow]];
285 } else if ( [sender indexOfSelectedItem] == 4 ) {
286 [statusWindow setExitEffect:[[ITPivotWindowEffect alloc] initWithWindow:statusWindow]];
289 [[statusWindow exitEffect] setEffectTime:[swSpeedSlider floatValue]];
295 /*************************************************************************/
297 #pragma mark ITTabView SUPPORT
298 /*************************************************************************/
300 - (IBAction)toggleTabDragging:(id)sender
302 if ([sender state] == NSOnState) {
303 [tabView setAllowsDragging:YES];
305 [tabView setAllowsDragging:NO];
309 - (IBAction)toggleCommandDragging:(id)sender
311 if ([sender state] == NSOnState) {
312 [tabView setRequiredModifiers:NSCommandKeyMask];
314 [tabView setRequiredModifiers:0];
318 - (IBAction)toggleControlDragging:(id)sender
322 - (IBAction)toggleOptionDragging:(id)sender
326 - (IBAction)toggleShiftDragging:(id)sender
331 /*************************************************************************/
333 #pragma mark ITBevelView SUPPORT
334 /*************************************************************************/
336 - (IBAction)changeBevelViewSetting:(id)sender
338 [bevelView setBevelDepth:[sender intValue]];
342 /*************************************************************************/
344 #pragma mark ITButton SUPPORT
345 /*************************************************************************/
348 /*************************************************************************/
350 #pragma mark NSWindow DELEGATE METHODS
351 /*************************************************************************/
353 - (void)windowWillMiniaturize:(NSNotification *)note
355 [[note object] setMiniwindowImage:[NSImage imageNamed:@"ITStatusItem"]];