home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / BlobMgr / Library Folder / Transaction.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-25  |  2.8 KB  |  128 lines  |  [TEXT/KAHL]

  1. /* ---------------------------------------------------------------------- */
  2. /*                        Blob Transaction Routines                        */
  3. /* ---------------------------------------------------------------------- */
  4.  
  5.  
  6. # include    "BlobMgr.h"
  7.  
  8.  
  9. /*
  10.  * If the blob has a blob glued to its drag area, dissociate the glued blob.
  11.  * Redraw the drag area.    Decrement the use count of the glued blob,
  12.  * undimming it if necessary.
  13.  */
  14.  
  15. pascal void
  16. UnglueGlob (BlobHandle b)
  17. {
  18. BlobHandle    g;
  19.  
  20.     g = (**b).glob;
  21.     if (g != nil)            /* skip if don't really have glued blob */
  22.     {
  23.         (**b).glob = nil;
  24.         DrawBlob (b, inDragBlob);
  25.         DecBlobGlue (g);    /* dec use count and undim if necessary */
  26.     }
  27. }
  28.  
  29.  
  30. pascal void
  31. UnglueGlobSet (BlobSetHandle bSet)
  32. {
  33.     BlobLoopProc1 (&UnglueGlob, bSet);
  34. }
  35.  
  36.  
  37. /*
  38.  * Glue donor blob d to receptor r.    Redraw the drag area of r.
  39.  * Increment the use count of d, dimming it if necessary.    If r
  40.  * already has a glue blob, unglue it first (undimming if necessary).
  41.  */
  42.  
  43. pascal void
  44. GlueGlob (BlobHandle d, BlobHandle r)
  45. {
  46. BlobHandle    g;
  47.  
  48.     g = (**r).glob;                    /* currently glued blob */
  49.     if (g != d)                        /* ignore if has a glob and it's same */
  50.     {
  51.         if (g != nil)                /* if it has a glob already, then */
  52.             DecBlobGlue (g);        /* detach and undim if necessary */
  53.         (**r).glob = d;
  54.         IncBlobGlue (d);            /* increment use and dim if necessary */
  55.         DrawBlob (r, inDragBlob);    /* now have source in drag area - redraw */
  56.     }
  57. }
  58.  
  59.  
  60. /*
  61.  * Transfer a glued blob from one blob to another (r1 -> r2).    Redraw
  62.  * the drag areas of the blob losing the glued blob, and the one
  63.  * receiving it, but the use count of the transferred blob does not
  64.  * change, so it's not necessary to redraw it.
  65.  */
  66.  
  67. pascal void
  68. TransferGlob (BlobHandle r1, BlobHandle r2)
  69. {
  70. BlobHandle    g1, g2;
  71.  
  72.     if (r1 != r2)                /* ignore unless different */
  73.     {
  74.         g1 = BGlob (r1);
  75.         g2 = BGlob (r2);
  76.         if (g1 != nil)            /* can't transfer if nothing there! */
  77.         {
  78.             (**r1).glob = nil;    /* detach and redraw drag area */
  79.             DrawBlob (r1, inDragBlob);
  80.             if (g2 != nil)        /* toss this first if something there */
  81.                 DecBlobGlue (g2);    /* undim if necessary */
  82.             (**r2).glob = g1;
  83.             DrawBlob (r2, inDragBlob);    /* new donor in drag area - redraw */
  84.         }
  85.     }
  86. }
  87.  
  88.  
  89. /*
  90.  * Swap the globs glued to r1 and r2.  If one of them doesn't actually
  91.  * have a glob, this is equivalent to a transfer.
  92.  */
  93.  
  94. pascal void
  95. SwapGlob (BlobHandle r1, BlobHandle r2)
  96. {
  97. BlobHandle    g1, g2;
  98.  
  99.     if (r1 != r2)                /* ignore unless different */
  100.     {
  101.         g1 = (**r1).glob;
  102.         g2 = (**r2).glob;
  103.         if (g1 != g2)            /* ignore if both have same glob */
  104.         {
  105.             (**r1).glob = g2;
  106.             (**r2).glob = g1;
  107.             DrawBlob (r1, inDragBlob);
  108.             DrawBlob (r2, inDragBlob);
  109.         }
  110.     }
  111. }
  112.  
  113.  
  114. /*
  115.  * Glue the glob that's glued to r1 onto r2 as well.  No check
  116.  * is made whether it's really gluable another time or not.
  117.  */
  118.  
  119. pascal void
  120. DupGlob (BlobHandle r1, BlobHandle r2)
  121. {
  122. BlobHandle    g;
  123.  
  124.     if ((g = BGlob (r1)) != nil)
  125.         GlueGlob (g, r2);    /* duplicate blob */
  126. }
  127.  
  128.