home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / cslib16b / include / csmenu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-01  |  4.7 KB  |  175 lines

  1. /***********************************************************************
  2.  
  3.                                        CSA Library, Version 1.6.b 
  4.                                          Released: March 2nd 1995 
  5.  
  6.        Definition of the MENU class.
  7.  
  8.                                            Copyright(c) 1994,1995 
  9.                                                            Combis 
  10.                                                   The Netherlands 
  11. ***********************************************************************/
  12.  
  13. #ifndef __CSMENU
  14. #define __CSMENU
  15.  
  16.  
  17. #define MENU_HOLD     1
  18. #define MENU_RELEASE  2
  19.  
  20. #define MENU_HOR      1
  21. #define MENU_VER      2
  22. #define MENU_HOVER    3
  23.  
  24. #define TO_SCREEN   FALSE
  25. #define TO_CURSOR   TRUE
  26.  
  27. #define MAX_OPTIONS 20
  28.  
  29. #include "string.h"
  30. #include "cswindow.h"
  31.  
  32.  
  33. ////////////////////////// OPTON class /////////////////////////////////////////
  34.  
  35.  
  36. class OPTION
  37. {
  38.  public:
  39.  
  40.   CSCHAR *opt;                   /* option string */
  41.   void *poi;                   /* pointer to submenu  */
  42.   int    rc;                   /* Return code */
  43.   int enable;
  44.  
  45. public:
  46.  
  47.   OPTION(void)                   { enable=TRUE; }
  48.   void init(CSCHAR *o,int r)           { opt=o; rc=r; }
  49.   void connect(void *p)            { poi=p; }
  50.  
  51. };
  52.  
  53.  
  54. ////////////////////////// MENU class /////////////////////////////////////////
  55.  
  56.  
  57. class MENU:public WINDOW
  58. {
  59.  
  60.   private:
  61.     int status;
  62.  
  63.     int typ;           //hori or verti
  64.     int hold_var;
  65.     int high_hor;
  66.     int high_ver;
  67.     int oc,kc;          // Option Color, Key Color
  68.  
  69.     int num_option;
  70.     int path;
  71.     int auto_return;
  72.     int opt_act;
  73.     int dwars_allow;
  74.     int menu_row;
  75.     int menu_col;
  76.     int abs_rel;       // Absolute or relative position
  77.  
  78.  
  79.     OPTION *option[MAX_OPTIONS];
  80.  
  81. protected:
  82.     int add_first_opt_len(int k);
  83.     void print_option(int k,int opt_col,int til_col);
  84.     MENU *sub_menu(int k);
  85.     OPTION *point_2_opt(int k);
  86.     void make_window(void);
  87.     int opt_len(int k);
  88.     int add_opt_len(void);
  89.     int is_dwars(int cursor);
  90.     int tilde_pos(CSCHAR *s);
  91.     int tilde_char(CSCHAR *s, CSCHAR &ch);
  92.     int choose2(int &);
  93.     void tilde_remove(CSCHAR *s);
  94.     void entry(void);
  95.     void yrtne(void);
  96.  
  97.  
  98. ////////////////////////////////////////////////////////////////////////
  99. ////////////////////// PUBLIC FUNCTIONS ////////////////////////////////
  100. ////////////////////////////////////////////////////////////////////////
  101.  
  102.  
  103.   public:
  104.  
  105.  
  106. ////////////////////////////Defining options ///////////////////////////
  107.     int add_option(CSCHAR *s,int key);
  108.     void enable_option(int num,int tf) { point_2_opt(num)->enable=tf; }
  109.     void enable_option(int tf)           { enable_option(num_option,tf); }
  110.  
  111.  
  112. ////////////////////////////Defining menus /////////////////////////////
  113.     int  type(int hor_or_ver) { typ=hor_or_ver; return TRUE;}
  114.     int  type(void) {return typ; }
  115.     void auto_ret(int yn)           { auto_return=yn; }
  116.     void hold(int tf)               { hold_var=tf; }
  117.     void dwars(int tf)               { dwars_allow=tf; }
  118.  
  119. ////////////////////////////Connecting menus ///////////////////////////
  120.     int connect(int option, MENU &m2);
  121.  
  122.  
  123. /////////////////////////////Colors ////////////////////////////////////
  124.     void option_color(int color)       { oc=color; }
  125.     void key_color(int color)           { kc=color; }
  126.     void color(int cb,int cs,int co,int ck)
  127.                        { border_color(cb);
  128.                      screen_color(cs);
  129.                      option_color(co);
  130.                      key_color(ck); }
  131.  
  132. /////////////////////////////Displaying ////////////////////////////////
  133.     int show_this(void);
  134.     int show_standby(void);
  135.     int show(void);
  136.     int show_nr(void);         // Doesn't return to the original WINDOW.
  137.     int show2(void);
  138.     int show(int opt);
  139.     int show_nr(int opt);     // Doesn't return to the original WINDOW.
  140.  
  141.     void standby2(void);
  142.     void standby(void);
  143.  
  144. /////////////////////////////Picking an option //////////////////////////
  145.     int choose(int &keus);      // Returns ENTER ,ESC etc.
  146.     int choose_hold(int &keus);   // Returns ENTER ,ESC etc.
  147.  
  148.  
  149.  
  150.  
  151. /////////////////////////////Postions and dimenstions //////////////////
  152.     void top(int w)               { menu_row=w; }
  153.     void left(int w)               { menu_col=w; }
  154.     void coord(int row,int col)        { top(row); left(col); }
  155.     void set_dim(int row,int col,int h,int w)
  156.                        { coord(row,col); height(h); width(w); }
  157.     void relative_pos(int tf)           { abs_rel=!tf; }
  158.  
  159.  
  160. ////////////////////////// Miscellaneous ///////////////////////////////////////
  161.     int  find_path(int key);
  162.  
  163. ////////////////////////// Removing the menu from the screen ///////////////////
  164.     void remove(void);
  165.  
  166. /////////////////////////////Con&Des-structors /////////////////////////
  167.     MENU(void);
  168.     ~MENU(void);
  169.  
  170.  
  171. };
  172.  
  173.  
  174. #endif
  175.