|
|
1.1 root 1: #ifndef lint
2: static char *rcsid_Iconify_c = "$Header: Iconify.c,v 10.5 86/11/19 16:23:46 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 = "@(#)Iconify.c 3.9 1/29/86";
40: #endif
41:
42: #include "uwm.h"
43:
44: Bool Iconify(window, mask, button, x, y)
45: Window window; /* Event window. */
46: int mask; /* Button/key mask. */
47: short button; /* Button event detail. */
48: int x, y; /* Event mouse position. */
49: {
50: register WindowInfo window_info; /* Event window info. */
51: register WindowInfo assoc_info; /* Associated window info. */
52: char *name; /* Event window name. */
53: int mse_x, mse_y; /* Mouse X and Y coordinates. */
54: int icon_x, icon_y; /* Icon U. L. X and Y coordinates. */
55: int icon_w, icon_h; /* Icon width and height. */
56: int icon_bdr; /* Icon border width. */
57: int num_vectors; /* Number of vectors in zap buffer. */
58: Window assoc; /* Associated window. */
59: Window sub_win; /* Mouse position sub-window. */
60: XButtonEvent button_event; /* Button event packet. */
61: Vertex zap[MAX_ZAP_VECTORS]; /* Zap effect vertex buffer. */
62: Bool iconifying; /* Are we iconifying? */
63:
64: /*
65: * Do not try to iconify the root window.
66: */
67: if (window == RootWindow)
68: return(FALSE);
69:
70: /*
71: * Clear the vector buffer.
72: */
73: if (Zap) bzero(zap, sizeof(zap));
74:
75: /*
76: * Get the mouse cursor position in case we must put a new
77: * icon there.
78: */
79: XQueryMouse(RootWindow, &mse_x, &mse_y, &sub_win);
80:
81: /*
82: * Get info on the event window.
83: */
84: status = XQueryWindow(window, &window_info);
85: if (status == FAILURE) return(FALSE);
86:
87: /*
88: * If the event window is an icon, de-iconify it and return.
89: */
90: if (window_info.type == IsIcon) {
91:
92: assoc = window_info.assoc_wind;
93:
94: /*
95: * Gather info about the assoc window.
96: */
97: status = XQueryWindow(assoc, &assoc_info);
98: if (status == FAILURE) return(FALSE);
99:
100: /*
101: * Store the zap vector buffer.
102: */
103: if (Zap) {
104: num_vectors = StoreZap(
105: zap,
106: assoc_info.x - 1,
107: assoc_info.y - 1,
108: assoc_info.x + assoc_info.width +
109: (assoc_info.bdrwidth << 1),
110: assoc_info.y + assoc_info.height +
111: (assoc_info.bdrwidth << 1),
112: window_info.x - 1,
113: window_info.y - 1,
114: window_info.x + window_info.width +
115: (window_info.bdrwidth << 1),
116: window_info.y + window_info.height +
117: (window_info.bdrwidth << 1));
118: }
119:
120: /*
121: * Map the window and synchronize.
122: */
123: XMapWindow(assoc);
124:
125: if (Zap) {
126: /*
127: * Draw the zap lines.
128: */
129: DrawZap();
130: }
131:
132: /*
133: * Unmap the icon window.
134: */
135: XUnmapWindow(window);
136:
137: return(FALSE);
138: }
139: else {
140: /*
141: * If event window doesn't already have an icon window,
142: * make one for it.
143: */
144: if (window_info.assoc_wind == 0) {
145:
146: /*
147: * Set the icon border width.
148: */
149: icon_bdr = IBorderWidth;
150:
151: /*
152: * Determine the size of the icon window.
153: */
154: status = XFetchName(window, &name);
155: if (status == FAILURE) return(FALSE);
156: icon_h = IFontInfo.height + (VIconPad << 1);
157: icon_w = XQueryWidth(name, IFont);
158: if (icon_w == 0)
159: icon_w = icon_h;
160: else icon_w += (HIconPad << 1);
161:
162: /*
163: * Determine the coordinates of the icon window;
164: * normalize so that we don't lose the icon off the
165: * edge of the screen.
166: */
167: icon_x = mse_x - (icon_w >> 1) + 1;
168: if (icon_x < 0) icon_x = 0;
169: icon_y = mse_y - (icon_h >> 1) + 1;
170: if (icon_y < 0) icon_y = 0;
171: if ((icon_x - 1 + icon_w + (icon_bdr << 1)) > ScreenWidth) {
172: icon_x = ScreenWidth - icon_w - (icon_bdr << 1) + 1;
173: }
174: if ((icon_y - 1 + icon_h + (icon_bdr << 1)) > ScreenHeight) {
175: icon_y = ScreenHeight - icon_h - (icon_bdr << 1) + 1;
176: }
177:
178:
179: /*
180: * Create the icon window.
181: */
182: assoc = XCreateWindow(
183: RootWindow,
184: icon_x, icon_y,
185: icon_w, icon_h,
186: icon_bdr,
187: IBorder, IBackground
188: );
189: if (assoc == FAILURE) return(FALSE);
190:
191: /*
192: * Use the text cursor whenever the mouse is in the icon window.
193: */
194: XDefineCursor(assoc, TextCursor);
195:
196: /*
197: * Select "key pressed", "window exposure" and "unmap window"
198: * events for the icon window.
199: */
200: XSelectInput(assoc, (KeyPressed | ExposeWindow | UnmapWindow));
201:
202: /*
203: * Set the event window's icon window to be the new icon window.
204: */
205: XSetIconWindow(window, assoc);
206: }
207: else {
208: /*
209: * If we already have an icon window all we have to do is
210: * map it.
211: */
212: assoc = window_info.assoc_wind;
213: status = XQueryWindow(assoc, &assoc_info);
214: if (status == FAILURE) return(FALSE);
215: icon_x = assoc_info.x;
216: icon_y = assoc_info.y;
217: icon_w = assoc_info.width;
218: icon_h = assoc_info.height;
219: }
220:
221: if (Zap) {
222: /*
223: * Store the zap effect vectors.
224: */
225: num_vectors = StoreZap(
226: zap,
227: window_info.x - 1,
228: window_info.y - 1,
229: window_info.x + window_info.width + (window_info.bdrwidth << 1),
230: window_info.y + window_info.height + (window_info.bdrwidth << 1),
231: icon_x - 1,
232: icon_y - 1,
233: icon_x + icon_w + (icon_bdr << 1),
234: icon_y + icon_h + (icon_bdr << 1)
235: );
236: }
237:
238: /*
239: * Map the icon window.
240: */
241: XMapWindow(assoc);
242:
243: if (Zap) {
244: /*
245: * Draw zap lines from the window to its icon.
246: */
247: DrawZap();
248: DrawZap();
249: }
250:
251: /*
252: * Unmap the event window.
253: */
254: XUnmapWindow(window);
255: }
256: return(FALSE);
257: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.