home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / x / x11p-13.zip / do_windows.c < prev    next >
C/C++ Source or Header  |  1989-12-07  |  7KB  |  289 lines

  1. /*****************************************************************************
  2. Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  3.  
  4.                         All Rights Reserved
  5.  
  6. Permission to use, copy, modify, and distribute this software and its 
  7. documentation for any purpose and without fee is hereby granted, 
  8. provided that the above copyright notice appear in all copies and that
  9. both that copyright notice and this permission notice appear in 
  10. supporting documentation, and that the name of Digital not be
  11. used in advertising or publicity pertaining to distribution of the
  12. software without specific, written prior permission.  
  13.  
  14. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20. SOFTWARE.
  21.  
  22. ******************************************************************************/
  23.  
  24. #include "x11perf.h"
  25.  
  26. static Window *parents;
  27. static Window *isolates;
  28. static int childrows, childcolumns, childwindows;
  29. static int parentrows, parentcolumns, parentwindows;
  30. static int parentwidth, parentheight;
  31. static Window popup;
  32.  
  33. void ComputeSizes(xp, p)
  34.     XParms  xp;
  35.     Parms   p;
  36. {
  37.     childwindows = p->objects;
  38.     childrows = (childwindows + MAXCOLS - 1) / MAXCOLS;
  39.     childcolumns = (childrows > 1 ? MAXCOLS : childwindows);
  40.  
  41.     parentwidth = (CHILDSIZE+CHILDSPACE) * childcolumns;
  42.     parentheight = (CHILDSIZE+CHILDSPACE) * childrows;
  43. }
  44.  
  45. int CreateParents(xp, p, reps)
  46.     XParms  xp;
  47.     Parms   p;
  48.     int     reps;
  49. {
  50.     int     i;
  51.  
  52.     ComputeSizes(xp, p);
  53.  
  54.     parentcolumns = WIDTH / parentwidth;
  55.     parentrows = HEIGHT / parentheight;
  56.     parentwindows = parentcolumns * parentrows; /* Max reps we can fit */
  57.  
  58.     if (parentwindows > reps) {
  59.     parentwindows = reps;
  60.     }
  61.  
  62.     /* We will do parentwindows sets of childwindows, in order to get better
  63.        timing accuracy.  Creating 4 windows at a millisecond apiece or so
  64.        is a bit faster than the 60 Hz clock. */
  65.     isolates = (Window *)malloc(parentwindows * sizeof(Window));
  66.     parents = (Window *)malloc(parentwindows * sizeof(Window));
  67.  
  68.     /*
  69.      *  Create isolation windows for the parents, and then the parents
  70.      *  themselves.  These isolation windows ensure that parent and children
  71.      *  windows created/mapped in DoWins and DoWin2 all see the same local
  72.      *  environment...the parent is an only child, and each parent contains
  73.      *  the number of children we are trying to get benchmarks on.
  74.      */
  75.  
  76.     for (i = 0; i != parentwindows; i++) {
  77.     isolates[i] = XCreateSimpleWindow(xp->d, xp->w,
  78.         (i/parentrows)*parentwidth, (i%parentrows)*parentheight,
  79.         parentwidth, parentheight, 0, xp->background, xp->background);
  80.     parents[i] = XCreateSimpleWindow(xp->d, isolates[i],
  81.         0, 0, parentwidth, parentheight, 0, xp->background, xp->background);
  82.     }
  83.  
  84.     XMapSubwindows(xp->d, xp->w);
  85.     return parentwindows;
  86. } /* CreateParents */
  87.  
  88.  
  89. void MapParents(xp, p, reps)
  90.     XParms  xp;
  91.     Parms   p;
  92.     int     reps;
  93. {
  94.     int i;
  95.  
  96.     for (i = 0; i != parentwindows; i++) {
  97.     XMapWindow(xp->d, parents[i]);
  98.     }
  99. }
  100.  
  101.  
  102. int InitCreate(xp, p, reps)
  103.     XParms  xp;
  104.     Parms   p;
  105.     int     reps;
  106. {
  107.     reps = CreateParents(xp, p, reps);
  108.     MapParents(xp, p, reps);
  109.     return reps;
  110. }
  111.  
  112. void CreateChildGroup(xp, p, parent)
  113.     XParms  xp;
  114.     Parms   p;
  115.     Window  parent;
  116. {
  117.     int j;
  118.  
  119.     for (j = 0; j != childwindows; j++) {
  120.     (void) XCreateSimpleWindow (xp->d, parent,
  121.         (CHILDSIZE+CHILDSPACE) * (j/childrows) + CHILDSPACE/2,
  122.         (CHILDSIZE+CHILDSPACE) * (j%childrows) + CHILDSPACE/2,
  123.         CHILDSIZE, CHILDSIZE, 0, xp->background, xp->foreground);
  124.     }
  125.  
  126.     if (p->special)
  127.     XMapSubwindows (xp->d, parent);
  128. }
  129.  
  130. void CreateChildren(xp, p, reps)
  131.     XParms  xp;
  132.     Parms   p;
  133.     int     reps;
  134. {
  135.     int     i;
  136.  
  137.     for (i = 0; i != parentwindows; i++) {
  138.     CreateChildGroup(xp, p, parents[i]);
  139.     } /* end i */
  140. }
  141.  
  142. void DestroyChildren(xp, p, reps)
  143.     XParms  xp;
  144.     Parms   p;
  145.     int     reps;
  146. {
  147.     int i;
  148.  
  149.     for (i = 0; i != parentwindows; i++) {
  150.     XDestroySubwindows(xp->d, parents[i]);
  151.     }
  152. }
  153.  
  154. void EndCreate(xp, p)
  155.     XParms  xp;
  156.     Parms   p;
  157. {
  158.     XDestroySubwindows(xp->d, xp->w);
  159.     free(parents);
  160.     free(isolates);
  161. }
  162.  
  163.  
  164. int InitMap(xp, p, reps)
  165.     XParms  xp;
  166.     Parms   p;
  167.     int     reps;
  168. {
  169.     int i;
  170.  
  171.     reps = CreateParents(xp, p, reps);
  172.     CreateChildren(xp, p, reps);
  173.     return reps;
  174. }
  175.  
  176. void UnmapParents(xp, p, reps)
  177.     XParms  xp;
  178.     Parms   p;
  179.     int     reps;
  180. {
  181.     int i;
  182.  
  183.     for (i = 0; i != parentwindows; i++) {
  184.     XUnmapWindow(xp->d, parents[i]);
  185.     }
  186. }
  187.  
  188. int InitDestroy(xp, p, reps)
  189.     XParms  xp;
  190.     Parms   p;
  191.     int     reps;
  192. {
  193.     reps = CreateParents(xp, p, reps);
  194.     CreateChildren(xp, p, reps);
  195.     MapParents(xp, p, reps);
  196.     return reps;
  197. }
  198.  
  199. void DestroyParents(xp, p, reps)
  200.     XParms  xp;
  201.     Parms   p;
  202.     int     reps;
  203. {
  204.     int i;
  205.  
  206.     for (i = 0; i != parentwindows; i++) {
  207.     XDestroyWindow(xp->d, parents[i]);
  208.     }
  209. }
  210.  
  211.  
  212. void RenewParents(xp, p)
  213.     XParms  xp;
  214.     Parms   p;
  215. {
  216.     int i;
  217.  
  218.     for (i = 0; i != parentwindows; i++) {
  219.     parents[i] = XCreateSimpleWindow(xp->d, isolates[i],
  220.         0, 0, parentwidth, parentheight, 0, xp->background, xp->background);
  221.     }
  222.     CreateChildren(xp, p, parentwindows);
  223.     MapParents(xp, p, parentwindows);
  224. }
  225.  
  226. int InitPopups(xp, p, reps)
  227.     XParms  xp;
  228.     Parms   p;
  229.     int     reps;
  230. {
  231.     XWindowAttributes    xwa;
  232.     XSetWindowAttributes xswa;
  233.     Window isolate;
  234.  
  235. #ifdef CHILDROOT
  236.     ComputeSizes(xp, p);
  237.     CreateChildGroup(xp, p, xp->w);
  238.  
  239.     /* Now create simple window to pop up over children */
  240.     (void) XGetWindowAttributes(xp->d, xp->w, &xwa);
  241.     xswa.override_redirect = True;
  242.     popup =  XCreateSimpleWindow (
  243.         xp->d, DefaultRootWindow(xp->d), 
  244.         xwa.x + xwa.border_width, xwa.y + xwa.border_width,
  245.         parentwidth, parentheight,
  246.         0, xp->foreground, xp->foreground);
  247. #else   
  248.     isolate = XCreateSimpleWindow(
  249.         xp->d, xp->w, 0, 0, WIDTH, HEIGHT,
  250.         0, xp->background, xp->background);
  251.  
  252.     ComputeSizes(xp, p);
  253.     CreateChildGroup(xp, p, isolate);
  254.     XMapWindow(xp->d, isolate);
  255.  
  256.     /* Now create simple window to pop up over children */
  257.     xswa.override_redirect = True;
  258.     popup =  XCreateSimpleWindow (
  259.         xp->d, xp->w, 0, 0,
  260.         parentwidth, parentheight,
  261.         0, xp->foreground, xp->foreground);
  262. #endif
  263.     XChangeWindowAttributes (xp->d, popup, CWOverrideRedirect, &xswa);
  264.     return reps;
  265. }
  266.  
  267. void DoPopUps(xp, p, reps)
  268.     XParms  xp;
  269.     Parms   p;
  270.     int     reps;
  271. {
  272.     int i;
  273.     for (i = 0; i != reps; i++) {
  274.         XMapWindow(xp->d, popup);
  275.     XUnmapWindow(xp->d, popup);
  276.     }
  277. }
  278.  
  279. void EndPopups(xp, p)
  280.     XParms  xp;
  281.     Parms p;
  282. {
  283.     XDestroySubwindows(xp->d, xp->w);
  284. #ifdef CHILDROOT
  285.     XDestroyWindow(xp->d, popup);
  286. #endif
  287. }
  288.  
  289.