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

  1. /*
  2. ** Module   :DIALOG.H
  3. ** Abstract :Dialog box controls
  4. **
  5. ** Copyright (C) Sergey I. Yevtushenko
  6. **
  7. ** Log: Sat  08/11/1997       Created
  8. */
  9.  
  10. #include <common.h>
  11. #include <buffer.h>
  12.  
  13. #ifndef  __DIALOG_H
  14. #define  __DIALOG_H
  15.  
  16. //-----------------------------------------------------------
  17. // Basic control
  18. //-----------------------------------------------------------
  19.  
  20. class Control;
  21. typedef Control* PControl;
  22.  
  23. class Control: public Rect
  24. {
  25.     protected:
  26.         int active;
  27.         int hotkey;
  28.  
  29.     public:
  30.  
  31.         Control(int r, int c, int nr, int nc);
  32.         virtual ~Control()              {}
  33.  
  34.         virtual void draw()             {}
  35.         virtual int  select(int i=0)    { active = i; return active;}
  36.         virtual void do_key(KeyInfo&)   {}
  37.         virtual char mk_clr(int)        { return 0;}
  38.         virtual void move(int r, int c) { row = r;  col = c; }
  39.         virtual void size(int r, int c) { rows = r; cols = c;}
  40. };
  41.  
  42. //-----------------------------------------------------------
  43. // Dialog
  44. //-----------------------------------------------------------
  45.  
  46. class Dialog: public Collection, public Control
  47. {
  48.         void *savebuff;
  49.         int   current;
  50.  
  51.         PControl control(int i) { return PControl(Get(i));}
  52.  
  53.     public:
  54.  
  55.         Dialog(int r, int c, int nr, int nc);
  56.         virtual ~Dialog();
  57.  
  58.         virtual void Free(Ptr p);
  59.         virtual void Ins(Control*);
  60.  
  61.         virtual void draw();
  62.  
  63.         PControl in_focus() { return (current < 0) ? 0:control(current);}
  64.  
  65.         void next();
  66.         void prev();
  67.  
  68.         virtual void do_key(KeyInfo&);
  69.         virtual char mk_clr(int index)  { return app_pal[CL_DIALOG_START+index];}
  70.         virtual void move(int r, int c);
  71. };
  72.  
  73. //-----------------------------------------------------------
  74. // Static text control
  75. //-----------------------------------------------------------
  76.  
  77. class StaticText: public Control
  78. {
  79.     protected:
  80.         char *text;
  81.  
  82.     public:
  83.  
  84.         StaticText(int r, int c, int nr, int nc, char *aText);
  85.  
  86.         virtual ~StaticText();
  87.  
  88.         virtual int  select(int = 0)    { return 0;}
  89.         virtual void draw();
  90.         virtual char mk_clr(int index)  { return app_pal[CL_STEXT_START+index];}
  91.  
  92.         void set_text(char *txt);
  93. };
  94.  
  95. //-----------------------------------------------------------
  96. // List box control
  97. //-----------------------------------------------------------
  98.  
  99. class ListBoxItem
  100. {
  101.     friend class ListBox;
  102.         enum lbiFlags
  103.         {
  104.             lbiSelected = 0x0001
  105.         };
  106.  
  107.         unsigned int userdata;
  108.         int flags;
  109.         int len;
  110.         char *text;
  111.  
  112.     public:
  113.  
  114.         ListBoxItem(char *aText):flags(0),len(0),text(0) {set_text(aText);}
  115.         ~ListBoxItem();
  116.  
  117.         char* get_text() { return text;}
  118.         void set_text(char *text);
  119. };
  120.  
  121. typedef ListBoxItem* PListBoxItem;
  122.  
  123. class ListBox: public Collection, public Control
  124. {
  125.     protected:
  126.         int flags;
  127.  
  128.         int start_row;
  129.         int cur_row;
  130.         int index_ptr;
  131.         int start_x;
  132.         int last_sel_was_key;
  133.  
  134.         void prev();
  135.         void next();
  136.         void sel(KeyInfo&);
  137.         PListBoxItem item(int ndx) { return PListBoxItem(Get(ndx));}
  138.         PListBoxItem cur_item()    { return PListBoxItem(Get(start_row+cur_row));}
  139.  
  140.         char item_char(int ndx);
  141.  
  142.     public:
  143.         enum lbFlags
  144.         {
  145.             lbCanScroll = 0x0001,
  146.             lbMultiSel  = 0x0002,
  147.             lbHilite    = 0x0004,
  148.             lbWrap      = 0x0008,
  149.             lbXScroll   = 0x0010
  150.         };
  151.  
  152.         ListBox(int r, int c, int nr, int nc, int opt = lbCanScroll);
  153.         virtual ~ListBox();
  154.  
  155.         virtual void Free(Ptr p);
  156.  
  157.         virtual void draw();
  158.  
  159.         int first_selected();
  160.         int next_selected();
  161.  
  162.         char * get_item_text(int);
  163.         void set_item_text(int, char*);
  164.  
  165.         unsigned int get_item_key(int);
  166.         void set_item_key(int, unsigned int);
  167.  
  168.         void add_item(char *text, int pos);
  169.         void add_at_begin(char *text)     { add_item(text, 0); }
  170.         void add_at_end(char *text)       { add_item(text, Count()); }
  171.         void del_item(int index);
  172.         void go_item(int index);
  173.  
  174.         virtual void do_key(KeyInfo&);
  175.         virtual char mk_clr(int index);
  176.         int abs_row()                   { return start_row+cur_row;}
  177.  
  178.         int selected_by_key()           { return last_sel_was_key;}
  179. };
  180.  
  181. //-----------------------------------------------------------
  182. // Menu control
  183. //-----------------------------------------------------------
  184.  
  185. class Menu: public ListBox
  186. {
  187.     public:
  188.         Menu(int r, int c, char **itemlist);
  189.         void add_menu(char* item);
  190.         virtual char mk_clr(int index);
  191. };
  192.  
  193. //-----------------------------------------------------------
  194. // class EditLine
  195. //-----------------------------------------------------------
  196.  
  197. class EditLine:public Control, public Buffer
  198. {
  199.     public:
  200.  
  201.         EditLine(int Row, int Col, int nRows, int nCols);
  202.  
  203.         void get_text(char *buff, int max_len);
  204.         void set_text(char *);
  205.  
  206.         virtual int  select(int i=0);
  207.         virtual void do_key(KeyInfo&);
  208.         virtual void draw();
  209. };
  210.  
  211. //----------------------------------------------------------------------
  212. // class JumpEntryHolder
  213. //----------------------------------------------------------------------
  214. class JumpEntryHolder;
  215. typedef class JumpEntryHolder* PJumpEntry;
  216.  
  217. class JumpEntryHolder
  218. {
  219.         int row;
  220.         int col;
  221.         char *text;
  222.         char *hdr;
  223.     public:
  224.         JumpEntryHolder(int row, int col, char *name, char *file);
  225.         ~JumpEntryHolder();
  226.  
  227.         int get_row()    { return row; }
  228.         int get_col()    { return col; }
  229.         char *get_file() { return text;}
  230.         char *get_name() { return hdr; }
  231. };
  232.  
  233. class JumpList;
  234. typedef JumpList* PJumpList;
  235.  
  236. class JumpList: public Collection
  237. {
  238.         int last_pos;
  239.     public:
  240.         JumpList():Collection(5,5),last_pos(0) {}
  241.         virtual ~JumpList();
  242.  
  243.         PJumpEntry get_entry(unsigned ndx) { return (PJumpEntry)Get(ndx);}
  244.         void add_entry(int row, int col, char *name, char *file);
  245.  
  246.         int  get_last_pos()        { return last_pos;}
  247.         void set_last_pos(int pos) { last_pos = (pos >= 0 && pos < Count()) ? pos: last_pos;}
  248. };
  249.  
  250. #endif //__DIALOG_H
  251.  
  252.