C:/Users/Dennis/src/lang/Life_start/Life/life-1.02/source/xpred.c

Go to the documentation of this file.
00001 /* Copyright 1991 Digital Equipment Corporation.
00002  ** Distributed only by permission.
00003  **
00004  ** Last modified on Wed Mar  2 11:32:59 MET 1994 by rmeyer
00005  **      modified on Fri Jan 28 14:24:13 MET 1994 by dumant
00006  **      modified on Thu Jun 24 06:55:40 1993 by Rmeyer
00007  **      modified on Thu Nov 26 20:13:50 1992 by herve
00008  *****************************************************************/
00009 /*      $Id: xpred.c,v 1.3 1995/07/27 19:28:45 duchier Exp $     */
00010 
00011 #ifndef lint
00012 static char vcid[] = "$Id: xpred.c,v 1.3 1995/07/27 19:28:45 duchier Exp $";
00013 #endif /* lint */
00014 
00015 
00016 #ifdef X11
00017 
00018 
00019 
00020 #include <stdio.h>
00021 #include <ctype.h>
00022 #include <malloc.h>
00023 #include <sys/types.h>
00024 #include <sys/time.h>
00025 #include <sys/ioctl.h>
00026 
00027 #ifndef NEEDXLIBINT
00028 #include <X11/Xlib.h>
00029 #else
00030 #include <X11/Xlibint.h>
00031 #endif
00032 #include <X11/Xutil.h>
00033 #include <X11/keysym.h>
00034 
00035 #include "extern.h"
00036 #include "token.h"
00037 #include "print.h"
00038 #include "built_ins.h"
00039 #include "types.h"
00040 #include "trees.h"
00041 #include "lefun.h"
00042 #include "login.h"
00043 #include "error.h"
00044 #include "memory.h"
00045 #include "templates.h"
00046 #include "modules.h"
00047 #include "xpred.h"
00048 #include "xdisplaylist.h"
00049 
00050 #include "life_icon"
00051 
00052 
00053 /*****************************************/
00054 
00055 
00056 #define stdin_fileno fileno(stdin)
00057 #define CR 0x0d
00058 #define BS 0x08
00059 
00060 
00061 /* a closure for enum xevents_list */
00062 typedef struct wl_EventClosure
00063 {
00064   Display *display;
00065   Window window;
00066   long mask;
00067   ptr_psi_term beginSpan;
00068 } EventClosure;
00069 
00070 
00071 /*****************************************/
00072 
00073 
00074 ptr_psi_term xevent_existing = NULL;
00075 ptr_psi_term xevent_list = NULL;
00076 
00077 ptr_definition xevent,xkeyboard_event,xbutton_event,/* RM: 7/12/92 */
00078   xexpose_event,xdestroy_event,xmotion_event,
00079   
00080   xenter_event,xleave_event,xmisc_event,/* RM: 3rd May 93 */
00081   
00082   xdisplay,xdrawable,xwindow,xpixmap,xconfigure_event,
00083   xgc,xdisplaylist;
00084 
00085 
00086 long x_window_creation = FALSE;
00087 
00088 /*****************************************/
00089 
00090 static long xevent_mask[] = {
00091 0,                              /* ???                   0 */
00092 0,                              /* ???                   1 */
00093 KeyPressMask,                   /* KeyPress              2 */
00094 KeyReleaseMask,                 /* KeyRelease            3 */
00095 ButtonPressMask,                /* ButtonPress           4 */ 
00096 ButtonReleaseMask,              /* ButtonRelease         5 */
00097 
00098 PointerMotionMask |     PointerMotionHintMask | ButtonMotionMask |
00099 Button1MotionMask |     Button2MotionMask |     Button3MotionMask |
00100 Button4MotionMask |     Button5MotionMask,
00101                                 /* MotionNotify          6 */
00102 EnterWindowMask,                /* EnterNotify           7 */
00103 LeaveWindowMask,                /* LeaveNotify           8 */
00104 FocusChangeMask,                /* FocusIn               9 */
00105 FocusChangeMask,                /* FocusOut             10 */
00106 KeymapStateMask,                /* KeymapNotify         11 */
00107 ExposureMask,                   /* Expose               12 */
00108 0,                              /* GraphicsExpose       13 */
00109 0,                              /* NoExpose             14 */
00110 VisibilityChangeMask,           /* VisibilityNotify     15 */
00111 SubstructureNotifyMask,         /* CreateNotify         16 */
00112 SubstructureNotifyMask,         /* DestroyNotify        17 */
00113 StructureNotifyMask,            /* UnmapNotify          18 */
00114 StructureNotifyMask,            /* MapNotify            19 */
00115 SubstructureRedirectMask,       /* MapRequest           20 */
00116 SubstructureNotifyMask,         /* ReparentNotify       21 */
00117 StructureNotifyMask,            /* ConfigureNotify      22 */
00118 SubstructureRedirectMask,       /* ConfigureRequest     23 */
00119 StructureNotifyMask,            /* GravityNotify        24 */
00120 ResizeRedirectMask,             /* ResizeRequest        25 */
00121 StructureNotifyMask,            /* CirculateNotify      26 */
00122 SubstructureRedirectMask,       /* CirculateRequest     27 */
00123 PropertyChangeMask,             /* PropertyNotify       28 */
00124 0,                              /* SelectionClear       29 */
00125 0,                              /* SelectionRequest     30 */
00126 0,                              /* SelectionNotify      31 */
00127 ColormapChangeMask,             /* ColormapNotify       32 */
00128 0,                              /* ClientMessage        33 */
00129 0                               /* MappingNotify        34 */
00130 };
00131 
00132 
00133 
00134 static char* xevent_name[] = {
00135   "???",
00136   "???",
00137   "KeyPress",
00138   "KeyRelease",
00139   "ButtonPress",
00140   "ButtonRelease",
00141   "MotionNotify",
00142   "EnterNotify",
00143   "LeaveNotify",
00144   "FocusIn",
00145   "FocusOut",
00146   "KeymapNotify",
00147   "Expose",
00148   "GraphicsExpose",
00149   "NoExpose",
00150   "VisibilityNotify",
00151   "CreateNotify",
00152   "DestroyNotify",
00153   "UnmapNotify",
00154   "MapNotify",
00155   "MapRequest",
00156   "ReparentNotify",
00157   "ConfigureNotify",
00158   "ConfigureRequest",
00159   "GravityNotify",
00160   "ResizeRequest",
00161   "CirculateNotify",
00162   "CirculateRequest",
00163   "PropertyNotify",
00164   "SelectionClear",
00165   "SelectionRequest",
00166   "SelectionNotify",
00167   "ColormapNotify",
00168   "ClientMessage",
00169   "MappingNotify"
00170 };
00171 
00172 
00173 
00174 
00175 /*****************************************************************/
00176 /* Macros */
00177 
00178 #define DrawableGC(w)(GC)GetIntAttr(GetPsiAttr(w,"graphic_context"),"id")
00179 #define WindowDisplayList(w) GetIntAttr(GetPsiAttr(w,"display_list"),"id")
00180 
00181 /* Macros to keep GCC happy. RM: Feb  9 1994  */
00182 #define DISP(X)(Display *)val[X]
00183 #define DRAW(X)(Drawable)val[X]
00184 #define WIND(X)(Window)val[X]
00185 #define GCVAL(X)(GC)val[X]
00186 #define FONT(X)(Font)val[X]
00187 #define CMAP(X)(Colormap)val[X]  
00188 #define STRG(X)(char *)val[X]
00189 
00190   
00191   
00192 /*****************************************************************/
00193 /* Static */
00194 /* handle the errors X */
00195 
00196 
00197 static int x_handle_error(display,x_error)
00198      Display *display;
00199      XErrorEvent *x_error;
00200 {
00201   char msg[128];
00202   XGetErrorText(display,x_error->error_code,msg,128);
00203   Errorline("X error message: %s.\n",msg);
00204   /* don't use abort_life(TRUE) because it tries to destroy windows ...
00205      and loops because the window is yet in the stack !!
00206      jch - Fri Aug  7 17:58:27 MET DST 1992
00207      */
00208   exit_life(TRUE);
00209 }
00210 
00211 
00212 static int x_handle_fatal_error(display)
00213      Display *display;
00214 {
00215   Errorline("fatal X Error.\n");
00216   exit_life(TRUE);
00217 }
00218 
00219 
00220 /*  RM: Jun 24 1993  */
00221 /* JCH didn't understand ANYTHING about trailing! */
00222 
00223 void bk_stack_add_int_attr(t,attrname,value)
00224      ptr_psi_term t;
00225      char *attrname;
00226      long value;
00227 {
00228   ptr_psi_term t1;
00229   ptr_node n;
00230   char *perm;
00231   
00232 
00233   perm=heap_copy_string(attrname);
00234   n=find(featcmp,perm,t->attr_list);
00235   if(n) {
00236     t1=(ptr_psi_term)n->data;
00237     deref_ptr(t1);
00238     if(!t1->value) {
00239       push_ptr_value(int_ptr,&(t1->value));
00240       t1->value=heap_alloc(sizeof(REAL));
00241     }
00242     *(REAL *)t1->value =(REAL) value;
00243   }
00244   else {
00245     t1=stack_psi_term(4);
00246     t1->type=integer;
00247     t1->value=heap_alloc(sizeof(REAL));
00248     *(REAL *)t1->value =(REAL) value;
00249     bk_stack_insert(featcmp,perm,&(t->attr_list),t1);
00250   }
00251 }
00252 
00253 
00254 void bk_change_psi_attr(t,attrname,value)
00255      ptr_psi_term t;
00256      char *attrname;
00257      ptr_psi_term value;
00258 {
00259   ptr_psi_term t1;
00260   ptr_node n;
00261   char *perm;
00262   
00263 
00264   perm=heap_copy_string(attrname);
00265   n=find(featcmp,perm,t->attr_list);
00266   if(n) {
00267     t1=(ptr_psi_term)n->data;
00268     deref_ptr(t1);
00269     *t1= *value;
00270     /*push_ptr_value(psi_term_ptr,&(t1->coref));*/
00271     if(value!=t1)
00272       value->coref=t1;
00273   }
00274   else
00275     bk_stack_insert(featcmp,perm,&(t->attr_list),value);
00276 }
00277 
00278 
00279 
00280 
00281 
00282 /*****************************************************************/
00283 /* Utility */
00284 /* unify psi_term T to the integer value V */
00285 /* could be in builtins.c */
00286 
00287 long unify_int_result(t,v)
00288      ptr_psi_term t;
00289      long v;
00290 {
00291   long smaller;
00292   long success=TRUE;
00293   
00294   
00295   deref_ptr(t);
00296   push_ptr_value(int_ptr,&(t->value));
00297   t->value = heap_alloc(sizeof(REAL));
00298   *(REAL *) t->value = v;
00299   
00300   matches(t->type,integer,&smaller);
00301   
00302   if(!smaller) 
00303     {
00304       push_ptr_value(def_ptr,&(t->type));
00305       t->type = integer;
00306       t->status = 0;
00307     }
00308   else
00309     success = FALSE;
00310   
00311   if(success) 
00312     {
00313       i_check_out(t);
00314       if(t->resid)
00315         release_resid(t);
00316     }
00317   
00318   return success;
00319 }
00320 
00321 
00322 /*****************************************************************/
00323 /* Static */
00324 /* build a psi-term of type t with a feature f of value v */
00325 
00326 static ptr_psi_term NewPsi(t,f,v)
00327      ptr_definition t;
00328      char * f;
00329      long v;
00330 {
00331   ptr_psi_term p;
00332   
00333   p = stack_psi_term(4);
00334   p->type = t;
00335   bk_stack_add_int_attr(p,f,v);
00336   return p;
00337 }
00338 
00339 
00340 /*****************************************************************/
00341 /* Utilities */
00342 /* return the value of the attribute attributeName on the psi-term psiTerm */
00343 
00344 long GetIntAttr(psiTerm,attributeName)
00345      
00346      ptr_psi_term psiTerm;
00347      char *attributeName;
00348 {
00349   ptr_node nodeAttr;
00350   ptr_psi_term psiValue;
00351   
00352   
00353   deref_ptr(psiTerm);
00354   nodeAttr=find(featcmp,attributeName,psiTerm->attr_list);
00355   if(!nodeAttr) {
00356     Errorline("in GetIntAttr: didn't find %s on %P\n",
00357                attributeName,
00358                psiTerm);
00359     exit_life(TRUE);
00360   }
00361   
00362   psiValue=(ptr_psi_term)nodeAttr->data;
00363   deref_ptr(psiValue);
00364   if(psiValue->value)
00365     return *(REAL *) psiValue->value;
00366   else {
00367     /* Errorline("in GetIntAttr: no value!\n"); */
00368     return -34466; /* Real nasty hack for now  RM: Apr 23 1993  */
00369   }
00370 }
00371 
00372 
00373 
00374 /*****************************************************************/
00375 /* Utilities */
00376 /* return the psi-term of the attribute attributeName on the psi-term psiTerm */
00377 
00378 ptr_psi_term GetPsiAttr(psiTerm,attributeName)
00379      
00380      ptr_psi_term psiTerm;
00381      char *attributeName;
00382 {
00383   ptr_node nodeAttr;
00384   ptr_psi_term psiValue;
00385   
00386   
00387   if((nodeAttr = find(featcmp,attributeName,psiTerm->attr_list)) == NULL)
00388     {
00389       Errorline("in GetPsiAttr: no attribute name on psi-term ?\n");
00390       exit_life(TRUE);
00391     }
00392   
00393   if((psiValue =(ptr_psi_term) nodeAttr->data) == NULL)
00394     {
00395       Errorline("in GetPsiAttr: no value on psi-term ?\n");
00396       exit_life(TRUE);
00397     }
00398   
00399   return psiValue;
00400 }
00401 
00402 /*****************************************************************/
00403 /* Static */
00404 /* resize the pixmap of the window */
00405 
00406 static void ResizePixmap(psi_window,display,window,width,height)
00407      
00408      ptr_psi_term psi_window;
00409      Display *display;
00410      Window window;
00411      unsigned long width,height;
00412 {
00413   Pixmap pixmap;
00414   GC pixmapGC;
00415   ptr_psi_term psiPixmap,psiPixmapGC;
00416   XGCValues gcvalues;
00417   XWindowAttributes attr;
00418   ptr_psi_term psi_gc;
00419   
00420     
00421   /* free the old pixmap */
00422   psiPixmap = GetPsiAttr(psi_window,"pixmap");
00423   psiPixmapGC=NULL;
00424   
00425   if((pixmap = GetIntAttr(psiPixmap,"id")) != 0)
00426     {
00427       /* change the pixmap */
00428       XFreePixmap(display,pixmap);
00429       /* change the pixmap'gc too,because the gc is created on the pixmap ! */
00430 
00431       psiPixmapGC = GetPsiAttr(psiPixmap,"graphic_context");
00432 
00433       /*  RM: Jun 24 1993  */
00434       pixmapGC=(GC)GetIntAttr(psiPixmapGC,"id");
00435       if(pixmapGC)
00436         XFreeGC(display,pixmapGC);
00437       
00438       bk_stack_add_int_attr(psiPixmap,"id",NULL);
00439       bk_stack_add_int_attr(psiPixmapGC,"id",NULL);
00440     }
00441   
00442   /* init a new pixmap on the window */
00443   XGetWindowAttributes(display,window,&attr);
00444   if((pixmap = XCreatePixmap(display,window,
00445                                attr.width+1,attr.height+1,
00446                                attr.depth)) != 0)
00447     {
00448       bk_stack_add_int_attr(psiPixmap,"id",pixmap);
00449       gcvalues.cap_style = CapRound;
00450       gcvalues.join_style = JoinRound;
00451       pixmapGC = XCreateGC(display,pixmap,
00452                             GCJoinStyle|GCCapStyle,&gcvalues);
00453 
00454       /*  RM: Jun 24 1993  */
00455       if(psiPixmapGC)
00456         bk_stack_add_int_attr(psiPixmapGC,"id",pixmapGC);
00457       else
00458         psiPixmapGC=NewPsi(xgc,"id",pixmapGC);
00459       bk_change_psi_attr(psiPixmap,"graphic_context",psiPixmapGC);
00460     }
00461 }
00462 
00463 
00464 /*****************************************************************/
00465 /* Static */
00466 /* free all attributes of a window,that is: its display list,its gc,
00467    its pixmap ... */
00468 
00469 static void FreeWindow(display,psi_window)
00470      
00471      Display *display;
00472      ptr_psi_term psi_window;
00473      
00474 {
00475   ptr_psi_term psiPixmap;
00476   
00477   
00478   XFreeGC(display,DrawableGC(psi_window));
00479   x_free_display_list(WindowDisplayList(psi_window));
00480   
00481   psiPixmap = GetPsiAttr(psi_window,"pixmap");
00482   XFreeGC(display,DrawableGC(psiPixmap));
00483   XFreePixmap(display,GetIntAttr(psiPixmap,"id"));
00484 }
00485 
00486 
00487 /*****************************************************************/
00488 /******** xcOpenConnection
00489   
00490   xcOpenConnection(+Name,-Connection)
00491   
00492   open a connection to the X server.
00493   
00494   */
00495 
00496 long xcOpenConnection()
00497      
00498 {
00499   include_var_builtin(2);
00500   ptr_definition types[2];
00501   char *display;
00502   Display * connection;
00503   ptr_psi_term psiConnection;
00504   
00505   
00506   types[0] = quoted_string;
00507   types[1] = xdisplay;
00508   
00509   
00510   begin_builtin(xcOpenConnection,2,1,types);
00511   
00512   if(strcmp(STRG(0),""))
00513     display =STRG(0);
00514   else
00515     display = NULL; 
00516   
00517   if(connection = XOpenDisplay(display))
00518     {
00519       psiConnection = NewPsi(xdisplay,"id",connection);
00520       push_goal(unify,psiConnection,args[1],NULL);
00521       
00522       success = TRUE;
00523     }
00524   else
00525     {
00526       Errorline("could not open connection in %P.\n",g);
00527       success = FALSE;
00528     }
00529   
00530   end_builtin();
00531 }
00532 
00533 
00534 /*****************************************************************/
00535 /******** xcDefaultRootWindow
00536   
00537   xcDefaultRootWindow(+Display,-Root)
00538   
00539   return the root window of the given display
00540   
00541   */
00542 
00543 long xcDefaultRootWindow()
00544      
00545 {
00546   include_var_builtin(2);
00547   ptr_definition types[2];
00548   Display *display;
00549   ptr_psi_term psiRoot;
00550   
00551   
00552   types[0] = real;
00553   types[1] = xdrawable;
00554   
00555   begin_builtin(xcDefaultRootWindow,2,1,types);
00556   
00557   display = DISP(0);
00558   
00559   psiRoot = NewPsi(xwindow,"id",DefaultRootWindow(display));
00560   
00561   push_goal(unify,psiRoot,args[1],NULL);
00562   success = TRUE;
00563   
00564   end_builtin();
00565 }
00566 
00567 
00568 
00569 /*****************************************************************/
00570 /******** static GetConnectionAttribute */
00571 
00572 static long GetConnectionAttribute(display,attributeId,attribute)
00573      
00574      Display *display;
00575      long attributeId,*attribute;
00576      
00577 {
00578   switch(attributeId) 
00579     {
00580     case 0: 
00581       *attribute =(unsigned long) ConnectionNumber(display);
00582       break;
00583     case 1: 
00584 #ifndef __alpha
00585       *attribute =(unsigned long)(display->proto_major_version);
00586 #endif
00587       break;
00588     case 2: 
00589 #ifndef __alpha
00590       *attribute =(unsigned long)(display->proto_minor_version);
00591 #endif
00592       break;
00593     case 3: 
00594       *attribute =(unsigned long) ServerVendor(display);
00595       break;
00596     case 4: 
00597       *attribute =(unsigned long) ImageByteOrder(display);
00598       break;
00599     case 5: 
00600       *attribute =(unsigned long) BitmapUnit(display);
00601       break;
00602     case 6: 
00603       *attribute =(unsigned long) BitmapPad(display);
00604       break;
00605     case 7: 
00606       *attribute =(unsigned long) BitmapBitOrder(display);
00607       break;
00608     case 8: 
00609       *attribute =(unsigned long) VendorRelease(display);
00610       break;
00611     case 9:
00612 #ifndef __alpha
00613       *attribute =(unsigned long)(display->qlen);
00614 #endif
00615       break;
00616     case 10: 
00617       *attribute =(unsigned long) LastKnownRequestProcessed(display);
00618       break;
00619     case 11: 
00620 #ifndef __alpha
00621       *attribute =(unsigned long)(display->request);
00622 #endif
00623       break;
00624     case 12: 
00625       *attribute =(unsigned long) DisplayString(display); 
00626       break;
00627     case 13: 
00628       *attribute =(unsigned long) DefaultScreen(display); 
00629       break;
00630     case 14: 
00631 #ifndef __alpha
00632       *attribute =(unsigned long)(display->min_keycode);
00633 #endif
00634       break;
00635     case 15: 
00636 #ifndef __alpha
00637       *attribute =(unsigned long)(display->max_keycode);
00638 #endif
00639       break;
00640     default: 
00641       return FALSE;
00642       break;
00643     }
00644   
00645   return TRUE;
00646 }
00647 
00648 
00649 long xcQueryTextExtents(); /*  RM: Apr 20 1993  */
00650 
00651 
00652 /*****************************************************************/
00653 /******** xcGetConnectionAttribute
00654   
00655   xcGetConnectionAttribute(+Display,+AttributeId,-Value)
00656   
00657   returns the value corresponding to the attribute id.
00658   
00659   */
00660 
00661 long xcGetConnectionAttribute()
00662      
00663 {
00664   include_var_builtin(3);
00665   ptr_definition types[3];
00666   long attr;
00667   
00668   
00669   types[0] = real;
00670   types[1] = real;
00671   types[2] = real;
00672   
00673   begin_builtin(xcGetConnectionAttribute,3,2,types);
00674   
00675   if(GetConnectionAttribute(DISP(0),DRAW(1),&attr))
00676     {
00677       unify_real_result(args[2],(REAL) attr);
00678       success = TRUE;
00679     }
00680   else
00681     {
00682       Errorline("could not get connection attribute in %P.\n",g);
00683       success = FALSE;
00684     }
00685   
00686   end_builtin();
00687 }
00688 
00689 
00690 /*****************************************************************/
00691 /******** GetScreenAttribute */
00692 
00693 static long GetScreenAttribute(display,screen,attributeId,attribute)
00694      
00695      Display *display;
00696      long screen,attributeId,*attribute;
00697      
00698 {
00699   Screen *s;
00700   
00701   
00702   s = ScreenOfDisplay(display,screen);
00703   switch(attributeId) 
00704     {
00705     case 0: 
00706       *attribute =(unsigned long) DisplayOfScreen(s);
00707       break;
00708     case 1: 
00709       *attribute =(unsigned long) RootWindowOfScreen(s);
00710       break;
00711     case 2: 
00712       *attribute =(unsigned long) WidthOfScreen(s);
00713       break;
00714     case 3: 
00715       *attribute =(unsigned long) HeightOfScreen(s);
00716       break;
00717     case 4: 
00718       *attribute =(unsigned long) WidthMMOfScreen(s);
00719       break;
00720     case 5: 
00721       *attribute =(unsigned long) HeightMMOfScreen(s);
00722       break;
00723     case 6: 
00724       *attribute =(unsigned long) DefaultDepthOfScreen(s);
00725       break;
00726     case 7: 
00727       *attribute =(unsigned long) DefaultVisualOfScreen(s);
00728       break;
00729     case 8: 
00730       *attribute =(unsigned long) DefaultGCOfScreen(s);
00731       break;
00732     case 9: 
00733       *attribute =(unsigned long) DefaultColormapOfScreen(s);
00734       break;
00735     case 10: 
00736       *attribute =(unsigned long) WhitePixelOfScreen(s);
00737       break;
00738     case 11: 
00739       *attribute =(unsigned long) BlackPixelOfScreen(s);
00740       break;
00741     case 12: 
00742       *attribute =(unsigned long) MaxCmapsOfScreen(s);
00743       break;
00744     case 13: 
00745       *attribute =(unsigned long) MinCmapsOfScreen(s);
00746       break;
00747     case 14: 
00748       *attribute =(unsigned long) DoesBackingStore(s);
00749       break;
00750     case 15: 
00751       *attribute =(unsigned long) DoesSaveUnders(s);
00752       break;
00753     case 16: 
00754       *attribute =(unsigned long) EventMaskOfScreen(s);
00755       break;
00756     default: 
00757       return FALSE;
00758       break;
00759     }
00760   
00761   return TRUE;
00762 }
00763 
00764 
00765 /*****************************************************************/
00766 /******** xcGetScreenAttribute
00767   
00768   xcGetScreenAttribute(+Display,+Screen,+AttributeId,-Value)
00769   
00770   returns the value corresponding to the attribute id.
00771   
00772   */
00773 
00774 long xcGetScreenAttribute()
00775      
00776 {
00777   include_var_builtin(4);
00778   ptr_definition types[4];
00779   long attr;
00780   
00781   
00782   types[0] = real;
00783   types[1] = real;
00784   types[2] = real;
00785   types[3] = real;
00786   
00787   begin_builtin(xcGetScreenAttribute,4,3,types);
00788   
00789   if(GetScreenAttribute(DISP(0),DRAW(1),val[2],&attr))
00790     {
00791       unify_real_result(args[3],(REAL) attr);
00792       success = TRUE;
00793     }
00794   else
00795     {
00796       Errorline("could not get screen attribute in %P.\n",g);
00797       success = FALSE;
00798     }
00799   
00800   end_builtin();
00801 }
00802 
00803 
00804 /*****************************************************************/
00805 /******** xcCloseConnection
00806   
00807   xcCloseConnection(+Connection)
00808   
00809   Close the connection.
00810   
00811   */
00812 
00813 long xcCloseConnection()
00814      
00815 {
00816   include_var_builtin(1);
00817   ptr_definition types[1];
00818   
00819   
00820   types[0] = real;
00821   
00822   begin_builtin(xcCloseConnection,1,1,types);
00823   
00824   XCloseDisplay(DISP(0));
00825   success = TRUE;
00826   
00827   end_builtin();
00828 }
00829 
00830 
00831 
00832 /*****************************************************************/
00833 /******** xcCreateSimpleWindow
00834   
00835   xcCreateSimpleWindow(+Display,+Parent,+X,+Y,+Width,+Height,
00836   +BackGroundColor,+WindowTitle,+IconTitle,
00837   +BorderWidth,+BorderColor,
00838   +Permanent,+Show,-Window)
00839   
00840   create a simple window.
00841   
00842   */
00843 
00844 long xcCreateSimpleWindow()
00845      
00846 {
00847   include_var_builtin(14);
00848   ptr_definition types[14];
00849   Window window;
00850   Pixmap life_icon;
00851   XSizeHints hints;
00852   XWindowChanges changes;
00853   unsigned long changesMask;
00854   XSetWindowAttributes attributes;
00855   unsigned long attributesMask;
00856   long j;
00857   long permanent,show;
00858   Display *display;
00859   GC gc;
00860   XGCValues gcvalues;
00861   ptr_psi_term psiWindow;
00862   
00863   
00864   for(j = 0; j < 14; j++)
00865     types[j] = real;
00866   types[7]= quoted_string;
00867   types[8]= quoted_string;
00868   types[11]= boolean;
00869   types[12]= boolean;
00870   
00871   begin_builtin(xcCreateSimpleWindow,14,13,types);
00872   
00873   permanent = val[11];
00874   show = val[12];
00875   
00876   if(window = XCreateSimpleWindow(DISP(0),WIND(1),/* display,parent */
00877                                     val[2],val[3],/* X,Y */
00878                                     val[4],val[5],/* Width,Height */
00879                                     val[9],val[10],/* BorderWidth,BorderColor */
00880                                     val[6]))        /* BackGround */
00881     {
00882       psiWindow = stack_psi_term(4);
00883       psiWindow->type = xwindow;
00884       bk_stack_add_int_attr(psiWindow,"id",window);
00885       
00886       /* attach the icon of life */
00887       life_icon = XCreateBitmapFromData(DISP(0),window,life_icon_bits,
00888                                          life_icon_width,life_icon_height);
00889       /* set properties */
00890 #if 0
00891       hints.x = val[2];
00892       hints.y = val[3];
00893       hints.width =val[4] ;
00894       hints.height = val[5];
00895       hints.flags = PPosition | PSize;
00896 #endif
00897       hints.flags = 0;
00898       XSetStandardProperties(DISP(0),window,
00899                              STRG(7),STRG(8),
00900                              life_icon,arg_v,arg_c,
00901                              &hints);   
00902 #if 0
00903       changes.x = val[2];
00904       changes.y = val[3];
00905       changes.width =val[4] ;
00906       changes.height = val[5];
00907       changesMask = CWX | CWY | CWWidth | CWHeight;
00908       display = DISP(0);
00909       XReconfigureWMWindow(DISP(0),window,DefaultScreen(display),
00910                             changesMask,&changes);
00911 #endif
00912       /* set the background color */
00913       XSetWindowBackground(DISP(0),window,val[6]);
00914 #if 0
00915       /* set the geometry before to show the window */
00916       XMoveResizeWindow(DISP(0),window,
00917                          val[2],val[3],val[4],val[5]);
00918 #endif
00919       /* set the back pixel in order to have the color when deiconify */
00920       attributes.background_pixel = val[6];
00921       attributes.backing_pixel = val[6];
00922       attributesMask = CWBackingPixel|CWBackPixel;
00923       XChangeWindowAttributes(DISP(0),window,
00924                                attributesMask,&attributes);
00925       
00926       if(!permanent)
00927         {
00928           push_window(destroy_window,DISP(0),window);
00929           x_window_creation = TRUE;
00930         }
00931       else
00932         if(show)
00933           push_window(show_window,DISP(0),window);
00934       
00935 #if 0
00936       /* map window is made in xCreateWindow(see xpred.lf) */
00937       /* due to the flag overrideRedirect */
00938       if(show)
00939         x_show_window(DISP(0),window);
00940 #endif
00941       
00942       /* create a GC on the window for the next outputs */
00943       gcvalues.cap_style = CapRound;
00944       gcvalues.join_style = JoinRound;
00945       gc = XCreateGC(DISP(0),window,GCJoinStyle|GCCapStyle,&gcvalues);
00946       bk_change_psi_attr(psiWindow,"graphic_context",
00947                           NewPsi(xgc,"id",gc));
00948       
00949       /* init a display list on the window for the refresh window */
00950       bk_change_psi_attr(psiWindow,"display_list",
00951                           NewPsi(xdisplaylist,"id",x_display_list()));
00952       
00953       /* init a pixmap on the window for the refresh mechanism */
00954       bk_change_psi_attr(psiWindow,"pixmap",
00955                           NewPsi(xpixmap,"id",NULL));
00956       ResizePixmap(psiWindow,DISP(0),window,val[4],val[5]);
00957       
00958       push_goal(unify,psiWindow,args[13],NULL);
00959       success = TRUE;
00960     }
00961   else
00962     {
00963       Errorline("could not create a simple window in %P.\n",g);
00964       success = FALSE;
00965     }
00966   
00967   end_builtin();
00968 }
00969 
00970 
00971 /*****************************************************************/
00972 #if 0
00973 
00974 xcCreateWindow is not used anymore since we use xcCreateSimpleWindow.
00975   I just keep this code in case - jch - Thu Aug  6 16:11:23 MET DST 1992
00976   
00977   /******** xcCreateWindow
00978     
00979     xcCreateWindow(+Connection,+Parent,+X,+Y,+Width,+Height,
00980     +BorderWidth,+Depth,+Class,+Visual,
00981     +Permanent,+Show,-Window)
00982     
00983     create a window on the display Connection.
00984     
00985     */
00986   
00987   long xcCreateWindow()
00988 
00989 {
00990   include_var_builtin(13);
00991   ptr_definition types[13];
00992   Window window;
00993   XWindowChanges changes;
00994   unsigned long changesMask;
00995   XSizeHints hints;
00996   long j,permanent,show;
00997   GC gc;
00998   XGCValues gcvalues;
00999   
01000   
01001   for(j = 0; j < 13; j++)
01002     types[j] = real;
01003   
01004   begin_builtin(xcCreateWindow,13,12,types);
01005   
01006   permanent = val[10];
01007   show = val[11];
01008   
01009   if(window = XCreateWindow(DISP(0),WIND(1),/* display,parent */
01010                               val[2],val[3],/* X,Y */
01011                               val[4],val[5],/* Width,Height */
01012                               val[6],val[7],/* BorderWidth,Depth */
01013                               val[8],val[9],/* Class,Visual */
01014                               0,(XSetWindowAttributes *) NULL))
01015     {
01016       unify_real_result(args[12],(REAL) window);
01017       
01018       changes.x = val[2];
01019       changes.y = val[3];
01020       changes.width =val[4] ;
01021       changes.height = val[5];
01022       changesMask = CWX | CWY | CWWidth | CWHeight;
01023       XConfigureWindow(DISP(0),window,changesMask,&changes);
01024       
01025       hints.x = val[2];
01026       hints.y = val[3];
01027       hints.width =val[4] ;
01028       hints.height = val[5];
01029       hints.flags = PPosition | PSize;
01030       XSetNormalHints(DISP(0),window,&hints);
01031       
01032       if(!permanent)
01033         {
01034           push_window(destroy_window,DISP(0),window);
01035           x_window_creation = TRUE;
01036         }
01037       else
01038         if(show)
01039           push_window(show_window,DISP(0),window);
01040       
01041       if(show)
01042         x_show_window(DISP(0),window);
01043       
01044       /* create a GC on the window for the next outputs */
01045       gcvalues.cap_style = CapRound;
01046       gcvalues.join_style = JoinRound;
01047       gc = XCreateGC(DISP(0),window,GCJoinStyle|GCCapStyle,&gcvalues);
01048       bk_stack_add_int_attr(args[12],"gc",gc);
01049       
01050       /* init a display list on the window for the refresh window */
01051       bk_stack_add_int_attr(args[12],"display_list",NULL);
01052       
01053       success = TRUE;
01054     }
01055   else
01056     {
01057       Errorline("could not create window in %P.\n",g);
01058       success = FALSE;
01059     }
01060   
01061   end_builtin();
01062 }
01063 
01064 #endif
01065 
01066 
01067 /*****************************************************************/
01068 /******** xcSetStandardProperties
01069   
01070   xcSetStandardProperties(+Display,+Window,+WindowTitle,+IconTitle,
01071   +X,+Y,+Width,+Height)
01072   
01073   */
01074 
01075 long xcSetStandardProperties()
01076 {
01077   include_var_builtin(8);
01078   ptr_definition types[8];
01079   long j;
01080   XSizeHints hints;
01081   
01082   
01083   for(j=0; j<8; j++)
01084     types[j] = real;
01085   types[1] = xwindow;
01086   types[2] = quoted_string;
01087   types[3] = quoted_string;
01088   
01089   begin_builtin(xcSetStandardProperties,8,8,types);
01090   
01091   hints.x = val[4];
01092   hints.y = val[5];
01093   hints.width = val[6] ;
01094   hints.height = val[7];
01095   hints.flags = PPosition | PSize; 
01096   
01097   XSetStandardProperties(DISP(0),WIND(1),
01098                         (char*)val[2],(char*)val[3],/* window title,icon title */
01099                          None,              /* icon pixmap */
01100                         (char **) NULL,0, /* argv,argc */
01101                          &hints); 
01102   
01103   ResizePixmap(args[1],val[0],val[1],val[6],val[7]);
01104   
01105   success = TRUE;
01106   
01107   end_builtin();
01108   
01109 }
01110 
01111 
01112 
01113 /*****************************************************************/
01114 /******** xcGetWindowGeometry
01115   
01116   xcGetWindowGeometry(+Display,+Window,-X,-Y,-Width,-Height)
01117   
01118   returns the geometry of the window.
01119   
01120   */
01121 
01122 long xcGetWindowGeometry()
01123      
01124 {
01125   include_var_builtin(6);
01126   ptr_definition types[6];
01127   int j,x,y;
01128   unsigned int w,h,bw,d;
01129   Window r;
01130   
01131   
01132   for(j=0; j<6; j++)
01133     types[j] = real;
01134   types[1] = xdrawable;
01135   
01136   begin_builtin(xcGetWindowGeometry,6,2,types);
01137   
01138   if(XGetGeometry(DISP(0),DRAW(1),
01139                     &r,&x,&y,&w,&h,&bw,&d))
01140     {
01141       unify_real_result(args[2],(REAL) x);
01142       unify_real_result(args[3],(REAL) y);
01143       unify_real_result(args[4],(REAL) w);
01144       unify_real_result(args[5],(REAL) h);
01145       success = TRUE;
01146     }
01147   else
01148     {
01149       Errorline("could not get the geometry in %P.\n",g);
01150       success = FALSE;
01151     }
01152   
01153   end_builtin();
01154 }
01155 
01156 
01157 /*****************************************************************/
01158 /******** GetWindowAttribute */
01159 
01160 static long GetWindowAttribute(display,window,attributeId,attribute)
01161      
01162      Display *display; long window,attributeId,*attribute;
01163 {
01164   XWindowAttributes windowAttributes;
01165   
01166   
01167   XGetWindowAttributes(display,window,&windowAttributes);
01168   switch(attributeId) 
01169     {
01170     case 0: 
01171       *attribute = windowAttributes.x;  
01172       break;
01173     case 1: 
01174       *attribute = windowAttributes.y;
01175       break;
01176     case 2: 
01177       *attribute = windowAttributes.width;
01178       break;
01179     case 3: 
01180       *attribute = windowAttributes.height;
01181       break;
01182     case 4: 
01183       *attribute = windowAttributes.border_width;
01184       break;
01185     case 5: 
01186       *attribute = windowAttributes.depth;
01187       break;
01188     case 6: 
01189       *attribute = windowAttributes.root;
01190       break;
01191     case 7: 
01192       *attribute =(unsigned long)windowAttributes.screen;
01193       break;
01194     case 8: 
01195       *attribute =(unsigned long)windowAttributes.visual;
01196       break;
01197     case 9: 
01198       *attribute = windowAttributes.class;
01199       break;
01200     case 10: 
01201       *attribute = windowAttributes.all_event_masks;
01202       break;
01203     case 11: 
01204       *attribute = windowAttributes.bit_gravity;
01205       break;
01206     case 12: 
01207       *attribute = windowAttributes.win_gravity;
01208       break;
01209     case 13: 
01210       *attribute = windowAttributes.backing_store;
01211       break;
01212     case 14: 
01213       *attribute = windowAttributes.backing_planes;
01214       break;
01215     case 15: 
01216       *attribute = windowAttributes.backing_pixel;
01217       break;
01218     case 16: 
01219       *attribute = windowAttributes.override_redirect;
01220       break;
01221     case 17: 
01222       *attribute = windowAttributes.save_under;
01223       break;
01224     case 18: 
01225       *attribute = windowAttributes.your_event_mask;
01226       break;
01227     case 19: 
01228       *attribute = windowAttributes.do_not_propagate_mask;
01229       break;
01230     case 20: 
01231       *attribute = windowAttributes.colormap;
01232       break;
01233     case 21: 
01234       *attribute = windowAttributes.map_installed;
01235       break;
01236     case 22: 
01237       *attribute = windowAttributes.map_state;
01238       break;
01239     default: 
01240       return FALSE;
01241       break;
01242     }
01243   return TRUE;
01244 }
01245 
01246 
01247 /*****************************************************************/
01248 /******** xcGetWindowAttribute
01249   
01250   xcGetWindowAttribute(+Display,+Window,+AttributeId,-Value)
01251   
01252   returns the value corresponding to the attribute id of the window.
01253   
01254   */
01255 
01256 long xcGetWindowAttribute()
01257      
01258 {
01259   include_var_builtin(4);
01260   ptr_definition types[4];
01261   long attr;
01262   
01263   
01264   types[0] = real;
01265   types[1] = xwindow;
01266   types[2] = real;
01267   types[3] = real;
01268   
01269   begin_builtin(xcGetWindowAttribute,4,3,types);
01270   
01271   if(GetWindowAttribute(DISP(0),WIND(1),val[2],&attr))
01272     {
01273       unify_real_result(args[3],(REAL) attr);
01274       success = TRUE;
01275     }
01276   else
01277     {
01278       Errorline("could not get a window attribute in %P.\n",g);
01279       success = FALSE;
01280     }
01281   
01282   end_builtin();
01283 }
01284 
01285 
01286 /*****************************************************************/
01287 /******** xcSetWindowGeometry
01288   
01289   xcSetWindowGeometry(+Display,+Window,+X,+Y,+Width,+Height)
01290   
01291   set the geometry of the window.
01292   
01293   */
01294 
01295 long xcSetWindowGeometry()
01296      
01297 {
01298   include_var_builtin(6);
01299   ptr_definition types[6];
01300   long j;
01301   
01302   
01303   for(j=0; j<6; j++)
01304     types[j] = real;
01305   types[1] = xdrawable;
01306   
01307   begin_builtin(xcSetWindowGeometry,6,6,types);
01308   
01309   XMoveResizeWindow(DISP(0),DRAW(1),
01310                      val[2],val[3],val[4],val[5]);
01311   
01312   /* modify the pixmap */
01313   ResizePixmap(args[1],val[0],val[1],val[4],val[5]);
01314   
01315   success = TRUE;
01316   
01317   end_builtin();
01318 }
01319 
01320 
01321 
01322 /*****************************************************************/
01323 /******** xcMoveWindow
01324   
01325   xcMoveWindow(+Display,+Window,+X,+Y)
01326   
01327   Move a window to a different location.
01328   
01329   */
01330 
01331 long xcMoveWindow()   /*  RM: May  4 1993  */
01332      
01333 {
01334   include_var_builtin(4);
01335   ptr_definition types[4];
01336   long j;
01337   
01338   
01339   for(j=0; j<4; j++)
01340     types[j] = real;
01341   types[1] = xdrawable;
01342   
01343   begin_builtin(xcMoveWindow,4,4,types);
01344   
01345   XMoveWindow(DISP(0),DRAW(1), val[2],val[3]);
01346   
01347   success = TRUE;
01348   
01349   end_builtin();
01350 }
01351 
01352 
01353 
01354 /*****************************************************************/
01355 /******** SetWindowAttribute */
01356 
01357 static long SetWindowAttribute(psi_window,display,window,attributeId,attribute)
01358      
01359      ptr_psi_term psi_window;
01360      Display *display;
01361      Drawable window;
01362      unsigned long attributeId,attribute;
01363      
01364 {
01365   XSetWindowAttributes attributes;
01366   XWindowChanges changes;
01367   unsigned long attributesMask = 0;
01368   unsigned long changesMask = 0;
01369   long backgroundChange = FALSE;
01370   long sizeChange = FALSE;
01371   unsigned int width,height;
01372   int x,y;
01373   unsigned int bw,d;
01374   Window r;
01375   
01376   switch(attributeId) 
01377     {
01378     case 0: 
01379       changes.x = attribute;
01380       changesMask |= CWX;
01381       break;
01382     case 1:
01383       changes.y = attribute;
01384       changesMask |= CWY;
01385       break;
01386     case 2:
01387       changes.width = attribute;
01388       changesMask |= CWWidth;
01389       XGetGeometry(display,window,&r,&x,&y,&width,&height,&bw,&d);
01390       width = attribute;
01391       sizeChange = TRUE;
01392       break;
01393     case 3:
01394       changes.height = attribute;
01395       changesMask |= CWHeight;
01396       XGetGeometry(display,window,&r,&x,&y,&width,&height,&bw,&d);
01397       height = attribute;
01398       sizeChange = TRUE;
01399       break;
01400     case 4:
01401       changes.border_width = attribute;
01402       changesMask |= CWBorderWidth;
01403       break;
01404     case 11:
01405       attributes.bit_gravity = attribute;
01406       attributesMask |= CWBitGravity;
01407       break;
01408     case 12:
01409       attributes.win_gravity = attribute;
01410       attributesMask |= CWWinGravity;
01411       break;
01412     case 13:
01413       attributes.backing_store = attribute;
01414       attributesMask |= CWBackingStore;
01415       break;
01416     case 14:
01417       attributes.backing_planes = attribute;
01418       attributesMask |= CWBackingPlanes;
01419       break;
01420     case 15:
01421       attributes.backing_pixel = attribute;
01422       attributesMask |= CWBackingPixel;
01423       break;
01424     case 16:
01425       attributes.override_redirect = attribute;
01426       attributesMask |= CWOverrideRedirect;
01427       break;
01428     case 17:
01429       attributes.save_under = attribute;
01430       attributesMask |= CWSaveUnder;
01431       break;
01432     case 18:
01433       attributes.event_mask = attribute;
01434       attributesMask |= CWEventMask;
01435       break;
01436     case 19:
01437       attributes.do_not_propagate_mask = attribute;
01438       attributesMask |= CWDontPropagate;
01439       break;
01440     case 20:
01441       attributes.colormap = attribute;
01442       attributesMask |= CWColormap;
01443       break;
01444     case 23:
01445       changes.sibling = attribute;
01446       changesMask |= CWSibling;
01447       break;
01448     case 24:
01449       changes.stack_mode = attribute;
01450       changesMask |= CWStackMode;
01451       break;
01452     case 25:
01453       attributes.background_pixmap = attribute;
01454       attributesMask |= CWBackPixmap;
01455       break;
01456     case 26:
01457       attributes.background_pixel = attribute;
01458       attributesMask |= CWBackPixel;
01459       backgroundChange = TRUE;
01460       
01461       /* change the backing_pixel in order to fill the pixmap with */
01462       attributes.backing_pixel = attribute;
01463       attributesMask |= CWBackingPixel;
01464       break;
01465     case 27:
01466       attributes.border_pixmap = attribute;
01467       attributesMask |= CWBorderPixmap;
01468       break;
01469     case 28:
01470       attributes.border_pixel = attribute;
01471       attributesMask |= CWBorderPixel;
01472       break;
01473     case 29:
01474       attributes.cursor = attribute;
01475       attributesMask |= CWCursor;
01476       break;
01477     default: 
01478       return FALSE;
01479       break;
01480     }
01481   
01482   if(changesMask)
01483     XConfigureWindow(display,window,changesMask,&changes);
01484   
01485   if(attributesMask)
01486     XChangeWindowAttributes(display,window,attributesMask,&attributes);
01487   
01488   if(backgroundChange)
01489     XClearArea(display,window,0,0,0,0,True);
01490   
01491   if(sizeChange)
01492     ResizePixmap(psi_window,display,window,width,height);
01493   
01494   return TRUE;
01495 }
01496 
01497 
01498 /*****************************************************************/
01499 /******** xcSetWindowAttribute
01500   
01501   xcSetWindowAttribute(+Display,+Window,+AttributeId,+Value)
01502   
01503   set the value corresponding to the attribute id.
01504   
01505   */
01506 
01507 long xcSetWindowAttribute()
01508      
01509 {
01510   include_var_builtin(4);
01511   ptr_definition types[4];
01512   
01513   
01514   types[0] = real;
01515   types[1] = xwindow;
01516   types[2] = real;
01517   types[3] = real;
01518   
01519   begin_builtin(xcSetWindowAttribute,4,4,types);
01520   
01521   if(SetWindowAttribute(args[1],val[0],val[1],val[2],val[3]))
01522     {
01523       XSync(DISP(0),0);
01524       success = TRUE;
01525     }
01526   else
01527     {
01528       Errorline("could not set window attribute in %P.\n",g);
01529       success = FALSE;
01530     }
01531   
01532   end_builtin();
01533 }
01534 
01535 
01536 
01537 /*****************************************************************/
01538 /******** xcMapWindow
01539   
01540   xcMapWindow(+Connection,+Window)
01541   
01542   map the Window on the display Connection.
01543   
01544   */
01545 
01546 long xcMapWindow()
01547      
01548 {
01549   include_var_builtin(2);
01550   ptr_definition types[2];
01551   
01552   
01553   types[0] = real;
01554   types[1] = real;
01555   
01556   begin_builtin(xcMapWindow,2,2,types);
01557   
01558   XMapWindow(DISP(0),WIND(1));
01559   XSync(DISP(0),0);
01560   
01561   push_window(hide_window,DISP(0),val[1]);
01562   success = TRUE;
01563   
01564   end_builtin();
01565 }
01566 
01567 
01568 
01569 /*****************************************************************/
01570 /******** xcRaiseWindow
01571   
01572   xcRaiseWindow(+Connection,+Window)
01573   
01574   raise the Window on the display Connection.
01575   
01576   */
01577 
01578 long xcRaiseWindow()
01579      
01580 {
01581   include_var_builtin(2);
01582   ptr_definition types[2];
01583   
01584   
01585   types[0] = real;
01586   types[1] = real;
01587   
01588   begin_builtin(xcRaiseWindow,2,2,types);
01589   
01590   XRaiseWindow(DISP(0),WIND(1));
01591   XSync(DISP(0),0);
01592   
01593   push_window(hide_window,DISP(0),WIND(1));
01594   success = TRUE;
01595   
01596   end_builtin();
01597 }
01598 
01599 
01600 
01601 /*****************************************************************/
01602 /******** xcUnmapWindow
01603   
01604   xcUnmapWindow(+Connection,+Window)
01605   
01606   unmap the Window on the display Connection.
01607   
01608   */
01609 
01610 long xcUnmapWindow()
01611      
01612 {
01613   include_var_builtin(2);
01614   ptr_definition types[2];
01615   
01616   
01617   types[0] = real;
01618   types[1] = real;
01619   
01620   begin_builtin(xcUnmapWindow,2,2,types);
01621   
01622   XUnmapWindow(DISP(0),WIND(1));
01623   XSync(DISP(0),0);
01624   
01625   push_window(show_window,DISP(0),WIND(1));
01626   success = TRUE;
01627   
01628   end_builtin();
01629 }
01630 
01631 
01632 
01633 
01634 
01635 
01636 /*** RM 8/12/92 START ***/
01637 
01638 
01639 /*****************************************************************/
01640 /******** xcMapSubwindows
01641   
01642   xcMapSubwindows(+Connection,+Window)
01643   
01644   map the sub-windows on the display Connection.
01645   
01646   */
01647 
01648 long xcMapSubwindows()
01649      
01650 {
01651   include_var_builtin(2);
01652   ptr_definition types[2];
01653   
01654   
01655   types[0] = real;
01656   types[1] = real;
01657   
01658   begin_builtin(xcMapSubwindow,2,2,types);
01659   
01660   XMapSubwindows(DISP(0),WIND(1));
01661   XSync(DISP(0),0);
01662   
01663   push_window(hide_subwindow,DISP(0),WIND(1));
01664   success = TRUE;
01665   
01666   end_builtin();
01667 }
01668 
01669 
01670 
01671 /*****************************************************************/
01672 /******** xcUnmapSubwindows
01673   
01674   xcUnmapSubwindows(+Connection,+Window)
01675   
01676   unmap the sub-windows on the display Connection.
01677   
01678   */
01679 
01680 long xcUnmapSubwindows()
01681      
01682 {
01683   include_var_builtin(2);
01684   ptr_definition types[2];
01685   
01686   
01687   types[0] = real;
01688   types[1] = real;
01689   
01690   begin_builtin(xcUnmapSubwindows,2,2,types);
01691   
01692   XUnmapSubwindows(DISP(0),WIND(1));
01693   XSync(DISP(0),0);
01694   
01695   push_window(show_subwindow,DISP(0),WIND(1));
01696   success = TRUE;
01697   
01698   end_builtin();
01699 }
01700 
01701 
01702 /*** RM 8/12/82 END ***/
01703 
01704 
01705 
01706 
01707 
01708 /*****************************************************************/
01709 /******** xcClearWindow
01710   
01711   xcClearWindow(+Connection,+Window)
01712   
01713   clear the Window on the display Connection.
01714   
01715   */
01716 
01717 long xcClearWindow()
01718      
01719 {
01720   include_var_builtin(2);
01721   ptr_definition types[2];
01722   
01723   
01724   types[0] = real;
01725   types[1] = xwindow;
01726   
01727   begin_builtin(xcClearWindow,2,2,types);
01728   
01729   XClearWindow(DISP(0),WIND(1));
01730 XSync(DISP(0),0);
01731   
01732   x_free_display_list(WindowDisplayList(args[1]));
01733   success = TRUE;
01734   
01735   end_builtin();
01736 }
01737 
01738 
01739 
01740 /*****************************************************************/
01741 /******** xcResizeWindowPixmap
01742   
01743   xcResizeWindowPixmap(+Display,+Window,+Width,+Height)
01744   
01745   resize the pixmap of the window,useful when we caught the resize event
01746   eg: the window is resized manualy.
01747   
01748   */
01749 
01750 long xcResizeWindowPixmap()
01751      
01752 {
01753   include_var_builtin(4);
01754   ptr_definition types[4];
01755   long j;
01756   
01757   
01758   for(j=0; j<4; j++)
01759     types[j] = real;
01760   types[1] = xdrawable;
01761   
01762   begin_builtin(xcResizeWindowPixmap,4,4,types);
01763   
01764   /* modify the pixmap */
01765   ResizePixmap(args[1],val[0],val[1],val[2],val[3]);
01766   
01767   success = TRUE;
01768   
01769   end_builtin();
01770 }
01771 
01772 
01773 
01774 /*****************************************************************/
01775 /******** xcSelectInput
01776   
01777   xcSelectInput(+Connection,+Window,+Mask)
01778   
01779   select the desired event types
01780   
01781   */
01782 
01783 long xcSelectInput()
01784      
01785 {
01786   include_var_builtin(3);
01787   ptr_definition types[3];
01788   
01789   
01790   types[0] = real;
01791   types[1] = real;
01792   types[2] = real;
01793   
01794   begin_builtin(xcSelectInput,3,3,types);
01795   
01796   XSelectInput(DISP(0),WIND(1),val[2]);
01797   success = TRUE;
01798   
01799   end_builtin();
01800 }
01801 
01802 
01803 
01804 /*****************************************************************/
01805 /******** xcRefreshWindow
01806   
01807   
01808   xcRefreshWindow(+Connection,+Window)
01809   
01810   refresh the window
01811   
01812   */
01813 
01814 long xcRefreshWindow()
01815      
01816 {
01817   include_var_builtin(2);
01818   ptr_definition types[2];
01819   Pixmap pixmap;
01820   ptr_psi_term psiPixmap;
01821   
01822   
01823   types[0] = real;
01824   types[1] = xwindow;
01825   
01826   begin_builtin(xcRefreshWindow,2,2,types);
01827   
01828   psiPixmap = GetPsiAttr(args[1],"pixmap");
01829   if((pixmap =(Pixmap) GetIntAttr(psiPixmap,"id")) != 0)
01830     x_refresh_window(val[0],val[1],pixmap,
01831                       DrawableGC(psiPixmap),
01832                       WindowDisplayList(args[1]));
01833   else
01834     x_refresh_window(val[0],val[1],val[1],
01835                       DrawableGC(args[1]),
01836                       WindowDisplayList(args[1]));
01837   
01838   success = TRUE;
01839   
01840   end_builtin();
01841 }
01842 
01843 
01844 
01845 /*****************************************************************/
01846 /******** xcPostScriptWindow
01847   
01848   
01849   xcPostScriptWindow(+Display,+Window,Filename)
01850   
01851   output the contents of the window in Filename
01852   
01853   */
01854 
01855 long xcPostScriptWindow()
01856      
01857 {
01858   include_var_builtin(3);
01859   ptr_definition types[3];
01860   
01861   
01862   types[0] = real;
01863   types[1] = xwindow;
01864   types[2] = quoted_string;
01865   
01866   begin_builtin(xcPostScriptWindow,3,3,types);
01867   
01868   success = x_postscript_window(val[0],val[1],
01869                                  GetIntAttr(GetPsiAttr(args[1],"display_list"),
01870                                              "id"),
01871                                  val[2]);
01872   
01873   end_builtin();
01874 }
01875 
01876 
01877 
01878 /*****************************************************************/
01879 /******** xcDestroyWindow
01880   
01881   
01882   xcDestroyWindow(+Connection,+Window)
01883   
01884   Close and destroy the window(unbacktrable).
01885   
01886   */
01887 
01888 long xcDestroyWindow()
01889      
01890 {
01891   include_var_builtin(2);
01892   ptr_definition types[2];
01893   ptr_psi_term psi;
01894   
01895   types[0] = real;
01896   types[1] = xwindow;
01897   
01898   begin_builtin(xcDestroyWindow,2,2,types);
01899   
01900   psi = GetPsiAttr(args[1],"permanent");
01901   if(!strcmp(psi->type->keyword->symbol,"true"))
01902     {
01903       Errorline("cannot destroy a permanent window.\n");
01904       exit_life(TRUE); /* was: main_loop_ok=FALSE; - jch */
01905       success = FALSE;
01906     }
01907   else
01908     {
01909       FreeWindow(val[0],args[1]);
01910       XDestroyWindow(DISP(0),WIND(1));
01911 XSync(DISP(0),0);
01912       clean_undo_window(DISP(0),WIND(1));
01913       success = TRUE;
01914     }
01915   
01916   end_builtin();
01917 }
01918 
01919 
01920 
01921 /*****************************************************************/
01922 /******** CREATEGC
01923   
01924   xcCreateGC(+Connection,+Drawable,-GC)
01925   
01926   create a graphic context.
01927   
01928   */
01929 
01930 long xcCreateGC()
01931      
01932 {
01933   include_var_builtin(3);
01934   ptr_definition types[3];
01935   GC gc;
01936   XGCValues GCvalues;
01937   
01938   
01939   types[0] = real;
01940   types[1] = xdrawable;
01941   types[2] = real;
01942   
01943   begin_builtin(xcCreateGC,3,2,types);
01944   
01945   if(gc = XCreateGC(DISP(0),WIND(1),0,&GCvalues))  /* RM: Feb  7 1994 */
01946     {
01947       unify_real_result(args[2],(REAL)(unsigned long) gc);
01948       success = TRUE;
01949     }
01950   else
01951     {
01952       Errorline("could not create gc in %P.\n",g);
01953       success = FALSE;
01954     }
01955   
01956   end_builtin();
01957 }
01958 
01959 
01960 
01961 /*****************************************************************/
01962 /******** GETGCATTRIBUTE */
01963 
01964 static long GetGCAttribute(gc,attributeId,attribute)
01965      
01966      GC gc;
01967      long attributeId,*attribute;
01968      
01969 {
01970 #ifndef __alpha
01971   switch(attributeId) 
01972     {
01973     case 0:
01974       *attribute = gc->values.function;
01975       break;
01976     case 1:
01977       *attribute = gc->values.plane_mask;
01978       break;
01979     case 2:
01980       *attribute = gc->values.foreground;
01981       break;
01982     case 3:
01983       *attribute = gc->values.background;
01984       break;
01985     case 4:
01986       *attribute = gc->values.line_width;
01987       break;
01988     case 5:
01989       *attribute = gc->values.line_style;
01990       break;
01991     case 6:
01992       *attribute = gc->values.cap_style;
01993       break;
01994     case 7:
01995       *attribute = gc->values.join_style;
01996       break;
01997     case 8:
01998       *attribute = gc->values.fill_style;
01999       break;
02000     case 9:
02001       *attribute = gc->values.fill_rule;
02002       break;
02003     case 10:
02004       *attribute = gc->values.tile;
02005       break;
02006     case 11:
02007       *attribute = gc->values.stipple;
02008       break;
02009     case 12:
02010       *attribute = gc->values.ts_x_origin;
02011       break;
02012     case 13:
02013       *attribute = gc->values.ts_y_origin;
02014       break;
02015     case 14:
02016       *attribute = gc->values.font;
02017       break;
02018     case 15:
02019       *attribute = gc->values.subwindow_mode;
02020       break;
02021     case 16:
02022       *attribute = gc->values.graphics_exposures;
02023       break;
02024     case 17:
02025       *attribute = gc->values.clip_x_origin;
02026       break;
02027     case 18:
02028       *attribute = gc->values.clip_y_origin;
02029       break;
02030     case 19:
02031       *attribute = gc->values.clip_mask;
02032       break;
02033     case 20:
02034       *attribute = gc->values.dash_offset;
02035       break;
02036     case 21: 
02037       *attribute =(unsigned char)(gc->values.dashes);
02038       break;
02039     case 22:
02040       *attribute = gc->values.arc_mode;
02041       break;
02042     case 23:
02043       *attribute = gc->rects;
02044       break;
02045     case 24:
02046       *attribute = gc->dashes;
02047       break;
02048     default: 
02049       return FALSE;
02050       break;
02051     }
02052 #endif
02053   return TRUE;
02054 }
02055 
02056 
02057 /*****************************************************************/
02058 /******** GETGCATTRIBUTE
02059   
02060   xcGetGCAttribute(+GC,+AttributeId,-Val)
02061   
02062   get the value of the attribute id of GC.
02063   
02064   */
02065 
02066 long xcGetGCAttribute()
02067      
02068 {
02069   include_var_builtin(3);
02070   ptr_definition types[3];
02071   long attr;
02072   
02073   
02074   types[0] = real;
02075   types[1] = real;
02076   types[2] = real;
02077   
02078   begin_builtin(xcGetGCAttribute,3,2,types);
02079   
02080   if(GetGCAttribute(DISP(0),GCVAL(1),&attr))
02081     {
02082       unify_real_result(args[2],(REAL) attr);
02083       success = TRUE;
02084     }
02085   else
02086     {
02087       Errorline("could not get gc attribute in %P.\n",g);
02088       success = FALSE;
02089     }
02090   
02091   end_builtin();
02092 }
02093 
02094 
02095 
02096 /*****************************************************************/
02097 /******** SETGCATTRIBUTE */
02098 
02099 static long SetGCAttribute(display,gc,attributeId,attribute)
02100      
02101      Display *display;
02102      GC gc;
02103      long attributeId,attribute;
02104      
02105 {
02106   XGCValues attributes;
02107   unsigned long attributesMask = 0;
02108   
02109   
02110   switch(attributeId) 
02111     {
02112     case 0:
02113       attributes.function = attribute;
02114       attributesMask |= GCFunction;
02115       break;
02116     case 1:
02117       attributes.plane_mask = attribute;
02118       attributesMask |= GCPlaneMask;
02119       break;
02120     case 2:
02121       attributes.foreground = attribute;
02122       attributesMask |= GCForeground;
02123       break;
02124     case 3:
02125       attributes.background = attribute;
02126       attributesMask |= GCBackground;
02127       break;
02128     case 4:
02129       attributes.line_width = attribute;
02130       attributesMask |= GCLineWidth;
02131       break;
02132     case 5:
02133       attributes.line_style = attribute;
02134       attributesMask |= GCLineStyle;
02135       break;
02136     case 6:
02137       attributes.cap_style = attribute;
02138       attributesMask |= GCCapStyle;
02139       break;
02140     case 7:
02141       attributes.join_style = attribute;
02142       attributesMask |= GCJoinStyle;
02143       break;
02144     case 8:
02145       attributes.fill_style = attribute;
02146       attributesMask |= GCFillStyle;
02147       break;
02148     case 9:
02149       attributes.fill_rule = attribute;
02150       attributesMask |= GCFillRule;
02151       break;
02152     case 10:
02153       attributes.tile = attribute;
02154       attributesMask |= GCTile;
02155       break;
02156     case 11:
02157       attributes.stipple = attribute;
02158       attributesMask |= GCStipple;
02159       break;
02160     case 12:
02161       attributes.ts_x_origin = attribute;
02162       attributesMask |= GCTileStipXOrigin;
02163       break;
02164     case 13:
02165       attributes.ts_y_origin = attribute;
02166       attributesMask |= GCTileStipYOrigin;
02167       break;
02168     case 14:
02169       attributes.font = attribute;
02170       attributesMask |= GCFont;
02171       break;
02172     case 15:
02173       attributes.subwindow_mode = attribute;
02174       attributesMask |= GCSubwindowMode;
02175       break;
02176     case 16:
02177       attributes.graphics_exposures = attribute;
02178       attributesMask |= GCGraphicsExposures;
02179       break;
02180     case 17:
02181       attributes.clip_x_origin = attribute;
02182       attributesMask |= GCClipXOrigin;
02183       break;
02184     case 18:
02185       attributes.clip_y_origin = attribute;
02186       attributesMask |= GCClipYOrigin;
02187       break;
02188     case 19:
02189       attributes.clip_mask = attribute;
02190       attributesMask |= GCClipMask;
02191       break;
02192     case 20:
02193       attributes.dash_offset = attribute;
02194       attributesMask |= GCDashOffset;
02195       break;
02196     case 21: 
02197       attributes.dashes =(char)(0xFF & attribute);
02198       attributesMask |= GCDashList;
02199       break;
02200     case 22:
02201       attributes.arc_mode = attribute;
02202       attributesMask |= GCArcMode;
02203       break;
02204     default: 
02205       return FALSE;
02206       break;
02207     }
02208   
02209   XChangeGC(display,gc,attributesMask,&attributes);
02210   return TRUE;
02211 }
02212 
02213 
02214 /*****************************************************************/
02215 /******** SETGCATTRIBUTE
02216   
02217   xcSetGCAttribute(+Display,+GC,+AttributeId,+Val)
02218   
02219   set the value of the attribute id of GC.
02220   
02221   */
02222 
02223 long xcSetGCAttribute()
02224      
02225 {
02226   include_var_builtin(4);
02227   ptr_definition types[4];
02228   
02229   
02230   types[0] = real;
02231   types[1] = real;
02232   types[2] = real;
02233   types[3] = real;
02234   
02235   begin_builtin(xcSetGCAttribute,4,4,types);
02236   
02237   if(SetGCAttribute(DISP(0),GCVAL(1),val[2],val[3]))
02238     success = TRUE;
02239   else
02240     {
02241       Errorline("could not set gc attribute in %P.\n",g);
02242       success = FALSE;
02243     }
02244   
02245   end_builtin();
02246 }
02247 
02248 
02249 
02250 /*****************************************************************/
02251 /******** DESTROYGC
02252   
02253   xcDestroyGC(+Connection,+GC)
02254   
02255   destroys a graphic context.
02256   
02257   */
02258 
02259 long xcDestroyGC()
02260      
02261 {
02262   include_var_builtin(2);
02263   ptr_definition types[2];
02264   
02265   
02266   types[0] = real;
02267   types[1] = real;
02268   
02269   begin_builtin(xcDestroyGC,2,2,types);
02270   
02271   XFreeGC(DISP(0),GCVAL(1));
02272   success = TRUE;
02273   
02274   end_builtin();
02275 }
02276 
02277 /*****************************************************************/
02278 /******** REQUESTCOLOR
02279   
02280   xcRequestColor(+Connection,+ColorMap,+Red,+Green,+Blue,-Pixel)
02281   
02282   get the closest color to(Red,Green,Blue) in the ColorMap
02283   
02284   */
02285 
02286 long xcRequestColor()
02287      
02288 {
02289   include_var_builtin(6);
02290   ptr_definition types[6];
02291   long j;
02292   XColor color;
02293   
02294   
02295   for(j=0; j<6; j++)
02296     types[j] = real;
02297   
02298   begin_builtin(xcRequestColor,6,5,types);
02299   
02300   color.red =(val[2]) << 8;
02301   color.green =(val[3]) << 8;
02302   color.blue =(val[4]) << 8;
02303   color.flags = DoRed|DoGreen|DoBlue;
02304   
02305   if(XAllocColor(DISP(0),CMAP(1),&color))
02306     {
02307       unify_real_result(args[5],(REAL) color.pixel);
02308       success = TRUE;
02309     }
02310   else
02311     {
02312       Errorline("could not request a color in %P.\n",g);
02313       success = FALSE;
02314     }
02315   
02316   end_builtin();
02317 }
02318 
02319 
02320 /*****************************************************************/
02321 /******** REQUESTNAMEDCOLOR
02322   
02323   xcRequestNamedColor(+Connection,+ColorMap,+Name,-Pixel)
02324   
02325   get the color corresponding to Name in the ColorMap
02326   
02327   */
02328 
02329 long xcRequestNamedColor()
02330      
02331 {
02332   include_var_builtin(4);
02333   ptr_definition types[4];
02334   long j;
02335   XColor cell,rgb;
02336   
02337   types[0] = real;
02338   types[1] = real;
02339   types[2] = quoted_string;
02340   types[3] = real;
02341   
02342   begin_builtin(xcRequestNamedColor,4,3,types);
02343   
02344   if(XAllocNamedColor(DISP(0),CMAP(1),STRG(2),&cell,&rgb))
02345     {
02346       unify_real_result(args[3],(REAL) cell.pixel);
02347       success = TRUE;
02348     }
02349   else
02350     {
02351       Errorline("could not request a named color in %P.\n",g);
02352       success = FALSE;
02353     }
02354   
02355   end_builtin();
02356 }
02357 
02358 
02359 /*****************************************************************/
02360 /******** FREECOLOR
02361   
02362   xcFreeColor(+Connection,+ColorMap,+Pixel)
02363   
02364   free the color in the colormap
02365   
02366   */
02367 
02368 long xcFreeColor()
02369      
02370 {
02371   include_var_builtin(3);
02372   ptr_definition types[3];
02373   long j;
02374   unsigned long pixel;
02375   
02376   
02377   for(j=0; j<3; j++)
02378     types[j] = real;
02379   
02380   begin_builtin(xcFreeColor,3,3,types);
02381   
02382   pixel = val[2];
02383   XFreeColors(DISP(0),CMAP(1),&pixel,1,0);
02384   success = TRUE;
02385   
02386   end_builtin();
02387 }
02388 
02389 
02390 /*****************************************************************/
02391 /******** DrawLine
02392   
02393   xcDrawLine(+Connection,+Drawable,+X0,+Y0,+X1,+Y1,
02394   +Function,+Color,+LineWidth)
02395   
02396   draw a line(X0,Y0) ->(X1,Y1)
02397   
02398   */
02399 
02400 long xcDrawLine()
02401      
02402 {
02403   include_var_builtin(9);
02404   ptr_definition types[9];
02405   long j;
02406   GC gc;
02407   
02408   
02409   for(j = 0; j < 9; j++)
02410     types[j] = real;
02411   types[1] = xdrawable;
02412   
02413   begin_builtin(xcDrawLine,9,9,types);
02414   
02415   gc = DrawableGC(args[1]);
02416   x_set_gc(val[0],gc,val[6],val[7],val[8],xDefaultFont);
02417   
02418   XDrawLine(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
02419              val[2],val[3],val[4],val[5]);         /* X0,Y0,X1,Y1 */
02420   
02421   x_record_line(WindowDisplayList(args[1]),DRAW_LINE,
02422                  val[2],val[3],val[4],val[5],
02423                  val[6],val[7],val[8]);
02424   
02425 XSync(DISP(0),0);
02426   success = TRUE;
02427   
02428   end_builtin();
02429 }
02430 
02431 /*****************************************************************/
02432 /******** DrawArc
02433   
02434   xcDrawArc(+Connection,+Drawable,+X,+Y,+Width,+Height,+StartAngle,+ArcAngle,
02435   +Function,+Color,+LineWidth)
02436   
02437   draw arc(see X Vol.2 page 135 for the meanings of the arguments).
02438   
02439   */
02440 
02441 long xcDrawArc()
02442      
02443 {
02444   include_var_builtin(11);
02445   ptr_definition types[11];
02446   long j;
02447   GC gc;
02448   
02449   
02450   for(j = 0; j < 11; j++)
02451     types[j] = real;
02452   types[1] = xdrawable;
02453   
02454   begin_builtin(xcDrawArc,11,11,types);
02455   
02456   gc = DrawableGC(args[1]);
02457   x_set_gc(val[0],gc,val[8],val[9],val[10],xDefaultFont);
02458   
02459   XDrawArc(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
02460             val[2],val[3],val[4],val[5],         /* X,Y,Width,Height */
02461             val[6],val[7]);                         /* StartAngle,ArcAngle */
02462   
02463   x_record_arc(WindowDisplayList(args[1]),DRAW_ARC,
02464                 val[2],val[3],val[4],val[5],
02465                 val[6],val[7],val[8],val[9],val[10]);
02466   
02467 XSync(DISP(0),0);
02468   success = TRUE;
02469   
02470   end_builtin();
02471 }
02472 
02473 
02474 /*****************************************************************/
02475 /******** DrawRectangle
02476   
02477   xcDrawRectangle(+Connection,+Drawable,+X,+Y,+Width,+Height,
02478   +Function,+Color,+LineWidth)
02479   
02480   draw a rectangle.
02481   
02482   */
02483 
02484 long xcDrawRectangle()
02485      
02486 {
02487   include_var_builtin(9);
02488   ptr_definition types[9];
02489   long j;
02490   GC gc;
02491   
02492   
02493   for(j = 0; j < 9; j++)
02494     types[j] = real;
02495   types[1] = xdrawable;
02496   
02497   begin_builtin(xcDrawRectangle,9,9,types);
02498   
02499   gc = DrawableGC(args[1]);
02500   x_set_gc(val[0],gc,val[6],val[7],val[8],xDefaultFont);
02501   
02502   XDrawRectangle(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
02503                   val[2],val[3],val[4],val[5]);         /* X,Y,Width,Height */
02504   
02505   x_record_rectangle(WindowDisplayList(args[1]),DRAW_RECTANGLE,
02506                       val[2],val[3],val[4],val[5],
02507                       val[6],val[7],val[8]);
02508   
02509 XSync(DISP(0),0);
02510   success = TRUE;
02511   
02512   end_builtin();
02513 }
02514 
02515 
02516 /*****************************************************************/
02517 /******** FillRectangle
02518   
02519   xcFillRectangle(+Connection,+Drawable,+X,+Y,+Width,+Height,
02520   +Function,+Color)
02521   
02522   fill a rectangle.
02523   
02524   */
02525 
02526 long xcFillRectangle()
02527      
02528 {
02529   include_var_builtin(8);
02530   ptr_definition types[8];
02531   long j;
02532   GC gc;
02533   
02534   
02535   for(j = 0; j < 8; j++)
02536     types[j] = real;
02537   types[1] = xdrawable;
02538   
02539   begin_builtin(xcFillRectangle,8,8,types);
02540   
02541   gc = DrawableGC(args[1]);
02542   x_set_gc(val[0],gc,val[6],val[7],xDefaultLineWidth,xDefaultFont); 
02543   
02544   XFillRectangle(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
02545                   val[2],val[3],val[4],val[5]);         /* X,Y,Width,Height */
02546   
02547   x_record_rectangle(WindowDisplayList(args[1]),FILL_RECTANGLE,
02548                       val[2],val[3],val[4],val[5],
02549                       val[6],val[7],
02550                       xDefaultLineWidth);
02551   
02552 XSync(DISP(0),0);
02553   success = TRUE;
02554   
02555   end_builtin();
02556 }
02557 
02558 
02559 /*****************************************************************/
02560 /******** FillArc
02561   
02562   xcFillArc(+Connection,+Drawable,+X,+Y,+Width,+Height,+StartAngle,+ArcAngle,
02563   +Function,+Color)
02564   fill an arc.
02565   
02566   */
02567 
02568 long xcFillArc()
02569      
02570 {
02571   include_var_builtin(10);
02572   ptr_definition types[10];
02573   long j;
02574   GC gc;
02575   
02576   
02577   for(j = 0; j < 10; j++)
02578     types[j] = real;
02579   types[1] = xdrawable;
02580   
02581   begin_builtin(xcFillArc,10,10,types);
02582   
02583   gc = DrawableGC(args[1]);
02584   x_set_gc(val[0],gc,val[8],val[9],xDefaultLineWidth,xDefaultFont);
02585   
02586   XFillArc(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
02587             val[2],val[3],val[4],val[5],         /* X,Y,Width,Height */
02588             val[6],val[7]);                         /* StartAngle,ArcAngle */
02589   
02590   x_record_arc(WindowDisplayList(args[1]),FILL_ARC,
02591                 val[2],val[3],val[4],val[5],
02592                 val[6],val[7],val[8],val[9],
02593                 xDefaultLineWidth);
02594   
02595 XSync(DISP(0),0);
02596   success = TRUE;
02597   
02598   end_builtin();
02599 }
02600 
02601 
02602 /*****************************************************************/
02603 /******** PointsAlloc
02604   
02605   xcPointsAlloc(+NbPoints,-Points)
02606   
02607   allocate n points
02608   */
02609 
02610 long xcPointsAlloc()
02611      
02612 {
02613   include_var_builtin(2);
02614   ptr_definition types[2];
02615   long Points;
02616   
02617   
02618   types[0] = real;
02619   types[1] = real;
02620   
02621   begin_builtin(xcPointsAlloc,2,1,types);
02622   Points =(long) malloc((val [0]) * 2 * sizeof(short));
02623   unify_real_result(args[1],(REAL) Points);
02624   
02625   success = TRUE;
02626   
02627   end_builtin();
02628 }
02629 
02630 
02631 /*****************************************************************/
02632 /******** CoordPut
02633   
02634   xcCoordPut(+Points,+N,+Coord)
02635   
02636   put nth coordinate in Points
02637   */
02638 
02639 long xcCoordPut()
02640      
02641 {
02642   include_var_builtin(3);
02643   ptr_definition types[3];
02644   short *Points;
02645   
02646   types[0] = real;
02647   types[1] = real;
02648   types[2] = real;
02649   
02650   begin_builtin(xcCoordPut,3,3,types);
02651   
02652   Points =(short *) val [0];
02653   Points += val[1];
02654   *Points = val[2];
02655   
02656   success = TRUE;
02657   
02658   end_builtin();
02659 }
02660 
02661 
02662 /*****************************************************************/
02663 /******** PointsFree
02664   
02665   xcPointsFree(+Points)
02666   
02667   free points
02668   */
02669 
02670 long xcPointsFree()
02671      
02672 {
02673   include_var_builtin(1);
02674   ptr_definition types[1];
02675   
02676   
02677   types[0] = real;
02678   
02679   begin_builtin(xcPointsFree,1,1,types);
02680   free((void *)val [0]);
02681   success = TRUE;
02682   
02683   end_builtin();
02684 }
02685 
02686 
02687 /*****************************************************************/
02688 /******** DrawPolygon
02689   
02690   xcDrawPolygon(+Connection,+Drawable,+Points,+NbPoints,
02691   +Function,+Color,+LineWidth)
02692   
02693   draw a polygon.
02694   
02695   */
02696 
02697 long xcDrawPolygon()
02698      
02699 {
02700   include_var_builtin(7);
02701   ptr_definition types[7];
02702   long j;
02703   GC gc;
02704   
02705   
02706   for(j = 0; j < 7; j++)
02707     types[j] = real;
02708   types[1] = xdrawable;
02709   
02710   begin_builtin(xcDrawPolygon,7,7,types);
02711   
02712   gc = DrawableGC(args[1]);
02713   x_set_gc(val[0],gc,val[4],val[5],val[6],xDefaultFont); 
02714   
02715   XDrawLines(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
02716              (XPoint *)val[2],val[3],CoordModeOrigin);        /* Points,NbPoints,mode */
02717   
02718   x_record_polygon(WindowDisplayList(args[1]),DRAW_POLYGON,
02719                     val[2],val[3],val[4],val[5],val[6]);
02720   
02721 XSync(DISP(0),0);
02722   success = TRUE;
02723   
02724   end_builtin();
02725 }
02726 
02727 
02728 /*****************************************************************/
02729 /******** FillPolygon
02730   
02731   xcFillPolygon(+Connection,+Drawable,+Points,+NbPoints,+Function,+Color)
02732   
02733   fill a polygon.
02734   
02735   */
02736 
02737 long xcFillPolygon()
02738      
02739 {
02740   include_var_builtin(6);
02741   ptr_definition types[6];
02742   long j;
02743   GC gc;
02744   
02745   
02746   for(j = 0; j < 6; j++)
02747     types[j] = real;
02748   types[1] = xdrawable;
02749   
02750   begin_builtin(xcFillPolygon,6,6,types);
02751   
02752   gc = DrawableGC(args[1]);
02753   x_set_gc(val[0],gc,val[4],val[5],xDefaultLineWidth,xDefaultFont); 
02754   
02755   XFillPolygon(DISP(0),(Window) val[1],gc,/* Display,Window,GC */
02756                (XPoint *)val[2],val[3],   /* Points,NbPoints */
02757                Complex,CoordModeOrigin);  /* shape,mode */
02758   
02759   x_record_polygon(WindowDisplayList(args[1]),FILL_POLYGON,
02760                     val[2],val[3],val[4],val[5],
02761                     xDefaultLineWidth);
02762   
02763   XSync(DISP(0),0);
02764   success = TRUE;
02765   
02766   end_builtin();
02767 }
02768 
02769 
02770 /*****************************************************************/
02771 /******** LoadFont
02772   
02773   xcLoadFont(+Connection,+Name,-Font)
02774   
02775   load a font.
02776   
02777   */
02778 
02779 long xcLoadFont()
02780      
02781 {
02782   include_var_builtin(3);
02783   ptr_definition types[3];
02784   Font font;
02785   
02786   
02787   types[0] = real;
02788   types[1] = quoted_string;
02789   types[2] = real;
02790   
02791   begin_builtin(xcLoadFont,3,2,types);
02792   
02793   if(font=XLoadFont(DISP(0),STRG(1)))
02794     {
02795       unify_real_result(args[2],(REAL) font);
02796       XSync(DISP(0),0);
02797       success = TRUE;
02798     }
02799   else
02800     {
02801       Errorline("could not load a font in %P.\n",g);
02802       success = FALSE;
02803     }
02804   
02805   end_builtin();
02806 }
02807 
02808 
02809 
02810 /*****************************************************************/
02811 /******** UnloadFont
02812   
02813   xcUnloadFont(+Connection,+Font)
02814   
02815   unload a font.
02816   
02817   */
02818 
02819 long xcUnloadFont()
02820      
02821 {
02822   include_var_builtin(2);
02823   ptr_definition types[2];
02824   
02825   
02826   types[0] = real;
02827   types[1] = real;
02828   
02829   begin_builtin(xcUnloadFont,2,2,types);
02830   
02831   XUnloadFont(DISP(0),FONT(1));
02832   XSync(DISP(0),0);
02833   success = TRUE;
02834   
02835   end_builtin();
02836 }
02837 
02838 
02839 
02840 /*****************************************************************/
02841 /******** DrawString
02842   
02843   xcDrawString(+Connection,+Drawable,+X,+Y,String,
02844   +Font,+Function,+Color)
02845   
02846   Print the string(only foreground).
02847   
02848   */
02849 
02850 long xcDrawString()
02851 {
02852   include_var_builtin(8);
02853   ptr_definition types[8];
02854   long j;
02855   GC gc;
02856   
02857   
02858   for(j = 0; j < 8; j++)
02859     types[j] = real;
02860   types[1] = xdrawable;
02861   types[4] = quoted_string;
02862   
02863   begin_builtin(xcDrawString,8,8,types);
02864   
02865   gc = DrawableGC(args[1]);
02866   x_set_gc(val[0],gc,val[6],val[7],xDefaultLineWidth,val[5]);
02867   
02868   XDrawString(DISP(0),(Window) val[1],gc, /* Display,Window,GC */
02869                val[2],val[3],STRG(4),                  /* X,Y *//* String */
02870                strlen(STRG(4)));                /* Length */
02871   
02872   x_record_string(WindowDisplayList(args[1]),DRAW_STRING,
02873                    val[2],val[3],      /* X,Y */
02874                   STRG(4),     /* String */
02875                    val[5],              /* Font */
02876                    val[6],val[7]);      /* Function,Color */
02877   
02878   XSync(DISP(0),0);
02879   success = TRUE;
02880   
02881   end_builtin();
02882 }
02883 
02884 
02885 /*****************************************************************/
02886 /******** DrawImageString
02887   
02888   xcDrawImageString(+Connection,+Drawable,+X,+Y,String,
02889   +Font,+Function,+Color)
02890   
02891   Print the string(foreground+background).
02892   
02893   */
02894 
02895 long xcDrawImageString()
02896 {
02897   include_var_builtin(8);
02898   ptr_definition types[8];
02899   long j;
02900   GC gc;
02901   
02902   
02903   for(j = 0; j < 8; j++)
02904     types[j] = real;
02905   types[1] = xdrawable;
02906   types[4] = quoted_string;
02907   
02908   begin_builtin(xcDrawImageString,8,8,types);
02909   
02910   gc = DrawableGC(args[1]);
02911   x_set_gc(val[0],gc,val[6],val[7],xDefaultLineWidth,val[5]);
02912   
02913   XDrawImageString(DISP(0),WIND(1),gc,          /* Display,Window,GC */
02914                     val[2],val[3],              /* X,Y */
02915                     STRG(4),                      /* String */
02916                     strlen(STRG(4)));    /* Length */
02917   
02918   x_record_string(WindowDisplayList(args[1]),DRAW_IMAGE_STRING,
02919                    val[2],val[3],               /* X,Y */
02920                   STRG(4),              /* String */
02921                    val[5],                       /* Font */
02922                    val[6],val[7]);               /* Function,Color */
02923   
02924   XSync(DISP(0),0);
02925   success = TRUE;
02926   
02927   end_builtin();
02928 }
02929 
02930 
02931 /*****************************************************************/
02932 /******** StringWidth
02933   
02934   xcStringWidth(+Connection,+Font,+String)
02935   
02936   
02937   returns the width in pixels of the string in the given font.
02938   
02939   */
02940 
02941 long xcStringWidth()
02942 {
02943   include_var_builtin(3);
02944   ptr_definition types[3];
02945   int direction,ascent,descent;
02946   XCharStruct overall;
02947   
02948   
02949   types[0] = real;
02950   types[1] = real;
02951   types[2] = quoted_string;
02952   
02953   begin_builtin(xcStringWidth,3,3,types);
02954   
02955   if(XQueryTextExtents(DISP(0),FONT(1),
02956                        STRG(2),strlen(STRG(2)),/* string,nbchars */
02957                        &direction,&ascent,&descent,&overall))
02958     {
02959       unify_real_result(aim->b,(REAL) overall.width);
02960       success = TRUE;
02961     }
02962   else
02963     {
02964       Errorline("bad font in %P.\n",g);
02965       success = FALSE;
02966     }
02967   
02968   end_builtin();
02969 }
02970 
02971 
02972 /*****************************************************************/
02973 /******** SYNC
02974   
02975   xcSync(+Connection,+Discard)
02976   
02977   flush the output of the connection.
02978   
02979   */
02980 
02981 long xcSync()
02982      
02983 {
02984   include_var_builtin(2);
02985   ptr_definition types[2];
02986   
02987   
02988   types[0] = real;
02989   types[1] = real;
02990   
02991   begin_builtin(xcSync,2,2,types);
02992   
02993   XSync(DISP(0),val[1]);
02994   success = TRUE;
02995   
02996   end_builtin();
02997 }
02998 
02999 
03000 
03001 /*****************************************************************/
03002 /******** EVENTtoPSITERM */
03003 
03004 static ptr_psi_term xcEventToPsiTerm(event)
03005      
03006      XEvent *event;
03007      
03008 {
03009   ptr_psi_term psiEvent,psi_str;
03010   KeySym keysym;
03011   char buffer[10];
03012   char tstr[2], *str;
03013 
03014   str=tstr;
03015   tstr[1]=0;
03016   
03017   psiEvent = stack_psi_term(4);
03018   bk_stack_add_int_attr(psiEvent,"display",event->xany.display);
03019   bk_stack_add_int_attr(psiEvent,"window",event->xany.window);
03020   
03021   switch(event->type) {
03022   case KeyPress:
03023   case KeyRelease:
03024     psiEvent->type = xkeyboard_event;
03025     bk_stack_add_int_attr(psiEvent,"x",event->xkey.x);
03026     bk_stack_add_int_attr(psiEvent,"y",event->xkey.y);
03027     bk_stack_add_int_attr(psiEvent,"state",event->xkey.state);
03028     
03029     buffer[0] = 0;
03030     *str = 0;
03031     XLookupString((XKeyEvent*)event,buffer,sizeof(buffer),&keysym,NULL);
03032     bk_stack_add_int_attr(psiEvent,"keycode",buffer[0]);
03033     if(keysym==XK_Return || keysym==XK_KP_Enter || keysym==XK_Linefeed)
03034       *str = CR;
03035     else
03036       if(keysym == XK_BackSpace || keysym == XK_Delete)
03037         *str = BS;
03038       else
03039         if(isascii(buffer[0]))
03040           /* if(isalnum(buffer[0]) || isspace(buffer[0])) 8.10 */
03041           *str = buffer[0];
03042     
03043     bk_stack_add_int_attr(psiEvent,"char",*str);
03044     break;
03045     
03046   case ButtonPress:
03047   case ButtonRelease:
03048     psiEvent->type = xbutton_event;
03049     bk_stack_add_int_attr(psiEvent,"x",event->xbutton.x);
03050     bk_stack_add_int_attr(psiEvent,"y",event->xbutton.y);
03051     bk_stack_add_int_attr(psiEvent,"x_root",event->xbutton.x_root);
03052     bk_stack_add_int_attr(psiEvent,"y_root",event->xbutton.y_root);
03053     bk_stack_add_int_attr(psiEvent,"state",event->xbutton.state);
03054     bk_stack_add_int_attr(psiEvent,"button",event->xbutton.button);
03055     break;
03056     
03057   case Expose:
03058     psiEvent->type = xexpose_event;
03059     bk_stack_add_int_attr(psiEvent,"width",event->xexpose.width);
03060     bk_stack_add_int_attr(psiEvent,"height",event->xexpose.height);
03061     break;
03062     
03063   case DestroyNotify:
03064     psiEvent->type = xdestroy_event;
03065     break;
03066     
03067     /*** RM 7/12/92 ***/
03068   case MotionNotify:
03069     psiEvent->type = xmotion_event;
03070     bk_stack_add_int_attr(psiEvent,"x",event->xbutton.x);
03071     bk_stack_add_int_attr(psiEvent,"y",event->xbutton.y);
03072     bk_stack_add_int_attr(psiEvent,"x_root",event->xbutton.x_root);
03073     bk_stack_add_int_attr(psiEvent,"y_root",event->xbutton.y_root);
03074     break;
03075     
03076   case ConfigureNotify:
03077     psiEvent->type = xconfigure_event;
03078     bk_stack_add_int_attr(psiEvent,"x",event->xconfigure.x);
03079     bk_stack_add_int_attr(psiEvent,"y",event->xconfigure.y);
03080     bk_stack_add_int_attr(psiEvent,"width",event->xconfigure.width);
03081     bk_stack_add_int_attr(psiEvent,"height",event->xconfigure.height);
03082     bk_stack_add_int_attr(psiEvent,"border_width",
03083                        event->xconfigure.border_width);
03084     break;
03085     /*** RM 7/12/92(END) ***/
03086     
03087     
03088     /*** RM: May 3rd 1993 ***/
03089   case EnterNotify:
03090     psiEvent->type = xenter_event;
03091     goto LeaveEnterCommon;
03092     
03093   case LeaveNotify:
03094     psiEvent->type = xleave_event;
03095     
03096   LeaveEnterCommon:
03097     bk_stack_add_int_attr(psiEvent,"root",     event->xcrossing.root);
03098     bk_stack_add_int_attr(psiEvent,"subwindow",event->xcrossing.subwindow);
03099     
03100     bk_stack_add_int_attr(psiEvent,"x",event->xcrossing.x);
03101     bk_stack_add_int_attr(psiEvent,"y",event->xcrossing.y);
03102     
03103     bk_stack_add_int_attr(psiEvent,"focus",event->xcrossing.focus);
03104     bk_stack_add_int_attr(psiEvent,"state",event->xcrossing.state);
03105     
03106     break;
03107     
03108     
03109   default:
03110     psiEvent->type = xmisc_event;
03111     bk_stack_add_int_attr(psiEvent,"event_type",event->type);
03112     break;
03113   }
03114   
03115   return psiEvent;
03116 }
03117 
03118 
03119 
03120 /*****************************************************************/
03121 
03122 /* some stuff to handle a list of psi-terms  */
03123 /*  RM: Dec 15 1992   Re-written to handle new list structure */
03124 
03125 
03126 
03127 /*  RM: Dec 15 1992   Test if a list is empty  */
03128 long list_is_nil(lst)
03129      
03130      ptr_psi_term(lst);
03131      
03132 {
03133   deref_ptr(lst);
03134   return lst->type==nil;
03135 }
03136 
03137 
03138 
03139 /*  RM: Dec 15 1992   Return the CDR of a list */
03140 ptr_psi_term list_cdr(lst)
03141      
03142      ptr_psi_term(lst);
03143 {
03144   ptr_psi_term car;
03145   ptr_psi_term cdr;
03146   
03147   
03148   deref_ptr(lst);
03149   if(lst->type==alist) {
03150     get_two_args(lst->attr_list,&car,&cdr);
03151     if(cdr) {
03152       deref_ptr(cdr);
03153       return cdr;
03154     }
03155   }
03156   
03157   Errorline("X event handling error in CDR(%P)\n",lst);
03158   return lst;
03159 }
03160 
03161 
03162 
03163 /*  RM: Dec 15 1992   Return the CAR of a list */
03164 ptr_psi_term list_car(lst)
03165      
03166      ptr_psi_term(lst);
03167 {
03168   ptr_psi_term car;
03169   ptr_psi_term cdr;
03170   
03171   
03172   deref_ptr(lst);
03173   if(lst->type==alist) {
03174     get_two_args(lst->attr_list,&car,&cdr);
03175     if(car) {
03176       deref_ptr(car);
03177       return car;
03178     }
03179   }
03180   
03181   Errorline("X event handling error in CAR(%P)\n",lst);
03182   return lst;
03183 }
03184 
03185 
03186 
03187 /*  RM: Dec 15 1992  Set the CAR of a list */
03188 void list_set_car(lst,value)
03189      
03190      ptr_psi_term lst;
03191      ptr_psi_term value;
03192 {
03193   deref_ptr(lst);
03194   stack_insert(featcmp,one,&(lst->attr_list),value);
03195 }
03196 
03197 
03198 /*  RM: Dec 15 1992  Set the CDR of a list */
03199 void list_set_cdr(lst,value)
03200      
03201      ptr_psi_term lst;
03202      ptr_psi_term value;
03203 {
03204   deref_ptr(lst);
03205   stack_insert(featcmp,two,&(lst->attr_list),value);
03206 }
03207 
03208 
03209 
03210 /*  RM: Dec 15 1992  Return the last element of a list */
03211 ptr_psi_term list_last_cdr(lst)
03212      
03213      ptr_psi_term lst;
03214 {
03215   while(!list_is_nil(lst))
03216     lst=list_cdr(lst);
03217   return lst;
03218 }
03219 
03220 
03221 
03222 /*  RM: Dec 15 1992  Append an element to a list,return the new CONS cell */
03223 ptr_psi_term append_to_list(lst,value)
03224      
03225      ptr_psi_term lst;
03226      ptr_psi_term value;
03227 {
03228   ptr_psi_term end;
03229   
03230   end=list_last_cdr(lst);
03231   push_ptr_value_global(psi_term_ptr,&(end->coref));
03232   end->coref=stack_cons(value,stack_nil());
03233   return end->coref;
03234 }
03235 
03236 
03237 /*  RM: Dec 15 1992
03238     Map a function,while TRUE,over the CONS cells of a list */
03239 long map_funct_over_list(lst,proc,closure)
03240      ptr_psi_term lst;
03241      long(*proc)();
03242      long *closure;
03243 {
03244   long notInterrupted=TRUE;
03245   
03246   while(notInterrupted && !list_is_nil(lst)) {
03247     notInterrupted =(*proc)(lst,closure);
03248     lst=list_cdr(lst);
03249   }
03250   
03251   return notInterrupted;
03252 }
03253 
03254 
03255 
03256 /*  RM: Dec 15 1992  Same thing,except map over the CARs of the list */
03257 long map_funct_over_cars(lst,proc,closure)
03258      ptr_psi_term lst;
03259      long(*proc)();
03260      long *closure;
03261 {
03262   ptr_psi_term cdr;
03263   int   notInterrupted = TRUE;
03264   
03265   while(notInterrupted && !list_is_nil(lst)) {
03266     /* save the next because the current could be removed
03267       (eg: xcFlushEvents) */
03268     
03269     cdr=list_cdr(lst);
03270     notInterrupted=(*proc)(list_car(lst),closure);
03271     lst=cdr;
03272   }
03273   
03274   return notInterrupted;
03275 }
03276 
03277 
03278 
03279 /*  RM: Dec 15 1992  Re-written for new lists */
03280 void list_remove_value(lst,value)
03281      
03282      ptr_psi_term lst;
03283      ptr_psi_term value;
03284 {
03285   ptr_psi_term car,cdr;
03286   long still_there=TRUE;
03287   
03288   deref_ptr(value);
03289   while(!list_is_nil(lst) && still_there) {
03290     car=list_car(lst);
03291     cdr=list_cdr(lst);
03292     if(car==value) {
03293       still_there=FALSE;
03294       push_ptr_value_global(psi_term_ptr,&(lst->coref));
03295       lst->coref=cdr;
03296     }
03297     lst=cdr;
03298   }
03299 }
03300 
03301 
03302 
03303 /*****************************************************************/
03304 /* Static */
03305 /* return FALSE if the events match */
03306 
03307 static long x_union_event(psiEvent,closure)
03308      
03309      ptr_psi_term psiEvent;
03310      EventClosure *closure;
03311      
03312 {
03313   return !((Display *)GetIntAttr(psiEvent,"display") == closure->display
03314            && (Window)GetIntAttr(psiEvent,"window") == closure->window
03315            &&(GetIntAttr(psiEvent,"mask") & closure->mask) != 0);
03316 }
03317 
03318 
03319 
03320 
03321 
03322 /*****************************************************************/
03323 /******** GetEvent
03324   
03325   xcGetEvent(+Display,+Window,+Mask)
03326   
03327   return an event matching the mask in the window.
03328   if no event residuate the call else return a null event.
03329   
03330   */
03331 
03332 long xcGetEvent()
03333      
03334 {
03335   include_var_builtin(3);
03336   ptr_definition types[3];
03337   XEvent event;
03338   ptr_psi_term psiEvent;
03339   ptr_psi_term eventElt;
03340   EventClosure eventClosure;
03341   ptr_psi_term result;
03342   
03343   
03344   types[0] = real;
03345   types[1] = xwindow;
03346   types[2] = real;
03347 
03348   result=aim->b;
03349   
03350   begin_builtin(xcGetEvent,3,3,types);
03351   
03352   if(!xevent_existing) {
03353         
03354     /* warning if a same event is already waiting */
03355     eventClosure.display =DISP(0);
03356     eventClosure.window  =WIND(1);
03357     eventClosure.mask    = val[2];
03358     if(!map_funct_over_cars(xevent_list,x_union_event,&eventClosure))
03359       Warningline("you have coinciding event handlers on the same window");
03360     
03361     /* transform the request into a psi-term */
03362     eventElt = stack_psi_term(4);
03363     bk_stack_add_int_attr(eventElt,"display",val[0]);
03364     bk_stack_add_int_attr(eventElt,"window",val[1]);
03365     bk_stack_add_int_attr(eventElt,"mask",val[2]);
03366 
03367     /* stack_insert(featcmp,"event",&(eventElt->attr_list),result); */
03368                    
03369     /* add the request in the list of waiting events */
03370     append_to_list(xevent_list,eventElt); /*  RM: Dec 15 1992  */
03371       
03372     /* residuate the call */
03373     residuate(eventElt);  /* RM: May  5 1993  */
03374     
03375     /* return a psi-term containing an `empty' event */
03376     /* psiEvent = stack_psi_term(4);
03377        psiEvent->type = xevent;  RM: May  5 1993  */
03378   }
03379   else {
03380     /* get the event built by x_exist_event */
03381     psiEvent = GetPsiAttr(xevent_existing,"event");
03382     push_ptr_value_global(psi_term_ptr,&xevent_existing);
03383     xevent_existing = NULL;
03384     push_goal(unify,psiEvent,aim->b,NULL); /*  RM: May  5 1993  */
03385   }
03386   
03387   /* push_goal(unify,psiEvent,aim->b,NULL);   RM: May  5 1993  */
03388   
03389   success = TRUE;
03390   
03391   end_builtin();
03392 }
03393 
03394 
03395 
03396 /*****************************************************************/
03397 /* Static */
03398 /* remove the event from the queue if matching */
03399 
03400 static long x_flush_event(eventElt,closure)
03401      ptr_psi_term eventElt;
03402      EventClosure *closure;
03403 {
03404   ptr_psi_term psiEvent;
03405   
03406   
03407   psiEvent = list_car(eventElt);
03408   if ((Display *)GetIntAttr(psiEvent,"display") == closure->display
03409        && (Window)GetIntAttr(psiEvent,"window") ==closure->window
03410        && (GetIntAttr(psiEvent,"mask") & closure->mask) != 0)
03411     {
03412       /* 9.10 */
03413       /* if(xevent_list == eventElt) */
03414       /*     push_ptr_value_global(psi_term_ptr,&xevent_list); */
03415       /* xevent_list = list_remove_value(xevent_list,psiEvent); */
03416       list_remove_value(xevent_list,psiEvent); /*  RM: Dec 15 1992  */
03417     }
03418   
03419   return TRUE;
03420 }
03421 
03422 
03423 /*****************************************************************/
03424 /******** FlushEvents
03425   
03426   xcFlushEvents(+Display,+Window,+Mask)
03427   
03428   flush all residuated events matching(display,window,mask).
03429   
03430   */
03431 
03432 long xcFlushEvents()
03433      
03434 {
03435   include_var_builtin(3);
03436   ptr_definition types[3];
03437   EventClosure eventClosure;
03438   
03439   
03440   types[0] = real;
03441   types[1] = xwindow;
03442   types[2] = real;
03443   
03444   begin_builtin(xcFlushEvents,3,3,types);
03445   
03446   eventClosure.display =DISP(0);
03447   eventClosure.window  = val[1];
03448   eventClosure.mask    = val[2];
03449   map_funct_over_list(xevent_list,x_flush_event,&eventClosure);
03450   
03451   success = TRUE;
03452   
03453   end_builtin();
03454 }
03455 
03456 #if 0
03457 
03458 /*****************************************************************/
03459 /******** xcSendEvent
03460   
03461   xcSendEvent(+Display,+Window,+Event)
03462   
03463   send the event to the specified window
03464   
03465   */
03466 
03467 long xcSendEvent()
03468      
03469 {
03470   include_var_builtin(3);
03471   ptr_definition types[3];
03472   XEvent event;
03473   ptr_psi_term psiEvent;
03474   ptr_node nodeAttr;
03475   ptr_psi_term psiValue;
03476   
03477   
03478   types[0] = real;
03479   types[1] = xwindow;
03480   types[2] = xevent;
03481   
03482   begin_builtin(xcSendEvent,3,3,types);
03483   
03484   if(xcPsiEventToEvent(val[2],&event))
03485     {
03486       XSendEvent(DISP(0),WIND(1),False,?,&event);
03487       success = TRUE;
03488     }
03489   else
03490     {
03491       Errorline("%P is not an event in %P.\n",val[2],g);
03492       success = FALSE;
03493     }
03494   
03495   end_builtin();
03496 }
03497 
03498 #endif
03499 
03500 
03501 /*** RM: 7/12/92 ***/
03502 
03503 /*****************************************************************/
03504 /******** xcQueryPointer
03505   
03506   xcQueryPointer(+Display,+Window,
03507   -root_return,  -child_return,
03508   -root_x_return,-root_y_return,
03509   -win_x_return, -win_y_return,
03510   -mask_return,  -same_screen)
03511   
03512   this predicate returns a psi-term containing loads of info about where the
03513   pointer is at. See 'XQueryPointer' for a complete definition(the boolean
03514   result of XQueryPointer is stored as 'same_screen'.
03515   */
03516 
03517 long xcQueryPointer()
03518      
03519 {
03520   include_var_builtin(10);
03521   ptr_definition types[10];
03522   Window root_return,child_return;
03523   int root_x_return,root_y_return;
03524   int win_x_return,win_y_return;
03525   unsigned int mask_return;
03526   long same_screen;
03527   long j;
03528   
03529   
03530   
03531   for(j=0; j<10; j++)
03532     types[j] = real;
03533   
03534   types[1] = xdrawable;
03535   
03536   begin_builtin(xcQueryPointer,10,2,types);
03537   
03538   
03539   same_screen=XQueryPointer(DISP(0),
03540                             WIND(1),
03541                             &root_return,  &child_return,
03542                             &root_x_return,&root_y_return,
03543                             &win_x_return, &win_y_return,
03544                             &mask_return);
03545   
03546   
03547   unify_real_result(args[2],(REAL)root_return);
03548   unify_real_result(args[3],(REAL)child_return);
03549   unify_real_result(args[4],(REAL)root_x_return);
03550   unify_real_result(args[5],(REAL)root_y_return);
03551   unify_real_result(args[6],(REAL)win_x_return);
03552   unify_real_result(args[7],(REAL)win_y_return);
03553   unify_real_result(args[8],(REAL)mask_return);
03554   unify_real_result(args[9],(REAL)same_screen);
03555   
03556   /* printf("root: %ld\nchild: %ld\n",root_return,child_return); */
03557   
03558   success = TRUE;
03559   
03560   end_builtin();
03561 }
03562 
03563 /*** RM: 7/12/92(END) ***/
03564 
03565 
03566   
03567 
03568 /*****************************************************************/
03569 /******** SETUPBUILTINS
03570   
03571   Set up the X built-in predicates.
03572   
03573   */
03574 
03575 void x_setup_builtins()
03576      
03577 {
03578   set_current_module(x_module); /*  RM: Feb  3 1993  */
03579   
03580   raw_setup_builtins(); /* to move in life.c */
03581   
03582   XSetErrorHandler(x_handle_error);
03583   XSetIOErrorHandler(x_handle_fatal_error);
03584   
03585   set_current_module(x_module); /*  RM: Feb  3 1993  */
03586   xevent = update_symbol(x_module,"event");
03587   xkeyboard_event = update_symbol(x_module,"keyboard_event");
03588   xbutton_event = update_symbol(x_module,"button_event");
03589   xexpose_event = update_symbol(x_module,"expose_event");
03590   xdestroy_event = update_symbol(x_module,"destroy_event");
03591   
03592   /*** RM: 7/12/92 ***/
03593   xconfigure_event = update_symbol(x_module,"configure_event");
03594   xmotion_event = update_symbol(x_module,"motion_event");
03595   /*** RM: 7/12/92 ***/
03596   
03597   
03598   /*** RM: 3 May 92 ***/
03599   xenter_event = update_symbol(x_module,"enter_event");
03600   xleave_event = update_symbol(x_module,"leave_event");
03601   xmisc_event  = update_symbol(x_module,"misc_event");
03602   
03603   /*** RM: 3 May 92 ***/
03604   
03605   xdisplay = update_symbol(x_module,"display");
03606   xdrawable = update_symbol(x_module,"drawable");
03607   xwindow = update_symbol(x_module,"window");
03608   xpixmap = update_symbol(x_module,"pixmap");
03609   
03610   xgc = update_symbol(x_module,"graphic_context");
03611   xdisplaylist = update_symbol(x_module,"display_list");
03612   
03613   new_built_in(x_module,"xcOpenConnection",       predicate,xcOpenConnection);
03614   new_built_in(x_module,"xcDefaultRootWindow",    predicate,xcDefaultRootWindow);
03615   new_built_in(x_module,"xcGetScreenAttribute",   predicate,xcGetScreenAttribute);
03616   new_built_in(x_module,"xcGetConnectionAttribute",predicate,xcGetConnectionAttribute);
03617   new_built_in(x_module,"xcCloseConnection",      predicate,xcCloseConnection);
03618   
03619   new_built_in(x_module,"xcCreateSimpleWindow", predicate,xcCreateSimpleWindow);
03620 #if 0
03621   new_built_in(x_module,"xcCreateWindow",       predicate,xcCreateWindow);
03622 #endif
03623   
03624   new_built_in(x_module,"xcSetStandardProperties", predicate,xcSetStandardProperties);
03625   new_built_in(x_module,"xcGetWindowGeometry",  predicate,xcGetWindowGeometry);
03626   new_built_in(x_module,"xcSetWindowGeometry",  predicate,xcSetWindowGeometry);
03627   new_built_in(x_module,"xcGetWindowAttribute", predicate,xcGetWindowAttribute);
03628   new_built_in(x_module,"xcSetWindowAttribute", predicate,xcSetWindowAttribute);
03629   new_built_in(x_module,"xcMapWindow",          predicate,xcMapWindow);
03630   
03631   /*  RM: May  6 1993  */
03632   new_built_in(x_module,"xcRaiseWindow",          predicate,xcRaiseWindow);
03633   
03634   new_built_in(x_module,"xcUnmapWindow",        predicate,xcUnmapWindow);
03635   
03636   /*** RM 8/12/92 ***/
03637   new_built_in(x_module,"xcMapSubwindows",          predicate,xcMapSubwindows);
03638   new_built_in(x_module,"xcUnmapSubwindows",        predicate,xcUnmapSubwindows);
03639   /*** RM 8/12/92 ***/
03640   
03641   new_built_in(x_module,"xcClearWindow",        predicate,xcClearWindow);
03642   new_built_in(x_module,"xcResizeWindowPixmap", predicate,xcResizeWindowPixmap);
03643   
03644   new_built_in(x_module,"xcSelectInput",        predicate,xcSelectInput);
03645   new_built_in(x_module,"xcRefreshWindow",      predicate,xcRefreshWindow);
03646   new_built_in(x_module,"xcPostScriptWindow",   predicate,xcPostScriptWindow);
03647   new_built_in(x_module,"xcDestroyWindow",      predicate,xcDestroyWindow);
03648   
03649   new_built_in(x_module,"xcCreateGC",           predicate,xcCreateGC);
03650   new_built_in(x_module,"xcGetGCAttribute",     predicate,xcGetGCAttribute);
03651   new_built_in(x_module,"xcSetGCAttribute",     predicate,xcSetGCAttribute);
03652   new_built_in(x_module,"xcDestroyGC",          predicate,xcDestroyGC);
03653   
03654   new_built_in(x_module,"xcDrawLine",           predicate,xcDrawLine);
03655   new_built_in(x_module,"xcMoveWindow",         predicate,xcMoveWindow);
03656   new_built_in(x_module,"xcDrawArc",            predicate,xcDrawArc);
03657   new_built_in(x_module,"xcDrawRectangle",      predicate,xcDrawRectangle);
03658   new_built_in(x_module,"xcDrawPolygon",        predicate,xcDrawPolygon);
03659   
03660   new_built_in(x_module,"xcLoadFont",           predicate,xcLoadFont);
03661   new_built_in(x_module,"xcUnloadFont",         predicate,xcUnloadFont);
03662   new_built_in(x_module,"xcDrawString",         predicate,xcDrawString);
03663   new_built_in(x_module,"xcDrawImageString",    predicate,xcDrawImageString);
03664   new_built_in(x_module,"xcStringWidth",        function, xcStringWidth);
03665   
03666   new_built_in(x_module,"xcRequestColor",       predicate,xcRequestColor);
03667   new_built_in(x_module,"xcRequestNamedColor",  predicate,xcRequestNamedColor);
03668   new_built_in(x_module,"xcFreeColor",          predicate,xcFreeColor);
03669   
03670   new_built_in(x_module,"xcFillRectangle",      predicate,xcFillRectangle);
03671   new_built_in(x_module,"xcFillArc",            predicate,xcFillArc);
03672   new_built_in(x_module,"xcFillPolygon",        predicate,xcFillPolygon);
03673   
03674   new_built_in(x_module,"xcPointsAlloc",        predicate,xcPointsAlloc);
03675   new_built_in(x_module,"xcCoordPut",           predicate,xcCoordPut);
03676   new_built_in(x_module,"xcPointsFree",         predicate,xcPointsFree);
03677   
03678   new_built_in(x_module,"xcSync",               predicate,xcSync);
03679   new_built_in(x_module,"xcGetEvent",           function, xcGetEvent);
03680   new_built_in(x_module,"xcFlushEvents",        predicate,xcFlushEvents);
03681   
03682   /*** RM: 7/12/92 ***/
03683   new_built_in(x_module,"xcQueryPointer",       predicate,xcQueryPointer);
03684   /*** RM: 7/12/92 ***/
03685   
03686   /*  RM: Apr 20 1993  */
03687   new_built_in(x_module,"xcQueryTextExtents",predicate,xcQueryTextExtents);
03688 }
03689 
03690 
03691 
03692 /*****************************************************************/
03693 /* not a built-in */
03694 /* called by what_next_aim in login.c */
03695 
03696 static long WaitNextEvent(ptreventflag)
03697      long *ptreventflag;
03698 {
03699   long nfds;
03700   fd_set readfd,writefd,exceptfd;
03701   struct timeval timeout;
03702   long charflag = FALSE,nbchar;
03703   char c = 0;
03704   
03705   
03706   *ptreventflag = FALSE;
03707   
03708   do
03709     {
03710       FD_ZERO(&readfd);
03711       FD_SET(stdin_fileno, &readfd);
03712       FD_ZERO(&writefd);
03713       FD_ZERO(&exceptfd);
03714       timeout.tv_sec = 0;
03715       timeout.tv_usec = 100000;
03716 
03717       nfds = select(32,&readfd,&writefd,&exceptfd,&timeout);
03718       if(nfds == -1)
03719         {
03720 #if 0
03721           /* not an error,but a signal has been occured */
03722           /* handle_interrupt(); does not work */
03723           exit();
03724 #endif
03725           if(errno != EINTR) 
03726             {
03727               Errorline("in select: interruption error.\n");
03728               exit_life(TRUE);
03729             }
03730           else 
03731             interrupt();
03732         }
03733       
03734       else
03735         if(nfds == 0)
03736           {
03737 #ifdef X11
03738             if(x_exist_event())
03739               {
03740                 *ptreventflag = TRUE;
03741                 start_of_line = TRUE;
03742               }         
03743 #endif
03744           }
03745         else
03746           {
03747             if(FD_ISSET(stdin_fileno, &readfd) != 0)
03748               {
03749 #if 0
03750                 if((nbchar = read(stdin_fileno,&c,1)) == -1)
03751                   {
03752                     Errorline("in select: keyboard error.\n");
03753                     exit_life(TRUE);
03754                   }
03755                 
03756                 /* see manpage of read */
03757                 if(nbchar == 0)
03758                   c = EOF;
03759 #endif
03760                 c = fgetc(input_stream);
03761                 charflag = TRUE;
03762               }
03763             else
03764               {
03765                 Errorline("select error.\n");
03766                 exit_life(TRUE);
03767               }
03768           }
03769     } while(!(charflag || *ptreventflag));
03770   
03771   return c;
03772 }
03773 
03774 /*****************************************/
03775 
03776 
03777 long x_read_stdin_or_event(ptreventflag)
03778      long *ptreventflag;
03779 {
03780   long c = 0;
03781   
03782   
03783   *ptreventflag = FALSE;
03784   
03785   if(c = saved_char) /* not an error ;-) */
03786     {
03787       saved_char = old_saved_char;
03788       old_saved_char=0;
03789     }
03790   else
03791     {
03792       if(feof(input_stream))
03793         c = EOF;
03794       else 
03795         {
03796           if(start_of_line) 
03797             {
03798               start_of_line = FALSE;
03799               line_count ++ ;
03800               Infoline("%s",prompt); 
03801               fflush(output_stream);
03802             }
03803           
03804           c = WaitNextEvent(ptreventflag);
03805           
03806           if(*ptreventflag)
03807             {
03808               if(verbose) printf("<X event>");
03809               if(NOTQUIET) printf("\n"); /* 21.1 */
03810             }
03811           
03812           if(c == EOLN)
03813             start_of_line = TRUE;
03814         }
03815     }
03816   
03817   return c;
03818 }
03819 
03820 
03821 /*****************************************************************/
03822 /* Static */
03823 /* returns TRUE if the mask matches the type */
03824 
03825 static long mask_match_type(mask,type)
03826      long mask,type;
03827 {
03828   long em;
03829 
03830   /* printf("mask=%d,type=%d=%s\n",mask,type,xevent_name[type]); */
03831 
03832   em=xevent_mask[type];
03833   if(!em ||(em & mask))
03834     return TRUE;
03835 
03836   /* printf("FALSE\n"); printf("event mask=%d\n",em); */
03837   
03838   return FALSE;
03839 }
03840 
03841 
03842 
03843 /*****************************************************************/
03844 /* Static */
03845 /* returns the psi-event of the list corresponding to the existing event */
03846 
03847 static ptr_psi_term x_what_psi_event(beginSpan,endSpan,eventType)
03848      ptr_psi_term beginSpan,endSpan;
03849      long eventType;
03850 {
03851   if(beginSpan == endSpan)
03852     return list_car(beginSpan);
03853   else
03854     if(mask_match_type(GetIntAttr(list_car(beginSpan),"mask"),
03855                          eventType))
03856       return list_car(beginSpan);
03857     else
03858       return x_what_psi_event(list_cdr(beginSpan),
03859                                endSpan,eventType);
03860 }
03861 
03862 
03863 
03864 /*****************************************************************/
03865 /* Static */
03866 /* builds xevent_existing */
03867 
03868 static void x_build_existing_event(event,beginSpan,endSpan,eventType)
03869      XEvent *event;
03870      ptr_psi_term beginSpan,endSpan;
03871      long eventType;
03872 {
03873   ptr_psi_term psiEvent;
03874   
03875 
03876   /* printf("building event: type=%s event=%s\n",
03877      xevent_name[type],xevent_name[event->type]); */
03878   
03879   /* get the event from the list */
03880   psiEvent = x_what_psi_event(beginSpan,endSpan,eventType);
03881   
03882   /* put the event on the waiting event */
03883   bk_change_psi_attr(psiEvent,"event",xcEventToPsiTerm(event));
03884   
03885   /* set the global */
03886   if(xevent_existing)
03887     Warningline("xevent_existing is non-null in x_build_existing_event");
03888   push_ptr_value_global(psi_term_ptr,&xevent_existing);
03889   xevent_existing = psiEvent;
03890   
03891   /* remove the event from the list */
03892   /* 9.10 */
03893   /* if(list_car(xevent_list) == psiEvent) */
03894   /*     push_ptr_value_global(psi_term_ptr,&xevent_list); */
03895   /* xevent_list = list_remove_value(xevent_list,psiEvent); */
03896   list_remove_value(xevent_list,psiEvent); /*  RM: Dec 15 1992  */
03897 }
03898 
03899 
03900 
03901 /*****************************************************************/
03902 /* Static */
03903 /* get the next span of waiting events */
03904 
03905 static long x_next_event_span(eventElt,eventClosure)
03906      ptr_psi_term eventElt;
03907      EventClosure *eventClosure;
03908 {
03909   ptr_psi_term psiEvent;
03910   Display *display;
03911   Window window;
03912   long mask;
03913   XEvent event;
03914 
03915   
03916   psiEvent = list_car(eventElt);
03917   display =(Display *)GetIntAttr(psiEvent,"display");
03918   window =(Window)GetIntAttr(psiEvent,"window");
03919   mask = GetIntAttr(psiEvent,"mask");
03920   
03921   if(eventClosure->display == NULL) {
03922     /* new span */
03923     eventClosure->display = display;
03924     eventClosure->window = window;
03925     eventClosure->mask = mask;
03926     eventClosure->beginSpan = eventElt;
03927     return TRUE;
03928   }
03929   else
03930     if(eventClosure->display == display && eventClosure->window == window) {
03931       /* same span */
03932       eventClosure->mask |= mask;
03933       return TRUE;
03934     }
03935     else {
03936       /* a next span begins,check the current span */
03937     Repeat:
03938       if(XCheckWindowEvent(eventClosure->display,eventClosure->window,
03939                              eventClosure->mask,&event)
03940           /* && event.xany.window == eventClosure->window */)
03941         {
03942           /* 9.10 */
03943           /* printf("Event type = %ld.\n",event.type); */
03944 
03945           
03946           if((event.type==Expose || event.type==GraphicsExpose)
03947               && event.xexpose.count!=0) {
03948             /* printf("Expose count = %ld.\n", event.xexpose.count); */
03949             goto Repeat;
03950           }
03951           
03952           /* build a psi-term containing the event */
03953           
03954           /* printf("*** event %d ***\n",event.type); */
03955           
03956           x_build_existing_event(&event,
03957                                   eventClosure->beginSpan,
03958                                   eventElt,event.type);
03959 
03960           return FALSE; /* stop ! we have an existing event !! */
03961         }
03962       else
03963         {
03964           /* init the new span */
03965           eventClosure->display = display;
03966           eventClosure->window = window;
03967           eventClosure->mask = mask;
03968           eventClosure->beginSpan = eventElt;
03969           return TRUE;
03970         }
03971     }
03972 }
03973 
03974 
03975 
03976 /*****************************************************************/
03977 /* not a built-in */
03978 /* used by main_prove() and what_next() */
03979 
03980 long x_exist_event()
03981 {
03982   XEvent event,exposeEvent;
03983   ptr_psi_term eventElt;
03984   EventClosure eventClosure;
03985   
03986 
03987   /*infoline("xevent_list=%P\n",xevent_list); */
03988 
03989   if(xevent_existing)
03990     return TRUE;
03991   
03992   if(list_is_nil(xevent_list)) {
03993     /* printf("nil event list\n"); */
03994     return FALSE;
03995   }
03996 
03997   
03998   /* traverse the list of waiting events */
03999   eventClosure.display = NULL;
04000   if(!map_funct_over_list(xevent_list,x_next_event_span,&eventClosure))
04001     return TRUE;
04002 
04003   /* printf("display=%d,window=%d,mask=%d\n",
04004      eventClosure.display,eventClosure.window,eventClosure.mask); */
04005   
04006 
04007   
04008   /* check the last span */
04009   if(XCheckWindowEvent(eventClosure.display,
04010                          eventClosure.window,
04011                          eventClosure.mask,
04012                          &event)) {
04013 
04014     /* printf("*** here event %d ***\n",event.xany.type); */
04015 
04016     if(event.xany.window==eventClosure.window) {
04017       if(event.type == Expose)
04018         while(XCheckWindowEvent(eventClosure.display,
04019                                   eventClosure.window,
04020                                   ExposureMask,
04021                                   &exposeEvent))
04022           ; /* that is continue until no expose event */
04023       
04024       /* build a psi-term containing the event */
04025       x_build_existing_event(&event,
04026                               eventClosure.beginSpan,
04027                               list_last_cdr(xevent_list),/* RM: Dec 15 1992*/
04028                               event.type);
04029       return TRUE;
04030     }
04031   }
04032   else
04033     return FALSE;
04034 }
04035 
04036 
04037 
04038 /*****************************************************************/
04039 /* used when backtracking a created window in order to destroy the window */
04040 
04041 void x_destroy_window(display,window)
04042      
04043      Display *display;
04044      Window window;
04045      
04046 {
04047   /* we need the psi-term window(not the value) to get the display list,the pixmap ...
04048      jch - Fri Aug  7 15:29:14 MET DST 1992
04049      
04050      FreeWindow(display,window);
04051      */
04052   XDestroyWindow(display,window);
04053   XSync(display,0);
04054 }
04055 
04056 
04057 /*****************************************************************/
04058 /* used when backtracking a xcUnmapWindow in order to show the window */
04059 
04060 void x_show_window(display,window)
04061      
04062      Display *display;long window;
04063      
04064 {
04065   XMapWindow(display,window);
04066   XSync(display,0);
04067 }
04068 
04069 
04070 /*****************************************************************/
04071 /* used when backtracking a xcMapWindow in order to hide the window */
04072 
04073 void x_hide_window(display,window)
04074      
04075      Display *display; long window;
04076      
04077 {
04078   XUnmapWindow(display,window);
04079   XSync(display,0);
04080 }
04081 
04082 
04083 /*** RM 8/12/92 ***/
04084 
04085 /*****************************************************************/
04086 /* used when backtracking a xcUnmapWindow in order to show the window */
04087 
04088 void x_show_subwindow(display,window)
04089      
04090      Display *display; long window;
04091      
04092 {
04093   XMapSubwindows(display,window);
04094   XSync(display,0);
04095 }
04096 
04097 
04098 /*****************************************************************/
04099 /* used when backtracking a xcMapWindow in order to hide the window */
04100 
04101 void x_hide_subwindow(display,window)
04102      
04103      Display *display; long window;
04104      
04105 {
04106   XUnmapSubwindows(display,window);
04107   XSync(display,0);
04108 }
04109 
04110 /*** RM 8/12/92 ***/
04111 
04112 
04113 
04114 /***  RM: Apr 20 1993 ***/
04115 
04116 
04117 /*
04118   xcQueryTextExtents(display,font,string,
04119   direction,font-ascent,font-descent,
04120   left-bearing,right-bearing,width,ascent,descent)
04121   */
04122 
04123 long xcQueryTextExtents()
04124      
04125 {
04126   include_var_builtin(11);
04127   ptr_definition types[11];
04128   Font font;
04129   XCharStruct over;
04130   int i;
04131   int direction,ascent,descent; /* RM: 28 Jan 94 */
04132   
04133   types[0] = real;   /* +Display       */
04134   types[1] = real;   /* +Font ID       */
04135   types[2] = quoted_string; /* +String        */
04136   types[3] = real;   /* -Direction     */
04137   types[4] = real;   /* -Font-ascent   */
04138   types[5] = real;   /* -Font-descent  */
04139   types[6] = real;   /* -left bearing  */
04140   types[7] = real;   /* -right bearing */
04141   types[8] = real;   /* -width         */
04142   types[9] = real;   /* -ascent        */
04143   types[10]= real;   /* -descent       */
04144   
04145   
04146   
04147   begin_builtin(xcLoadFont,11,3,types);
04148   
04149 
04150   XQueryTextExtents(DISP(0),
04151                     (XID)val[1],
04152                     STRG(2),
04153                     strlen(STRG(2)),
04154                     &direction,
04155                     &ascent,
04156                     &descent,
04157                     &over);
04158 
04159   val[3]=direction;
04160   val[4]=ascent;
04161   val[5]=descent;
04162   
04163   val[6] =over.lbearing;
04164   val[7] =over.rbearing;
04165   val[8] =over.width;
04166   val[9] =over.ascent;
04167   val[10]=over.descent;
04168   
04169   for(i=3;i<11;i++)
04170     unify_real_result(args[i],(REAL)val[i]);
04171   
04172   end_builtin();
04173 }
04174 /***  RM: Apr 20 1993  ***/
04175 
04176 
04177 /*****************************************************************/
04178 /* not used anymore, but interesting */
04179 
04180 ptr_goal GoalFromPsiTerm(psiTerm)
04181      
04182      ptr_psi_term psiTerm;
04183      
04184 {
04185   ptr_residuation resid;
04186   ptr_goal aim;
04187   
04188   
04189   if(psiTerm == NULL)
04190     {
04191       Errorline("X error in GoalFromPsiTerm: psiTerm is null\n");
04192       return FALSE;
04193     }
04194   
04195   if((resid = psiTerm->resid) == NULL)
04196     {
04197       Errorline("X error in GoalFromPsiTerm: psiTerm has no residuating functions\n");
04198       return FALSE;
04199     }
04200   
04201   if(resid->next != NULL)
04202     {
04203       Errorline("X error in GoalFromPsiTerm: psiTerm has more than one residuating function\n");
04204       return FALSE;
04205     }
04206   
04207   if((aim = resid->goal) == NULL)
04208     {
04209       Errorline("X error in GoalFromPsiTerm: psiTerm has no goal\n");
04210       return FALSE;
04211     }
04212   
04213   return aim;
04214 }
04215 
04216 
04217 #endif

Generated on Sat Jan 26 08:48:08 2008 for WildLife by  doxygen 1.5.4