File: MacWinOther.c

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (431 lines) | stat: -rw-r--r-- 9,503 bytes parent folder | download | duplicates (3)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
/*------------------------------------------------------------------------
    Graphic library for 2D and 3D plotting 
    Copyright (C) 1998 Chancelier Jean-Philippe
    jpc@cergrene.enpc.fr 
 --------------------------------------------------------------------------*/

#include "machine.h"
#include <QuickDraw.h>
#include <MacTypes.h>
#include <WindowMgr.h>
#include <ControlMgr.h>
#include <EventMgr.h>

#ifdef THINK_C	/* SYSDEP.H */
#include <stdlib.h>
#define __STDC__
#define  SYS5
#define  AIFF
#define  WINDOWS	/* with winmac.c */
#else
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#endif

#ifdef SYS5
#define  index(A,B) strchr(A,B)
#include <fcntl.h>
#include <string.h>
#else
#include <strings.h>
#endif


#include <stdio.h>
#define XINIT    10	/* set default window location */
#define YINIT    50
#define WIDTH    300	/* start off v small - user resizes */
#define HEIGHT   300
#define BDR      2
#define MSGX     16	/* offset for message in window */
#define MSGY     16
#define TXHGHT   14	/* baseline offset for text */
#define SBARWIDTH 16
#define SBarWidth 16
/* protoypes */
static void myWwait(char *msg);
void myWwinWait(WindowPtr win, char *msg);

/* static variables */

static winstance = 0;	/* counts windows to offset across screen */
#define STACKDEPTH 4	/* number of windows down to go */

WindowPtr lwin = 0;
Rect dragRect;
static int width = 5;

#define	MAXWIN 16
WindowPtr ourWins[MAXWIN] = {NULL, NULL, NULL, NULL,
  NULL, NULL, NULL, NULL,
  NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL};

/* Clears the current window  */
UpdateCWindow()
{
  WindowPtr theWindow;
  extern WindowPtr C2F(GetWindowNumber)();
  int verbose = 0, win1, narg;
  C2F(dr)("xget", "window", &verbose, &win1, &narg,(int *) 0, (int *) 0, (int *) 0, 0, 0);
  theWindow = C2F(GetWindowNumber)(win1);
  if ( theWindow != NULL) 
  	{
  	  	GrafPtr savePort;
  	  	Scistring("UpdateCWindow In \n");
  		GetPort(&savePort);
  		SetPort(theWindow);
  		EraseRect(&theWindow->portRect);
  		DrawGrowIcon(theWindow);
  		SetPort(savePort);
  		Scistring("UpdateCWindow Out \n");
  	}
}

/* Called when a window Needs update */

UpdateWindow(theWindow)
  WindowPtr theWindow;
{
  GrafPtr savePort;
  GetPort(&savePort);
  SetPort(theWindow);
  BeginUpdate(theWindow);
  EraseRect(&theWindow->portRect);
  DrawGrowIcon(theWindow);
  DrawContents(theWindow);
  EndUpdate(theWindow);
  SetPort(savePort);
}

/** No effect **/

DoContent(theWindow, theEvent)
     WindowPtr	theWindow;
     EventRecord	*theEvent;
{
  int				cntlCode;
  ControlHandle 	theControl;
  int				pageSize;
  GrafPtr			savePort;
/*
  GetPort(&savePort);
  SetPort(theWindow);
  GlobalToLocal( &theEvent->where );
  if ((cntlCode = FindControl(theEvent->where, theWindow, &theControl)) == 0) {
    if (PtInRect( theEvent->where, &myWindow->portRect ))
      DoMyContent(theWindow, theEvent);		
  }
  else if (cntlCode == inThumb) {
    TrackControl(theControl, theEvent->where, 0L);
    AdjustText();
  }
  else
    TrackControl(theControl, theEvent->where, &ScrollProc);

  SetPort(savePort);
*/
}

/** Called when a Window is sized **/

MyGrowWindow(w, p)
  WindowPtr w;
  Point p;
{
  GrafPtr savePort;
  long theResult;
  Rect r, oView;
  GetPort(&savePort);
  SetPort(w);
  SetRect(&r, 80, 80, screenBits.bounds.right, screenBits.bounds.bottom);
  theResult = GrowWindow(w, p, &r);
  if (theResult == 0)
    return;
  SizeWindow(w, LoWord(theResult), HiWord(theResult), 1);
  InvalRect(&w->portRect);
  oView = w->portRect;
  HidePen();
  DrawContents(w);
  DrawGrowIcon(w);
  ShowPen();
  SetPort(savePort);
}

/*
CloseMyWindow()
{
  HideWindow( myWindow );
  DisposeWindow( myWindow );
}
*/
/* called during program initialisation */

int Graphable()	
{	
  /* Always use graphs on mac, so just sets it up */
  /* mac screen initialisation ? */
  InitGraf(&thePort);
  return (1);			
  /* graphics available */
}

WaitForUpdate(WindowPtr w)
{
  MainEvent(updateEvt);
}

RedrawGWin(WindowPtr w)
{
  Rect myRect;
}

/** Searches if the Window win is a graphic one and then redraws it **/

DrawContents(WindowPtr win)
{
  Rect myRect;
  int msgW, msgH, color = true, i, winnumber;
  winnumber = 0;
  for (i = 0; i < MAXWIN; ++i)
    if (ourWins[i] == win)
    {
      WindowPtr loc;
      int verbose = 0, win1, narg;
      	sciprint("Tape redraw of %d\r\n",i);
    
      C2F(dr)("xget", "window", &verbose, &win1, &narg
	  ,(int *) 0, (int *) 0, (int *) 0, 0, 0);
      winnumber = i;
      /* fait planter */
      /* C2F(dr)("xset","window",&i,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);*/
      Tape_Replay("v", &winnumber);
      /*C2F(dr)("xset","window",&win1,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);*/
    }
}

/* print click-Exit message in most recently active window */

int ExitGraph()	
{
  myWwait("click here to EXIT");
  return (lwin == NULL);
}

static void myWprintLines(win, msg, x, y, pw, ph)	/* prints str with embdd
							 * '\n's */
  WindowPtr win;	/* on multiple lines */
  char *msg;	/* returns overall width & depth of area printed */
  int x, y;
  int *pw, *ph;
{
  int lin = 0, w, slen;
  char *s1, *s2;
  *pw = 0;
  *ph = 0;
  s1 = msg;
  do
  {
    s2 = strchr(s1, '\n');
    if (s2)
      *s2 = '\0';
    AddText(MSGX, MSGY + lin * TXHGHT, s1);
    if (s2)
      *s2 = '\n';
    if ((w = 8 * (s2 - s1)) > *pw)	/* hack to figure width of text */
      *pw = w;
    *ph += TXHGHT;
    s1 = s2 + 1;
    ++lin;
  } while (s2 != NULL);
}

static void myWwait(msg)
  char *msg;
{
  if (lwin != NULL)
    myWwinWait(lwin, msg);
}

void myWwinWait(win, msg)
  WindowPtr win;
  char *msg;
{
  int msgW, msgH;
  Rect r;
  char dummy;
  long oldRefCon;

  /* cursNorm(); */
  BeginUpdate(win);
  oldRefCon = ((WindowPeek) win)->refCon;
  ((WindowPeek) win)->refCon = (long) msg;
  myWprintLines(win, msg, MSGX, MSGY, &msgW, &msgH);
  dummy = MainEvent(mouseDown);
  r.top = MSGY - TXHGHT + 4;
  r.left = MSGX;
  r.bottom = r.top + msgH;
  r.right = r.left + msgW;
  EraseRect(&r);
  ((WindowPeek) win)->refCon = oldRefCon;
  /* cursPop(); */
  EndUpdate(win);
  Scistring( " j'envoie un message \n");
}

AddText(x, y, s)	/* Just put a string on screen */
  int x, y;
  char *s;	/* null terminated */
{
  TextFont(4);			/* Monaco */
  TextSize(9);			/* 9 pt   */
  MoveTo(x, y);			/* Add text label in top left of unit */
  CtoPstr(s);
  DrawString(s);
  PtoCstr(s);
}

int MainEvent(int waitforevent)
{
  EventRecord myEvent;
  WindowPtr whichWindow;
  Rect r;
  int done = 0;
  SystemTask();
  /* Debugger();	 */
  do
    {
      if (GetNextEvent(everyEvent, &myEvent))
	{
	  done = 0;
	  switch (myEvent.what)
	    {
	    case mouseDown:
	      switch (FindWindow(myEvent.where, &whichWindow))
		{
		case inDesk:
		  SysBeep(10L);
		  SysBeep(10L);
		  break;
		  /* case inGoAway: if (ours(whichWindow)) if (TrackGoAway(
		   * whichWindow, myEvent.where) ) DoFile(fmClose); break; */
		case inMenuBar:
		  Scistring("in menu bar \n");
		  AdjustMenus();
		  HandleMenu(MenuSelect(myEvent.where));
		  Scistring("out menu bar \n");
		  break;
		case inSysWindow:
		  SystemClick(&myEvent, whichWindow);
		  break;
		case inDrag:
		  if (ours(whichWindow))
		    {
		      Scistring( " Trying to drag The Window\n");
		      Scistring( " OK Going on \n");
		       DragWindow(whichWindow, myEvent.where, &dragRect);
		    }
		  break;
		case inGrow:
		  if (ours(whichWindow))
		    {
		    	Scistring( " Enlarging a Graphic Window\n");
		    	MyGrowWindow(whichWindow, myEvent.where);
		    		}
		  break;
		case inContent:
		  if (whichWindow != FrontWindow())
		    SelectWindow(whichWindow);
		  else if (ours(whichWindow))
		    Scistring( " Docontent on  a Graphic Window\n");
		    /* DoContent(whichWindow, &myEvent);*/
		    done = 1;
		  break;
		default:
		  break;
		}			
	      /* end switch FindWindow	 */
	      break;
	    case keyDown:
	    case autoKey:
	      /* { register char	theChar;
	       * 
	       * theChar = myEvent.message & charCodeMask; if ((myEvent.modifiers &
	       * cmdKey) != 0) return( DoCommand( MenuKey( theChar ) )); else{
	       * ShowSelect(); dirty = 1; } }	 */
	      done = 1;		/* that will do */
	      break;
	    case activateEvt:
	      if (ours(whichWindow = (WindowPtr) myEvent.message))
		{
		  r = (*whichWindow).portRect;
		  r.top = r.bottom - (SBarWidth + 1);
		  r.left = r.left - (SBarWidth + 1);
		  InvalRect(&r);
		  if (myEvent.modifiers & activeFlag)
		    {
		      /* ShowControl( vScroll ); */
		      /* DisableItem( myMenus[editM], undoCommand ); */
		    } else
		      {
			/* HideControl( vScroll ); */
			ZeroScrap();
		      }
		}
	      break;
	    case updateEvt:
	      if (ours(whichWindow = (WindowPtr) myEvent.message))
		{
		  Scistring( " Trying to Update \n");
		  UpdateWindow(whichWindow);
		  done = 1;
		}
	      break;
	    default:
	      Scistring( " defaut : Nothing done \n");
	      break;
	      ;
	    }				/* end of case myEvent.what */
	}
    } while (done == 0 || myEvent.what != waitforevent);
  return (myEvent.what);
}

RegWin(WindowPtr w)
{
  int i;

  for (i = 0; i < MAXWIN; ++i)
    if (ourWins[i] == NULL)
    {
      ourWins[i] = w;
      i = MAXWIN;
    }
}

RmvWin(WindowPtr w)
{
  int i;

  for (i = 0; i < MAXWIN; ++i)
    if (ourWins[i] == w)
    {
      ourWins[i] = NULL;
      i = MAXWIN;
    }
}

int ours(WindowPtr w)
{
  int i;
  int rc = 0;

  for (i = 0; i < MAXWIN; ++i)
    if (ourWins[i] == w)
    {
      rc = 1;
      i = MAXWIN;
    }
  return (rc);
}