|
|
1.1 root 1: #ifndef lint
2: static char *rcsid_Resize_c = "$Header: Resize.c,v 10.4 86/11/19 16:24:34 jg Rel $";
3: #endif lint
4:
5: /*
6: * COPYRIGHT 1985, 1986
7: * DIGITAL EQUIPMENT CORPORATION
8: * MAYNARD, MASSACHUSETTS
9: * ALL RIGHTS RESERVED.
10: *
11: * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
12: * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
13: * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITIBILITY OF THIS SOFTWARE FOR
14: * ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
15: *
16: * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT RIGHTS,
17: * APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN ADDITION TO THAT
18: * SET FORTH ABOVE.
19: *
20: *
21: * Permission to use, copy, modify, and distribute this software and its
22: * documentation for any purpose and without fee is hereby granted, provided
23: * that the above copyright notice appear in all copies and that both that
24: * copyright notice and this permission notice appear in supporting documentation,
25: * and that the name of Digital Equipment Corporation not be used in advertising
26: * or publicity pertaining to distribution of the software without specific,
27: * written prior permission.
28: *
29: */
30:
31:
32: /*
33: * MODIFICATION HISTORY
34: *
35: * 000 -- M. Gancarz, DEC Ultrix Engineering Group
36: */
37:
38: #ifndef lint
39: static char *sccsid = "@(#)Resize.c 3.8 1/24/86";
40: #endif
41:
42: #include "uwm.h"
43:
44: Bool Resize(window, mask, button, x0, y0)
45: Window window; /* Event window. */
46: int mask; /* Button/key mask. */
47: short button; /* Button event detail. */
48: int x0, y0; /* Event mouse position. */
49: {
50: register WindowInfo window_info; /* Event window info. */
51: register WindowInfo assoc_info; /* Icon's associated window info. */
52: int d; /* ??? */
53: int t; /* ??? */
54: int x, y; /* ??? */
55: int h0, hinc, w0, winc, wadd, hadd; /* ??? */
56: int x1, y1, x2, y2; /* ??? */
57: int mx, my; /* ??? */
58: int ox, oy; /* ??? */
59: int lx, ly; /* ??? */
60: int pop_x, pop_y; /* ??? */
61: int hsize, vsize; /* ??? */
62: int dx, dy; /* ??? */
63: int num_vectors; /* Number of vectors to XDraw. */
64: Window assoc; /* Window represented by the icon. */
65: Window sub_win; /* Mouse query sub window. */
66: XButtonEvent button_event; /* Button event packet. */
67: Vertex box[MAX_BOX_VECTORS]; /* Box drawing vertex buffer. */
68: Vertex zap[MAX_ZAP_VECTORS]; /* Zap drawing vertex buffer. */
69: Bool domult; /* ??? */
70: Bool stop; /* Should the window stop changing? */
71:
72: /*
73: * Do nothing if the event window is the root window.
74: */
75: if (window == RootWindow)
76: return(FALSE);
77:
78: /*
79: * Gather info about the event window.
80: */
81: status = XQueryWindow(window, &window_info);
82: if (status == FAILURE) return(FALSE);
83:
84: /*
85: * Do not resize an icon window.
86: */
87: if (window_info.type == IsIcon)
88: return(FALSE);
89:
90: /*
91: * Clear the vector buffers.
92: */
93: bzero(box, sizeof(box));
94: if (Zap) bzero(zap, sizeof(zap));
95:
96: /*
97: * If we are here then we have a resize operation in progress.
98: */
99:
100: /*
101: * Turn on the resize cursor.
102: */
103: status = XGrabButton(RootWindow, ArrowCrossCursor, mask, EVENTMASK);
104: if (status == FAILURE) {
105: Error("Resize -> Unable to grab button and change cursor.");
106: }
107:
108: /*
109: * Get the event window resize hint.
110: */
111: XGetResizeHint(window, &w0, &h0, &winc, &hinc);
112:
113: /*
114: * If I ever have the time to REALLY figure the rest of this out I will
115: * comment it better.
116: */
117: wadd = winc >> 1;
118: hadd = hinc >> 1;
119: x1 = window_info.x;
120: y1 = window_info.y;
121: x2 = x1 + window_info.width + (window_info.bdrwidth << 1) - 1;
122: y2 = y1 + window_info.height + (window_info.bdrwidth << 1) - 1;
123: domult = (winc > 3 && hinc > 3 &&
124: (window_info.width - w0) % winc == 0 &&
125: (window_info.height - h0) % hinc == 0) ? TRUE : FALSE;
126: if (w0 == 0 && winc == 1 && h0 == 0 && hinc == 1) {
127: w0 = h0 = 1;
128: }
129: mx = x2 - window_info.width + w0 + winc;
130: my = y2 - window_info.height + h0 + hinc;
131: w0 += (window_info.bdrwidth << 1) - 1;
132: h0 += (window_info.bdrwidth << 1) - 1;
133: x = x2;
134: y = y2;
135: dx = dy = 1;
136: if (x0 - x1 < x2 - x0) {
137: dx = -1;
138: x = x1;
139: mx = x2 - (mx - x1);
140: t = x1; x1 = x2; x2 = t;
141: }
142: if (y0 - y1 < y2 - y0) {
143: dy = -1;
144: y = y1;
145: my = y2 - (my - y1);
146: t = y1; y1 = y2; y2 = t;
147: }
148: ox = ((x0 - window_info.x - window_info.bdrwidth) * 3) /
149: window_info.width;
150: oy = ((y0 - window_info.y - window_info.bdrwidth) * 3) /
151: window_info.height;
152: if (window_info.width > 2 && window_info.height > 2 && ((ox + oy) & 1)) {
153: if (ox & 1)
154: dx = 0;
155: else
156: dy = 0;
157: }
158:
159: if (Grid) {
160: num_vectors = StoreGridBox(
161: box,
162: MIN(x1, x), MIN(y1, y),
163: MAX(x1, x), MAX(y1, y)
164: );
165: }
166: else {
167: num_vectors = StoreBox(
168: box,
169: MIN(x1, x), MIN(y1, y),
170: MAX(x1, x), MAX(y1, y)
171: );
172: }
173:
174: /*
175: * If we freeze the server, then we will draw solid
176: * lines instead of flickering ones during resizing.
177: */
178: if (Freeze) XGrabServer();
179:
180: /*
181: * Process any pending exposure events before drawing the box.
182: */
183: while (QLength() > 0) {
184: XPeekEvent(&button_event);
185: if (button_event.window == RootWindow)
186: break;
187: GetButton(&button_event);
188: }
189:
190: /*
191: * Now draw the box.
192: */
193: DrawBox();
194: Frozen = window;
195:
196: stop = FALSE;
197: ox = oy = lx = ly = -1;
198:
199: while (!stop) {
200: if (x != ox || y != oy) {
201:
202: /*
203: * If we've frozen the server, then erase
204: * the old box.
205: */
206: if (Freeze)
207: DrawBox();
208:
209: if (Grid) {
210: num_vectors = StoreGridBox(
211: box,
212: MIN(x1, x), MIN(y1, y),
213: MAX(x1, x), MAX(y1, y)
214: );
215: }
216: else {
217: num_vectors = StoreBox(
218: box,
219: MIN(x1, x), MIN(y1, y),
220: MAX(x1, x), MAX(y1, y)
221: );
222: }
223:
224: if (Freeze)
225: DrawBox();
226:
227: if (domult) {
228: hsize = (abs(x - x1) - w0) / winc;
229: vsize = (abs(y - y1) - h0) / hinc;
230: PText[0] = hsize / 100 + '0';
231: PText[1] = (hsize / 10) % 10 + '0';
232: PText[2] = hsize % 10 + '0';
233: PText[4] = vsize / 100 + '0';
234: PText[5] = (vsize / 10) % 10 + '0';
235: PText[6] = vsize % 10 + '0';
236:
237: /*
238: * If the font is not fixed width we have to
239: * clear the window to guarantee that the characters
240: * that were there before are erased.
241: */
242: if (!(PFontInfo.fixedwidth)) XClear(Pop);
243: XTextPad (
244: Pop,
245: PPadding, PPadding,
246: PText, PTextSize,
247: PFont, 0, 0,
248: PTextForground, PTextBackground,
249: GXcopy, AllPlanes
250: );
251: }
252: ox = x;
253: oy = y;
254: }
255:
256: if (!Freeze) {
257: DrawBox();
258: DrawBox();
259: }
260:
261: if (XPending() && GetButton(&button_event)) {
262:
263: if (Freeze) {
264: DrawBox();
265: Frozen = (Window)0;
266: XUngrabServer();
267: }
268:
269: if (
270: (button_event.type == ButtonReleased) &&
271: ((button_event.detail & ValueMask) == button)
272: ){
273: x = button_event.x;
274: y = button_event.y;
275: stop = TRUE;
276: }
277: else {
278: if (domult) {
279: XUnmapWindow(Pop);
280: }
281: Grab(mask);
282: return(TRUE);
283: }
284: }
285: else {
286: XUpdateMouse(RootWindow, &x, &y, &sub_win);
287: }
288:
289: if (x == lx && y == ly) {
290: x = ox;
291: y = oy;
292: continue;
293: }
294:
295: lx = x;
296: ly = y;
297:
298: if (dx)
299: ox = -1;
300: else
301: oy = -1;
302: if (domult) {
303: if (dx > 0)
304: pop_x = x1 + window_info.bdrwidth;
305: else if (dx < 0)
306: pop_x = x1 - PWidth - window_info.bdrwidth + 1;
307: else
308: pop_x = window_info.x + window_info.bdrwidth +
309: (window_info.width - PWidth) / 2;
310: if (dy > 0)
311: pop_y = y1 + window_info.bdrwidth;
312: else if (dy < 0)
313: pop_y = y1 - PHeight - window_info.bdrwidth + 1;
314: else
315: pop_y = window_info.y + window_info.bdrwidth +
316: (window_info.height - PHeight) / 2;
317: XMoveWindow(Pop, pop_x, pop_y);
318: XMapWindow(Pop);
319: }
320:
321: if (dx) {
322: if ((d = abs(x - x0) + wadd) < 0)
323: d = 0;
324: d = (d / winc) * winc;
325: if (x < x0) {
326: x = x2 - d;
327: if (dx > 0 && x < mx)
328: x = mx;
329: } else {
330: x = x2 + d;
331: if (dx < 0 && x > mx)
332: x = mx;
333: }
334: } else
335: x = ox;
336: if (dy) {
337: if ((d = abs(y - y0) + hadd) < 0)
338: d = 0;
339: d = (d / hinc) * hinc;
340: if (y < y0) {
341: y = y2 - d;
342: if (dy > 0 && y < my)
343: y = my;
344: } else {
345: y = y2 + d;
346: if (dy < 0 && y > my)
347: y = my;
348: }
349: } else
350: y = oy;
351: }
352: if (x == x2 && y == y2) {
353: XUnmapWindow(Pop);
354: XRaiseWindow(window);
355: } else {
356: if (x < x1) {
357: t = x1; x1 = x; x = t;
358: }
359: if (y < y1) {
360: t = y1; y1 = y; y = t;
361: }
362: dx = x - x1 + 1 - (window_info.bdrwidth << 1);
363: dy = y - y1 + 1 - (window_info.bdrwidth << 1);
364: if (
365: (PWidth > window_info.width) ||
366: (PHeight > window_info.height) ||
367: (PWidth > dx) ||
368: (PHeight > dy)
369: ) {
370: XUnmapWindow(Pop);
371: }
372: else {
373: XUnmapTransparent(Pop);
374: }
375: XConfigureWindow(window, x1, y1, dx, dy);
376: }
377: Grab(mask);
378: return(TRUE);
379: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.