home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / awm2 / part09 / Push.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-20  |  5.2 KB  |  191 lines

  1.  
  2.  
  3.  
  4. #ifndef lint
  5. static char *rcsid_Push_c = "$Header: /usr/graph2/X11.3/contrib/windowmgrs/awm/RCS/Push.c,v 1.2 89/02/07 21:23:21 jkh Exp $";
  6. #endif    lint
  7.  
  8. #include "X11/copyright.h"
  9. /*
  10.  *
  11.  * Copyright 1987, 1988 by Ardent Computer Corporation, Sunnyvale, Ca.
  12.  *
  13.  * Copyright 1987 by Jordan Hubbard.
  14.  *
  15.  *
  16.  *                         All Rights Reserved
  17.  *
  18.  * Permission to use, copy, modify, and distribute this software and its
  19.  * documentation for any purpose and without fee is hereby granted,
  20.  * provided that the above copyright notice appear in all copies and that
  21.  * both that copyright notice and this permission notice appear in
  22.  * supporting documentation, and that the name of Ardent Computer
  23.  * Corporation or Jordan Hubbard not be used in advertising or publicity
  24.  * pertaining to distribution of the software without specific, written
  25.  * prior permission.
  26.  *
  27.  */
  28.  
  29. /*
  30.  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  31.  *
  32.  *                         All Rights Reserved
  33.  *
  34.  * Permission to use, copy, modify, and distribute this software and its
  35.  * documentation for any purpose and without fee is hereby granted,
  36.  * provided that the above copyright notice appear in all copies and that
  37.  * both that copyright notice and this permission notice appear in
  38.  * supporting documentation, and that the name of Digital Equipment
  39.  * Corporation not be used in advertising or publicity pertaining to
  40.  * distribution of the software without specific, written prior permission.
  41.  *
  42.  *
  43.  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  44.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  45.  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  46.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  47.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  48.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  49.  * SOFTWARE.
  50.  */
  51.  
  52.  
  53.  
  54. /*
  55.  * MODIFICATION HISTORY
  56.  *
  57.  * 000 -- M. Gancarz, DEC Ultrix Engineering Group
  58.  * 001 -- Loretta Guarino Reid, DEC Ultrix Engineering Group,
  59.     Western Software Lab. Convert to X11.
  60.  */
  61.  
  62. #include "awm.h"
  63.  
  64. #define SHOVE_DOWN    1
  65. #define SHOVE_UP        2
  66. #define SHOVE_LEFT    3
  67. #define SHOVE_RIGHT    4
  68.  
  69. extern Boolean ShoveAll();
  70.  
  71. /*ARGSUSED*/
  72. Boolean ShoveDown(window, mask, button, x, y)
  73. Window window;                /* Event window. */
  74. int mask;                /* Button/key mask. */
  75. int button;                /* Button event detail. */
  76. int x, y;                /* Event mouse position. */
  77. {
  78.     Entry("ShoveDown")
  79.  
  80.     Leave(ShoveAll(window, SHOVE_DOWN))
  81. }
  82.  
  83. /*ARGSUSED*/
  84. Boolean ShoveUp(window, mask, button, x, y)
  85. Window window;                /* Event window. */
  86. int mask;                /* Button/key mask. */
  87. int button;                /* Button event detail. */
  88. int x, y;                /* Event mouse position. */
  89. {
  90.     Entry("ShoveUp")
  91.  
  92.     Leave(ShoveAll(window, SHOVE_UP))
  93. }
  94.  
  95. /*ARGSUSED*/
  96. Boolean ShoveLeft(window, mask, button, x, y)
  97. Window window;                /* Event window. */
  98. int mask;                /* Button/key mask. */
  99. int button;                /* Button event detail. */
  100. int x, y;                /* Event mouse position. */
  101. {
  102.     Entry("ShoveLeft")
  103.  
  104.     Leave(ShoveAll(window, SHOVE_LEFT))
  105. }
  106.  
  107. /*ARGSUSED*/
  108. Boolean ShoveRight(window, mask, button, x, y)
  109. Window window;                /* Event window. */
  110. int mask;                /* Button/key mask. */
  111. int button;                /* Button event detail. */
  112. int x, y;                /* Event mouse position. */
  113. {
  114.     Entry("ShoveRight")
  115.  
  116.     Leave(ShoveAll(window, SHOVE_RIGHT))
  117. }
  118.  
  119. Boolean ShoveAll(w, direction)
  120. Window w;
  121. int direction;
  122. {
  123.     XWindowAttributes winfo;            /* Event window information. */
  124.     int xofs, yofs;            /* Movement offsets. */
  125.     int x, y;                /* New window position. */
  126.  
  127.     Entry("ShoveAll")
  128.  
  129.     /*
  130.      * Do not try to move the root window.
  131.      */
  132.     if (w == RootWindow(dpy, scr))
  133.         Leave(FALSE)
  134.  
  135.     /*
  136.      * Gather info on the event window.
  137.      */
  138.     status = XGetWindowAttributes(dpy, w, &winfo);
  139.     if (status == FAILURE) Leave(FALSE)
  140.     if (!Pushval && Push)
  141.      Pushval = DEF_PUSH;
  142.  
  143.     /*
  144.      * Calculate the movement offsets.
  145.      */
  146.     switch(direction) {
  147.     case SHOVE_DOWN:
  148.         xofs = 0;
  149.         yofs = Push ? (winfo.height / Pushval) : Pushval;
  150.         break;
  151.     case SHOVE_UP:
  152.         xofs = 0;
  153.         yofs = 0 - (Push ? (winfo.height / Pushval) : Pushval);
  154.         break;
  155.     case SHOVE_LEFT:
  156.         xofs = 0 - (Push ? (winfo.width / Pushval) : Pushval);
  157.         yofs = 0;
  158.         break;
  159.     case SHOVE_RIGHT:
  160.         xofs = Push ? (winfo.width / Pushval) : Pushval;
  161.         yofs = 0;
  162.         break;
  163.     }
  164.  
  165.     /*
  166.      * Calculate the new window position.
  167.      */
  168.     x = winfo.x + xofs;
  169.     y = winfo.y + yofs;
  170.  
  171.     /*
  172.      * Normalize the new window coordinates so we don't
  173.      * lose the window off the edge of the screen.
  174.      */
  175.     if (x < (0 - winfo.width + CURSOR_WIDTH - (winfo.border_width << 1)))
  176.         x = 0 - winfo.width + CURSOR_WIDTH - (winfo.border_width << 1);
  177.     if (y < (0 - winfo.height + CURSOR_HEIGHT - (winfo.border_width << 1)))
  178.         y = 0 - winfo.height + CURSOR_HEIGHT - (winfo.border_width << 1);
  179.     if (x > (ScreenWidth - CURSOR_WIDTH))
  180.         x = ScreenWidth - CURSOR_WIDTH;
  181.     if (y > (ScreenHeight - CURSOR_HEIGHT))
  182.         y = ScreenHeight - CURSOR_HEIGHT;
  183.  
  184.     /*
  185.      * Move the window into place.
  186.      */
  187.     XMoveWindow(dpy, w, x, y);
  188.  
  189.     Leave(FALSE)
  190. }
  191.