Initial release of Maemo 5 port of gnuplot
[gnuplot] / src / OpenStep / Controller.m
1 #import "Controller.h"
2 #import "GnuViewController.h"
3 #import "GnuView.h"
4
5 @implementation Controller
6
7 - (id) activeTerm
8 {
9   return activeTerm;
10 }
11
12 - (void) applicationDidFinishLaunching:(NSNotification *) notification
13 {
14     // NSApplication *theApplication = [notification object];
15     NSDictionary *gnutermDefaults;
16     NSPrintInfo *prInfo;
17
18 #if 0
19     gnutermDefaults = [NSDictionary dictionaryWithObjectsAndKeys:  @"400", @"Width", @"300", @"Height",  @"Buffered", @"Backing", NULL];
20 #endif
21
22     activeTerm = keyTerm = [self newGnuTerm:self];
23
24     myConnection = [NSConnection defaultConnection];
25     [myConnection retain];
26     [myConnection setRootObject:self];
27     if([myConnection registerName:@"gnuplotServer"] == NO) {
28         NSLog(@"Error registering %s\n", "gnuplotServer");
29     }
30
31 #warning PrintingConversion:  The current PrintInfo object now depends on context. '[NSPrintInfo sharedPrintInfo]' used to be '[NSApp printInfo]'. This might want to be [[NSPrintOperation currentOperation] printInfo] or possibly [[PageLayout new] printInfo].
32     prInfo = [NSPrintInfo sharedPrintInfo];
33 //        prInfo = [[NSPrintOperation currentOperation] printInfo];
34 #warning PrintingConversion: May be able to remove some of the [prInfo setXXXXMargin:] calls
35     [prInfo setLeftMargin:0];
36
37     [prInfo setRightMargin:0];
38
39     [prInfo setTopMargin:0];
40
41     [prInfo setBottomMargin:50];
42     [prInfo setOrientation:NSLandscapeOrientation];
43     [prInfo setHorizontallyCentered:YES];
44     [prInfo setVerticallyCentered:YES];
45
46 #if 0
47     /* Get user Preferences */
48     [[NSUserDefaults standardUserDefaults] registerDefaults: gnutermDefaults];  // TODO this may override existing values
49
50     [[DefaultSize cellAtIndex:0] setStringValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"Width"]];
51     [[DefaultSize cellAtIndex:1] setStringValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"Height"]];
52
53     if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Backing"] isEqualToString:@"Buffered"]) {
54         backing = NSBackingStoreBuffered;
55         [useBufferedSwitch setState:YES];
56     }
57     else {
58         backing = NSBackingStoreRetained;
59         [useBufferedSwitch setState:NO];
60     }
61
62     gvList = [NSMutableArray array];
63     [gvList retain];
64 #endif
65 }
66
67 - newGnuTerm:sender
68 {
69     NSWindow *win;
70     NSRect frame;
71
72     if ([NSBundle loadNibNamed:@"gnuview.nib" owner:self] == NO) {
73         return nil;
74     }
75
76     if (win = [activeTerm window]) {
77         frame = [win frame];
78         (&frame)->origin.x += offset;
79         (&frame)->origin.y -= offset;
80         if ( (offset += 24.0) > 100.0)
81             offset = 0.0;
82
83         [win setTitle:[NSString stringWithFormat: @"gnuplot %d", ++gnuviewNum]];
84
85         [win setFrame:frame display:YES];
86         [win makeKeyAndOrderFront:nil];
87
88         return activeTerm;
89     }
90     return nil;
91 }
92
93
94 - (void) setActiveTerm:(id) newTerm
95 {
96         if (activeTerm != nil) [activeTerm deactivate:self];
97
98         activeTerm = newTerm;
99 }
100
101 - (void) printPScodeInKey:sender
102 {
103     [[keyTerm gnuView] print:sender];
104 }
105
106 - (void) setKeyTerm: (id) newTerm
107 {
108         keyTerm = newTerm;
109
110         [NameField setStringValue:[[keyTerm window] title]];
111         [NameField selectText:self];
112 }
113
114 - (void) setKeyTitle:sender
115 {
116         [[keyTerm window] setTitle:[NameField stringValue]];
117         [[NameField window] performClose:self];
118 }
119
120 - (void) executePScode:(NSString *) PSstring termTitle:(NSString *) title;
121 {
122         NSLog(@"Request for window: %@\n", title);
123
124         if (activeTerm == nil) [self newGnuTerm:self];
125
126         [[activeTerm gnuView] executePS:PSstring];
127 }
128
129
130
131 @end