LCOV - code coverage report
Current view: top level - engine/interface - textedit.h (source / functions) Coverage Total Hit
Test: Libprimis Test Coverage Lines: 0.0 % 16 0
Test Date: 2025-02-21 06:59:27 Functions: 0.0 % 4 0

            Line data    Source code
       1              : #ifndef TEXTEDIT_H_
       2              : #define TEXTEDIT_H_
       3              : 
       4              : struct EditLine
       5              : {
       6              :     enum { Chunk_Size = 256 };
       7              : 
       8              :     char *text;
       9              :     int len, maxlen;
      10              : 
      11            0 :     EditLine() : text(nullptr), len(0), maxlen(0) {}
      12            0 :     EditLine(const char *init) : text(nullptr), len(0), maxlen(0)
      13              :     {
      14            0 :         set(init);
      15            0 :     }
      16              : 
      17              :     bool empty();
      18              :     void clear();
      19              :     bool grow(int total, const char *fmt = "", ...);
      20              :     void set(const char *str, int slen = -1);
      21              :     void prepend(const char *str);
      22              :     void append(const char *str);
      23              :     bool read(std::fstream& f, int chop = -1);
      24              :     void del(int start, int count);
      25              :     void chop(int newlen);
      26              :     void insert(char *str, int start, int count = 0);
      27              :     void combinelines(std::vector<EditLine> &src);
      28              : };
      29              : 
      30              : enum
      31              : {
      32              :     Editor_Focused = 1,
      33              :     Editor_Used,
      34              :     Editor_Forever
      35              : };
      36              : 
      37              : class Editor
      38              : {
      39              :     public:
      40              :         int mode; //editor mode - 1= keep while focused, 2= keep while used in gui, 3= keep forever (i.e. until mode changes)
      41              :         bool active, rendered;
      42              :         std::string name;
      43              :         const char *filename;
      44              : 
      45              :         int maxx, maxy; // maxy=-1 if unlimited lines, 1 if single line editor
      46              : 
      47              :         bool linewrap;
      48              :         int pixelwidth; // required for up/down/hit/draw/bounds
      49              :         int pixelheight; // -1 for variable sized, i.e. from bounds()
      50              : 
      51              :         std::vector<EditLine> lines; // MUST always contain at least one line!
      52              : 
      53            0 :         Editor(std::string name, int mode, const char *initval) :
      54            0 :             mode(mode), active(true), rendered(false), name(name), filename(nullptr),
      55            0 :             maxx(-1), maxy(-1), linewrap(false), pixelwidth(-1), pixelheight(-1),
      56            0 :             cx(0), cy(0), mx(-1), my(-1), scrolly(0)
      57              :         {
      58              :             //printf("editor %08x '%s'\n", this, name);
      59            0 :             lines.emplace_back();
      60            0 :             lines.back().set(initval ? initval : "");
      61            0 :         }
      62              : 
      63            0 :         ~Editor()
      64              :         {
      65              :             //printf("~editor %08x '%s'\n", this, name);
      66            0 :             delete[] filename;
      67              : 
      68            0 :             filename = nullptr;
      69            0 :             clear(nullptr);
      70            0 :         }
      71              : 
      72              :         bool empty();
      73              :         void clear(const char *init = "");
      74              :         void init(const char *inittext);
      75              :         void updateheight();
      76              :         void setfile(const char *fname);
      77              :         void load();
      78              :         void save();
      79              :         void mark(bool enable);
      80              :         void selectall();
      81              :         bool region();
      82              :         EditLine &currentline();
      83              :         void copyselectionto(Editor *b);
      84              :         char *tostring();
      85              :         char *selectiontostring();
      86              :         void insert(const char *s);
      87              :         void insertallfrom(const Editor * const b);
      88              :         void scrollup();
      89              :         void scrolldown();
      90              :         void key(int code);
      91              :         void input(const char *str, int len);
      92              :         void hit(int hitx, int hity, bool dragged);
      93              :         void draw(int x, int y, int color);
      94              :     private:
      95              :         int cx, cy; // cursor position - ensured to be valid after a region() or currentline()
      96              :         int mx, my; // selection mark, mx=-1 if following cursor - avoid direct access, instead use region()
      97              :         int scrolly; // vertical scroll offset
      98              : 
      99              :         void removelines(int start, int count);
     100              :         bool region(int &sx, int &sy, int &ex, int &ey);
     101              :         bool del(); // removes the current selection (if any)
     102              :         void insert(char ch);
     103              :         bool readback(std::fstream& file);
     104              : };
     105              : 
     106              : extern void readyeditors();
     107              : extern void flusheditors();
     108              : extern Editor *useeditor(std::string name, int mode, bool focus, const char *initval = nullptr);
     109              : 
     110              : #endif
        

Generated by: LCOV version 2.0-1