forked from scrod/nv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BorderlessWindowControler.m
332 lines (238 loc) · 5.93 KB
/
BorderlessWindowControler.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
//
// BorderlessWindowControler.m
// WindowOpener
//
// Created by Agl on 12.02.10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "BorderlessWindowControler.h"
@implementation BorderlessWindowControler
/**
* sets the title of the window
*/
- (void) setWindowTitle:(NSString *)theTitle {
[titleField setStringValue:theTitle];
[self refreshWindow];
}
/**
*
*/
- (void) windowDidBecomeKey:(NSNotification *) notification {
if (notification.object == daWindow) {
[self myWindowGainedFocus]; //set full alpha value...
if (!hasFocus) {
[daWindow display]; //...and repaint if necessary
}
hasFocus = YES;
}
else {
if (hasFocus) {
[self myWindowLostFocus]; //set lower alpha value...
}
if (hasFocus) {
[daWindow display]; //...and repaint if necessary
}
hasFocus = NO;
}
}
- (void) myWindowLostFocus {
[minimizeButton setAlphaValue:0.5];
[closeButton setAlphaValue:0.5];
[titleField setAlphaValue:0.5];
}
- (void) myWindowGainedFocus {
[minimizeButton setAlphaValue:1];
[closeButton setAlphaValue:1];
[titleField setAlphaValue:1];
[daWindow doMouseDownWork:[daWindow convertScreenToBase:[NSEvent mouseLocation]]];
}
/**
* relays a double klick in the dragging region to the minimize button
*/
- (void) doubleClickInDragRegion {
[minimizeButton performClick:minimizeButton];
}
/**
* relays a minimize invokation the the window
*/
- (IBAction)minimizeToggle: (id) sender {
[daWindow minimizeToggle];
[self refreshWindow];
}
- (void) resetColors {
yellow = NO;
green = NO;
grey = NO;
blue = NO;
violet = NO;
pink = NO;
}
- (void) setYellow {
//[textView setBackgroundColor:[NSColor colorWithCalibratedRed:0.996 green:0.957 blue:0.612 alpha:1]];
[textView setBackgrColor:0.996 greenC:0.957 blueC:0.612];
[view setLowerColor:0.996 greenC:0.957 blueC:0.612];
[view setUpperColor:0.966 greenC:0.918 blueC:0.239];
[self resetColors];
yellow = YES;
[self refreshWindow];
}
- (void) setBlue {
[textView setBackgrColor:0.678 greenC:0.957 blueC:1];
[view setLowerColor:0.678 greenC:0.957 blueC:1];
[view setUpperColor:0.537 greenC:0.957 blueC:1];
[self resetColors];
blue = YES;
[self refreshWindow];
}
- (void) setGreen {
[textView setBackgrColor:0.698 greenC:1 blueC:0.63];
[view setLowerColor:0.698 greenC:1 blueC:0.63];
[view setUpperColor:0.514 greenC:0.996 blueC:0.514];
[self resetColors];
green = YES;
[self refreshWindow];
}
- (void) setPink {
[textView setBackgrColor:1 greenC:0.78 blueC:0.78];
[view setLowerColor:1 greenC:0.78 blueC:0.78];
[view setUpperColor:1 greenC:0.698 blueC:0.698];
[self resetColors];
pink = YES;
[self refreshWindow];
}
- (void) setViolet {
[textView setBackgrColor:0.714 greenC:0.792 blueC:1];
[view setLowerColor:0.714 greenC:0.792 blueC:1];
[view setUpperColor:0.608 greenC:0.714 blueC:0.996];
[self resetColors];
violet = YES;
[self refreshWindow];
}
- (void) setGrey {
[textView setBackgrColor:0.933 greenC:0.933 blueC:0.933];
[view setLowerColor:0.933 greenC:0.933 blueC:0.933];
[view setUpperColor:0.855 greenC:0.855 blueC:0.855];
[self resetColors];
grey = YES;
[self refreshWindow];
}
- (void) setOpaque:(BOOL)setOpaque {
if (setOpaque) {
[daWindow setAlphaValue:0.73];
}
else {
[daWindow setAlphaValue:1];
}
opaque = setOpaque;
}
- (void) setFloating:(BOOL)setFloating {
if (setFloating) {
[daWindow setLevel:NSFloatingWindowLevel];
}
else {
[daWindow setLevel:NSNormalWindowLevel];
}
onTop = setFloating;
}
- (void) initWindow {
[daWindow init:self];
}
- (void) initWindowWithCentral: (AutoMoveCentral *)central {
[self initWindow];
[daWindow initWithCentral:central];
}
- (void) intiWindowWithCentralAndSetWindowToInitPos: (AutoMoveCentral *)central {
[self initWindowWithCentral:central];
[central setInitialPosition:daWindow];
}
- (id) init {
visible = NO;
opaque = NO;
onTop = NO;
if (! ( green || grey || blue || pink || violet ) ) {
[self setYellow];
}
[self initWindow];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:nil];
return self;
}
- (void) showWindow:(id)sender {
/*[daWindow minimize];
[daWindow makeKeyAndOrderFront:self];
[daWindow unminimize];*/
NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity:2];
//NSRect end = [daWindow frame];
//NSPoint start = NSMakePoint(-400, -400);
//[daWindow setFrameNoCall:start display:NO animate:NO];
//[daWindow setFrameOrigin:start];
[dict setObject:daWindow forKey:NSViewAnimationTargetKey];
[dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
//[dict setObject: [NSValue valueWithRect:end] forKey:NSViewAnimationEndFrameKey];
NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict,nil]];
[anim setDuration: 0.8];
//[daWindow setOpaque:NO];
[daWindow setAlphaValue:0];
[daWindow makeKeyAndOrderFront:self];
[anim startAnimation];
visible = YES;
}
- (IBAction)closeWindow: (id) sender {
[self closeWindowAndFreeAll];
}
- (void) closeWindowAndFreeAll {
[daWindow minimize];
[daWindow close];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[daWindow release];
visible = NO;
}
/*- (BOOL) isVisible {
return visible;
}*/
- (BOOL) isFloating {
return onTop;
}
- (BOOL) isOpaque {
return opaque;
}
- (BOOL) isGrey {
return grey;
}
- (BOOL) isViolet {
return violet;
}
- (BOOL) isPink {
return pink;
}
- (BOOL) isGreen {
return green;
}
- (BOOL) isBlue {
return blue;
}
- (BOOL) isYellow {
return yellow;
}
- (void) refreshWindow {
if (visible) {
[daWindow display];
}
}
- (void) setVisible:(BOOL) vis {
if (vis) {
[daWindow makeKeyAndOrderFront:self];
}
else {
[daWindow orderOut:self];
}
visible = vis;
}
- (void) textContentDidChange {
}
- (BOOL) isMinimized {
return [daWindow isMimimized];
}
- (BorderlessWindow *) window {
return daWindow;
}
@end