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