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