home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / LVSWIN31.ZIP / LVSWIN.HPP < prev   
C/C++ Source or Header  |  1992-02-26  |  23KB  |  589 lines

  1. /*
  2.  *            LVS Windows
  3.  *      The Window Class System
  4.  *
  5.  *        Copyright 1991 (c), Lake View Software
  6.  *                            4321 Harborough Rd.
  7.  *                            Columbus, OH 43220
  8.  *        All rights reserved.
  9.  */
  10. // LVSwin.HPP
  11.  
  12. #ifndef LVSWIN_HPP
  13. #define LVSWIN_HPP
  14.  
  15. #include <stdio.h>
  16. #include "lvswin.h"
  17.  
  18. typedef int (*valid_func)(void *);
  19. typedef int (*valid2_func)(void *, void *);
  20. typedef void (*before_func)(void *);
  21. typedef int (*button_func_t)(int);
  22. typedef void (*mouse_routine_t)(int, int);
  23.  
  24. class GetObj {
  25. // Base Get Object
  26.         friend class WinObj;
  27.     protected:
  28.         GetObj
  29.             *Prev_get,
  30.             *Next_get;
  31.         WinObj
  32.             *w;                 // window the get object is in
  33.         int 
  34.             y, x,               // window coordinates
  35.             attr,               // its get attribute
  36.             _attr,              // windows current attribute
  37.             mouse_positioner;   // mouse location
  38.         valid_func 
  39.             valid;              // Call after read to get
  40.         valid2_func 
  41.             valid2;             // Call after read to get with 2 params
  42.         void *valid2_pass;      // second param to pass to valid2 func
  43.         before_func 
  44.             before;             // Call before read to get
  45.         int add_to_list ();     // add to a windows linked list
  46.         #ifdef __LARGE__
  47.             /*
  48.              * Paradox stuf
  49.              */
  50.             void *PX_buf;
  51.             char PX_type [11];
  52.             unsigned
  53.                 PX_fld,
  54.                 PX_tbl,
  55.                 PX_dec,
  56.                 PX_rec;
  57.         #endif      // defined large
  58.     public:
  59.         GetObj ();
  60.         ~GetObj ();
  61.         virtual int input ();               // read from the user
  62.         virtual void display ();            // display the get
  63.         virtual int is_on (int y, int x);   // test coordinate
  64. };
  65.  
  66. class GetObj_L:public GetObj
  67. /*
  68.  * Long get class
  69.  */
  70. {
  71.     private:
  72.         long *obj;
  73.         int length;
  74.     public:
  75.         GetObj_L (WinObj *w);
  76.         int get (int y, int x, long &L, int len);
  77.         int input ();               // read from the user
  78.         void display ();            // display the get
  79.         int is_on (int y, int x);   // test coordinate
  80. };
  81.  
  82. class GetObj_R:public GetObj
  83. /*
  84.  * Radio button class
  85.  */
  86. {
  87.     private:
  88.         int *obj;               // will contain the button value
  89.         char **string_list;
  90.         int count;
  91.         int length;             // length of string.
  92.         void select_button (int button);
  93.         void display_button (int button);
  94.     public:
  95.         GetObj_R (WinObj *w);
  96.         int get (int y1, int x1, char *str[], int &value, int cnt);
  97.         int input ();               // read from the user
  98.         void display ();            // display the get
  99.         int is_on (int y, int x);   // test coordinate
  100. };
  101.  
  102. class GetObj_S:public GetObj
  103. /*
  104.  * String get class
  105.  */
  106. {
  107.     private:
  108.         char *obj;
  109.         char *picture;
  110.         int length;
  111.         char style;
  112.     public:
  113.         GetObj_S (WinObj *w);
  114.         int get (int y, int x, char *str, char s, int len);
  115.         int get (int y, int x, char *str, char *pict);
  116.         int input ();               // read from the user
  117.         void display ();            // display the get
  118.         int is_on (int y, int x);   // test coordinate
  119. };
  120.  
  121. class GetObj_X:public GetObj
  122. /*
  123.  * Check box class
  124.  */
  125. {
  126.     private:
  127.         int *obj;
  128.         char *check_str;
  129.         int length;
  130.     public:
  131.         GetObj_X (WinObj *w);
  132.         int get (int y1, int x1, char *str, int &value);
  133.         int input ();               // read from the user
  134.         void display ();            // display the get
  135.         int is_on (int y, int x);   // test coordinate
  136. };
  137.  
  138. class GetObj_P:public GetObj
  139. /*
  140.  * Pick list class
  141.  */
  142. {
  143.     private:
  144.         int *obj;               // selected item
  145.         int sr, sc, er, ec;
  146.         char **picklist;
  147.         int count;              // adjustable count
  148.         int start;              // first showing in box
  149.         int max;                // max displayed in list at a time
  150.         int width;              // width of the list items
  151.         int scroll_flag;        // show scroll flag
  152.         int adjust ();          // adjust the list window
  153.         void display_scroll (); // display the scroll bars
  154.         void remove_scroll ();  // remove the scroll bars
  155.         int calc_elev_row ();   // calc the elevator column
  156.     public:
  157.         GetObj_P (WinObj *w);
  158.         int get (int sr1, int sc1, int er1, int ec1,
  159.                  char **list, int &cnt, int &selected);
  160.         int input ();               // read from the user
  161.         void display ();            // display the get
  162.         int is_on (int y, int x);   // test coordinate
  163.         void set_new_count (int cnt);       // adjust count while running
  164. };
  165.  
  166. class GetObj_B:public GetObj
  167. /*
  168.  * Push button class
  169.  */
  170. {
  171.     private:
  172.         int obj;                // will contain the button value
  173.         button_func_t bf;         
  174.         char *button_str;       // string displayed for button
  175.         int length;             // length of string.
  176.     public:
  177.         GetObj_B (WinObj *w);
  178.         int get (int y1, int x1, char *s, button_func_t func, int value);
  179.         int input ();               // read from the user
  180.         void display ();            // display the get
  181.         int is_on (int y, int x);   // test coordinate
  182. };
  183.  
  184. class GetObj_D:public GetObj
  185. /*
  186.  * Double class
  187.  */
  188. {
  189.     private:
  190.         double *obj;
  191.         int length;
  192.         int decimals;
  193.     public:
  194.         GetObj_D (WinObj *w);
  195.         int get (int y1, int x1, double &d, int l, int dec);
  196.         int input ();               // read from the user
  197.         void display ();            // display the get
  198.         int is_on (int y, int x);   // test coordinate
  199. };
  200.  
  201. class GetObj_C:public GetObj
  202. /*
  203.  * Char get class
  204.  */
  205. {
  206.     private:
  207.         char *obj;
  208.     public:
  209.         GetObj_C (WinObj *w);
  210.         int get (int y, int x, char &ch);
  211.         int input ();               // read from the user
  212.         void display ();            // display the get
  213.         int is_on (int y, int x);   // test coordinate
  214. };
  215.  
  216. class GetObj_I:public GetObj
  217. /*
  218.  * Integer class
  219.  */
  220. {
  221.     private:
  222.         int *obj;
  223.         int len;
  224.     public:
  225.         GetObj_I (WinObj *w);
  226.         int get (int y, int x, int &i, int len);
  227.         int input ();               // read from the user
  228.         void display ();            // display the get
  229.         int is_on (int y, int x);   // test coordinate
  230. };
  231.  
  232.  
  233. class WinObj  {
  234. /*
  235.  * Window Class
  236.  */
  237.     friend class WinMouse;
  238.     friend class GetObj;
  239.     friend WinObj *Win_whos_active ();
  240.     friend void Win_close_all ();
  241.     protected:
  242.         static WinObj *w_active;        // Current active window object
  243.         static int w_count;             // number of window objects
  244.         static char *buffer;            // working buffer
  245.         WinObj *next_win;               // Next window object
  246.         WinObj *prev_win;               // Previous window object
  247.         unsigned wsc,wsr,wec,wer;       // Screen coordinates
  248.         unsigned width,height;          // Actual screen space available
  249.         int get_attr;                   // Get attribute
  250.         int win_attr;                   // Window attribute
  251.         int bor_attr;                   // Border attribute
  252.         int bor_type;                   // Border type
  253.         int win_type;                   // type of window
  254.         unsigned char fill_char;        // window fill character
  255.         int title_pos;                  // Title position
  256.         char *title_str;                // Pointer to title string
  257.         char *wdata_buf;                // Data buffer
  258.         char *wattr_buf;                // attribute buffer
  259.         GetObj *Current_get;            // Current get object
  260.         GetObj *Last_get;               // Last get object in list
  261.         char opened;                    // Opened flag
  262.         char hidden;                    // Hidden flag
  263.         char needs_display;             // Refresh flag
  264.         char has_border;                // border flag
  265.         char has_shadow;                // shadow flag
  266.         char user_move;                 // user movement flag
  267.         char insert;                    // insert mode flag
  268.         char scroll_h,scroll_v;         // scroll arrows flag
  269.         char read_change_flag;          // flag for read changes
  270.         char read_in_progress;          // read in progress flag
  271.         unsigned vh,vw;                 // Virtual height and width
  272.         unsigned buf_size;              // Window data and attr buf size
  273.         unsigned sx,sy;                 // Start x and y for virtual display
  274.         unsigned cur_pos;               // Cursor x and y
  275.         void reset_window ();           // reset all flags
  276.         int get_titlestart (int &len);  // get start x of title and length
  277.         int input (GetObj *Obj);        // Get a read from the screen
  278.         int create_get (int y, int x);  // create a new get object
  279.         void draw_border ();            // draw the window border
  280.         virtual unsigned char bor_char (int, int, unsigned char &);// calculate the border char/attr
  281.         void update_scroll ();          // update scroll bars
  282.         virtual void display ();        // Display window contents on top
  283.         virtual void update (int start_pos,int len);  // Update a portion of window
  284.         void show_shadow ();            // Display the windows shadow.
  285.         virtual void mouse_routine (int y, int x); // mouse click routine 
  286.         mouse_routine_t mouse_user_routine; // programmers mouse routine
  287.  
  288.         /*  Paradox Stuf */
  289.         unsigned PX_tbl,                // Paradox table handle
  290.                  PX_rec;                // Paradox record handle
  291. public:
  292.         WinObj (int v_h, int v_w=0);
  293.         WinObj ();                      // allows init of arrays
  294.         ~WinObj ();
  295.  
  296.         char *get_version ();
  297.         int set_virtual (int y,int x);      // set virtual size
  298.         virtual int open (int sr, int sc, int er, int ec,
  299.             int btype=W_DOUBLE, int wattr=_BLACK|LGREY,
  300.             int battr=_BLACK|LGREY);        // Open the window object
  301.  
  302.         /* Mouse related */
  303.         mouse_routine_t set_mouseroutine (mouse_routine_t); // programmers mouse routine
  304.         void allow_user_moves (int true_flase);  // allow user to move or size window
  305.  
  306.         /* Attributes */
  307.         int set_attr (int color);           // Returns pervios attribute
  308.         void set_attr (int color, int y,
  309.                 int x, int cnt=1);          // change attr
  310.         void set_fill (char fill); // set window fill character.
  311.         void change_border (int type,
  312.                 int color=-1);              // Set new border style/color
  313.         void title (char *str,
  314.                 int position=W_CENTER);     // Change the window title
  315.         virtual void shadow (int on_off=W_ON);      // Turn window shadow on/off
  316.         void set_insert (int on_off);       // switch insert mode
  317.  
  318.         /* Display routines */
  319.         void box (int sr, int sc, int er, 
  320.                 int ec, int type = W_SINGLE,
  321.                 int fill = (1!=1));       // Draw a box in the window
  322.         void scroll_box (int sr, int sc, int er, 
  323.                 int ec, int type = W_SINGLE,
  324.                 int fill = (1!=1));       // Draw a scroll box in the window
  325.         virtual void update ();             // Update but don't set current
  326.         void update_all ();                 // update all open windows
  327.         virtual void show_cursor ();        // Show cursor in window
  328.         virtual void close ();              // Close the window object.
  329.         virtual void set_active ();         // makes window current window
  330.         void bprintf (char *,...);          // Print f in window
  331.         void bprintf (int y, int x, char *,...);  // xy bprintf
  332.         void printf (char *,...);           // Print f in window
  333.         void printf (int y,int x,char *,...);    // xy printf
  334.         void puts (char *,int translate=W_ON);    // Display a string
  335.         void puts (int y, int x, char *, int translate=W_ON);
  336.         void putch (char ch, int translate=W_OFF); // display a character
  337.         void putch (int y, int x, char ch, int translate=W_OFF);
  338.         int center (int y, char *);         // center in virtual window
  339.         void clr_win ();                    // Clear window
  340.         void clr_eol ();                    // Clear to end of current line
  341.         void clr_eow ();                    // Clear to end of window
  342.         void del_line (int line_no);        // Delete current, line pull up
  343.         void ins_line (int line_no);        // Ins new line, push down
  344.  
  345.         /* Get routines */
  346.         int get (int y, int x, char *str, char *picture=NULL);
  347.         int get (int y, int x, char *str, char style, int len = 0);
  348.         int get (int y, int x, char &ch);
  349.         int get (int y, int x, int &geti, int len=4);
  350.         int get (int y, int x, long int &getl,int len=5);
  351.         int get (int y, int x, double &getd, int len=10, int dec=2);
  352.         int get_button (int y, int x, char *str, button_func_t bf, int value);
  353.         int get_checkbox (int y, int x, char *str, int &value);
  354.         int get_radio (int y, int x, char *str[], int &value, int count);
  355.         int get_picklist (int sr, int sc, int er, int ec, char *list[],
  356.                           int cnt, int &selected);
  357.         void *get_object_ptr ();              // get pointer to last get object
  358.         int set_getattr (int new_attr = -1);  // Change the get attribute
  359.         int valid (valid_func func);    // Valid function with one param
  360.         int valid (valid2_func func, void *); // valid function with two params
  361.         int before (before_func func);    // Before get function
  362.         virtual int get_key (int echo=W_NOECHO, int seconds = 0);  // Get single key from keyboard  do not echo, wait forever
  363.         virtual int read (int clear = 1);           // Read all defined gets
  364.         int any_read_change ();                     // any change after last read
  365.         void set_read_change ();                    // set read change flag
  366.         int update_gets ();                         // Update gets on screen.
  367.         void clear_gets ();                         // Clear all defined gets
  368.  
  369.         /* Window Movement */
  370.         virtual void hide ();                       // Hide window
  371.         virtual void unhide ();                     // Show window
  372.         virtual int move (int new_y, int new_x);    // Move the window
  373.         virtual int size (int new_height, int new_width);    // Resize the window
  374.         WinObj& gotoxy (unsigned y=0, unsigned x=0);  // Move cursor in window
  375.         int  pan (int delta_y, int delta_x);        // change pan location
  376.         int set_pan (int y, int x);                 // set pan location
  377.  
  378.         /* Information routines */
  379.         int do_youown (int y, int x, unsigned char &ch,unsigned char &attr);        // Do you own screen position
  380.         WinObj *who_owns (int y, int x, unsigned char &ch,unsigned char &attr);
  381.         WinObj *whos_below (int y, int x, unsigned char &ch, unsigned char &attr);
  382.         unsigned max_x(), max_y();                   // return maximum virtual x/y coordinates
  383.         int get_scr (int &sr, int &sc, int &er, int &ec);  // get coordinates
  384.         int get_pan (int &y, int &x);               // return current pan coordinates
  385.         int wherexy (int &y, int &x);               // return current cursor pos
  386.         int wherex ();                              // return current col
  387.         int wherey ();                              // return current row
  388.         int get_insert ();                          // return insert mode
  389.         int is_open ();                             // open status
  390.         int is_hidden ();                           // hidden status
  391.         int ret_char (int y, int x);                // get window char at window location
  392.         int ret_attr (int y, int x);                // get window attr at window location
  393.         int text_save (FILE *fp);                   // save window text
  394.         int text_retrieve (FILE *fp);               // retrieve window text
  395.  
  396.         /*   Paradox get / read routines  */
  397.         int PXrecord (unsigned tbl_handle, unsigned rec_handle);
  398.         int PXget (int y, int x, unsigned fld_handle);
  399.         int PXget (int y, int x, unsigned fld_handle, int len, int dec);
  400.         int PXget (int y, int x, unsigned fld_handle, char style);
  401.         int PXget (int y, int x, unsigned fld_handle, char *picture);
  402.         int PXread (int clear=1);             // use this read with PX
  403.  
  404.         /* Overloaded operators */
  405.         WinObj& operator << (int i);
  406.         WinObj& operator << (char *str);
  407.         WinObj& operator << (char ch);
  408.         WinObj& operator << (long l);
  409.         WinObj& operator << (double d);
  410.         WinObj& operator << (float f);
  411.         WinObj& operator << (unsigned ui);
  412.         WinObj& operator << (unsigned long ul);
  413. };
  414.  
  415. /*
  416.  * Global functions
  417.  */
  418. extern WinObj *Win_whos_active ();
  419. extern int printf_translate (int mode);
  420.  
  421. /*
  422.  * Mouse Routines/Class
  423.  */
  424.  
  425. #define     M_NONE        0         /* No mouse support */
  426. #define     M_SIMPLE      1         /* Simple cursor replacement Mode */
  427. #define     M_FULL        2         /* Full function mouse support */
  428.  
  429. #define     DELTAX       16         /* amount of change to cause an arrow */
  430. #define     DELTAY       16         /* key when in simple mode */
  431. #define     PIXELS        8         /* Pixels / screen coordinate */
  432.  
  433. /*
  434.  * Global routines
  435.  */
  436. extern WinMouse Win_mouse;
  437. int Win_mouse_mode (int mode = M_SIMPLE);
  438.  
  439. class WinMouse {
  440.     private:
  441.         int Mouse_Mode;             /* Mouse Init flag / mode */
  442.         int Mouse_Buttons;          /* Number of mouse button */
  443.         int Mouse_Hidden;           /* Mouse hidden flag */
  444.         void scan_full ();          /* Scan full mouse support */
  445.     public:
  446.         void clear_counters ();     /* clear counters for mouse_scan */
  447.         void scan ();               /* translate clicks to keys */
  448.         WinMouse (int mode = M_SIMPLE);
  449.         ~WinMouse ();
  450.  
  451.         void close ();                  /* close the mouse */
  452.         int init (int mode = M_SIMPLE); /* Mouse init function */
  453.         int get_mode ();                /* Get current mouse mode */
  454.         void motion (int &y, int &x);   /* Return micky motion in char */
  455.         void position (int y, int x);   /* Position the mouse cursor */
  456.         int clicks (int button, int &y, int &x); /* get click count  returns 
  457.                                                     position of last click */
  458.         int releases (int button, int &y, int &x); /* get click count  returns 
  459.                                                     position of last release */
  460.         void show ();                   /* Display the mouse cursor */
  461.         void hide ();                   /* Hide the cursor */
  462.         int status (int &y, int &x);    /* mouse status */
  463.         int x ();                       /* return current x coordinate */
  464.         int y ();                       /* return y coordinate */
  465.         void limit_x (int min, int max); /* limit mouse x coordinates */
  466.         void limit_y (int min, int max); /* limit mouse y coordinates */
  467.         int protect (int sr, int sc, int er, int ec);  /* protect cursor */
  468. };
  469.  
  470. /*
  471.  * Low level routines in MOU_FUN.ASM & MOU_FUN2.ASM
  472.  */
  473.  
  474. extern "C" {
  475.     void far Mouse_Hide ();
  476.     void far Mouse_Show ();
  477.     int far Mouse_Init (int far *Buttons);
  478.     void far Mouse_Motion (int far *y, int far *x);
  479.     void far Mouse_Location (int far *y, int far *x);
  480.     int far Mouse_Status (int far *y, int far *x);
  481.     int far Mouse_Clicks (int key, int far *y, int far *x);
  482.     int far Mouse_Releases (int key, int far *y, int far *x);
  483.     void far Mouse_Position (int y, int x);
  484.     void far Mouse_Limit_X (int min, int max);
  485.     void far Mouse_Limit_Y (int min, int max);
  486.     int far Mouse_Y ();
  487.     int far Mouse_X ();
  488. };
  489.  
  490.  
  491. /*
  492.  * Some macros for internal use
  493.  */
  494.  
  495. #define SHADOW_ATTR    DGREY
  496. #define BUFFER_OFFSET(y,x) (y * vw + x)
  497. #define GET_REAL_X(x) ((x - sx) + wsc + has_border)
  498. #define GET_REAL_Y(y) ((y - sy) + wsr + has_border)
  499. #define CALC_SCROLL_POSITION(s,x,a_rng,b_rng) ((a_rng) ? (s + 2 + (int)((long) (x) * (long)(b_rng) / (long)(a_rng))): 0)
  500.  
  501. /*
  502.  * Class to save the current screen state to restore it when the
  503.  * program is finished.
  504.  */
  505.  
  506. class ScreenState {
  507.     private:
  508.         int restore;        // restore state on exit flag
  509.         int page;           // previous screen page
  510.         int *scr_buf;       // screen buffer
  511.         int y, x;           // cursor location
  512.         int rows, cols;     // row/col count
  513.         int mode;
  514.     public:
  515.         ScreenState ();
  516.         ~ScreenState ();
  517. };
  518.  
  519.  
  520. /*
  521.  * Some tools Previously in WinTools.hpp
  522.  */
  523.  
  524. void Win_Calculator ();
  525.  
  526. void Win_Calc_colors (int win_attr = _GREEN|BLACK, int bor_attr = _GREEN|WHITE);
  527.  
  528. void Win_Calendar ();
  529.  
  530. char *Win_File_Pick (char *file_spec, int win_attr = _CYAN|WHITE,
  531.         int bor_attr = _CYAN|BLACK );
  532.  
  533. void Win_Error (char *msg = "Error", int win_attr = _RED|BLACK,
  534.         int bor_attr = _RED|WHITE);
  535.  
  536. void Win_Msg (char *msg = "Hello", int win_attr = _BLUE|WHITE,
  537.         int bor_attr = _BLUE|BLACK);
  538.  
  539. char Win_Get_Choice (char *msg, char *choices, int win_attr = _GREEN|BLACK,
  540.         int bor_attr = _GREEN|WHITE);
  541.  
  542. int Win_Get_YN (char *msg = "Yes or No", int winattr = _GREEN|BLACK, 
  543.     int borattr = _GREEN|BLACK);
  544.  
  545. class Win_File_List {
  546.     friend int File_Spec_Valid (void *obj, void *file_list);
  547.     friend int File_List_Valid (void *obj, void *file_list);
  548.  
  549.     private:
  550.         enum { GETSIZE  = 28,
  551.                MAXPFILES = 150 };
  552.  
  553.         char 
  554.             *Title,
  555.             Input_Str[GETSIZE + 1],
  556.             Old_Spec[81],
  557.             *File_List[MAXPFILES],
  558.             *choice;
  559.         int 
  560.             Count,
  561.             Selected,
  562.             Win_Attr,
  563.             Bor_Attr,
  564.             Bor_Type,
  565.             Get_Attr,
  566.             Button_Attr,
  567.             start_y,
  568.             start_x;
  569.         GetObj_P *PL;
  570.         WinObj *W;
  571.  
  572.         void reset ();
  573.         int Build_List ();
  574.         void Free_List ();
  575.         
  576.     public:
  577.         Win_File_List ();
  578.         ~Win_File_List ();
  579.         int set_attr (int newattr);
  580.         int set_getattr (int newattr);
  581.         int set_butattr (int newattr);
  582.         int position (int y, int x);
  583.         int change_border (int type, int newattr);
  584.         char *read (char *spec = "*.*");
  585. };
  586.  
  587.  
  588. #endif  //  #ifndef LVSWIN_HPP
  589.