home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / xfedor.zip / XFree86 / src / xfedor / couchex.c < prev    next >
C/C++ Source or Header  |  1998-11-06  |  25KB  |  972 lines

  1. /* Copyright 1989 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  2. /***  COUCHE DE PORTAGE SUR X WINDOW ***/
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. extern int strlen() ;
  7.  
  8. #include <X11/Xlib.h>
  9. #include <X11/Xatom.h>        /* XA_WM_NAME */
  10. #include <X11/cursorfont.h>        /* XC_arrow */
  11. #include <X11/Xutil.h>        /* BitmapSucces */
  12. #include <X11/keysym.h>        /* IsModifierKey */
  13. #include <X11/keysymdef.h>        /* IsModifierKey */
  14.  
  15. #include "couche.h"         /* myEvent, ..CURS, ON */
  16. #include "clientimage.h"    /* ClientImage */
  17.  
  18. #include "X11/xpm.h"        /* PixmapSuccess ...*/
  19.  
  20.  
  21. /*===== VARIABLES EXPORTEES DU MODULE ==============================*/
  22. /* principalement vers myrast.c */
  23.  
  24. Display * Dpl ;
  25. Window root ;
  26. int depth ;
  27. int screen ;
  28. int BackColor ;
  29. int ImaForm ;
  30.  
  31. /*===== VARIABLES LOCALES DU MODULE ==============================*/
  32.  
  33. static GC Gc, GcInv, GcCInv, GcTil, GcPft, GcFontColor, GcColor ; 
  34. static Colormap colormap ;
  35. static Atom WM_Delete_Window;
  36.  
  37.     /* pour la gestion des zones */
  38. #define NBZONE 200
  39. static struct {int zone,mere,xorz,yorz;} Tzone[NBZONE];
  40.  
  41. static XColor fore,back ; /* pour XCreatePixmapCursor */
  42.  
  43. static unsigned long background_pixel, border_pixel ; /* pour wattrib */
  44.  
  45. static XFontStruct * ft ;        /* pour w_centrer */
  46.  
  47. static Cursor ServCurs[5];     /* tableau indic'es par les macros .. CURS */
  48.  
  49. static int argc ;
  50. static char ** argv ;    /* pour XSetStandardProperties */
  51.  
  52. #include "bitmaps/nfmono"           /* fond fenetre mere */
  53. #include "bitmaps/bull"             /* icone arbre bull */
  54.  
  55. static Pixmap bullicon ;
  56.  
  57. static long flagPosition ;
  58.  
  59. #define PIXELGREY -13      /* pour traitement special monochome entre
  60.                   w_color et w_greypixel */
  61. int ErrorStatus ;
  62.  
  63. int NoXError(display, error)
  64. Display        *display;
  65. XErrorEvent    *error;
  66. {
  67.    ErrorStatus = error -> error_code;
  68.    return 0;
  69. }
  70.  
  71. /*--------------------------------------------------------------*/      
  72. /* W_INITIAL */
  73. int w_initial (reverse,display,font1,font2,r_argc,r_argv,geom,imaform)
  74.     int reverse ;
  75.     char  * display ;
  76.     char * font1, * font2 ;
  77.     int r_argc ;
  78.     char ** r_argv ;
  79.         char * geom ;
  80.         int imaform ;   /* determine le format d'image XY ou ZPixmap */
  81.         
  82. {  
  83.          XGCValues xgcv;
  84.      Pixmap MyGrey ;
  85.      long TabGris[8];    /* 16 sur 16 bits */
  86.      int i ;
  87.  
  88.       if ((Dpl = XOpenDisplay(display)) == NULL) {
  89.         fprintf(stderr,"Cannot open display : %s\n",
  90.             XDisplayName(display));
  91.         exit(0);
  92.       }
  93.  
  94. /* XSynchronize(Dpl,1);  use in debug */
  95.  
  96.       screen = DefaultScreen(Dpl) ;
  97.       root = DefaultRootWindow(Dpl);
  98.       depth = DefaultDepth(Dpl,screen) ;
  99.       colormap = DefaultColormap(Dpl,screen) ;
  100.  
  101.       if (imaform == 0) {  /* pas de format specifie : choix hack */
  102.     if (depth > 2) ImaForm = ZPixmap ; else ImaForm = XYPixmap ; 
  103.       } else
  104.       if ((imaform == 2) && (depth != 2)) ImaForm = ZPixmap ; else
  105.     ImaForm = XYPixmap ;
  106.  
  107.       if (reverse == OFF ) {
  108.               xgcv.foreground = BlackPixel(Dpl,screen) ;
  109.          border_pixel = BlackPixel(Dpl,screen) ;
  110.         fore.pixel = BlackPixel(Dpl,screen) ;
  111.           
  112.         xgcv.background = WhitePixel(Dpl,screen) ;
  113.         background_pixel = WhitePixel(Dpl,screen) ;
  114.          back.pixel = WhitePixel(Dpl,screen) ;
  115.     } else {
  116.               xgcv.foreground = WhitePixel(Dpl,screen) ;
  117.         border_pixel = WhitePixel(Dpl,screen) ;
  118.         fore.pixel = WhitePixel(Dpl,screen) ;
  119.           
  120.         xgcv.background = BlackPixel(Dpl,screen) ;
  121.         background_pixel = BlackPixel(Dpl,screen) ;
  122.         back.pixel = BlackPixel(Dpl,screen) ;
  123.       }
  124.  
  125.       BackColor = WhitePixel(Dpl,screen) ;
  126.       XQueryColor(Dpl,colormap,&fore) ;
  127.       XQueryColor(Dpl,colormap,&back) ;
  128.  
  129.     /* init de shapes souris predefinis */
  130.       ServCurs[CURS1]  = XCreateFontCursor(Dpl,XC_dot);
  131.       ServCurs[CURS2]   = XCreateFontCursor(Dpl,XC_plus);
  132.       ServCurs[CURS3] = XCreateFontCursor(Dpl,XC_fleur);
  133.       ServCurs[CURS4]  = XCreateFontCursor(Dpl,XC_left_ptr);
  134.       ServCurs[CURS5]  = XCreateFontCursor(Dpl,XC_sb_h_double_arrow);
  135.  
  136.     /* Creation des Gc de travail globaux */
  137.       xgcv.graphics_exposures = False ;
  138.  
  139.       XSynchronize(Dpl,1);
  140.       ErrorStatus = 0;
  141.       XSetErrorHandler(NoXError);
  142.       xgcv.font = XLoadFont(Dpl,font1);
  143.       if (ErrorStatus) {
  144.       fprintf(stderr,"Can'f find font named \"%s\", try another one with -f1 option\n",font1);
  145.           exit(0);
  146. /*      xgcv.font = XQueryFont(Dpl,DefaultGC(Dpl,screen) -> gid)-> fid; */
  147.       }
  148.       ft = XQueryFont(Dpl,xgcv.font) ;
  149.       Gc = XCreateGC(Dpl,root,GCForeground|GCBackground|GCFont|
  150.                 GCGraphicsExposures, &xgcv);
  151.  
  152.       GcColor = XCreateGC(Dpl,root,GCGraphicsExposures, &xgcv);
  153.  
  154.       GcFontColor = XCreateGC(Dpl,root,GCBackground|GCForeground|
  155.                   GCGraphicsExposures, &xgcv);
  156.  
  157.       ErrorStatus = 0;
  158.       XSetErrorHandler(NoXError);
  159.       xgcv.font = XLoadFont(Dpl,font2);
  160.       if (ErrorStatus) {
  161.       fprintf(stderr,"Can'f find font named \"%s\", try another one with -f2 option\n",font2);
  162.           exit(0);
  163. /*      xgcv.font = XQueryFont(Dpl,DefaultGC(Dpl,screen) -> gid)-> fid; */
  164.       }
  165.       XSynchronize(Dpl,0);
  166.       GcPft = XCreateGC(Dpl,root,GCForeground|GCBackground|GCFont|
  167.                 GCGraphicsExposures, &xgcv);
  168.  
  169.       xgcv.function = GXinvert ;
  170.       GcInv = XCreateGC(Dpl,root,GCForeground|GCBackground|
  171.             GCFunction|GCGraphicsExposures, &xgcv);
  172.  
  173.       xgcv.function = GXcopyInverted ;
  174.       GcCInv = XCreateGC(
  175. Dpl,root,GCForeground|GCBackground|
  176.              GCFunction|GCGraphicsExposures, &xgcv);
  177.  
  178.       for (i=0;i<8;i++) TabGris[i] = 0x5555aaaa ;
  179.       MyGrey = XCreatePixmap(Dpl,root,16,16,depth);
  180.       XFillRectangle(Dpl,MyGrey,GcColor,0,0,16,16);
  181.       XPutImage(Dpl,MyGrey,GcColor,
  182.         XCreateImage(Dpl,DefaultVisual(Dpl,screen),
  183.                  1,XYBitmap,0,(char *)TabGris,16,16,16,0),
  184.         0,0,0,0,16,16);
  185.  
  186.       xgcv.tile = MyGrey ;
  187.       xgcv.fill_style = FillTiled ;
  188.       GcTil = XCreateGC(Dpl,root,GCForeground|GCBackground|
  189.             GCFillStyle|GCTile|GCGraphicsExposures, &xgcv);
  190.  
  191.       argc = r_argc ;
  192.       argv = r_argv ;
  193.  
  194.       bullicon = XCreateBitmapFromData(Dpl,root,
  195.                        (char *)bull_bits,bull_width,bull_height);
  196.  
  197.       if (geom) flagPosition = USPosition ; else
  198.             flagPosition = PPosition ;
  199.  
  200.       return((int)root);
  201. }
  202.    
  203. /*---------------------------------------------------------------------*/
  204. /* W_OUVRIR */
  205. long TransformMask(mask)
  206.     int mask ;
  207. {    int eventmask=0 ;
  208.  
  209.     if (mask & KeyPressed) eventmask |= KeyPressMask ;
  210.     if (mask & ButtonPressed) eventmask |= ButtonPressMask ;
  211.     if (mask & MoveMouse) eventmask |= PointerMotionMask ;
  212.     if (mask & LeaveWindow) eventmask |= LeaveWindowMask ;
  213.     if (mask & EnterWindow) eventmask |= EnterWindowMask ;
  214.     if (mask & ResizeWindow) eventmask |= StructureNotifyMask ;
  215.     if (mask & LeaveZone) eventmask |= LeaveWindowMask ;
  216.     if (mask & EnterZone) eventmask |= EnterWindowMask ;
  217.     return eventmask|ExposureMask|ButtonReleaseMask ;
  218. }
  219.  
  220. int w_ouvrir (wd,x,y,w,h,titre,mlook,eventmask,no_wm)
  221.    int wd ;        /* fenetre mere */
  222.    int x,y,w,h ;    /* dimension + origine */
  223.    char *  titre;       /* titre de la fenetre , ou "" si on veut rien */
  224.    int mlook;         /* look de la souris */
  225.    int eventmask ;    /* masque des evenements */
  226.    int no_wm ;        /* False or True */
  227.     Window wn;
  228.     XSetWindowAttributes wattrib ;
  229.     XSizeHints hints ;
  230.     XWMHints wmhints ;
  231.     XClassHint classhint ;
  232.     int backflag  ;
  233.  
  234.     wattrib.event_mask = TransformMask(eventmask) ;
  235.     wattrib.cursor = ServCurs[mlook] ; 
  236.  
  237.     if ((wd == root) && (no_wm == WMOFF)) {
  238.       wattrib.save_under = False ;
  239.       wattrib.override_redirect = True ;
  240.     } else {
  241.       wattrib.save_under = False ;
  242.       wattrib.override_redirect = False ;
  243.     }
  244.  
  245.     if (eventmask == 0) {  /* moyen de test sur nf_mono */
  246.         Pixmap pix = XCreateBitmapFromData(Dpl,wd,
  247.                 nfmono_bits,nfmono_width,nfmono_height);
  248.         wattrib.background_pixmap = XCreatePixmap(Dpl,wd,
  249.                     nfmono_width,nfmono_height,depth);
  250.         XFillRectangle(Dpl,wattrib.background_pixmap,GcColor,
  251.                    0,0,nfmono_width,nfmono_height);
  252.         XCopyPlane(Dpl,pix,wattrib.background_pixmap,GcColor,0,0,
  253.                     nfmono_width,nfmono_height,0,0,1);
  254.  
  255.         backflag = CWBackPixmap ;
  256.         XFreePixmap(Dpl, pix);
  257.     } else {
  258.         wattrib.background_pixel = background_pixel ;
  259.         backflag = CWBackPixel ;
  260.     }
  261.     wattrib.border_pixel = border_pixel ;
  262.     wattrib.bit_gravity = StaticGravity ;
  263.     wattrib.win_gravity = StaticGravity ;
  264.  
  265.         wn = XCreateWindow(Dpl,wd,x,y,w,h,1,depth,
  266.                InputOutput,CopyFromParent,
  267.                CWOverrideRedirect |  backflag | CWBorderPixel | 
  268.                CWSaveUnder | CWEventMask | CWCursor,
  269.                /*| CWBitGravity | CWWinGravity */
  270.             &wattrib);
  271.  
  272.     /* on a determiner si l'utilisateur a donner un ordre de
  273.        positionnement avec l'option -geometry, dans ce cas le flag
  274.        de position est USPosition, sinon c'est le programme qui
  275.        positionne */ 
  276.     
  277.     if ((wd == root) && (no_wm == WMON)) {
  278.         hints.flags = PPosition|PSize|PMinSize|PMaxSize ;
  279.         hints.x = x ;
  280.         hints.y = y ;
  281.          hints.width = w ;
  282.         hints.height = h ;
  283.         hints.min_width = hints.width ;
  284.         hints.min_height = hints.height ;
  285.         hints.max_width = hints.width ;
  286.         hints.max_height = hints.height ;
  287.         XSetNormalHints(Dpl,wn,&hints);    
  288.  
  289.         XStoreName(Dpl,wn,titre);    
  290.         XSetIconName(Dpl,wn,"XFEDOR");    
  291.         XSetCommand(Dpl,wn,argv,argc);
  292.             
  293.         wmhints.flags = InputHint | IconPixmapHint ;
  294.         wmhints.input = True ;
  295.         wmhints.icon_pixmap = bullicon ;
  296.         XSetWMHints(Dpl,wn,&wmhints);
  297.  
  298.         classhint.res_name = "xfedor" ;
  299.         classhint.res_class = "font_editor" ;
  300.         XSetClassHint(Dpl,wn,&classhint);
  301.  
  302.             WM_Delete_Window = XInternAtom(Dpl, "WM_DELETE_WINDOW", False);
  303.             XSetWMProtocols(Dpl, wn, &WM_Delete_Window, 1); 
  304.     }
  305.     return ((int)wn);
  306. }
  307.    
  308. /*-------------------------------------------------------------*/
  309. /* W_CRZON */
  310. int w_crzon (wd,x1,y1,x2,y2,mlook) 
  311.    int wd ;
  312.    int x1,y1,x2,y2 ;
  313.    int mlook;             /* numero d'icone souris */
  314. {
  315.     Window wn;
  316.     XSetWindowAttributes wattrib ;
  317.     XWindowAttributes watt ;
  318.  
  319.         static int iz = 0 ;
  320.  
  321.     XGetWindowAttributes(Dpl,wd,&watt);
  322.     wattrib.cursor = ServCurs[mlook] ; 
  323.     wattrib.event_mask = watt.your_event_mask ;
  324.  
  325.         wn = XCreateWindow(Dpl,wd,x1,y1,x2-x1,y2-y1,0,0,
  326.                InputOnly,CopyFromParent,CWEventMask|CWCursor,
  327.                &wattrib);
  328.  
  329.     Tzone[iz].zone = wn ;
  330.     Tzone[iz].mere = wd ;    /* gestion des zones pour GetEvent */
  331.           Tzone[iz].xorz = x1 ;
  332.           Tzone[iz].yorz = y1 ;
  333.     iz ++ ;            
  334.         XMapWindow(Dpl,wn);
  335.     return ((int)wn);
  336.         
  337. }
  338.  
  339. /*-------------------------------------------------------------*/
  340. /* W_GETEVENT */
  341. int TransformEvent(xtype)
  342.     int xtype ;
  343. {
  344.     switch(xtype) {
  345.     case KeyPress : return KeyPressed ; 
  346.     case ButtonPress : return ButtonPressed ; 
  347.     case ButtonRelease : return ButtonReleased ; 
  348.     case MotionNotify : return MoveMouse ; 
  349.     case LeaveNotify : return LeaveWindow ; 
  350.     case EnterNotify : return EnterWindow ; 
  351.     case Expose : return Exposure ; 
  352.     case ClientMessage : return CloseWindow ;
  353.     }
  354.    return 0;
  355. }
  356.  
  357. static int
  358. is_del_win_event(XEvent *rep)
  359. {
  360.     return rep->type == ClientMessage &&
  361.         rep->xclient.format == 32 &&
  362.         rep->xclient.data.l[0] == WM_Delete_Window;
  363. }
  364.  
  365. void w_getevent (pev)
  366.    myEvent * pev;
  367.         
  368. {
  369.     XEvent rep ;
  370.     static int ZoneCour = 0 ;
  371.     int i, keysym ;
  372.     char s[1] ;
  373.  
  374.     do {
  375.        XNextEvent(Dpl,&rep) ;
  376.        if (is_del_win_event(&rep))
  377.            break;
  378.            if (rep.type == KeyPress)
  379.            XLookupString((XKeyEvent *)&rep,s,1,(KeySym *)&keysym,NULL);
  380.     } while ( ((rep.type != Expose) || (rep.xexpose.count != 0)) &&
  381.           ((rep.type != KeyPress) || (IsModifierKey(keysym))) &&
  382.           (rep.type != ButtonPress) &&
  383.           (rep.type != ButtonRelease) &&
  384.           (rep.type != MotionNotify) &&
  385.           (rep.type != LeaveNotify) &&
  386.           (rep.type != EnterNotify)) ;
  387.  
  388.     pev->key = (char) keysym ;    
  389.     if ((rep.type == KeyPress) && (pev->key > 96) && (pev->key < 123) &&
  390.         ((rep.xkey.state && ControlMask))) pev->key -= 96 ;
  391.  
  392.         if (rep.type == ButtonPress) XUngrabPointer(Dpl,CurrentTime);
  393.  
  394.     /* recherche dans la liste des fenetres zones pour voir si
  395.         cette fenetre X est une zone a moi */
  396.     for (i=0;((i<NBZONE)&&(Tzone[i].zone!= rep.xany.window));i++) ;
  397.  
  398.     if (i==NBZONE) {    /* window normale */
  399.         pev->window = rep.xany.window ;
  400.         pev->zone = ZoneCour ;
  401.             pev->type = TransformEvent(rep.type) ;
  402.     } else {        /* window = zone */
  403.         pev->window = Tzone[i].mere ;
  404.         pev->zone = rep.xany.window ;
  405.         pev->xz = Tzone[i].xorz ;
  406.         pev->yz = Tzone[i].yorz ;
  407.         if (rep.type == EnterNotify) {
  408.             ZoneCour = pev->zone ;
  409.             pev->type = EnterZone ;
  410.         } else
  411.         if (rep.type == LeaveNotify) {
  412.             ZoneCour = 0 ;
  413.             pev->type = LeaveZone ;
  414.                 } else  pev->type = TransformEvent(rep.type) ;
  415.     }
  416.  
  417.     pev->click = (rep.xbutton.button == 1)? 1:2 ;
  418.     pev->x = rep.xbutton.x ;
  419.     pev->y = rep.xbutton.y ;
  420.  
  421.     if (rep.type == Expose) {
  422.         pev->x = rep.xexpose.x ;
  423.         pev->y = rep.xexpose.y ;
  424.         pev->xz = rep.xexpose.width ;
  425.         pev->yz = rep.xexpose.height ;
  426.     }
  427. }
  428.  
  429. /*--------------------------------------------------------------------*/
  430. /* W_ECRIRE */    
  431. void w_ecrire (wd,chaine,x,y)
  432.    int wd;         /* la fenetre */
  433.    char * chaine ;     /* la chaine a ecrire */
  434.    int x,y ;         /* ou ecrire */
  435. {
  436.       XDrawImageString (Dpl,wd,GcPft,x,y,chaine,strlen(chaine));
  437. }
  438.    
  439. /*--------------------------------------------------------------------*/
  440. /* W_CENTRER */
  441. void w_centrer (wd,chaine,x1,y1,x2,y2)
  442.    int wd; /* la fenetre */
  443.    char * chaine ; /* la chaine a ecrire */
  444.    int x1,y1,x2,y2 ; /* boite  dans laquelle on centre */
  445.  
  446. {    register int x,y,l,len,w,h ;
  447.  
  448.       w = x2 - x1 ;
  449.       h = y2 - y1 ;
  450.       XFillRectangle(Dpl,wd,GcCInv,x1+1,y1+1,w-1,h-1);
  451.       len = strlen(chaine) ;
  452.       do { 
  453.         l = XTextWidth(ft,chaine,len);
  454.     if (l <= w) break ;
  455.     len -- ;
  456.       } while (1) ;
  457.       x = x1 + ((w - l)>>1) ;
  458.       y = y1 + ((h + ft->ascent + ft->descent)>>1)-1 ;
  459.       XDrawString(Dpl,wd,Gc,x,y,chaine,len);
  460. }
  461.    
  462. /*--------------------------------------------------------------------*/
  463. /* W_LINE */
  464. void w_line (wd,x1,y1,x2,y2,mode)
  465.        int wd ;
  466.     int x1,y1,x2,y2;
  467.     int mode ;
  468. {
  469.           XDrawLine(Dpl,wd,(mode==ON)?Gc:GcInv,x1,y1,x2,y2);
  470. }    
  471.  
  472. /*--------------------------------------------------------------------*/
  473. /* W_RECT */
  474. void w_rect (wd,x1,y1,x2,y2,mode)
  475.        int wd ;
  476.     int x1,y1,x2,y2 ;
  477.     int mode ;
  478. {    
  479.          XDrawRectangle(Dpl,wd,(mode==ON)?Gc:GcInv,x1,y1,x2-x1,y2-y1);    
  480. }         
  481.  
  482.  
  483. /*--------------------------------------------------------------------*/ 
  484. /* W_FELLIPS */    
  485. void w_fellips (wd,x1,y1,x2,y2,mode)    
  486.        int wd ;
  487.     int x1,y1,x2,y2 ;
  488.      int mode ;
  489. {
  490.           XFillArc(Dpl,wd,(mode==ON)?Gc:GcInv,x1,y1,x2-x1,y2-y1,0,23040) ;
  491. }
  492.  
  493. /*----------------------------------------------------------------*/
  494. /* W_ELLIPS */
  495. void w_ellips (wd,x1,y1,x2,y2,mode)    
  496.        int wd ;
  497.     int x1,y1,x2,y2 ;
  498.     int mode ;
  499. {
  500.           XDrawArc(Dpl,wd,(mode==ON)?Gc:GcInv,x1,y1,x2-x1,y2-y1,0,23040) ;
  501. }
  502.  
  503. /*--------------------------------------------------------------------*/
  504. /* W_GRIS */
  505. void w_gris (wd,x1,y1,x2,y2) 
  506.        int wd ;
  507.     int x1,y1,x2,y2 ;
  508. {
  509.           XFillRectangle(Dpl,wd,GcTil,x1,y1,x2-x1,y2-y1);
  510. }
  511.  
  512. /*--------------------------------------------------------------------*/
  513. /* W_INV */
  514. void w_inv (wd,x1,y1,x2,y2)
  515.        int wd ;
  516.     int x1,y1,x2,y2 ;
  517. {
  518.           XFillRectangle(Dpl,wd,GcInv,x1,y1,x2-x1,y2-y1);
  519. }
  520.  
  521. /*--------------------------------------------------------------------*/
  522. /* W_FORE */
  523. void w_fore (wd,x1,y1,x2,y2)
  524.        int wd ;
  525.     int x1,y1,x2,y2 ;
  526. {
  527.           XFillRectangle(Dpl,wd,Gc,x1,y1,x2-x1,y2-y1);
  528. }
  529.  
  530. /*--------------------------------------------------------------------*/
  531. /* W_COLOR */
  532. void w_color (wd,x1,y1,x2,y2,color)
  533.        int wd ;
  534.     int x1,y1,x2,y2 ;
  535.         int color ;
  536. {
  537.   if ((depth == 1) && (color == PIXELGREY))
  538.     w_gris(wd,x1,y1,x2,y2) ;
  539.   else
  540.   {
  541.     XSetForeground(Dpl,GcColor,color);
  542.     XFillRectangle(Dpl,wd,GcColor,x1,y1,x2-x1,y2-y1);
  543.   }
  544. }
  545.  
  546. /* ------------------------------------------------------------*/
  547. /* W_POINT */
  548. void w_point(wd,x,y,color)
  549.     int wd ;
  550.     int x,y ;
  551.     int color ;    /* pixel value */
  552. {
  553.         XSetForeground(Dpl,GcColor,color);
  554.     XDrawPoint(Dpl,wd,GcColor,x,y);
  555. }
  556.  
  557. /*---------------------------------------------------------------------*/
  558. /* W_RASTOP */
  559. void w_rastop(ws,wd,sx,sy,w,h,dx,dy)
  560.     int ws,wd ;
  561.     int sx,sy,w,h,dx,dy ;
  562. {
  563.     XCopyArea(Dpl,ws, wd, GcColor, sx, sy, w, h, dx, dy);
  564. }    
  565.  
  566. /*---------------------------------------------------------------------*/
  567. /* W_BITBLT */
  568. void w_bitblt(wd,clientimage,sx,sy,w,h,dx,dy)
  569.     int wd ;
  570.     ClientImage * clientimage ;
  571.     int sx,sy,w,h,dx,dy ;
  572. {
  573.         XPutImage(Dpl,wd,GcFontColor,
  574.           (XImage *) clientimage, 
  575.           sx,sy,dx,dy,w,h);
  576. }
  577.  
  578. /*---------------------------------------------------------------------*/
  579. /* W_PIXEL */
  580. void w_pixel(wd,data,x,y,w,h)
  581.     int wd ;
  582.     char * data ;
  583.     int x,y,w,h ;
  584. {
  585.     Pixmap bm = XCreateBitmapFromData(Dpl,root,data,w,h);
  586.  
  587.     XCopyPlane(Dpl,bm, wd, Gc,0,0,w,h,x,y,1);
  588.     XFreePixmap(Dpl, bm);
  589. }
  590.  
  591. /*--------------------------------------------------------------------*/
  592. /* W_SOURIS */
  593. void w_souris (wd, climafore, climask, w,h,xhot,yhot)    
  594.     int wd ;
  595.         ClientImage * climafore, * climask ;  /* depth 1 */
  596.     int w,h ;
  597.     int xhot, yhot ;
  598. {
  599.     Pixmap pfore1, pmask1 ;
  600.         XGCValues xgcv;
  601.     GC Gc1 ;
  602.  
  603.     pfore1 = XCreatePixmap(Dpl,root,w,h,1);
  604.     pmask1 = XCreatePixmap(Dpl,root,w,h,1);
  605.  
  606.     xgcv.graphics_exposures = False ;
  607.     xgcv.function = GXcopyInverted ;
  608.  
  609.         Gc1 = XCreateGC(Dpl,pfore1,GCFunction|GCGraphicsExposures, &xgcv);
  610.  
  611.  
  612.     XPutImage(Dpl,pfore1,Gc1,
  613.           (XImage*)climafore,
  614.           0,0,0,0,w,h);
  615.     XPutImage(Dpl,pmask1,Gc1,
  616.           (XImage*)climask,
  617.           0,0,0,0,w,h);
  618.  
  619.     XDefineCursor(Dpl,wd,
  620.         XCreatePixmapCursor(Dpl,pfore1,pmask1,&fore,&back,
  621.             (xhot<0)?0:(xhot>w)?w:xhot,
  622.             (yhot<0)?0:(yhot>h)?h:yhot));
  623. }
  624.  
  625. /*--------------------------------------------------------------------*/
  626. /* W_WRITEPIXMAP */
  627. int w_writepixmap (name,clientimage,x,y,w,h)    
  628.     char * name ;
  629.     ClientImage * clientimage ;   /* depth n */
  630.     int x,y,w,h ;
  631.  
  632. {    
  633.     Pixmap p ;
  634.     XpmAttributes icon_attributes ;
  635.  
  636.     if ((w == 0) || (h == 0)) return 0 ;
  637.     p = XCreatePixmap(Dpl,root,w,h,depth);
  638.  
  639.     XPutImage(Dpl,p,GcColor,
  640.           (XImage *) clientimage, 
  641.           x,y,0,0,w,h);
  642.  
  643.     icon_attributes.width = w;
  644.     icon_attributes.height = h;
  645.     icon_attributes.valuemask = XpmSize ;
  646.  
  647.     if (XpmWriteFileFromPixmap (Dpl, name, p, 0, &icon_attributes)
  648.     == XpmSuccess)
  649.     return 1 ; 
  650.     else return 0 ;
  651. }
  652.  
  653. /*--------------------------------------------------------------------*/
  654. /* W_WRITEBITMAP */
  655. int w_writebitmap (name,clientimage,w,h,xhot,yhot)    
  656.     char * name ;
  657.     ClientImage * clientimage ;   /* depth 1 */
  658.     int w,h,xhot,yhot ;
  659. {    Pixmap p ;
  660.         XGCValues xgcv;
  661.     GC Gc1 ;
  662.  
  663.     if ((w == 0) || (h == 0)) return 0 ;
  664.     p = XCreatePixmap(Dpl,root,w,h,1);
  665.  
  666.     xgcv.graphics_exposures = False ;
  667.     xgcv.function = GXcopyInverted ;
  668.  
  669.         Gc1 = XCreateGC(Dpl,p,GCFunction|GCGraphicsExposures, &xgcv);
  670.  
  671.     XPutImage(Dpl,p,Gc1,
  672.           (XImage *) clientimage, 
  673.           0,0,0,0,w,h);
  674.  
  675.           if (XWriteBitmapFile(Dpl,name,p,w,h,xhot,yhot)==BitmapSuccess)
  676.         return 1 ; 
  677.     else    return 0 ;
  678. }
  679.  
  680. /*--------------------------------------------------------------------*/
  681. /* W_READBITMAP */
  682. int w_readbitmap (name,bitmage,w,h,xhot,yhot)    
  683.     char * name ;
  684.         ClientImage * * bitmage ; 
  685.     unsigned int *w,*h;
  686.         int *xhot,*yhot ;
  687. {    
  688.   Pixmap bit ;
  689.  
  690.         if (XReadBitmapFile(Dpl,root,name,w,h,&bit,xhot,yhot)!=BitmapSuccess)
  691.                 return 0 ;
  692.     
  693.     *bitmage = XGetImage(Dpl,bit,0,0,*w,*h,1,XYPixmap) ;
  694.  
  695.     return (1);
  696. }
  697.  
  698. /*--------------------------------------------------------------------*/
  699. /* W_READPIXMAP */
  700. int w_readpixmap (name,bitmage,w,h)    
  701.     char * name ;
  702.         ClientImage * * bitmage ; 
  703.     int *w,*h ;
  704. {    
  705.     Pixmap pix ;
  706.     XpmAttributes icon_attributes;
  707.  
  708.     icon_attributes.valuemask = XpmReturnPixels | XpmSize;
  709.     
  710.     if (XpmReadFileToPixmap(Dpl, root, name, &pix, NULL, &icon_attributes)
  711.     != XpmSuccess)
  712.     return 0 ;
  713.  
  714.     *w =  icon_attributes.width;
  715.     *h =  icon_attributes.height;
  716.     
  717.     *bitmage = XGetImage(Dpl,pix,0,0,*w,*h,AllPlanes,ImaForm) ;
  718.  
  719.     return (1);
  720. }
  721.  
  722. /*------------------------------------------------------------------*/
  723. /* W_CLEARAREA */
  724. void w_cleararea(wd,x1,y1,x2,y2)
  725.          int wd ;
  726.     int x1,y1,x2,y2 ;
  727. {
  728.     XClearArea(Dpl,wd,x1,y1,x2-x1,y2-y1,False);
  729. }
  730.  
  731. /*------------------------------------------------------------------*/
  732. /* W_CLEAR */
  733. void w_clear(wd)
  734.          int wd ;
  735. {
  736.     XClearWindow(Dpl,wd);
  737. }
  738.  
  739. /*---------------------------------------------------------------------*/
  740. /* W_BITMAP */
  741. int w_bitmap(w,h)
  742.     int w,h ;
  743. {
  744.         return (int)XCreatePixmap(Dpl,root,w,h,depth);
  745. }
  746.  
  747. /*------------------------------------------------------------------*/
  748. /* W_MONTRER */
  749. void w_montrer (wd)
  750.         int wd ;
  751. {
  752.   XMapRaised(Dpl,wd);
  753. }
  754.  
  755. /*------------------------------------------------------------------*/
  756. /* W_FLUSH */
  757. void w_flush ()
  758. {
  759.         XSync(Dpl,0);
  760. }
  761.  
  762.                 
  763. /*------------------------------------------------------------------*/
  764. /* W_CACHER */
  765. void w_cacher (wd)
  766.         int wd ;
  767. {
  768.       XUnmapWindow(Dpl,wd);
  769. }
  770.  
  771. /*----------------------------------------------------------------------*/
  772. /* W_RESIZE */
  773. void w_resize(wd,largeur,hauteur)
  774.     int wd;
  775.     int largeur,hauteur ;
  776. {
  777.     XSizeHints hints ;
  778.  
  779.     hints.flags = USSize|PMinSize|PMaxSize ;
  780.     hints.width = largeur ;
  781.     hints.height = hauteur ;
  782.     hints.min_width = largeur ;
  783.     hints.min_height = hauteur ;
  784.     hints.max_width = largeur ;
  785.     hints.max_height = hauteur ;
  786.     XSetNormalHints(Dpl,wd,&hints);
  787.  
  788.     XResizeWindow(Dpl,wd,largeur,hauteur);
  789. }
  790.  
  791. /*------------------------------------------------------------------*/
  792. /*------------------------------------------------------------------*/
  793. /* W_POP */
  794. void w_pop (wd)
  795.         int wd ;
  796.         int px, py ;
  797.     long bidon ;
  798.         Window wind;
  799.     XWindowAttributes watt ;
  800.  
  801.     XGetWindowAttributes(Dpl,wd,&watt);
  802.     XQueryPointer(Dpl,root,&wind,&wind,&px,&py,(int *)&bidon,(int *)&bidon,(unsigned int *)&bidon);
  803.     
  804.     if ((px + watt.width/2) > DisplayWidth(Dpl,screen))
  805.       px = DisplayWidth(Dpl,screen) - watt.width/2 ;
  806.     if ((py + watt.height) > DisplayHeight(Dpl,screen))
  807.       py = DisplayHeight(Dpl,screen) - watt.height ;
  808.  
  809.     XMoveWindow(Dpl,wd,px-watt.width/2,py-7);
  810.     XMapRaised(Dpl,wd);
  811.  
  812. }
  813.  
  814.  
  815. /*----------------------------------------------------------------------*/
  816. /* W_LARGEUR*/
  817. int w_largeur(wd)
  818.     int wd ;
  819. {    XWindowAttributes watt ;
  820.  
  821.     XGetWindowAttributes(Dpl,wd,&watt);
  822.     return(watt.width);
  823. }
  824.  
  825.  
  826. /* ------------------------------------------------------------*/
  827. /* W_STRWIDTH */    
  828. int w_strwidth(s)         /* popup.c l'utilise */
  829.      register char * s;
  830. {  
  831.     return(XTextWidth(ft,s,strlen(s))) ;
  832. }
  833.  
  834. /* ------------------------------------------------------------*/
  835. /* W_CLICK */    
  836.  
  837. Bool fpress (display,event,args)
  838. /** utilisee pour XCheckIfEvent **/
  839.     Display * display ;
  840.     XEvent * event ;
  841.     char * args ;
  842. {
  843.     return ((event->type == ButtonPress)?True:False) ;
  844. }
  845.  
  846.  
  847. int w_click()      /* rends vrai si un event click est arrive */
  848. {  
  849.      XEvent e ;
  850.     return(XCheckIfEvent(Dpl, &e, fpress, NULL) == False);
  851. }
  852.  
  853. /* ------------------------------------------------------------*/
  854. /* W_SETFOCUS */    
  855. void w_setfocus(w)
  856.      int w ;
  857. {
  858.      XSetInputFocus(Dpl,w,RevertToPointerRoot,CurrentTime);
  859. }
  860.  
  861. /* ------------------------------------------------------------*/
  862. /* W_SETROOT */    
  863. void w_setroot(clientimage,x,y,w,h)    
  864.         ClientImage * clientimage ;
  865.     int x,y,w,h ;
  866. {    Pixmap p ;
  867.  
  868.     if (w == 0 ) return ;
  869.     p = w_bitmap(w,h);
  870.  
  871.     XPutImage(Dpl,p,GcColor,
  872.           (XImage *) clientimage, 
  873.           x,y,0,0,w,h);
  874.  
  875.     XSetWindowBackgroundPixmap(Dpl,
  876.                                 RootWindow(Dpl, DefaultScreen(Dpl)),p);
  877.         XClearWindow(Dpl,RootWindow(Dpl, DefaultScreen(Dpl)));
  878.         XFlush(Dpl) ; 
  879. }
  880.  
  881.  
  882. /* ------------------------------------------------------------*/
  883. /* W_NCOLOR */    
  884. int w_ncolor()
  885. /* rends le nombre de couleurs differentes du display */
  886. {
  887.   return DisplayCells(Dpl,screen);
  888.  
  889. }
  890.  
  891.  
  892. /* ------------------------------------------------------------*/
  893. /* W_BLACKPIXEL */    
  894. int w_blackpixel()
  895. /* rends le pixel noir */
  896. {
  897.   return BlackPixel(Dpl,screen);
  898. }
  899.  
  900. /* ------------------------------------------------------------*/
  901. /* W_GREYPIXEL */    
  902. int w_greypixel()
  903. /* rends un pixel gris (compatible w_color) */
  904. {
  905.   XColor def, exact ;
  906.  
  907.   if (depth > 1) {
  908.     XAllocNamedColor(Dpl,colormap,"LightGrey",&def,&exact);
  909.     return def.pixel ;
  910.   } else return PIXELGREY ;
  911. }
  912.  
  913.  
  914. /* ------------------------------------------------------------*/
  915. /* W_CUTBUF */    
  916. char *  w_cutbuf()
  917. /* rends un pointeur sur le cut buffer 0 ou '\0' au moins */
  918. {
  919.   int n,i=0 ;
  920.   char * s ;
  921.   char * buff ;
  922.  
  923.   s = XFetchBytes(Dpl,&n);
  924.   if (s == NULL) buff = (char*) malloc(1) ;
  925.   else {
  926.     buff = (char*) malloc(n+1) ;
  927.     for (i=0 ;i<n ; i++) buff[i] = s[i] ;
  928.   }
  929.   buff[i] = '\0' ;
  930.   return buff ;
  931. }
  932.  
  933. /* ------------------------------------------------------------*/
  934. /* W_NOSAVEUNDER */    
  935. int w_nosaveunder()
  936. {
  937.    return !XDoesSaveUnders(DefaultScreenOfDisplay(Dpl)) ;
  938.  
  939. }
  940.  
  941. /* ------------------------------------------------------------*/
  942. /* W_SETBACK */    
  943. void w_setback(win,pix)    
  944.     int win;
  945.     int pix ;
  946. {
  947.     XSetWindowBackgroundPixmap(Dpl,win,pix);
  948.         XClearWindow(Dpl,win);
  949.         XFlush(Dpl) ; 
  950. }
  951.  
  952. /* ------------------------------------------------------------*/
  953. /* W_CLOSE */    
  954. void w_close()
  955. {
  956.    XCloseDisplay(Dpl);
  957. }
  958.  
  959. /* ------------------------------------------------------------*/
  960. /* W_BACKING */    
  961. void w_backing(wd)
  962.    int wd ;
  963. {
  964.    XSetWindowAttributes wattrib ;
  965.  
  966.    wattrib.backing_store = WhenMapped ;
  967.  
  968.    XChangeWindowAttributes(Dpl,wd,CWBackingStore,&wattrib);
  969. }
  970.