Commit | Line | Data |
---|---|---|
f10de189 GM |
1 | /* Copyright Massachusetts Institute of Technology 1985 */ |
2 | ||
e745ede7 DL |
3 | #include "copyright.h" |
4 | ||
f10de189 | 5 | /* |
73b0cd50 | 6 | Copyright (C) 1993, 1996, 2001-2011 Free Software Foundation, Inc. |
f10de189 | 7 | |
4eaa4034 | 8 | This program is free software: you can redistribute it and/or modify |
f10de189 | 9 | it under the terms of the GNU General Public License as published by |
4eaa4034 GM |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
f10de189 GM |
12 | |
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
4eaa4034 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
f10de189 | 20 | |
e745ede7 DL |
21 | |
22 | /* | |
23 | * XMenu: MIT Project Athena, X Window system menu package | |
24 | * | |
25 | * XMenuInternal.c - XMenu internal (not user visible) routines. | |
26 | * | |
27 | * Author: Tony Della Fera, DEC | |
28 | * November, 1985 | |
29 | * | |
30 | */ | |
31 | ||
32 | #include <config.h> | |
33 | #include "XMenuInt.h" | |
34 | ||
e745ede7 DL |
35 | /* |
36 | * Internal Window creation queue sizes. | |
37 | */ | |
38 | #define S_QUE_SIZE 300 | |
39 | #define P_QUE_SIZE 20 | |
e745ede7 DL |
40 | |
41 | ||
42 | /* | |
43 | * XMWinQue - Internal window creation queue datatype. | |
44 | */ | |
45 | typedef struct _xmwinquedef { | |
46 | int sq_size; | |
47 | XMSelect *sq[S_QUE_SIZE]; | |
48 | XMSelect **sq_ptr; | |
49 | int pq_size; | |
50 | XMPane *pq[P_QUE_SIZE]; | |
51 | XMPane **pq_ptr; | |
52 | } XMWinQue; | |
53 | ||
54 | /* | |
55 | * _XMWinQue - Internal static window creation queue. | |
56 | */ | |
57 | static Bool _XMWinQueIsInit = False; | |
58 | static XMWinQue _XMWinQue; | |
59 | ||
60 | /* | |
61 | * _XMErrorCode - Global XMenu error code. | |
62 | */ | |
177c0ea7 | 63 | int _XMErrorCode = XME_NO_ERROR; |
e745ede7 DL |
64 | /* |
65 | * _XMErrorList - Global XMenu error code description strings. | |
66 | */ | |
55660072 | 67 | char const *const |
e745ede7 DL |
68 | _XMErrorList[XME_CODE_COUNT] = { |
69 | "No error", /* XME_NO_ERROR */ | |
70 | "Menu not initialized", /* XME_NOT_INIT */ | |
71 | "Argument out of bounds", /* XME_ARG_BOUNDS */ | |
72 | "Pane not found", /* XME_P_NOT_FOUND */ | |
73 | "Selection not found", /* XME_S_NOT_FOUND */ | |
74 | "Invalid menu style parameter", /* XME_STYLE_PARAM */ | |
75 | "Unable to grab mouse", /* XME_GRAB_MOUSE */ | |
76 | "Unable to interpret locator", /* XME_INTERP_LOC */ | |
77 | "Unable to calloc memory", /* XME_CALLOC */ | |
78 | "Unable to create XAssocTable", /* XME_CREATE_ASSOC */ | |
79 | "Unable to store bitmap", /* XME_STORE_BITMAP */ | |
80 | "Unable to make tile pixmaps", /* XME_MAKE_TILES */ | |
81 | "Unable to make pixmap", /* XME_MAKE_PIXMAP */ | |
82 | "Unable to create cursor", /* XME_CREATE_CURSOR */ | |
83 | "Unable to open font", /* XME_OPEN_FONT */ | |
84 | "Unable to create windows", /* XME_CREATE_WINDOW */ | |
85 | "Unable to create transparencies", /* XME_CREATE_TRANSP */ | |
86 | }; | |
87 | ||
88 | /* | |
89 | * _XMEventHandler - Internal event handler variable. | |
90 | */ | |
b782e2d7 | 91 | int (*_XMEventHandler)(XEvent*) = NULL; |
e745ede7 DL |
92 | |
93 | ||
94 | ||
95 | /* | |
96 | * _XMWinQueInit - Internal routine to initialize the window | |
97 | * queue. | |
98 | */ | |
55660072 | 99 | void |
b782e2d7 | 100 | _XMWinQueInit(void) |
e745ede7 DL |
101 | { |
102 | /* | |
103 | * If the queue is not initialized initialize it. | |
104 | */ | |
105 | if (!_XMWinQueIsInit) { | |
106 | /* | |
107 | * Blank the queue structure. | |
108 | */ | |
109 | register int i; | |
110 | ||
111 | for (i = 0; i < S_QUE_SIZE; i++) | |
112 | _XMWinQue.sq[i] = 0; | |
113 | ||
114 | for (i = 0; i < P_QUE_SIZE; i++) | |
115 | _XMWinQue.pq[i] = 0; | |
116 | ||
117 | _XMWinQue.sq_size = _XMWinQue.pq_size = 0; | |
118 | ||
119 | /* | |
120 | * Initialize the next free location pointers. | |
121 | */ | |
122 | _XMWinQue.sq_ptr = _XMWinQue.sq; | |
123 | _XMWinQue.pq_ptr = _XMWinQue.pq; | |
124 | } | |
125 | } | |
126 | ||
127 | ||
128 | ||
129 | /* | |
130 | * _XMWinQueAddPane - Internal routine to add a pane to the pane | |
131 | * window queue. | |
132 | */ | |
133 | int | |
b782e2d7 | 134 | _XMWinQueAddPane(register Display *display, register XMenu *menu, register XMPane *p_ptr) |
55660072 | 135 | |
b782e2d7 DN |
136 | /* Menu being manipulated. */ |
137 | /* XMPane being queued. */ | |
e745ede7 DL |
138 | { |
139 | /* | |
140 | * If the queue is currently full then flush it. | |
141 | */ | |
142 | if (_XMWinQue.pq_size == P_QUE_SIZE) { | |
143 | if (_XMWinQueFlush(display, menu, 0, 0) == _FAILURE) return(_FAILURE); | |
144 | } | |
145 | ||
146 | /* | |
147 | * Insert the new XMPane pointer and increment the queue pointer | |
148 | * and the queue size. | |
149 | */ | |
150 | *_XMWinQue.pq_ptr = p_ptr; | |
151 | _XMWinQue.pq_ptr++; | |
152 | _XMWinQue.pq_size++; | |
153 | ||
154 | /* | |
155 | * All went well, return successfully. | |
156 | */ | |
157 | _XMErrorCode = XME_NO_ERROR; | |
158 | return(_SUCCESS); | |
159 | } | |
160 | ||
161 | ||
162 | ||
163 | /* | |
164 | * _XMWinQueAddSelection - Internal routine to add a selection to | |
165 | * the selection window queue. | |
166 | */ | |
167 | int | |
b782e2d7 | 168 | _XMWinQueAddSelection(register Display *display, register XMenu *menu, register XMSelect *s_ptr) |
55660072 | 169 | |
b782e2d7 DN |
170 | /* Menu being manipulated. */ |
171 | /* XMSelection being queued. */ | |
e745ede7 DL |
172 | { |
173 | /* | |
174 | * If this entry will overflow the queue then flush it. | |
175 | */ | |
176 | if (_XMWinQue.sq_size == S_QUE_SIZE) { | |
177 | if (_XMWinQueFlush(display, menu, 0, 0) == _FAILURE) return(_FAILURE); | |
178 | } | |
179 | ||
180 | /* | |
181 | * Insert the new XMSelect pointer and increment the queue pointer | |
182 | * and the queue size. | |
183 | */ | |
184 | *_XMWinQue.sq_ptr = s_ptr; | |
185 | _XMWinQue.sq_ptr++; | |
186 | _XMWinQue.sq_size++; | |
187 | ||
188 | /* | |
189 | * All went well, return successfully. | |
190 | */ | |
191 | _XMErrorCode = XME_NO_ERROR; | |
192 | return(_SUCCESS); | |
193 | } | |
194 | ||
195 | ||
196 | ||
197 | /* | |
198 | * _XMWinQueFlush - Internal routine to flush the pane and | |
199 | * selection window queues. | |
200 | */ | |
201 | int | |
55660072 PE |
202 | _XMWinQueFlush(register Display *display, register XMenu *menu, register XMPane *pane, XMSelect *sel) |
203 | ||
b782e2d7 DN |
204 | /* Menu being manipulated. */ |
205 | /* Current pane. */ | |
e745ede7 DL |
206 | { |
207 | register int pq_index; /* Pane queue index. */ | |
208 | register int sq_index; /* Selection queue index. */ | |
209 | register XMPane *p_ptr; /* XMPane pointer. */ | |
210 | register XMSelect *s_ptr; /* XMSelect pointer. */ | |
211 | unsigned long valuemask; /* Which attributes to set. */ | |
55660072 PE |
212 | XSetWindowAttributes attributes_buf; /* Attributes to be set. */ |
213 | XSetWindowAttributes *attributes = &attributes_buf; | |
e745ede7 DL |
214 | |
215 | /* | |
216 | * If the pane window queue is not empty... | |
217 | */ | |
177c0ea7 | 218 | |
e745ede7 DL |
219 | if (_XMWinQue.pq_size > 0) { |
220 | /* | |
221 | * set up attributes for pane window to be created. | |
222 | */ | |
223 | valuemask = (CWBackPixmap | CWBorderPixel | CWOverrideRedirect); | |
e745ede7 DL |
224 | attributes->border_pixel = menu->p_bdr_color; |
225 | attributes->background_pixmap = menu->inact_pixmap; | |
226 | attributes->override_redirect = True; | |
177c0ea7 | 227 | |
e745ede7 DL |
228 | /* |
229 | * Create all the pending panes in order, so that the | |
230 | * current pane will be on top, with the others | |
231 | * stacked appropriately under it. | |
232 | */ | |
233 | for (pq_index = _XMWinQue.pq_size - 1; | |
234 | pq_index >= 0; | |
177c0ea7 | 235 | pq_index--) |
e745ede7 DL |
236 | { |
237 | p_ptr = _XMWinQue.pq[pq_index]; /* Retrieve next pane. */ | |
238 | if (p_ptr == pane) break; | |
239 | p_ptr->window = XCreateWindow(display, | |
240 | menu->parent, | |
241 | p_ptr->window_x, | |
242 | p_ptr->window_y, | |
243 | p_ptr->window_w, | |
244 | p_ptr->window_h, | |
245 | menu->p_bdr_width, | |
246 | CopyFromParent, | |
247 | InputOutput, | |
248 | CopyFromParent, | |
249 | valuemask, | |
250 | attributes); | |
251 | XMakeAssoc(display, menu->assoc_tab, p_ptr->window, p_ptr); | |
252 | XSelectInput(display, p_ptr->window, menu->p_events); | |
253 | } | |
254 | for (pq_index = 0; | |
255 | pq_index < _XMWinQue.pq_size; | |
177c0ea7 | 256 | pq_index++) |
e745ede7 DL |
257 | { |
258 | p_ptr = _XMWinQue.pq[pq_index]; /* Retrieve next pane. */ | |
259 | p_ptr->window = XCreateWindow(display, | |
260 | menu->parent, | |
261 | p_ptr->window_x, | |
262 | p_ptr->window_y, | |
263 | p_ptr->window_w, | |
264 | p_ptr->window_h, | |
265 | menu->p_bdr_width, | |
266 | CopyFromParent, | |
267 | InputOutput, | |
268 | CopyFromParent, | |
269 | valuemask, | |
270 | attributes); | |
271 | XMakeAssoc(display, menu->assoc_tab, p_ptr->window, p_ptr); | |
272 | XSelectInput(display, p_ptr->window, menu->p_events); | |
273 | if (p_ptr == pane) break; | |
274 | } | |
275 | ||
276 | /* | |
277 | * Reset the pane queue pointer and size. | |
278 | */ | |
279 | _XMWinQue.pq_size = 0; | |
280 | _XMWinQue.pq_ptr = _XMWinQue.pq; | |
281 | } | |
282 | ||
283 | /* | |
284 | * If the selection window queue is not empty... | |
285 | */ | |
177c0ea7 | 286 | |
e745ede7 DL |
287 | if (_XMWinQue.sq_size > 0) { |
288 | ||
289 | for (sq_index = 0; sq_index < _XMWinQue.sq_size; sq_index++) { | |
290 | /* | |
291 | * Retrieve the XMSelect pointer. | |
292 | */ | |
293 | s_ptr = _XMWinQue.sq[sq_index]; | |
294 | s_ptr->window = XCreateWindow(display, | |
295 | s_ptr->parent_p->window, | |
296 | s_ptr->window_x, | |
297 | s_ptr->window_y, | |
298 | s_ptr->window_w, | |
299 | s_ptr->window_h, | |
300 | 0, /* border width*/ | |
301 | CopyFromParent, | |
302 | InputOnly, | |
303 | CopyFromParent, | |
304 | 0, | |
305 | attributes); | |
177c0ea7 | 306 | |
e745ede7 DL |
307 | /* |
308 | * Insert the new window id and its | |
177c0ea7 | 309 | * associated XMSelect structure into the |
e745ede7 DL |
310 | * association table. |
311 | */ | |
312 | XMakeAssoc(display, menu->assoc_tab, s_ptr->window, s_ptr); | |
313 | XSelectInput(display, s_ptr->window, menu->s_events); | |
314 | } | |
315 | ||
316 | /* | |
317 | * Reset the selection queue pointer and size. | |
318 | */ | |
319 | _XMWinQue.sq_size = 0; | |
320 | _XMWinQue.sq_ptr = _XMWinQue.sq; | |
321 | } | |
322 | ||
323 | /* | |
324 | * Flush X's internal queues. | |
325 | */ | |
326 | XFlush(display); | |
327 | ||
328 | /* | |
329 | * All went well, return successfully. | |
330 | */ | |
331 | _XMErrorCode = XME_NO_ERROR; | |
332 | return(_SUCCESS); | |
333 | } | |
334 | ||
335 | ||
336 | ||
337 | /* | |
338 | * _XMGetPanePtr - Given a menu pointer and a pane index number, return | |
339 | * a pane pointer that points to the indexed pane. | |
340 | */ | |
341 | XMPane * | |
b782e2d7 DN |
342 | _XMGetPanePtr(register XMenu *menu, register int p_num) |
343 | /* Menu to find the pane in. */ | |
344 | /* Index number of pane to find. */ | |
e745ede7 DL |
345 | { |
346 | register XMPane *p_ptr; /* Pane pointer to be returned. */ | |
347 | register int i; /* Loop counter. */ | |
348 | ||
349 | /* | |
350 | * Is the pane number out of range? | |
351 | */ | |
352 | if ((p_num < 0) || (p_num > (menu->p_count - 1))) { | |
353 | _XMErrorCode = XME_P_NOT_FOUND; | |
354 | return(NULL); | |
355 | } | |
356 | ||
357 | /* | |
358 | * Find the right pane. | |
359 | */ | |
360 | p_ptr = menu->p_list->next; | |
361 | for (i = 0; i < p_num; i++) p_ptr = p_ptr->next; | |
362 | ||
363 | /* | |
364 | * Return successfully. | |
365 | */ | |
366 | _XMErrorCode = XME_NO_ERROR; | |
367 | return(p_ptr); | |
368 | } | |
369 | ||
370 | ||
371 | ||
372 | /* | |
373 | * _XMGetSelectionPtr - Given pane pointer and a selection index number, | |
374 | * return a selection pointer that points to the | |
375 | * indexed selection. | |
376 | */ | |
377 | XMSelect * | |
b782e2d7 DN |
378 | _XMGetSelectionPtr(register XMPane *p_ptr, register int s_num) |
379 | /* Pane to find the selection in. */ | |
380 | /* Index number of the selection to find. */ | |
e745ede7 DL |
381 | { |
382 | register XMSelect *s_ptr; /* Selection pointer to be returned. */ | |
383 | register int i; /* Loop counter. */ | |
177c0ea7 | 384 | |
e745ede7 DL |
385 | /* |
386 | * Is the selection number out of range? | |
387 | */ | |
388 | if ((s_num < 0) || (s_num > (p_ptr->s_count - 1))) { | |
389 | _XMErrorCode = XME_S_NOT_FOUND; | |
390 | return(NULL); | |
391 | } | |
392 | ||
393 | /* | |
394 | * Find the right selection. | |
395 | */ | |
396 | s_ptr = p_ptr->s_list->next; | |
397 | for (i = 0; i < s_num; i++) s_ptr = s_ptr->next; | |
398 | ||
399 | /* | |
400 | * Return successfully. | |
401 | */ | |
402 | _XMErrorCode = XME_NO_ERROR; | |
403 | return(s_ptr); | |
404 | } | |
405 | ||
406 | ||
407 | ||
408 | /* | |
409 | * _XMRecomputeGlobals - Internal subroutine to recompute menu wide | |
410 | * global values. | |
411 | */ | |
55660072 | 412 | void |
b782e2d7 DN |
413 | _XMRecomputeGlobals(register Display *display, register XMenu *menu) |
414 | /*X11 display variable. */ | |
415 | /* Menu object to compute from. */ | |
e745ede7 DL |
416 | { |
417 | register XMPane *p_ptr; /* Pane pointer. */ | |
418 | register XMSelect *s_ptr; /* Selection pointer. */ | |
419 | ||
420 | register int max_p_label = 0; /* Maximum pane label width. */ | |
421 | register int max_s_label = 0; /* Maximum selection label width. */ | |
422 | register int s_count = 0; /* Maximum selection count. */ | |
423 | ||
424 | int p_s_pad; /* Pane <-> selection padding. */ | |
425 | int p_s_diff; /* Pane <-> selection separation. */ | |
426 | ||
427 | int p_height; /* Pane window height. */ | |
428 | int p_width; /* Pane window width. */ | |
429 | int s_width; /* Selection window width. */ | |
430 | ||
431 | int screen; /* DefaultScreen holder. */ | |
177c0ea7 | 432 | |
e745ede7 DL |
433 | /* |
434 | * For each pane... | |
435 | */ | |
436 | for ( | |
437 | p_ptr = menu->p_list->next; | |
438 | p_ptr != menu->p_list; | |
439 | p_ptr = p_ptr->next | |
440 | ){ | |
177c0ea7 | 441 | |
e745ede7 DL |
442 | /* |
443 | * Recompute maximum pane label width. | |
444 | */ | |
445 | max_p_label = max(max_p_label, p_ptr->label_width); | |
446 | ||
447 | /* | |
177c0ea7 | 448 | * Recompute maximum selection count. |
e745ede7 DL |
449 | */ |
450 | s_count = max(s_count, p_ptr->s_count); | |
451 | ||
452 | /* | |
453 | * For each selection in the current pane... | |
454 | */ | |
455 | for ( | |
456 | s_ptr = p_ptr->s_list->next; | |
457 | s_ptr != p_ptr->s_list; | |
458 | s_ptr = s_ptr->next | |
459 | ){ | |
460 | ||
461 | /* | |
462 | * Recompute maximum selection label width. | |
463 | */ | |
464 | max_s_label = max(max_s_label, s_ptr->label_width); | |
465 | } | |
466 | } | |
467 | ||
468 | /* | |
469 | * Recompute pane height. | |
470 | */ | |
471 | p_height = (menu->flag_height << 1) + (menu->s_y_off * s_count); | |
472 | ||
473 | /* | |
474 | * Recompute horizontal padding between the pane window and the | |
475 | * selection windows. | |
476 | */ | |
477 | p_s_pad = menu->p_x_off << 1; | |
478 | ||
479 | /* | |
480 | * Recompute pane and selection window widths. | |
481 | * This is done by first computing the window sizes from the maximum | |
482 | * label widths. If the spacing between the selection window and the | |
483 | * containing pane window is less than the pane selection padding value | |
484 | * (twice the pane X offset) then change the size of the pane to be | |
485 | * the size of the selection window plus the padding. If, however the | |
486 | * spacing between the selection window and the containing pane window | |
487 | * is more than the pane selection padding value increase the size of | |
488 | * the selection to its maximum possible value (the pane width minus | |
489 | * the pane selection padding value). | |
490 | */ | |
491 | p_width = max_p_label + p_s_pad; | |
492 | s_width = max_s_label + (menu->s_fnt_pad << 1) + (menu->s_bdr_width << 1); | |
493 | p_s_diff = p_width - s_width; | |
494 | if (p_s_diff < p_s_pad) { | |
495 | p_width = s_width + p_s_pad; | |
496 | } | |
497 | else if (p_s_diff > p_s_pad) { | |
498 | s_width = p_width - p_s_pad; | |
499 | } | |
500 | ||
501 | /* | |
502 | * Reset menu wide global values. | |
503 | */ | |
504 | menu->s_count = s_count; | |
505 | menu->p_height = p_height; | |
506 | menu->p_width = p_width; | |
507 | menu->s_width = s_width; | |
508 | ||
177c0ea7 | 509 | /* |
e745ede7 DL |
510 | * Ensure that the origin of the menu is placed so that |
511 | * None of the panes ore selections are off the screen. | |
512 | */ | |
513 | screen = DefaultScreen(display); | |
514 | if (menu->x_pos + menu->width > DisplayWidth(display, screen)) | |
515 | menu->x_pos = DisplayWidth(display, screen) - menu->width; | |
516 | else if (menu->x_pos < 0) menu->x_pos = 0; | |
517 | if(menu->y_pos + menu->height > DisplayHeight(display, screen)) | |
518 | menu->y_pos = DisplayHeight(display, screen) - menu->height; | |
519 | else if (menu->y_pos < 0) menu->y_pos = 0; | |
520 | } | |
521 | ||
522 | ||
523 | /* | |
524 | * _XMRecomputePane - Internal subroutine to recompute pane | |
525 | * window dependencies. | |
526 | */ | |
527 | int | |
b782e2d7 DN |
528 | _XMRecomputePane(register Display *display, register XMenu *menu, register XMPane *p_ptr, register int p_num) |
529 | /* Standard X display variable. */ | |
530 | /* Menu object being recomputed. */ | |
531 | /* Pane pointer. */ | |
532 | /* Pane sequence number. */ | |
e745ede7 DL |
533 | { |
534 | register int window_x; /* Recomputed window X coordinate. */ | |
535 | register int window_y; /* Recomputed window Y coordinate. */ | |
177c0ea7 | 536 | |
e745ede7 DL |
537 | unsigned long change_mask; /* Value mask to reconfigure window. */ |
538 | XWindowChanges *changes; /* Values to use in configure window. */ | |
177c0ea7 | 539 | |
e745ede7 DL |
540 | register Bool config_p = False; /* Reconfigure pane window? */ |
541 | ||
542 | /* | |
543 | * Update the pane serial number. | |
544 | */ | |
545 | p_ptr->serial = p_num; | |
546 | ||
547 | /* | |
548 | * Recompute window X and Y coordinates. | |
549 | */ | |
550 | switch (menu->menu_style) { | |
551 | case LEFT: | |
552 | window_x = menu->p_x_off * ((menu->p_count - 1) - p_num); | |
553 | window_y = menu->p_y_off * ((menu->p_count - 1) - p_num); | |
554 | break; | |
555 | case RIGHT: | |
556 | window_x = menu->p_x_off * p_num; | |
557 | window_y = menu->p_y_off * ((menu->p_count - 1) - p_num); | |
558 | break; | |
559 | case CENTER: | |
560 | window_x = 0; | |
561 | window_y = menu->p_y_off * ((menu->p_count - 1) - p_num); | |
562 | break; | |
563 | default: | |
564 | /* Error! Invalid style parameter. */ | |
565 | _XMErrorCode = XME_STYLE_PARAM; | |
566 | return(_FAILURE); | |
567 | } | |
568 | window_x += menu->x_pos; | |
569 | window_y += menu->y_pos; | |
570 | ||
571 | /* | |
177c0ea7 | 572 | * If the newly compute pane coordinates differ from the |
e745ede7 DL |
573 | * current coordinates, reset the current coordinates and |
574 | * reconfigure the pane. | |
575 | */ | |
576 | if ( | |
577 | (window_x != p_ptr->window_x) || | |
578 | (window_y != p_ptr->window_y) | |
579 | ){ | |
580 | /* | |
581 | * Reset the coordinates and schedule | |
582 | * the pane for reconfiguration. | |
583 | */ | |
584 | p_ptr->window_x = window_x; | |
585 | p_ptr->window_y = window_y; | |
586 | config_p = True; | |
587 | } | |
588 | ||
589 | /* | |
590 | * If the local pane width and height differs from the | |
591 | * menu pane width and height, reset the local values. | |
592 | */ | |
593 | if ( | |
594 | (p_ptr->window_w != menu->p_width) || | |
595 | (p_ptr->window_h != menu->p_height) | |
596 | ){ | |
597 | /* | |
598 | * Reset window width and height and schedule | |
599 | * the pane for reconfiguration. | |
600 | */ | |
601 | p_ptr->window_w = menu->p_width; | |
602 | p_ptr->window_h = menu->p_height; | |
603 | config_p = True; | |
604 | } | |
605 | ||
606 | /* | |
607 | * If we need to reconfigure the pane window do it now. | |
608 | */ | |
609 | if (config_p == True) { | |
610 | /* | |
611 | * If the pane window has already been created then | |
612 | * reconfigure the existing window, otherwise queue | |
613 | * it for creation with the new configuration. | |
614 | */ | |
615 | if (p_ptr->window) { | |
616 | change_mask = (CWX | CWY | CWWidth | CWHeight); | |
617 | changes = (XWindowChanges *)malloc(sizeof(XWindowChanges)); | |
618 | changes->x = p_ptr->window_x; | |
619 | changes->y = p_ptr->window_y; | |
620 | changes->width = p_ptr->window_w; | |
621 | changes->height = p_ptr->window_h; | |
177c0ea7 | 622 | |
e745ede7 DL |
623 | XConfigureWindow( |
624 | display, | |
625 | p_ptr->window, | |
626 | change_mask, | |
627 | changes | |
628 | ); | |
629 | free(changes); | |
177c0ea7 | 630 | |
e745ede7 DL |
631 | } |
632 | else { | |
633 | if (_XMWinQueAddPane(display, menu, p_ptr) == _FAILURE) { | |
634 | return(_FAILURE); | |
635 | } | |
636 | } | |
637 | } | |
177c0ea7 | 638 | |
e745ede7 DL |
639 | /* |
640 | * Recompute label X position. | |
641 | */ | |
642 | switch (menu->p_style) { | |
643 | case LEFT: | |
644 | p_ptr->label_x = menu->p_x_off + menu->p_fnt_pad; | |
645 | break; | |
646 | case RIGHT: | |
647 | p_ptr->label_x = menu->p_width - | |
648 | (p_ptr->label_width + menu->p_x_off + menu->p_fnt_pad); | |
649 | break; | |
650 | case CENTER: | |
651 | p_ptr->label_x = (menu->p_width - p_ptr->label_width) >> 1; | |
652 | break; | |
653 | default: | |
654 | /* Error! Invalid style parameter. */ | |
655 | _XMErrorCode = XME_STYLE_PARAM; | |
656 | return(_FAILURE); | |
657 | } | |
658 | /* | |
659 | * Recompute label Y positions. | |
660 | */ | |
661 | p_ptr->label_uy = menu->p_fnt_pad + menu->p_fnt_info->max_bounds.ascent; | |
662 | p_ptr->label_ly = (menu->p_height - menu->p_fnt_pad - menu->p_fnt_info->max_bounds.descent); | |
663 | ||
664 | /* | |
665 | * All went well, return successfully. | |
666 | */ | |
667 | _XMErrorCode = XME_NO_ERROR; | |
668 | return(_SUCCESS); | |
669 | } | |
670 | ||
671 | ||
672 | ||
673 | /* | |
674 | * _XMRecomputeSelection - Internal subroutine to recompute | |
675 | * selection window dependencies. | |
676 | */ | |
677 | int | |
b782e2d7 | 678 | _XMRecomputeSelection(register Display *display, register XMenu *menu, register XMSelect *s_ptr, register int s_num) |
55660072 | 679 | |
b782e2d7 DN |
680 | /* Menu object being recomputed. */ |
681 | /* Selection pointer. */ | |
682 | /* Selection sequence number. */ | |
e745ede7 DL |
683 | { |
684 | register Bool config_s = False; /* Reconfigure selection window? */ | |
685 | XWindowChanges *changes; /* Values to change in configure. */ | |
686 | unsigned long change_mask; /* Value mask for XConfigureWindow. */ | |
177c0ea7 | 687 | |
e745ede7 DL |
688 | /* |
689 | * If the selection serial numbers are out of order, begin | |
690 | * resequencing selections. Recompute selection window coordinates | |
691 | * and serial number. | |
692 | * | |
693 | * When selections are created they are given a serial number of | |
694 | * -1, this causes this routine to give a new selection | |
695 | * its initial coordinates and serial number. | |
696 | */ | |
697 | if (s_ptr->serial != s_num) { | |
698 | /* | |
699 | * Fix the sequence number. | |
700 | */ | |
701 | s_ptr->serial = s_num; | |
702 | /* | |
703 | * Recompute window X and Y coordinates. | |
704 | */ | |
705 | s_ptr->window_x = menu->s_x_off; | |
706 | s_ptr->window_y = menu->flag_height + (menu->s_y_off * s_num); | |
707 | /* | |
708 | * We must reconfigure the window. | |
709 | */ | |
710 | config_s = True; | |
711 | } | |
712 | ||
713 | /* | |
714 | * If the local selection width and height differs from the | |
715 | * menu selection width and height, reset the local values. | |
716 | */ | |
717 | if ( | |
718 | (s_ptr->window_w != menu->s_width) || | |
719 | (s_ptr->window_h != menu->s_height) | |
720 | ){ | |
721 | /* | |
722 | * We must reconfigure the window. | |
723 | */ | |
724 | config_s = True; | |
725 | /* | |
726 | * Reset window width and height. | |
727 | */ | |
728 | s_ptr->window_w = menu->s_width; | |
729 | s_ptr->window_h = menu->s_height; | |
730 | } | |
731 | ||
732 | /* | |
733 | * If we need to reconfigure the selection window do it now. | |
734 | */ | |
735 | if (config_s == True) { | |
736 | /* | |
737 | * If the selection window has already been created then | |
738 | * reconfigure the existing window, otherwise queue it | |
739 | * for creation with the new configuration. | |
740 | */ | |
741 | if (s_ptr->window) { | |
742 | changes = (XWindowChanges *)malloc(sizeof(XWindowChanges)); | |
743 | change_mask = (CWX | CWY | CWWidth | CWHeight); | |
744 | changes = (XWindowChanges *)malloc(sizeof(XWindowChanges)); | |
745 | changes->x = s_ptr->window_x; | |
746 | changes->y = s_ptr->window_y; | |
747 | changes->width = s_ptr->window_w; | |
748 | changes->height = s_ptr->window_h; | |
177c0ea7 | 749 | |
e745ede7 DL |
750 | XConfigureWindow( |
751 | display, | |
752 | s_ptr->window, | |
753 | change_mask, | |
754 | changes | |
755 | ); | |
756 | free(changes); | |
177c0ea7 | 757 | |
e745ede7 DL |
758 | } |
759 | else { | |
760 | if (_XMWinQueAddSelection(display, menu, s_ptr) == _FAILURE) { | |
761 | return(_FAILURE); | |
762 | } | |
763 | } | |
764 | } | |
765 | ||
766 | /* | |
767 | * Recompute label X position. | |
768 | */ | |
769 | switch (menu->s_style) { | |
770 | case LEFT: | |
771 | s_ptr->label_x = menu->s_bdr_width + menu->s_fnt_pad + s_ptr->window_x; | |
772 | break; | |
773 | case RIGHT: | |
774 | s_ptr->label_x = s_ptr->window_x + menu->s_width - | |
775 | (s_ptr->label_width + menu->s_bdr_width + menu->s_fnt_pad); | |
776 | break; | |
777 | case CENTER: | |
778 | s_ptr->label_x = s_ptr->window_x + ((menu->s_width - s_ptr->label_width) >> 1); | |
779 | break; | |
780 | default: | |
781 | /* Error! Invalid style parameter. */ | |
782 | _XMErrorCode = XME_STYLE_PARAM; | |
783 | return(_FAILURE); | |
784 | } | |
785 | /* | |
786 | * Recompute label Y position. | |
787 | */ | |
788 | s_ptr->label_y = s_ptr->window_y + menu->s_fnt_info->max_bounds.ascent + menu->s_fnt_pad + menu->s_bdr_width; | |
177c0ea7 | 789 | |
e745ede7 DL |
790 | /* |
791 | * All went well, return successfully. | |
792 | */ | |
793 | _XMErrorCode = XME_NO_ERROR; | |
794 | return(_SUCCESS); | |
795 | } | |
796 | ||
797 | ||
798 | ||
799 | /* | |
800 | * _XMTransToOrigin - Internal subroutine to translate the point at | |
177c0ea7 | 801 | * the center of the current pane and selection to the |
e745ede7 DL |
802 | * the menu origin. |
803 | * | |
804 | * WARNING! ****** Be certain that all menu dependencies have been | |
805 | * recomputed before calling this routine or | |
806 | * unpredictable results will follow. | |
807 | */ | |
55660072 | 808 | void |
b782e2d7 DN |
809 | _XMTransToOrigin(Display *display, register XMenu *menu, register XMPane *p_ptr, register XMSelect *s_ptr, int x_pos, int y_pos, int *orig_x, int *orig_y) |
810 | /* Not used. Included for consistency. */ | |
811 | /* Menu being computed against. */ | |
812 | /* Current pane pointer. */ | |
813 | /* Current selection pointer. */ | |
814 | /* X coordinate of point to translate. */ | |
815 | /* Y coordinate of point to translate. */ | |
816 | /* Return value X coord. of the menu origin. */ | |
817 | /* Return value Y coord. of the menu origin. */ | |
e745ede7 DL |
818 | { |
819 | register int l_orig_x; /* Local X coordinate of the menu origin. */ | |
820 | register int l_orig_y; /* Local Y coordinate of the menu origin. */ | |
177c0ea7 | 821 | |
e745ede7 DL |
822 | /* |
823 | * Translate the menu origin such that the cursor hot point will be in the | |
824 | * center of the desired current selection and pane. | |
825 | * If the current selection pointer is NULL then assume that the hot point | |
826 | * will be in the center of the current pane flag. | |
827 | */ | |
828 | ||
829 | if (s_ptr == NULL) { | |
830 | /* | |
831 | * Translate from the center of the pane flag to the upper left | |
832 | * of the current pane window. | |
833 | */ | |
834 | l_orig_x = x_pos - (menu->p_width >> 1) - menu->p_bdr_width; | |
835 | l_orig_y = y_pos - (menu->flag_height >> 1) - menu->p_bdr_width; | |
836 | } | |
837 | else { | |
838 | /* | |
839 | * First translate from the center of the current selection | |
840 | * to the upper left of the current selection window. | |
841 | */ | |
842 | l_orig_x = x_pos - (menu->s_width >> 1); | |
843 | l_orig_y = y_pos - (menu->s_height >> 1); | |
844 | ||
845 | /* | |
846 | * Then translate to the upper left of the current pane window. | |
847 | */ | |
848 | l_orig_x -= (s_ptr->window_x + menu->p_bdr_width); | |
849 | l_orig_y -= (s_ptr->window_y + menu->p_bdr_width); | |
850 | } | |
851 | ||
852 | /* | |
853 | * Finally translate to the upper left of the menu. | |
854 | */ | |
855 | l_orig_x -= (p_ptr->window_x - menu->x_pos); | |
856 | l_orig_y -= (p_ptr->window_y - menu->y_pos); | |
857 | ||
858 | /* | |
859 | * Set the return values. | |
860 | */ | |
861 | *orig_x = l_orig_x; | |
862 | *orig_y = l_orig_y; | |
863 | } | |
864 | ||
865 | /* | |
866 | * _XMRefreshPane - Internal subroutine to completely refresh | |
867 | * the contents of a pane. | |
868 | */ | |
55660072 | 869 | void |
b782e2d7 | 870 | _XMRefreshPane(register Display *display, register XMenu *menu, register XMPane *pane) |
e745ede7 DL |
871 | { |
872 | register XMSelect *s_list = pane->s_list; | |
873 | register XMSelect *s_ptr; | |
874 | ||
875 | /* | |
177c0ea7 | 876 | * First clear the pane. |
e745ede7 DL |
877 | */ |
878 | XClearWindow(display, pane->window); | |
879 | if (!pane->activated) { | |
880 | XFillRectangle(display, | |
881 | pane->window, | |
882 | menu->inverse_select_GC, | |
883 | pane->label_x - menu->p_fnt_pad, | |
884 | pane->label_uy - menu->p_fnt_info->max_bounds.ascent - menu->p_fnt_pad, | |
885 | pane->label_width + (menu->p_fnt_pad << 1), | |
886 | menu->flag_height); | |
887 | ||
888 | XFillRectangle(display, | |
889 | pane->window, | |
890 | menu->inverse_select_GC, | |
891 | pane->label_x - menu->p_fnt_pad, | |
892 | pane->label_ly - menu->p_fnt_info->max_bounds.ascent - menu->p_fnt_pad, | |
893 | pane->label_width + (menu->p_fnt_pad << 1), | |
894 | menu->flag_height); | |
895 | } | |
896 | if (!pane->active) { | |
897 | XDrawString(display, | |
898 | pane->window, | |
899 | menu->inact_GC, | |
900 | pane->label_x, pane->label_uy, | |
901 | pane->label, pane->label_length); | |
902 | XDrawString(display, | |
903 | pane->window, | |
904 | menu->inact_GC, | |
905 | pane->label_x, pane->label_ly, | |
906 | pane->label, pane->label_length); | |
907 | } | |
908 | else { | |
909 | XDrawString(display, | |
910 | pane->window, | |
911 | menu->pane_GC, | |
912 | pane->label_x, pane->label_uy, | |
913 | pane->label, pane->label_length); | |
914 | XDrawString(display, | |
915 | pane->window, | |
916 | menu->pane_GC, | |
917 | pane->label_x, pane->label_ly, | |
918 | pane->label, pane->label_length); | |
919 | ||
920 | /* | |
921 | * Finally refresh each selection if the pane is activated. | |
922 | */ | |
923 | if (pane->activated) { | |
924 | for (s_ptr = s_list->next; s_ptr != s_list; s_ptr = s_ptr->next) | |
925 | _XMRefreshSelection(display, menu, s_ptr); | |
926 | } | |
927 | } | |
928 | } | |
177c0ea7 JB |
929 | |
930 | ||
e745ede7 DL |
931 | |
932 | ||
933 | /* | |
177c0ea7 | 934 | * _XMRefreshSelection - Internal subroutine that refreshes |
e745ede7 DL |
935 | * a single selection window. |
936 | */ | |
55660072 PE |
937 | void |
938 | _XMRefreshSelection(register Display *display, register XMenu *menu, register XMSelect *sel) | |
e745ede7 | 939 | { |
55660072 PE |
940 | register int width = sel->window_w; |
941 | register int height = sel->window_h; | |
e745ede7 | 942 | register int bdr_width = menu->s_bdr_width; |
177c0ea7 | 943 | |
55660072 | 944 | if (sel->type == SEPARATOR) { |
e745ede7 | 945 | XDrawLine(display, |
55660072 | 946 | sel->parent_p->window, |
e745ede7 | 947 | menu->normal_select_GC, |
55660072 PE |
948 | sel->window_x, |
949 | sel->window_y + height / 2, | |
950 | sel->window_x + width, | |
951 | sel->window_y + height / 2); | |
e745ede7 | 952 | } |
55660072 | 953 | else if (sel->activated) { |
e745ede7 | 954 | if (menu->menu_mode == INVERT) { |
177c0ea7 | 955 | XFillRectangle(display, |
55660072 | 956 | sel->parent_p->window, |
e745ede7 | 957 | menu->normal_select_GC, |
55660072 | 958 | sel->window_x, sel->window_y, |
177c0ea7 | 959 | width, height); |
e745ede7 | 960 | XDrawString(display, |
55660072 | 961 | sel->parent_p->window, |
e745ede7 | 962 | menu->inverse_select_GC, |
55660072 PE |
963 | sel->label_x, |
964 | sel->label_y, | |
965 | sel->label, sel->label_length); | |
e745ede7 DL |
966 | } |
967 | else { | |
968 | /* | |
969 | * Using BOX mode. | |
970 | * Since most drawing routines with arbitrary width lines | |
971 | * are slow compared to raster-ops lets use a raster-op to | |
972 | * draw the boxes. | |
973 | */ | |
177c0ea7 | 974 | |
e745ede7 | 975 | XDrawRectangle(display, |
55660072 | 976 | sel->parent_p->window, |
e745ede7 | 977 | menu->normal_select_GC, |
55660072 PE |
978 | sel->window_x + (bdr_width >> 1), |
979 | sel->window_y + (bdr_width >> 1 ), | |
e745ede7 DL |
980 | width - bdr_width, |
981 | height - bdr_width); | |
982 | XDrawString(display, | |
55660072 | 983 | sel->parent_p->window, |
e745ede7 | 984 | menu->normal_select_GC, |
55660072 PE |
985 | sel->label_x, |
986 | sel->label_y, | |
987 | sel->label, sel->label_length); | |
e745ede7 DL |
988 | } |
989 | } | |
990 | else { | |
177c0ea7 | 991 | XClearArea(display, |
55660072 PE |
992 | sel->parent_p->window, |
993 | sel->window_x, sel->window_y, | |
e745ede7 DL |
994 | width, height, |
995 | False); | |
55660072 | 996 | if (sel->active) { |
e745ede7 | 997 | XDrawString(display, |
55660072 | 998 | sel->parent_p->window, |
e745ede7 | 999 | menu->normal_select_GC, |
55660072 PE |
1000 | sel->label_x, |
1001 | sel->label_y, | |
1002 | sel->label, sel->label_length); | |
e745ede7 DL |
1003 | } |
1004 | else { | |
1005 | XDrawString(display, | |
55660072 | 1006 | sel->parent_p->window, |
e745ede7 | 1007 | menu->inact_GC, |
55660072 PE |
1008 | sel->label_x, |
1009 | sel->label_y, | |
1010 | sel->label, sel->label_length); | |
e745ede7 DL |
1011 | } |
1012 | } | |
1013 | } |