home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / fed0217s.zip / include / buffer.h < prev    next >
C/C++ Source or Header  |  2001-08-08  |  7KB  |  256 lines

  1. /*
  2. ** Module   :BUFFER.H
  3. ** Abstract :General purpose edit buffer
  4. **
  5. ** Copyright (C) Sergey I. Yevtushenko
  6. **
  7. ** Log: Sun  06/04/1997       Created from stripped down EDIT.H
  8. **      Fri  07/11/1997       Updated for UNDO implementation
  9. */
  10.  
  11. #include <line.h>
  12. #include <_ctype.h>
  13.  
  14. #ifndef  __BUFFER_H
  15. #define  __BUFFER_H
  16.  
  17. #define WW_STATE        0x01    /* Word wrap state on/off */
  18. #define WW_MERGE        0x02    /* Merge wrapped part with next line */
  19. #define WW_LONG         0x04    /* Reformat until changes are made */
  20.  
  21. class Buffer;
  22. typedef Buffer* PBuffer;
  23. typedef char (*PerCharFunc)(char);
  24. extern Buffer* Clipboard;
  25.  
  26. class Buffer: public Collection
  27. {
  28.         int num_cols;
  29.         int col_block;
  30.         int old_abs_col;
  31.         int old_abs_row;
  32.         int start_row;
  33.         int start_col;
  34.         int mark_state;
  35.         int cur_row;
  36.         int cur_col;
  37.         int ins_mode;
  38.         int hiliting;
  39.         int auto_indent;
  40.         int changed;
  41.         int undo_count;
  42.         int found_show;
  43.         int found_row;
  44.         int found_len;
  45.         int found_col;
  46.         int is_unix;
  47.         int custom_syntax;
  48.         int word_wrap;
  49.         int ww_width;
  50.  
  51.         char cp_in [256];
  52.         char cp_out[256];
  53.         char cur_cp[64];
  54.  
  55.         struct
  56.         {
  57.             int start_row;
  58.             int start_col;
  59.         } draw_save;
  60.  
  61.     public:
  62.  
  63.         int pal_start;
  64.         void ins_line(Line*, int);
  65.         void add_line(Line*);
  66.         Line* del_line(Rect& rect, int line_num);
  67.  
  68.         void dup_line(Rect& rect, int line_num);
  69.  
  70.         void fill_hiliting(int start, int initial_state);
  71.         void check_hiliting();
  72.  
  73.         Line* abs_line()        { return line(abs_row());}
  74.         Parser* gen_parser(int =0);
  75.  
  76.         struct trackinfo
  77.         {
  78.             int op;
  79.             void *arg1;
  80.             void *arg2;
  81.             trackinfo* next;
  82.         };
  83.  
  84.         enum track_op
  85.         {
  86.             opAction,
  87.             opCurRow,
  88.             opCurCol,
  89.             opStartRow,
  90.             opStartCol,
  91.             opRestoreLine,
  92.             opDelLine,
  93.             opInsLine,
  94.             opInsBlock,
  95.             opHiliting,
  96.             opMarking,
  97.             opMarkPos,
  98.             opColBlock,
  99.             opInsMode,
  100.             opInsChar,
  101.             opDelChar,
  102.             opRestoreOrder
  103.         };
  104.  
  105.         struct restore_sort
  106.         {
  107.             int start;
  108.             int len;
  109.             void* ptrs[1];
  110.         };
  111.  
  112.         int tracking;
  113.         trackinfo *track_head;
  114.         trackinfo *undobuff;
  115.  
  116.         void track(int op, void *arg1 = 0, void *arg2 = 0);
  117.  
  118.         void process_block(Rect&, PerCharFunc);
  119.         void init_buffer();
  120.  
  121.         Buffer(int sz);
  122.         Buffer();
  123.  
  124.         virtual ~Buffer();
  125.  
  126.         virtual void Free(Ptr p);
  127.  
  128.         void draw(Rect&);
  129.  
  130.         void from_pm();
  131.         void to_pm();
  132.  
  133.         void from_text(char *);
  134.         char* as_text();
  135.  
  136.         int abs_row()       { return cur_row + start_row;}
  137.         int abs_col()       { return cur_col + start_col;}
  138.  
  139.         int get_ins_mode()   { return ins_mode;}
  140.         int get_hiliting()   { return hiliting;}
  141.         int get_mark_state() { return mark_state;}
  142.         int get_auto_indent(){ return auto_indent;}
  143.  
  144.         int get_cur_row()   { return cur_row;}
  145.         int get_cur_col()   { return cur_col;}
  146.         int get_start_row() { return start_row;}
  147.         int get_start_col() { return start_col;}
  148.         char* get_cur_cp()  { return cur_cp;   }
  149.  
  150.  
  151.         int get_changed()   { return changed; }
  152.         int get_unix()      { return is_unix; }
  153.         int get_custom_syntax() { return custom_syntax;}
  154.  
  155.         int get_edit_row()   { return abs_row() + 1; }
  156.         int get_edit_col()   { return abs_col() + 1; }
  157.  
  158.         int get_edit_row_2() { return old_abs_row + 1; }
  159.         int get_edit_col_2() { return old_abs_col + 1; }
  160.  
  161.         int get_cur_char()   { return (unsigned char)abs_line()->char_at(abs_col());}
  162.         int get_rel_pos()    { return abs_row()*100/Count();}
  163.  
  164.         int get_column_block()  { return col_block;}
  165.         int get_undo_count();
  166.  
  167.         char chr_in (char c) { return cp_in [c];}
  168.         char chr_out(char c) { return cp_out[c];}
  169.  
  170.         int do_smart()       { return ((hiliting == HI_CPP ||
  171.                                         hiliting == HI_HTML||
  172.                                         hiliting == HI_PL) &&
  173.                                        auto_indent &&
  174.                                        abs_col()) ? 1:0;}
  175.  
  176. //-------------------------------------------------------------
  177.         void track_beg();
  178.         void track_end();
  179.         void track_cancel();
  180.         Line* line(int num) { return PLine(Get(num));}
  181.  
  182. //------------------ Cursor movement
  183.         void text_begin(Rect&);
  184.         void text_end(Rect&);
  185.         void line_begin(Rect&);
  186.         void line_end(Rect&);
  187.         void page_up(Rect&);
  188.         void page_down(Rect&);
  189.         void cursor_up(Rect&);
  190.         void cursor_down(Rect&);
  191.         void cursor_left(Rect&);
  192.         void cursor_right(Rect&);
  193.         void word_left(Rect&);
  194.         void word_right(Rect&);
  195.         void goto_line(Rect&, int);
  196.         void goto_col(Rect&, int);
  197.         void put_mouse(Rect& rect, int new_row, int new_col);
  198.         void match_bracket(Rect&);
  199.         int search(Rect& rect, char* flags, char *pattern);
  200.         int replace(Rect& rect, char *str);
  201.  
  202. //------------------- Editing
  203.         void ins_char(Rect&, int chr);
  204.         int  del_char(Rect&);
  205.         int  replace_char(Rect&, int chr);
  206.         void del_word_right(Rect&);
  207.         void del_word_left(Rect&);
  208.         void del_to_EOL(Rect&);
  209.         void split_line(Rect&);
  210.         void back_space(Rect&);
  211.         void undo(Rect&);
  212.         void toupper(Rect&);
  213.         void tolower(Rect&);
  214.         void indent();
  215.         void unindent();
  216.         void sort();
  217.  
  218. //------------------- Clipboard
  219.         Buffer* cut(Rect&);
  220.         Buffer* copy();
  221.         void clear(Rect&);
  222.         void paste(Rect&,Buffer*);
  223.         void paste_over(Rect&,Buffer*);     //Still unimplemented
  224.  
  225. //------------------- Marking
  226.         void mark();
  227.         void unmark();
  228.  
  229. //------------------ Other actions
  230.         void set_auto_indent(int mode) { auto_indent = (mode) ? 1:0;}
  231.         void set_column_block(int mode);
  232.         void set_ins_mode(int mode);
  233.         void set_changed(int i = 1);
  234.         void set_found(int start_row, int start_col, int len);
  235.         void set_unix(int mode)        { is_unix = (mode) ? 1:0;}
  236.         void clear_undobuff();
  237.         void set_xlate(char *cp);
  238.  
  239.         void flip_hiliting();
  240.         void set_hiliting(int mode);
  241.         void set_custom_syntax(int i)  { custom_syntax = i;}
  242.  
  243. //------------------ Word wrap
  244.         int ww_need(int ln);
  245.         int ww_perform(Rect&, int ln);
  246.         int ww_get()                   { return word_wrap;}
  247.         int ww_get_width()             { return ww_width;}
  248.         void ww_set(int flags)         { word_wrap = flags;}
  249.         void ww_set_width(int width)   { ww_width = (width > 1) ? width:ww_width;}
  250.  
  251.     protected:
  252.         int is_word_char()       { return __isic(chr_out(abs_line()->char_at(abs_col())));}
  253. };
  254.  
  255. #endif //__BUFFER_H
  256.