"fixed image scaling" more like "broke aspect ratios" am i rite
[MenuTunes.git] / MTShizzleWindow.m
1 #import "MTShizzleWindow.h"
2 #import "MainController.h"
3
4 @interface MTShizzleWindow (Private)
5 - (void)setBling:(id)bling;
6 - (void)buildWindow;
7 - (void)setTargets;
8 @end
9
10 @implementation MTShizzleWindow
11
12 static MTShizzleWindow *_privateSharedWindow = nil;
13
14 + (id)sharedWindowForSender:(id)sender
15 {
16     if( _privateSharedWindow ) {
17         [_privateSharedWindow setBling:sender];
18         return _privateSharedWindow;
19     } else {
20         _privateSharedWindow = [[MTShizzleWindow alloc]
21                         initWithContentRect:NSMakeRect(0, 0, 385, 353)
22                         styleMask:NSTitledWindowMask
23                         backing:NSBackingStoreBuffered
24                         defer:YES];
25         [_privateSharedWindow setBling:sender];
26         return _privateSharedWindow;
27     }
28 }
29
30 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
31 {
32     if ( (self = [super initWithContentRect:contentRect
33                         styleMask:styleMask
34                         backing:backingType
35                         defer:flag]) ) {
36         [self buildWindow];
37     }
38     return self;
39 }
40
41 - (void)makeKeyAndOrderFront:(id)sender {
42     if ( ( [[NSDate date] timeIntervalSinceDate:[[MainController sharedController] getBlingTime]] >= 604800 ) && ([[regLater title] isEqualToString:@"Register Later"]) ) {
43         [regLater setTitle:@"Quit"];
44         [regLater setTarget:[NSApplication sharedApplication]];
45         [regLater setAction:@selector(terminate:)];
46     }
47     [super makeKeyAndOrderFront:sender];
48 }        
49
50 - (void)dealloc
51 {
52     [regMessage release];
53     [regBenefits release];
54     [enterInfo release];
55     [owner release];
56     [key release];
57     [ownerEntry release];
58     [keyEntry release];
59     [registerButton release];
60     [regLater release];
61     [verifyKey release];
62     [contentView release];
63     [box release];
64     [super dealloc];
65 }
66
67 - (void)setBling:(id)bling
68 {
69     _sender = bling;
70     [self setTargets];
71 }
72
73 - (void)buildWindow
74 {
75     unichar returnChar = '\r';
76     
77     [self setReleasedWhenClosed:NO];
78     [self setTitle:[NSString stringWithFormat:@"Register %@", @"MenuTunes"]];
79     contentView = [self contentView];
80     
81     regMessage = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 282, 345, 51)];
82     [regMessage setStringValue:[NSString stringWithFormat:@"%@ is shareware.  If you find it to be a valuable tool, please click the button below to buy your copy.  Your support is greatly appreciated.", @"MenuTunes"]];
83     [regMessage setBordered:NO];
84     [regMessage setBezeled:NO];
85     [regMessage setEditable:NO];
86     [regMessage setSelectable:NO];
87     [regMessage setDrawsBackground:NO];
88     [contentView addSubview:regMessage];
89     
90     //Make me gray!
91     box = [[NSBox alloc] initWithFrame:NSMakeRect(20, 181, 345, 81)];
92     [box setTitlePosition:NSNoTitle];
93     [box setBorderType:NSBezelBorder];
94     [contentView addSubview:box];
95     
96     //This isn't tall enough
97     registerButton = [[NSButton alloc] initWithFrame:NSMakeRect(24, 13, 115, 49)];
98     [registerButton setImage:[NSImage imageNamed:@"esellerate"]];
99     [registerButton setButtonType:NSMomentaryPushButton];
100     [registerButton setBezelStyle:NSRegularSquareBezelStyle];
101     [registerButton setTarget:_sender];
102     [registerButton setAction:@selector(goToTheStore:)];
103     [[box contentView] addSubview:registerButton];
104     
105     regBenefits = [[NSTextField alloc] initWithFrame:NSMakeRect(152, 16, 175, 42)];
106     [regBenefits setStringValue:[NSString stringWithUTF8String:"• Register instantly and easily.\n• Fast, secure transaction.\n• Major credit cards accepted."]];
107     [regBenefits setBordered:NO];
108     [regBenefits setBezeled:NO];
109     [regBenefits setEditable:NO];
110     [regBenefits setSelectable:NO];
111     [regBenefits setDrawsBackground:NO];
112     [regBenefits setFont:[NSFont fontWithName:@"Lucida Grande" size:11]];
113     [[box contentView] addSubview:regBenefits];
114     
115     enterInfo = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 148, 345, 17)];
116     [enterInfo setStringValue:@"Please enter your registration information below."];
117     [enterInfo setBordered:NO];
118     [enterInfo setBezeled:NO];
119     [enterInfo setEditable:NO];
120     [enterInfo setSelectable:NO];
121     [enterInfo setDrawsBackground:NO];
122     [enterInfo setFont:[NSFont fontWithName:@"Lucida Grande" size:13]];
123     [contentView addSubview:enterInfo];
124     
125     owner = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 126, 345, 14)];
126     [owner setStringValue:@"License Owner:"];
127     [owner setBordered:NO];
128     [owner setBezeled:NO];
129     [owner setEditable:NO];
130     [owner setSelectable:NO];
131     [owner setDrawsBackground:NO];
132     [owner setFont:[NSFont fontWithName:@"Lucida Grande" size:11]];
133     [contentView addSubview:owner];
134     
135     key = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 82, 345, 14)];
136     [key setStringValue:@"License Key:"];
137     [key setBordered:NO];
138     [key setBezeled:NO];
139     [key setEditable:NO];
140     [key setSelectable:NO];
141     [key setDrawsBackground:NO];
142     [key setFont:[NSFont fontWithName:@"Lucida Grande" size:11]];
143     [contentView addSubview:key];
144     
145     ownerEntry = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 104, 345, 22)];
146     [ownerEntry setTarget:_sender];
147     [ownerEntry setAction:@selector(verifyKey:)];
148     [contentView addSubview:ownerEntry];
149     
150     keyEntry = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 60, 345, 22)];
151     [keyEntry setTarget:_sender];
152     [keyEntry setAction:@selector(verifyKey:)];
153     [contentView addSubview:keyEntry];
154     
155     regLater = [[NSButton alloc] initWithFrame:NSMakeRect(138, 16, 116, 25)];
156     [regLater setTitle:@"Register Later"];
157     [regLater setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
158     [regLater setTarget:_sender];
159     [regLater setAction:@selector(registerLater:)];
160     [regLater setBezelStyle:NSRoundedBezelStyle];
161     [contentView addSubview:regLater];
162     
163     verifyKey = [[NSButton alloc] initWithFrame:NSMakeRect(255, 16, 116, 25)];
164     [verifyKey setTitle:@"Verify Key"];
165     [verifyKey setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
166     [verifyKey setTarget:_sender];
167     [verifyKey setAction:@selector(verifyKey:)];
168     [verifyKey setBezelStyle:NSRoundedBezelStyle];
169     [verifyKey setKeyEquivalent:[NSString stringWithCharacters:&returnChar length:1]];
170     [contentView addSubview:verifyKey];
171 }
172
173 - (void)setTargets
174 {
175     [registerButton setTarget:_sender];
176     [ownerEntry setTarget:_sender];
177     [keyEntry setTarget:_sender];
178     [regLater setTarget:_sender];
179     [verifyKey setTarget:_sender];
180 }
181
182 - (NSString *)owner
183 {
184     return [ownerEntry stringValue];
185 }
186
187 - (NSString *)key
188 {
189     return [keyEntry stringValue];
190 }
191
192 @end