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"];
33 [button setButtonType:NSMomentaryLight];
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:[swSpeedSlider floatValue]];
43 [[statusWindow exitEffect] setEffectTime:[swSpeedSlider floatValue]];
44 // [tabView setAllowsDragging: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.
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];
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 [[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"]];