home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /** Copyright 1988 by Evans & Sutherland Computer Corporation, **/
- /** Salt Lake City, Utah **/
- /** **/
- /** All Rights Reserved **/
- /** **/
- /** Permission to use, copy, modify, and distribute this software and **/
- /** its documentation for any purpose and without fee is hereby **/
- /** granted, provided that the above copyright notice appear in all **/
- /** copies and that both that copyright notice and this permis- **/
- /** sion notice appear in supporting documentation, and that the **/
- /** name of Evans & Sutherland not be used in advertising or publi- **/
- /** city pertaining to distribution of the software without specif- **/
- /** ic, written prior permission. **/
- /** **/
- /** EVANS & SUTHERLAND DISCLAIMS ALL WARRANTIES WITH REGARD TO **/
- /** THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI- **/
- /** TY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND BE LIABLE **/
- /** FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAM- **/
- /** AGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, **/
- /** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS **/
- /** ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER- **/
- /** FORMANCE OF THIS SOFTWARE. **/
- /*****************************************************************************/
-
- /***********************************************************************
- *
- * $Header: resize.c,v 1.6 88/04/15 07:09:35 tlastran Exp $
- *
- * window resizing borrowed from the "wm" window manager
- *
- * 11-Dec-87 Thomas E. LaStrange File created
- *
- ***********************************************************************/
-
- #ifndef lint
- static char RCSinfo[]=
- "$Header: resize.c,v 1.6 88/04/15 07:09:35 tlastran Exp $";
- #endif
-
- #include <stdio.h>
- #include "twm.h"
- #include "util.h"
- #include "resize.h"
- #include "resize.bm"
- #include "focus.bm"
-
- #define MINHEIGHT 32
- #define MINWIDTH 60
-
- static int dragx; /* all these variables are used */
- static int dragy; /* in resize operations */
- static int dragWidth;
- static int dragHeight;
-
- static int origx;
- static int origy;
- static int origWidth;
- static int origHeight;
-
- static int clampTop;
- static int clampBottom;
- static int clampLeft;
- static int clampRight;
-
- /***********************************************************************
- *
- * Procedure:
- * StartResize - begin a window resize operation
- *
- * Inputs:
- * ev - the event structure (button press)
- * tmp_win - the TwmWindow pointer
- *
- ***********************************************************************
- */
-
- void
- StartResize(ev, tmp_win)
- XEvent ev;
- TwmWindow *tmp_win;
- {
- Window junkRoot;
- int junkbw, junkDepth;
-
- XMapRaised(dpy, SizeWindow);
- ResizeWindow = tmp_win->frame;
- XGrabServer(dpy);
- XGrabPointer(dpy, ev.xbutton.root, True,
- ButtonReleaseMask | PointerMotionMask,
- GrabModeAsync, GrabModeSync,
- Root, MoveCursor, CurrentTime);
-
- XGetGeometry(dpy, (Drawable) tmp_win->frame, &junkRoot,
- &dragx, &dragy, &dragWidth, &dragHeight, &junkbw,
- &junkDepth);
- dragx += BorderWidth;
- dragy += BorderWidth;
- origx = dragx;
- origy = dragy;
- origWidth = dragWidth;
- origHeight = dragHeight;
- clampTop = clampBottom = clampLeft = clampRight = 0;
-
- DisplaySize(tmp_win, origWidth, origHeight);
- }
-
- /***********************************************************************
- *
- * Procedure:
- * DoResize - move the rubberband around. This is called for
- * each motion event when we are resizing
- *
- * Inputs:
- * ev - the event structure for the motion event
- * tmp_win - the current twm window
- *
- ***********************************************************************
- */
-
- void
- DoResize(ev, tmp_win)
- XEvent ev;
- TwmWindow *tmp_win;
- {
- int action;
-
- action = 0;
-
- if (clampTop) {
- int delta = ev.xmotion.y_root - dragy;
- if (dragHeight - delta < MINHEIGHT) {
- delta = dragHeight - MINHEIGHT;
- clampTop = 0;
- }
- dragy += delta;
- dragHeight -= delta;
- action = 1;
- }
- else if (ev.xmotion.y_root <= dragy/* ||
- ev.xmotion.y_root == findRootInfo(root)->rooty*/) {
- dragy = ev.xmotion.y_root;
- dragHeight = origy + origHeight -
- ev.xmotion.y_root;
- clampBottom = 0;
- clampTop = 1;
- action = 1;
- }
- if (clampLeft) {
- int delta = ev.xmotion.x_root - dragx;
- if (dragWidth - delta < MINWIDTH) {
- delta = dragWidth - MINWIDTH;
- clampLeft = 0;
- }
- dragx += delta;
- dragWidth -= delta;
- action = 1;
- }
- else if (ev.xmotion.x_root <= dragx/* ||
- ev.xmotion.x_root == findRootInfo(root)->rootx*/) {
- dragx = ev.xmotion.x_root;
- dragWidth = origx + origWidth -
- ev.xmotion.x_root;
- clampRight = 0;
- clampLeft = 1;
- action = 1;
- }
- if (clampBottom) {
- int delta = ev.xmotion.y_root - dragy - dragHeight;
- if (dragHeight + delta < MINHEIGHT) {
- delta = MINHEIGHT - dragHeight;
- clampBottom = 0;
- }
- dragHeight += delta;
- action = 1;
- }
- else if (ev.xmotion.y_root >= dragy + dragHeight - 1/* ||
- ev.xmotion.y_root == findRootInfo(root)->rooty
- + findRootInfo(root)->rootheight - 1*/) {
- dragy = origy;
- dragHeight = 1 + ev.xmotion.y_root - dragy;
- clampTop = 0;
- clampBottom = 1;
- action = 1;
- }
- if (clampRight) {
- int delta = ev.xmotion.x_root - dragx - dragWidth;
- if (dragWidth + delta < MINWIDTH) {
- delta = MINWIDTH - dragWidth;
- clampRight = 0;
- }
- dragWidth += delta;
- action = 1;
- }
- else if (ev.xmotion.x_root >= dragx + dragWidth - 1/* ||
- ev.xmotion.x_root == findRootInfo(root)->rootx +
- findRootInfo(root)->rootwidth - 1*/) {
- dragx = origx;
- dragWidth = 1 + ev.xmotion.x_root - origx;
- clampLeft = 0;
- clampRight = 1;
- action = 1;
- }
- if (action) {
- MoveOutline(Root,
- dragx - BorderWidth,
- dragy - BorderWidth,
- dragWidth + 2 * BorderWidth,
- dragHeight + 2 * BorderWidth);
- }
-
- DisplaySize(tmp_win, dragWidth, dragHeight);
- }
-
- /***********************************************************************
- *
- * Procedure:
- * DisplaySize - display the size in the dimensions window
- *
- * Inputs:
- * tmp_win - the current twm window
- * width - the width of the rubber band
- * height - the height of the rubber band
- *
- ***********************************************************************
- */
-
- void
- DisplaySize(tmp_win, width, height)
- TwmWindow *tmp_win;
- int width;
- int height;
- {
- char str[100];
- int dwidth;
- int dheight;
-
- dwidth = width;
- dheight = height - tmp_win->title_height;
-
- if (tmp_win->hints.flags&PMinSize && tmp_win->hints.flags & PResizeInc)
- {
- dwidth -= tmp_win->hints.min_width;
- dheight -= tmp_win->hints.min_height;
- }
-
- if (tmp_win->hints.flags & PResizeInc)
- {
- dwidth /= tmp_win->hints.width_inc;
- dheight /= tmp_win->hints.height_inc;
- }
-
- sprintf(str, "%d x %d", dwidth, dheight);
-
- width = XTextWidth(SizeFont, str, strlen(str)) + 20,
- strcat(str, " ");
- XResizeWindow(dpy, SizeWindow, width, SizeFontHeight + 4);
- XRaiseWindow(dpy, SizeWindow);
- XDrawImageString(dpy, SizeWindow, SizeNormalGC,
- 10, 2 + SizeFont->ascent, str, strlen(str));
- }
-
- /***********************************************************************
- *
- * Procedure:
- * EndResize - finish the resize operation
- *
- ***********************************************************************
- */
-
- void
- EndResize()
- {
- TwmWindow *tmp_win;
-
- XUnmapWindow(dpy, SizeWindow);
- MoveOutline(Root, 0, 0, 0, 0);
-
- XFindContext(dpy, ResizeWindow, TwmContext, &tmp_win);
-
- dragHeight = dragHeight - tmp_win->title_height;
-
- if (tmp_win->hints.flags&PMinSize && tmp_win->hints.flags & PResizeInc)
- {
- dragWidth -= tmp_win->hints.min_width;
- dragHeight -= tmp_win->hints.min_height;
- }
-
- if (tmp_win->hints.flags & PResizeInc)
- {
- dragWidth /= tmp_win->hints.width_inc;
- dragHeight /= tmp_win->hints.height_inc;
-
- dragWidth *= tmp_win->hints.width_inc;
- dragHeight *= tmp_win->hints.height_inc;
- }
-
- if (tmp_win->hints.flags&PMinSize && tmp_win->hints.flags & PResizeInc)
- {
- dragWidth += tmp_win->hints.min_width;
- dragHeight += tmp_win->hints.min_height;
- }
-
- dragHeight = dragHeight + tmp_win->title_height;
-
- SetupWindow(tmp_win,
- dragx - BorderWidth,
- dragy - BorderWidth,
- dragWidth, dragHeight);
-
- XRaiseWindow(dpy, ResizeWindow);
- ResizeWindow = NULL;
- }
-
- /***********************************************************************
- *
- * Procedure:
- * SetupWindow - set window sizes, this was called from either
- * AddWindow, EndResize, or HandleConfigureNotify.
- *
- * Inputs:
- * tmp_win - the TwmWindow pointer
- * x - the x coordinate of the frame window
- * y - the y coordinate of the frame window
- * w - the width of the frame window
- * h - the height of the frame window
- *
- ***********************************************************************
- */
-
- void
- SetupWindow(tmp_win, x, y, w, h)
- TwmWindow *tmp_win;
- int x, y, w, h;
- {
- XWindowChanges xwc;
- unsigned int xwcm;
- int width;
-
- tmp_win->frame_x = x;
- tmp_win->frame_y = y;
-
- xwcm = CWX | CWY | CWWidth | CWHeight;
-
- xwc.x = x;
- xwc.y = y;
- xwc.width = w;
- xwc.height = h;
- XConfigureWindow(dpy, tmp_win->frame, xwcm, &xwc);
-
- xwcm = CWWidth;
- XConfigureWindow(dpy, tmp_win->title_w, xwcm, &xwc);
-
- xwcm |= CWX | CWY | CWHeight;
- xwc.x = 0;
- xwc.y = tmp_win->title_height;
- xwc.height = h - tmp_win->title_height;
- XConfigureWindow(dpy, tmp_win->w, xwcm, &xwc);
-
- xwcm = CWX;
- xwc.x = w - resize_width - 1;
- XConfigureWindow(dpy, tmp_win->resize_w, xwcm, &xwc);
-
- xwc.x = w - resize_width - focus_width - 3;
- XConfigureWindow(dpy, tmp_win->focus_w, xwcm, &xwc);
-
- width = w - TitleBarX - focus_width - resize_width - 5 -
- tmp_win->name_width - 10;
-
- if (width <= 0)
- {
- xwc.x = 3000;
- xwc.width = 1;
- }
- else
- {
- xwc.x = TitleBarX + tmp_win->name_width + 6;
- xwc.width = width;
- }
-
- xwcm = CWX | CWWidth;
- XConfigureWindow(dpy, tmp_win->hilite_w, xwcm, &xwc);
- }
-