home *** CD-ROM | disk | FTP | other *** search
/ Executor 2.0 / executorv2.0.iso / pc / dos / extra / source / browser / browser.hqx / Browser / iconmanip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-28  |  8.1 KB  |  306 lines

  1. #include "go.h"
  2. #include "xfer.h"
  3. #include "display.h"
  4.  
  5. #include "getrects.proto.h"
  6. #include "iconmanip.proto.h"
  7. #include "initdirs.proto.h"
  8. #include "inithotband.proto.h"
  9. #include "misc.proto.h"
  10. #include "sharedtransfer.proto.h"
  11. #include "update.proto.h"
  12.  
  13. CCrsrHandle g_movecursor, g_copycursor;
  14.   
  15. enum
  16.   {
  17.     BIG_RECT_LEFT = -20000,
  18.     BIG_RECT_TOP = -20000,
  19.     BIG_RECT_RIGHT = 20000,
  20.     BIG_RECT_BOTTOM = 20000
  21.   };
  22.  
  23. void
  24. xorrectframe (icondraginfo ** h)
  25. {
  26.   GrafPtr wport, saveport;
  27.   PenState ps;
  28.   RgnHandle rgn, savergn;
  29.   unsigned char state;
  30.  
  31.   if (h == (icondraginfo **) 0 || (*h)->x == -1)
  32.     return;
  33.   rgn = NewRgn ();
  34.   savergn = NewRgn ();
  35.   GetPort (&saveport);
  36.   GetWMgrPort (&wport);
  37.   SetPort (wport);
  38.   GetPenState (&ps);
  39.   PenMode (patXor);
  40.   SetRectRgn (rgn, BIG_RECT_LEFT, BIG_RECT_TOP, BIG_RECT_RIGHT,
  41.           BIG_RECT_BOTTOM);
  42.   GetClip (savergn);
  43.   SetClip (rgn);
  44.   state = HGetState ((Handle) h);
  45.   HLock ((Handle) h);
  46.   OffsetRect (&(*h)->iconrect, (*h)->x, (*h)->y);
  47.   FrameRect (&(*h)->iconrect);
  48.   OffsetRect (&(*h)->iconrect, -(*h)->x, -(*h)->y);
  49.   OffsetRect (&(*h)->textrect, (*h)->x, (*h)->y);
  50.   FrameRect (&(*h)->textrect);
  51.   OffsetRect (&(*h)->textrect, -(*h)->x, -(*h)->y);
  52.   HSetState ((Handle) h, state);
  53.   SetClip (savergn);
  54.   SetPenState (&ps);
  55.   SetPort (saveport);
  56.   DisposeRgn (rgn);
  57.   DisposeRgn (savergn);
  58. }
  59.  
  60. short
  61. cleanupdrag (Point p, ControlHandle c)
  62. {
  63.   WindowPtr wp;
  64.   short part;
  65.   ControlHandle curc;
  66.  
  67.   xorrectframe ((icondraginfo **) (*c)->contrlRfCon);
  68.   DisposeHandle ((Handle) (*c)->contrlRfCon);
  69.   (*c)->contrlRfCon = 0L;
  70.  
  71.   FindWindow (p, &wp);
  72.   if (wp == (WindowPtr) 0)
  73. /*-->*/ return 0;
  74.  
  75.   SetPort (wp);
  76.   GlobalToLocal (&p);
  77.   part = FindControl (p, wp, &curc);
  78.   return c == curc ? part : 0;
  79. }
  80.  
  81. void
  82. updateoutline (Point p, ControlHandle startc, ControlHandle * nextc)
  83. {
  84.   icondraginfo **h;
  85.   short infoexists, part;
  86.   Rect *r;
  87.   WindowPtr wp;
  88.   Point local_p;
  89.   unsigned char state;
  90.  
  91.   infoexists = ((*startc)->contrlRfCon != 0L);
  92.   FindWindow (p, &wp);
  93.   
  94.   if (wp)
  95.     {
  96.       SetPort (wp);
  97.       GlobalToLocal (&p);
  98.     }
  99.   local_p = p;
  100.   part = FindControl (p, wp, nextc);
  101.   if (wp)
  102.     LocalToGlobal (&p);
  103.   if (startc != *nextc)
  104.     {
  105.       if (!infoexists)
  106.     {
  107.       (*startc)->contrlRfCon = (long) NewHandle (sizeof (icondraginfo));
  108.       h = (icondraginfo **) (*startc)->contrlRfCon;
  109.       state = HGetState ((Handle) h);
  110.       HLock ((Handle) h);
  111.       getrects (startc, &(*h)->textrect, &(*h)->iconrect);
  112.       r = &(*h)->iconrect;
  113.       if (EmptyRect (r))
  114.         OffsetRect (&(*h)->textrect, -local_p.h, -(*h)->textrect.top);
  115.       else
  116.         OffsetRect (&(*h)->textrect, -r->left, -r->top);
  117.       OffsetRect (&(*h)->iconrect, -r->left, -r->top);
  118.       (*h)->x = -1;
  119.       (*h)->y = -1;
  120.       HSetState ((Handle) h, state);
  121.     }
  122.       else
  123.     h = (icondraginfo **) (*startc)->contrlRfCon;
  124.       if ((*h)->x != p.h || (*h)->y != p.v)
  125.     {
  126.       xorrectframe (h);
  127.       (*h)->x = p.h;
  128.       (*h)->y = p.v;
  129.       xorrectframe (h);
  130.     }
  131.     }
  132.   else if (infoexists)
  133.     {
  134.       h = (icondraginfo **) (*startc)->contrlRfCon;
  135.       xorrectframe (h);
  136.       (*h)->x = -1;
  137.       (*h)->y = -1;
  138.     }
  139.   if (wp == g_hotband && *nextc == (ControlHandle) 0)
  140.     {
  141.       SetCCursor (g_copycursor);
  142.     }
  143.   else if (*nextc != (ControlHandle) 0 && *nextc != startc &&
  144.        (*(item **) (**nextc)->contrlData)->action == OPENDIR)
  145.     {
  146. /* Todo: check for option key being held down */
  147.       if ((*(item **) (**nextc)->contrlData)->vrefnum ==
  148.       (*(item **) (*startc)->contrlData)->vrefnum &&
  149.       (*startc)->contrlOwner != g_hotband)
  150.     SetCCursor (g_movecursor);
  151.       else
  152.     SetCCursor (g_copycursor);
  153.     }
  154.   else if (*nextc == (ControlHandle) 0 && wp != 0 &&
  155.        wp != (*startc)->contrlOwner)
  156.     {
  157.       if ((*(opendirinfo **) ((WindowPeek) wp)->refCon)->vrefnum ==
  158.       (*(item **) (*startc)->contrlData)->vrefnum &&
  159.       (*startc)->contrlOwner != g_hotband)
  160.     SetCCursor (g_movecursor);
  161.       else
  162.     SetCCursor (g_copycursor);
  163.     }
  164.   else
  165. #ifdef THINK_C
  166.     SetCursor (&arrow);
  167. #else
  168.     SetCursor (&qd.arrow);
  169. #endif
  170. }
  171.  
  172. short
  173. followcontrol (ControlHandle c, short startpart)
  174. {
  175.   EventRecord ev;
  176.   short part, selected;
  177.   ControlHandle lastc, nextc;
  178.   WindowPtr wp, saveport;
  179.   item **ih1, **ih2;
  180.   opendirinfo **dirinfoh;
  181.   CInfoPBRec pb;
  182.   unsigned char state;
  183.   long flags;
  184.   Str255 save_ctl_title;
  185.       
  186.   mystr255copy (save_ctl_title, (*c)->contrlTitle);
  187.   GetPort (&saveport);
  188.   selected = (*(item **) (*c)->contrlData)->selected;
  189.   lastc = (ControlHandle) 0;
  190.   nextc = (ControlHandle) - 1;
  191.   while (!GetNextEvent (mUpMask, &ev))
  192.     {
  193.       updateoutline (ev.where, c, &nextc);
  194.       if (lastc != nextc)
  195.     {
  196.       if (lastc != (ControlHandle) 0)
  197.         {
  198.           xorrectframe ((icondraginfo **) (*c)->contrlRfCon);
  199.           HiliteControl (lastc, 0);
  200.           xorrectframe ((icondraginfo **) (*c)->contrlRfCon);
  201.         }
  202.       if (nextc != 0)
  203.         {
  204.           if (nextc == c)
  205.         HiliteControl (c, selected ? INSELECTEDICON : inButton);
  206.           else if ((*(item **) (*nextc)->contrlData)->action == OPENDIR)
  207.         {
  208.           xorrectframe ((icondraginfo **) (*c)->contrlRfCon);
  209.           HiliteControl (nextc, inButton);
  210.           xorrectframe ((icondraginfo **) (*c)->contrlRfCon);
  211.         }
  212.         }
  213.     }
  214.       lastc = nextc;
  215.     }
  216.   part = cleanupdrag (ev.where, c);
  217.   if (lastc != 0)
  218.     {
  219.       HiliteControl (lastc, 0);
  220.       wp = (*c)->contrlOwner;
  221.       ih1 = (item **) (*c)->contrlData;
  222.       ih2 = (item **) (*lastc)->contrlData;
  223.       if ((*ih2)->action == OPENDIR && lastc != c)
  224.     {
  225.       state = HGetState ((Handle) lastc);
  226.       HLock ((Handle) lastc);
  227.       pb.dirInfo.ioNamePtr = (*lastc)->contrlTitle;
  228.       pb.dirInfo.ioVRefNum = (*ih2)->vrefnum;
  229.       pb.dirInfo.ioFDirIndex = 0;
  230.       pb.dirInfo.ioDrDirID = (*ih2)->ioparid;
  231.       PBGetCatInfo (&pb, false);
  232.       HSetState ((Handle) lastc, state);
  233.       if (wp == g_hotband || ((*ih2)->vrefnum != ((*ih1)->vrefnum)))
  234.         {
  235.           if (!commontrans ((*ih1)->ioparid, pb.dirInfo.ioDrDirID, (*ih1)->vrefnum,
  236.                  (*ih2)->vrefnum, save_ctl_title, &flags, copy1file))
  237.         {
  238.           if (flags & FILE_REPLACED_BIT)
  239.             changewindow (save_ctl_title, pb.dirInfo.ioDrDirID, (*ih2)->vrefnum, removefromlist);
  240.           changewindow (save_ctl_title, pb.dirInfo.ioDrDirID, (*ih2)->vrefnum, updatemove);
  241.         }
  242.         }
  243.       else
  244.         {
  245.           if (!commontrans ((*ih1)->ioparid, pb.dirInfo.ioDrDirID, (*ih1)->vrefnum,
  246.                  (*ih2)->vrefnum, save_ctl_title, &flags, move1file))
  247.         {
  248.           changehot (c, pb.dirInfo.ioDrDirID, (*ih2)->vrefnum);
  249.           changewindow (save_ctl_title, (*ih1)->ioparid, (*ih1)->vrefnum, removefromlist);
  250.           if (flags & FILE_REPLACED_BIT)
  251.             changewindow (save_ctl_title, pb.dirInfo.ioDrDirID, (*ih2)->vrefnum, removefromlist);
  252.           changewindow (save_ctl_title, pb.dirInfo.ioDrDirID, (*ih2)->vrefnum, updatemove);
  253.         }
  254.         }
  255.     }
  256.     }
  257.   else if (nextc != (ControlHandle) - 1)
  258.     {
  259.       FindWindow (ev.where, &wp);
  260.       if (wp == g_hotband)
  261.     {
  262.       if ((*c)->contrlOwner != wp)
  263.         copycontroltohotband (c);
  264.     }
  265.       else if (wp != 0 && wp != (*c)->contrlOwner)
  266.     {
  267.       dirinfoh = (opendirinfo **) ((WindowPeek) wp)->refCon;
  268.       ih1 = (item **) (*c)->contrlData;
  269.       if ((*dirinfoh)->vrefnum != ((*ih1)->vrefnum))
  270.         {
  271.           if (!commontrans ((*ih1)->ioparid, (*dirinfoh)->iodirid, (*ih1)->vrefnum,
  272.             (*dirinfoh)->vrefnum, save_ctl_title, &flags, copy1file))
  273.         {
  274.           if (flags & FILE_REPLACED_BIT)
  275.             changewindow (save_ctl_title, (*dirinfoh)->iodirid, (*dirinfoh)->vrefnum, removefromlist);
  276.           changewindow (save_ctl_title, (*dirinfoh)->iodirid, (*dirinfoh)->vrefnum, updatemove);
  277.         }
  278.         }
  279.       else
  280.         {
  281.           if (!commontrans ((*ih1)->ioparid, (*dirinfoh)->iodirid, (*ih1)->vrefnum,
  282.             (*dirinfoh)->vrefnum, save_ctl_title, &flags, move1file))
  283.         {
  284.           changehot (c, (*dirinfoh)->iodirid, (*dirinfoh)->vrefnum);
  285.           changewindow (save_ctl_title, (*ih1)->ioparid, (*ih1)->vrefnum, removefromlist);
  286.           if (flags & FILE_REPLACED_BIT)
  287.             changewindow (save_ctl_title, (*dirinfoh)->iodirid, (*dirinfoh)->vrefnum, removefromlist);
  288.           changewindow (save_ctl_title, (*dirinfoh)->iodirid, (*dirinfoh)->vrefnum, updatemove);
  289.         }
  290.         }
  291.     }
  292.       else
  293.     {
  294.       if ((*c)->contrlOwner == g_hotband && g_currentband != VOLBAND)
  295.         removeitemfromhotband (c);
  296.     }
  297.     }
  298. #ifdef THINK_C
  299.   SetCursor (&arrow);
  300. #else
  301.   SetCursor (&qd.arrow);
  302. #endif
  303.   return startpart == part ? part : 0;
  304.   SetPort (saveport);
  305. }
  306.