|
@@ -8,9 +8,27 @@
|
8
|
8
|
|
9
|
9
|
#import "MainWindow.h"
|
10
|
10
|
|
|
11
|
+#define RESIZE_START 1
|
|
12
|
+#define RESIZE_END 5
|
|
13
|
+#define RESIZE_STEP 1
|
|
14
|
+
|
|
15
|
+#define CONFIG_START_SCALE @"window_scale"
|
|
16
|
+#define CONFIG_KEEP_POSITION @"keep_position"
|
|
17
|
+#define CONFIG_KEEP_ON_TOP @"keep_on_top"
|
|
18
|
+
|
11
|
19
|
@interface MainWindow ()
|
12
|
20
|
|
13
|
21
|
@property (assign) NSSize defaultSize;
|
|
22
|
+@property (assign) NSInteger startScale;
|
|
23
|
+
|
|
24
|
+@property (weak) IBOutlet NSMenuItem *lockPositionItem;
|
|
25
|
+@property (weak) IBOutlet NSMenuItem *keepOnTopItem;
|
|
26
|
+
|
|
27
|
+@property (weak) IBOutlet NSMenuItem *changeSize1;
|
|
28
|
+@property (weak) IBOutlet NSMenuItem *changeSize2;
|
|
29
|
+@property (weak) IBOutlet NSMenuItem *changeSize3;
|
|
30
|
+@property (weak) IBOutlet NSMenuItem *changeSize4;
|
|
31
|
+@property (weak) IBOutlet NSMenuItem *changeSize5;
|
14
|
32
|
|
15
|
33
|
@end
|
16
|
34
|
|
|
@@ -18,7 +36,11 @@
|
18
|
36
|
|
19
|
37
|
@synthesize dragStart;
|
20
|
38
|
@synthesize keepPosition;
|
|
39
|
+
|
21
|
40
|
@synthesize defaultSize;
|
|
41
|
+@synthesize startScale;
|
|
42
|
+
|
|
43
|
+// TODO window position should be remembered!
|
22
|
44
|
|
23
|
45
|
- (id)initWithContentRect:(NSRect)contentRect
|
24
|
46
|
styleMask:(NSUInteger)aStyle
|
|
@@ -29,13 +51,28 @@
|
29
|
51
|
[self setAlphaValue:1.0];
|
30
|
52
|
[self setOpaque:NO];
|
31
|
53
|
|
|
54
|
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
55
|
+
|
32
|
56
|
// load and see if window should be kept on top
|
33
|
|
- // also set proper button state
|
34
|
|
- //[self setLevel:NSFloatingWindowLevel];
|
|
57
|
+ if ([defaults objectForKey:CONFIG_KEEP_ON_TOP] != nil) {
|
|
58
|
+ if ([defaults boolForKey:CONFIG_KEEP_ON_TOP]) {
|
|
59
|
+ [self setLevel:NSFloatingWindowLevel];
|
|
60
|
+ }
|
|
61
|
+ }
|
35
|
62
|
|
36
|
63
|
// load and see if window pos should be fixed
|
37
|
|
- // also set proper button state
|
38
|
|
- self.keepPosition = NO;
|
|
64
|
+ if ([defaults objectForKey:CONFIG_KEEP_POSITION] == nil) {
|
|
65
|
+ keepPosition = NO;
|
|
66
|
+ } else {
|
|
67
|
+ keepPosition = [defaults boolForKey:CONFIG_KEEP_POSITION];
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ // load window scale factor
|
|
71
|
+ if ([defaults objectForKey:CONFIG_START_SCALE] == nil) {
|
|
72
|
+ startScale = 1;
|
|
73
|
+ } else {
|
|
74
|
+ startScale = [defaults integerForKey:CONFIG_START_SCALE];
|
|
75
|
+ }
|
39
|
76
|
}
|
40
|
77
|
return self;
|
41
|
78
|
}
|
|
@@ -44,25 +81,53 @@
|
44
|
81
|
defaultSize = size;
|
45
|
82
|
NSRect frame = [self frame];
|
46
|
83
|
frame.size = defaultSize;
|
|
84
|
+
|
|
85
|
+ frame.size.width *= startScale;
|
|
86
|
+ frame.size.height *= startScale;
|
|
87
|
+
|
|
88
|
+ // We need to do all initialization of view state in here, because they are not ready in init
|
|
89
|
+ if (keepPosition) [self.lockPositionItem setState:NSOnState];
|
|
90
|
+ if ([self level] == NSFloatingWindowLevel) [self.keepOnTopItem setState:NSOnState];
|
|
91
|
+ if (startScale == 1) [self.changeSize1 setState:NSOnState];
|
|
92
|
+ if (startScale == 2) [self.changeSize2 setState:NSOnState];
|
|
93
|
+ if (startScale == 3) [self.changeSize3 setState:NSOnState];
|
|
94
|
+ if (startScale == 4) [self.changeSize4 setState:NSOnState];
|
|
95
|
+ if (startScale == 5) [self.changeSize5 setState:NSOnState];
|
|
96
|
+
|
47
|
97
|
[self setFrame:frame display:YES];
|
48
|
98
|
}
|
49
|
99
|
|
50
|
100
|
- (IBAction)changeSize:(NSMenuItem *)sender {
|
51
|
101
|
NSRect frame = [self frame];
|
52
|
102
|
|
53
|
|
- if ([[sender title] isEqualToString:@"1x"]) {
|
54
|
|
- frame.size = defaultSize;
|
55
|
|
- } else if ([[sender title] isEqualToString:@"2x"]) {
|
56
|
|
- NSSize newSize = defaultSize;
|
57
|
|
- newSize.height *= 2;
|
58
|
|
- newSize.width *= 2;
|
59
|
|
- frame.size = newSize;
|
60
|
|
- } else {
|
61
|
|
- NSLog(@"Unknown changeSize sender: %@", sender);
|
62
|
|
- return;
|
|
103
|
+ [self.changeSize1 setState:NSOffState];
|
|
104
|
+ [self.changeSize2 setState:NSOffState];
|
|
105
|
+ [self.changeSize3 setState:NSOffState];
|
|
106
|
+ [self.changeSize4 setState:NSOffState];
|
|
107
|
+ [self.changeSize5 setState:NSOffState];
|
|
108
|
+
|
|
109
|
+ BOOL found = NO;
|
|
110
|
+ for (int i = RESIZE_START; i <= RESIZE_END; i += RESIZE_STEP) {
|
|
111
|
+ NSString *title = [NSString stringWithFormat:@"%dx", i];
|
|
112
|
+ if ([[sender title] isEqualToString:title]) {
|
|
113
|
+ [sender setState:NSOnState];
|
|
114
|
+ NSSize newSize = defaultSize;
|
|
115
|
+ newSize.height *= i;
|
|
116
|
+ newSize.width *= i;
|
|
117
|
+ frame.size = newSize;
|
|
118
|
+ found = YES;
|
|
119
|
+
|
|
120
|
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
121
|
+ [defaults setInteger:i forKey:CONFIG_START_SCALE];
|
|
122
|
+ [defaults synchronize];
|
|
123
|
+ }
|
63
|
124
|
}
|
64
|
125
|
|
65
|
|
- [self setFrame:frame display:YES];
|
|
126
|
+ if (found == NO) {
|
|
127
|
+ NSLog(@"Unknown changeSize sender: %@", sender);
|
|
128
|
+ } else {
|
|
129
|
+ [self setFrame:frame display:YES];
|
|
130
|
+ }
|
66
|
131
|
}
|
67
|
132
|
|
68
|
133
|
- (IBAction)lockPosition:(NSMenuItem *)sender {
|
|
@@ -72,13 +137,19 @@
|
72
|
137
|
state = NSOnState;
|
73
|
138
|
[sender setState:state];
|
74
|
139
|
self.keepPosition = YES;
|
75
|
|
- // store...
|
|
140
|
+
|
|
141
|
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
142
|
+ [defaults setBool:YES forKey:CONFIG_KEEP_POSITION];
|
|
143
|
+ [defaults synchronize];
|
76
|
144
|
} else {
|
77
|
145
|
// Unlock position
|
78
|
146
|
state = NSOffState;
|
79
|
147
|
[sender setState:state];
|
80
|
148
|
self.keepPosition = NO;
|
81
|
|
- // store...
|
|
149
|
+
|
|
150
|
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
151
|
+ [defaults setBool:NO forKey:CONFIG_KEEP_POSITION];
|
|
152
|
+ [defaults synchronize];
|
82
|
153
|
}
|
83
|
154
|
}
|
84
|
155
|
|
|
@@ -89,13 +160,19 @@
|
89
|
160
|
state = NSOnState;
|
90
|
161
|
[sender setState:state];
|
91
|
162
|
[self setLevel:NSFloatingWindowLevel];
|
92
|
|
- // store...
|
|
163
|
+
|
|
164
|
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
165
|
+ [defaults setBool:YES forKey:CONFIG_KEEP_ON_TOP];
|
|
166
|
+ [defaults synchronize];
|
93
|
167
|
} else {
|
94
|
168
|
// Don't keep window on top
|
95
|
169
|
state = NSOffState;
|
96
|
170
|
[sender setState:state];
|
97
|
171
|
[self setLevel:NSNormalWindowLevel];
|
98
|
|
- // store...
|
|
172
|
+
|
|
173
|
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
174
|
+ [defaults setBool:NO forKey:CONFIG_KEEP_ON_TOP];
|
|
175
|
+ [defaults synchronize];
|
99
|
176
|
}
|
100
|
177
|
}
|
101
|
178
|
|
|
@@ -105,8 +182,6 @@
|
105
|
182
|
|
106
|
183
|
- (void)mouseDown:(NSEvent *)theEvent {
|
107
|
184
|
self.dragStart = [theEvent locationInWindow];
|
108
|
|
-
|
109
|
|
- NSLog(@"Mouse at %f %f", self.dragStart.x, self.dragStart.y);
|
110
|
185
|
}
|
111
|
186
|
|
112
|
187
|
- (void)mouseDragged:(NSEvent *)theEvent {
|