home *** CD-ROM | disk | FTP | other *** search
/ Executor 2.0 / executorv2.0.iso / pc / dos / extra / source / browser / browser.hqx / Browser / window.c < prev   
Encoding:
C/C++ Source or Header  |  1995-11-05  |  4.6 KB  |  200 lines

  1. #include <Windows.h>
  2. #include "go.h"
  3. #include "display.h"
  4.  
  5. #include "window.proto.h"
  6. #include "init.proto.h"
  7. #include "initdirs.proto.h"
  8. #include "initicons.proto.h"
  9. #include "misc.proto.h"
  10. #include "menu.proto.h"
  11. #include "view.proto.h"
  12. #include "mouse.proto.h"
  13.  
  14. #include "windlist.h"
  15.  
  16. void
  17. setwindowicons (CWindowPeek wp)
  18. {
  19.   ControlHandle c;
  20.   opendirinfo **infoh;
  21.  
  22.   infoh = (opendirinfo **) wp->refCon;
  23.   for (c = wp->controlList; c != 0; c = (*c)->nextControl)
  24.     {
  25.       if (c != (*infoh)->sbar)
  26.     {
  27.       setoneicon (c);
  28.       ShowControl (c);
  29.     }
  30.     }
  31. }
  32.  
  33. int
  34. executor_p (void)
  35. {
  36.   return *(long *) 0x5c != *(long *) 0x58;
  37. }
  38.  
  39. static void
  40. make_at_least (short n, short *valp)
  41. {
  42.   if (*valp < n)
  43.     *valp = n;
  44. }
  45.  
  46. #define FRAME_HEIGHT 20
  47.  
  48. static void
  49. adjust_zoom_rect (CWindowPeek wp)
  50. {
  51.   WStateDataHandle wh;
  52.   
  53.   wh = (WStateDataHandle) wp->dataHandle;
  54.   make_at_least (HOTBANDBOTTOM + FRAME_HEIGHT + 2, &(*wh)->userState.top);
  55.   make_at_least (HOTBANDBOTTOM + FRAME_HEIGHT + 2, &(*wh)->stdState.top);
  56. }
  57.  
  58. static void
  59. watch_cursor (void)
  60. {
  61.   static CursHandle watch_cursorh = 0;
  62.   
  63.   if (!watch_cursorh)
  64.     watch_cursorh = GetCursor (watchCursor);
  65.   SetCursor (*watch_cursorh);
  66. }
  67.  
  68. static void
  69. arrow_cursor (void)
  70. {
  71.   SetCursor (&arrow);
  72. }
  73.  
  74. CWindowPtr
  75. createdirwindow (CInfoPBRec *dir, Rect *r, char **path, short volume)
  76. {
  77.   CWindowPeek wp;
  78.   short i;
  79.   OSErr e;
  80.   Str255 s;
  81.   opendirinfo **infoh;
  82.   ControlHandle c;
  83.  
  84.   watch_cursor ();
  85.   if (executor_p ())
  86.     {
  87.       CInfoPBRec cpb;
  88.       OSErr e2;
  89.  
  90.       cpb = *dir;
  91.       e2 = unixmount (&cpb);
  92.       if (e2 == noErr)
  93.     volume = cpb.hFileInfo.ioVRefNum;
  94.     }
  95.   tail (*path, s);
  96.   wp = (CWindowPeek) NewPtr (sizeof (CWindowRecord));
  97.   wp = (CWindowPeek) NewCWindow (wp, r, s, false, documentProc+zoomDocProc, (WindowPtr) 0, true, 0);
  98.   adjust_zoom_rect (wp);
  99.   add_browser_window ((WindowPtr) wp);
  100.   wp->refCon = (long) NewHandle (sizeof (opendirinfo));
  101.  
  102.   infoh = (opendirinfo **) wp->refCon;
  103. #if 1
  104. /* This handle should be unlocked later, but it isn't for Executor 1.99m */
  105.   HLock ((Handle) infoh);
  106. #endif /* 0 */
  107.   (*infoh)->sortorder = ALPHABETIC;
  108.   (*infoh)->items = (ControlHandle (**)[])
  109.     NewHandle (BANDARRAYSIZE * sizeof (ControlHandle));
  110.   (*infoh)->path = path;
  111.   (*infoh)->iodirid = dir->dirInfo.ioDrDirID;
  112.   (*infoh)->vrefnum = volume;
  113.   (*infoh)->numitems = 0;
  114.   (*infoh)->view = ICONVIEW;
  115.  
  116. /* NOTE: r is the wrong rectangle, but it gets fixed before it's used. */
  117.   (*infoh)->sbar = NewControl ((WindowPtr) wp, r, (StringPtr) "\p", false, 0, 0, 0,
  118.                    scrollBarProc, 0);
  119.   MoveControl ((*infoh)->sbar, wp->port.portRect.right - SCROLLBARWIDTH, 0);
  120.  
  121.   dir->hFileInfo.ioNamePtr = s;
  122.   dir->hFileInfo.ioVRefNum = volume;
  123.   e = noErr;
  124.   for (i = 1; e == noErr; i++)
  125.     {
  126.       checkgrowitemarray (i, (*infoh)->items);
  127.       dir->hFileInfo.ioDirID = (*infoh)->iodirid;
  128.       dir->hFileInfo.ioFDirIndex = i;
  129.       e = PBGetCatInfo (dir, false);
  130.       if (e == noErr && !(dir->hFileInfo.ioFlFndrInfo.fdFlags & fInvisible))
  131.     {
  132.       c = addtolist ((WindowPeek) wp, s, dir->hFileInfo.ioFlParID, volume);
  133.       if (dir->hFileInfo.ioFlFndrInfo.fdType == 'APPL' ||
  134.           dir->hFileInfo.ioFlFndrInfo.fdType == 'dfil')
  135.         hashicons (c);
  136.     }
  137.     }
  138.   setwindowicons (wp);
  139.   sortwin ((WindowPtr) wp, namecmp, ALPHABETIC);
  140.   straightenwindow ((WindowPtr) wp);
  141.   arrow_cursor ();
  142.   return (CWindowPtr) wp;
  143. }
  144.  
  145. void
  146. dodragwin (Point start, WindowPtr wp)
  147. {
  148.   Rect r;
  149.  
  150.   SetRect (&r, 4, HOTBANDBOTTOM + 4 + start.v -
  151.        (*((WindowPeek) wp)->strucRgn)->rgnBBox.top,
  152.        qd.screenBits.bounds.right - 4, qd.screenBits.bounds.bottom - 4);
  153.   DragWindow (wp, start, &r);
  154. }
  155.  
  156. void
  157. dogrowwin (Point start, WindowPtr wp)
  158. {
  159.   Rect r;
  160.   long newsize;
  161.  
  162. /* todo: find out what is normally done when there is no maximum size that needs to be enforced */
  163.   SetRect (&r, ICONWIDTHUSED, 2 * ICONHEIGHTUSED, 32767, 32767);
  164.   newsize = GrowWindow (wp, start, &r);
  165.   SizeWindow (wp, LoWord (newsize), HiWord (newsize), true);
  166.   InvalRect (&wp->portRect);
  167.   straightenwindow (wp);
  168. }
  169.  
  170. void
  171. disposedirwindow (WindowPtr wp)
  172. {
  173.   SendBehind (g_hotband, (WindowPtr) 0);
  174.   if ((**g_selection)[0] != 0 && (*(**g_selection)[0])->contrlOwner == wp)
  175.     replaceselected((ControlHandle) 0);
  176.   DisposHandle ((*(opendirinfo **) ((WindowPeek) wp)->refCon)->path);
  177.   remove_browser_window (wp);
  178.   DisposeWindow (wp);
  179.   showviewmenu (FrontWindow () != g_hotband);
  180. }
  181.  
  182. void
  183. dogoaway (Point start, WindowPtr wp)
  184. {
  185.   if (TrackGoAway (wp, start))
  186.     disposedirwindow (wp);
  187. }
  188.  
  189. void
  190. do_zoom (short part, Point start, WindowPtr wp)
  191. {
  192.   if (TrackBox (wp, start, part))
  193.     {
  194.       SetPort (wp);
  195.       ZoomWindow (wp, part, TRUE);
  196.       EraseRect (&wp->portRect);
  197.       InvalRect (&wp->portRect);
  198.       straightenwindow (wp);
  199.     }
  200. }