home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / objease3 / libs / tui.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-18  |  12.2 KB  |  654 lines

  1. #include <dos.h>
  2. #include <string.h>
  3. #include <direct.h>
  4.  
  5. #define TRUE 1
  6. #define FALSE 0
  7.  
  8. #define ALTA 30
  9. #define ALTB 48
  10. #define ALTC 46
  11. #define ALTD 32
  12. #define ALTE 18
  13. #define ALTF 33
  14. #define ALTG 34
  15. #define ALTH 35
  16. #define ALTI 23
  17. #define ALTJ 36
  18. #define ALTK 37
  19. #define ALTL 38
  20. #define ALTM 50
  21. #define ALTN 49
  22. #define ALTO 24
  23. #define ALTP 25
  24. #define ALTQ 16
  25. #define ALTR 19
  26. #define ALTS 31
  27. #define ALTT 20
  28. #define ALTU 22
  29. #define ALTV 47
  30. #define ALTW 17
  31. #define ALTX 45
  32. #define ALTY 21
  33. #define ALTZ 44
  34.  
  35. #define ALT1 120
  36. #define ALT2 121
  37. #define ALT3 122
  38. #define ALT4 123
  39. #define ALT5 124
  40. #define ALT6 125
  41. #define ALT7 126
  42. #define ALT8 127
  43. #define ALT9 128
  44. #define ALT0 129
  45.  
  46. #define ALTMINUS  130
  47. #define ALTPLUS   131
  48.  
  49. void determine_video_mode();
  50.  
  51. //LIB
  52. void vprintat(int cols,int rows,int fore,int back,char *,...);
  53. void vprintc(int row,int fore,int back,char *,...);
  54. void printat(int,int,int,int,char *);
  55. void printc(int,int,int,char *);
  56. void cprintat(int,int,int,int,char *,...);
  57. void cprintc(int,int,int,char *,...);
  58. void clear(char ch,int fore,int back);
  59. void cursoroff();
  60. void cursoron();
  61. void settext(int,int);
  62. void chsattr(int,int);
  63. void chcattr(int,int,int,int,int);
  64. void dlay(int ticks);
  65. long getticks();
  66. int altkey();
  67. int ctrlkey();
  68. int lshiftkey();
  69. int rshiftkey();
  70. void flushkeys();
  71. unsigned char getvidmode();
  72. unsigned char alt_to_asc(unsigned char);
  73.  
  74. void far interrupt MouseHandler(void);
  75.  
  76. //MOUSECLASS
  77. extern int _MX;
  78. extern int _MY;
  79.  
  80. void far mhandler();
  81. class Mcursor {
  82.       int shown;
  83.       int current;
  84.       int xpos;
  85.       int ypos;
  86.       void mouse_interrupt();
  87.       int m1;
  88.       int m2;
  89.       int m3;
  90.       int m4;
  91.       int button;
  92.       int count;
  93.       int disabled;
  94.       int handler_installed;
  95.       int eventMask;
  96.       void ClearHandler();
  97.       void InstallHandler(unsigned mask,void far interrupt (*handler)(void)=MouseHandler);
  98.     public:
  99.       Mcursor();
  100.       ~Mcursor();
  101.       int  init();
  102.       void get_status();
  103.       void show();
  104.       void hide();
  105.       void set_hor_bounds(int,int);
  106.       void set_ver_bounds(int,int);
  107.       void Mcursor::conditional_off(int x1,int y1,int x2,int y2);
  108.       void Mcursor::position(int,int);
  109.       int  LBP();
  110.       int  RBP();
  111.       int  mousex();
  112.       int  mousey();
  113.       int  mx();
  114.       int  my();
  115.       void unarm();
  116.       void arm();
  117.       int  LBDCLK();
  118.       long thistick;
  119.       long previoustick;
  120.       int doubleclicked;
  121.       };
  122.  
  123. #define UPARROW 1
  124. #define DOT 2
  125. #define PENCIL 3
  126. #define CROSSHAIR 4
  127. #define ARROW 5
  128. #define FINGER 6
  129. #define POINT 7
  130. #define CLOCK 8
  131. #define DISK 9
  132. #define IBAR 10
  133. #define PAINTCAN 11
  134. #define HAND 12
  135. #define ERASOR 13
  136. #define GUNSIGHT 14
  137. #define SCISSORS 15
  138. #define JAWS 16
  139.  
  140. //WINDOW
  141. //typedef unsigned char screenbuff[4000];
  142. typedef char itemarray[24][80];
  143.  
  144. #define SINGLE 0
  145. #define DOUBLE 1
  146. #define HOR 0
  147. #define VER 1
  148.  
  149. class Twindow{
  150.     protected:
  151.         int x;
  152.         int y;
  153.         int x1;
  154.         int y1;
  155.         int fgd;
  156.         int bgd;
  157.         int shad;
  158.         int shadcolor;
  159.         int shaddirection;
  160.         int size;
  161.         char id[15];
  162.         int existtitle;
  163.         int bordertype;
  164.         int shown;
  165.         unsigned char *save;
  166.     public:
  167.         Twindow();
  168.         ~Twindow();
  169.         void getstyle();
  170.         void init(int xpos,int ypos,int x1pos,int y1pos,
  171.         int fore,int back,int shadow,int shadowcolor,int shadowdir=0);
  172.         void border();
  173.         void setborder(int style);
  174.         int  getborder();
  175.         void cfgd(int fore);
  176.         void cbgd(int back);
  177.         int  getfgd();
  178.         int  getbgd();
  179.         void fill();
  180.         void divider(int direction,int style,int offset);
  181.         void show();
  182.         void zoom();
  183.         void hide();
  184.         void elim();
  185.         void title(char txt[15]);
  186.         int  istitle();
  187.         int isshown();
  188.         int isx();
  189.         int isy();
  190.         int isx1();
  191.         int isy1();
  192.         int issize();
  193.         void wprintat(int,int,int,int,char*);
  194.         void wprintc(int,int,int,char*);
  195.         int hit();
  196.         };
  197.  
  198. //TMENU
  199. class Tmenu:public Twindow{
  200.     protected:
  201.         int itemcount;
  202.         itemarray items;
  203.         int hifore;
  204.         int hiback;
  205.         int menuchoice;
  206.     public:
  207.         void init(int itemcnt,itemarray item,int xpos,int ypos,int width,
  208.         int fore,int back,int hfore,int hback,
  209.         int shadow,int shadowcolor);
  210.         int show(int seconds=0);
  211.         void move(int xpos,int ypos);
  212.         };
  213.  
  214. //INPUT
  215. void beep();
  216. char *strdel(char *,int);
  217. char *strins(char *,int,char);
  218.  
  219. class Tstring {
  220.     protected:
  221.         char laststring[81];
  222.         char bar[81];
  223.         int xpos;
  224.         int x;
  225.         int y;
  226.         int length;
  227.         int ucase;
  228.         int escape;
  229.         int retrn;
  230.         int tab;
  231.         int uparrow;
  232.         int dnarrow;
  233.         int shown;
  234.         int barred;
  235.         int firstchar;
  236.         int infgd;
  237.         int inbgd;
  238.     public:
  239.         Tstring();
  240.         ~Tstring();
  241.         void init(int xloc,int yloc,int len,int uppercase);
  242.         void draw_bar();
  243.         void show();
  244.         void input();
  245.         void get_input();
  246.         void get_form_input();
  247.         void get_form_mouse_input();
  248.         void reset();
  249.         void preset(char *);
  250.         void erase(int);
  251.         char *getstring();
  252.         int escapehit();
  253.         int returnhit();
  254.         int tabhit();
  255.         int uparrowhit();
  256.         int dnarrowhit();
  257.         int isshown();
  258.         int isbarred();
  259.         int hit();
  260.         void setincolors(int,int);
  261.         };
  262.  
  263. class Tnumeral:public Tstring {
  264.     protected:
  265.         int real;
  266.         int end;
  267.     public:
  268.         void init(int xloc,int yloc,int len,int int_or_float);
  269.         void show();
  270.         void get_input();
  271.         void get_form_input();
  272.         void get_form_mouse_input();
  273.         void input();
  274.         float getfloat();
  275.         int getint();
  276.         long getlong();
  277.         };
  278.  
  279. class Tdate:public Tstring {
  280.     protected:
  281.         int date_ok;
  282.     public:
  283.         void init(int xloc,int yloc);
  284.         void show();
  285.         void get_input();
  286.         void validate();
  287.         int  verified();
  288.         char *getdatestring();
  289.         long getdate();
  290.         };
  291.  
  292. //TBUTTON
  293. class Tbutton {
  294.     protected:
  295.         int xpos;
  296.         int ypos;
  297.         int width;
  298.         int pressed;
  299.         int hilite;
  300.         char button[81];
  301.         char shadow[81];
  302.         char id[41];
  303.     public:
  304.         Tbutton();
  305.         void init(int,int,char *,int);
  306.         ~Tbutton();
  307.         void show(int);
  308.         int buttonpressed();
  309.         int hit();
  310.         void press(int);
  311.         int ispressed();
  312.         };
  313.  
  314. class Tbutton3d {
  315.     protected:
  316.         int xpos;
  317.         int ypos;
  318.         int width;
  319.         int pressed;
  320.         int hilite;
  321.         char id[41];
  322.         int bgd;
  323.     public:
  324.         Tbutton3d();
  325.         ~Tbutton3d();
  326.         void init(int,int,char *,int,int bkgd=7);
  327.         void show();
  328.         int hit();
  329.         void press();
  330.         int ispressed();
  331.         };
  332.  
  333. class Tcheckbox {
  334.     protected:
  335.         int xpos;
  336.         int ypos;
  337.         int fgd;
  338.         int bgd;
  339.         int checked;
  340.     public:
  341.         Tcheckbox();
  342.         void init(int,int,int,int);
  343.         ~Tcheckbox();
  344.         void show();
  345.         void grabcursor();
  346.         int hit();
  347.         void check();
  348.         void uncheck();
  349.         int ischecked();
  350.         };
  351.  
  352. //MISC
  353. void smover(int row,int startpos,int endpos,int fgd,int bgd,char *string);
  354. void smovel(int row,int startpos,int endpos,int fgd,int bgd,char *string);
  355. void smoveu(int col,int startpos,int endpos,int fgd,int bgd,char *string);
  356. void smoved(int col,int startpos,int endpos,int fgd,int bgd,char *string);
  357.  
  358. //SOUNDQ
  359. #define TimerTick 0x8
  360. #define noisemax 8192
  361. #define ON 1
  362. #define OFF 0
  363.  
  364. #define C 523
  365. #define CS 554
  366. #define D 587
  367. #define DS 622
  368. #define E 659
  369. #define F 698
  370. #define FS 740
  371. #define G 784
  372. #define GS 831
  373. #define A 880
  374. #define AS 932
  375. #define B 988
  376. #define C1 1046
  377.  
  378. #define SN 32
  379. #define EN 63
  380. #define QN 125
  381. #define HN 250
  382. #define WN 500
  383.  
  384. #define ENT 20
  385. #define QNT 41
  386. #define HNT 83
  387.  
  388. #define BN 30000,5
  389. #define SR 30000,32
  390. #define ER 30000,63
  391. #define QR 30000,125
  392. #define HR 30000,250
  393. #define WR 30000,500
  394. #define NM 30000,1
  395.  
  396. class SoundQ{
  397.     protected:
  398.         float speed_factor;
  399.     public:
  400.         SoundQ();
  401.         ~SoundQ();
  402.         void play(int,int);
  403.         void adjust_speed(float);
  404.         };
  405.  
  406. typedef struct
  407. {
  408.   int duration;
  409.   int freq;
  410. } noise;
  411.  
  412. void empty_sound_queue();
  413. void init_sound(void);
  414. void restore_sound(void);
  415. int submit_sound(int freq,int delay);
  416. void interrupt soundsystem(...);
  417.  
  418. //OPTION
  419. class option {
  420.     protected:
  421.         int x;
  422.         int y;
  423.         int width;
  424.         int r_value;
  425.         int selectable;
  426.     int selected;
  427.         char text[30];
  428.         int hl;
  429.         int self_colored;
  430.         int sfgd;
  431.         int sbgd;
  432.         int shfgd;
  433.         int shbgd;
  434.         int disabled;
  435.         int disabled_fgd;
  436.         int disabled_bgd;
  437.         int divider;
  438.         int underline;
  439.         int underline_position;
  440.         long last_tick;
  441.         int clickcount;
  442.         int fgd,bgd,hfgd,hbgd;
  443.     public:
  444.         void init(int,int,char *,int);
  445.         int Getx();
  446.         int Gety();
  447.         void set_highlight_attrib(int);
  448.         void display(int,int,int);
  449.         char * get_text();
  450.         int is_selectable();
  451.         int get_r_value();
  452.         void set_width(int);
  453.         int hit();
  454.         int is_highlighted();
  455.         void self_color(int,int,int,int);
  456.         void unable(int,int);
  457.         void reenable();
  458.         int is_enabled();
  459.         int is_divider();
  460.         void adjust_pos_to_pulldown(int,int);
  461.         int clicked();
  462.         int LBDCLK();
  463.         int _3d;
  464.         };
  465.  
  466.  
  467. //PULLDOWN
  468. class pulldown {
  469.         protected:
  470.         friend class menubar;
  471.         int nfg,nbg,hfg,hbg;
  472.         int x,y;
  473.         Twindow frame;
  474.         int shown;
  475.         int width,height;
  476.         int num_options;
  477.         int part_of_menubar;
  478.         char hotkeys[20];
  479.         int kbtrigger_index;
  480.     public:
  481.         option options[20];
  482.         void init(int,int,int,int,int xpos=2,int ypos=2);
  483.         void set_option(int,char *,int);
  484.         void determine_width_height();
  485.         void display();
  486.         void position(int,int);
  487.         int trackmenu();
  488.         void hide();
  489.         int is_shown();
  490.         void adjust_option_widths();
  491.         void adjust_pos_to_menubar(int);
  492.         int is_part_of_menubar();
  493.         };
  494.  
  495.  
  496. //MENUBAR
  497. class menubar {
  498.     protected:
  499.         option *titles[10];
  500.         pulldown *pd[10];
  501.         int nfg,nbg,hfg,hbg;
  502.         int num_titles;
  503.         char hotkeys[10];
  504.         int kbtrigger_index;
  505.     public:
  506.         menubar();
  507.         ~menubar();
  508.         void init(int,int,int,int);
  509.         void set_title(int,char *,pulldown *);
  510.         void display();
  511.         int trackbar();
  512.         int hit();
  513.         int mouse_triggered();
  514.         int kb_triggered();
  515.         int triggered();
  516.         };
  517.  
  518. //PAD
  519. //This is a supplemental class for use only in the scrollbar class
  520. class pad {
  521.     protected:
  522.         int x,y;
  523.         int fgd,bgd;
  524.         char id[2];
  525.     public:
  526.         void init(int,int,int,int,char);
  527.         void show();
  528.         void hide();
  529.         void move(int,int);
  530.         int hit();
  531.         int Getx();
  532.         int Gety();
  533.         };
  534.  
  535. //SCROLLBAR
  536. class scrollbar {
  537.     protected:
  538.         int x,y;
  539.         pad *thumbpad;
  540.         pad *increase;
  541.         pad *decrease;
  542.         int vertical;
  543.         int length;
  544.         int small_d,large_d;
  545.         long minimum,maximum;
  546.         long value;
  547.         int changed;
  548.     public:
  549.         void init(int,int,int,int,long,long);
  550.         void show();
  551.         int thumbpad_hit();
  552.         int decrease_hit();
  553.         int increase_hit();
  554.         void track_scrollbar();
  555.         long get_value();
  556.         int value_changed();
  557.         int hit();
  558.         void set_small_d(int);
  559.         void set_large_d(int);
  560.         void set_minimum(long);
  561.         void set_maximum(long);
  562.         void update_value(long);
  563.         };
  564.  
  565. //LISTBOX
  566. struct optionrec {
  567.     option *entry;
  568.     int index;
  569.     optionrec *next;
  570.     optionrec *previous;
  571.     };
  572.  
  573. class listbox {
  574.     protected:
  575.         int x,y;
  576.         optionrec *listroot;
  577.         optionrec *listend;
  578.         optionrec *currentsel;
  579.         Twindow far *box;
  580.         scrollbar sbar;
  581.         int selected_index;
  582.         char *selected_string;
  583.         int option_string_length;
  584.         int changed;
  585.         int size_forced;
  586.         int forced_width;
  587.         int forced_height;
  588.     public:
  589.         listbox();
  590.         ~listbox();
  591.         void init(int,int,int,int,int,int,int);
  592.         void force_size(int,int);
  593.         void set_highlight_position(int);
  594.         void append_item(char *);
  595.         void show();
  596.         void show_options(int);
  597.         void hide();
  598.         void scroll_list_up();
  599.         void scroll_list_down();
  600.         int tracklist();
  601.         int options_displayed;
  602.         int options_in_list;
  603.         int option_width;
  604.         int shown;
  605.         int nfg,nbg,hfg,hbg;
  606.         int index_at_top;
  607.         int index_at_bottom;
  608.         int hit();
  609.         int is_current_index();
  610.         char *is_current_string();
  611.         int is_selected_index();
  612.         char *is_selected_string();
  613.         int selection_changed();
  614.         void deactivate();
  615.         void reactivate();
  616.         int active;
  617.         int part_of_structure;
  618.         int Gety();
  619.         int Getx();
  620.         int list_index;
  621.         };
  622.  
  623. //DIRBOX
  624. int name_sort(const void *a,const void *b);
  625. class dirbox {
  626.     protected:
  627.         Twindow *box;
  628.         listbox *drive;
  629.         listbox *directory;
  630.         Tbutton *OK;
  631.         Tbutton *CANCEL;
  632.         char fullpath[MAXPATH];
  633.         char returnpath[MAXPATH];
  634.         char lastvalidpath[MAXPATH];
  635.         Tstring *filename;
  636.         int shown;
  637.         int turn;
  638.         char dirmask[13];
  639.         int intnumber;
  640.         void interrupt (*oldhandler)(...);
  641.     public:
  642.         dirbox();
  643.         ~dirbox();
  644.         void show();
  645.         void hide();
  646.         char * trackdir();
  647.         void print_current_path();
  648.         void change_directory(char *);
  649.         void fill_directory_list();
  650.         void fill_drive_list();
  651.         void set_mask(char *);
  652.         static void interrupt _handler(...);
  653.         };
  654.