home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / netnwscd.sit / CListWind.c < prev    next >
Text File  |  1990-10-21  |  5KB  |  296 lines

  1. /*
  2.  * CListWind
  3.  *
  4.  *     SUPERCLASS = CDirector
  5.  * Copyright ⌐ Tom Bereiter, 1990
  6.  */
  7.  
  8. #include <CApplication.h>
  9. #include <CBartender.h>
  10. #include <Commands.h>
  11. #include <CDesktop.h>
  12. #include <CColorWindow.h>
  13. #include <CStaticText.h>
  14. #include <CDecorator.h>
  15. #include "CListWind.h"
  16. #include "bits.h"
  17.  
  18. /*** Global Variables ***/
  19.  
  20. extern CApplication    *gApplication;        /* Application object                */
  21. extern CBartender *gBartender;
  22. extern CDesktop        *gDesktop;            /* The visible Desktop                */
  23. extern RgnHandle    gUtilRgn;            /* Utility region                    */
  24. extern CDecorator *gDecorator;
  25.  
  26. #define cmdSelectAll    1070L
  27.  
  28. /*
  29.  * IListWind
  30.  *
  31.  *        Initialize a ListWInd object
  32.  */
  33.  
  34. void    CListWind::IListWind(
  35.     int windresid, char *title, int width, int length)
  36. {
  37.     Rect margin;
  38.     FontInfo fi;
  39.     int h,v;
  40.     
  41.     CDirector::IDirector(gApplication);    /* Initialize superclass */
  42.     
  43.     itsWindow = new(CColorWindow);        /* Create the basic window */
  44.     itsWindow->IWindow(windresid, FALSE, gDesktop, this);
  45.  
  46.     /* set sizes */
  47.     SetPort(itsWindow->macPort);
  48.     TextFont(monaco);    /* adjust font so calculations work */
  49.     TextSize(9);
  50.     GetFontInfo(&fi);
  51.     h = (fi.widMax * width) + 15;        /* width plus scroll width */
  52.     v = ((fi.ascent + fi.descent) * length) + 15;    /* length plus scroll width */
  53.     itsWindow->ChangeSize(h,v);
  54.     
  55.     itsPane = new(CLList);
  56.     itsGopher = itsPane;
  57.     itsPane->ILList(itsWindow, this, 0, 0, 0, 0, sizELASTIC, sizELASTIC);
  58.     itsPane->FitToEnclosure(TRUE, TRUE);
  59. #ifdef MYCLASSMODS    
  60.     gDecorator->PlaceNewWindow(itsWindow, FALSE);
  61. #else
  62.     gDecorator->PlaceNewWindow(itsWindow);
  63. #endif
  64.     CtoPstr(title);
  65.     itsWindow->SetTitle((StringPtr)title);
  66.     PtoCstr(title);
  67.     itsWindow->Select();
  68. }
  69.     
  70. void    CListWind::Dispose()
  71. {
  72.     inherited::Dispose();
  73. }
  74.  
  75. void CListWind::DoCommand(long theCommand)
  76. {
  77.     switch (theCommand) {
  78.     
  79.     case cmdSelectAll:
  80.         {
  81.             Cell theCell;
  82.             
  83.             theCell.h = 0;
  84.             for (theCell.v=0; theCell.v < itsPane->nrows; theCell.v++)
  85.                 LSetSelect(TRUE, theCell, itsPane->listH);
  86.         }
  87.         break;
  88.  
  89.     default:
  90.         inherited::DoCommand(theCommand);
  91.         break;
  92.     }
  93. }
  94.  
  95. void CListWind::UpdateMenus()
  96. {
  97.     inherited::UpdateMenus();
  98.     
  99.     gBartender->EnableCmd(cmdSelectAll);
  100. }
  101.  
  102. void CListWind::ClickLine(int line)
  103. {
  104. }
  105.  
  106. void CListWind::Enab(Boolean enab)
  107. {
  108.     LDoDraw(enab, itsPane->listH);
  109.     if (enab == 0) {
  110.         itsPane->nrows = 0;
  111.         LDelRow(0, 1, itsPane->listH);
  112.     }
  113.     else
  114.         itsPane->Refresh();
  115. }
  116.  
  117. /*
  118.  * display a temporary message (i.e. won't be refreshed)
  119.  */
  120. void CListWind::TmpMsg(char *msg) {
  121.     Rect r;
  122.     
  123.     itsPane->GetFrame(&r);
  124.     r.left += 10;
  125.     r.right -= 32;
  126.     r.top += 40;
  127.     r.bottom = r.top + 80;
  128.     itsPane->Prepare();
  129.     TextBox(msg, strlen(msg), &r, teJustLeft);
  130. }
  131.  
  132.  
  133. /* -------------- --------------- */
  134.  
  135. void CLList::ILList(
  136.     CView            *anEnclosure,
  137.     CBureaucrat        *aSupervisor,
  138.     short            aWidth,
  139.     short            aHeight,
  140.     short            aHEncl,
  141.     short            aVEncl,
  142.     SizingOption    aHSizing,
  143.     SizingOption    aVSizing)
  144. {
  145.     Point cellpt;
  146.     WindowPtr w;
  147.     Rect r, db;
  148.     
  149.     inherited::IPane(anEnclosure, aSupervisor, aWidth, aHeight,
  150.                         aHEncl, aVEncl, aHSizing, aVSizing);
  151.                         
  152.     wantsClicks = TRUE;
  153.  
  154.     cellpt.h = 0;
  155.     cellpt.v = 0;
  156.     SetRect(&db, 0,0, 1,0);
  157.     r = macPort->portRect;
  158.     r.right -= 15;    /* room for scroll */
  159.     
  160.     listH = LNew(&r, &db, cellpt, 0, macPort, FALSE,TRUE, TRUE,TRUE);    
  161.     /* LAddColumn(1, 0, listH); */
  162.     LDoDraw(TRUE, listH);
  163. }
  164.  
  165. void CLList::Dispose()
  166. {
  167.     LDispose(listH);
  168.     inherited::Dispose();
  169. }
  170.  
  171. void CLList::Draw(Rect *area)
  172. {
  173.     RectRgn(gUtilRgn, area);
  174.     LUpdate(gUtilRgn, listH);
  175.     DrawGrowIcon(macPort);
  176. }
  177.  
  178. void CLList::Activate()
  179. {
  180.     inherited::Activate();
  181.     Prepare();
  182.     LActivate(TRUE, listH);
  183. }
  184.  
  185. void CLList::Deactivate()
  186. {
  187.     Prepare();
  188.     LActivate(FALSE, listH);
  189.     inherited::Deactivate();
  190. }
  191.  
  192. void CLList::DoClick(
  193.     Point        hitPt,
  194.     short        modifierKeys,
  195.     long        when)
  196. {
  197.     Rect r;
  198.     long x;
  199.     extern pascal long LLastClick();
  200.     
  201.     LClick(hitPt, modifierKeys, listH);
  202.     r = macPort->portRect;
  203.     if (hitPt.h < r.right - 16 && hitPt.v < r.bottom - 16) {    /* within fields */
  204.         x = HiWord( LLastClick(listH) );
  205.         if (x >= 0)
  206.             ((CListWind *)itsSupervisor)->ClickLine(x);
  207.     }
  208. }
  209.  
  210. void CLList::DoKeyDown(
  211.     char        theChar,
  212.     Byte        keyCode,
  213.     EventRecord    *macEvent)
  214. {
  215.     switch(theChar) {
  216.     case '\b':
  217.         itsSupervisor->DoCommand(cmdClear);
  218.         break;
  219.     }
  220. }
  221.  
  222. bitmap_t * CLList::GetSelect(long len)
  223. {
  224.     bitmap_t *bm;
  225.     Cell theCell;
  226.     int i;
  227.     
  228.     bm = bmalloc(len);
  229.     
  230.     theCell.h = theCell.v = 0;
  231.     while (LGetSelect(TRUE, &theCell, listH) && theCell.v < len) {
  232.         Bset(bm, theCell.v);
  233.         theCell.v++;
  234.     }
  235.     return (bm);
  236. }
  237.  
  238. void    CLList::ChangeSize(
  239.     register Rect        *delta,            /* Movement for each side            */
  240.     Boolean                redraw)            /* Redraw Pane or not?                */
  241. {
  242.     Rect r;
  243.  
  244.     inherited::ChangeSize(delta, redraw);
  245.     
  246.     r = macPort->portRect;
  247.     r.bottom -= 15;
  248.     r.right -= 15;    /* room for scroll */
  249.     Prepare();
  250.     LSize(r.right-r.left, r.bottom-r.top, listH);
  251. }
  252.  
  253.  
  254. void CLList::AddLine(char *line)
  255. {
  256.     Cell cellpt;
  257.     
  258.     Prepare();
  259.     LAddRow(1, nrows, listH);
  260.     cellpt.h = 0;
  261.     cellpt.v = nrows++;
  262.     LSetCell(line, strlen(line), cellpt, listH);
  263. }
  264.  
  265. void CLList::DelLine(int line, int count)
  266. {
  267.     gDesktop->UpdateWindows();        /* hack to keep list display current */
  268.  
  269.     Prepare();
  270.     LDelRow(count, line, listH);
  271.     nrows -= count;
  272. }
  273.  
  274. void CLList::SetLine(int line, char *txt)
  275. {
  276.     Cell cellpt;
  277.     
  278.     gDesktop->UpdateWindows();        /* hack to keep list display current */
  279.  
  280.     Prepare();
  281.     cellpt.h = 0;
  282.     cellpt.v = line;
  283.     LSetCell(txt, strlen(txt), cellpt, listH);
  284. }
  285.  
  286. void CLList::SelectLine(int line)
  287. {
  288.     Cell cellpt;
  289.     
  290.     Prepare();
  291.     cellpt.h = 0;
  292.     cellpt.v = line;
  293.     if (cellpt.v >= nrows)
  294.         cellpt.v = nrows-1;
  295.     LSetSelect(TRUE, cellpt, listH);
  296. }