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

  1. /*
  2.  * CArticleDoc - manage an article document window
  3.  *
  4.  * SUPERCLASS = CEditDoc
  5.  * Copyright ⌐ Tom Bereiter, 1990
  6.  */
  7.  
  8. #include <CApplication.h>
  9. #include <CBartender.h>
  10. #include <CStaticText.h>
  11. #include "CArticleList.h"
  12. #include "CArticleDoc.h"
  13.  
  14.  
  15. extern CApplication *gApplication;
  16. extern CBartender *gBartender;
  17.  
  18. #define cmdNext        1030L
  19. #define cmdUnread    1031L
  20. #define cmdDetach    1032L
  21.  
  22.  
  23. extern art_t *next_article(CArticleList *alist, art_t *ap, Boolean zap, Boolean modline);
  24.  
  25.  
  26. void CArticleDoc::IArticleDoc(CBureaucrat *articlelist, art_t *articlep)
  27. {
  28.     CEditDoc::IEditDoc(gApplication, FALSE);
  29.     ap = articlep;
  30.     alist = articlelist;
  31.     
  32.     NewFile();
  33. }
  34.  
  35. Boolean    CArticleDoc::Close(Boolean quitting) {
  36.     CBureaucrat *alist1 = alist;    /* need to make copies since a close zaps data */
  37.     art_t *ap1 = ap;
  38.     Boolean detached1 = detached;
  39.     Boolean keepunread1 = keepunread;
  40.     
  41.     if (inherited::Close(quitting) == FALSE)
  42.         return FALSE;
  43.         
  44.     if (!detached1) {
  45.         if (!keepunread1)
  46.             next_article((CArticleList *)alist1, ap1, FALSE, TRUE);
  47.     }        
  48.     return TRUE;
  49. }
  50.  
  51. void CArticleDoc::NewFile(void)
  52. {
  53.     extern char *artbuf;
  54.     extern int artlen;
  55.  
  56.     if (readart(ap) < 0) {
  57.         Close(FALSE);
  58.         return;
  59.     }
  60.     
  61.     inherited::NewFile();
  62.     
  63.     CtoPstr(ap->title);
  64.     itsWindow->SetTitle((StringPtr)ap->title);
  65.     PtoCstr(ap->title);
  66.     ((CStaticText *)itsMainPane)->SetFontNumber(monaco);
  67.     ((CStaticText *)itsMainPane)->SetFontSize(9);
  68.     
  69.     ((CStaticText *)itsMainPane)->SetTextPtr(artbuf, artlen);
  70. }
  71.  
  72. void CArticleDoc::DoCommand(long theCommand)
  73. {
  74.     int n, i;
  75.     art_t *old_ap;
  76.     Point top;
  77.     extern char *artbuf;
  78.     extern int artlen;
  79.  
  80.     switch (theCommand) {
  81.  
  82.     case cmdNext:        /* next article */
  83.         old_ap = ap;
  84.         ap = next_article((CArticleList *)alist, ap, FALSE, TRUE);
  85.         if (ap == NULL || readart(ap) < 0) {
  86.             Close(FALSE);
  87.             break;
  88.         }
  89.     
  90.         if (ap != old_ap) {
  91.             CtoPstr(ap->title);
  92.             itsWindow->SetTitle((StringPtr)ap->title);
  93.             PtoCstr(ap->title);
  94.         }
  95.         ((CStaticText *)itsMainPane)->SetTextPtr(artbuf, artlen);
  96.         top.h = top.v = 0;
  97.         ((CStaticText *)itsMainPane)->ScrollTo(top, TRUE);
  98.         break;
  99.         
  100.     case cmdUnread:        /* close, but keep unread */
  101.         keepunread = TRUE;
  102.         Close(FALSE);
  103.         break;
  104.         
  105.     case cmdDetach:
  106.         detached = TRUE;
  107.         break;
  108.     
  109.     default:
  110.         inherited::DoCommand(theCommand);
  111.         break;
  112.     }
  113. }
  114.  
  115. void CArticleDoc::UpdateMenus()
  116. {
  117.     inherited::UpdateMenus();
  118.     
  119.     if (!detached) {
  120.         if (ap->next || ap->tindex < ap->nthread-1)
  121.             gBartender->EnableCmd(cmdNext);
  122.         gBartender->EnableCmd(cmdUnread);
  123.         gBartender->EnableCmd(cmdDetach);
  124.     }
  125. }
  126.