home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / netnwscd.sit / CArticleList.c < prev    next >
Text File  |  1990-10-16  |  3KB  |  150 lines

  1. /*
  2.  * CArticleList - manage an article list window
  3.  *
  4.  *     SUPERCLASS = CListWind
  5.  * Copyright ⌐ Tom Bereiter, 1990
  6.  */
  7.  
  8. #include <Commands.h>
  9. #include <CBartender.h>
  10. #include "CGroupList.h"
  11. #include "CArticleDoc.h"
  12. #include "CArticleList.h"
  13.  
  14. #define    WINDreg        500        /* Resource ID for WIND template */
  15.  
  16. extern CBartender *gBartender;
  17. extern short        gClicks;            /* Click counter, = 1 single click    */
  18.  
  19. art_t *next_article(CArticleList *alist, art_t *ap, Boolean zap, Boolean modline);
  20.  
  21.  
  22.  
  23. void    CArticleList::IArticleList(CBureaucrat *grouplist, grp_t *gp)
  24. {
  25.     CListWind::IListWind(WINDreg, gp->gname, 80, 24);
  26.     groupptr = gp;
  27.     glist = grouplist;
  28.     ReDo();
  29. }
  30.  
  31. void    CArticleList::Dispose(void) {
  32.     dispose_artlist(groupptr);
  33.     inherited::Dispose();
  34. }
  35.  
  36. Boolean    CArticleList::Close(Boolean quitting) {
  37.     return inherited::Close(quitting);
  38. }
  39.  
  40. void CArticleList::DoCommand(long theCommand)
  41. {
  42.     int n, i, sub, lastl;
  43.     art_t *ap;
  44.     bitmap_t *bm;
  45.  
  46.     switch (theCommand) {
  47.  
  48.     case cmdClear:    /* remove all selected */
  49.         bm = itsPane->GetSelect(bmTOTAL(groupptr));
  50.         sub = n = 0;
  51.         lastl = -1;
  52.         for (ap = groupptr->art_head,i=0; ap; i++) {    /* for each selected cell */
  53.             if (Btst(bm, i))
  54.                 ap = next_article(this, ap, TRUE, FALSE);
  55.             else {
  56.                 ap=ap->next;
  57.                 /* delete lines [n-i] */
  58.                 if (n != i) {
  59.                     itsPane->DelLine(n-sub, i-n);
  60.                     lastl = (n-sub);
  61.                     sub += (i-n);
  62.                 }
  63.                 n = i+1;
  64.             }
  65.         }
  66.         if (n != i) {
  67.             itsPane->DelLine(n-sub, i-n);
  68.             lastl = (n-sub);
  69.         }
  70.         DisposPtr(bm);
  71.         if (lastl > 0)
  72.             itsPane->SelectLine(lastl);
  73.         ((CGroupList *)glist)->ReDoLine(groupptr);
  74.         
  75.         if (groupptr->art_head == NULL)
  76.             Close(FALSE);
  77.         break;
  78.     
  79.     default:
  80.         inherited::DoCommand(theCommand);
  81.         break;
  82.     }
  83. }
  84.  
  85. void CArticleList::UpdateMenus()
  86. {
  87.     inherited::UpdateMenus();
  88.     
  89.     gBartender->EnableCmd(cmdClear);
  90. }
  91.  
  92. void    CArticleList::Dawdle(long *maxSleep)
  93. {
  94. }
  95.  
  96. void CArticleList::ReDo()
  97. {
  98.     char buf[100];
  99.     art_t *ap;
  100.  
  101.     Enab(0);
  102.     
  103.     for (ap=groupptr->art_head; ap; ap = ap->next) {
  104.         sprintf(buf,"%5u    %s%.90s", ap->nthread-ap->tindex, ap->re?"Re: ":"",ap->title);
  105.         itsPane->AddLine(buf);
  106.     }
  107.     Enab(1);
  108. }
  109.  
  110. void CArticleList::ModLine(art_t *line_ap, int what)
  111. {
  112.     art_t *ap;
  113.     char buf[128];
  114.     int n;
  115.  
  116.     for (ap=groupptr->art_head,n=0; ap; ap = ap->next,n++)
  117.         if (ap == line_ap)
  118.             goto found;
  119.     return;
  120. found:
  121.     switch(what) {
  122.     case 0:        /* remove */
  123.         itsPane->DelLine(n, 1);
  124.         itsPane->SelectLine(n);
  125.         break;
  126.     case 1:        /* redisplay */
  127.         sprintf(buf,"%5u    %s%.90s", ap->nthread-ap->tindex, ap->re?"Re: ":"",ap->title);
  128.         itsPane->SetLine(n, buf);
  129.         break;
  130.     }
  131.     ((CGroupList *)glist)->ReDoLine(groupptr);
  132. }
  133.  
  134. void CArticleList::ClickLine(int line)
  135. {
  136.     CArticleDoc *doc;
  137.     art_t *ap;
  138.     int n;
  139.     
  140.     if (gClicks == 2  && lastclickline == line) {    /* double-click: open article */
  141.         for (ap=groupptr->art_head,n=0; ap; ap = ap->next,n++)
  142.             if (n == line) {
  143.                 doc = new(CArticleDoc);
  144.                 doc->IArticleDoc(this, ap);
  145.                 return;
  146.             }
  147.     }
  148.     lastclickline = line;
  149. }
  150.