home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / msq31004.zip / NSHOW.C < prev    next >
Text File  |  1995-07-14  |  13KB  |  589 lines

  1. /* nshow.c
  2. **
  3. ** released into the PUBLIC DOMAIN 10 jul 1994 by John Dennis
  4. **
  5. ** Routines for displaying message information on
  6. ** the screen.  This includes both text and header
  7. ** information.
  8. */
  9.  
  10. #include "msged.h"
  11. #include "date.h"
  12. #include "main.h"
  13. #include "menu.h"
  14. #include "keys.h"
  15. #include "nshow.h"
  16. #include "dialogs.h"
  17.  
  18. static LINE *top    = NULL;          /* top of screen */
  19. static LINE *bottom = NULL;          /* bottom of screen */
  20.  
  21. static char  line[256];              /* used as temporary storage */
  22. static WND  *hMsgWnd, *hMsgCurr;     /* main window and Msg window */
  23. HotGroup     Hot;
  24.  
  25. char *v7lookupsystem(ADDRESS *faddr, char *system);
  26.  
  27. /*/$/ int InitScreen(void);
  28. **
  29. ** Initializes the (basic) screen.
  30. **
  31. ** returns -1 on failure (terminate).
  32. */
  33.  
  34. int InitScreen(void)
  35. {
  36.     if (SW->usemouse == NO)
  37.         term.Abil |= NOMOUSE;
  38.  
  39.     TTopen();
  40.  
  41.     maxx = term.NCol;
  42.     maxy = term.NRow;
  43.  
  44.     if ((hMnScr = WndOpen(0, 0, maxx-1, maxy-1, NBDR, 0, cm[CM_NTXT])) == NULL)
  45.         return 0;
  46.  
  47.     SW->redraw = TRUE;
  48.  
  49.     return 0;
  50. }
  51.  
  52.  
  53. /*
  54. ** Adds an item to a HotGroup.
  55. */
  56.  
  57. void AddHG(HotGroup *h, int num, int id, int x1, int y1, int x2, int y2)
  58. {
  59.     h->harr[num].id = id;
  60.     h->harr[num].x1 = x1;
  61.     h->harr[num].y1 = y1;
  62.     h->harr[num].x2 = x2;
  63.     h->harr[num].y2 = y2;
  64. }
  65.  
  66.  
  67. /*/$/ void BuildHotSpots(void);
  68. **
  69. ** Builds the Hot spots on the main window and
  70. ** initializes the menu system.  We cannot use
  71. ** a hotspot for the menu system;  We wish to
  72. ** send the messages un-altered to the menu
  73. ** processing function.
  74. */
  75.  
  76. void BuildHotSpots(void)
  77. {
  78.     Hot.wid = hMnScr->wid;
  79.     Hot.num = 6;
  80.  
  81.     AddHG(&Hot, 0, ID_MGRGT, maxx - 2, 6,         maxx - 1, maxy - 1);
  82.     AddHG(&Hot, 1, ID_MGLFT, 0,        6,         1,        maxy - 1);
  83.     AddHG(&Hot, 2, ID_SCRUP, 0,        6,         maxx - 1, 7);
  84.     AddHG(&Hot, 3, ID_SCRDN, 0,        maxy - 2,  maxx - 1, maxy - 1);
  85.     AddHG(&Hot, 4, ID_LNDN,  65,       2,               69, 2);
  86.     AddHG(&Hot, 5, ID_LNUP,  70,       2,               75, 2);
  87.  
  88.     /* Push the group onto the HotHroup stack */
  89.  
  90.     PushHotGroup(&Hot);
  91.  
  92.     /* Setup the mouse menu on top of the screen  */
  93.     /* It'll use the parent window for displaying */
  94.     /* the menu, and we send any messages in that */
  95.     /* vicinity for processing by it              */
  96.  
  97.     MouseMnu.cmdtab[0].col = 0 +  maxx - MNU_LEN - 1;
  98.     MouseMnu.cmdtab[1].col = 7 +  maxx - MNU_LEN - 1;
  99.     MouseMnu.cmdtab[2].col = 14 + maxx - MNU_LEN - 1;
  100.     MouseMnu.cmdtab[3].col = 21 + maxx - MNU_LEN - 1;
  101.     MouseMnu.cmdtab[4].col = 28 + maxx - MNU_LEN - 1;
  102.     MnuSetColours(cm[MN_BTXT], cm[MN_NTXT], cm[MN_STXT]);
  103.  
  104.     /*
  105.     ** Set up the dialog box colours.
  106.     */
  107.  
  108.     SetDialogColors();
  109. }
  110.  
  111. /*/$/ void KillHotSpots(void);
  112. **
  113. ** Kills the HotSpots on the stack.
  114. */
  115.  
  116. void KillHotSpots(void)
  117. {
  118.     PopHotGroup();
  119. }
  120.  
  121.  
  122. /*/$/ void DrawHeader(void);
  123. **
  124. ** Draws the msg header on the screen.  This should
  125. ** only have to be drawn once during normal operation.
  126. */
  127.  
  128. void DrawHeader(void)
  129. {
  130.     EVT e;
  131.  
  132.     WClear(0, 0, maxx - 1, 0, cm[CM_ITXT]);
  133.  
  134.     WWriteStr(0, 1, cm[CM_FTXT], "From:");        /* header info */
  135.     WWriteStr(0, 2, cm[CM_FTXT], "To:");
  136.     WWriteStr(0, 3, cm[CM_FTXT], "Subj:");
  137.     WWriteStr(0, 4, cm[CM_FTXT], "Attr:");
  138.  
  139.     memset(line, '─', maxx + 1);                  /* clear dividing line */
  140.     WPutsn(0, 5, maxx, cm[CM_DTXT], line);
  141.                                                   /* mouse menu */
  142.     ProcessMenu(&MouseMnu, &e, 1);
  143. }
  144.  
  145.  
  146. /*/$/ void ClearScreen(void);
  147. **
  148. ** Clears the screen (only used with the list function to
  149. ** make it look bwtter when it returns).
  150. **
  151. */
  152.  
  153. void ClearScreen(void)
  154. {
  155.     WClear(0, 0,  maxx - 1, maxy - 1, cm[CM_FTXT]);
  156. }
  157.  
  158.  
  159. /*/$/ void ClearMsgScreen(void);
  160. **
  161. ** Clears message information (header and text)
  162. ** from the screen.
  163. **
  164. */
  165.  
  166. void ClearMsgScreen(void)
  167. {
  168.     WClear(7, 1,  maxx - 1, 4, cm[CM_FTXT]);       /* clear header info */
  169.     RefreshMsg(NULL, 6);
  170. }
  171.  
  172.  
  173. /*/$/ void ShowNewArea(void);
  174. **
  175. ** Shows a new area on the screen.
  176. **
  177. */
  178.  
  179. void ShowNewArea(void)
  180. {
  181.     memset(line, '─', maxx + 1);                  /* clear dividing line */
  182.     WPutsn(0, 5, maxx, cm[CM_DTXT], line);
  183.     WWriteStr(1, 5, cm[CM_NINF], CurArea.description);
  184.     if (SW->showaddr)
  185.     {                                  /* then show the current address */
  186.         sprintf(line, "%s", show_address(&CurArea.addr));
  187.         WWriteStr(strlen(CurArea.description) + 2, 5, cm[CM_NINF], line);
  188.     }
  189. }
  190.  
  191.  
  192. int OpenMsgWnd(int wid, int dep, char *title, char *msg, int x, int y)
  193. {
  194.     hMsgCurr = Wtop();
  195.     hMsgWnd  = WPopUp(wid, dep, INSBDR|SHADOW, cm[IP_BTXT], cm[IP_NTXT]);
  196.  
  197.     if (!hMsgWnd)
  198.         return 0;
  199.  
  200.     if (title)
  201.     {
  202.         WTitle(title, cm[IP_BTXT]);
  203.     }
  204.  
  205.     if (msg)
  206.     {
  207.         WWriteStr(x, y, cm[IP_NTXT], msg);
  208.     }
  209.     return 1;
  210. }
  211.  
  212. void SendMsgWnd(char *msg, int y)
  213. {
  214.     WND *hCurr;
  215.  
  216.     hCurr = Wtop();
  217.  
  218.     if (!hCurr) return;
  219.  
  220.     WClearLine(y, cm[IP_NTXT]);
  221.     WPutsCen(y, cm[IP_NTXT], msg);
  222. }
  223.  
  224. int CloseMsgWnd(void)
  225. {
  226.     WClose(hMsgWnd);
  227.     WCurr(hMsgCurr);
  228.     return (0);
  229. }
  230.  
  231.  
  232.  
  233. /*/$/ void MakeMsgAttrs(char *buf, struct _attributes *att);
  234. **
  235. ** Builds a text version of the attributes set
  236. ** in an _attribute structure.
  237. **
  238. */
  239.  
  240. void MakeMsgAttrs(char *buf, struct _attributes *att, int scanned)
  241. {
  242.     char nul[] = "";
  243.  
  244.     sprintf(buf, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
  245.                       (att->private)  ? "priv "   : nul,
  246.                       (att->crash)    ? "crash "  : nul,
  247.                       (att->recvd)    ? "recvd "  : nul,
  248.                       (att->sent)     ? "sent "   : nul,
  249.                       (att->attached) ? "f/a "    : nul,
  250.                       (att->killsent) ? "k/s "    : nul,
  251.                       (att->freq)     ? "freq "   : nul,
  252.                       (att->ureq)     ? "ureq "   : nul,
  253.                       (att->hold)     ? "hold "   : nul,
  254.                       (att->orphan)   ? "orph "   : nul,
  255.                       (att->forward)  ? "trans "  : nul,
  256.                       (att->local)    ? "local "  : nul,
  257.                       (att->direct)   ? "dir "    : nul,
  258.                       (att->rreq)     ? "rreq "   : nul,
  259.                       (att->rcpt)     ? "rcpt "   : nul,
  260.                       (att->areq)     ? "areq "   : nul,
  261.                       (scanned)       ? "scanned ": nul);
  262. }
  263.  
  264. void ShowAddress(ADDRESS *addr, int y)
  265. {
  266.     sprintf(line, "  %s", show_address(addr));
  267.     WPutsn(32, y, 26, cm[CM_HTXT], line);
  268.     return;
  269. }
  270.  
  271. void ShowNameAddress(char *name, ADDRESS *addr, int y, int newrcvd, int nm_only)
  272. {
  273.     char tmp[256];
  274.     
  275.     if (addr->fidonet || (addr->notfound && !(CurArea.uucp || CurArea.news)))
  276.     {
  277.         /*
  278.         ** Show fidonet-type names.
  279.         */
  280.  
  281.         if (nm_only)
  282.         {
  283.             if (name)
  284.                 sprintf(line, "%s,", name);
  285.             else
  286.                 strcpy(line, ", ");
  287.         }
  288.         else
  289.         {
  290.             if (CurArea.netmail || (CurArea.echomail && y == 1))
  291.             {
  292.                 if (name)
  293.                     sprintf(line, "%s, %s", name, show_address(addr));
  294.                 else
  295.                     sprintf(line, ", %s", show_address(addr));
  296.                     
  297.                 if (SW->showsystem && v7lookupsystem(addr, tmp))
  298.                 {
  299.                     strcat(line, ", ");
  300.                     strcat(line, tmp);
  301.                 }
  302.             }
  303.             else
  304.             {
  305.                 if (name)
  306.                     sprintf(line, "%s", name);
  307.                 else
  308.                     strcpy(line, " ");
  309.             }
  310.         }
  311.         if (newrcvd)
  312.             WPutsn(7,  y, 52, cm[CM_BTXT], line);
  313.         else
  314.             WPutsn(7,  y, 52, cm[CM_HTXT], line);
  315.     }
  316.     else
  317.     {
  318.         /*
  319.         ** Show internet-type names.
  320.         */
  321.  
  322.         if (name == NULL)
  323.         {
  324.             sprintf(line, "%s", show_address(addr));
  325.             WPutsn(7, y, 53, cm[CM_HTXT], line);
  326.         }
  327.         else
  328.         {
  329.             sprintf(line, "%s (%s)", show_address(addr), name);
  330.             if (newrcvd)
  331.                 WPutsn(7, y, 53, cm[CM_BTXT], line);
  332.             else
  333.                 WPutsn(7, y, 54, cm[CM_HTXT], line);
  334.         }
  335.     }
  336. }
  337.  
  338. void ShowSubject(char *subj)
  339. {
  340.     WPutsn(7, 3, 72, cm[CM_HTXT], subj);
  341. }
  342.  
  343. void ShowAttrib(msg *m)
  344. {
  345.     MakeMsgAttrs(line, &m->attrib, m->scanned);
  346.     if (SW->datearrived)
  347.         WPutsn(7, 4, 52, cm[CM_HTXT], line);
  348.     else
  349.         WPutsn(7, 4, 72, cm[CM_HTXT], line);
  350. }
  351.  
  352.  
  353. /*/$/ void ShowMsgHeader(msg *m);
  354. **
  355. ** Puts the message header onto the screen.
  356. **
  357. */
  358.  
  359. void ShowMsgHeader(msg *m)
  360. {
  361.     int  i, r = 0;
  362.     unsigned long rep = 0;
  363.  
  364.     if (!m)
  365.     {
  366.         strcpy(line, "0 of 0          ");
  367.     }
  368.     else
  369.     {
  370.         sprintf(line, 
  371.                 "%ld of %ld          ", 
  372.                 CurArea.current, 
  373.                 CurArea.messages);
  374.     }
  375.  
  376.     line[16] = '\0';
  377.     
  378.     WPutsn(0, 0, 16, cm[CM_ITXT], line);
  379.  
  380. #if defined(MSDOS)
  381.     sprintf(line, " %ld ", corerem());
  382.     WWriteStr(67, 5, cm[CM_DTXT], line);
  383. #endif
  384.  
  385.     if (m == NULL)
  386.         return;
  387.  
  388.     /*
  389.     ** Show the date of creation and the date of arrival.
  390.     */
  391.  
  392.     WPrintf(60, 1, cm[CM_HTXT], "%s", mtime(m->timestamp));
  393.  
  394.     if (SW->datearrived && m->time_arvd != 0 && m->time_arvd != m->timestamp)
  395.         WPrintf(60, 4, cm[CM_HTXT], "%s", mtime(m->time_arvd));
  396.     else
  397.         WPutsn(60, 4, 19, cm[CM_HTXT], " ");
  398.  
  399.     /*
  400.     ** Show the message links, up and down.
  401.     */
  402.  
  403.     if (m->replyto)
  404.     {
  405.         sprintf(line, "%6ld\x11", m->replyto);
  406.     }
  407.     else
  408.     {
  409.         strcpy(line, "       ");
  410.     }
  411.     line[7] = '\0';
  412.     WPrintf(63, 2, cm[CM_FTXT], line);
  413.  
  414.     for (i = 0; i < 10; i++)
  415.     {
  416.         if (m->replies[i] != 0)
  417.         {
  418.             if (!rep)
  419.             {
  420.                 rep = m->replies[i];
  421.             }
  422.             r++;
  423.         }
  424.     }
  425.  
  426.     if (rep && (r == 1))
  427.     {
  428.         sprintf(line, "\x10%ld      ", rep);
  429.     }
  430.     else if (rep && (r > 1))
  431.     {
  432.         sprintf(line, "\x10\x10%ld     ", rep);
  433.     }
  434.     else
  435.     {
  436.         strcpy(line,  "        ");
  437.     }
  438.     line[8] = '\0';
  439.     WWriteStr(70, 2, cm[CM_FTXT], line);
  440.  
  441.     /*
  442.     ** Display the rest of the header information.
  443.     */
  444.  
  445.     ShowNameAddress(m->isfrom, &m->from, 1, 0, 0);
  446.     ShowNameAddress(m->isto,   &m->to,   2, m->newrcvd, 0);
  447.     ShowSubject(m->subj);
  448.     ShowAttrib(m);
  449. }
  450.  
  451. void PutLine(LINE *l, int y)
  452. {
  453.     int   Attr = (l->block) ? cm[CM_BTXT] : (l->quote) ? cm[CM_QTXT] : (l->hide) ? cm[CM_KTXT] : (l->templt) ? cm[CM_TTXT] : cm[CM_NTXT];
  454.     char *s;
  455.  
  456. /* debug mode, so we can see the details.. */
  457.  
  458.     strcpy(line, l->text);
  459.  
  460.     if ((s = strchr(line, '\n')) != NULL)
  461.     {
  462.         if (SW->showcr)
  463.             *s = '';
  464.         else
  465.             *s = '\0';
  466.     }
  467.  
  468.     if (SW->showeol && SW->showcr)
  469.         strcat(line, "");
  470.  
  471.     WPutsn(0, y, maxx, Attr, line);
  472. }
  473.  
  474. void MsgScroll(int Dir)
  475. {
  476.     WScroll(0, 6, maxx-1, maxy - 1, Dir);
  477. }
  478.  
  479. void Go_Up(void)
  480. {
  481.     if (!message)
  482.         return;
  483.  
  484.     if (top->prev)
  485.     {
  486.         while (top->prev)          /* we want to skip hidden lines */
  487.         {
  488.             top = top->prev;
  489.             if (SW->shownotes || (*(top->text) != '\01'))
  490.             {
  491.                 MsgScroll(0);
  492.                 PutLine(top, 6);
  493.                 break;             /* stop when we atctually write something */
  494.             }
  495.         }
  496.     }
  497. }
  498.  
  499. void Go_Dwn(void)
  500. {
  501.     int i = 1;
  502.  
  503.     if (!message)
  504.         return;
  505.  
  506.     for (bottom = top; i < maxy - 6; bottom = bottom->next)
  507.     {
  508.         if (!bottom->next) break;
  509.         i++;
  510.     }
  511.  
  512.     if (i == maxy - 6)
  513.     {
  514.         if (bottom->next)
  515.         {
  516.             bottom = bottom->next;
  517.             top    = top->next;
  518.             MsgScroll(1);
  519.             PutLine(bottom, maxy - 1);
  520.         }
  521.     }
  522. }
  523.  
  524. void Go_PgDwn(void)
  525. {
  526.     int i;
  527.  
  528.     if (!message)
  529.         return;
  530.  
  531.     for (i = 0; i < maxy - 6; i++)
  532.     {
  533.         if (!top->next) break;
  534.         top = top->next;
  535.     }
  536.     if (i != 0)
  537.         RefreshMsg(top, 6);
  538. }
  539.  
  540. void Go_PgUp(void)
  541. {
  542.     int i;
  543.  
  544.     if (!message)
  545.         return;
  546.  
  547.     for (i = 0; i < maxy - 6; i++)
  548.     {
  549.         if (!top->prev) break;
  550.         top = top->prev;
  551.     }
  552.     if (i != 0)
  553.         RefreshMsg(top, 6);
  554. }
  555.  
  556. void RefreshMsg(LINE *line, int y)
  557. {
  558.     LINE *t = line;
  559.     LINE  l = {" ", 0, 0, 0, 0, 0, NULL, NULL};
  560.     int   i = y;
  561.  
  562.     top = line;
  563.  
  564.     if (y >= maxy)
  565.         return;
  566.  
  567.     if (!line)
  568.     {
  569.         WClear(0, y, maxx - 1, maxy - 1, cm[CM_NTXT]);
  570.         return;
  571.     }
  572.  
  573.     while (t && i <= maxy - 1)
  574.     {
  575.         PutLine(t, i);
  576.         t = t->next; i++;
  577.     }
  578.     if (i <= maxy - 1)
  579.     {
  580.         while (i <= maxy - 1)
  581.         {
  582.             PutLine(&l, i);
  583.             i++;
  584.         }
  585.     }
  586. }
  587.  
  588. /* end */
  589.