File: dispatchobj.m

package info (click to toggle)
pgplot5 5.2.2-19.3
  • links: PTS
  • area: non-free
  • in suites: buster, stretch
  • size: 7,136 kB
  • ctags: 6,763
  • sloc: fortran: 39,792; ansic: 22,549; objc: 1,534; sh: 1,298; makefile: 385; perl: 234; pascal: 233; tcl: 190; awk: 51; csh: 25
file content (194 lines) | stat: -rw-r--r-- 4,540 bytes parent folder | download | duplicates (11)
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
// dispatch.m--The purpose is to keep track of the currently active plot
// view and to route messages from the PGPLOT program there.  To do this,
// dispatchobj needs to be the target for the Menu items that create
// windows.  It also needs to be the window delegate. And finally it
// needs to receive messages from the Port object (i.e., from the
// socket interface to the PGPLOT program).
//    If PGPLOT is drawing to a window then dispatchobj doe not allow
// the user to delete the window.
//
// 1999-Feb-20 - Update for OpenStep - [AFT]
// 1992-Mar-9 - [AFT]
//---
#import "dispatchobj.h"
#import "ipanelobj.h"

@implementation dispatchobj

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

- init
{
      NSPoint  spot;

      [super init];

// Scale print jobs to print on one page.
      [[NSPrintInfo sharedPrintInfo] setHorizontalPagination:NSFitPagination];
      [[NSPrintInfo sharedPrintInfo] setVerticalPagination:NSFitPagination];

// Prepare the cross cursor
      spot.x = 7.0; spot.y = 7.0;
      crossCursor = [[NSCursor alloc]
         initWithImage:[NSImage imageNamed:@"cross.tiff"]
         hotSpot:spot];

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

      return self;
}

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

- (void)windowDidBecomeMain:(NSNotification *)notification
// If PGPLOT is actively drawing, then we try to prevent the key window
// from changing.  This is done so that the key window (i.e., the one
// with the back title bar) will denote the currently active plot window.
{
      NSWindow *theWindow = [notification object];
      if( qdrawing ) {
// If we are drawing, then force the curView view to be the key window.
         if( [theWindow contentView] != curView) {
             [[curView window] makeKeyWindow];
         }
      } else {
         curView=[theWindow contentView];
         [curView gettype: &iwtype];
         if(iwtype==0) {
            [[NSPrintInfo sharedPrintInfo] setOrientation:NSLandscapeOrientation];
         } else {
            [[NSPrintInfo sharedPrintInfo] setOrientation:NSPortraitOrientation];
         }
      }
      return;
}

- (BOOL)windowShouldClose:(id)sender
// Prevent window manager from closing a window in which PGPLOT is
// still drawing.
{
      if( !qdrawing || curView != [sender contentView] ) {
         if ( !qdrawing ) curView=NULL;
         return YES;
      }
      return NO;
}


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

- (void)newLand
{
static NSRect wRect = {{330.0, 230.0},{720.0,535.0}};
      pgviewobj *newView;

      newView = [[pgviewobj alloc] initWithFrame:wRect];
      [[newView window] setDelegate:self];
      if( !qdrawing ) {
         curView=newView;
         iwtype=0;
         [[NSPrintInfo sharedPrintInfo] setOrientation:NSLandscapeOrientation];
      }
      return;
}

- (void)newPort
{
static NSRect wRect = {{500.0, 70.0},{535.0,720.0}};
      pgviewobj *newView;

      newView = [[pgviewobj alloc] initWithFrame:wRect];
      [[newView window] setDelegate:self];
      if( !qdrawing ) {
         curView=newView;
         iwtype=1;
         [[NSPrintInfo sharedPrintInfo] setOrientation:NSPortraitOrientation];
      }
      return;
}

- (void)pgprint
{
      [curView print:self];
      return;
}

- (void)showInfo
{
      [[[ipanelobj alloc] init] showit];
      return;
}

- (void)deactive
{
      [NSApp hide:self];
      [NSApp unhideWithoutActivation];
      return;
}

//
//--- methods called by the Port object ---------------------------------
//

- (void)beginp
{
      qdrawing=YES;
      [curView beginp];
      return;
}

- (void)cursorat: (float *) xpos and: (float *) ypos  char: (int *) ichar
{
      NSPoint aPoint;

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

- (void)flushpg
{
      [curView flushpg];
      return;
}

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

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

- (void)endp
{
      qdrawing=NO;
      [curView endp];
      return;
}

@end