1 |
/* main.m |
2 |
|
3 |
Copyright (C) 1999 Free Software Foundation, Inc. |
4 |
|
5 |
Author: Richard frith-Macdonald (richard@brainstorm.co.uk> |
6 |
Date: 1999 |
7 |
|
8 |
This file is part of GNUstep. |
9 |
|
10 |
This program is free software; you can redistribute it and/or modify |
11 |
it under the terms of the GNU General Public License as published by |
12 |
the Free Software Foundation; either version 2 of the License, or |
13 |
(at your option) any later version. |
14 |
|
15 |
This program is distributed in the hope that it will be useful, |
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
GNU General Public License for more details. |
19 |
|
20 |
You should have received a copy of the GNU General Public License |
21 |
along with this program; if not, write to the Free Software |
22 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 |
*/ |
24 |
#include <Foundation/Foundation.h> |
25 |
#include <AppKit/AppKit.h> |
26 |
#include "GormPrivate.h" |
27 |
#include "GormNSWindow.h" |
28 |
#include "GormNSPanel.h" |
29 |
|
30 |
@interface GormWindowMaker : NSObject <NSCoding> |
31 |
{ |
32 |
} |
33 |
@end |
34 |
|
35 |
@implementation GormWindowMaker |
36 |
- (void) encodeWithCoder: (NSCoder*)aCoder |
37 |
{ |
38 |
} |
39 |
|
40 |
- (id) initWithCoder: (NSCoder*)aCoder |
41 |
{ |
42 |
id w; |
43 |
unsigned style = NSTitledWindowMask | NSClosableWindowMask |
44 |
| NSResizableWindowMask | NSMiniaturizableWindowMask; |
45 |
NSRect screenRect = [[NSScreen mainScreen] frame]; |
46 |
float |
47 |
x = (screenRect.size.width - 500)/2, |
48 |
y = (screenRect.size.height - 300)/2; |
49 |
NSRect windowRect = NSMakeRect(x,y,500,300); |
50 |
|
51 |
// NSLog(@"Making window %@ on screen: %@",NSStringFromRect(windowRect),NSStringFromRect(screenRect)); |
52 |
w = [[GormNSWindow alloc] initWithContentRect: windowRect |
53 |
styleMask: style |
54 |
backing: NSBackingStoreRetained |
55 |
defer: NO]; |
56 |
[w setFrame: windowRect display: YES]; |
57 |
[w setTitle: @"Window"]; |
58 |
[w orderFront: self]; |
59 |
RELEASE(self); |
60 |
return w; |
61 |
} |
62 |
@end |
63 |
|
64 |
@interface GormPanelMaker : NSObject <NSCoding> |
65 |
{ |
66 |
} |
67 |
@end |
68 |
|
69 |
@implementation GormPanelMaker |
70 |
- (void) encodeWithCoder: (NSCoder*)aCoder |
71 |
{ |
72 |
} |
73 |
|
74 |
- (id) initWithCoder: (NSCoder*)aCoder |
75 |
{ |
76 |
id w; |
77 |
unsigned style = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; |
78 |
NSRect screenRect = [[NSScreen mainScreen] frame]; |
79 |
float |
80 |
x = (screenRect.size.width - 500)/2, |
81 |
y = (screenRect.size.height - 300)/2; |
82 |
NSRect windowRect = NSMakeRect(x,y,500,300); |
83 |
|
84 |
w = [[GormNSPanel alloc] initWithContentRect: windowRect |
85 |
styleMask: style |
86 |
backing: NSBackingStoreRetained |
87 |
defer: NO]; |
88 |
[w setFrame: windowRect display: YES]; |
89 |
[w setTitle: @"Panel"]; |
90 |
[w orderFront: self]; |
91 |
RELEASE(self); |
92 |
return w; |
93 |
} |
94 |
@end |
95 |
|
96 |
@interface WindowsPalette: IBPalette |
97 |
{ |
98 |
} |
99 |
@end |
100 |
|
101 |
@implementation WindowsPalette |
102 |
- (void) finishInstantiate |
103 |
{ |
104 |
NSView *contents; |
105 |
id w; |
106 |
id v; |
107 |
NSBundle *bundle = [NSBundle bundleForClass: [self class]]; |
108 |
NSString *path = [bundle pathForImageResource: @"WindowDrag"]; |
109 |
NSImage *dragImage = [[NSImage alloc] initWithContentsOfFile: path]; |
110 |
|
111 |
RELEASE(window); |
112 |
window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, 272, 192) |
113 |
styleMask: NSBorderlessWindowMask |
114 |
backing: NSBackingStoreRetained |
115 |
defer: NO]; |
116 |
contents = [window contentView]; |
117 |
|
118 |
w = [GormWindowMaker new]; |
119 |
v = [[NSButton alloc] initWithFrame: NSMakeRect(35, 60, 80, 64)]; |
120 |
[v setBordered: NO]; |
121 |
[v setImage: dragImage]; |
122 |
[v setImagePosition: NSImageOverlaps]; |
123 |
[v setTitle: @"Window"]; |
124 |
[contents addSubview: v]; |
125 |
[self associateObject: w |
126 |
type: IBWindowPboardType |
127 |
with: v]; |
128 |
RELEASE(v); |
129 |
RELEASE(w); |
130 |
|
131 |
w = [GormPanelMaker new]; |
132 |
v = [[NSButton alloc] initWithFrame: NSMakeRect(155, 60, 80, 64)]; |
133 |
[v setBordered: NO]; |
134 |
[v setImage: dragImage]; |
135 |
[v setImagePosition: NSImageOverlaps]; |
136 |
[v setTitle: @"Panel"]; |
137 |
[contents addSubview: v]; |
138 |
[self associateObject: w |
139 |
type: IBWindowPboardType |
140 |
with: v]; |
141 |
RELEASE(v); |
142 |
RELEASE(w); |
143 |
|
144 |
RELEASE(dragImage); |
145 |
} |
146 |
@end |
147 |
|
148 |
/* --------------------------------------------------------- |
149 |
NSwindow inspector |
150 |
---------------------------------------------------------*/ |
151 |
@implementation NSWindow (GormPrivate) |
152 |
+ (id) allocSubstitute |
153 |
{ |
154 |
return [GormNSWindow alloc]; |
155 |
} |
156 |
@end |
157 |
|
158 |
// the normal classes... |
159 |
@implementation NSWindow (IBInspectorClassNames) |
160 |
- (NSString*) inspectorClassName |
161 |
{ |
162 |
return @"GormWindowAttributesInspector"; |
163 |
} |
164 |
- (NSString*) sizeInspectorClassName |
165 |
{ |
166 |
return @"GormWindowSizeInspector"; |
167 |
} |
168 |
@end |
169 |
|
170 |
@implementation NSPanel (IBInspectorClassNames) |
171 |
- (NSString*) inspectorClassName |
172 |
{ |
173 |
return @"GormWindowAttributesInspector"; |
174 |
} |
175 |
- (NSString*) sizeInspectorClassName |
176 |
{ |
177 |
return @"GormWindowSizeInspector"; |
178 |
} |
179 |
@end |
180 |
|
181 |
// special subclasses... |
182 |
@implementation GormNSWindow (IBInspectorClassNames) |
183 |
- (NSString*) inspectorClassName |
184 |
{ |
185 |
return @"GormWindowAttributesInspector"; |
186 |
} |
187 |
- (NSString*) sizeInspectorClassName |
188 |
{ |
189 |
return @"GormWindowSizeInspector"; |
190 |
} |
191 |
@end |
192 |
|
193 |
@implementation GormNSPanel (IBInspectorClassNames) |
194 |
- (NSString*) inspectorClassName |
195 |
{ |
196 |
return @"GormWindowAttributesInspector"; |
197 |
} |
198 |
- (NSString*) sizeInspectorClassName |
199 |
{ |
200 |
return @"GormWindowSizeInspector"; |
201 |
} |
202 |
@end |
203 |
|
204 |
|
205 |
|
206 |
|
207 |
@interface GormWindowAttributesInspector : IBInspector |
208 |
{ |
209 |
id titleForm; |
210 |
id backingMatrix; |
211 |
id optionMatrix; |
212 |
id controlMatrix; |
213 |
} |
214 |
@end |
215 |
|
216 |
@implementation GormWindowAttributesInspector |
217 |
|
218 |
- (void) _setValuesFromControl: control |
219 |
{ |
220 |
|
221 |
if (control == titleForm) |
222 |
{ |
223 |
[object setTitle: [[control cellAtIndex: 0] stringValue] ]; |
224 |
} |
225 |
else if (control == backingMatrix) |
226 |
{ |
227 |
[object setBackingType: [[control selectedCell] tag] ]; |
228 |
} |
229 |
else if (control == controlMatrix) |
230 |
{ |
231 |
unsigned int newStyleMask; |
232 |
int rows,cols,i; |
233 |
|
234 |
[control getNumberOfRows:&rows columns:&cols]; |
235 |
|
236 |
newStyleMask = [object styleMask]; |
237 |
for (i=0;i<rows;i++) { |
238 |
if ([[control cellAtRow: i column: 0] state] == NSOnState) |
239 |
newStyleMask |= [[control cellAtRow: i column: 0] tag]; |
240 |
else |
241 |
newStyleMask &= ~[[control cellAtRow: i column: 0] tag]; |
242 |
} |
243 |
|
244 |
[object setStyleMask: newStyleMask]; |
245 |
// FIXME: This doesn't refresh the window decoration. How to do that? |
246 |
// (currently needs manual hide/unhide to update decorations) |
247 |
[object display]; |
248 |
} |
249 |
else if (control == optionMatrix) |
250 |
{ |
251 |
BOOL flag; |
252 |
|
253 |
// Release When Closed |
254 |
flag = ([[control cellAtRow: 0 column: 0] state] == NSOnState) ? YES : NO; |
255 |
[object setReleasedWhenClosed: flag]; |
256 |
|
257 |
// Hide on deactivate |
258 |
flag = ([[control cellAtRow: 1 column: 0] state] == NSOnState) ? YES : NO; |
259 |
[object setHidesOnDeactivate: flag]; |
260 |
|
261 |
// Visible at launch time. (not an object property. Stored in a Gorm dictionnary) |
262 |
flag = ([[control cellAtRow: 2 column: 0] state] == NSOnState) ? YES : NO; |
263 |
{ |
264 |
GormDocument *doc = (GormDocument*)[(id<IB>)NSApp activeDocument]; |
265 |
[doc setObject: object isVisibleAtLaunch: flag]; |
266 |
} |
267 |
|
268 |
// Deferred |
269 |
flag = ([[control cellAtRow: 3 column: 0] state] == NSOnState) ? YES : NO; |
270 |
{ |
271 |
GormDocument *doc = (GormDocument*)[(id<IB>)NSApp activeDocument]; |
272 |
[doc setObject: object isDeferred: flag]; |
273 |
} |
274 |
|
275 |
// One shot |
276 |
flag = ([[control cellAtRow: 4 column: 0] state] == NSOnState) ? YES : NO; |
277 |
[object setOneShot: flag]; |
278 |
|
279 |
// Dynamic depth limit |
280 |
flag = ([[control cellAtRow: 5 column: 0] state] == NSOnState) ? YES : NO; |
281 |
[object setDynamicDepthLimit: flag]; |
282 |
|
283 |
// wants to be color |
284 |
// FIXME: probably means window depth > 2 bits per pixel but don't know |
285 |
// exactly what NSWindow method to use to enforce that. |
286 |
flag = ([[control cellAtRow: 6 column: 0] state] == NSOnState) ? YES : NO; |
287 |
} |
288 |
} |
289 |
|
290 |
|
291 |
- (void) _getValuesFromObject: anObject |
292 |
{ |
293 |
if (anObject != object) |
294 |
return; |
295 |
|
296 |
[[titleForm cellAtIndex: 0] setStringValue: [anObject title] ]; |
297 |
|
298 |
[backingMatrix selectCellWithTag: [anObject backingType] ]; |
299 |
|
300 |
|
301 |
[controlMatrix deselectAllCells]; |
302 |
if ([anObject styleMask] & NSMiniaturizableWindowMask) |
303 |
[controlMatrix selectCellAtRow: 0 column: 0]; |
304 |
if ([anObject styleMask] & NSClosableWindowMask) |
305 |
[controlMatrix selectCellAtRow: 1 column: 0]; |
306 |
if ([anObject styleMask] & NSResizableWindowMask) |
307 |
[controlMatrix selectCellAtRow: 2 column: 0]; |
308 |
|
309 |
[optionMatrix deselectAllCells]; |
310 |
if ([anObject isReleasedWhenClosed]) |
311 |
[optionMatrix selectCellAtRow: 0 column: 0]; |
312 |
if ([anObject hidesOnDeactivate]) |
313 |
[optionMatrix selectCellAtRow: 1 column: 0]; |
314 |
|
315 |
// visible at launch time. |
316 |
{ |
317 |
GormDocument *doc = (GormDocument*)[(id<IB>)NSApp activeDocument]; |
318 |
if ([doc objectIsVisibleAtLaunch: anObject]) |
319 |
[optionMatrix selectCellAtRow: 2 column: 0]; |
320 |
} |
321 |
|
322 |
// defer comes here. |
323 |
{ |
324 |
GormDocument *doc = (GormDocument*)[(id<IB>)NSApp activeDocument]; |
325 |
if ([doc objectIsDeferred: anObject]) |
326 |
[optionMatrix selectCellAtRow: 3 column: 0]; |
327 |
} |
328 |
|
329 |
if ([anObject isOneShot]) |
330 |
[optionMatrix selectCellAtRow: 4 column: 0]; |
331 |
|
332 |
if ([anObject hasDynamicDepthLimit]) |
333 |
[optionMatrix selectCellAtRow: 5 column: 0]; |
334 |
|
335 |
// FIXME: wants to be color comes here |
336 |
|
337 |
} |
338 |
|
339 |
- (void) _validate: (id)anObject |
340 |
{ |
341 |
id cell = [controlMatrix cellAtRow: 0 column: 0]; |
342 |
// Assumed to be the "miniaturize" cell. |
343 |
// panels should not be allowed to miniaturize the app. |
344 |
|
345 |
if([anObject isKindOfClass: [NSPanel class]]) |
346 |
{ |
347 |
[cell setEnabled: NO]; |
348 |
} |
349 |
else |
350 |
{ |
351 |
[cell setEnabled: YES]; |
352 |
} |
353 |
} |
354 |
|
355 |
- (id) init |
356 |
{ |
357 |
if ([super init] == nil) |
358 |
return nil; |
359 |
|
360 |
if ([NSBundle loadNibNamed: @"GormNSWindowInspector" owner: self] == NO) |
361 |
{ |
362 |
NSLog(@"Could not gorm GormNSWindowInspector"); |
363 |
return nil; |
364 |
} |
365 |
return self; |
366 |
} |
367 |
|
368 |
- (void) ok: (id)sender |
369 |
{ |
370 |
[self _setValuesFromControl: sender]; |
371 |
} |
372 |
|
373 |
- (void) setObject: (id)anObject |
374 |
{ |
375 |
// Need to do something here to disable certain portions of |
376 |
// the inspector if the object being edited is an NSPanel. |
377 |
[super setObject: anObject]; |
378 |
// [self _validate: anObject]; |
379 |
[self _getValuesFromObject: anObject]; |
380 |
} |
381 |
|
382 |
@end |
383 |
|
384 |
|
385 |
|
386 |
@interface GormWindowSizeInspector : IBInspector |
387 |
{ |
388 |
NSForm *sizeForm; |
389 |
NSForm *minForm; |
390 |
} |
391 |
@end |
392 |
|
393 |
@implementation GormWindowSizeInspector |
394 |
|
395 |
- (void) _setValuesFromControl: control |
396 |
{ |
397 |
if (control == sizeForm) |
398 |
{ |
399 |
NSRect rect; |
400 |
rect = NSMakeRect([[control cellAtIndex: 0] floatValue], |
401 |
[[control cellAtIndex: 1] floatValue], |
402 |
[[control cellAtIndex: 2] floatValue], |
403 |
[[control cellAtIndex: 3] floatValue]); |
404 |
[object setFrame: rect display: YES]; |
405 |
} |
406 |
else if (control == minForm) |
407 |
{ |
408 |
NSSize size; |
409 |
size = NSMakeSize([[minForm cellAtIndex: 0] floatValue], |
410 |
[[minForm cellAtIndex: 1] floatValue]); |
411 |
[object setMinSize: size]; |
412 |
} |
413 |
} |
414 |
|
415 |
- (void) _getValuesFromObject: anObject |
416 |
{ |
417 |
NSRect frame; |
418 |
NSSize size; |
419 |
|
420 |
if (anObject != object) |
421 |
return; |
422 |
|
423 |
frame = [anObject frame]; |
424 |
[[sizeForm cellAtIndex: 0] setFloatValue: NSMinX(frame)]; |
425 |
[[sizeForm cellAtIndex: 1] setFloatValue: NSMinY(frame)]; |
426 |
[[sizeForm cellAtIndex: 2] setFloatValue: NSWidth(frame)]; |
427 |
[[sizeForm cellAtIndex: 3] setFloatValue: NSHeight(frame)]; |
428 |
|
429 |
size = [anObject minSize]; |
430 |
[[minForm cellAtIndex: 0] setFloatValue: size.width]; |
431 |
[[minForm cellAtIndex: 1] setFloatValue: size.height]; |
432 |
} |
433 |
|
434 |
- (void) windowChangeNotification: (NSNotification*)aNotification |
435 |
{ |
436 |
id notifier = [aNotification object]; |
437 |
|
438 |
[self _getValuesFromObject: notifier]; |
439 |
} |
440 |
|
441 |
- (id) init |
442 |
{ |
443 |
if ([super init] == nil) |
444 |
return nil; |
445 |
|
446 |
if ([NSBundle loadNibNamed: @"GormNSWindowSizeInspector" owner: self] == NO) |
447 |
{ |
448 |
NSLog(@"Could not gorm GormNSWindowSizeInspector"); |
449 |
return nil; |
450 |
} |
451 |
[[NSNotificationCenter defaultCenter] |
452 |
addObserver: self |
453 |
selector: @selector(windowChangeNotification:) |
454 |
name: NSWindowDidMoveNotification |
455 |
object: object]; |
456 |
[[NSNotificationCenter defaultCenter] |
457 |
addObserver: self |
458 |
selector: @selector(windowChangeNotification:) |
459 |
name: NSWindowDidResizeNotification |
460 |
object: object]; |
461 |
return self; |
462 |
} |
463 |
|
464 |
- (void) ok: (id)sender |
465 |
{ |
466 |
[self _setValuesFromControl: sizeForm]; |
467 |
[self _setValuesFromControl: minForm]; |
468 |
} |
469 |
|
470 |
- (void) setObject: (id)anObject |
471 |
{ |
472 |
[super setObject: anObject]; |
473 |
[self _getValuesFromObject: anObject]; |
474 |
} |
475 |
|
476 |
@end |