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 [testTextField setCastsShadow:YES];
31 [tabView setAllowsDragging:YES];
32 [bevelView setBevelDepth:10];
33 statusWindow = [ITTransientStatusWindow sharedWindow];
34 [statusWindow setEntryEffect:[[ITCutWindowEffect alloc] initWithWindow:statusWindow]];
35 [statusWindow setExitEffect:[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow]];
36 [[statusWindow entryEffect] setEffectTime:[swSpeedSlider floatValue]];
37 [[statusWindow exitEffect] setEffectTime:[swSpeedSlider floatValue]];
38 // [tabView setAllowsDragging:YES];
42 /*************************************************************************/
44 #pragma mark ITStatusItem SUPPORT
45 /*************************************************************************/
47 - (void)createStatusItem
49 statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar]
50 withLength:NSVariableStatusItemLength];
52 if ( [showImageCheckBox state] == NSOnState ) {
53 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
56 if ( [useInvertedCheckBox state] == NSOnState ) {
57 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
60 if ( [showTitleCheckBox state] == NSOnState ) {
61 [statusItem setTitle:@"ITStatusItem"];
64 [statusItem setMenu:statusItemMenu];
66 [statusItemMenu addItemWithTitle:[NSString stringWithUTF8String:"★★★★★"]
71 - (void)removeStatusItem
73 [[statusItem statusBar] removeStatusItem:statusItem];
74 [statusItem autorelease];
78 - (IBAction)toggleStatusItem:(id)sender
80 if ( [sender state] == NSOnState ) {
81 [self createStatusItem];
82 [showImageCheckBox setEnabled:YES];
83 [showTitleCheckBox setEnabled:YES];
84 [useInvertedCheckBox setEnabled:YES];
86 [self removeStatusItem];
87 [showImageCheckBox setEnabled:NO];
88 [useInvertedCheckBox setEnabled:NO];
89 [showTitleCheckBox setEnabled:NO];
93 - (IBAction)toggleImage:(id)sender
95 if ( [sender state] == NSOnState ) {
96 [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
97 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
98 [useInvertedCheckBox setEnabled:YES];
99 [useInvertedCheckBox setState:NSOnState];
101 [statusItem setImage:nil];
102 [statusItem setAlternateImage:nil];
103 [useInvertedCheckBox setEnabled:NO];
104 [useInvertedCheckBox setState:NSOffState];
108 - (IBAction)toggleInvertedImage:(id)sender
110 if ( [sender state] == NSOnState ) {
111 [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
113 [statusItem setAlternateImage:nil];
117 - (IBAction)toggleTitle:(id)sender
119 if ( [sender state] == NSOnState ) {
120 [statusItem setTitle:@"ITStatusItem"];
122 [statusItem setTitle:nil];
127 /*************************************************************************/
129 #pragma mark ITTextView SUPPORT
130 /*************************************************************************/
132 - (IBAction)toggleCastsShadow:(id)sender
134 [testTextField setCastsShadow:([sender state] == NSOnState)];
138 /*************************************************************************/
140 #pragma mark ITTransientStatusWindow SUPPORT
141 /*************************************************************************/
143 - (IBAction)buildStatusWindow:(id)sender
145 NSImageView *imageView = nil;
146 ITTextField *textField = nil;
147 NSImage *image = [NSImage imageNamed:SW_IMAGE];
151 float imageWidth = 0.0;
152 float imageHeight = 0.0;
153 float textWidth = 0.0;
154 float textHeight = 0.0;
155 float contentHeight = 0.0;
156 float windowWidth = 0.0;
157 float windowHeight = 0.0;
159 NSString *text = [swSampleTextView string];
160 NSArray *lines = [text componentsSeparatedByString:@"\n"];
162 NSEnumerator *lineEnum = [lines objectEnumerator];
164 NSFont *font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
165 NSDictionary *attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
167 // Get image width and height.
168 imageWidth = [image size].width;
169 imageHeight = [image size].height;
171 // Iterate over each line to get text width and height
172 while ( oneLine = [lineEnum nextObject] ) {
173 // Get the width of one line, adding 8.0 because Apple sucks donkey rectum.
174 float oneLineWidth = ( [oneLine sizeWithAttributes:attr].width + 8.0 );
175 // Add the height of this line to the total text height
176 textHeight += [oneLine sizeWithAttributes:attr].height;
177 // If this line wider than the last one, set it as the text width.
178 textWidth = ( ( textWidth > oneLineWidth ) ? textWidth : oneLineWidth );
181 // Add 4.0 to the final textHeight to accomodate the shadow.
184 // Set the content height to the greater of the text and image heights.
185 contentHeight = ( ( imageHeight > textHeight ) ? imageHeight : textHeight );
187 // Setup the Window, and remove all its contentview's subviews.
188 windowWidth = ( SW_PAD + imageWidth + SW_SPACE + textWidth + SW_PAD );
189 windowHeight = ( SW_PAD + contentHeight + SW_PAD );
190 [statusWindow setFrame:NSMakeRect(SW_BORDER, SW_BORDER, windowWidth, windowHeight) display:YES];
191 [[[statusWindow contentView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
193 // Setup, position, fill, and add the image view to the content view.
194 imageRect = NSMakeRect( SW_PAD,
195 (SW_PAD + ((contentHeight - imageHeight) / 2)),
198 imageView = [[[NSImageView alloc] initWithFrame:imageRect] autorelease];
199 [imageView setImage:image];
200 [[statusWindow contentView] addSubview:imageView];
202 // Setup, position, fill, and add the text view to the content view.
203 textRect = NSMakeRect( (SW_PAD + imageWidth + SW_SPACE),
204 (SW_PAD + ((contentHeight - textHeight) / 2)),
207 textField = [[[ITTextField alloc] initWithFrame:textRect] autorelease];
208 [textField setEditable:NO];
209 [textField setSelectable:NO];
210 [textField setBordered:NO];
211 [textField setDrawsBackground:NO];
212 [textField setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:18]];
213 [textField setTextColor:[NSColor whiteColor]];
214 [textField setCastsShadow:YES];
215 [textField setStringValue:text];
216 [[statusWindow contentView] addSubview:textField];
218 [[statusWindow contentView] setNeedsDisplay:YES];
221 - (IBAction)toggleStatusWindow:(id)sender
223 if ( ([statusWindow visibilityState] == ITWindowHiddenState) ||
224 ([statusWindow visibilityState] == ITWindowVanishingState) ) {
225 [[statusWindow contentView] setNeedsDisplay:YES];
226 [statusWindow appear:self];
228 [statusWindow vanish:self];
232 - (IBAction)changeWindowSetting:(id)sender
234 if ( [sender tag] == 3010 ) {
236 if ( [sender indexOfSelectedItem] == 0) {
237 [statusWindow setExitMode:ITTransientStatusWindowExitAfterDelay];
238 } else if ( [sender indexOfSelectedItem] == 1) {
239 [statusWindow setExitMode:ITTransientStatusWindowExitOnCommand];
242 } else if ( [sender tag] == 3020 ) {
244 } else if ( [sender tag] == 3030 ) {
245 [statusWindow setExitDelay:[sender floatValue]];
246 } else if ( [sender tag] == 3040 ) {
247 [statusWindow setVerticalPosition:[sender indexOfSelectedItem]];
248 } else if ( [sender tag] == 3050 ) {
249 [statusWindow setHorizontalPosition:[sender indexOfSelectedItem]];
250 } else if ( [sender tag] == 3060 ) {
251 [[statusWindow entryEffect] setEffectTime:[sender floatValue]];
252 [[statusWindow exitEffect] setEffectTime:[sender floatValue]];
253 } else if ( [sender tag] == 3070 ) {
255 if ( [sender indexOfSelectedItem] == 0 ) {
256 [statusWindow setEntryEffect:[[[ITCutWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
257 } else if ( [sender indexOfSelectedItem] == 1 ) {
258 [statusWindow setEntryEffect:[[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
259 } else if ( [sender indexOfSelectedItem] == 2 ) {
260 [statusWindow setEntryEffect:[[[ITSlideVerticallyWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
261 } else if ( [sender indexOfSelectedItem] == 3 ) {
262 [statusWindow setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
263 } else if ( [sender indexOfSelectedItem] == 4 ) {
264 [statusWindow setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
267 [[statusWindow entryEffect] setEffectTime:[swSpeedSlider floatValue]];
269 } else if ( [sender tag] == 3080 ) {
271 if ( [sender indexOfSelectedItem] == 0 ) {
272 [statusWindow setExitEffect:[[ITCutWindowEffect alloc] initWithWindow:statusWindow]];
273 } else if ( [sender indexOfSelectedItem] == 1 ) {
274 [statusWindow setExitEffect:[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow]];
275 } else if ( [sender indexOfSelectedItem] == 2 ) {
276 [statusWindow setExitEffect:[[ITSlideVerticallyWindowEffect alloc] initWithWindow:statusWindow]];
277 } else if ( [sender indexOfSelectedItem] == 3 ) {
278 [statusWindow setExitEffect:[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:statusWindow]];
279 } else if ( [sender indexOfSelectedItem] == 4 ) {
280 [statusWindow setExitEffect:[[ITPivotWindowEffect alloc] initWithWindow:statusWindow]];
283 [[statusWindow exitEffect] setEffectTime:[swSpeedSlider floatValue]];
289 /*************************************************************************/
291 #pragma mark ITTabView SUPPORT
292 /*************************************************************************/
294 - (IBAction)toggleTabDragging:(id)sender
296 if ([sender state] == NSOnState) {
297 [tabView setAllowsDragging:YES];
299 [tabView setAllowsDragging:NO];
303 - (IBAction)toggleCommandDragging:(id)sender
305 if ([sender state] == NSOnState) {
306 [tabView setRequiredModifiers:NSCommandKeyMask];
308 [tabView setRequiredModifiers:0];
312 - (IBAction)toggleControlDragging:(id)sender
316 - (IBAction)toggleOptionDragging:(id)sender
320 - (IBAction)toggleShiftDragging:(id)sender
325 /*************************************************************************/
327 #pragma mark ITBevelView SUPPORT
328 /*************************************************************************/
330 - (IBAction)changeBevelViewSetting:(id)sender
332 [bevelView setBevelDepth:[sender intValue]];
335 /*************************************************************************/
337 #pragma mark NSWindow DELEGATE METHODS
338 /*************************************************************************/
340 - (void)windowWillMiniaturize:(NSNotification *)note
342 [[note object] setMiniwindowImage:[NSImage imageNamed:@"ITStatusItem"]];