home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / include / textviewer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-24  |  3.7 KB  |  157 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1987, 1988, 1989 Stanford University
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8.   /**
  9.      stolen from the InterViews 2.5 source files (text directory, which 
  10.      is unsupported in 2.6.  
  11.    **/
  12.  
  13. /*
  14.  * TextViewer - basic text buffer
  15.  */
  16.  
  17. #ifndef textviewer_h
  18. #define textviewer_h
  19.  
  20. #include <InterViews/interactor.h>
  21. #include <InterViews/paint.h>
  22. #include <InterViews/painter.h>
  23.  
  24. enum CaretStyle { None, Bar, Block, Outline, Underline };
  25.  
  26. struct StyleSet {
  27.     char flags;
  28.  
  29.     StyleSet() { Plain(); }
  30.     StyleSet(char c) { flags = c; }
  31.     operator char() { return flags; }
  32.  
  33.     void Plain() { flags = 0; }
  34.     void Add(TextStyle s) { flags |= (1<<s); }
  35.     void Remove(TextStyle s) { flags &= ~(1<<s); }
  36.     boolean Includes(TextStyle s) { return flags& (1<<s); }
  37. };
  38.  
  39. class TPainter : public Painter {
  40. public:
  41.     TPainter() { }
  42.     TPainter(Painter* p) : (p) { }
  43.     void StyledText(Canvas*, const char*, int, StyleSet);
  44.     void Reverse() { SetColors(GetBgColor(), GetFgColor()); }
  45. };
  46.  
  47. struct TextLine {
  48.     TextLine* above;            // links
  49.     TextLine* below;
  50.  
  51.     char* text;
  52.     char* attr;
  53.     int size;                // space allocated
  54.     int length;                // characters in line
  55.     boolean touched;
  56.  
  57.     TextLine();
  58.     ~TextLine();
  59.  
  60.     void Size(int);            // grow if needed
  61.  
  62.     void Replace(int index, const char*, int len, char attr);
  63.     void Insert(int index, const char*, int len, char attr);
  64.     void Delete(int index, int len);
  65.     void Blank(int index, int len);
  66.     void EndLine(int);
  67.  
  68.     TextLine* Split(int index);
  69.     void Merge(TextLine*);
  70. };
  71.  
  72. class TextViewer : public Interactor {
  73. public:
  74.     TextViewer(Painter* out = stdpaint, int cols = 80, int rows = 24);
  75.     ~TextViewer();
  76.  
  77.     virtual void Draw();
  78.     virtual void Redraw(Coord, Coord, Coord, Coord);
  79.     virtual void Handle(Event&);
  80.     virtual void Resize();
  81.     virtual void Adjust(Perspective&);
  82.     virtual void Reshape(Shape&);
  83.  
  84.     CaretStyle caretstyle;        /* type of caret */
  85.     StyleSet style;            /* current text style */
  86.  
  87.     boolean overwrite;            /* replace or move old text? */
  88.     boolean buffer;            /* don't update immediately? */
  89.     boolean viewcaret;            /* keep caret in view? */
  90.  
  91.     void NoCaret();
  92.     void Caret();            /* at dot */
  93.     void Caret(Coord row, Coord col);
  94.     void View();            /* dot */
  95.     void View(Coord row, Coord col);
  96.     void GoTo(Coord row, Coord col);
  97.     void GetPos(Coord& row, Coord& col);/* of dot */
  98.  
  99.     void Margin(int);
  100.     void Indent(int count);
  101.  
  102.     void Insert(int rows, int cols);    /* insert or delete before dot */
  103.  
  104.     void String(const char*, int);
  105.     void String(const char*);
  106.     void NewLine();
  107.     void Rubout(int count);
  108.     void Tab(int spacing);
  109.     void Spaces(int count);
  110.  
  111.     void EndLine();                // after dot
  112.     void EndText();                // after dot
  113.  
  114.     void Flush();
  115. protected:
  116.     TPainter* painter;
  117.     TPainter* highlight;
  118.  
  119.     TextLine* top;
  120.     TextLine* bottom;
  121.  
  122.     TextLine* prev;
  123.     Coord prow;
  124.  
  125.     TextLine* dot;
  126.     Coord row, col;
  127.  
  128.     TextLine* caret;
  129.     Coord crow, ccol;
  130.  
  131.     int margin;
  132.  
  133.     Coord YPix(Coord y);
  134.     Coord YChar(Coord y);
  135.     Coord XPix(TextLine*, Coord);
  136.     Coord XChar(TextLine*, Coord);
  137.     void ToPix(Coord& x, Coord& y);
  138.     void ToChar(Coord& x, Coord& y);
  139.  
  140.     TextLine* FindLine(Coord y);
  141.     void Position(TextLine*&, Coord& row, Coord& col);
  142.  
  143.     void AddLine(TextLine* before, TextLine* newLine);
  144.     void AddLines(TextLine* before, int count);
  145.     void RemoveLine(TextLine* before);
  146.     void RemoveLines(TextLine* before, int count);
  147.  
  148.     void DrawLine(TextLine*, Coord baseline, Coord first, Coord last);
  149.     void FlushLine(TextLine*, Coord baseline);
  150.  
  151.     void HideCaret();
  152.     void ShowCaret();
  153.     void BringToView(Coord row, Coord col);
  154. };
  155.  
  156. #endif
  157.