home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 3.ddi / BROWSE2.ZIP / BROWSE.CPP
Encoding:
C/C++ Source or Header  |  1990-09-28  |  116.8 KB  |  2,932 lines

  1.  
  2. // 2926 lines, includes inline Object.hpp, Button.hpp, Slider.hpp, TextArea.hpp
  3. //      Friend.hpp, Dispatch.cpp, Ishdmous.cpp, YOU MUST MAKE THESE SEPARATE
  4. //      files else (1) insuf memory to compile (2) my includes will fail.
  5. //                     ^^^^^^^^^^^^                ^^^^^^^^^^
  6. //      Browses current directory for *.c, *.cpp, *.hpp files and shows
  7. //      objects in use, many with no labels or handles at all using a group
  8. //      concept. Demonstrates limites multitasking with a busy wheel and a
  9. //      counter.
  10. //
  11. //      Uses Zortech C++ compiler supporting AT&T version 2.0, use:-
  12. //      " -a -g -w -ml fg.lib "  to compile it
  13. //      
  14. //      For C++ before 2.0 USE -1 -g -w -ml fgl.lib AND alter static class
  15. //      data initialisers from being outside the class to being back in the
  16. //      class. I could have used a special constructor making static inits
  17. //      language level independant.
  18. //
  19. //      Bugs exist, are trivial. Intent to spur interest in object oriented
  20. //      programming for workstation logic. See OBJECT.C and OBJECT.CPP that
  21. //      were uploaded earlier. Intent is to use objects where useful, but not
  22. //      to over do it. Does NOT use any Zortech classes, only the fg functions.
  23.  
  24. //------------------------------------------------> config.hpp <-------------
  25. /* [ ] ---CONFIG.HPP------ PC OR COMPANY SPECIFIC DATA ---------------- [ ] */
  26. /*  |                                                                    |  */
  27. /*  |  Needed because fg_init_all() does not always detect vga12 in      |  */
  28. /*  |  2.0, even though it does prior to 2.0                             |  */
  29. /*  |                                                                    |  */
  30. /* [ ] ---------------------------------------------------------------- [ ] */
  31.  
  32. #ifndef confighpp
  33. #define confighpp
  34.  
  35. /////// How to get fg_init_all to work under c++ 2.0
  36. //
  37. #define ISHDGraphicsOpen fg_init_all
  38. //                       fg_init_vga12          vga systems (AMEX)
  39. //                       fg_init_all            ega and general systems
  40. //
  41. /////// Under 1.7 fg_init_all works on vga
  42.  
  43.  
  44.  
  45.  
  46. /////// Key c++ 2.0 and 1.7 differences ///// Static initialised data
  47. //
  48. //      c++ 1.7                         c++ 2.0
  49. //
  50. //      class A { static int a=2;       class A { static int a;
  51. //      }                               }
  52. //                                      A::a=2;
  53. //
  54. //
  55. /////// Key C++ 2.0 and 1.7 differences ///// function definitions
  56. //
  57. //      C++ 1.7                         C++ 2.0
  58. //
  59. //      Subr() { ; }                    void Subr(void) { ; }
  60. //
  61. //
  62. //      in 1.7 a function with no return type is int, as is 2.0, however
  63. //      in 2.0 if declared as int (no void) then the function MUST return
  64. //      a value. Similarly you will get burned on paramaters, so always
  65. //      put void if none is intended.
  66. //
  67.  
  68. /////// Key c++ 2.0 and 1.7 differences ///// Pointers to functions 
  69. //
  70. //      c++ 1.7                         c++ 2.0
  71. //
  72. //      class Button {                  class Button {
  73. //1     void (* Notifier)();            void (* Notifier)(Button *);
  74. //
  75. //2     Button(,void (*fn)(),)          Button(,void (*fn)(Button *),)
  76. //
  77. //3             Notifier = fn;                  Notifier = fn;
  78. //      };                              };
  79. //4     notify() { ; }                  void notify(Button *) { ; }
  80. //5     main() { new Button(,notify,);  main() { new Button(,notify,);
  81. //
  82. //
  83. //      1. A pointer to a function, in 2.0 the pointer must by typed.
  84. //      2. As a parameter of a function the return and parameter types
  85. //         of the function being passed must be typed.
  86. //      3. Assignment of the parameter to the pointer is the same.
  87. //      4. All functions referenced MUST be typed, even if nulls.
  88. //      5. Invoking a function passing a pointer to a function is the same.
  89.  
  90. #endif
  91. /* END of config.hpp */
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. //------------------------------------------------------> object.hpp <--------
  113. /* [ ] - - - - - - - - - - - - - O B J E C T - - - - - - - - - - - - - - [ ] */
  114. /*  |                                                                     |  */
  115. /*  |  CLASS HIEARCHY:       Object <1>                                   |  */
  116. /*  |                          |                                          |  */
  117. /*  |    +----------+----------+----------+----------+----------+         |  */
  118. /*  |    |          |          |          |          |          |         |  */
  119. /*  |    Button     TextArea   HostLU2    Network    o          o         |  */
  120. /*  |    | <2>      |          |          |                               |  */
  121. /*  |    Slider     o          o          o                               |  */
  122. /*  |    |                                                                |  */
  123. /*  |    o                                                                |  */
  124. /*  |                                                                     |  */
  125. /*  |                                                                     |  */
  126. /*  |                                                                     |  */
  127. /*  |                                                                     |  */
  128. /*  |                                                                     |  */
  129. /*  |   <1> Object includes Friend.hpp the friends of derived classes     |  */
  130. /*  |   <2> Button includes Dispatch.hpp as Dispatch uses a Button        |  */
  131. /*  |       Button includes Ishdmous.cpp as Button absolutley needs it    |  */
  132. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  133.  
  134. /* [ ] - - - - - - - - - - - - - O B J E C T - - - - - - - - - - - - - - [ ] */
  135. /*  |  Object.hpp defines a class "Object" for other system compatability |  */
  136. /*  |                                                                     |  */
  137. /*  |  SetClassTraceOn()  Off()  Enable or disable debugging.             |  */
  138. /*  |  GetFreeGroupId()          Get a group id, two forms allowed,       |  */
  139. /*  |                            Returns an id for Group concept objects. |  */
  140. /*  |                                                                     |  */
  141. /*  |  obj->GetClassName()       Returns the class name of an object      |  */
  142. /*  |  obj->GetClassCode()       Returns an integer identifyinh the class |  */
  143. /*  |                                                                     |  */
  144. /*  |  Object-----Button         Mouse selectable button                  |  */
  145. /*  |             Text           Text area                                |  */
  146. /*  |             Hostlu2        Host sessions with HLLAPI                |  */
  147. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  148. #include "Config.hpp"           // local system configuration
  149. #ifndef ObjectDefined           // compiler switch to not re compile
  150. #define ObjectDefined
  151. #include <stdio.h>
  152. #include <string.h>
  153. #include <stdlib.h>
  154. #include <conio.h>
  155.  
  156. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  157. /*  |  Object.hpp defines a class, "Object" to be compatible with other   |  */
  158. /*  |  systems, for example Objective C and Smalltalk. Our constructor    |  */
  159. /*  |  is be called before the sub or derived class.                      |  */
  160. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  161.  
  162. #define ObjectMaxEverAllowed 500        // current objects in existance 
  163. class Object {                          //
  164.         //                              //
  165.         // class variables              //
  166.         static Object * ObjectMasterList[ObjectMaxEverAllowed];
  167.         static int      ObjectCountNow; // objects right now
  168.         static int      ObjectFirstTime;// first time logic
  169.         public:
  170.         static int      ObjectTrace;    // 0=notrace, 1=text 
  171.         private:
  172.         static int      ObjectGroupNow; // group number allocator
  173.  
  174.  
  175.  
  176.  
  177.  
  178.         // instance variables           // code 0001 = Object    class
  179.         protected:                      // code 0010 = Button    "
  180.         int ObjectType;                 // code 0011 = Slider    "
  181.         // 0 = null                     // code 0020 = TextArea  "
  182.         // 1-999     = graphic          // code 0030 = Hostlu2   "
  183.         // 1000-2000 = non graphic      // code 1000 = Network   "
  184.  
  185.  
  186.  
  187.         public:
  188.         Object();                       // constructor - tracks new objects
  189.         virtual ~Object();              // virtual for friend.hpp GroupDelete
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.         public:
  201.  
  202.         // Instance methods/functions needing an object to do their work,
  203.         //          derived classes must implement these to get action,
  204.         //          these are all considered to be common to all objects.
  205.         virtual void GetClassName(char *); // return the name of the class 
  206.         virtual void GetClassCode(int&);   // return the code of the class 
  207.         virtual int GetClassCode();     // overload of the above         
  208.         virtual void Show()     { ; }   // Show is virtual 
  209.         virtual void Hide()     { ; }   // Hide is virtual
  210.         virtual void Select()   { ; }   // Slect is virtual
  211.         virtual void Use()      { ; }   // Use is virtual
  212.         virtual void Busy()     { ; }   // Busy is virtual
  213.         virtual void Swap()     { ; }   // Swap is virtual
  214.         virtual void Fade()     { ; }   // Fade is virtual
  215.         virtual void Read()     { ; }   // Read is virtual
  216.         virtual int GetThisGroup();     // Return the group id when obj built
  217.  
  218.  
  219.  
  220.  
  221.  
  222.         // Friend functions that need no object to perform their work
  223.         //        these need access to the master list of objects that
  224.         //        is why they must be friends.
  225.  
  226.         friend void SetClassTraceOn();  // turn traces on
  227.         friend void SetClassTraceOff(); // turn traces off
  228.         friend int  GetFreeGroupId();   // get a unique group id code
  229.         friend void GroupShow(int);     // show all of a group
  230.         friend void GroupHide(int);     // hide all of a group
  231.         friend void GroupDelete(int);   // delete all of a group
  232. };
  233.  
  234. // STATIC VARIABLE INITIALISERS - VERSION 2.0 OF C++
  235. int Object::ObjectCountNow=0;           // objects right now
  236. int Object::ObjectFirstTime=0;          // first time logic
  237. int Object::ObjectTrace=0;              // 0=notrace, 1=text 
  238. int Object::ObjectGroupNow=0;           // group number allocator
  239.  
  240. // STATIC VARIABLE INITIALISERS IN PRE VERSION 2.0 OF C++ ARE
  241. // placed in the class and coded as:-  "" static int ObjectCountNow=0; ""
  242.  
  243.  
  244. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  245. /*  |   STANDARD MASTER CONSTRUCTOR                                       |  */
  246. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  247.  
  248. Object::Object()                        // standard constructor
  249. {       ObjectCountNow++;               // add to live objects right now
  250.         ObjectType=1;                   // derived class may alter
  251.         if      ( ObjectFirstTime++ )   // startup code if any
  252.         {       int * test;             // check 2 or 4 bytes for memory
  253.                 if      ( sizeof(test) != 4 ) 
  254.                 {       printf("Compile with large memory model\n");
  255.                 }
  256.         }
  257.         for (int i=0; i<ObjectMaxEverAllowed; i++) 
  258.         {       if      ( ObjectMasterList[i]  == (Object *) 0 )   
  259.                 {       ObjectMasterList[i]  = this;    
  260.                         break;          // exit as operation completed
  261.                 }                       
  262.         }
  263.         if      ( ObjectTrace ) printf("Object created\n");
  264. }                                       // end of constructor        
  265.  
  266. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  267. /*  |   STANDARD MASTER DESTRUCTOR                                        |  */
  268. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  269.  
  270. Object::~Object()                       // standard destructor
  271. {       ObjectCountNow--;               // sub from live objects right now
  272.  
  273.         if      ( ObjectTrace ) printf("Object deleted\n");
  274.  
  275.         if      ( !ObjectCountNow )     // if no objects left
  276.         {       if ( ObjectTrace) printf("Down to zero objects\n");
  277.         }
  278.  
  279.         for (int i=0; i<ObjectMaxEverAllowed; i++) 
  280.         {       if      ( ObjectMasterList[i]  == this )   
  281.                 {       ObjectMasterList[i]  = (Object *) 0;    
  282.                         break;          // exit as actual object found
  283.                 }               
  284.         }
  285. }                                       // end of destructor       
  286.  
  287.  
  288. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  289. /*  |   FRIEND TO TURN TRACES ON OR OFF                                   |  */
  290. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  291.  
  292. // Friend functions allowing direct function call as opposed to via object
  293.  
  294. inline void SetClassTraceOn()
  295. {       Object::ObjectTrace=1;          // class variable set on
  296.         printf("Object traces are on\n");
  297. }
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304. inline void SetClassTraceOff()
  305. {       Object::ObjectTrace=0;          // class variable set off
  306.         printf("Object traces are off\n");
  307. }
  308.  
  309.  
  310. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  311. /*  |   FRIEND TO RETURN A FREE-GROUP-ID TO ALLOW LOGICAL GROUPS          |  */
  312. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  313.  
  314. inline int GetFreeGroupId()             // get a unique group id code
  315. {       Object::ObjectGroupNow++;       // add to unique code
  316.         return(Object::ObjectGroupNow); // return value
  317. }
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  333. /*  |   MEMBER TO RETURN A CLASS NAME char OR CLASS CODE int              |  */
  334. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  335.  
  336. void Object::GetClassCode(int &i)       // return the name of the class 
  337. {       i=ObjectType;                   // return the object item type
  338. }
  339.  
  340. int Object::GetClassCode()              // overload of the above        
  341. {       return(ObjectType);             
  342. }
  343.  
  344.  
  345. void Object::GetClassName(char * cl)    // return the name of the class 
  346. {       strcpy(cl,"Object  ");          // default is cl8'object'
  347. }
  348.  
  349. int Object::GetThisGroup()              // return a group id
  350. {       return(0);                      // no group code as is "Object" class
  351. }
  352.  
  353.  
  354. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  355. /*  |   GENERAL CONCLUDING NOTES ABOUT Object CLASS                       |  */
  356. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  357.  
  358. /*      The general structure of a program using these classes created is:-
  359.          include <stdio.h>              // must be first                0
  360.          include "object.hpp"           // base class file              1----+
  361.          include "button.hpp"           // derived class file           2--+ |
  362.          include "textarea.hpp"         // derived class file           2  | |
  363.          include "hostlu2.hpp"          // derived class file           2  | |
  364.          include "slider.hpp"           // derived from Button          3  | |
  365.          include "dispatch.hpp"         // dispatcher for subtasks      4<-+ |
  366.          include "ishdmous.cpp"         // mouse handler                5<-+ v
  367.          inclide "friend.hpp"           // friend functions             6<---+
  368.         ... user program ...
  369. */
  370. #include "Friend.hpp"                   // friends of derived classes that
  371. #endif                                  // are common to most classes 
  372.  
  373. /* END of Object.hpp */
  374.  
  375.  
  376. //------------------------------------------------------> friend.hpp <-------
  377. /* [ ]--- FRIEND.HPP------- C L A S S     R U L E S --------------------[ ] */
  378. /*  |                                                                    |  */
  379. /*  |     GroupShow(int)        Show all of a button group               |  */
  380. /*  |     GroupHide(int)        Hide all of a button group               |  */
  381. /*  |     GroupDelete(int)      Delete all of a button group             |  */
  382. /*  |                                                                    |  */
  383. /*  |                   *** INCLUDED BY OBJECT ***                       |  */
  384. /*  |                                                                    |  */
  385. /* [ ]------------------------------------------------------------------[ ] */
  386.  
  387.  
  388. #ifndef FriendDefined
  389. #define FriendDefined
  390.  
  391.  
  392. // friend functions - group delete needs list access
  393. //      friend GroupHide(int);          // group HIDE            
  394. //      friend GroupShow(int);          // group show variation
  395. //      friend GroupDelete(int);        // group delete variation
  396.  
  397.  
  398. void GroupShow(int g)                   // FRIEND of Object base class
  399.  
  400. {       // function as a friend and not a class member
  401.         // given a integer group, show all of them
  402.         // this is public and is a friend
  403.         // works for Buttons and Textareas etc as Show is virtual
  404.  
  405.         for (int i=0; i<ObjectMaxEverAllowed; i++)
  406.         {       if  ( Object::ObjectMasterList[i] != (void *) 0 )
  407.                 {       if ( Object::ObjectMasterList[i]->GetThisGroup() == g )
  408.                         {       Object::ObjectMasterList[i]->Show(); 
  409.                         }
  410.                 }
  411.         }
  412. }
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420. void GroupHide(int g)                   // Friend of Object base class
  421.   
  422. {       for (int i=0; i<ObjectMaxEverAllowed; i++)
  423.         {       if  ( Object::ObjectMasterList[i] != (void *) 0 )
  424.                 {       if ( Object::ObjectMasterList[i]->GetThisGroup() == g )
  425.                         {       Object::ObjectMasterList[i]->Hide(); 
  426.                         }
  427.                 }
  428.         }
  429. }
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442. void GroupDelete(int g)                 // Friend of Object base class
  443.  
  444. {       // this uses the list and given a group identifier it deletes for
  445.         // the same user group (first parm on the button constructor) it
  446.         // finds all matching objects and deletes them.
  447.  
  448.         for (int i=0; i<ObjectMaxEverAllowed; i++)
  449.         {       if  ( Object::ObjectMasterList[i] != (void *) 0 )
  450.                 {       if ( Object::ObjectMasterList[i]->GetThisGroup() == g )
  451.                         {       // The destructors of each class that have
  452.                                 // groups MUST BE VIRTUAL, if not then the
  453.                                 // destructor is not found and the objects
  454.                                 // remain i=on the screen and in memory.
  455.                                 delete Object::ObjectMasterList[i]; 
  456.                         }
  457.                 }
  458.         }
  459. }
  460.  
  461.  
  462.  
  463.  
  464. /******
  465. * END *
  466. ******/
  467.  
  468. #endif
  469.  
  470. /* [] END of friend.hpp [] */
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486. //----------------------------------------------> ishdmous.cpp <------------
  487. /* [ ] ------- ISHDMOUS.CPP ------------------------------------------ [ ] */
  488. /*  |                                                                   |  */
  489. /*  |  This handles the primitive operations use by the mouse handler   |  */
  490. /*  |  in the Button Class. This is for Zortech and NOT for Borland.    |  */
  491. /*  |                                                                   |  */
  492. /*  |  MOPEN()                    Open the mouse for general use        |  */
  493. /*  |                                                                   |  */
  494. /*  |  int MINFO(&x,&y,           Acquire current state and if any      |  */
  495. /*  |            &l,&m,&r,        changes have happened.                |  */
  496. /*  |            &stus)                                                 |  */
  497. /*  |                                                                   |  */
  498. /* [ ] --------------------------------------------------------------- [ ] */
  499.  
  500. #include <stdio.h>              /* *** INCLUDED BY BUTTON.HPP *** */
  501. #include <msmouse.h>
  502. #ifndef ishdmouscpp
  503. #define ishdmouscpp
  504.  
  505. // static means it has file scope only
  506. static unsigned int MouseLastX=20, MouseLastY=20;// remember where we are
  507.  
  508. /* [ ] --------------------------------------------------------------- [ ] */
  509. /*  |  NEXT HIGHER LEVEL CODE, AS USED BY A NOTIFIER PROCESS            |  */
  510. /* [ ] --------------------------------------------------------------- [ ] */
  511.  
  512. MOPEN()
  513. {  if ( ! (msm_init() == -1) )
  514.    {  fputs("Cannot initialize mouse.", stderr) ;
  515.       fputs("\nNeed mouse driver to be installed (GOMOUSE).\n", stderr) ;
  516.       getch();
  517.       return(0);                       /* RETURN 0 if error */
  518.    }
  519.    msm_setcurpos(MouseLastX,MouseLastY);
  520.    msm_showcursor();                            
  521.    return(1);                          /* RETURN 1 if it went ok */
  522. }
  523.  
  524.  
  525. MCLOSE()
  526. {  msm_hidecursor() ;
  527.    msm_term() ;
  528. }
  529.  
  530. /* [ ] --------------------------------------------------------------- [ ] */
  531. /*  |  My logic as opposed to the original authors logic                |  */
  532. /* [ ] --------------------------------------------------------------- [ ] */
  533.  
  534. int MINFO_LC(int *x, int *y,   int *l, int *m, int *r)
  535. {    int bits;
  536.      static unsigned int lx,ly, ll,lm,lr;       int stus;
  537.  
  538.      ll=lr=lm=0;
  539.      bits = msm_getstatus(&lx, &ly);   /* update button status */
  540.      if  ( bits == 1 ) ll=1;
  541.      if  ( bits == 2 ) lr=1;
  542.      if  ( bits == 4 ) lm=1;
  543.  
  544.      lx=lx/8+1;         ly=ly/8+1;     stus=0;
  545.      if ( *x!=lx || *y!=ly || *l!=ll ||*m!=lm ||  *r!=lr )
  546.         stus=1; 
  547.      *x=lx;             *y=ly;           *l=ll;           *m=lm;     *r=lr;
  548.  
  549.      return(stus);
  550. }
  551.  
  552. /* [ ] --------------------------------------------------------------- [ ] */
  553. /*  |  My logic as opposed to the original authors logic                |  */
  554. /* [ ] --------------------------------------------------------------- [ ] */
  555.  
  556. int MINFO_XY(int *x, int *y,   int *l, int *m, int *r)
  557. {    int bits;
  558.      static unsigned int lx,ly, ll,lm,lr;       int stus;
  559.  
  560.      ll=lr=lm=0;
  561.      bits = msm_getstatus(&lx, &ly);   /* update button status */
  562.      if  ( (bits & 1) == 1 ) ll=1;
  563.      if  ( (bits & 2) == 2 ) lr=1;
  564.      if  ( (bits & 4) == 4 ) lm=1;
  565.  
  566.      stus=0;
  567.      if ( *x!=lx || *y!=ly || *l!=ll ||*m!=lm ||  *r!=lr )
  568.         stus=1; 
  569.      *x=lx;         *y=ly;    *l=ll;   *m=lm;     *r=lr;
  570.      MouseLastX=lx; MouseLastY=ly;
  571.      return(stus);
  572. }
  573.  
  574. /* ...
  575.  
  576. main()
  577. {  int X,Y,x,y,   l,m,r,    stus;
  578.    MOPEN();       system("cls");
  579.  
  580.    while( !kbhit() )
  581.    {   if  (   stus=MINFO_LC(&x,&y, &l,&m,&r)   )
  582.        {  
  583.           printf("\n x:y= %3d, %3d ", x,y ) ;
  584.           l ? printf(" Left  DOWN ") : printf(" Left  UP  ") ;
  585.           r ? printf(" Right DOWN ") : printf(" Right UP  ") ;
  586.           MINFO_XY(&X,&Y, &l,&m,&r); 
  587.           printf("X:Y= %3d, %3d \n", X,Y ) ;  
  588.        }
  589.    }
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.    char c = getch();
  598.    while( !kbhit() )
  599.    {   if  (   stus=MINFO_LC(&x,&y, &l,&m,&r)   )
  600.        {  
  601.           MINFO_XY(&X,&Y, &l,&m,&r); 
  602.           if ( l+m+r>0 ) break;
  603.        }
  604.    }
  605.    MCLOSE();
  606. }  
  607.  
  608. ... */
  609.  
  610.  
  611. /* END of ishdmous.cpp */
  612.  
  613. #endif
  614.  
  615.  
  616.  
  617.  
  618. //----------------------------------------------> button.hpp <---------------
  619. /* [ ]--- BUTTON.HPP ------ C L A S S     R U L E S --------------------[ ] */
  620. /*  |                                                                    |  */
  621. /*  | Each Button is defind with NEW and needs a group id, x, y and      |  */
  622. /*  | startup text. The group is an integer and collects buttons as      |  */
  623. /*  | groups, so that SELECT, USE etc automatically cause all others     |  */
  624. /*  | in the group to go to a state of SHOW. The group can be used for   |  */
  625. /*  | a group delete or group hide. Groups and in fact all buttons are   |  */
  626. /*  | held in a private list, and PvtGroupShow ( above function) is also |  */
  627. /*  | private. Group funcions are in Object class and are not here!      |  */
  628. /*  |                                                                    |  */
  629. /*  | Functions are "new", SHOW/HIDE, SELECT, USE, SWAP, FADE, BUSY,     |  */
  630. /*  | READ and Notify. Notify is invoked when the mouse is in the box    |  */
  631. /*  | and clicked, or when USE is invoked.                               |  */
  632. /*  |                                                                    |  */
  633. /* [ ]------------------------------------------------------------------[ ] */
  634.  
  635. MOPEN();
  636. MCLOSE();
  637. int MINFO_LC(int *x, int *y,   int *l, int *m, int *r);
  638. int MINFO_XY(int *x, int *y,   int *l, int *m, int *r);
  639.  
  640. /* [ ]--- BUTTON ---------- O B J E C T    S T A T E S -----------------[ ] */
  641. /*  |                                                                    |  */
  642. /*  | STATE:   0   initialised, hidden                                   |  */
  643. /*  |          1   show      (dark blue, text=white)   (border=cyan)     |  */
  644. /*  |          2   select    (light blue,   "      )   (  "  )           |  */
  645. /*  |          U   use       (white,        " black)   (  "  )           |  */
  646. /*  |          B   busy      (white,        " black)   (  "  )           |  */
  647. /*  |          S*  swap      (white,        " black)   (  "  )           |  */
  648. /*  |          F*  fade      (white,        " black)   (  "  )           |  */
  649. /*  |                                                                    |  */
  650. /*  |          * swap and fade set state to S or F only if prior state   |  */
  651. /*  |            was not numeric.                                        |  */
  652. /*  |                                                                    |  */
  653. /*  |          0   hide (see above)                                      |  */
  654. /*  |          -   read (no change)                                      |  */
  655. /*  |                                                                    |  */
  656. /*  |            *** INCLUDES DISPATCH.HPP AND ISHDMOUS.CPP ***          |  */
  657. /*  |                                                                    |  */
  658. /* [ ]------------------------------------------------------------------[ ] */
  659.  
  660.  
  661.  
  662. /* [ ]--- BUTTON ---------- RELATIONSHIPS ------------------------------ [ ] 
  663.     |                                                                     |  
  664.     | The Button class is related to the Textarea class, and polymorphism |  
  665.     | is extant, as are overloaded functions. Refer to Textarea.HPP and   |  
  666.     | Friend.HPP and Dispatch.HPP.                                        |
  667.     |                                                                     |
  668.     | Below are some examples of overloading and polymorphism. Other      |  
  669.     | cases exist.                                                        |  
  670.     |                                                                     |  
  671.     | polymorphics:         Show(), Hide(), Select(), Use(), ...          |  
  672.     |                                                                     |  
  673.     | group functions in                                                  |  
  674.     | Object class:         GroupShow()                                   |  
  675.     |                       GroupDelete()                                 |  
  676.     |                       GroupHide()                                   |  
  677.     |                                                                     |  
  678.    [ ] ----------------------------------------------------------------- [ ] */
  679.  
  680. #ifndef ButtonDefined
  681. #define ButtonDefined
  682.  
  683.  
  684. /* [ ]--- CRTCLASS ---- M A S T E R   V A R I A B L E S ----------------[ ] */
  685. /*  |                                                                    |  */
  686. /*  |  ObjectCompile    a compiler #define to avoid duplication of       |  */
  687. /*  |                                                                    |  */
  688. /*  |                   1.  #include <fg.h>     for function prototypes  |  */
  689. /*  |                   2.  ObjectMaxYpx        has many uses            |  */
  690. /*  |                   3.  ObjectGraphOpen     graphics open switch     |  */
  691. /*  |                                                                    |  */
  692. /*  |  The above appear at the start of Button & Textarea class defns.   |  */
  693. /*  |                                                                    |  */
  694. /* [ ]------------------------------------------------------------------[ ] */
  695.  
  696.  
  697. /* [ ]--- Button ------ M A S T E R   V A R I A B L E S ----------------[ ] */
  698. /*  |                                                                    |  */
  699. /*  |  ButtonWide       width of the button box in pixels                |  */
  700. /*  |  ButtonTall       height of the button box in pixels               |  */
  701. /*  |  ButtonMax        maximum number of instantiated Button instances  |  */
  702. /*  |                                                                    |  */
  703. /* [ ]------------------------------------------------------------------[ ] */
  704.  
  705.  
  706. /* [ ]--- Button ------ S P E C I A L    N O T E S ---------------------[ ] */
  707. /*  |                                                                    |  */
  708. /*  |  Notifier              the class structure includes a pointer to a |  */
  709. /*  |                        user provided function.                     |  */
  710. /*  |  void (* Notifier)();  Declared in the class structure             |  */
  711. /*  |  void (*fn)(),         Function prototype in constructor           |  */
  712. /*  |  Notifier=fn;          Usage when saved in constructor             |  */
  713. /*  |  (Notifier)(this);     Usage in the Button::Use() function         |  */
  714. /*  |                                                                    |  */
  715. /*  |  GROUP is the first parameter in the constructor, allows caller    |  */
  716. /*  |  to specify logical GROUPS of buttons.                             |  */
  717. /*  |                                                                    |  */
  718. /* [ ]------------------------------------------------------------------[ ] */
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728. /* [ ]--- Button ------ M E M B E R    F U N C T I O N S ---------------[ ] */
  729. /*  |  Show()           Dark blue with cyan border                       |  */
  730. /*  |  Select()         Light blue and all others in the group go Show() |  */
  731. /*  |  Use()            White and all others in the group go to Show().  |  */
  732. /*  |                   then the Notifier function is invoked.           |  */
  733. /*  |  Busy()           A diagnal line rotates clipped in the button.    |  */
  734. /*  |  Swap("...")      The button compresses, expansa with new text     |  */
  735. /*  |  Fade("...")      The button faeds and grows with new text         |  */
  736. /*  |  Hide()           The button is blanked out                        |  */
  737. /*  |  Read(char *)     The button text is returned, useful in notify    |  */
  738. /*  | #GroupDelete()    Hide buttons not hidden then delete them.        |  */
  739. /*  | #GroupShow()      Public function, given any one button of the     |  */
  740. /*  |                   user defined group, SHOW all of the group.       |  */
  741. /*  |  GetThisGroup()   return the group id of this button.              |  */
  742. /*  |  PvtGroupShow(int) Set all buttons not in SHOW state just for this |  */
  743. /*  |                   user defined group, and excluding the present    |  */
  744. /*  |                   button, to SHOW state, dark blue, this is a      |  */
  745. /*  |                   private internal function.                       |  */
  746. /*  |  MouseButtonNotify()  A mouse button otifier given a group         |  */
  747. /*  | # - - - - - - - > These are in Object and use a list               |  */                  
  748. /* [ ]------------------------------------------------------------------[ ] */
  749.  
  750. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  751. /*  |    S T A R T     O F    O B J E C T    T Y P E    B U T T O N       |  */
  752. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  753.  
  754. // globals needed for all class items are here with compile test switch
  755. #ifndef ObjectCompile                   /* this IFDEF logic in other classes */
  756. #define ObjectCompile                   /* stops future global includes */
  757. #include <fg.h>                         /* include if needed for ztc grafics */
  758. #include "Object.hpp"                   /* base class */
  759. int     ObjectMaxYpx;                   /* convert y=0 to top */
  760. int     ObjectGraphOpen = 0;            /* INITIALISED GRAPHICS YET? 1=yes */
  761. #include "ishdmous.cpp"                 /* mouse routines */
  762. #endif
  763.  
  764.  
  765. // globals needed for button class items are here
  766. int     ButtonWide=70,                  /* BOX SIZE horizontally */
  767.         ButtonTall=20;                  /* BOX SIZE vertically */
  768. const   int ButtonMax = 150;            /* number to be remembered - limit */
  769.  
  770.  
  771.  
  772. class   Button    : public Object
  773.  
  774. {       /*   general button control parameters needed are first */
  775.         protected:
  776.         int       ObjectType;           /* 0010 is a button type */
  777.  
  778.         //   state of the button itself
  779.         char      ObjectState;          /* last action */
  780.         int       ObjectGroup;          /* logical group buttons for control */
  781.  
  782.         /*   graphics part of the box   */
  783.         int       top, left;            /* top and left of the box */
  784.         fg_box_t  border;               /* coordinates for box border */
  785.         fg_box_t  box;                  /* coordinates for box */
  786.         int       box_wide,             /* size of the box in x units */
  787.                   box_tall;             /* size of a box in y units   */
  788.  
  789.         /*   text part of the button    */
  790.         int       t, l;                 /* words start at top and left */
  791.         char      word[40];             /* word base is t,l */
  792.  
  793.  
  794.         // globals to this class of objects - one for the entire class
  795.         // static type implies private to others outside of this class
  796.  
  797.         // list used for GROUP functions of all types, routines accessed via
  798.         // list contents do not need to be virtual since list AND the routines
  799.         // are defined in the SAME class.
  800.         static Button * list[ButtonMax]; /* for control of the groups   */
  801.  
  802.  
  803.         //   We need a pointer to a routine to be called when Notifier is
  804.         //   needed, so here it is. This is the USER'S EXIT ROUTINE.
  805.         //   He calls ButtonMouseNotify and it invokes the users Notifier
  806.         //   associated with clicked button, then returns to original caller
  807.         //   of ButtonMouseNotify(group).
  808.         void (* Notifier)(Button *);    // defines a pointer to a function
  809.         //   ^          ^               tells it a pointer as opposed to
  810.         //                              a declaration of a function.
  811.  
  812.         void * DerivedAddr;             // a pointer of any derived class
  813.         //                              // lets derived class entered by a
  814.         //                              // notify exit find the derived data.
  815.  
  816.         // DECLARATIONS FOR CONSTRUCTOR AND DESTRUCTOR FUNCTIONS
  817.         public: Button(int, int, int, char *, void (*fn)(Button *), int, int);
  818.         virtual ~Button();              // virtual for GroupDelete in friend.hpp
  819.  
  820.  
  821.  
  822.         // DECLARATIONS OF member functions below, definition later
  823.         virtual void Show();            /* BLUE -- also invoked by GroupShow */
  824.         virtual void Select();          /* LIGHT BLUE */
  825.         virtual void Use();             /* WHITE */
  826.         virtual void Busy();            /* WHITE -- also shows activities */
  827.         virtual void Swap(char *);      /* WHITE..WHITE */
  828.         virtual void Fade(char *);      /* WHITE..WHITE */
  829.         virtual void Hide();            /* BLACK */
  830.         virtual void Read(char *);      /* no color change */
  831.         virtual int  GetThisGroup();    /* return group id */
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.         // Poymorphic methods/functions needing an object to do their work
  839.         //            implemented as Object needs them for correctness
  840.         virtual void GetClassName(char *);  // return the name of the class 
  841.         virtual void GetClassCode(int&);    // return the code of the class 
  842.         virtual int  GetClassCode();    // return the code of the class 
  843.         
  844.         
  845.         // friend functions - group delete needs list access
  846.         friend ButtonMouseNotify(int);  // mouse/cursor invoke notifier
  847.         friend void SliderNotify(Button *);
  848.  
  849.         // dispatch doesnt actually need friend status but what the heck
  850.         //                              it does work with us.
  851.         friend int Dispatch();          // dispatcher is a friend
  852.  
  853.  
  854.         // private group members - group reset to show status 
  855.         private:
  856.         void PvtGroupShow(int);         /* BLUE for items not in SHOW state */
  857. };                                      // end of the button class
  858.  
  859.  
  860. // C++ constructor for the button class of objects
  861.  
  862. Button::Button  (int xgroup, int xleft, int xtop, char * xword, 
  863.                 void (*fn)(Button *),int xsz=ButtonWide, int ysz=ButtonTall)
  864. {       if (!ObjectGraphOpen)           /* first button logic */
  865.         {       ObjectGraphOpen=1;      /* say not first now */
  866.                 ISHDGraphicsOpen();     // fg_init_all();     EGA
  867.                 //                      // fg_init_vga12();   VGA
  868.                 ObjectMaxYpx = (int) fg_displaybox[FG_Y2]-5 ;
  869.                 for (int i=0; i<ButtonMax; i++) /* list allows control*/
  870.                     list[i] = (Button *) 0;     /* of button groups */
  871.         }
  872.  
  873.         // Set DerivedAddr to 0 assuming no special cases exist, let any
  874.         DerivedAddr = (void *) 0;       // derived classes fill it in
  875.  
  876.         /* build top and left, ZTZ y=0=bottom, we tell user 0=top */
  877.         top=ObjectMaxYpx-xtop;          /* convert y=0 to top */
  878.         left=xleft;                     /* x is standard */
  879.         box_wide=xsz;                   /* set up box size */
  880.         box_tall=ysz;
  881.  
  882.         /* build a bounbary box for (1) clipping and (2) easy drawing */
  883.         border[FG_X1] = left;           
  884.         border[FG_Y1] = top-box_tall;
  885.         border[FG_X2] = left+box_wide;  
  886.         border[FG_Y2] = top; 
  887.  
  888.         /* build the internal box for easy drawing */
  889.         box[FG_X1] = left+1;            
  890.         box[FG_Y1] = top-box_tall+1;
  891.         box[FG_X2] = left+box_wide-1;   
  892.         box[FG_Y2] = top-1; 
  893.  
  894.         /* copy over the text string */
  895.         strcpy(word,xword);
  896.         t=top-17;
  897.         l=left+2;
  898.  
  899.         /* set the state to initial */
  900.         ObjectState='0';
  901.  
  902.  
  903.  
  904.         // set up the notify address for mouse/cursor Notifier
  905.         Notifier = fn;
  906.  
  907.         /* set the group to as specified - group is a group of related */
  908.         ObjectGroup=xgroup;             /* buttons for control */
  909.  
  910.         ObjectType=10;                  /* type = 10 means button */
  911.  
  912.         for (int i=0; i<ButtonMax; i++) /* list to allow */
  913.         {       if  (   list[i]  == (Button *) 0 )      /* control of */
  914.                 {   list[i] = this;     /* buttons and */
  915.                     break;
  916.                 }                       /* groups of them */
  917.        }
  918. }                                       // END OF CONSTRUCTOR LOGIC
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926. // C++ destructor fot the button class of objects
  927.  
  928. Button::~Button()
  929. {       // Hide();  cant invoke HIDE here as it says it is not a class 
  930.         //          member, so we do it inline. Dont hide if already hidden!
  931.  
  932.         if (ObjectState!='0') fg_fillbox(FG_BLACK,FG_MODE_SET,~0,border);
  933.   
  934.         // remove from he array of buttons
  935.         for (int i=0; i<ButtonMax; i++)
  936.         {       if      ( list[i] != (Button *) 0 )
  937.                         if ( list[i]  ==  this )
  938.                                 list[i]  =   (void *) 0; 
  939.         }
  940. }
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  949. /*  |   MEMBER TO RETURN A CLASS NAME char OR CLASS CODE int              |  */
  950. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  951.  
  952. void Button::GetClassCode(int &i)       // return the name of the class 
  953. {       i=ObjectType;                   // return the object item type
  954. }
  955.  
  956. int Button::GetClassCode()              // return the name of the class 
  957. {       return(ObjectType);             // return the object item type
  958. }
  959.  
  960.  
  961. void Button::GetClassName(char * cl)    // return the name of the class 
  962. {       strcpy(cl,"Button  ");          // default is cl8'object'
  963. }
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970. void Button::PvtGroupShow(int xgroup)           // private internal function 
  971.  
  972. {       // this is private - used internally when SELECT/USE issued
  973.  
  974.         // if I select or use this button then all others of the same group
  975.         // drop to a state of show, the following code does that
  976.  
  977.         for (int i=0; i<ButtonMax; i++)
  978.         {       if  ( list[i] != (Button *) 0 )
  979.  
  980.                         if ( list[i]->ObjectGroup == xgroup
  981.                                 && list[i] != this 
  982.                                 && list[i]->ObjectState != '1' )
  983.                                 
  984.                         {       list[i]->Show(); 
  985.                         }
  986.         }
  987. }
  988.  
  989.  
  990.  
  991.  
  992. void Button::Show()
  993. {       // this is invoked by GroupShow function also
  994.         if ( ObjectState!='1' )         // optimise for speed
  995.         {       // border for the box
  996.                 fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  997.                            border,fg_displaybox);
  998.  
  999.                 // box itself         
  1000.                 fg_fillbox(FG_BLUE,FG_MODE_SET,~0,box);
  1001.  
  1002.                 // now show the text
  1003.                 fg_puts(FG_WHITE,FG_MODE_SET,~0,FG_ROT0,l,t,word,fg_displaybox);
  1004.  
  1005.                 // set state to SHOW (BLUE) state
  1006.                 ObjectState='1';
  1007.         }
  1008. }       
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014. void Button::Select()
  1015. {       if ( ObjectState!='2' )                 // optimise for speed
  1016.         {       // ensure all other buttons in group are at show state
  1017.                 // must do this before SELECT so SELECT is on top of SHOWs
  1018.                 PvtGroupShow(ObjectGroup);      // do first in case ovlpng btns
  1019.  
  1020.                 // border for the box
  1021.                 fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  1022.                            border,fg_displaybox);
  1023.  
  1024.                 // box itself         
  1025.                 fg_fillbox(FG_LIGHT_BLUE,FG_MODE_SET,~0,box);
  1026.  
  1027.                 // now show the text
  1028.                 fg_puts(FG_WHITE,FG_MODE_SET,~0,FG_ROT0,l,t,word,fg_displaybox);
  1029.  
  1030.                 // make state now selected, but not yet in use 
  1031.                 ObjectState='2';
  1032.                 if ( DerivedAddr )  (*Notifier)(this); // call Slider notifier
  1033.         }       // special case for derived class, mouse cursor is off now.
  1034. }       
  1035.  
  1036. void Button::Use()
  1037. {
  1038.         // ensure all other buttons in group are at show state BEFORE work
  1039.         PvtGroupShow(ObjectGroup);
  1040.  
  1041.         // border for the box
  1042.         fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,border,fg_displaybox);
  1043.  
  1044.         // box itself         
  1045.         fg_fillbox(FG_WHITE,FG_MODE_SET,~0,box);
  1046.  
  1047.         // now show the text and specify we are in a new state
  1048.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,l,t,word,fg_displaybox);
  1049.         ObjectState='U';
  1050.  
  1051.         (*Notifier)(this);              // call users notify proc he wanted
  1052.                                         // at button build time - passing
  1053.                                         // "this" instance of the object
  1054.                                         // member of this class.
  1055. }       
  1056.  
  1057.  
  1058. void Button::Busy()
  1059. {       fg_line_t tln;
  1060.  
  1061.         // first build a line parameter box from the box (not border) values
  1062.         for (int i=0; i<3; i++)
  1063.  
  1064.         {   tln[FG_X1] = left+1;                
  1065.             tln[FG_Y1] = top-1;
  1066.             tln[FG_X2] = left+box_wide-1; 
  1067.             tln[FG_Y2] = top-box_tall+1;
  1068.  
  1069.         // then we will roll the line by working x keeping y or
  1070.         // working y and keeping x, we let fg_functions use "box"
  1071.         // as opposed to border to clip the line, making it look
  1072.         // nice.
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.             while ( tln[FG_Y1]>box[FG_Y1] )     
  1081.             {   fg_fillbox(FG_WHITE,FG_MODE_SET,~0,box);
  1082.             //  fg_drawline(FG_RED,FG_MODE_SET,~0,FG_LINE_SOLID,tln);
  1083.                 fg_drawthickline(FG_RED,FG_MODE_SET,~0,FG_LINE_SOLID,tln,box,6);
  1084.                 tln[FG_Y1] --;          
  1085.                 tln[FG_Y2] ++;              
  1086.                 fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,l,t,word,
  1087.                         fg_displaybox);
  1088.                 Dispatch();             // give some time to multi tasker
  1089.             }
  1090.  
  1091.             while ( tln[FG_X1]<box[FG_X2] )     
  1092.             {   fg_fillbox(FG_WHITE,FG_MODE_SET,~0,box);
  1093.             //  fg_drawline(FG_RED,FG_MODE_SET,~0,FG_LINE_SOLID,tln);
  1094.                 fg_drawthickline(FG_RED,FG_MODE_SET,~0,FG_LINE_SOLID,tln,box,6);
  1095.                 tln[FG_X1] ++;          tln[FG_X2] --;              
  1096.                 fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,l,t,word,
  1097.                         fg_displaybox);
  1098.                 Dispatch();             // give some time to multi tasker
  1099.             }
  1100.  
  1101.  
  1102.         // we have now finished the line rolling logic
  1103.         }                               // end of the for loop
  1104.  
  1105.         // set state to busy
  1106.         ObjectState='B';
  1107.  
  1108.         // draw the border
  1109.         fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  1110.                    border,fg_displaybox);
  1111.  
  1112.         // box itself         
  1113.         fg_fillbox(FG_WHITE,FG_MODE_SET,~0,box);
  1114.  
  1115.         // now redisplay text as probably clobbered
  1116.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,l,t,word,
  1117.                 fg_displaybox);
  1118.  
  1119.         // ensure all other buttons in group are at show state
  1120.         PvtGroupShow(ObjectGroup);
  1121. }       
  1122.  
  1123.  
  1124. void Button::Swap(char * text) 
  1125. {       fg_box_t  tbx;                  
  1126.  
  1127.         // box itself temporarily set up as we will reduce/expand x values
  1128.         tbx[FG_X1] = border[FG_X1];     // use border not box so the border             
  1129.         tbx[FG_Y1] = border[FG_Y1];     // will shrisk also, if you used box
  1130.         tbx[FG_X2] = border[FG_X2];     // the border would stay while the
  1131.         tbx[FG_Y2] = border[FG_Y2];     // insides shrank, looks tacky
  1132.  
  1133.         while ( tbx[FG_X1]<tbx[FG_X2] ) 
  1134.         {       fg_fillbox(FG_LIGHT_BLUE,FG_MODE_SET,~0,tbx);
  1135.                 for (int j=0; j<1000; j++)  ;           // 1000 to 4000
  1136.                 fg_fillbox(FG_BLACK,FG_MODE_SET,~0,tbx);
  1137.                 tbx[FG_X1] ++;          
  1138.                 tbx[FG_X2] --;              
  1139.                 // allow multi tasking one call in 4    (4 use 0003)
  1140.                 if ( !(tbx[FG_X1] & 0x0003) ) Dispatch(); 
  1141.         }
  1142.  
  1143.  
  1144.  
  1145.  
  1146.         while ( tbx[FG_X2]<left+box_wide )      
  1147.         {       fg_fillbox(FG_LIGHT_BLUE,FG_MODE_SET,~0,tbx);
  1148.                 for (int j=0; j<1000; j++)  ;           // 1000 to 4000
  1149.                 tbx[FG_X1] --;          
  1150.                 tbx[FG_X2] ++;              
  1151.                 // allow multi tasking one call in 4    ( 8 use 0007)
  1152.                 if ( !(tbx[FG_X1] & 0x0003) ) Dispatch(); 
  1153.         }
  1154.  
  1155.         // finally redraw the border and the box
  1156.         fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,border,fg_displaybox);
  1157.         fg_fillbox(FG_WHITE,FG_MODE_SET,~0,box);
  1158.  
  1159.         // then redraw the text and reset the state
  1160.         strcpy(word,text);
  1161.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,l,t,word,fg_displaybox);
  1162.         ObjectState='B';
  1163.  
  1164.         // ensure all other buttons in group are at show state
  1165.         PvtGroupShow(ObjectGroup);
  1166. }       
  1167.  
  1168. void Button::Fade(char * text)
  1169.  
  1170. {       int rx,ry;
  1171.         /* fade out */
  1172.         for (int i=0;i<4000;i++)
  1173.         {       rx= left + ( rand()%box_wide ); 
  1174.                 ry= top  - ( rand()%box_tall ); 
  1175.                 fg_drawdot(FG_BLACK,FG_MODE_SET,~0,rx,ry);
  1176.                 // allow multi tasking one call in 64
  1177.                 if ( !(i & 0x003f) ) Dispatch(); 
  1178.         }
  1179.         /* fade in */
  1180.         for (i=0;i<3000;i++)
  1181.         {       rx= left + ( rand()%box_wide ); 
  1182.                 ry= top  - ( rand()%box_tall ); 
  1183.                 fg_drawdot(FG_WHITE,FG_MODE_SET,~0,rx,ry);
  1184.                 // allow multi tasking one call in 64
  1185.                 if ( !(i & 0x003f) ) Dispatch(); 
  1186.         }
  1187.  
  1188.  
  1189.  
  1190.         // draw the border again
  1191.         fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  1192.                    border,fg_displaybox);
  1193.  
  1194.         // draw the box inside the border
  1195.         fg_fillbox(FG_WHITE,FG_MODE_SET,~0,box);
  1196.  
  1197.         // reshow the text in the box
  1198.         strcpy(word,text);
  1199.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,l,t,word,fg_displaybox);
  1200.  
  1201.         // specify box state now
  1202.         ObjectState='F';
  1203.  
  1204.         // ensure all other buttons in group are at show state
  1205.         PvtGroupShow(ObjectGroup);
  1206. }
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212. void Button::Hide() 
  1213.  
  1214. {       fg_fillbox(FG_BLACK,FG_MODE_SET,~0,border);
  1215.         ObjectState='0';
  1216. }
  1217.  
  1218.  
  1219. void Button::Read(char * text) 
  1220. {       // used to return the text string in a button, usefull for generic
  1221.         // button list notify processing, so uses doesnt need to remember
  1222.         // all the buttons he created.
  1223.  
  1224.         strcpy(text,word);
  1225. }
  1226.  
  1227.  
  1228. int Button::GetThisGroup()
  1229. {       // used in case someone needs to know their group
  1230.         return(ObjectGroup);
  1231. }
  1232.  
  1233.  
  1234. /*FRIEND*/ButtonMouseNotify(int g)      // public friend runs the mouse 
  1235.  
  1236. #define TB Button::list[i]              // TB means this button - shorthand
  1237. #define BD fg_displaybox                // BD is Boundary Border - shorthand
  1238.  
  1239. {       // given a integer group (not a button), track the cursor till
  1240.         // the mouse hits a button.        
  1241.  
  1242.         // once in a button, must do a msm_hidecursor BEFORE we work graphics
  1243.         // on the screen, and a msm_showcursor after to reenable mouse. If
  1244.         // you dont do this then the graphics inteferes and color fades and
  1245.         // text is shown garbled. <- IMPORTANT NOTICE
  1246.  
  1247.         // the "list" processed is processed from back to front  +---------
  1248.         // so that overlaps are processed ih the box that        |  +--x--
  1249.         // was displayed last rather than in the box that        +--|  
  1250.         // technically owns that geographic area. Thus location     +-----
  1251.         // "x" is in the lower box as displayed not in the upper
  1252.         // box as it is geographically owned. <- IMPORTANT NOTICE
  1253.  
  1254.  
  1255.  
  1256.         int  x,  y,                     // x,y are PRESENT values
  1257.              l,  m,  r,                 // l,m,r are the buttons hit
  1258.              stus,                      // stus id mouse status
  1259.              flag;                      // flag is our control flag 
  1260.         char X[5], Y[5];                // debugging values only
  1261.  
  1262.         MOPEN();                        // fire up the mouse
  1263.  
  1264.         l=m=r=0;                        // say no button hit yet
  1265.         x=y=0;                          // set initial coordinates to 0,0
  1266.         stus=1;                         // set up initial values
  1267.         flag=1;                         // primes the loop
  1268.  
  1269.         while ( flag )                  // while no keys depressed at all
  1270.                                         //
  1271.                                         //
  1272.                                         // following loop run till FLAG!=0
  1273.                                                 //
  1274.                                                 //
  1275.                                                 //
  1276.  
  1277.  
  1278.         // below WHILE group watches the mouse in the buttons
  1279.         // this loop breaks when flag is set to non zero
  1280.  
  1281.         {       Dispatch();             // <<==== friendly multi tasker
  1282.                 if  ( stus=MINFO_XY(&x,&y, &l,&m,&r) )
  1283.                         
  1284.                 {       // fix the Y value from MOUSE to FG_ values         
  1285.                         y = ObjectMaxYpx - y;
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.                         // start end to front to handle box overlap properly.
  1301.                         for (int i=ButtonMax-1; i>-1 ; i--)
  1302.                         {   // multitasker 1 in 15 could be done here
  1303.                             if  ( TB != (Button *) 0 & TB->ObjectGroup == g )
  1304.                                 {  if ( x>TB->left && x<(TB->left+TB->box_wide)
  1305.                                       && y<TB->top && y>(TB->top-TB->box_tall) )
  1306.                                       if ( !(l+m+r) )
  1307.                                       {  msm_hidecursor(); // avoid bad video
  1308.                                          TB->Select();     // clean video
  1309.                                          msm_showcursor(); // allow mouse video
  1310.                                          break;            // skip rest
  1311.                                       }
  1312.                                       else
  1313.                                       {  msm_hidecursor(); // avoid bad video
  1314.                                          //Button::list[i]->Use();
  1315.                                          TB->Use();        // clean video
  1316.                                          msm_showcursor(); // allow mouse video
  1317.                                          flag=0; break;    // skip rest
  1318.                                       }
  1319.                                 }       // end of is it valid & in our group
  1320.                         }               // end of FOR loop checking all buttons
  1321.  
  1322.                 // at this point the whole array has been run and if no key
  1323.                 // hit on the mouse then buttons overlaid are highlighted
  1324.                 // IF they were not already highlighted.
  1325.  
  1326.                 // also if a button was hit in a button then the button
  1327.                 // was USED and this fires up the notify routine.
  1328.  
  1329.                 // this ends the IF that tested for new mouse status
  1330.  
  1331.                 }                       // end of IF ( STUS=INFO_XY()...
  1332.  
  1333.         // this ends the WHILE loop that runs until one action is clicked on
  1334.         // and it is up to the user calling program whether he will re issue
  1335.         // the ButtonMouseNotify() code or not. For example, if the button 
  1336.         // had the word "quit" in it he may break his endless Notifier() loop.
  1337.         
  1338.         }                               // end of WHILE loop
  1339.         MCLOSE();                       // either way we are stopping mice
  1340. }
  1341.  
  1342.  
  1343.  
  1344. /******
  1345. * END *
  1346. ******/
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358. #include "dispatch.hpp"                 // dispatch uses a button
  1359. //       "ishdmous.cpp"                 // included earlier as always needed
  1360.  
  1361. #endif
  1362.  
  1363. /* [] END of button.hpp [] */
  1364.  
  1365.  
  1366. //----------------------------------------------> dispatch.hpp <------------
  1367. /* [ ] --- DISPATCH.HPP ---- D I S P A T C H --------------------------- [ ] 
  1368.     |                                                                     |  
  1369.     | This is a function called whenever anyone has any free CPU time.    |  
  1370.     | The very first time we show a box, and build parameters.            |  
  1371.     | This is a friend of Button and also can be of TEXT. Called whenever |  
  1372.     | the mouse or the keyboard nitifier are running.                     |  
  1373.     | From then on we rotate the busy line one rotation unit and also     |  
  1374.     | allow work that needs to be "simulated" "time shared" or in other   |  
  1375.     | words effectivley multitasked.                                      |  
  1376.     |                                                                     |  
  1377.     | usercode-->|               *** INCLUDED BY BUTTON ***               |  
  1378.     |        ^   |                                                        |  
  1379.     |        |   | Button_MOUSE_NOTIFY()                                  |  
  1380.     |        |   |               |                                        |  
  1381.     |        |   |               DISPATCH() -----> asynch code to be      |  
  1382.     |        |   |                                 pseudo multi tasked    |  
  1383.     |        |   |                                 |                      |  
  1384.     |        +<--|---------------------------------+                      |  
  1385.     |                                                                     |  
  1386.    [ ] --------------------- D I S P A T C H --------------------------- [ ] */
  1387.  
  1388. #ifndef DispatchDefined
  1389. #define DispatchDefined
  1390.  
  1391.  
  1392.  
  1393.  
  1394. #include "object.hpp"                   // dispatch needs object
  1395. #include "button.hpp"                   // dispatch uses button
  1396.  
  1397.  
  1398.  
  1399. //   This is a prototype to keep the compiler happy.
  1400. void Sub_Task_Runner();                 // prototype
  1401.  
  1402.  
  1403.  
  1404. //   This is the dispatcher list.
  1405. #define DispatchMaxTasks 10
  1406. static void (* DispatchTaskList [DispatchMaxTasks])  (void);
  1407.  
  1408.  
  1409.  
  1410. //   To use the DISPATCHER, do the following:
  1411. //      
  1412. //      Attach(subtask);    if 0 returned then not added as no room
  1413. //      Detach(subtask);    if 0 returned then subtask was not found
  1414. //
  1415. //      In code at conveniant points add
  1416. //
  1417. //      Dispatch();
  1418. //
  1419. //      For examples, refer to Button class where the MOUSE is run.
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432. //   This is the Attach subtask routine
  1433. int Attach( void (*fn)(void) )
  1434. {       for (int i=0; i<DispatchMaxTasks; i++)
  1435.         {       if ( DispatchTaskList[i] == (void *) 0 )
  1436.                 {       DispatchTaskList[i] = fn;
  1437.                         return(1);
  1438.                 }
  1439.         }
  1440.         return(0);                      // dispatch returns 0 if no room
  1441. }
  1442.  
  1443. //   This is the Detach subtask routine
  1444. int Detach(void (*fn)() )
  1445. {       for (int i=0; i<DispatchMaxTasks; i++)
  1446.         {       if ( DispatchTaskList[i] == (void *) fn )
  1447.                 {       DispatchTaskList[i] = (void *) 0;
  1448.                         return(1);
  1449.                 }
  1450.         }
  1451.         return(0);                      // dispatch returns 0 if not found
  1452. }
  1453.  
  1454. // Global switch and functions to enable or disable the rotating wheel
  1455. static int SubTaskWheel=1;              // master rotating wheel flag
  1456.  
  1457.  
  1458. // Stop rotating wheel
  1459. void DispatchWheelOff() 
  1460. {       SubTaskWheel=0;                 // stop rotating wheel
  1461. }
  1462.  
  1463. // Start rotating wheel
  1464. void DispatchWheelOn()
  1465. {       SubTaskWheel=1;                 // enable rotating wheel
  1466. }
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476. int Dispatch()
  1477. {       static int status = 0;          // first time or not
  1478.         static Button * DispatchButton;
  1479.         static fg_line_t tln;                   // a line boundary box
  1480.         static int do_down=0, do_along=0;       // what to rotate next
  1481.  
  1482.         if ( !SubTaskWheel ) goto bypass;       // bypass wheel GOTO used to
  1483.                                                 // save indentations !
  1484.         // if first time then build up a busy symbol and build a border box
  1485.         if ( !status)
  1486.         {       status=1;               // cancel first time setup switch
  1487.                 DispatchButton = new Button(0,  550, 13, " ",0, 25,14);
  1488.                 DispatchButton->Show(); // enable the button to be visible
  1489.                 tln[FG_X1] = DispatchButton->left+2;            
  1490.                 tln[FG_Y1] = DispatchButton->top-2;
  1491.                 tln[FG_X2] = DispatchButton->left+
  1492.                              DispatchButton->box_wide-2; 
  1493.                 tln[FG_Y2] = DispatchButton->top-
  1494.                              DispatchButton->box_tall+2;
  1495.                 do_down=1;              // where to start
  1496.         }
  1497.  
  1498.         // coming in here there may or may not be a box, and it may have a
  1499.         // partially rotated line or it may not. the first thing we do is
  1500.         // to redraw the box and remove the old line so we can draw a new
  1501.         // line.
  1502.  
  1503.         // draw the border
  1504.         fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  1505.                    DispatchButton->border,fg_displaybox);
  1506.  
  1507.         // box itself         
  1508.         fg_fillbox(FG_LIGHT_BLUE,FG_MODE_SET,~0,DispatchButton->box);
  1509.  
  1510.         // there is no text to be displayed
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.         // coming in here on the first and subsequent times, we are rotating
  1521.         // the line one rotation unit.
  1522.  
  1523.         // up one side...
  1524.         if ( do_down ) 
  1525.         {       do_along=0;             // no need yet for along
  1526.                 if      ( tln[FG_Y1]  >  DispatchButton->box[FG_Y1] )   
  1527.                 {       fg_fillbox(FG_LIGHT_BLUE,FG_MODE_SET,~0,
  1528.                                 DispatchButton->box);
  1529.                         fg_drawthickline(FG_WHITE,FG_MODE_SET,~0,FG_LINE_SOLID,
  1530.                                 tln,DispatchButton->box,2);
  1531.                         tln[FG_Y1] --;          
  1532.                         tln[FG_Y2] ++;              
  1533.                 }
  1534.                 else
  1535.                 {       do_along=1;             // need "along" now
  1536.                         do_down=0;              // and stop "down"
  1537.                 }
  1538.         }
  1539.  
  1540.  
  1541.  
  1542.         // down the other...
  1543.  
  1544.         if ( do_along )
  1545.         {       do_down=0;              // no need for "down" yet
  1546.                 if      ( tln[FG_X1]  <  DispatchButton->box[FG_X2] )   
  1547.                 {       fg_fillbox(FG_LIGHT_BLUE,FG_MODE_SET,~0,
  1548.                                 DispatchButton->box);
  1549.                         fg_drawthickline(FG_WHITE,FG_MODE_SET,~0,FG_LINE_SOLID,
  1550.                                 tln,DispatchButton->box,2);
  1551.                         tln[FG_X1] ++;          
  1552.                         tln[FG_X2] --;              
  1553.                         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,
  1554.                                 DispatchButton->l,DispatchButton->t,
  1555.                                 DispatchButton->word,fg_displaybox);
  1556.                 }
  1557.  
  1558.                 else
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.                 {       do_along=0;     // no "along" now
  1566.                         do_down=1;      // but do "down"
  1567.  
  1568.                         tln[FG_X1] = DispatchButton->left+2;            
  1569.                         tln[FG_Y1] = DispatchButton->top-2;
  1570.                         tln[FG_X2] = DispatchButton->left+
  1571.                                      DispatchButton->box_wide-2; 
  1572.                         tln[FG_Y2] = DispatchButton->top-
  1573.                                      DispatchButton->box_tall+2;
  1574.                 }
  1575.         }
  1576.  
  1577.         bypass:                         // end of bypass wheel
  1578.  
  1579.         // now the line has been rotated in the box we can call routines that
  1580.         // need time sharing
  1581.         //      =========>> put here calls to asynch tasks ==========>>
  1582.                 Sub_Task_Runner();
  1583.         //      =========>> put here calls to asynch tasks ==========>>
  1584.  
  1585.  
  1586.         // The theory is that the crt class objects all have spare time, this
  1587.         // may be the mouse notifier (Button CLASS RELATED) or the keyboard
  1588.         // notifier, not related to the TEXT class as such but included in
  1589.         // the TEXT class as it is conceptually there. The theory also thinks
  1590.         // that other functions in the class methods have some spare time.
  1591.         // Even an application can decide it has spare time.
  1592.  
  1593.         // All places where spare time exists simply do a call DISPATCH();
  1594.         // and on each call the wheel is rotated one pixel and the subtask
  1595.         // is invoked, if there is one. The subtask may not wait, it must
  1596.         // do work, albeit based on READY-TO-RUN switches, or exit. It
  1597.         // must track itself by state switches, they must thus be static.
  1598.  
  1599.         // This allows the DISPATCHer to call routines, they could access
  1600.         // the serial ports, or anything else. The busy wheel controlled
  1601.         // by the DISPATCHER simply shows the CPU is running ok and how much
  1602.         // spare cpu time there is.
  1603. }       
  1604.  
  1605.  
  1606.  
  1607.  
  1608. void Sub_Task_Runner()
  1609. {       // This function can invoke as many routines as it desires, it could
  1610.         // use a LIST kept some where, and Attach would add functions, and
  1611.         // Detach would remove functions.
  1612.  
  1613.         // Attached and Detached functions could be communications hanlers,
  1614.         // low prioroty disk to print routines
  1615.  
  1616.         // Where for each invocation the subtask would do ONE iteration of
  1617.         // its work.
  1618.  
  1619.         for (int i=0; i<DispatchMaxTasks; i++)
  1620.         {       if ( DispatchTaskList[i] != (void *) 0 )
  1621.                 {       DispatchTaskList[i]();  // <---- this is what actually
  1622.                 }                               //       calls user suntasks
  1623.         }
  1624.  
  1625. }
  1626.  
  1627. #endif
  1628. /* [] END of dispatch.hpp [] */
  1629.  
  1630. //----------------------------------------------> textarea.hpp <-------------
  1631. /* [ ]--- TEXTAREA.HPP ------ C L A S S     R U L E S ------------------[ ] */
  1632. /*  |                                                                    |  */
  1633. /*  | Each "TEXTAREA" is defind with NEW and needs a group id, x, y and  |  */
  1634. /*  | startup text. The group is an integer and collects "TEXTAREAs" as  |  */
  1635. /*  | groups, so that SELECT, USE etc automatically cause all others     |  */
  1636. /*  | in the group to go to a state of SHOW. The group can be used for   |  */
  1637. /*  | a group delete or group hide. Groups and in fact all "TEXTAREAs"   |  */
  1638. /*  | are held in a private list, and PvtGroupShow ( above function) is  |  */
  1639. /*  | also private.                                                      |  */
  1640. /*  |                                                                    |  */
  1641. /*  | Functions are "new", SHOW/HIDE, SELECT, USE, SWAP, FADE, BUSY,     |  */
  1642. /*  | READ and Notifier. Notifier is invoked when the textarea needs     |  */
  1643. /*  | some work.                                                         |  */
  1644. /*  |                                                                    |  */
  1645. /*  | The only difference between TEXTAREA and BUTTON is that TEXTAREA   |  */
  1646. /*  | is usually bigger and some functions do different things.          |  */
  1647. /* [ ]------------------------------------------------------------------[ ] */
  1648.  
  1649. #ifndef TextAreaDefined                 // avoid recompiling if not needed
  1650. #define TextAreaDefined
  1651.  
  1652. /* [ ]--- TEXTAREA -------- O B J E C T    S T A T E S -----------------[ ] */
  1653. /*  |                                                                    |  */
  1654. /*  | STATE:   0   initialised, hidden                                   |  */
  1655. /*  |          1   show      (dark blue, text=white)   (border=cyan)     |  */
  1656. /*  |          2   select    (light blue,   "      )   (  "  )           |  */
  1657. /*  |          U   use       (white,        " black)   (  "  )           |  */
  1658. /*  |          B   busy      (white,        " black)   (  "  )           |  */
  1659. /*  |          S*  swap      (white,        " black)   (  "  )           |  */
  1660. /*  |          F*  fade      (white,        " black)   (  "  )           |  */
  1661. /*  |                                                                    |  */
  1662. /*  |          * swap and fade set state to S or F only if prior state   |  */
  1663. /*  |            was not numeric.                                        |  */
  1664. /*  |                                                                    |  */
  1665. /*  |          0   hide (see above)                                      |  */
  1666. /*  |          -   read (no change)                                      |  */
  1667. /*  |                                                                    |  */
  1668. /* [ ]------------------------------------------------------------------[ ] */
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  1675. /*  |    S T A R T     O F    O B J E C T    T Y P E    T E X T A R E A   |  */
  1676. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  1677.  
  1678. // globals needed for all sws class items are here
  1679. #ifndef ObjectCompile                   /* this IFDEF logic in other classes */
  1680. #define ObjectCompile                   /* stops future global includes */
  1681. #include <fg.h>                         /* include if needed for ztc grafics */
  1682. #include "Object.hpp"                   /* base class */
  1683. #include "friend.hpp"
  1684. int     ObjectMaxYpx;                   /* convert y=0 to top */
  1685. int     ObjectGraphOpen = 0;            /* INITIALISED GRAPHICS YET? 1=yes */
  1686. //#include "ishdmous.cpp"               /* mouse routines */
  1687. #endif
  1688.  
  1689. // globals needed for all sws text class items are here
  1690. int     TextWide=250, TextTall=125;     /* TEXT BOX SIZES */
  1691. const   int MaxTextAreas = 10;          /* number to be remembered - limit */
  1692.  
  1693.  
  1694.  
  1695.  
  1696. class   TextArea : public Object
  1697. {       /*   control area of the box    */
  1698.         int     ObjectType;             /* 0020 is a text type */
  1699.         char    ObjectState;            /* last action */
  1700.         int     ObjectGroup;            /* groups buttons for control */
  1701.  
  1702.         // globals to this class of objects - one for the entire class
  1703.         // static type implies private to others outside of this class
  1704.         static TextArea   * list[MaxTextAreas ]; /* for control of the groups */
  1705.  
  1706.         /*   graphics part of the box   */
  1707.         int     top, left;              /* top and left */
  1708.         fg_box_t  border;               /* coordinates for box border */
  1709.         fg_box_t  box;                  /* coordinates for box */
  1710.         int     box_wide, 
  1711.                 box_tall;               /* size of a box */
  1712.         /*   text part of the button    */
  1713.         int     t, l;   
  1714.         char    word[80];        /* word base is t,l */
  1715.  
  1716.  
  1717.  
  1718.         //   we need a pointer to a routine to be called when Notifier is
  1719.         //   needed, so here it is. 
  1720.         void (* Notifier)(TextArea *);
  1721.  
  1722.  
  1723.         // data areas to support line at a time writes in the box
  1724.         int       cur_line;
  1725.         int       cur_line_max;
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.         // Class constructor and destructor prottypes
  1741.         public: TextArea (int,int,int,char *,void (*fn)(TextArea *),int,int);
  1742.         virtual ~TextArea();            // virtual for GroupDelete in friend.hpp
  1743.  
  1744.  
  1745.         // member functions declared below, definition later
  1746.         virtual void Show();            /* BLUE -- also invoked by GroupShow */
  1747.         virtual void Select();          /* LIGHT BLUE */
  1748.         virtual void Use();                     /* WHITE */
  1749.         virtual void Busy();                    /* WHITE -- also shows activities */
  1750.         int Type(char *,int );          /* line at a time into the box */ 
  1751.         virtual void Swap(char *);              /* WHITE..WHITE */
  1752.         virtual void Fade(char *);              /* WHITE..WHITE */
  1753.         virtual void Hide();                    /* BLACK */
  1754.         virtual void Read(char *);              /* no color change */
  1755.  
  1756.  
  1757.         // friend functions - none defined yet
  1758.         friend int Dispatch();          // same dispatch as the buttons
  1759.  
  1760.  
  1761.  
  1762.         // Instance methods/functions needing an object to do their work
  1763.         virtual void GetClassName(char *);      // return the name of the class 
  1764.         virtual void GetClassCode(int&);     // return the code of the class 
  1765.         virtual int GetClassCode();     // return the code of the class 
  1766.         virtual int GetThisGroup();     // return group code
  1767.  
  1768.         // associated function - need not be a friend as such as is simply
  1769.         // a keyboard reader - it is here as an equivalent to the BUTTON
  1770.         // ButtonMouseNotify() but does not need access to any list so
  1771.         // is not a friend. In fact it has nothing to do with TEXTAREA class
  1772.         // and is only here as is is the TEXTAREA equivalent to the BUTTON 
  1773.         /// notifier.
  1774.         void TextKeyboardNotify();              // keyboard waiter
  1775.  
  1776.         // private group members - group reset to show status 
  1777.         private:
  1778.         void PvtGroupShow(int);                 /* BLUE for items not in SHOW state */
  1779. };
  1780.  
  1781.  
  1782.  
  1783.  
  1784. /* C++ constructor function */
  1785.  
  1786. TextArea::TextArea (int xgroup, int xleft, int xtop, char * xword, 
  1787.                 void (*fn)(TextArea *),int xsz=TextWide , int ysz=TextTall )
  1788.  
  1789. {       if (!ObjectGraphOpen)           /* first button logic */
  1790.         {  ObjectGraphOpen=1;           /* say not first now */
  1791.                 ISHDGraphicsOpen();     // fg_init_all();   EGA
  1792.                 //                      // fg_init_vga12(); VGA
  1793.                 ObjectMaxYpx = (int) fg_displaybox[FG_Y2] - 5 ;
  1794.                 for (int i=0; i<MaxTextAreas ; i++)     /* list allows control*/
  1795.                     list[i] = (TextArea  *) 0;          /* of button groups */
  1796.         }
  1797.  
  1798.         /* build top and left, ZTZ y=0=bottom, we tell user 0=top */
  1799.         top=ObjectMaxYpx-xtop;          /* convert y=0 to top */
  1800.         left=xleft;                     /* x is standard */
  1801.         box_wide=xsz;                   /* set up box size */
  1802.         box_tall=ysz;
  1803.  
  1804.  
  1805.  
  1806.         /* build a boundary box for (1) clipping and (2) easy drawing */
  1807.         border[FG_X1] = left;           
  1808.         border[FG_Y1] = top-box_tall;
  1809.         border[FG_X2] = left+box_wide;  
  1810.         border[FG_Y2] = top; 
  1811.  
  1812.         /* build the internal box for easy drawing */
  1813.         box[FG_X1] = left+1;            
  1814.         box[FG_Y1] = top-box_tall+1;
  1815.         box[FG_X2] = left+box_wide-1;   
  1816.         box[FG_Y2] = top-1; 
  1817.  
  1818.         /* copy over the text string */
  1819.         strcpy(word,xword);
  1820.         t=top-17;
  1821.         l=left+5;
  1822.  
  1823.         /* set the state to initial */
  1824.         ObjectState='0';
  1825.  
  1826.  
  1827.  
  1828.         // set up the notify address for mouse/cursor Notifier
  1829.         Notifier = fn;
  1830.  
  1831.         /* set the group to as specified - group is a group of related */
  1832.         ObjectGroup=xgroup;             /* buttons for control */
  1833.  
  1834.         ObjectType=20;                  /* 20 means text item */
  1835.  
  1836.         cur_line=0;                     /* line at a time function support */
  1837.         cur_line_max =  ysz / (4 + fg_charbox[FG_Y2])  ; 
  1838.  
  1839.         for (int i=0; i<MaxTextAreas ; i++)         /* list to allow */
  1840.         {       if   (  list[i] == (TextArea *) 0 ) /* control of */
  1841.                 {       list[i] = this;             /* buttons and */
  1842.                         break;                      /* groups of them */
  1843.                 }               
  1844.         }
  1845. }                               // end of constructor logic
  1846.  
  1847.  
  1848.  
  1849.  
  1850. /* C++ destructor must remove the text box from view */
  1851.  
  1852. TextArea::~TextArea()
  1853.  
  1854. {       // Hide(); cant invoke as it says not a class member at this time
  1855.         //         so we are doinf the code inline. Dont if already hidden!
  1856.  
  1857.         if (ObjectState!='0') fg_fillbox(FG_BLACK,FG_MODE_SET,~0,border);
  1858.  
  1859.         // remove from the array of buttons
  1860.         for (int i=0; i<MaxTextAreas; i++)
  1861.         {   if  ( list[i] != (TextArea *) 0 )
  1862.                 if ( list[i]  ==  this )
  1863.                        list[i]    =   (void *) 0; 
  1864.         }
  1865. }
  1866.  
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  1873. /*  |   MEMBER TO RETURN A CLASS NAME char OR CLASS CODE int              |  */
  1874. /* [ ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ ] */
  1875.  
  1876. void TextArea::GetClassCode(int &i)             // return the name of the class 
  1877. {       i=ObjectType;                   // return the object item type
  1878. }
  1879.  
  1880. int TextArea::GetClassCode()            // return the name of the class 
  1881. {       return(ObjectType);             // return the object item type
  1882. }
  1883.  
  1884. void TextArea::GetClassName(char * cl)  // return the name of the class 
  1885. {       strcpy(cl,"TextArea");          // default is cl8'object'
  1886. }
  1887.  
  1888. int TextArea::GetThisGroup()            // return group code
  1889. {       return(ObjectGroup);                    
  1890. }
  1891.  
  1892.  
  1893.  
  1894. void TextArea::PvtGroupShow(int xgroup)         // private internal function
  1895.  
  1896. {       // if I select or use this text then all others of the same group
  1897.         // drop to a state of show, the following code does that
  1898.  
  1899.         for (int i=0; i<MaxTextAreas ; i++)
  1900.         {   if  ( list[i] != (TextArea   *) 0 )
  1901.  
  1902.                 if ( list[i]->ObjectGroup == xgroup
  1903.                      && list[i] != this 
  1904.                      && list[i]->ObjectState != '1' )
  1905.  
  1906.                 {    list[i]->Show(); 
  1907.                 }
  1908.         }
  1909. }
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916. void TextArea::Show()
  1917. {       if ( ObjectState!='1')                  
  1918.         // dont reshow if already in show state because text may already have
  1919.         // been TYPEd into the area
  1920.         {       // this is invoked by GroupShow function also
  1921.  
  1922.                 // border for the box
  1923.                 fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  1924.                            border,fg_displaybox);
  1925.  
  1926.                 // box itself         
  1927.                 fg_fillbox(FG_BLUE,FG_MODE_SET,~0,box);
  1928.  
  1929.                 // now show the text
  1930.                 fg_puts(FG_WHITE,FG_MODE_SET,~0,FG_ROT0,l,t,word,fg_displaybox);
  1931.         }
  1932.         cur_line=0;                     /* line at a time function support */
  1933.         // set state to SHOW (BLUE) state
  1934.         ObjectState='1';
  1935. }       
  1936.  
  1937.  
  1938. void TextArea::Select()
  1939. {       // border for the box
  1940.         fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  1941.                    border,fg_displaybox);
  1942.  
  1943.         // box itself         
  1944.         fg_fillbox(FG_LIGHT_BLUE,FG_MODE_SET,~0,box);
  1945.  
  1946.         // now show the text
  1947.         fg_puts(FG_WHITE,FG_MODE_SET,~0,FG_ROT0,l,t,word,fg_displaybox);
  1948.  
  1949.         // make state now selected, but not yet in use - EG Notifier/CURSOR
  1950.         ObjectState='2';
  1951.  
  1952.         // ensure all other buttons in group are at show state
  1953.         PvtGroupShow(ObjectGroup);
  1954. }       
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960. void TextArea::Use()
  1961. {       // border for the box
  1962.         fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  1963.                    border,fg_displaybox);
  1964.  
  1965.         // box itself         
  1966.         fg_fillbox(FG_WHITE,FG_MODE_SET,~0,box);
  1967.  
  1968.         // now show the text
  1969.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,l,t,word,fg_displaybox);
  1970.         ObjectState='U';
  1971.  
  1972.         // ensure all other buttons in group are at show state
  1973.         PvtGroupShow(ObjectGroup);
  1974. }       
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982. //void nulprc(Button * p) { ; }
  1983. void TextArea_NULLPROC(Button * p) { ; }
  1984.  
  1985. void TextArea::Busy()
  1986. {       // we use a group of 256 higher so there is no chance of group screwups
  1987.         Button * TXTBTN;
  1988.         TXTBTN = new Button(0,left,ObjectMaxYpx-top,
  1989.                             " ", TextArea_NULLPROC, 30,20);
  1990. //      TXTBTN = new Button(0,10,10," ", nulprc, 30,20);
  1991.         TXTBTN->Busy();
  1992.         delete TXTBTN;
  1993.         // end of the temporary button group number group+256
  1994.  
  1995.         // redraw the border and the box
  1996.         fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  1997.                    border,fg_displaybox);
  1998.         fg_fillbox(FG_WHITE,FG_MODE_SET,~0,box);
  1999.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,l,t,word,
  2000.                 fg_displaybox);
  2001.         ObjectState='B';
  2002. }       
  2003.  
  2004. void TextArea::Swap(char * text) 
  2005. {       fg_box_t  tbx;                  
  2006.  
  2007.         // redraw the border and the box
  2008.         fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  2009.                    border,fg_displaybox);
  2010.         fg_fillbox(FG_WHITE,FG_MODE_SET,~0,box);
  2011.  
  2012.         // then redraw the text and reset the state
  2013.         strcpy(word,text);
  2014.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,l,t,word,
  2015.                 fg_displaybox);
  2016.         ObjectState='B';
  2017.  
  2018.         // ensure all other buttons in group are at show state
  2019.         PvtGroupShow(ObjectGroup);
  2020. }       
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026. int TextArea::Type(char * text, int ln=0)       /* line at a time print */
  2027. {       int x,y,  i,j;                  /* temporary variables */
  2028.         x=l;      y=ln;                 /* x and y coordinates */
  2029.  
  2030.         if ( ObjectState != '1' ) { this->Show(); } // auto show if is needed
  2031.  
  2032.         i=0; 
  2033.         while (text[i])                 /* loop til \0 - strips bad codes */
  2034.         {       if (text[i]<' ' || text[i]>'~')
  2035.                    text[i]=' ';         /* repl bad code with a blank code */
  2036.                 i++;                    /* add to counter */
  2037.         }
  2038.  
  2039.         if ( !y ) y=cur_line++;         /* if no line assume next and incr it*/
  2040.         if ( y+1>cur_line_max ) y=cur_line=0;    /* wrap to start of textbox */
  2041.         else 
  2042.         { y= t - (y * (4 + /* fg_charbox[FG_Y2] */ 14) );   /* y coord */
  2043.                 fg_puts(FG_WHITE,FG_MODE_SET,~0,FG_ROT0,x,y,text,fg_displaybox);
  2044.         }
  2045.         return(cur_line_max);           /* return max lines for info */
  2046. }       
  2047.  
  2048. void TextArea::Fade(char * text)
  2049.  
  2050. {       // draw the border again
  2051.         fg_drawbox(FG_CYAN,FG_MODE_SET,~0,FG_LINE_SOLID,
  2052.                    border,fg_displaybox);
  2053.  
  2054.         // draw the box inside the border
  2055.         fg_fillbox(FG_WHITE,FG_MODE_SET,~0,box);
  2056.  
  2057.         // reshow the text in the box
  2058.         strcpy(word,text);
  2059.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,l,t,word,fg_displaybox);
  2060.  
  2061.         // specify box state now
  2062.         ObjectState='F';
  2063.  
  2064.         // ensure all other buttons in group are at show state
  2065.         PvtGroupShow(ObjectGroup);
  2066. }
  2067.  
  2068.  
  2069.  
  2070. void TextArea::Hide() 
  2071.  
  2072. {       fg_fillbox(FG_BLACK,FG_MODE_SET,~0,border);
  2073.         ObjectState='0';
  2074. }
  2075.  
  2076.  
  2077. void TextArea::Read(char * text) 
  2078. {
  2079.         strcpy(text,word); 
  2080. }
  2081.  
  2082. void TextKeyboardNotify()
  2083. {       while ( !kbhit() )  Dispatch();
  2084.         getch();
  2085. }
  2086.  
  2087.  
  2088. #endif
  2089. /* [] END of textarea.hpp [] */
  2090.  
  2091.  
  2092. //------------------------------------------------> slider.hpp <-------------
  2093. /* [ ]--- SLIDER.HPP ------ C L A S S     R U L E S --------------------[ ] */
  2094. /*  |                                                                    |  */
  2095. /*  | A slider is used exactly like a button except that we dont have    |  */
  2096. /*  | a user defined notify.                                             |  */
  2097. /*  |                                                                    |  */
  2098. /*  | This is derived from the Button class.                             |  */
  2099. /*  |                                                                    |  */
  2100. /* [ ]------------------------------------------------------------------[ ] */
  2101.  
  2102. #ifndef SliderDefined
  2103. #define SliderDefined
  2104.  
  2105. // globals needed for all class items are here without compile test switch
  2106. #include "Object.hpp"                   /* base classes base class */
  2107. #include "Button.hpp"                   /* my base class */
  2108. #include "dispatch.hpp"
  2109. #include "ishdmous.cpp"
  2110. #include "friend.hpp"
  2111. #include "sound.h"
  2112.  
  2113.  
  2114. /* [ ]--- SLIDER ---------- O B J E C T    S T A T E S ------------------[ ]   
  2115.     |                                                                     |    
  2116.     | STATE:   same as Buttton and TextArea classes.                      |    
  2117.     |                                                                     |    
  2118.    [ ]-------------------------------------------------------------------[ ] */
  2119.  
  2120. /* [ ]--- SLIDER ---------- RELATIONSHIPS ------------------------------ [ ] 
  2121.     |                                                                     |  
  2122.     | The Slider class is related to the Textarea class, and polymorphism |  
  2123.     | is extant, as are overloaded functions. Refer to Textarea.HPP and   |  
  2124.     | Friend.HPP and Dispatch.HPP.                                        |
  2125.     |                                                                     |
  2126.     |                                                                     |  
  2127.    [ ] ----------------------------------------------------------------- [ ] */
  2128.  
  2129. // Prototypes
  2130. MOPEN();
  2131. MCLOSE();
  2132. int MINFO_LC(int *x, int *y,   int *l, int *m, int *r);
  2133. int MINFO_XY(int *x, int *y,   int *l, int *m, int *r);
  2134.  
  2135.  
  2136. /* [ ]--- CRTCLASS ---- M A S T E R   V A R I A B L E S ----------------[ ] */
  2137. /*  |                                                                    |  */
  2138. /*  |  ObjectCompile    a compiler #define to avoid duplication of       |  */
  2139. /*  |                                                                    |  */
  2140. /*  |                   1.  #include <fg.h>     for function prototypes  |  */
  2141. /*  |                   2.  ObjectMaxYpx        has many uses            |  */
  2142. /*  |                   3.  ObjectGraphOpen     graphics open switch     |  */
  2143. /*  |                                                                    |  */
  2144. /*  |  The above appear at the start of Slider & Textarea class defns.   |  */
  2145. /*  |                                                                    |  */
  2146. /* [ ]------------------------------------------------------------------[ ] */
  2147.  
  2148.  
  2149. /* [ ]--- Slider ------ M A S T E R   V A R I A B L E S ----------------[ ] */
  2150. /*  |                                                                    |  */
  2151. /*  |  SliderWide       width of the button box in pixels                |  */
  2152. /*  |  SliderTall       height of the button box in pixels               |  */
  2153. /*  |  SliderMax        does not exist - Slider is a Button special case |  */
  2154. /*  |                                                                    |  */
  2155. /* [ ]------------------------------------------------------------------[ ] */
  2156.  
  2157.  
  2158. /* [ ]--- Slider ------ S P E C I A L    N O T E S ---------------------[ ] */
  2159. /*  |                                                                    |  */
  2160. /*  |  Notifier              the class structure includes a pointer to a |  */
  2161. /*  |                        user provided function.                     |  */
  2162. /*  |  void (* Notifier)();  Declared in the class structure             |  */
  2163. /*  |  void (*fn)(),         Function prototype in constructor           |  */
  2164. /*  |  Notifier=fn;          Usage when saved in constructor             |  */
  2165. /*  |  (*Notifier)(this);    Usage in the Slider::Use() function         |  */
  2166. /*  |                                                                    |  */
  2167. /* [ ]------------------------------------------------------------------[ ] */
  2168.  
  2169.  
  2170. // globals needed for button class items are here
  2171. int     SliderWide=70,                  /* BOX SIZE horizontally */
  2172.         SliderTall=20;                  /* BOX SIZE vertically */
  2173. #define SliderMax ButtonMax             /* number to be remembered - limit */
  2174.  
  2175. #define HV fg_puts(FG_LIGHT_BLUE,FG_MODE_SET,~0,FG_ROT0,lastx,lasty,"-",fg_displaybox);
  2176. #define HH fg_puts(FG_LIGHT_BLUE,FG_MODE_SET,~0,FG_ROT0,lastx,lasty,"I",fg_displaybox);
  2177. #define DV fg_puts(FG_RED,FG_MODE_SET,~0,FG_ROT0,lastx,lasty,"-",fg_displaybox);
  2178. #define DH fg_puts(FG_RED,FG_MODE_SET,~0,FG_ROT0,lastx,lasty,"I",fg_displaybox);
  2179.  
  2180. class   Slider  : public Button
  2181.  
  2182. {       /*   general button control parameters needed are first */
  2183.         int     ObjectType;             /* 0011 is a button special case */
  2184.  
  2185.         char    SliderText[20];         /* descriptor */
  2186.  
  2187.         public:
  2188.         int     value;                  /* relative x or y value returned */
  2189.         private:
  2190.  
  2191.         char    mode;                   /* continuous notify or end notify */
  2192.         char    style;                  /* vertical or horizontal */
  2193.  
  2194.         void (* BNotifier)(Slider *);   // defines a pointer to a function
  2195.         //   ^           ^              The ^tells it a pointer as opposed 
  2196.         //                              to a function
  2197.         //                              This is the user's exit when we get
  2198.         //                              a new slider value. We ourselves use
  2199.         //                              the button exit for our own evil
  2200.         //                              purposes.
  2201.  
  2202.         // DECLARATIONS FOR CONSTRUCTOR AND DESTRUCTOR FUNCTIONS
  2203.         public: 
  2204.  
  2205.         // C++ constructor for the button class of objects
  2206.         Slider  (int xgroup, int xleft, int xtop,char * str,
  2207.                 void(*fn)(Slider*),int xsz, int ysz)
  2208.                 :  Button(xgroup,xleft,xtop,"",SliderNotify,xsz,ysz)
  2209.         {       ObjectType=11;          /* type = 11 means button.slider */
  2210.                 strcpy(SliderText,str); /* get slider text */
  2211.                 BNotifier=fn;           /* get users exit to be given value */
  2212.                 DerivedAddr=this;       // save derived address IN Button area
  2213.                 SliderContinuous();     // set continuous default
  2214.                 SliderVertical();       // assume vertical but..
  2215.                 if (xsz>ysz) SliderHorizontal();  // check out horizontal
  2216.         }                               // END OF CONSTRUCTOR LOGIC
  2217.  
  2218.         virtual ~Slider() { ; }         // virtual 
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.         // Slider specific methods - run time mode
  2225.         void SliderContinuous()   { mode='c'; }
  2226.         void SliderNotContinuous(){ mode='n'; }
  2227.  
  2228.         // Slider specific methods - 
  2229.         void SliderVertical()     { style='v'; }
  2230.         void SliderHorizontal()   { style='h'; }
  2231.  
  2232.  
  2233.         // DECLARATIONS OF member functions below, definition later
  2234.         virtual void Busy()       { ; } // null functions
  2235.         virtual void Swap(char *) { ; } 
  2236.         virtual void Fade(char *) { ; } 
  2237.  
  2238.  
  2239.         // Slider Friends
  2240.         friend void SliderNotify(Button *);     
  2241. };                                      // end of the slider class
  2242.  
  2243.  
  2244. /* [ ] ----- END OF CLASS ----- [ ] */
  2245.  
  2246. void SliderNotify(Button * tb)
  2247. {       // slider exit will steal the mouse and do good things - special code
  2248.         // in Button enters this notifier on a Select as opposed to Use.
  2249.         int  x,  y,                     // x,y are PRESENT values
  2250.              l,  m,  r,                 // l,m,r are the buttons hit
  2251.              stus,                      // stus id mouse status
  2252.              flag;                      // flag is our control flag 
  2253.  
  2254.         int  lastx,lasty;               // for the line used as a slider cursor
  2255.  
  2256.         int  X, Y;                      // working values of x,y
  2257.  
  2258.         // Get the slider associated with the Button - slider is derived from
  2259.         //                              // Button and has Sliders typed address
  2260.         Slider * ts;                    // temporary slider pointer for the
  2261.                                         // slider associated with this Button
  2262.         ts=tb->DerivedAddr;             // Get our Sliders address
  2263.  
  2264.         //MOPEN();                      // fire up the mouse - is already BUT
  2265.         msm_showcursor();               // allow mouse video as Button tnd off
  2266.  
  2267.  
  2268.         // Setup the initial cross bar in the slider
  2269.         lastx=lasty=l=m=r=0;            // set all values to 0           
  2270.         stus=MINFO_XY(&x,&y, &l,&m,&r); // prime values for later
  2271.         lastx=0;                        // say no "last" values yet
  2272.         lasty=0;                        
  2273.         l=m=r=0;                
  2274.  
  2275.         // Prime the slider loop run until a click to exit
  2276.         stus=1;                         // set up initial values
  2277.         flag=1;                         // primes the loop
  2278.         while ( flag )                  // while no keys depressed at all
  2279.         {       Dispatch();             // <<==== friendly multi tasker
  2280.                 if ( stus=MINFO_XY(&x,&y, &l,&m,&r) )
  2281.                 {       // (0) fix the Y value from MOUSE to FG_ values
  2282.                         //     and make x,y->X,Y so we dont alter x,y for
  2283.                         //     mouse, making false mouse detects.
  2284.                         Y=ObjectMaxYpx-y;
  2285.                         X=x;
  2286.  
  2287.  
  2288.  
  2289.  
  2290.                         // (1) calculate what we would return to user exit
  2291.                         if (ts->style == 'h') 
  2292.                            ts->value = ((long)(X - tb->left)*100) / 
  2293.                                                         (tb->box_wide);
  2294.                         if (ts->style == 'v') 
  2295.                            ts->value = ((long)(tb->top - Y )*100) / 
  2296.                                                         (tb->box_tall);
  2297.  
  2298.                         if (ts->value < 0)  ts->value=0;
  2299.                         if (ts->value > 99) ts->value=100;
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.                         // (2) If outside slider go back to prior operation, ie
  2313.                         // prior mouse work, WELL away from slider area is 30 
  2314.                         if ( X<(tb->left-30) || X>(tb->left + tb->box_wide+30)
  2315.                            || Y>(tb->top+30) || Y<(tb->top-(tb->box_tall+30)))
  2316.                         {       flag=0;         // make sure while halts
  2317.                                 msm_hidecursor(); // avoid bad video
  2318.                                 tb->Show();     // Drop from Select to Show
  2319.                                 if (ts->style=='v') DV; 
  2320.                                 if (ts->style=='h') DH; 
  2321.                                 msm_showcursor(); // avoid bad video
  2322.                                 break;          // stop further tests
  2323.                         }
  2324.  
  2325.                         // (3) restrict the dimension not in use if style is
  2326.                         //     V or H to make slider less wobbly
  2327.                         if (ts->style=='v') 
  2328.                                 X=tb->left -5 +(tb->box_wide)/2;
  2329.                         if (ts->style=='h') 
  2330.                                 Y=tb->top -5  -(tb->box_tall)/2;
  2331.  
  2332.  
  2333.  
  2334.                         // (4) Check if WELL within the slider area - pad used
  2335.                         if    ( X > tb->left+1 &&                       // 1
  2336.                                 X < (tb->left+(tb->box_wide-6)) &&      // 6
  2337.                                 Y < tb->top-8  &&                       // 8
  2338.                                 Y > (tb->top-(tb->box_tall-1))   )      // 1
  2339.                         {       if ( !(l+m+r) )
  2340.                                 {       msm_hidecursor(); // avoid bad video
  2341.                                         tb->Select();     // change to active
  2342.                                         
  2343.                                         if ( lastx>0 && lasty>0 )
  2344.                                         {       if (ts->style=='v') HV; 
  2345.                                                 if (ts->style=='h') HH;
  2346.                                         }
  2347.                                         lastx=X ;       lasty=Y ;
  2348.                                         if (ts->style=='v') DV; 
  2349.                                         if (ts->style=='h') DH; 
  2350.  
  2351.                                         if (ts->mode=='c')              /*1*/
  2352.                                         { sound_click();  ts->BNotifier(ts); }
  2353.                                         msm_showcursor(); // allow mouse video
  2354.                                 }
  2355.                                 
  2356.                                 else
  2357.                                 {       msm_hidecursor(); // avoid bad video
  2358.                                         ts->BNotifier(ts);             /*1*/
  2359.                                         tb->Show();       // slider to SHOW  
  2360.                                         if (ts->style=='v') DV; 
  2361.                                         if (ts->style=='h') DH; 
  2362.                                         msm_showcursor(); // avoid bad video
  2363.                                         flag=0;           // Show from Select
  2364.                                         break;            // skip rest
  2365.                                 }       // end of FOR loop checking all buttons
  2366.                         }               // end of IF mouse was in our slider  
  2367.                 }                       // end of IF any relevant mouse action
  2368.         }                               // end of WHILE loop*
  2369.         //MCLOSE();                     // Dont close as still in Button Mouse
  2370. }
  2371.  
  2372. //      /*1*/   object passes object as parm since function called cant 
  2373. //              use "this" as it is not a member function.
  2374.  
  2375. #endif
  2376. /* [] END of slider.hpp [] */
  2377.  
  2378. // Sample program to use Slider and Button. Button is used to QUIT
  2379. //efine samples
  2380. #ifdef samples
  2381. int loopflag;
  2382. void myexitS(Slider * v) 
  2383. {       static int x=450;       static int y=10;        static char s[10];
  2384. //      fg_drawdot(FG_WHITE,FG_MODE_SET,~0,x,y);
  2385. //      if (x++>500) { x=10; y+=2; }
  2386.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,x,y,s,fg_displaybox);
  2387.         sprintf(s,"%4d",v->value);
  2388.         fg_puts(FG_WHITE,FG_MODE_SET,~0,FG_ROT0,x,y,s,fg_displaybox);
  2389. }
  2390. void myexitT(Slider * v) 
  2391. {       static int x=410;       static int y=10;        static char s[10];
  2392.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,x,y,s,fg_displaybox);
  2393.         sprintf(s,"%4d",v->value);
  2394.         fg_puts(FG_WHITE,FG_MODE_SET,~0,FG_ROT0,x,y,s,fg_displaybox);
  2395. }
  2396. void myexitB(Button *) 
  2397. {       loopflag=1;                      
  2398. }
  2399.  
  2400. main()
  2401. {       Button * b;
  2402.         Slider * s;
  2403.         Slider * t;
  2404.         b = new Button(1, 10,  10,  "QUIT", myexitB);
  2405.         s = new Slider(1, 600, 50,  "s",    myexitS,20,200);
  2406.         t = new Slider(1, 100, 100, "t",    myexitT,350,50);
  2407. //      t->SliderNotContinuous();
  2408.         GroupShow(1);                   // s->Show(); etc...     
  2409.         loopflag=0;
  2410.         while (!loopflag)
  2411.         {       ButtonMouseNotify(1);
  2412.         }
  2413.         fg_term();
  2414.         int i,j;
  2415.         i=s->value;
  2416.         j=t->value;
  2417.         printf("%4d\n", i);
  2418.         printf("%4d\n", j);
  2419. }
  2420. #endif
  2421.  
  2422. //---------------------------------------------------> browser.cpp (program)
  2423. /* [ ]--- BROWSER --------- DIRECTORY ANALYSER FOR C++ -----------------[ ] */
  2424. /*  |     NOV 16 1989       Simon Wheaton-SMith                          |  */
  2425. /* [ ]------------------------------------------------------------------[ ] */
  2426. /*  |                                                                    |  */
  2427. /*  |   ASSOCIATIONS:  cl3'CPP'  and int 'j'                             |  */
  2428. /*  |                  cl3'C  '  and int 'k'                             |  */
  2429. /*  |                  cl3'HPP'  and int 'l'                             |  */
  2430. /*  |                  cl4'HOST' and int 'm'                             |  */
  2431. /*  |                                                                    |  */
  2432. /*  |   QUIT BUTTON    10,10  master quit                                |  */
  2433. /*  |                  20,20  next level quit - eg directory select      |  */
  2434. /*  |                  30,30  lower level quit - eg browse/edit          |  */
  2435. /*  |                                                                    |  */
  2436. /*  |   WORK TO DO:    HOST:  use HLLAPI class to logon to tso and do    |  */
  2437. /*  |                         a listds and capture the results           |  */
  2438. /*  |                                                                    |  */
  2439. /*  |                  EDIT:  add notifier code                          |  */
  2440. /*  |                  PRINT: add print code                             |  */
  2441. /*  |                                                                    |  */
  2442. /* [ ]------------------------------------------------------------------[ ] */
  2443.  
  2444. // standard includes for our classes, code and system functions
  2445. #include "stdio.h"                      // first to bypass autoprototyping
  2446. #include "Button.hpp"           // implies ishdmous.cpp and dispatch.hpp
  2447. #include "TextArea.hpp"         // keyboard text area
  2448. #include "slider.hpp"                   // slider derived from class button
  2449.  
  2450.  
  2451.  
  2452. // subtasking functions and their global parameters
  2453. void printer(Button *);                 // declaration for file printer
  2454. char printer_file_name[20];             // file name if busy, else blank
  2455. FILE * printer_file_handle;             // global file handle
  2456. int  printer_file_recno=0;              // current record in the file
  2457.  
  2458.  
  2459. // editing function is not subtasked but has global parameters
  2460. void editor(Button *);                  // declaration for file editor   
  2461. char editor_file_name[20];              // file name being edited
  2462. FILE * editor_file_handle;              // global file handle 
  2463.  
  2464.  
  2465.  
  2466. // declarations of functions defined later
  2467. void c_button(Button *);                // declaration of a later USE function
  2468. void file_button(Button *);             // declaration of a later USE function
  2469. void file_quit_button(Button *);        // declaration of a later function
  2470. void quit(Button *);                    // declaration of a later function
  2471. int  showfile(int, int, char *);        // declaration for a file display
  2472. buildlib(int,  int, char *);            // declaration for directory load
  2473. void cpu_button(Button *);              // hllapi interface
  2474. void sliderexit(Slider *);              // slider for text area
  2475. void slidernull(Slider *) {;}           // slider for text area
  2476.  
  2477.  
  2478. // functions that do nothing
  2479. void text_button(TextArea *)    { ; }   // actual null function for text area
  2480. void notify(Button *)           { ; }   // actual null function for buttons
  2481.  
  2482.  
  2483. // a subtask prototype - however this subtask only counts numbers!
  2484. void browser_subtask();                 // an asynchronous task
  2485.  
  2486.  
  2487.  
  2488. // preprocessor equates for Mouse (in Button) and Keyboard (in TextArea). 
  2489. // these routines are used in application code whenever we wish to give
  2490. // up control to the "system" and we take over in the two notifier routines
  2491. // and do two things, we nudge the global busy wheel and we run asynchronous
  2492. // code, such as could run an rs232 port activity, this is the DispatchER().
  2493.  
  2494. #define Keyboard() TextKeyboardNotify()  // pause on keyboard - text entry
  2495. #define Mouse(a)   ButtonMouseNotify(a)  // pause on mouse - button notift
  2496.  
  2497.  
  2498.  
  2499. // used for endless loop on the Mouse notifier until someting says
  2500. // not to loop anymore.
  2501. int loopexit;                           // mouse loop stops after SHOWFILE sw
  2502.  
  2503. /*              ----- useful debug code -----
  2504.                 char pp[50]; sprintf(pp,"%4d",j);
  2505.                 fg_puts(FG_WHITE,FG_MODE_SET,~0,FG_ROT0,50,
  2506.                                 50,pp,fg_displaybox);
  2507. */
  2508.  
  2509.  
  2510. // used for the current group of entities to work on
  2511. char suffix[5];                         // global file suffix
  2512. int  workinggroup;                      // global group being played with
  2513.  
  2514.  
  2515.  
  2516.  
  2517. // Globals for group id association - avoiding need for ANY object pointers
  2518. int  cppgroup;
  2519. int  cgroup;
  2520. int  hppgroup;
  2521. int  hostgroup;                         // global for host interface group id
  2522.  
  2523.  
  2524.  
  2525.  
  2526. // configuration limiting defines
  2527. #define MAXFILES 100                    // arbitrary limit
  2528. #define LOOPLIMIT 5000                  // arbitrary loop detect
  2529.  
  2530.  
  2531.  
  2532. /* [ ]------------------------------------------------------------------[ ] */
  2533. /*  |     MAIN BROWSER PROCEDURE                                         |  */
  2534. /* [ ]------------------------------------------------------------------[ ] */
  2535.  
  2536. main()
  2537. {       int      i,j,k,l,m;             /* group id codes for clasification */
  2538.  
  2539.  
  2540.         // get group ids so we can reference objects by group
  2541.         i = GetFreeGroupId();           // group id's allow us to access a
  2542.         j = GetFreeGroupId();           // group of objects and not needing
  2543.         k = GetFreeGroupId();           // to have a pointer to them
  2544.         l = GetFreeGroupId();
  2545.         m = GetFreeGroupId();           // we need host code for SHOW code
  2546.  
  2547.  
  2548.         // assign global names for other functions
  2549.         cppgroup=j;
  2550.         cgroup=k;
  2551.         hppgroup=l;
  2552.         hostgroup=m;                    // below, so save it for later
  2553.  
  2554.         // build directories using group names
  2555.         buildlib(j,110,"CPP");          // we define group j to be C++ code
  2556.         buildlib(k,210,"C  ");          //                 k       C code  
  2557.         buildlib(l,310,"HPP");          //                 l       classes
  2558.         // host build deferred till requested              m       host
  2559.  
  2560.  
  2561.         if ( !Attach(browser_subtask) ) // attach asynch task
  2562.         {       printf("Attach failed\n");      
  2563.                 exit(1);
  2564.         }               
  2565.  
  2566.         //              G    X   Y    TEXT    NOTIFY
  2567.         new Button(i,  10, 10, "QUIT",  quit  ,70,20);          // group
  2568.         new Button(i, 110, 10, "CPP",   c_button);              // j 
  2569.         new Button(i, 210, 10, "C  ",   c_button);              // k 
  2570.         new Button(i, 310, 10, "HPP",   c_button);              // l 
  2571.         new Button(i, 410, 10, "HOST",  cpu_button);            // m   
  2572.  
  2573.         GroupShow(i); 
  2574.  
  2575.  
  2576.         // reset printer globals to show printer is free
  2577.         strcpy(printer_file_name,"               ");
  2578.         printer_file_recno=0;
  2579.  
  2580.  
  2581.         loopexit=1;                     // loop till reset
  2582.         workinggroup=1;                 // current group
  2583.         while (loopexit) 
  2584.         {       Mouse(i);               // run above top row buttons
  2585.         //      DispatchWheelOff();     // stop the rotating wheel now forever
  2586.                 GroupHide(j);           // hide the lower layers
  2587.                 GroupHide(k);
  2588.                 GroupHide(l);
  2589.                 GroupHide(m);           // after hide, reshow upper layers
  2590.                 GroupHide(i);           // force state off so SHOW relights
  2591.                 GroupShow(i);           // the top row of buttons
  2592.         }
  2593. }                                       // end of MAIN()
  2594.  
  2595.  
  2596.  
  2597.  
  2598. /* [ ]------------------------------------------------------------------[ ] */
  2599. /*  |     READ A DIRECTORY FOR A SUFFIX AND CREATE A Button GROUP        |  */
  2600. /* [ ]------------------------------------------------------------------[ ] */
  2601.  
  2602. buildlib(int g, int x, char * sfx)
  2603. {       char     cmd[256],  tfn[64], str[256];
  2604.         char    *vp;
  2605.         FILE    *tfp;                   /* file to read DOS DIR command */
  2606.  
  2607.         strcpy(cmd,"dir *.");   
  2608.         strcat(cmd,sfx);                        // add file suffix
  2609.         strcat(cmd," > tempfil.tmp");           /* build dos command */
  2610.         strcpy(tfn,"tempfil.tmp");              /* save file name */
  2611.         system(cmd);                            /* run the directory display */
  2612.  
  2613.         if ((tfp=fopen(tfn,"r")) == NULL)       /* see if we got a directory */
  2614.         {       printf("*** tempfil.tmp cant open:memory?  ***\n");
  2615.                 printf("%x\n",*tfp);
  2616.                 printf("%x\n",tfp);
  2617.                 return(-1);
  2618.         }
  2619.  
  2620.         int y=100, i=0;                 /* x,y for dynamic buttons */
  2621.  
  2622.         while (  i<MAXFILES  )
  2623.         {       if ( !(fgets(str,80,tfp)) )   break;    // break at eof   
  2624.  
  2625.                 if ( strlen(str)>38 &&  str[25]=='-' )  // DIR format ? 
  2626.                 {       strncpy(cmd,str,20);            // copy file name in 
  2627.                         vp=cmd;                         // locate flname and 
  2628.                         *(vp+8)='\0';                   // force size to 8
  2629.  
  2630.                         new  Button ( g,x,y,cmd,file_button);
  2631.                         i++;                   
  2632.                         x+=10;  
  2633.                         y+=15;                                      
  2634.                         if (y>300) { y=100;  x+=0;} 
  2635.                 }
  2636.         }
  2637.  
  2638.         new Button (g,20,20,"quit", file_quit_button);  /* quit button */
  2639.  
  2640.  
  2641.  
  2642.         unlink(tfn);                    /* delete temp file */
  2643.         fclose(tfp);                    /* also close it */
  2644.  
  2645.         //  What we have just done is built a lot of objects and let Button
  2646.         //  keep track of them in its array. We told Button they were all
  2647.         //  group XX, any unique hiearchical number would have done.
  2648.  
  2649. }
  2650.  
  2651.  
  2652.  
  2653.  
  2654.  
  2655.  
  2656.  
  2657.  
  2658.  
  2659.  
  2660.  
  2661.  
  2662.  
  2663.  
  2664. /* [ ]-------------------------------vvvv-------------------------------[ ] */
  2665. /*  |     TOP ROW BUTTON depressed - QUIT cpp  c  hpp  host              |  */
  2666. /* [ ]-------------------------------^^^^-------------------------------[ ] */
  2667.  
  2668. void quit(Button * notify_button)
  2669. {       Detach(browser_subtask);        // suspend sub task demo code
  2670.         notify_button->Fade("ENDING");  // <-- this is an overloaded function
  2671.         fg_term();
  2672.         exit(0);                        // mouse clicked quit
  2673. }                                       // end of DIR_BUTTON()
  2674.  
  2675.  
  2676.  
  2677.  
  2678.  
  2679.  
  2680.  
  2681.  
  2682.  
  2683.  
  2684.  
  2685.  
  2686. /* [ ]------------------------------------vvv-vvv-vvv-------------------[ ] */
  2687. /*  |     TOP ROW BUTTON depressed - quit CPP  C  HPP  host              |  */
  2688. /* [ ]------------------------------------^^^-^^^-^^^-------------------[ ] */
  2689.        
  2690. void c_button(Button * notify_button)
  2691. {       notify_button->Read(suffix);    // get the group
  2692.         if (!strcmp(suffix,"CPP"))      workinggroup=cppgroup;       
  2693.         if (!strcmp(suffix,"C  "))      workinggroup=cgroup;       
  2694.         if (!strcmp(suffix,"HPP"))      workinggroup=hppgroup;       
  2695.         notify_button->Swap(suffix); 
  2696.         GroupShow(workinggroup);        // group show - uses an integer      
  2697.         loopexit = 1;                   // loop till notify wants stop
  2698.         while ( loopexit )
  2699.         {       GroupHide(workinggroup);        // file name buttons
  2700.                 GroupShow(workinggroup);
  2701.                 Mouse(workinggroup);            // run the mouse notifier
  2702.         }
  2703.         notify_button->Swap(suffix);
  2704.         loopexit=1;                     // allow lower MOUSE loop to run
  2705. }                                       // end of DIR_BUTTON()
  2706.  
  2707.  
  2708. /* [ ]-------------------------------------------------vvvv-------------[ ] */
  2709. /*  |     TOP ROW BUTTON depressed - quit cpp  c  hpp  HOST              |  */
  2710. /* [ ]-------------------------------------------------^^^^-------------[ ] */
  2711.        
  2712. void cpu_button(Button * bb)
  2713.  
  2714. {       int m;                          // get the code used for HOST GROUP
  2715.         m=hostgroup;    
  2716.         new Button (m,20, 20, "quit", notify   );       /* quit */
  2717.         new Button (m,410,100,"none", notify   );       /* quit */
  2718.         GroupShow(m);
  2719.         Detach(browser_subtask);        // suspend sub task demo code
  2720.         Mouse(m);                       // wait for any group 23 hit
  2721.                 
  2722.         Attach(browser_subtask);        // resume subtask demo code
  2723.         GroupDelete(m);
  2724.         loopexit=1;                     // force refresh of MOUSE loop
  2725. }                       
  2726.  
  2727.  
  2728.  
  2729.  
  2730. /* [ ]------------------------------------------------------------------[ ] */
  2731. /*  |     A specific file button has been selected                       |  */
  2732. /* [ ]------------------------------------------------------------------[ ] */
  2733.        
  2734. void file_button(Button * notify_button)
  2735. {       char filnam[20];
  2736.         // the button we got passed is a pointer to the button hit.
  2737.        
  2738.         notify_button->Read(filnam);    // get filename from the button
  2739.  
  2740.         if ( strncmp("quit",filnam,3) ) // strcmp ret !0 if not match - remember
  2741.         {  
  2742.                 showfile( 10,80,filnam);        // ----------> two pages on
  2743.         }
  2744.         if ( !strncmp("quit",filnam,3)) // strcmp returns 0 if true - remember
  2745.         {       loopexit = 0;   }       // halt mouse  - BUT file_quit_button
  2746.                                         // should actually get the notify --->
  2747. }                                       // end of FILE_BUTTON()
  2748.  
  2749.  
  2750.  
  2751.  
  2752. /* [ ]------------------------------------------------------------------[ ] */
  2753. /*  |     A file button was hit but it was the file directory quit       |  */
  2754. /* [ ]------------------------------------------------------------------[ ] */
  2755.  
  2756. void    file_quit_button(Button * bb)
  2757. {       loopexit = 0;                   // halt mouse loop
  2758. }
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774. /* [ ]------------------------------------------------------------------[ ] */
  2775. /*  |     Subroutine to display a disk file, neednt be separate code.    |  */
  2776. /* [ ]------------------------------------------------------------------[ ] */
  2777.  
  2778. char *recs[500]; long int nrecs;        // global for slider exit - holds up
  2779. TextArea * t;                           // to 500 records of the file
  2780.  
  2781. int     showfile(int ax,  int ay,  char * tx)
  2782. {       char  * vp;   
  2783.         char    tfn[65], str[256];
  2784.         char    frslt;                  // file results
  2785.         FILE  * tfp;
  2786.         int     i,j,k, y;               // integers and a Y working area
  2787.         int     G1, G2;                 // group codes for buttons and etc
  2788.  
  2789.         strcpy(tfn,tx);                 /* tfn now a file name____0 */
  2790.         for (i=0; i<64; i++)  if (tfn[i]==' ')     tfn[i]='\0';
  2791.         strcat(tfn,".");                /* tfn now a proper file name */
  2792.         strcat(tfn,suffix);
  2793.  
  2794.         y = ay-15;                      // y is zortech coord
  2795.  
  2796.         if ((tfp=fopen(tfn,"r")) == NULL)   return(-1);
  2797.  
  2798.         for (i=0;i<500;i++)             // build the 500 null entries for data
  2799.         {       recs[i]= (void *)0;
  2800.         }
  2801.  
  2802.         G1=GetFreeGroupId();            // get a group for use and a
  2803.         G2=GetFreeGroupId();            // group for show but not use
  2804.  
  2805.         t = new TextArea(G1,ax,ay," ",text_button,600,235);
  2806.         //GroupShow(G1);                // or t->Show() to show text area
  2807.  
  2808.  
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.         i=0;    j=1;    k=9999;         // i=recno, j=size of data read in
  2819.                                         // k=max lines in the present textarea
  2820.         while   (  (j) )
  2821.         {       j=(int)(fgets(str,80,tfp))  ;
  2822.                 
  2823.                 if ( j>0 && i<500 )     // do as long as not file|array end
  2824.                 {       vp=str;
  2825.                         if  (  strlen(vp)>70  ) *(vp+70)='\0';
  2826.                         Dispatch();     // once each record run DispatchER 
  2827.                         if (i<k)        // if textarea not full show text
  2828.                         {       k=t->Type(str);    
  2829.                         } //if(i>k){t->Hide();t->Show();i=0;} // <<<<<<< debug
  2830.                         // get memory, copy text to buffer array points to
  2831.                         recs[i]=malloc(5+strlen(str));
  2832.                         strcpy(recs[i],str);
  2833.                         nrecs=i;        // save file size
  2834.  
  2835.                         i++;            // add to record counter
  2836.                 }
  2837.                 else j=0;               // stop on EOF or End of array
  2838.         }
  2839.  
  2840.         new Button(G1,30,30,    "exit",  notify);   
  2841.         new Button(G1,10, y,    "PRINT", printer);  // needs future
  2842.         new Button(G1,110,y,    "EDIT",  editor);   // code
  2843.         new Button(G2,250,y,    tfn,     notify,    210, 20);
  2844.         new Slider(G1,ax+605,ay,"vert",  sliderexit,20,  235);
  2845.         new Slider(G1,ax,ay+240,"horz",  slidernull,600, 15 ); // no use yet
  2846.         GroupShow(G1);                  // show the exit button
  2847.         GroupShow(G2);                  // show the file name also
  2848.  
  2849.         // either a keyboard
  2850.         //      Keyboard();
  2851.         // or a mouse
  2852.                 Mouse(G1);              // wait for any CLICK to mean quit
  2853.  
  2854.         delete t;                       // delete text window
  2855.         GroupDelete(G1);                // delete clickable buttons
  2856.         GroupDelete(G2);                // delete unclickable file name button
  2857.  
  2858.         (void) fclose(tfp);
  2859.         for (i=0;i<500;i++) if (recs[i] != (void *)0) free(recs[i]);
  2860. }
  2861.  
  2862. /* [ ]------------------------------------------------------------------[ ] */
  2863. /*  |     The textarea slider exit is here                               |  */
  2864. /* [ ]------------------------------------------------------------------[ ] */
  2865.  
  2866. void sliderexit(Slider * ts)
  2867. {       static long int record=0;               // record is a percent, not rec
  2868.         if ( record != (ts->value) )
  2869.         {       record=((ts->value) * nrecs)/100;
  2870.                 t->Hide();                      // now record is a record no
  2871.                 t->Show();                      // by hide then show
  2872.                 int j=9999; int i=1;            // count lines typed>Textarea           
  2873.                 while   (  (record+20<nrecs)  ) // dont run over array, pad 20
  2874.                 {       if ( (void *) recs[record] )
  2875.                         {       j=t->Type(recs[record]);
  2876.                                 if (i++>j) record=nrecs+1; // halt on full txt
  2877.                         }
  2878.                         record++;               // add to record number
  2879.                 }
  2880.         }
  2881.         record=ts->value;                       // remember start point as %
  2882. }
  2883.  
  2884. /* [ ]------------------------------------------------------------------[ ] */
  2885. /*  |     The named file is to be printer                                |  */
  2886. /* [ ]------------------------------------------------------------------[ ] */
  2887.  
  2888. void printer(Button *)                          // printer function
  2889. {       // AT EOF - reset printer globals to show printer is free
  2890.         strcpy(printer_file_name,"               ");
  2891.         printer_file_recno=0;
  2892. }
  2893.  
  2894. /* [ ]------------------------------------------------------------------[ ] */
  2895. /*  |     The named file is to be edited                                 |  */
  2896. /* [ ]------------------------------------------------------------------[ ] */
  2897.  
  2898. void editor(Button *)                   // editor function
  2899. {       ;                               
  2900. }
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906. /* [ ]------------------------------------------------------------------[ ] */
  2907. /*  |     A useless asynchronous thread for no good reason at all        |  */
  2908. /* [ ]------------------------------------------------------------------[ ] */
  2909.  
  2910. // BROWSER SUB TASK FOR NO GOOD REASON - just shows a number
  2911.  
  2912. void browser_subtask()                  // RULES: you do one quanta of work
  2913. {       static int value=0;             //        for each invocation.
  2914.         char w[20];
  2915.  
  2916.         sprintf(w,"%8d",value);
  2917.         // erase the file name from the screen and exit
  2918.         fg_puts(FG_BLACK,FG_MODE_SET,~0,FG_ROT0,10,1,w,fg_displaybox);
  2919.  
  2920.         if (value++>LOOPLIMIT) exit(1); // loop abend DEBUG PURPOSES
  2921.         sprintf(w,"%8d",value);
  2922.         // show the data
  2923.         fg_puts(FG_RED,FG_MODE_SET,~0,FG_ROT0,10,1,w,fg_displaybox);
  2924. }
  2925. /* [] END OF browser.cpp C++ V2.0 BROWSER OF C,CPP,HPP FILES WITH TASKING [] */
  2926. /* end of the whole nine yards*/
  2927.  
  2928.   
  2929.  
  2930.   
  2931.  
  2932.