home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff386.lzh / XLispStat / src1.lzh / IView / hardwareobs.c < prev    next >
C/C++ Source or Header  |  1990-10-04  |  14KB  |  441 lines

  1. /* hardwareobjects - Lisp representation of physical machine objects.  */
  2. /* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
  3. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  4. /* You may give out copies of this software; for conditions see the    */
  5. /* file COPYING included with this distribution.                       */
  6.  
  7. /*
  8. Physical machine objects, such as windows or menus, allocated in a 
  9. session are represented as xlisp objects. A list of such objects is
  10. kept in the variable *HARDWARE-OBJECTS*. Every such object must 
  11. understand the :ALLOCATE and :DISPOSE messages. When an object is
  12. created it is entered into the list; when it is disposed it must 
  13. remove itself from the list. The object is assumed to have an
  14. instance variable HARDWARE-ADDRESS that will be set to the 
  15. representation described below when the object is allocated and to
  16. NIL otherwise.
  17.  
  18. Representations for the machine address include information to allow
  19. determination of whether an address is valid or not. This is as
  20. protection from referencing objects from a previous session after a 
  21. restore. The restore function will be modified to deallocate all
  22. objects in the old *HARDWARE-OBJECTS* list before the restore and 
  23. reallocate objects in this list after the restore. The menu bar may
  24. require special handling.
  25. */
  26.  
  27. #include "xlisp.h"
  28. #include "osdef.h"
  29. #ifdef ANSI
  30. #include "xlproto.h"
  31. #include "xlsproto.h"
  32. #include "iviewproto.h"
  33. #include "Stproto.h"
  34. #else
  35. #include "xlfun.h"
  36. #include "xlsfun.h"
  37. #include "iviewfun.h"
  38. #include "Stfun.h"
  39. #endif ANSI
  40. #include "xlsvar.h"
  41.  
  42. /* forward declarations */
  43. #ifdef ANSI
  44. int valid_hardware_address(LVAL,int *);
  45. void set_hardware_address(void *,LVAL,int *);
  46. #else
  47. int valid_hardware_address();
  48. void set_hardware_address();
  49. #endif
  50.  
  51. #ifndef nil
  52. #define nil 0L
  53. #endif
  54.  
  55. #define NONE -1
  56. #define WINDOW 0
  57. #define IVIEWWINDOW 1
  58. #define IVIEW 2
  59. #define SPINNER 3
  60. #define SCATMAT 4
  61. #define HISTOGRAM 5
  62. #define NAMELIST 6
  63.  
  64. #define MENU 7
  65. #define APPLEMENU 8
  66. #define DIALOG 9
  67. #define EDIT 10
  68. #define DISPLAY 11
  69.  
  70. static int window_data[] = { WINDOW, NONE };
  71. static int *window = window_data;
  72. static int iview_window_data[] = { WINDOW, IVIEWWINDOW, NONE };
  73. static int *iview_window = iview_window_data;
  74. static int iview_data[] = { WINDOW, IVIEWWINDOW, IVIEW, NONE };
  75. static int *iview = iview_data;
  76. static int menu_data[] = { MENU, NONE };
  77. static int *menu = menu_data;
  78. static int apple_menu_data[] = { MENU, APPLEMENU, NONE };
  79. static int *apple_menu = apple_menu_data;
  80. static int dialog_data[] = { WINDOW, DIALOG, NONE };
  81. static int *dialog = dialog_data;
  82. static int edit_window_data[] = { WINDOW, EDIT, NONE };
  83. static int *edit_window = edit_window_data;
  84. static int display_window_data[] = { WINDOW, DISPLAY, NONE };
  85. static int *display_window = display_window_data;
  86.  
  87. /**************************************************************************/
  88. /**                                                                      **/
  89. /**                       General Address Functions                      **/
  90. /**                                                                      **/
  91. /**************************************************************************/
  92.  
  93. /*
  94. Addresses are stored in a list of the form
  95.  
  96.   (time-stamp address xlisp-object ....)
  97.   
  98. Additional entries give information about the specific type of the object.
  99. */
  100.  
  101. LOCAL int valid_hardware_address(addr, type)
  102.     LVAL addr;
  103.     int *type;
  104. {
  105.   LVAL val;
  106.  
  107.   if (! consp(addr)) return(FALSE);
  108.   val = car(addr);
  109.   if (! fixp(val) || time_stamp != getfixnum(val)) return(FALSE);
  110.   addr = cdr(addr);
  111.   if (! consp(addr) || ! fixp(car(addr))) return(FALSE);
  112.   addr = cdr(addr);
  113.   if (! consp(addr) || ! objectp(car(addr))) return(FALSE);
  114.   addr = cdr(addr);
  115.  
  116.   for (; *type != NONE; type++, addr = cdr(addr)) {
  117.     if (! consp(addr)) return(FALSE);
  118.     val = car(addr);
  119.     if (! fixp(val) || getfixnum(val) != *type) return(FALSE);
  120.   }
  121.   return(TRUE);
  122. }
  123.  
  124. LOCAL void set_hardware_address(ptr, object, type)
  125.     /*char*/ void *ptr; /* changed JKL */
  126.     LVAL object;
  127.     int *type;
  128. {
  129.   LVAL t, p, last, result, oblistsym, newoblist;
  130.   
  131.   if (! objectp(object)) xlerror("not an object", object);
  132.   
  133.   oblistsym = s_hardware_objects;
  134.   if (! consp(getvalue(oblistsym))) setvalue(oblistsym, NIL);
  135.   
  136.   xlstkcheck(4);
  137.   xlsave(t);
  138.   xlsave(p);
  139.   xlsave(result);
  140.   xlsave(newoblist);
  141.   
  142.   t = cvfixnum((FIXTYPE) time_stamp);
  143.   p = cvfixnum((FIXTYPE) ptr);
  144.   result = last = consa(object);
  145.   result = cons(p, result);
  146.   result = cons(t, result);
  147.   
  148.   newoblist = cons(result, getvalue(oblistsym));
  149.   setvalue(oblistsym, newoblist);
  150.   set_slot_value(object, s_hardware_address, result);
  151.   
  152.   for (;*type != NONE; type++, last = cdr(last)) {
  153.     t = cvfixnum((FIXTYPE) *type);
  154.     t = consa(t);
  155.     rplacd(last, t);
  156.   }
  157.   xlpopn(4);
  158. }
  159.  
  160. void standard_hardware_clobber(object)
  161.     LVAL object;
  162. {
  163.   LVAL addr, oblistsym, oblist;
  164.   
  165.   if (! objectp(object)) xlerror("not an object", object);
  166.   
  167.   addr = slot_value(object, s_hardware_address);
  168.   
  169.   oblistsym = xlenter("*HARDWARE-OBJECTS*");
  170.   oblist = getvalue(oblistsym);
  171.   if (! listp(oblist)) xlerror("not a list", oblist);
  172.   
  173.   setvalue(oblistsym, xscallsubr2(xdelete, addr, oblist));
  174.   set_slot_value(object, s_hardware_address, NIL);
  175.   
  176.   send_message(object, sk_clobber);
  177. }
  178.  
  179. LVAL get_hardware_object_by_address(ptr)
  180.     /*char*/ void *ptr; /* changed JKL */
  181. {
  182.   LVAL oblist = getvalue(s_hardware_objects);
  183.   LVAL result, addr;
  184.   
  185.   for (result = NIL; result == NIL && consp(oblist); oblist = cdr(oblist)) {
  186.     addr = car(oblist);
  187.     if (ptr == (char *) getfixnum(car(cdr(addr)))) result = car(cdr(cdr(addr)));
  188.   }
  189.   return(result);
  190. }
  191.     
  192. /**************************************************************************/
  193. /**                                                                      **/
  194. /**                       Window Address Functions                       **/
  195. /**                                                                      **/
  196. /**************************************************************************/
  197.  
  198. int valid_window_address(addr)
  199.     LVAL addr;
  200. {
  201.   return(valid_hardware_address(addr, window));
  202. }
  203.  
  204. void set_window_address(ptr, object)
  205.     /*char*/ void *ptr;
  206.     LVAL object;
  207. {
  208.   set_hardware_address(ptr, object, window);
  209. }
  210.  
  211. /*char * */ IVIEW_WINDOW GETWINDOWADDRESS(object) /* changed  JKL */
  212.     LVAL object;
  213. {
  214.   LVAL addr = slot_value(object, s_hardware_address);
  215.   if (addr == NIL) return(nil);
  216.   if (! valid_window_address(addr))
  217.     xlfail("not a valid window address - try reallocating the object");
  218.   return(/*(char *)*/ (IVIEW_WINDOW) getfixnum(car(cdr(addr))));
  219. }
  220.  
  221. /**************************************************************************/
  222. /**                                                                      **/
  223. /**                    IView Window Address Functions                    **/
  224. /**                                                                      **/
  225. /**************************************************************************/
  226.  
  227. int valid_iview_window_address(addr)
  228.     LVAL addr;
  229. {
  230.   return(valid_hardware_address(addr, iview_window));
  231. }
  232.  
  233. void set_iview_window_address(ptr, object)
  234.     /*char*/ void *ptr; /* changed JKL */
  235.     LVAL object;
  236. {
  237.   set_hardware_address(ptr, object, iview_window);
  238. }
  239.  
  240. /*char * */ IVIEW_WINDOW GETIVIEWWINDOWADDRESS(object) /* changed JKL */
  241.     LVAL object;
  242. {
  243.   LVAL addr = slot_value(object, s_hardware_address);
  244.   if (addr == NIL) return(nil);
  245.   else if (! valid_iview_window_address(addr))
  246.     xlfail("not a valid graph window address - try reallocating the object");
  247.   return(/*(char *)*/ (IVIEW_WINDOW) getfixnum(car(cdr(addr))));
  248. }
  249.  
  250. /**************************************************************************/
  251. /**                                                                      **/
  252. /**                        IView Address Functions                       **/
  253. /**                                                                      **/
  254. /**************************************************************************/
  255.  
  256. int valid_iview_address(addr)
  257.     LVAL addr;
  258. {
  259.   return(valid_hardware_address(addr, iview));
  260. }
  261.  
  262. void set_iview_address(ptr, object)
  263.     /*char*/ void *ptr; /* changed JKL */
  264.     LVAL object;
  265. {
  266.   set_hardware_address(ptr, object, iview);
  267. }
  268.  
  269. /* char * */ IVIEW_WINDOW get_iview_address(object) /* changed JKL */
  270.     LVAL object;
  271. {
  272.   LVAL addr;   /* why these two functions ??? JKL */
  273.   
  274.   addr = slot_value(object, s_hardware_address);
  275.   if (! valid_iview_address(addr))
  276.     xlfail("not a valid graph address - try reallocating the object");
  277.   return(/*(char *)*/ (IVIEW_WINDOW) getfixnum(car(cdr(addr))));
  278. }
  279.  
  280. /*char * */ IVIEW_WINDOW GETIVIEWADDRESS(object) /* changed JKL */
  281.     LVAL object;
  282. {
  283.   LVAL addr = slot_value(object, s_hardware_address);
  284.   if (addr == NIL) return(nil);
  285.   else if (! valid_iview_address(addr))
  286.     xlfail("not a valid graph address - try reallocating the object");
  287.   else return(/*(char *)*/ (IVIEW_WINDOW) getfixnum(car(cdr(addr))));
  288. }
  289.  
  290. /**************************************************************************/
  291. /**                                                                      **/
  292. /**                        Menu Address Functions                        **/
  293. /**                                                                      **/
  294. /**************************************************************************/
  295.  
  296. int valid_menu_address(addr)
  297.     LVAL addr;
  298. {
  299.   return(valid_hardware_address(addr, menu));
  300. }
  301.  
  302. void set_menu_address(ptr, object)
  303.     /*char*/ void *ptr; /* changed JKL */
  304.     LVAL object;
  305. {
  306.   set_hardware_address(ptr, object, menu);
  307. }
  308.  
  309. /*char*/ void *get_menu_address(object) /* changed JKL */
  310.     LVAL object;
  311. {
  312.   LVAL addr;
  313.   
  314.   addr = slot_value(object, s_hardware_address);
  315.   if (! valid_menu_address(addr))
  316.     xlfail("not a valid menu address - try reallocating the object");
  317.   return((char *) getfixnum(car(cdr(addr))));
  318. }
  319. #ifdef MACINTOSH
  320. /**************************************************************************/
  321. /**                                                                      **/
  322. /**                    Apple Menu Address Functions                      **/
  323. /**                                                                      **/
  324. /**************************************************************************/
  325.  
  326. int valid_apple_menu_address(addr)
  327.     LVAL addr;
  328. {
  329.   return(valid_hardware_address(addr, apple_menu));
  330. }
  331.  
  332. void set_apple_menu_address(ptr, object)
  333.     char *ptr;
  334.     LVAL object;
  335. {
  336.   set_hardware_address(ptr, object, apple_menu);
  337. }
  338.  
  339. char *get_apple_menu_address(object)
  340.     LVAL object;
  341. {
  342.   LVAL addr;
  343.   
  344.   addr = slot_value(object, s_hardware_address);
  345.   if (! valid_apple_menu_address(addr))
  346.     xlfail("not a valid apple menu address - try reallocating the object");
  347.   return((char *) getfixnum(car(cdr(addr))));
  348. }
  349. #endif MACINTOSH
  350. /**************************************************************************/
  351. /**                                                                      **/
  352. /**                        Dialog Address Functions                      **/
  353. /**                                                                      **/
  354. /**************************************************************************/
  355.  
  356. int valid_dialog_address(addr)
  357.     LVAL addr;
  358. {
  359.   return(valid_hardware_address(addr, dialog));
  360. }
  361.  
  362. void set_dialog_address(ptr, object)
  363.     /*char*/ void *ptr; /* changed JKL */
  364.     LVAL object;
  365. {
  366.   set_hardware_address(ptr, object, dialog);
  367. }
  368.  
  369. /*char * */ IVIEW_WINDOW GETDIALOGADDRESS(object) /* return changed JKL */
  370.     LVAL object;
  371. {
  372.   LVAL addr = slot_value(object, s_hardware_address);
  373.   if (addr == NIL) return(nil);
  374.   if (! valid_dialog_address(addr))
  375.     xlfail("not a valid dialog address - try reallocating the object");
  376.   return(/*(char *)*/ (IVIEW_WINDOW) getfixnum(car(cdr(addr))));
  377. }
  378.  
  379. #ifdef MACINTOSH
  380. /**************************************************************************/
  381. /**                                                                      **/
  382. /**                      Edit Window Address Functions                   **/
  383. /**                                                                      **/
  384. /**************************************************************************/
  385.  
  386. int valid_edit_window_address(addr)
  387.     LVAL addr;
  388. {
  389.   return(valid_hardware_address(addr, edit_window));
  390. }
  391.  
  392. void set_edit_window_address(ptr, object)
  393.     char *ptr;
  394.     LVAL object;
  395. {
  396.   set_hardware_address(ptr, object, edit_window);
  397. }
  398.  
  399. char *get_edit_window_address(object)
  400.     LVAL object;
  401. {
  402.   LVAL addr;
  403.   
  404.   addr = slot_value(object, s_hardware_address);
  405.   if (! valid_edit_window_address(addr))
  406.     xlfail("not a valid edit window address - try reallocating the object");
  407.   return((char *) getfixnum(car(cdr(addr))));
  408. }
  409.  
  410. /**************************************************************************/
  411. /**                                                                      **/
  412. /**                    Display Window Address Functions                  **/
  413. /**                                                                      **/
  414. /**************************************************************************/
  415.  
  416. int valid_display_window_address(addr)
  417.     LVAL addr;
  418. {
  419.   return(valid_hardware_address(addr, display_window));
  420. }
  421.  
  422. void set_display_window_address(ptr, object)
  423.     char *ptr;
  424.     LVAL object;
  425. {
  426.   set_hardware_address(ptr, object, display_window);
  427. }
  428.  
  429. char *get_display_window_address(object)
  430.     LVAL object;
  431. {
  432.   LVAL addr;
  433.   
  434.   addr = slot_value(object, s_hardware_address);
  435.   if (! valid_display_window_address(addr))
  436.     xlfail("not a valid display window address - try reallocating the object");
  437.   return((char *) getfixnum(car(cdr(addr))));
  438. }
  439. #endif MACINTOSH
  440.  
  441.