home *** CD-ROM | disk | FTP | other *** search
- # include "BlobMgr.h"
-
-
- # define New(typename) (typename **) NewHandle ((Size) sizeof (typename))
-
- /*
- * Handle to list of all existing blob sets - empty initially
- */
-
- static BlobSetHandle blobSetMaster = nil;
-
-
- /* ---------------------------------------------------------------------- */
- /* Object Creation Routines */
- /* ---------------------------------------------------------------------- */
-
-
-
- pascal void
- NewBlobMatch (BlobHandle b1, BlobHandle b2)
- {
- MatchHandle m;
-
- m = New (MatchRecord);
- if (m != nil)
- {
- (**m).mBlob = b1;
- (**m).nextMatch = (**b2).matches;
- (**b2).matches = m;
- }
- }
-
-
- /*
- * Add a blob to (the END of) a blob set
- */
-
- pascal void
- AddBlob (BlobHandle b, BlobSetHandle bSet)
- {
- if ((**bSet).firstBlob == (BlobHandle) nil)
- {
- (**bSet).firstBlob = b;
- (**bSet).lastBlob = b;
- }
- else
- {
- (**((**bSet).lastBlob)).nextBlob = b;
- (**bSet).lastBlob = b;
- }
- (**b).nextBlob = (BlobHandle) nil;
- }
-
-
- /*
- * Create a new blob, adding it to the given set. The blob is enabled
- * or not according to the enable parameter. The blob is given empty
- * static and drag regions and rectangles, nil picture, match set, and
- * glob handles. The drawing modes are set according to statDraw
- * and dragDraw. The blob is set to be single-use or not by the
- * glueMax parameter. mustMatch determines whether the blob must
- * have a glue blob to be matched. The refCon is installed in the
- * record.
- */
-
- pascal BlobHandle
- NewBlob (BlobSetHandle bSet, /* set to add blob to */
- Boolean enable, /* whether blob is enabled or not */
- short glueMVal, /* maximum glue count */
- Boolean mustMatch, /* whether must have glob to be matched */
- long refCon) /* reference constant */
- {
- BlobHandle bHand;
- BlobPtr b;
- Rect r;
-
- bHand = New (BlobRecord);
- if (bHand != nil)
- {
- AddBlob (bHand, bSet); /* sets nextBlob field */
- b = *bHand;
- b->flags = 0 | bPicMask; /* clear flags, then set appropriate fields */
- if (enable)
- EnableBlob (bHand);
- if (mustMatch)
- SetBlobFlags (bHand, bNeedGlobMask);
- b->bPicProc.bPic = nil; /* no picture or drawing proc */
- SetRect (&r, 0, 0, 0, 0);
- b->statRect = r; /* empty rects */
- b->dragRect = r;
- b->statRgn = NewRgn (); /* empty regions */
- b->dragRgn = NewRgn ();
- b->glueMax = glueMVal;
- b->glueCount = 0;
- b->glob = nil;
- b->matches = nil;
- b->bRefCon = refCon;
-
- }
- return (bHand);
- }
-
-
- /*
- * Create a new, empty blob set. Add it to the master blob set list.
- * Return a handle to it.
- */
-
- pascal BlobSetHandle
- NewBlobSet (void)
- {
- BlobSetHandle bSet;
-
- bSet = New (BlobSetRecord);
- if (bSet != nil)
- {
- (**bSet).firstBlob = (BlobHandle) nil; /* initialize to empty set */
- (**bSet).lastBlob = (BlobHandle) nil;
- (**bSet).nextBlobSet = blobSetMaster; /* add to master list */
- blobSetMaster = bSet;
- }
-
- return (bSet);
- }
-
-
- /* ---------------------------------------------------------------------- */
- /* Object Disposal Routines */
- /* ---------------------------------------------------------------------- */
-
-
- pascal void
- DisposeBlobPic (BlobHandle b)
- {
- if (PicBlob (b) && (**b).bPicProc.bPic != nil)
- {
- KillPicture ((**b).bPicProc.bPic);
- (**b).bPicProc.bPic = nil;
- }
- }
-
-
- pascal void
- DisposeBlobMatchSet (BlobHandle b)
- {
- MatchHandle m1, m2;
-
- m1 = (**b).matches;
- (**b).matches = nil;
- for (;;)
- {
- if (m1 == nil) return;
- m2 = (**m1).nextMatch;
- DisposeHandle ((Handle) m1);
- m1 = m2;
- }
- }
-
-
- pascal void
- DisposeBlob (BlobHandle b)
- {
- DisposeRgn ((**b).statRgn);
- DisposeRgn ((**b).dragRgn);
- DisposeBlobPic (b);
- DisposeBlobMatchSet (b);
- DisposeHandle ((Handle) b);
- }
-
-
- /*
- * Remove blob set from the master blob set list, then dispose of
- * everything in the list. All handles to the set or elements in
- * it become invalid.
- */
-
- pascal void
- DisposeBlobSet (BlobSetHandle bSet)
- {
- BlobHandle b1, b2;
- BlobSetHandle bSet2;
-
- /*
- * Remove set from master list
- */
- if (bSet == blobSetMaster) /* first set in list */
- blobSetMaster = (**blobSetMaster).nextBlobSet;
- else
- {
- bSet2 = blobSetMaster;
- for (;;)
- {
- if (bSet2 == nil) return; /* set isn't in master list */
- if ((**bSet2).nextBlobSet == bSet) /* found it */
- {
- (**bSet2).nextBlobSet = (**bSet).nextBlobSet;
- break;
- }
- bSet2 = (**bSet2).nextBlobSet; /* try next one */
- }
- }
- /*
- * Toss elements of set
- */
- b1 = (**bSet).firstBlob;
- for (;;)
- {
- if (b1 == nil) break;
- b2 = (**b1).nextBlob;
- DisposeBlob (b1);
- b1 = b2;
- }
- /*
- * Toss set header
- */
- DisposeHandle ((Handle) bSet);
- }
-
-
- /*
- * Dispose of all existing sets. This is the routine to call at
- * the end of the host program to dispose of all Blob Manager
- * structures.
- */
-
- pascal void
- DisposeBlobSets (void)
- {
- for (;;)
- {
- if (blobSetMaster == nil) break; /* no more sets */
- DisposeBlobSet (blobSetMaster); /* changes the master list */
- }
- }
-
-
- /*
- * Delete a blob from a blob list. Should not be done lightly, e.g.,
- * if the blob is some other blob's glob. Check to be sure that the
- * current glueCount is zero first. All handles to the blob become
- * invalid.
- */
-
- pascal void
- ClobberBlob (BlobHandle b, BlobSetHandle bSet)
- {
- BlobHandle b2;
-
- if ((**bSet).firstBlob == b) /* special case - first in list */
- {
- (**bSet).firstBlob = (**b).nextBlob;
- if ((**bSet).lastBlob == b) /* if true, set is now empty */
- (**bSet).lastBlob = nil;
- }
- else
- {
- b2 = (**bSet).firstBlob;
- for (;;)
- {
- if (b2 == nil) return; /* NOT break! */
- if ((**b2).nextBlob == b)
- {
- (**b2).nextBlob = (**b).nextBlob;
- if ((**bSet).lastBlob == b) /* clobbering last one */
- (**bSet).lastBlob = b2; /* back pointer up */
- break;
- }
- b2 = (**b2).nextBlob;
- }
- }
- DisposeBlob (b);
- }
-
-
- /*
- * Delete s from the match set of d
- */
-
- pascal void
- ClobberBlobMatch (BlobHandle b1, BlobHandle b2)
- {
- MatchHandle m1, m2;
-
- m1 = (**b2).matches;
- if (m1 != nil) /* don't look if match set empty */
- {
- if ((**m1).mBlob == b1) /* is it the first one in the list? */
- {
- (**b2).matches = (**m1).nextMatch;
- }
- else /* it's not first one */
- {
- for (;;)
- {
- m2 = (**m1).nextMatch;
- if (m2 == nil) return; /* NOT break! */
- if ((**m2).mBlob == b1) /* found it */
- {
- (**m1).nextMatch = (**m2).nextMatch;
- break;
- }
- m1 = m2;
- }
- }
- DisposeHandle ((Handle) m2);
- }
- }
-