home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-02-03 | 8.6 KB | 264 lines | [TEXT/KAHL] |
- //-- Window.c --//
-
- // Generic window management routines.
-
- // The window management routines to create and distroy drawing windows and their data
- // structures, to redraw windows, and to append lines to the window line buffer, as well
- // to managing scrolling and such. This is the total of all the routines to manage windows.
- // This also contains the code to manage the project window as such. */
-
- #include <stdio.h>
- #include "struct.h"
- #include "res.h"
- #include "error.h"
-
- //-- GLOBALS --//
-
- //-- The globals used for the window structure.
-
- struct DrawWindow *drawList;
- static struct DrawWindow *whichScroll; // What window is being scrolled?
- Rect openSize;
- extern unsigned char MultiWidget; // State flags.
-
- //-- CODE --//
-
- //-- The different routines
-
- //-- Basic allocation/deallocation of windows.
-
- //-- AllocateWindow --//
-
- //-- This allocs a new window.
- //-- WARNING: Errors are returned using the 'Throw' mechanism.
-
- struct DrawWindow *AllocateWindow()
- {
- int i;
-
- for (i = 0; i < MAXWINDOWS; i++) if (drawList[i].inuse == 0) break;
- if (i == MAXWINDOWS) Throw(OUTWINDOWS);
-
- drawList[i].inuse = 1;
- openSize.top = 38 + i * 20;
- openSize.left = 30 - i * 3;
- openSize.right = -i * 3;
- openSize.bottom = - 10;
- if (MultiWidget) openSize.right -= 75;
- return &(drawList[i]);
- }
-
-
- //-- FreeWind
-
- // This frees a window. Only do this AFTER disposing of the window.
-
- FreeWind(w)
- struct DrawWindow *w;
- {
- w->inuse = 0;
- }
-
- //-- Basic window math. --//
-
- //-- CalcScroll --//
-
- // Given a window, this computes where the scroll bars are to go..
-
- CalcScroll(w,x,y)
- WindowPtr w;
- Rect *x,*y;
- {
- Rect r;
-
- r = w->portRect;
- x->top = r.bottom - 15;
- x->bottom = r.bottom + 1;
- x->right = r.right - 14;
- x->left = -1;
-
- y->top = -1;
- y->bottom = r.bottom - 14;
- y->left = r.right - 15;
- y->right = r.right + 1;
- }
-
-
- //-- CalcClip --//
-
- // Calculate the clip area of the window (where to draw, which doesn't include scroll
- // bars.
-
- CalcClip(w,c)
- WindowPtr w;
- Rect *c;
- {
- Rect r;
-
- r = w->portRect;
- c->top = r.top;
- c->left = r.left;
- c->right = r.right - 15;
- c->bottom = r.bottom - 15;
- }
-
- //-- Window management. --//
-
-
- //-- NewPlan --//
-
- // Open a new window.
-
- struct DrawWindow *NewPlan(name)
- short name; /* vRefNum of this object */
- {
- int i;
- struct DrawWindow *w;
- short step;
- GrafPtr foo;
- Rect r;
- Rect s;
- int t;
-
- // Step 1: Prepare for disaster.
-
- step = 1;
- if (i = Catch()) {
-
- // According to the step number, do the appropriate shutting down.
-
- switch (step) {
- case 2:
- CloseWindow(w);
- FreeWind(w);
- case 1:
- break;
- }
-
- // Post the error message, and return.
-
- PostError(i);
- return NULL;
- }
-
- // Step 2: Allocate and open the window.
-
- w = AllocateWindow();
- GetWMgrPort(&foo);
- r = foo->portRect;
- r.right += openSize.right;
- r.bottom += openSize.bottom;
- r.top = openSize.top;
- r.left = openSize.left;
- InsetRect(&r,4,4);
- NewWindow(w,&r,"\pUntitled",1,8,(char *)-1,CanEject(name),0L);
- step = 2;
-
- /*
- * Step 3: Initialize different data structures
- */
-
- w->state = 0; /* Directories only */
- w->w.windowKind = WK_PLAN;
- ComputePict(name,w);
-
- CalcScroll(w,&r,&s);
- if (NULL == (w->yScroll = NewControl(w,&s,"",1,0,0,0,16,0L)))
- Throw(OUTMEM);
-
- t = (GetHandleSize(w->data) / sizeof(struct DirectData)) - 1;
- if (t < 0) t = 0;
- SetCtlMax(w->yScroll,t);
-
- // All done. Return.
-
- Uncatch();
- return w;
- }
-
-
-
-
- //-- ClosePlan --//
-
- // What to do when the 'close' option is selected for a particular plan.
-
-
- int ClosePlan(w)
- struct DrawWindow *w;
- {
-
- // Dispose of the window and quit.
-
- if (!CanEject(w->vRefNum)) return 0; /* Failure */
- Eject("",w->vRefNum);
- UnmountVol("",w->vRefNum);
- DisposHandle(w->data);
- CloseWindow(w);
- FreeWind(w);
- return 1; /* Success */
- }
-
-
-
- //-- UpdatePlan --//
-
- // This updates the plan (redraws the contents of the window).
-
- UpdatePlan(w)
- struct DrawWindow *w;
- {
- DrawGrowIcon(w);
- DrawControls(w);
- DrawPlanWind(w);
- }
-
-
-
- //-- DrawPlanWind --//
-
- // Actually draw the contents of this drawing window.
-
- DrawPlanWind(w)
- struct DrawWindow *w;
- {
- int x,y;
- Rect r;
- RgnHandle rgn;
- Rect s;
- long l,i;
- struct DirectData *ptr;
- short ind;
-
- //-- Properly initialize clipping for redrawing the screen
-
- SetPort(w);
- CalcClip(w,&r);
- rgn = NewRgn();
- GetClip(rgn);
- ClipRect(&r);
-
- //-- Draw the contents of the screen
-
- HLock(w->data);
- ptr = *(w->data);
- TextFont(4);
- TextSize(9);
- y = GetCtlValue(w->yScroll);
- l = GetHandleSize(w->data) / sizeof(struct DirectData);
- for (i = y, x = 12; i < l; i++, x += 12) {
- for (ind = 0; ind < ptr[i].indent; ind++) {
- MoveTo(ind*12+15,x-10);
- Line(0,12);
- }
- Move e 4:
- case 5:
- case 6:
- SetBtn(dlog,4+nv,0);
- nv = x - 4;
- SetBtn(dlog,4+nv,1);
- break;
- }
- }
- }
-