home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1999 November / PCOnline_11_1999.iso / filesbbs / OS2 / MMSRC029.ZIP / mmail-0.29 / interfac / interfac.h < prev    next >
C/C++ Source or Header  |  1999-08-23  |  12KB  |  573 lines

  1. /*
  2.  * MultiMail offline mail reader
  3.  * most class definitions for the interface
  4.  
  5.  Copyright (c) 1996 Kolossvary Tamas <thomas@tvnet.hu>
  6.  Copyright (c) 1997 John Zero <john@graphisoft.hu>
  7.  Copyright (c) 1999 William McBrine <wmcbrine@clark.net>
  8.  
  9.  Distributed under the GNU General Public License.
  10.  For details, see the file COPYING in the parent directory. */
  11.  
  12. #ifndef INTERFACE_H
  13. #define INTERFACE_H
  14.  
  15. #define USE_SHADOWS    // "Shadowed" windows
  16. #define MM_TOPHEADER "%s offline reader v%d.%d"
  17.  
  18. #include "../mmail/mmail.h"
  19.  
  20. #include <csignal>
  21.  
  22. extern "C" {
  23. #include CURS_INC
  24. }
  25.  
  26. #include "mmcolor.h"
  27. #include "isoconv.h"
  28.  
  29. enum direction {UP, DOWN, PGUP, PGDN, HOME, END};
  30. enum statetype {nostate, packetlist, arealist, letterlist, letter,
  31.         letter_help, littlearealist, address, tagwin, ansiwin,
  32.         ansi_help};
  33. enum searchret {False, True, Abort};
  34.  
  35. enum {s_fulltext = 1, s_headers, s_arealist, s_pktlist};
  36.  
  37. #if defined (SIGWINCH) && !defined (XCURSES)
  38. void sigwinchHandler(int);
  39. #endif
  40.  
  41. #define TAGLINE_LENGTH 76
  42.  
  43. /* Include Keypad keys for PDCurses */
  44.  
  45. #ifdef __PDCURSES__
  46. # define MM_PLUS '+': case PADPLUS
  47. # define MM_MINUS '-': case PADMINUS
  48. # define MM_ENTER '\r': case '\n': case PADENTER
  49. # define MM_SLASH '/': case PADSLASH
  50. #else
  51. # define MM_PLUS '+'
  52. # define MM_MINUS '-'
  53. # define MM_ENTER '\r': case '\n'
  54. # define MM_SLASH '/'
  55. #endif
  56.  
  57. class tagline
  58. {
  59.  public:
  60.      tagline(const char * = 0);
  61.      tagline *next;
  62.      char text[TAGLINE_LENGTH + 1];
  63. };
  64.  
  65. class ColorClass : public baseconfig
  66. {
  67.     static chtype allcolors[];
  68.     static const char *col_names[], *col_intro[], *col_comments[];
  69.     static const chtype mapped[];
  70.  
  71.     chtype colorparse(const char *);
  72.     void processOne(int, const char *);
  73.     const char *configLineOut(int);
  74.     const char *findcol(chtype);
  75.     const char *decompose(chtype);
  76.  public:
  77.     void Init();
  78. };
  79.  
  80. class Win
  81. {
  82.  protected:
  83.     WINDOW *win;
  84.  public:
  85.     Win(int, int, int, chtype);
  86.     ~Win();
  87.     void Clear(chtype);
  88.     void put(int, int, chtype);
  89.     void put(int, int, char);
  90.     void put(int, int, const chtype *, int = 0);
  91.     int put(int, int, const char *);
  92.     void attrib(chtype);
  93.     void horizline(int, int);
  94.     void update();
  95.     void delay_update();
  96.     void wtouch();
  97.     void wscroll(int);
  98.     void cursor_on();
  99.     void cursor_off();
  100.     int keypressed();
  101.     int inkey();
  102.     void boxtitle(chtype, const char *, chtype);
  103. };
  104.  
  105. class ShadowedWin : public Win
  106. {
  107. #ifdef USE_SHADOWS
  108.     WINDOW *shadow;
  109. #endif
  110.  public:
  111.     ShadowedWin(int, int, int, chtype, const char * = 0, chtype = 0);
  112.     ~ShadowedWin();
  113.     void touch();
  114.     int getstring(int, int, char *, int, chtype, chtype);
  115. };
  116.  
  117. class InfoWin : public ShadowedWin
  118. {
  119.     Win *info;
  120.  public:
  121.     char *lineBuf;
  122.  
  123.     InfoWin(int, int, int, chtype, const char * = 0,
  124.         chtype = 0, int = 3, int = 2);
  125.     ~InfoWin();
  126.     void irefresh();
  127.     void touch();
  128.     void oneline(int, chtype);
  129.     void iscrl(int);
  130. };
  131.  
  132. class ListWindow
  133. {
  134.  private:
  135.     bool lynxNav;    //use Lynx-like navigation?
  136.     bool useScrollBars;
  137.     int oldPos;    //position at last Draw()
  138.     int oldActive;    //active at last Draw()
  139.     int oldHigh;    //location of highlight bar at last Draw()
  140.  
  141.     void checkPos(int);
  142.     chtype setHighlight(chtype);
  143.  protected:
  144.     InfoWin *list;
  145.       int list_max_y, list_max_x, top_offset;
  146.     int position;    //the first element in the window
  147.     int active;    //this is the highlited    
  148.  
  149.     chtype borderCol;
  150.  
  151.     void Draw();        //refreshes the window
  152.     void DrawOne(int, chtype);
  153.     void DrawAll();
  154.     virtual int NumOfItems() = 0;
  155.     virtual void oneLine(int) = 0;
  156.     virtual searchret oneSearch(int, const char *, int) = 0;
  157.     virtual bool extrakeys(int) = 0;
  158.  public:
  159.      ListWindow();
  160.     virtual ~ListWindow();
  161.     void Move(direction);        //scrolloz
  162.     void setActive(int);
  163.     int getActive();
  164.     searchret search(const char *, int);
  165.     bool KeyHandle(int);
  166.     virtual void Delete() = 0;
  167.     virtual void Prev();
  168.     virtual void Next();
  169. };
  170.  
  171. class Welcome
  172. {
  173.      ShadowedWin *window;
  174.  public:
  175.      void MakeActive();
  176.      void Delete();
  177. };
  178.  
  179. class Person
  180. {
  181.     void Init(const char *);
  182.  public:
  183.      Person *next;
  184.      char name[45];
  185.      net_address netmail_addr;
  186.  
  187.     Person(const char * = 0, const char * = 0);
  188.     Person(const char *, net_address &);
  189.     void dump(FILE *);
  190. };
  191.  
  192. class AddressBook : public ListWindow
  193. {
  194.     Person head, *curr, *highlighted, **people;
  195.     const char *addfname;
  196.     int NumOfPersons;
  197.     bool NoEnter, inletter;
  198.  
  199.       int NumOfItems();
  200.     void oneLine(int);
  201.     searchret oneSearch(int, const char *, int);
  202.     bool extrakeys(int);
  203.  
  204.     void Add(const char *, net_address &);
  205.     void GetAddress();
  206.     int HeaderLine(ShadowedWin &, char *, int, int, int);
  207.     int Edit(Person &);
  208.     void NewAddress();
  209.     void ChangeAddress();
  210.      void ReadFile();
  211.      void DestroyChain();
  212.     friend int perscomp(const void *, const void *);
  213.     void MakeChain();
  214.     void ReChain();
  215.      void SetLetterThings();
  216.     void WriteFile();
  217.     void kill();
  218. public:
  219.     AddressBook();
  220.     ~AddressBook();
  221.     void MakeActive(bool);
  222.     void Delete();
  223.     void Init();
  224. };
  225.  
  226. class TaglineWindow : public ListWindow
  227. {
  228.     tagline head, *curr, *highlighted, **taglist;
  229.     const char *tagname;
  230.       int NumOfTaglines;
  231.     bool nodraw;
  232.  
  233.      int NumOfItems();
  234.     void oneLine(int);
  235.     searchret oneSearch(int, const char *, int);
  236.     bool extrakeys(int);
  237.  
  238.     void kill();
  239.     bool ReadFile();
  240.     void WriteFile(bool);
  241.     void DestroyChain();
  242.     void MakeChain();
  243.     void RandomTagline();
  244.  public:
  245.      TaglineWindow();
  246.     ~TaglineWindow();
  247.     void MakeActive();
  248.     void Delete();
  249.      void EnterTagline(const char * = 0);
  250.     void EditTagline();
  251.     void Init();
  252.     const char *getCurrent();
  253. };
  254.  
  255. class LittleAreaListWindow : public ListWindow
  256. {
  257.     int disp, areanum;
  258.  
  259.     int NumOfItems();
  260.     void oneLine(int);
  261.     searchret oneSearch(int, const char *, int);
  262.     bool extrakeys(int);
  263.     void Select();
  264.  public:
  265.      void MakeActive();
  266.      void Delete();
  267.     int getArea();
  268. };
  269.  
  270. class PacketListWindow : public ListWindow
  271. {
  272.     Welcome welcome;
  273.     file_list *dirList, *packetList;
  274.     const char *currDir, *origDir;
  275.     time_t currTime;
  276.     int noDirs, noFiles;
  277.     bool sorttype;
  278.  
  279.     int NumOfItems();
  280.     void oneLine(int);
  281.     searchret oneSearch(int, const char *, int);
  282.     bool extrakeys(int);
  283.  
  284.     void newList();
  285.     void error();
  286.     void gotoDir();
  287.     void renamePacket();
  288.     void killPacket();
  289.  public:
  290.     PacketListWindow();
  291.     ~PacketListWindow();
  292.      void MakeActive();
  293.      void Delete();
  294.     void Select();
  295.     pktstatus OpenPacket();
  296.     bool back();
  297. };
  298.  
  299. class AreaListWindow : public ListWindow
  300. {
  301.     char format[40], format2[40];
  302.     bool mode;
  303.  
  304.      int NumOfItems();
  305.     void oneLine(int);
  306.     searchret oneSearch(int, const char *, int);
  307.     bool extrakeys(int);
  308.  
  309.  public:
  310.     void ResetActive();
  311.      void MakeActive();
  312.      void Delete();
  313.     void Select();
  314.     void ReDraw();
  315.     void FirstUnread();
  316.     void Prev();
  317.     void Next();
  318. };
  319.  
  320. class LetterListWindow : public ListWindow
  321. {
  322.     char format[50];
  323.  
  324.     int NumOfItems();
  325.     void oneLine(int);
  326.     searchret oneSearch(int, const char *, int);
  327.     bool extrakeys(int);
  328.  
  329.     void listSave();
  330.  public:
  331.     LetterListWindow();
  332.     void ResetActive();
  333.     void MakeActive();
  334.     void Delete();
  335.     void Select();
  336.     void FirstUnread();
  337.     void Prev();
  338.     void Next();
  339. };
  340.  
  341. class Line
  342. {
  343.  public:
  344.     Line *next;
  345.     char *text;
  346.     unsigned length;
  347.     bool quoted, hidden, tearline, tagline, origin;
  348.  
  349.      Line(int);
  350.     ~Line();
  351. };
  352.  
  353. class LetterWindow
  354. {
  355.     Win *headbar, *header, *text, *statbar;
  356.     Line **linelist;
  357.     char key, tagline1[TAGLINE_LENGTH + 1], To[30];
  358.     int letter_in_chain;    //0 = no letter in chain
  359.     int position;        //which row is the first in the text window
  360.     int NumOfLines;
  361.     int y;            //height of the window, set by MakeActive
  362.     int replyto_area, stripCR, beepPers;
  363.     bool rot13, hidden, lynxNav;
  364.     net_address NM;
  365.  
  366.     void lineCount();
  367.     void oneLine(int);
  368.     void Move(int);
  369.     char *netAdd(char *);
  370.     int HeaderLine(ShadowedWin &, char *, int, int, int);
  371.     int EnterHeader(char *, char *, char *, bool &);
  372.     void QuoteText(FILE *);
  373.     void DestroyChain();
  374.     void editletter(const char *);
  375.     void setToFrom(char *, char *);
  376.     void EditLetter(bool);
  377.     bool SplitLetter(int = 0);
  378.     long reconvert(const char *);
  379.     void write_header_to_file(FILE *);
  380.     void write_to_file(FILE *);
  381.     void GetTagline();
  382.     bool Previous();
  383.     void NextDown();
  384.     void MakeChain(int, bool = false);
  385.      void DrawHeader();
  386.      void DrawBody();
  387.     void DrawStat();
  388.     bool EditOriginal();
  389.  public:
  390.     LetterWindow();
  391.      void MakeActive(bool);
  392.      void Delete();
  393.     bool Next();
  394.      void Draw(bool = false);
  395.     void ReDraw();
  396.     bool Save(int);
  397.     void EnterLetter();
  398.     void StatToggle(int);
  399.     net_address &PickNetAddr();
  400.     void set_Letter_Params(int, char);
  401.     void set_Letter_Params(net_address &, const char *);
  402.     void setPos(int);
  403.     int getPos();
  404.     searchret search(const char *);
  405.     void SplitAll(int);
  406.     void KeyHandle(int);
  407. };
  408.  
  409. class HelpWindow
  410. {
  411.      Win *menu;
  412.     int midpos, endpos, base, items;
  413.  
  414.     void newHelpMenu(const char **, const char **, int);
  415.     void h_packetlist();
  416.     void h_arealist();
  417.     void h_letterlist();
  418.     void h_letter(bool);
  419.  public:
  420.     HelpWindow();
  421.     void MakeActive();
  422.     void Delete();
  423.     void baseNext();
  424.     void baseReset();
  425. };
  426.  
  427. class AnsiLine
  428. {
  429.  private:
  430.     AnsiLine *prev, *next;
  431.  public:
  432.     AnsiLine *getprev();
  433.     AnsiLine *getnext(int = 0);
  434.     chtype *text;
  435.     unsigned length;
  436.      AnsiLine(int = 0, AnsiLine * = 0);
  437.     ~AnsiLine();
  438. };
  439.  
  440. class AnsiWindow
  441. {
  442.     bool colorsused[64];
  443.     char escparm[256];    //temp copy of ESC sequence parameters
  444.     const char *title;
  445.     file_header *fromFile;
  446.     const unsigned char *source;
  447.     Win *header, *text, *statbar, *animtext;
  448.     AnsiLine *head, *curr, **linelist;
  449.     int position;        //which row is the first in the window
  450.     int NumOfLines;
  451.     int x, y;        //dimensions of the window
  452.     int cpx, cpy, lpy;    //ANSI positions
  453.     int spx, spy;        //stored ANSI positions
  454.     int ccf, ccb, cfl, cbr, crv;    //colors and attributes
  455.     int oldcolorx, oldcolory;
  456.     int baseline;        //base for positions in non-anim mode
  457.     bool anim;        //animate mode?
  458.     bool ansiAbort, sourceDel;
  459.     chtype attrib;        //current attribute
  460.  
  461.     void oneLine(int);
  462.     void lineCount();
  463.     void DrawBody();
  464.     int getparm();
  465.     void colreset();
  466.     void colorset();
  467.     const unsigned char *escfig(const unsigned char *);
  468.     void posreset();
  469.     void checkpos();
  470.     void update(unsigned char);
  471.     void ResetChain();
  472.     void MakeChain(const unsigned char *);
  473.     void DestroyChain();
  474.     void animate();
  475.     void statupdate(const char * = 0);
  476.     void getFile();
  477.     void Save();
  478.  public:
  479.     void set(const char *, const char *);
  480.     void setFile(file_header *, const char * = 0);
  481.     void MakeActive();
  482.     void Delete();
  483.     void setPos(int);
  484.     int getPos();
  485.     searchret search(const char *);
  486.     void KeyHandle(int);
  487. };
  488.  
  489. class Interface
  490. {
  491.     PacketListWindow packets;
  492.     AddressBook addresses;
  493.     HelpWindow helpwindow;
  494.     LittleAreaListWindow littleareas;
  495.  
  496.     Win *screen;
  497.     ListWindow *currList;
  498.      statetype state, prevstate, searchstate;
  499.     const char *searchItem, *cmdpktname;
  500.     file_header *newFiles, **bulletins;
  501.     int Key, searchmode, s_oldpos;
  502.     bool unsaved_reply, any_read, addrparm, commandline, abortNow,
  503.         dontSetAsRead, lynxNav;
  504. #ifdef SIGWINCH
  505.     bool resized;
  506.  
  507.     void sigwinch();
  508. #endif
  509.     void init_colors();
  510.     void oldstate(statetype);
  511.     void helpreset(statetype);
  512.     void newstate(statetype);
  513.     void alive();
  514.     void screen_init();
  515.     const char *pkterrmsg(pktstatus);
  516.     void newpacket();
  517.     void create_reply_packet();
  518.     void save_read();
  519.     int ansiCommon();
  520.     void searchNext();
  521.     void searchSet();
  522.     void KeyHandle();
  523.  public:
  524.     ColorClass colorlist;
  525.     AreaListWindow areas;
  526.     LetterListWindow letters;
  527.     LetterWindow letterwindow;
  528.     TaglineWindow taglines;
  529.     AnsiWindow ansiwindow;
  530.  
  531.      Interface();
  532.     ~Interface();
  533.     void init();
  534.     void main();
  535.      int WarningWindow(const char *, const char ** = 0, int = 2);
  536.     int savePrompt(const char *, char *);
  537.     void nonFatalError(const char *);
  538.     void changestate(statetype);
  539.     void redraw();
  540.      bool select();
  541.      bool back();        //returns true if we have to quit
  542.     statetype active();
  543.     statetype prevactive();
  544. #ifdef SIGWINCH
  545.     void setResized();
  546. #endif
  547.     void addressbook(bool = false);
  548.     bool Tagwin();
  549.     int ansiLoop(const char *, const char *);
  550.     int ansiFile(file_header *, const char * = 0);
  551.     int areaMenu();
  552.     void kill_letter();
  553.     void setUnsaved();
  554.     void setUnsavedNoAuto();
  555.     void setAnyRead();
  556.     void setKey(int);
  557.     bool dontRead();
  558.     bool fromCommandLine(const char *);
  559. };
  560.  
  561. extern mmail mm;
  562. extern Interface *interface;
  563.  
  564. #if defined (__PDCURSES__) && !defined (XCURSES)
  565. extern "C" {
  566. int PDC_get_cursor_mode();
  567. int PDC_set_cursor_mode(int, int);
  568. }
  569. extern int curs_start, curs_end;
  570. #endif
  571.  
  572. #endif
  573.