home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / luschsrc.sit / list.c < prev    next >
Text File  |  1990-05-23  |  3KB  |  152 lines

  1. /********************************************************************************
  2.  *    list.c
  3.  *
  4.  *    List Window Management Package
  5.  *
  6.  *    Written by Paco Xander Nathan
  7.  *    ⌐1990, Motorola Inc.  Public domain source code.
  8.  ********************************************************************************/
  9.  
  10. #include "applic.h"
  11. #include "window.h"
  12. #include "list.h"
  13.  
  14. #include "test.h"
  15. #include "gnosis.h"
  16.  
  17.  
  18. /* Create a new window info handle with a list item
  19.  */
  20. WindowPtr
  21. ListWindow (windID, top, left, isActive)
  22.     register short windID;
  23.     register short top, left;
  24.     register Boolean isActive;
  25. {
  26.     register WindowPtr theWindow;
  27.     register InfoPtr infoPtr;
  28.     register ListHandle listHdl;
  29.     static Rect cellBounds = { 0, 0, 1, 3 };
  30.     static Cell cellSize = { (FONTSIZE * 3 / 2), 40 };
  31.     static Cell theCell = { 0, 0 };
  32.     GrafPtr savePort;
  33.  
  34.     if (theWindow = WindAllocate(windID, isActive)) {
  35.         GetPort(&savePort);
  36.         SetPort(theWindow);
  37.     
  38.         /* Set the font attributes and create the List handle
  39.          */
  40.         TextFont(FONTNUM);
  41.         TextSize(FONTSIZE);
  42.         TextFace(0);
  43.         TextMode(srcOr);
  44.     
  45.         infoPtr = (InfoPtr) GetWRefCon(theWindow);
  46.         SetRect(&(infoPtr->offset), top, left, 20, 20);
  47.         infoPtr->kind = wkList;
  48.  
  49.         if (listHdl = infoPtr->item.list = LNew(&(infoPtr->offset), &cellBounds, cellSize, 0, theWindow, TRUE, FALSE, FALSE, TRUE)) {
  50.             /* Place a prompt in the first cell
  51.              */
  52.             HLock(listHdl);
  53.             (*listHdl)->selFlags |= lOnlyOne;
  54.             (*listHdl)->listFlags |= lDoVAutoScroll;
  55.             HUnlock(listHdl);
  56.         
  57.             /* Finally, adjust the window rect dimensions
  58.              */
  59.             ListAdjust(theWindow);
  60.         }
  61.  
  62.         SetPort(savePort);
  63.     }
  64.     
  65.     return theWindow;
  66. }
  67.  
  68.  
  69. /* Resize the list view rect for a list window
  70.  */
  71. void
  72. ListAdjust (theWindow)
  73.     register WindowPtr theWindow;
  74. {
  75.     register InfoPtr infoPtr = (InfoPtr) GetWRefCon(theWindow);
  76.     register Rect view;
  77.     GrafPtr savePort;
  78.     Cell cellSize;
  79.     
  80.     GetPort(&savePort);
  81.     SetPort(theWindow);
  82.  
  83.     /* Resize the list 
  84.      */
  85.     view = theWindow->portRect;
  86.     LSize(view.right - view.left - 15, view.bottom - view.top, infoPtr->item.list);
  87.  
  88.     /* Reset the cell size
  89.      */
  90.     SetPt(&cellSize, (view.right - view.left - 15) / 2, FONTSIZE * 3 / 2);
  91.     LCellSize(cellSize, infoPtr->item.list);
  92.     
  93.     SetPort(savePort);
  94. }
  95.  
  96.  
  97. /* Draw an application window - switch on particular window to draw all the fancy
  98.  * bells and whistles
  99.  */
  100. void
  101. ListDraw (theWindow, fullDraw)
  102.     register WindowPtr theWindow;
  103.     register Boolean fullDraw;
  104. {
  105.     register InfoPtr infoPtr = (InfoPtr) GetWRefCon(theWindow);
  106.     register ListHandle listHdl = infoPtr->item.list;
  107.  
  108.     if (fullDraw)
  109.         LUpdate(theWindow->visRgn, listHdl);
  110. }
  111.  
  112.  
  113. /* Handle a click inside a list window
  114.  */
  115. void 
  116. ListContent (theWindow, theMods, thePoint)
  117.     register WindowPtr theWindow;
  118.     register short theMods;
  119.     register Point thePoint;
  120. {
  121.     register InfoPtr infoPtr = (InfoPtr) GetWRefCon(theWindow);
  122.     register ListHandle listHdl = infoPtr->item.list;
  123.     register Boolean dblClick;
  124.     register Rect *view;
  125.     register long last;
  126.     Cell theCell;
  127.  
  128.     /* Let the ListMgr scroll, select, etc., and test for double click
  129.      */
  130.     dblClick = LClick(thePoint, theMods, listHdl);
  131.     
  132.     HLock(listHdl);
  133.     view = &((*listHdl)->rView);
  134.     HUnlock(listHdl);
  135.  
  136.     /* Find out if its inside a cell
  137.      */
  138.     if (PtInRect(thePoint, view)) {
  139.         last = LLastClick(listHdl);
  140.         theCell.v = HiWord(last);
  141.         theCell.h = LoWord(last);
  142.         
  143.         if (theWindow == wPtrGnos)
  144.             GnosClick(theCell, dblClick);
  145.     }
  146.     else {
  147.         /* Possible scrolling, make sure to redraw non-ListMgr features
  148.          */
  149.         InvalRect(view);
  150.     }
  151. }
  152.