home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / UArticleManageView.cp < prev    next >
Encoding:
Text File  |  1994-02-20  |  5.9 KB  |  251 lines  |  [TEXT/MPS ]

  1. // Copyright © 1992 Peter Speck, speck@dat.ruc.dk. All rights reserved.
  2. // UArticleManageView.cp
  3.  
  4. #include "UArticleManageView.h"
  5. #include "UArticleView.h"
  6. #include "UArticleCache.h"
  7. #include "UTriangleControl.h"
  8. #include "UGroupDoc.h"
  9. #include "UArticleStatus.h"
  10. #include "UPrefsDatabase.h"
  11. #include "NetAsciiTools.h"
  12. #include "Tools.h"
  13.  
  14. #include <RsrcGlobals.h>
  15. #include <ErrorGlobals.h>
  16.  
  17. #pragma segment MyArticle
  18.  
  19. #define qDebugFrame qDebug & 0
  20.  
  21. const VPoint kArticleViewLocation(17, 0);
  22. const VCoordinate kManageViewWidth = 640;
  23. const VCoordinate kMinHeight = 16;
  24.  
  25. pascal void TArticleManageView::Initialize()
  26. {
  27.     inherited::Initialize();
  28.     fDoc = nil;
  29.     fArticleView = nil;
  30.     fTriControl = nil;
  31. }
  32.  
  33. void TArticleManageView::IArticleManageView(TGroupDoc *doc, TView *superView, VCoordinate top,
  34.                             long articleID, TArticle *article, Boolean showExpanded)
  35. {
  36.     VPoint tl(0, top);
  37.     inherited::IView(doc, superView, tl, VPoint(kManageViewWidth, 0), 
  38.         sizeVariable, sizeVariable);
  39.     FailInfo fi;
  40.     if (fi.Try())
  41.     {
  42.         fDoc = doc;
  43.         fArticleID = articleID;
  44.         
  45.         StandardGridViewTextStyle gvts;
  46.         gPrefs->GetTextStylePrefs('TSar', gvts.fTextStyle);
  47.         CalcStandardGridViewFont(gvts);
  48.         fGridViewTextStyle = gvts;
  49.  
  50.         TTriangleControl *tri = new TTriangleControl();
  51.         tri->ITriangleControl(this, VPoint(0, 0), showExpanded);
  52.         fTriControl = tri;
  53.         
  54. #if qDebugFrame
  55.         VRect oldFrame;
  56.         GetFrame(oldFrame);
  57. #endif
  58.         BuildDisplay(showExpanded, article);
  59. #if qDebugFrame
  60.         VRect newFrame;
  61.         GetFrame(newFrame);
  62.         fprintf(stderr, "TAMV: Frame %s -> ", (char*)oldFrame);
  63.         fprintf(stderr, "%s\n", (char*)newFrame);
  64. #endif
  65.         Focus();
  66.         ForceRedraw();
  67.         fi.Success();
  68.     }
  69.     else // fail
  70.     {
  71.         Free();
  72.         fi.ReSignal();
  73.     }
  74. }
  75.  
  76. pascal void TArticleManageView::Free()
  77. {
  78.     inherited::Free();
  79. }
  80.  
  81. pascal void TArticleManageView::DoEvent(EventNumber eventNumber, 
  82.                                                             TEventHandler* source, TEvent* event)
  83. {
  84.     if (eventNumber == mToggle)
  85.         BuildDisplay(!fIsExpanded);
  86.     inherited::DoEvent(eventNumber, source, event);
  87. }
  88.  
  89. void TArticleManageView::BuildDisplay(Boolean expand, TArticle *article)
  90. {
  91.     VOLATILE(expand);
  92.     FailInfo fi;
  93.     if (fi.Try())
  94.     {
  95.         fTriControl->SetExpand(expand);
  96.         fIsExpanded = expand;
  97.         if (expand)
  98.             DoShowArticleView(article);
  99.         else
  100.             DoShowHeaderView();
  101.         fi.Success();
  102.     }
  103.     else // fail
  104.     {
  105.         fTriControl->SetExpand(false);
  106.         fIsExpanded = false;
  107.         DoShowHeaderView();
  108.         FailNewMessage(fi.error, fi.message, messageExpandArticle);
  109.     }
  110. }
  111.  
  112. void TArticleManageView::DoShowArticleView(TArticle *article)
  113. {
  114.     if (fArticleView)
  115.     {
  116. #if qDebug
  117.         if (article)
  118.             fprintf(stderr, "Problem: in TAMV::DoSAV: got article view and new article\n");
  119. #endif
  120.         fArticleView->UpdateDisplay();
  121.     }
  122.     else
  123.     {
  124.         if (!article)
  125.         {
  126.             CStr255 groupDotName;
  127.             fDoc->GetGroupDotName(groupDotName);
  128.             FailInfo fi;
  129.             if (fi.Try())
  130.             {
  131.                 article = gArticleCache->GetArticle(groupDotName, fArticleID);
  132.                 fi.Success();
  133.             }
  134.             else // fail
  135.             {
  136.                 fDoc->GetArticleStatus()->SetStatus(fArticleID, kArticleRead);
  137.                 fDoc->GetOldArticleStatus()->SetMinStatus(fArticleID, kArticleRead);
  138.                 fi.ReSignal();
  139.             }
  140.         }
  141.         TArticleView *av = new TArticleView();
  142.         av->IArticleView(fDoc, this, kArticleViewLocation, fArticleID, article);
  143.         fArticleView = av;
  144.         // SubViewChangedFrame takes care of resizing this view
  145.     }
  146. }
  147.  
  148. void TArticleManageView::DoShowHeaderView()
  149. {
  150.     if (fArticleView)
  151.     {
  152.         fArticleView->Close();
  153.         fArticleView->Free();
  154.         fArticleView = nil;
  155.     }
  156.     VPoint viewSize(kManageViewWidth, Max(16, fGridViewTextStyle.fRowHeight));
  157.     VRect myNewFrame(fLocation, fLocation + viewSize);
  158.     // don't invalidate released space, as TViewListView takes care of updating
  159.     // so invalidate only changed contents
  160.     VRect vr(kArticleViewLocation, kArticleViewLocation + viewSize);
  161.     vr.right = fSize.h; // to get all updated
  162.     Focus();
  163.     InvalidateVRect(vr);
  164. #if qDebugFrame
  165. fprintf(stderr, "MyNewFrame = %s\n", (char*)myNewFrame);
  166. #endif
  167.     SetFrame(myNewFrame, !kRedraw);
  168. }
  169.  
  170.  
  171. pascal void TArticleManageView::Draw(const VRect& area)
  172. {
  173.     FailInfo fi;
  174.     if (fi.Try())
  175.     {
  176.         inherited::Draw(area);
  177.         fi.Success();
  178.     }
  179.     else // fail
  180.     {
  181.         if (fi.error == errNoSuchArticle)
  182.         {
  183.             fTriControl->SetExpand(false);
  184.             fIsExpanded = false;
  185.             DoShowHeaderView();
  186.         }
  187.         fi.ReSignal();
  188.     }
  189.     if (!fIsExpanded)
  190.     {
  191.         TextStyle itsTextStyle = fGridViewTextStyle.fTextStyle;
  192.         SetPortTextStyle(itsTextStyle);
  193.         MoveTo(20, fGridViewTextStyle.fVertOffset + short(fSize.v - fGridViewTextStyle.fRowHeight)/2);
  194.         HandleOffsetLength hol;
  195.         CStr255 text, from, email, realname, subject;
  196.         if (!fDoc->GetSubject(fArticleID, hol))
  197.         {
  198.             MyGetIndString(text, kUnknownArticleText);
  199.             DrawString(text);
  200.             return;
  201.         }
  202.         CopyHolToCStr255(hol, subject);
  203.         if (!fDoc->GetFrom(fArticleID, hol))
  204.         {
  205.             MyGetIndString(text, kUnknownArticleText);
  206.             DrawString(text);
  207.             return;
  208.         }
  209.         CopyHolToCStr255(hol, text);
  210.         if (!GetPrintableAuthorName(text, realname, email))
  211.             realname = email;
  212.         MyGetIndString(text, kArticleCompactTemplate);
  213.         SubstituteStringItems(text, "«realname»", realname);
  214.         SubstituteStringItems(text, "«email»", email);
  215.         SubstituteStringItems(text, "«subject»", subject);
  216.         DrawString(text);
  217.     }
  218. }
  219.  
  220. TArticleView *TArticleManageView::GetArticleView()
  221. {
  222.     return fArticleView;
  223. }
  224.  
  225. pascal void TArticleManageView::SubViewChangedFrame(TView* theSubView,
  226.                             const VRect& oldFrame, const VRect& newFrame, Boolean invalidate)
  227. {
  228.     inherited::SubViewChangedFrame(theSubView, oldFrame, newFrame, invalidate);
  229.     VRect myFrame(0, 0, kManageViewWidth, Max(kMinHeight, fGridViewTextStyle.fRowHeight));
  230.     myFrame = myFrame | newFrame;
  231.     myFrame.right = kManageViewWidth;
  232.     myFrame += fLocation;
  233.     SetFrame(myFrame, !kRedraw);
  234.     // don't invalidate, as TViewListView takes care of updating
  235. #if qDebugFrame
  236.     fprintf(stderr, "AMV: SBCF -> new frame = %s\n", (char*)myFrame);
  237. #endif
  238. }
  239.  
  240. void TArticleManageView::SetNewFont(const TextStyle &textStyle)
  241. {
  242.     StandardGridViewTextStyle gvts;
  243.     gvts.fTextStyle = textStyle;
  244.     CalcStandardGridViewFont(gvts);
  245.     fGridViewTextStyle = gvts;
  246.     if (fArticleView)
  247.         fArticleView->SetNewFont(textStyle);
  248.     else
  249.         BuildDisplay(fIsExpanded);
  250. }
  251.