Annotation of OpenXM_contrib/gnuplot/NeXT/Controller.m, Revision 1.1.1.1
1.1 maekawa 1: #import <defaults/defaults.h>
2: #import "Controller.h"
3: #import "gnuviewController.h"
4: #import "GnuView.h"
5:
6:
7: @implementation Controller
8:
9: - (id) activeTerm
10: {
11: return activeTerm;
12: }
13:
14:
15: - appDidInit:sender
16: {
17: id prInfo;
18: NXRect *paperRect;
19:
20: static NXDefaultsVector GnuTermDefaults = {
21: {"Width", "400"},
22: {"Height", "300"},
23: {"Backing", "Buffered"},
24: {NULL}
25: };
26:
27:
28: activeTerm = keyTerm = nil;
29:
30: myConnection = [NXConnection registerRoot:self withName:"gnuplotServer"];
31: [myConnection runFromAppKit];
32:
33: prInfo = [NXApp printInfo];
34: paperRect = (NXRect *) [prInfo paperRect];
35: [prInfo setOrientation:NX_LANDSCAPE andAdjust:YES];
36: [prInfo setHorizCentered:YES];
37: [prInfo setVertCentered:YES];
38:
39: /* Get user Preferences */
40: NXRegisterDefaults("GnuTerm", GnuTermDefaults);
41:
42: [DefaultSize setStringValue:NXGetDefaultValue("GnuTerm","Width") at:0];
43: [DefaultSize setStringValue:NXGetDefaultValue("GnuTerm","Height") at:1];
44:
45: if (!strcmp(NXGetDefaultValue("GnuTerm","Backing"), "Buffered")) {
46: backing = NX_BUFFERED;
47: [useBufferedSwitch setState:YES];
48: }
49: else {
50: backing = NX_RETAINED;
51: [useBufferedSwitch setState:NO];
52: }
53:
54: gvList = [[List new] initCount:10];
55:
56: return self;
57: }
58:
59: - newGnuTerm:sender
60: {
61: NXRect frame;
62:
63: if ([gvList indexOf:keyTerm] != NX_NOT_IN_LIST) {
64: [[keyTerm window] getFrame: &frame];
65: NX_X(&frame) += 24;
66: NX_Y(&frame) -= 24;
67: }
68: else {
69: NX_WIDTH(&frame) = atof(NXGetDefaultValue("GnuTerm","Width"));
70: NX_HEIGHT(&frame) = atof(NXGetDefaultValue("GnuTerm","Height"));
71: NX_X(&frame) = 200;
72: NX_Y(&frame) = 350;
73: }
74:
75: if ([NXApp loadNibSection: "gnuview.nib" owner: self] == nil) {
76: return nil;
77: }
78: // fprintf(stderr,"newGnuTerm: %g x %g\n",NX_WIDTH(&frame),NX_HEIGHT(&frame));
79:
80: [[activeTerm window] setBackingType:backing];
81: [[activeTerm window] placeWindowAndDisplay: &frame];
82: [self setKeyTerm:activeTerm];
83:
84: [gvList addObject:activeTerm];
85: ++wcnt;
86:
87: return activeTerm;
88: }
89:
90:
91: - setActiveTerm:(id) newTerm
92: {
93: if (activeTerm != nil) [activeTerm deactivate:self];
94:
95: activeTerm = newTerm;
96: [activeTerm GVactivate:self];
97:
98: return self;
99: }
100:
101: - printPScodeInKey:sender
102: {
103: [[keyTerm gnuView] printPSCode:sender];
104:
105: return self;
106:
107:
108: }
109:
110: - setKeyTerm:newTerm
111: {
112: keyTerm = newTerm;
113:
114: [NameField setStringValue:[[keyTerm window] title]];
115: [NameField selectText:self];
116:
117: return self;
118: }
119:
120: - setKeyTitle:sender
121: {
122: [[keyTerm window] setTitle:[NameField stringValue]];
123: [[NameField window] performClose:self];
124: return self;
125: }
126:
127: - executePScode:(char *)PSstring termTitle:(char *)title
128: {
129: int i, cnt;
130: id test;
131: char buf[50];
132:
133: //fprintf(stderr, "Request for window: %s\n", title);
134:
135: if (*title) {
136: /* If the window exists, use it */
137: cnt = [gvList count];
138: for (i=0; i < cnt; ++i) {
139: test = [gvList objectAt:i];
140: if ( !strcmp([[test window] title], title)) {
141: if (test != activeTerm) [self setActiveTerm:test];
142: break;
143: }
144: }
145: /* O.K., it doesn't exist, what now? */
146: if (i == cnt) {
147: [self newGnuTerm:self];
148: [[activeTerm window] setTitle: title];
149: }
150: }
151: else {
152: if (activeTerm == nil) {
153: [self newGnuTerm:self];
154: sprintf(buf, "gnuplot %d", wcnt);
155: [[activeTerm window] setTitle: buf];
156: }
157: }
158:
159:
160: [[activeTerm window] makeKeyAndOrderFront: nil];
161: [[activeTerm gnuView] executePS:PSstring];
162:
163: return activeTerm;
164: }
165:
166: - termWillClose:sender
167: {
168: [gvList removeObject:sender];
169: if (activeTerm == sender) activeTerm =nil;
170:
171: return self;
172: }
173:
174: - setDefaultGTSize:sender
175: {
176: NXRect frame;
177:
178: if (sender == useKeyButton) {
179: fprintf(stderr, "useKey\n");
180: if ([gvList indexOf:keyTerm] != NX_NOT_IN_LIST) {
181: [[keyTerm window] getFrame: &frame];
182: [DefaultSize setFloatValue:NX_WIDTH(&frame) at:0];
183: [DefaultSize setFloatValue:NX_HEIGHT(&frame) at:1];
184: }
185: }
186:
187: NXWriteDefault("GnuTerm", "Width", [DefaultSize stringValueAt:0]);
188: NXWriteDefault("GnuTerm", "Height", [DefaultSize stringValueAt:1]);
189:
190:
191: fprintf(stderr, "setDefaultGTSize: %s x %s\n",
192: [DefaultSize stringValueAt:0],[DefaultSize stringValueAt:1]);
193:
194: return self;
195: }
196:
197: - setUseBuffered:sender
198: {
199: if ([sender state] == YES) {
200: backing = NX_BUFFERED;
201: NXWriteDefault("GnuTerm", "Backing", "Buffered");
202: }
203: else {
204: backing = NX_RETAINED;
205: NXWriteDefault("GnuTerm", "Backing", "Retained");
206: }
207: [[activeTerm window] setBackingType:backing];
208:
209:
210: return self;
211: }
212:
213:
214: - closeAll:sender
215: {
216: while([gvList count]) [[[gvList objectAt:0] window] performClose:self];
217: return self;
218: }
219: - miniaturizeAll:sender
220: {
221: int i, cnt;
222:
223: cnt = [gvList count];
224:
225: for (i=0; i < cnt; ++i)
226: [[[gvList objectAt:i] window] performMiniaturize:self];
227:
228: return self;
229: }
230:
231: @end
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>