Added sizing to the main status window class, and added a basic icon and
[ITKit.git] / Showcase / Controller.m
1 #import "Controller.h"
2 //#import "ITTransientStatusWindow.h"
3 #import "ITIconAndTextStatusWindow.h"
4 #import "ITTSWBackgroundView.h"
5 #import "ITTextField.h"
6 #import "ITBevelView.h"
7 #import "ITCutWindowEffect.h"
8 #import "ITDissolveWindowEffect.h"
9 #import "ITSlideHorizontallyWindowEffect.h"
10 #import "ITSlideVerticallyWindowEffect.h"
11 #import "ITPivotWindowEffect.h"
12
13
14 #define SW_PAD    24.0
15 #define SW_SPACE  24.0
16 #define SW_MINW   211.0
17 #define SW_BORDER 32.0
18 #define SW_IMAGE  @"Library"
19
20
21 @interface Controller (ITStatusItemSupport)
22 - (void)createStatusItem;
23 - (void)removeStatusItem;
24 @end
25
26
27 @implementation Controller
28
29 - (void)awakeFromNib
30 {
31     [self createStatusItem];
32     [button setBezelStyle:1001];
33     [button setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:14]];
34     [button setTitle:@"Launch Manually"];
35     [button sizeToFit];
36     [button setFrameSize:NSMakeSize([button frame].size.width + 8, 24)];
37     [testTextField setCastsShadow:YES];
38     [tabView setAllowsDragging:YES];
39     [bevelView setBevelDepth:10];
40     statusWindow = [ITIconAndTextStatusWindow sharedWindow];
41     [statusWindow setEntryEffect:[[ITCutWindowEffect alloc] initWithWindow:statusWindow]];
42     [statusWindow setExitEffect:[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow]];
43     [[statusWindow entryEffect] setEffectTime:[swEntrySpeedSlider floatValue]];
44     [[statusWindow exitEffect]  setEffectTime:[swExitSpeedSlider floatValue]];
45 //  [tabView setAllowsDragging:YES];
46     [[NSColorPanel sharedColorPanel] setShowsAlpha:YES];
47 }
48
49 /*************************************************************************/
50 #pragma mark -
51 #pragma mark ITStatusItem SUPPORT
52 /*************************************************************************/
53
54 - (void)createStatusItem
55 {
56     statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar]
57                                               withLength:NSVariableStatusItemLength];
58
59     if ( [showImageCheckBox state] == NSOnState ) {
60         [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
61     }
62
63     if ( [useInvertedCheckBox state] == NSOnState ) {
64         [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
65     }
66
67     if ( [showTitleCheckBox state] == NSOnState ) {
68         [statusItem setTitle:@"ITStatusItem"];
69     }
70
71     [statusItem setMenu:statusItemMenu];
72
73     [statusItemMenu addItemWithTitle:[NSString stringWithUTF8String:"★★★★★"]
74                               action:nil
75                        keyEquivalent:@""];
76 }
77
78 - (void)removeStatusItem
79 {
80     [[statusItem statusBar] removeStatusItem:statusItem];
81     [statusItem autorelease];
82     statusItem = nil;
83 }
84
85 - (IBAction)toggleStatusItem:(id)sender
86 {
87     if ( [sender state] == NSOnState ) {
88         [self createStatusItem];
89         [showImageCheckBox   setEnabled:YES];
90         [showTitleCheckBox   setEnabled:YES];
91         [useInvertedCheckBox setEnabled:YES];
92     } else {
93         [self removeStatusItem];
94         [showImageCheckBox   setEnabled:NO];
95         [useInvertedCheckBox setEnabled:NO];
96         [showTitleCheckBox   setEnabled:NO];
97     }
98 }
99
100 - (IBAction)toggleImage:(id)sender
101 {
102     if ( [sender state] == NSOnState ) {
103         [statusItem setImage:[NSImage imageNamed:@"ITStatusItem"]];
104         [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
105         [useInvertedCheckBox setEnabled:YES];
106         [useInvertedCheckBox setState:NSOnState];
107     } else {
108         [statusItem setImage:nil];
109         [statusItem setAlternateImage:nil];
110         [useInvertedCheckBox setEnabled:NO];
111         [useInvertedCheckBox setState:NSOffState];
112     }
113 }
114
115 - (IBAction)toggleInvertedImage:(id)sender
116 {
117     if ( [sender state] == NSOnState ) {
118         [statusItem setAlternateImage:[NSImage imageNamed:@"ITStatusItemInv"]];
119     } else {
120         [statusItem setAlternateImage:nil];
121     }
122 }
123
124 - (IBAction)toggleTitle:(id)sender
125 {
126     if ( [sender state] == NSOnState ) {
127         [statusItem setTitle:@"ITStatusItem"];
128     } else {
129         [statusItem setTitle:nil];
130     }
131 }
132
133
134 /*************************************************************************/
135 #pragma mark -
136 #pragma mark ITTextView SUPPORT
137 /*************************************************************************/
138
139 - (IBAction)toggleCastsShadow:(id)sender
140 {
141     [testTextField setCastsShadow:([sender state] == NSOnState)];
142 }
143
144
145 /*************************************************************************/
146 #pragma mark -
147 #pragma mark ITTransientStatusWindow SUPPORT
148 /*************************************************************************/
149
150 - (IBAction)buildStatusWindow:(id)sender
151 {
152     NSImage     *image        = [NSImage imageNamed:SW_IMAGE];
153     NSString    *text     = [swSampleTextView string];
154     [statusWindow setImage:image];
155     [statusWindow buildTextWindowWithString:text];
156 }
157
158 - (IBAction)toggleStatusWindow:(id)sender
159 {
160     if ( ([statusWindow visibilityState] == ITWindowHiddenState) ||
161          ([statusWindow visibilityState] == ITWindowVanishingState) ) {
162         [[statusWindow contentView] setNeedsDisplay:YES];
163         [statusWindow appear:self];
164     } else {
165         [statusWindow vanish:self];
166     }
167 }
168
169 - (IBAction)changeWindowSetting:(id)sender
170 {
171     if ( [sender tag] == 3010 ) {
172
173         if ( [sender indexOfSelectedItem] == 0) {
174             [statusWindow setExitMode:ITTransientStatusWindowExitAfterDelay];
175         } else if ( [sender indexOfSelectedItem] == 1) {
176             [statusWindow setExitMode:ITTransientStatusWindowExitOnCommand];
177         }
178
179     } else if ( [sender tag] == 3020 ) {
180         // Not yet supported
181     } else if ( [sender tag] == 3030 ) {
182         [statusWindow setExitDelay:[sender floatValue]];
183     } else if ( [sender tag] == 3040 ) {
184         [statusWindow setVerticalPosition:[sender indexOfSelectedItem]];
185     } else if ( [sender tag] == 3050 ) {
186         [statusWindow setHorizontalPosition:[sender indexOfSelectedItem]];
187     } else if ( [sender tag] == 3060 ) {
188         [[statusWindow entryEffect] setEffectTime:[sender floatValue]];
189     } else if ( [sender tag] == 3061 ) {
190         [[statusWindow exitEffect]  setEffectTime:[sender floatValue]];
191     } else if ( [sender tag] == 3070 ) {
192     
193         if ( [sender indexOfSelectedItem] == 0 ) {
194             [statusWindow setEntryEffect:[[[ITCutWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
195         } else if ( [sender indexOfSelectedItem] == 1 ) {
196             [statusWindow setEntryEffect:[[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
197         } else if ( [sender indexOfSelectedItem] == 2 ) {
198             [statusWindow setEntryEffect:[[[ITSlideVerticallyWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
199         } else if ( [sender indexOfSelectedItem] == 3 ) {
200             [statusWindow setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
201         } else if ( [sender indexOfSelectedItem] == 4 ) {
202             [statusWindow setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:statusWindow] autorelease]];
203         }
204
205         [[statusWindow entryEffect] setEffectTime:[swEntrySpeedSlider floatValue]];
206         
207     } else if ( [sender tag] == 3080 ) {
208
209         if ( [sender indexOfSelectedItem] == 0 ) {
210             [statusWindow setExitEffect:[[ITCutWindowEffect alloc] initWithWindow:statusWindow]];
211         } else if ( [sender indexOfSelectedItem] == 1 ) {
212             [statusWindow setExitEffect:[[ITDissolveWindowEffect alloc] initWithWindow:statusWindow]];
213         } else if ( [sender indexOfSelectedItem] == 2 ) {
214             [statusWindow setExitEffect:[[ITSlideVerticallyWindowEffect alloc] initWithWindow:statusWindow]];
215         } else if ( [sender indexOfSelectedItem] == 3 ) {
216             [statusWindow setExitEffect:[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:statusWindow]];
217         } else if ( [sender indexOfSelectedItem] == 4 ) {
218             [statusWindow setExitEffect:[[ITPivotWindowEffect alloc] initWithWindow:statusWindow]];
219         }
220
221         [[statusWindow exitEffect] setEffectTime:[swExitSpeedSlider floatValue]];
222
223     } else if ( [sender tag] == 3090 ) {
224     
225         if ( [sender indexOfSelectedItem] == 0 ) {
226             [(ITTSWBackgroundView *)[statusWindow contentView] setBackgroundMode:ITTSWBackgroundApple];
227         } else if ( [sender indexOfSelectedItem] == 1 ) {
228             [(ITTSWBackgroundView *)[statusWindow contentView] setBackgroundMode:ITTSWBackgroundReadable];
229         } else if ( [sender indexOfSelectedItem] == 2 ) {
230             [(ITTSWBackgroundView *)[statusWindow contentView] setBackgroundMode:ITTSWBackgroundColored];
231         }
232         
233     } else if ( [sender tag] == 3100 ) {
234         [(ITTSWBackgroundView *)[statusWindow contentView] setBackgroundColor:[sender color]];
235     }
236 }
237
238
239 /*************************************************************************/
240 #pragma mark -
241 #pragma mark ITTabView SUPPORT
242 /*************************************************************************/
243
244 - (IBAction)toggleTabDragging:(id)sender
245 {
246     if ([sender state] == NSOnState) {
247         [tabView setAllowsDragging:YES];
248     } else {
249         [tabView setAllowsDragging:NO];
250     }
251 }
252
253 - (IBAction)toggleCommandDragging:(id)sender
254 {
255     if ([sender state] == NSOnState) {
256         [tabView setRequiredModifiers:NSCommandKeyMask];
257     } else {
258         [tabView setRequiredModifiers:0];
259     }
260 }
261
262 - (IBAction)toggleControlDragging:(id)sender
263 {
264 }
265
266 - (IBAction)toggleOptionDragging:(id)sender
267 {
268 }
269
270 - (IBAction)toggleShiftDragging:(id)sender
271 {
272 }
273
274
275 /*************************************************************************/
276 #pragma mark -
277 #pragma mark ITBevelView SUPPORT
278 /*************************************************************************/
279
280 - (IBAction)changeBevelViewSetting:(id)sender
281 {
282     [bevelView setBevelDepth:[sender intValue]];
283 }
284
285
286 /*************************************************************************/
287 #pragma mark -
288 #pragma mark ITButton SUPPORT
289 /*************************************************************************/
290
291
292 /*************************************************************************/
293 #pragma mark -
294 #pragma mark NSWindow DELEGATE METHODS
295 /*************************************************************************/
296
297 - (void)windowWillMiniaturize:(NSNotification *)note
298 {
299     [[note object] setMiniwindowImage:[NSImage imageNamed:@"ITStatusItem"]];
300 }
301
302
303 @end