File: Dispatch.m

package info (click to toggle)
pgplot5 5.2-8
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 6,268 kB
  • ctags: 5,900
  • sloc: fortran: 37,938; ansic: 18,809; sh: 1,136; objc: 532; perl: 443; makefile: 271; pascal: 233; tcl: 178; awk: 51; csh: 25
file content (201 lines) | stat: -rw-r--r-- 4,974 bytes parent folder | download | duplicates (15)
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
// Dispatch is the central clearinghouse for the pgview program.  Dispatch
// creates a Listener object to listen to messages from PGPLOT programs.
// Most of these messages are routed to the active PGView object.
// Dispatch also allows the user to create new windows and to print
// windows using the main menu.  Since changing windows in the middle of
// a PostScript stream may cause problems, Dispatch does now allow the
// active window to change if PGPLOT is in the midst of a plot, i.e.,
// between the Begin Picture and End Picture commands.  Since most PGPLOT
// programs only send an End Picture immdediately prior to the next Begin
// Picture command, this means that you will not be able to change windows
// while most PGPLOT programs are running.
//
// 1992-Mar-9 - [AFT]
//---
#import "Dispatch.h"
#import <appkit/Application.h>
#import <appkit/PrintInfo.h>
#import "PGView.h"
#import "pgvListener.h"
#import "sername.h"

@implementation Dispatch

//
//--- Class methods -----------------------------------------------------
//

- init
{
      NXPoint  spot;

      [super init];

// Listen for PGPLOT programs
      myListener = [[pgvListener alloc] init];
      [myListener checkInAs: PGV_SERVER_NAME];
      [myListener addPort];
      [myListener setDelegate:self];

// Scale print jobs to print on one page.  Note setxxxPagination does not
// return self.
      [[NXApp printInfo] setHorizPagination:NX_FITPAGINATION];
      [[NXApp printInfo]  setVertPagination:NX_FITPAGINATION];

// Prepare the cross cursor
      crossCursor=[[NXCursor alloc] 
         initFromImage:[NXImage newFromSection:"cross.tiff"]];
      spot.x = spot.y = 7.0;
      [crossCursor setHotSpot:&spot];

// 0=Landscape, 1=portrait
      iwtype=0;
      curView=NULL;
      qdrawing=NO;

      return self;
}

//
//--- Window delegate ---------------------------------------------------
//

- windowDidBecomeMain:sender
// If PGPLOT is actively drawing, then we try to prevent the key window
// from changing.  This is done so that the main window (i.e., the one
// with the back title bar) will denote the currently active plot window.
{
      if( qdrawing ) {
         if( [sender contentView] != curView) {
            [[curView window] makeKeyWindow];
         }
      } else {
         curView=[sender contentView];
         [curView gettype: &iwtype];
         if(iwtype==0) {
            [[NXApp printInfo] setOrientation:NX_LANDSCAPE andAdjust:YES];
         } else {
            [[NXApp printInfo] setOrientation:NX_PORTRAIT  andAdjust:YES];
         }
      }
      return self;
}

- windowWillClose:sender
// Prevent PGPLOT from trying to draw to a window that was closed.
{
      if( curView == [sender contentView] ) curView=NULL;
      return self;
}

//
//--- Targets for menu items --------------------------------------------
//

- showInfo:sender
{
      if(!infoPanel) {
         [NXApp loadNibSection:"info.nib" owner:self];
      }
      [infoPanel makeKeyAndOrderFront:self];
      return self;
}

- newLand:sender
{
static NXRect wRect = {{330.0, 230.0},{720.0,535.0}};
      PGView   *newView;

      newView = [[PGView alloc] initFrame:&wRect];
      [[newView window] setDelegate:self];     
      if( !qdrawing ) {
         curView=newView;
         iwtype=0;
         [[NXApp printInfo] setOrientation:NX_LANDSCAPE andAdjust:YES];
      }
      return self;
}

- newPort:sender
{
static NXRect wRect = {{500.0, 70.0},{535.0,720.0}};
      PGView   *newView;

      newView = [[PGView alloc] initFrame:&wRect];
      [[newView window] setDelegate:self];
      if( !qdrawing ) {
         curView=newView;
         iwtype=1;
         [[NXApp printInfo] setOrientation:NX_PORTRAIT andAdjust:YES];
      }
      return self;
}

- print:sender
{
      [curView printPSCode:self];
      return self;
}

//
//--- Listener methods --------------------------------------------------
//

- beginp
{
      qdrawing=YES;
      [curView beginp];
      if([NXApp isHidden]) {
         [NXApp unhideWithoutActivation:self];
      }
      if(![[curView window] isVisible]) {
         [[curView window] orderFront:self];
      }
      return 0;
}

- cursorat: (double *) xpos and: (double *) ypos  char: (int *) ichar
{
      NXPoint aPoint;

      aPoint.x=(float) *xpos;
      aPoint.y=(float) *ypos;
      [curView readcursor: &aPoint char: ichar cursor:crossCursor];
      *xpos=(double) aPoint.x;
      *ypos=(double) aPoint.y;
      return 0;
}

- flush
{
      [curView flush];
      return 0;
}

- getwind: (int *) ixdim  by: (int *) iydim
         scale: (double *) dmag  color: (int *) icol
{
      if(curView == NULL) {
         if(iwtype==0) {
            [self newLand:self];
         } else {
            [self newPort:self];
         }
      }
      [curView getwind:ixdim  by:iydim  color:icol  scale:dmag];
      return 0;
}

- pscode: (char *) cbuf
{
      [curView pscode:cbuf];
      return 0;
}

- endp
{
      qdrawing=NO;
      return 0;
}

@end