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 |
@implementation GormNSWindow (IBInspectorClassNames) |
159 |
- (NSString*) inspectorClassName |
160 |
{ |
161 |
return @"GormWindowAttributesInspector"; |
162 |
} |
163 |
- (NSString*) sizeInspectorClassName |
164 |
{ |
165 |
return @"GormWindowSizeInspector"; |
166 |
} |
167 |
@end |
168 |
|
169 |
@implementation GormNSPanel (IBInspectorClassNames) |
170 |
- (NSString*) inspectorClassName |
171 |
{ |
172 |
return @"GormWindowAttributesInspector"; |
173 |
} |
174 |
- (NSString*) sizeInspectorClassName |
175 |
{ |
176 |
return @"GormWindowSizeInspector"; |
177 |
} |
178 |
@end |
179 |
|
180 |
|
181 |
|
182 |
|
183 |
@interface GormWindowAttributesInspector : IBInspector |
184 |
{ |
185 |
id titleForm; |
186 |
id backingMatrix; |
187 |
id optionMatrix; |
188 |
id controlMatrix; |
189 |
} |
190 |
@end |
191 |
|
192 |
@implementation GormWindowAttributesInspector |
193 |
|
194 |
- (void) _setValuesFromControl: control |
195 |
{ |
196 |
|
197 |
if (control == titleForm) |
198 |
{ |
199 |
[object setTitle: [[control cellAtIndex: 0] stringValue] ]; |
200 |
} |
201 |
else if (control == backingMatrix) |
202 |
{ |
203 |
[object setBackingType: [[control selectedCell] tag] ]; |
204 |
} |
205 |
else if (control == controlMatrix) |
206 |
{ |
207 |
unsigned int newStyleMask; |
208 |
int rows,cols,i; |
209 |
|
210 |
[control getNumberOfRows:&rows columns:&cols]; |
211 |
|
212 |
newStyleMask = [object styleMask]; |
213 |
for (i=0;i<rows;i++) { |
214 |
if ([[control cellAtRow: i column: 0] state] == NSOnState) |
215 |
newStyleMask |= [[control cellAtRow: i column: 0] tag]; |
216 |
else |
217 |
newStyleMask &= ~[[control cellAtRow: i column: 0] tag]; |
218 |
} |
219 |
|
220 |
[object setStyleMask: newStyleMask]; |
221 |
// FIXME: This doesn't refresh the window decoration. How to do that? |
222 |
// (currently needs manual hide/unhide to update decorations) |
223 |
[object display]; |
224 |
} |
225 |
else if (control == optionMatrix) |
226 |
{ |
227 |
BOOL flag; |
228 |
|
229 |
// Release When Closed |
230 |
flag = ([[control cellAtRow: 0 column: 0] state] == NSOnState) ? YES : NO; |
231 |
[object setReleasedWhenClosed: flag]; |
232 |
|
233 |
// Hide on deactivate |
234 |
flag = ([[control cellAtRow: 1 column: 0] state] == NSOnState) ? YES : NO; |
235 |
[object setHidesOnDeactivate: flag]; |
236 |
|
237 |
// Visible at launch time. (not an object property. Stored in a Gorm dictionnary) |
238 |
flag = ([[control cellAtRow: 2 column: 0] state] == NSOnState) ? YES : NO; |
239 |
{ |
240 |
GormDocument *doc = (GormDocument*)[(id<IB>)NSApp activeDocument]; |
241 |
[doc setObject: object isVisibleAtLaunch: flag]; |
242 |
} |
243 |
|
244 |
// Deferred |
245 |
flag = ([[control cellAtRow: 3 column: 0] state] == NSOnState) ? YES : NO; |
246 |
{ |
247 |
GormDocument *doc = (GormDocument*)[(id<IB>)NSApp activeDocument]; |
248 |
[doc setObject: object isDeferred: flag]; |
249 |
} |
250 |
|
251 |
// One shot |
252 |
flag = ([[control cellAtRow: 4 column: 0] state] == NSOnState) ? YES : NO; |
253 |
[object setOneShot: flag]; |
254 |
|
255 |
// Dynamic depth limit |
256 |
flag = ([[control cellAtRow: 5 column: 0] state] == NSOnState) ? YES : NO; |
257 |
[object setDynamicDepthLimit: flag]; |
258 |
|
259 |
// wants to be color |
260 |
// FIXME: probably means window depth > 2 bits per pixel but don't know |
261 |
// exactly what NSWindow method to use to enforce that. |
262 |
flag = ([[control cellAtRow: 6 column: 0] state] == NSOnState) ? YES : NO; |
263 |
} |
264 |
} |
265 |
|
266 |
|
267 |
- (void) _getValuesFromObject: anObject |
268 |
{ |
269 |
if (anObject != object) |
270 |
return; |
271 |
|
272 |
[[titleForm cellAtIndex: 0] setStringValue: [anObject title] ]; |
273 |
|
274 |
[backingMatrix selectCellWithTag: [anObject backingType] ]; |
275 |
|
276 |
|
277 |
[controlMatrix deselectAllCells]; |
278 |
if ([anObject styleMask] & NSMiniaturizableWindowMask) |
279 |
[controlMatrix selectCellAtRow: 0 column: 0]; |
280 |
if ([anObject styleMask] & NSClosableWindowMask) |
281 |
[controlMatrix selectCellAtRow: 1 column: 0]; |
282 |
if ([anObject styleMask] & NSResizableWindowMask) |
283 |
[controlMatrix selectCellAtRow: 2 column: 0]; |
284 |
|
285 |
[optionMatrix deselectAllCells]; |
286 |
if ([anObject isReleasedWhenClosed]) |
287 |
[optionMatrix selectCellAtRow: 0 column: 0]; |
288 |
if ([anObject hidesOnDeactivate]) |
289 |
[optionMatrix selectCellAtRow: 1 column: 0]; |
290 |
|
291 |
// visible at launch time. |
292 |
{ |
293 |
GormDocument *doc = (GormDocument*)[(id<IB>)NSApp activeDocument]; |
294 |
if ([doc objectIsVisibleAtLaunch: anObject]) |
295 |
[optionMatrix selectCellAtRow: 2 column: 0]; |
296 |
} |
297 |
|
298 |
// defer comes here. |
299 |
{ |
300 |
GormDocument *doc = (GormDocument*)[(id<IB>)NSApp activeDocument]; |
301 |
if ([doc objectIsDeferred: anObject]) |
302 |
[optionMatrix selectCellAtRow: 3 column: 0]; |
303 |
} |
304 |
|
305 |
if ([anObject isOneShot]) |
306 |
[optionMatrix selectCellAtRow: 4 column: 0]; |
307 |
|
308 |
if ([anObject hasDynamicDepthLimit]) |
309 |
[optionMatrix selectCellAtRow: 5 column: 0]; |
310 |
|
311 |
// FIXME: wants to be color comes here |
312 |
|
313 |
} |
314 |
|
315 |
- (void) _validate: (id)anObject |
316 |
{ |
317 |
id cell = [controlMatrix cellAtRow: 0 column: 0]; |
318 |
// Assumed to be the "miniaturize" cell. |
319 |
// panels should not be allowed to miniaturize the app. |
320 |
|
321 |
if([anObject isKindOfClass: [NSPanel class]]) |
322 |
{ |
323 |
[cell setEnabled: NO]; |
324 |
} |
325 |
else |
326 |
{ |
327 |
[cell setEnabled: YES]; |
328 |
} |
329 |
} |
330 |
|
331 |
- (id) init |
332 |
{ |
333 |
if ([super init] == nil) |
334 |
return nil; |
335 |
|
336 |
if ([NSBundle loadNibNamed: @"GormNSWindowInspector" owner: self] == NO) |
337 |
{ |
338 |
NSLog(@"Could not gorm GormNSWindowInspector"); |
339 |
return nil; |
340 |
} |
341 |
return self; |
342 |
} |
343 |
|
344 |
- (void) ok: (id)sender |
345 |
{ |
346 |
[self _setValuesFromControl: sender]; |
347 |
} |
348 |
|
349 |
- (void) setObject: (id)anObject |
350 |
{ |
351 |
// Need to do something here to disable certain portions of |
352 |
// the inspector if the object being edited is an NSPanel. |
353 |
[super setObject: anObject]; |
354 |
// [self _validate: anObject]; |
355 |
[self _getValuesFromObject: anObject]; |
356 |
} |
357 |
|
358 |
@end |
359 |
|
360 |
|
361 |
|
362 |
@interface GormWindowSizeInspector : IBInspector |
363 |
{ |
364 |
NSForm *sizeForm; |
365 |
NSForm *minForm; |
366 |
} |
367 |
@end |
368 |
|
369 |
@implementation GormWindowSizeInspector |
370 |
|
371 |
- (void) _setValuesFromControl: control |
372 |
{ |
373 |
if (control == sizeForm) |
374 |
{ |
375 |
NSRect rect; |
376 |
rect = NSMakeRect([[control cellAtIndex: 0] floatValue], |
377 |
[[control cellAtIndex: 1] floatValue], |
378 |
[[control cellAtIndex: 2] floatValue], |
379 |
[[control cellAtIndex: 3] floatValue]); |
380 |
[object setFrame: rect display: YES]; |
381 |
} |
382 |
else if (control == minForm) |
383 |
{ |
384 |
NSSize size; |
385 |
size = NSMakeSize([[minForm cellAtIndex: 0] floatValue], |
386 |
[[minForm cellAtIndex: 1] floatValue]); |
387 |
[object setMinSize: size]; |
388 |
} |
389 |
} |
390 |
|
391 |
- (void) _getValuesFromObject: anObject |
392 |
{ |
393 |
NSRect frame; |
394 |
NSSize size; |
395 |
|
396 |
if (anObject != object) |
397 |
return; |
398 |
|
399 |
frame = [anObject frame]; |
400 |
[[sizeForm cellAtIndex: 0] setFloatValue: NSMinX(frame)]; |
401 |
[[sizeForm cellAtIndex: 1] setFloatValue: NSMinY(frame)]; |
402 |
[[sizeForm cellAtIndex: 2] setFloatValue: NSWidth(frame)]; |
403 |
[[sizeForm cellAtIndex: 3] setFloatValue: NSHeight(frame)]; |
404 |
|
405 |
size = [anObject minSize]; |
406 |
[[minForm cellAtIndex: 0] setFloatValue: size.width]; |
407 |
[[minForm cellAtIndex: 1] setFloatValue: size.height]; |
408 |
} |
409 |
|
410 |
- (void) windowChangeNotification: (NSNotification*)aNotification |
411 |
{ |
412 |
id notifier = [aNotification object]; |
413 |
|
414 |
[self _getValuesFromObject: notifier]; |
415 |
} |
416 |
|
417 |
- (id) init |
418 |
{ |
419 |
if ([super init] == nil) |
420 |
return nil; |
421 |
|
422 |
if ([NSBundle loadNibNamed: @"GormNSWindowSizeInspector" owner: self] == NO) |
423 |
{ |
424 |
NSLog(@"Could not gorm GormNSWindowSizeInspector"); |
425 |
return nil; |
426 |
} |
427 |
[[NSNotificationCenter defaultCenter] |
428 |
addObserver: self |
429 |
selector: @selector(windowChangeNotification:) |
430 |
name: NSWindowDidMoveNotification |
431 |
object: object]; |
432 |
[[NSNotificationCenter defaultCenter] |
433 |
addObserver: self |
434 |
selector: @selector(windowChangeNotification:) |
435 |
name: NSWindowDidResizeNotification |
436 |
object: object]; |
437 |
return self; |
438 |
} |
439 |
|
440 |
- (void) ok: (id)sender |
441 |
{ |
442 |
[self _setValuesFromControl: sizeForm]; |
443 |
[self _setValuesFromControl: minForm]; |
444 |
} |
445 |
|
446 |
- (void) setObject: (id)anObject |
447 |
{ |
448 |
[super setObject: anObject]; |
449 |
[self _getValuesFromObject: anObject]; |
450 |
} |
451 |
|
452 |
@end |