calc.texi: Use emacsver.texi to determine Emacs version.
[emacs.git] / oldXMenu / Internal.c
blobcb87dd650c74e5d509de9246359ece34c151319b
1 /* Copyright Massachusetts Institute of Technology 1985 */
3 #include "copyright.h"
5 /*
6 Copyright (C) 1993, 1996, 2001, 2002, 2003, 2004, 2005, 2006,
7 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 * XMenu: MIT Project Athena, X Window system menu package
26 * XMenuInternal.c - XMenu internal (not user visible) routines.
28 * Author: Tony Della Fera, DEC
29 * November, 1985
33 #include <config.h>
34 #include "XMenuInt.h"
37 * Toggle color macro.
39 #define toggle_color(x) \
40 ((x) == menu->bkgnd_color ? menu->s_frg_color : menu->bkgnd_color)
43 * Internal Window creation queue sizes.
45 #define S_QUE_SIZE 300
46 #define P_QUE_SIZE 20
47 #define BUFFER_SIZE (S_QUE_SIZE >= P_QUE_SIZE ? S_QUE_SIZE : P_QUE_SIZE)
51 * XMWinQue - Internal window creation queue datatype.
53 typedef struct _xmwinquedef {
54 int sq_size;
55 XMSelect *sq[S_QUE_SIZE];
56 XMSelect **sq_ptr;
57 int pq_size;
58 XMPane *pq[P_QUE_SIZE];
59 XMPane **pq_ptr;
60 } XMWinQue;
63 * _XMWinQue - Internal static window creation queue.
65 static Bool _XMWinQueIsInit = False;
66 static XMWinQue _XMWinQue;
69 * _XMErrorCode - Global XMenu error code.
71 int _XMErrorCode = XME_NO_ERROR;
73 * _XMErrorList - Global XMenu error code description strings.
75 char *
76 _XMErrorList[XME_CODE_COUNT] = {
77 "No error", /* XME_NO_ERROR */
78 "Menu not initialized", /* XME_NOT_INIT */
79 "Argument out of bounds", /* XME_ARG_BOUNDS */
80 "Pane not found", /* XME_P_NOT_FOUND */
81 "Selection not found", /* XME_S_NOT_FOUND */
82 "Invalid menu style parameter", /* XME_STYLE_PARAM */
83 "Unable to grab mouse", /* XME_GRAB_MOUSE */
84 "Unable to interpret locator", /* XME_INTERP_LOC */
85 "Unable to calloc memory", /* XME_CALLOC */
86 "Unable to create XAssocTable", /* XME_CREATE_ASSOC */
87 "Unable to store bitmap", /* XME_STORE_BITMAP */
88 "Unable to make tile pixmaps", /* XME_MAKE_TILES */
89 "Unable to make pixmap", /* XME_MAKE_PIXMAP */
90 "Unable to create cursor", /* XME_CREATE_CURSOR */
91 "Unable to open font", /* XME_OPEN_FONT */
92 "Unable to create windows", /* XME_CREATE_WINDOW */
93 "Unable to create transparencies", /* XME_CREATE_TRANSP */
97 * _XMEventHandler - Internal event handler variable.
99 int (*_XMEventHandler)(XEvent*) = NULL;
104 * _XMWinQueInit - Internal routine to initialize the window
105 * queue.
107 _XMWinQueInit(void)
110 * If the queue is not initialized initialize it.
112 if (!_XMWinQueIsInit) {
114 * Blank the queue structure.
116 register int i;
118 for (i = 0; i < S_QUE_SIZE; i++)
119 _XMWinQue.sq[i] = 0;
121 for (i = 0; i < P_QUE_SIZE; i++)
122 _XMWinQue.pq[i] = 0;
124 _XMWinQue.sq_size = _XMWinQue.pq_size = 0;
127 * Initialize the next free location pointers.
129 _XMWinQue.sq_ptr = _XMWinQue.sq;
130 _XMWinQue.pq_ptr = _XMWinQue.pq;
137 * _XMWinQueAddPane - Internal routine to add a pane to the pane
138 * window queue.
141 _XMWinQueAddPane(register Display *display, register XMenu *menu, register XMPane *p_ptr)
143 /* Menu being manipulated. */
144 /* XMPane being queued. */
147 * If the queue is currently full then flush it.
149 if (_XMWinQue.pq_size == P_QUE_SIZE) {
150 if (_XMWinQueFlush(display, menu, 0, 0) == _FAILURE) return(_FAILURE);
154 * Insert the new XMPane pointer and increment the queue pointer
155 * and the queue size.
157 *_XMWinQue.pq_ptr = p_ptr;
158 _XMWinQue.pq_ptr++;
159 _XMWinQue.pq_size++;
162 * All went well, return successfully.
164 _XMErrorCode = XME_NO_ERROR;
165 return(_SUCCESS);
171 * _XMWinQueAddSelection - Internal routine to add a selection to
172 * the selection window queue.
175 _XMWinQueAddSelection(register Display *display, register XMenu *menu, register XMSelect *s_ptr)
177 /* Menu being manipulated. */
178 /* XMSelection being queued. */
181 * If this entry will overflow the queue then flush it.
183 if (_XMWinQue.sq_size == S_QUE_SIZE) {
184 if (_XMWinQueFlush(display, menu, 0, 0) == _FAILURE) return(_FAILURE);
188 * Insert the new XMSelect pointer and increment the queue pointer
189 * and the queue size.
191 *_XMWinQue.sq_ptr = s_ptr;
192 _XMWinQue.sq_ptr++;
193 _XMWinQue.sq_size++;
196 * All went well, return successfully.
198 _XMErrorCode = XME_NO_ERROR;
199 return(_SUCCESS);
205 * _XMWinQueFlush - Internal routine to flush the pane and
206 * selection window queues.
209 _XMWinQueFlush(register Display *display, register XMenu *menu, register XMPane *pane, XMSelect *select)
211 /* Menu being manipulated. */
212 /* Current pane. */
214 register int pq_index; /* Pane queue index. */
215 register int sq_index; /* Selection queue index. */
216 register XMPane *p_ptr; /* XMPane pointer. */
217 register XMSelect *s_ptr; /* XMSelect pointer. */
218 unsigned long valuemask; /* Which attributes to set. */
219 XSetWindowAttributes *attributes; /* Attributes to be set. */
222 * If the pane window queue is not empty...
225 if (_XMWinQue.pq_size > 0) {
227 * set up attributes for pane window to be created.
229 valuemask = (CWBackPixmap | CWBorderPixel | CWOverrideRedirect);
230 attributes = (XSetWindowAttributes *)malloc(sizeof(XSetWindowAttributes));
231 attributes->border_pixel = menu->p_bdr_color;
232 attributes->background_pixmap = menu->inact_pixmap;
233 attributes->override_redirect = True;
236 * Create all the pending panes in order, so that the
237 * current pane will be on top, with the others
238 * stacked appropriately under it.
240 for (pq_index = _XMWinQue.pq_size - 1;
241 pq_index >= 0;
242 pq_index--)
244 p_ptr = _XMWinQue.pq[pq_index]; /* Retrieve next pane. */
245 if (p_ptr == pane) break;
246 p_ptr->window = XCreateWindow(display,
247 menu->parent,
248 p_ptr->window_x,
249 p_ptr->window_y,
250 p_ptr->window_w,
251 p_ptr->window_h,
252 menu->p_bdr_width,
253 CopyFromParent,
254 InputOutput,
255 CopyFromParent,
256 valuemask,
257 attributes);
258 XMakeAssoc(display, menu->assoc_tab, p_ptr->window, p_ptr);
259 XSelectInput(display, p_ptr->window, menu->p_events);
261 for (pq_index = 0;
262 pq_index < _XMWinQue.pq_size;
263 pq_index++)
265 p_ptr = _XMWinQue.pq[pq_index]; /* Retrieve next pane. */
266 p_ptr->window = XCreateWindow(display,
267 menu->parent,
268 p_ptr->window_x,
269 p_ptr->window_y,
270 p_ptr->window_w,
271 p_ptr->window_h,
272 menu->p_bdr_width,
273 CopyFromParent,
274 InputOutput,
275 CopyFromParent,
276 valuemask,
277 attributes);
278 XMakeAssoc(display, menu->assoc_tab, p_ptr->window, p_ptr);
279 XSelectInput(display, p_ptr->window, menu->p_events);
280 if (p_ptr == pane) break;
284 * Reset the pane queue pointer and size.
286 _XMWinQue.pq_size = 0;
287 _XMWinQue.pq_ptr = _XMWinQue.pq;
291 * If the selection window queue is not empty...
294 if (_XMWinQue.sq_size > 0) {
296 for (sq_index = 0; sq_index < _XMWinQue.sq_size; sq_index++) {
298 * Retrieve the XMSelect pointer.
300 s_ptr = _XMWinQue.sq[sq_index];
301 s_ptr->window = XCreateWindow(display,
302 s_ptr->parent_p->window,
303 s_ptr->window_x,
304 s_ptr->window_y,
305 s_ptr->window_w,
306 s_ptr->window_h,
307 0, /* border width*/
308 CopyFromParent,
309 InputOnly,
310 CopyFromParent,
312 attributes);
315 * Insert the new window id and its
316 * associated XMSelect structure into the
317 * association table.
319 XMakeAssoc(display, menu->assoc_tab, s_ptr->window, s_ptr);
320 XSelectInput(display, s_ptr->window, menu->s_events);
324 * Reset the selection queue pointer and size.
326 _XMWinQue.sq_size = 0;
327 _XMWinQue.sq_ptr = _XMWinQue.sq;
331 * Flush X's internal queues.
333 XFlush(display);
336 * All went well, return successfully.
338 _XMErrorCode = XME_NO_ERROR;
339 return(_SUCCESS);
345 * _XMGetPanePtr - Given a menu pointer and a pane index number, return
346 * a pane pointer that points to the indexed pane.
348 XMPane *
349 _XMGetPanePtr(register XMenu *menu, register int p_num)
350 /* Menu to find the pane in. */
351 /* Index number of pane to find. */
353 register XMPane *p_ptr; /* Pane pointer to be returned. */
354 register int i; /* Loop counter. */
357 * Is the pane number out of range?
359 if ((p_num < 0) || (p_num > (menu->p_count - 1))) {
360 _XMErrorCode = XME_P_NOT_FOUND;
361 return(NULL);
365 * Find the right pane.
367 p_ptr = menu->p_list->next;
368 for (i = 0; i < p_num; i++) p_ptr = p_ptr->next;
371 * Return successfully.
373 _XMErrorCode = XME_NO_ERROR;
374 return(p_ptr);
380 * _XMGetSelectionPtr - Given pane pointer and a selection index number,
381 * return a selection pointer that points to the
382 * indexed selection.
384 XMSelect *
385 _XMGetSelectionPtr(register XMPane *p_ptr, register int s_num)
386 /* Pane to find the selection in. */
387 /* Index number of the selection to find. */
389 register XMSelect *s_ptr; /* Selection pointer to be returned. */
390 register int i; /* Loop counter. */
393 * Is the selection number out of range?
395 if ((s_num < 0) || (s_num > (p_ptr->s_count - 1))) {
396 _XMErrorCode = XME_S_NOT_FOUND;
397 return(NULL);
401 * Find the right selection.
403 s_ptr = p_ptr->s_list->next;
404 for (i = 0; i < s_num; i++) s_ptr = s_ptr->next;
407 * Return successfully.
409 _XMErrorCode = XME_NO_ERROR;
410 return(s_ptr);
416 * _XMRecomputeGlobals - Internal subroutine to recompute menu wide
417 * global values.
419 _XMRecomputeGlobals(register Display *display, register XMenu *menu)
420 /*X11 display variable. */
421 /* Menu object to compute from. */
423 register XMPane *p_ptr; /* Pane pointer. */
424 register XMSelect *s_ptr; /* Selection pointer. */
426 register int max_p_label = 0; /* Maximum pane label width. */
427 register int max_s_label = 0; /* Maximum selection label width. */
428 register int s_count = 0; /* Maximum selection count. */
430 int p_s_pad; /* Pane <-> selection padding. */
431 int p_s_diff; /* Pane <-> selection separation. */
433 int p_height; /* Pane window height. */
434 int p_width; /* Pane window width. */
435 int s_width; /* Selection window width. */
437 int screen; /* DefaultScreen holder. */
440 * For each pane...
442 for (
443 p_ptr = menu->p_list->next;
444 p_ptr != menu->p_list;
445 p_ptr = p_ptr->next
449 * Recompute maximum pane label width.
451 max_p_label = max(max_p_label, p_ptr->label_width);
454 * Recompute maximum selection count.
456 s_count = max(s_count, p_ptr->s_count);
459 * For each selection in the current pane...
461 for (
462 s_ptr = p_ptr->s_list->next;
463 s_ptr != p_ptr->s_list;
464 s_ptr = s_ptr->next
468 * Recompute maximum selection label width.
470 max_s_label = max(max_s_label, s_ptr->label_width);
475 * Recompute pane height.
477 p_height = (menu->flag_height << 1) + (menu->s_y_off * s_count);
480 * Recompute horizontal padding between the pane window and the
481 * selection windows.
483 p_s_pad = menu->p_x_off << 1;
486 * Recompute pane and selection window widths.
487 * This is done by first computing the window sizes from the maximum
488 * label widths. If the spacing between the selection window and the
489 * containing pane window is less than the pane selection padding value
490 * (twice the pane X offset) then change the size of the pane to be
491 * the size of the selection window plus the padding. If, however the
492 * spacing between the selection window and the containing pane window
493 * is more than the pane selection padding value increase the size of
494 * the selection to its maximum possible value (the pane width minus
495 * the pane selection padding value).
497 p_width = max_p_label + p_s_pad;
498 s_width = max_s_label + (menu->s_fnt_pad << 1) + (menu->s_bdr_width << 1);
499 p_s_diff = p_width - s_width;
500 if (p_s_diff < p_s_pad) {
501 p_width = s_width + p_s_pad;
503 else if (p_s_diff > p_s_pad) {
504 s_width = p_width - p_s_pad;
508 * Reset menu wide global values.
510 menu->s_count = s_count;
511 menu->p_height = p_height;
512 menu->p_width = p_width;
513 menu->s_width = s_width;
516 * Ensure that the origin of the menu is placed so that
517 * None of the panes ore selections are off the screen.
519 screen = DefaultScreen(display);
520 if (menu->x_pos + menu->width > DisplayWidth(display, screen))
521 menu->x_pos = DisplayWidth(display, screen) - menu->width;
522 else if (menu->x_pos < 0) menu->x_pos = 0;
523 if(menu->y_pos + menu->height > DisplayHeight(display, screen))
524 menu->y_pos = DisplayHeight(display, screen) - menu->height;
525 else if (menu->y_pos < 0) menu->y_pos = 0;
530 * _XMRecomputePane - Internal subroutine to recompute pane
531 * window dependencies.
534 _XMRecomputePane(register Display *display, register XMenu *menu, register XMPane *p_ptr, register int p_num)
535 /* Standard X display variable. */
536 /* Menu object being recomputed. */
537 /* Pane pointer. */
538 /* Pane sequence number. */
540 register int window_x; /* Recomputed window X coordinate. */
541 register int window_y; /* Recomputed window Y coordinate. */
543 unsigned long change_mask; /* Value mask to reconfigure window. */
544 XWindowChanges *changes; /* Values to use in configure window. */
546 register Bool config_p = False; /* Reconfigure pane window? */
549 * Update the pane serial number.
551 p_ptr->serial = p_num;
554 * Recompute window X and Y coordinates.
556 switch (menu->menu_style) {
557 case LEFT:
558 window_x = menu->p_x_off * ((menu->p_count - 1) - p_num);
559 window_y = menu->p_y_off * ((menu->p_count - 1) - p_num);
560 break;
561 case RIGHT:
562 window_x = menu->p_x_off * p_num;
563 window_y = menu->p_y_off * ((menu->p_count - 1) - p_num);
564 break;
565 case CENTER:
566 window_x = 0;
567 window_y = menu->p_y_off * ((menu->p_count - 1) - p_num);
568 break;
569 default:
570 /* Error! Invalid style parameter. */
571 _XMErrorCode = XME_STYLE_PARAM;
572 return(_FAILURE);
574 window_x += menu->x_pos;
575 window_y += menu->y_pos;
578 * If the newly compute pane coordinates differ from the
579 * current coordinates, reset the current coordinates and
580 * reconfigure the pane.
582 if (
583 (window_x != p_ptr->window_x) ||
584 (window_y != p_ptr->window_y)
587 * Reset the coordinates and schedule
588 * the pane for reconfiguration.
590 p_ptr->window_x = window_x;
591 p_ptr->window_y = window_y;
592 config_p = True;
596 * If the local pane width and height differs from the
597 * menu pane width and height, reset the local values.
599 if (
600 (p_ptr->window_w != menu->p_width) ||
601 (p_ptr->window_h != menu->p_height)
604 * Reset window width and height and schedule
605 * the pane for reconfiguration.
607 p_ptr->window_w = menu->p_width;
608 p_ptr->window_h = menu->p_height;
609 config_p = True;
613 * If we need to reconfigure the pane window do it now.
615 if (config_p == True) {
617 * If the pane window has already been created then
618 * reconfigure the existing window, otherwise queue
619 * it for creation with the new configuration.
621 if (p_ptr->window) {
622 change_mask = (CWX | CWY | CWWidth | CWHeight);
623 changes = (XWindowChanges *)malloc(sizeof(XWindowChanges));
624 changes->x = p_ptr->window_x;
625 changes->y = p_ptr->window_y;
626 changes->width = p_ptr->window_w;
627 changes->height = p_ptr->window_h;
629 XConfigureWindow(
630 display,
631 p_ptr->window,
632 change_mask,
633 changes
635 free(changes);
638 else {
639 if (_XMWinQueAddPane(display, menu, p_ptr) == _FAILURE) {
640 return(_FAILURE);
646 * Recompute label X position.
648 switch (menu->p_style) {
649 case LEFT:
650 p_ptr->label_x = menu->p_x_off + menu->p_fnt_pad;
651 break;
652 case RIGHT:
653 p_ptr->label_x = menu->p_width -
654 (p_ptr->label_width + menu->p_x_off + menu->p_fnt_pad);
655 break;
656 case CENTER:
657 p_ptr->label_x = (menu->p_width - p_ptr->label_width) >> 1;
658 break;
659 default:
660 /* Error! Invalid style parameter. */
661 _XMErrorCode = XME_STYLE_PARAM;
662 return(_FAILURE);
665 * Recompute label Y positions.
667 p_ptr->label_uy = menu->p_fnt_pad + menu->p_fnt_info->max_bounds.ascent;
668 p_ptr->label_ly = (menu->p_height - menu->p_fnt_pad - menu->p_fnt_info->max_bounds.descent);
671 * All went well, return successfully.
673 _XMErrorCode = XME_NO_ERROR;
674 return(_SUCCESS);
680 * _XMRecomputeSelection - Internal subroutine to recompute
681 * selection window dependencies.
684 _XMRecomputeSelection(register Display *display, register XMenu *menu, register XMSelect *s_ptr, register int s_num)
686 /* Menu object being recomputed. */
687 /* Selection pointer. */
688 /* Selection sequence number. */
690 register Bool config_s = False; /* Reconfigure selection window? */
691 XWindowChanges *changes; /* Values to change in configure. */
692 unsigned long change_mask; /* Value mask for XConfigureWindow. */
695 * If the selection serial numbers are out of order, begin
696 * resequencing selections. Recompute selection window coordinates
697 * and serial number.
699 * When selections are created they are given a serial number of
700 * -1, this causes this routine to give a new selection
701 * its initial coordinates and serial number.
703 if (s_ptr->serial != s_num) {
705 * Fix the sequence number.
707 s_ptr->serial = s_num;
709 * Recompute window X and Y coordinates.
711 s_ptr->window_x = menu->s_x_off;
712 s_ptr->window_y = menu->flag_height + (menu->s_y_off * s_num);
714 * We must reconfigure the window.
716 config_s = True;
720 * If the local selection width and height differs from the
721 * menu selection width and height, reset the local values.
723 if (
724 (s_ptr->window_w != menu->s_width) ||
725 (s_ptr->window_h != menu->s_height)
728 * We must reconfigure the window.
730 config_s = True;
732 * Reset window width and height.
734 s_ptr->window_w = menu->s_width;
735 s_ptr->window_h = menu->s_height;
739 * If we need to reconfigure the selection window do it now.
741 if (config_s == True) {
743 * If the selection window has already been created then
744 * reconfigure the existing window, otherwise queue it
745 * for creation with the new configuration.
747 if (s_ptr->window) {
748 changes = (XWindowChanges *)malloc(sizeof(XWindowChanges));
749 change_mask = (CWX | CWY | CWWidth | CWHeight);
750 changes = (XWindowChanges *)malloc(sizeof(XWindowChanges));
751 changes->x = s_ptr->window_x;
752 changes->y = s_ptr->window_y;
753 changes->width = s_ptr->window_w;
754 changes->height = s_ptr->window_h;
756 XConfigureWindow(
757 display,
758 s_ptr->window,
759 change_mask,
760 changes
762 free(changes);
765 else {
766 if (_XMWinQueAddSelection(display, menu, s_ptr) == _FAILURE) {
767 return(_FAILURE);
773 * Recompute label X position.
775 switch (menu->s_style) {
776 case LEFT:
777 s_ptr->label_x = menu->s_bdr_width + menu->s_fnt_pad + s_ptr->window_x;
778 break;
779 case RIGHT:
780 s_ptr->label_x = s_ptr->window_x + menu->s_width -
781 (s_ptr->label_width + menu->s_bdr_width + menu->s_fnt_pad);
782 break;
783 case CENTER:
784 s_ptr->label_x = s_ptr->window_x + ((menu->s_width - s_ptr->label_width) >> 1);
785 break;
786 default:
787 /* Error! Invalid style parameter. */
788 _XMErrorCode = XME_STYLE_PARAM;
789 return(_FAILURE);
792 * Recompute label Y position.
794 s_ptr->label_y = s_ptr->window_y + menu->s_fnt_info->max_bounds.ascent + menu->s_fnt_pad + menu->s_bdr_width;
797 * All went well, return successfully.
799 _XMErrorCode = XME_NO_ERROR;
800 return(_SUCCESS);
806 * _XMTransToOrigin - Internal subroutine to translate the point at
807 * the center of the current pane and selection to the
808 * the menu origin.
810 * WARNING! ****** Be certain that all menu dependencies have been
811 * recomputed before calling this routine or
812 * unpredictable results will follow.
814 _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)
815 /* Not used. Included for consistency. */
816 /* Menu being computed against. */
817 /* Current pane pointer. */
818 /* Current selection pointer. */
819 /* X coordinate of point to translate. */
820 /* Y coordinate of point to translate. */
821 /* Return value X coord. of the menu origin. */
822 /* Return value Y coord. of the menu origin. */
824 register int l_orig_x; /* Local X coordinate of the menu origin. */
825 register int l_orig_y; /* Local Y coordinate of the menu origin. */
828 * Translate the menu origin such that the cursor hot point will be in the
829 * center of the desired current selection and pane.
830 * If the current selection pointer is NULL then assume that the hot point
831 * will be in the center of the current pane flag.
834 if (s_ptr == NULL) {
836 * Translate from the center of the pane flag to the upper left
837 * of the current pane window.
839 l_orig_x = x_pos - (menu->p_width >> 1) - menu->p_bdr_width;
840 l_orig_y = y_pos - (menu->flag_height >> 1) - menu->p_bdr_width;
842 else {
844 * First translate from the center of the current selection
845 * to the upper left of the current selection window.
847 l_orig_x = x_pos - (menu->s_width >> 1);
848 l_orig_y = y_pos - (menu->s_height >> 1);
851 * Then translate to the upper left of the current pane window.
853 l_orig_x -= (s_ptr->window_x + menu->p_bdr_width);
854 l_orig_y -= (s_ptr->window_y + menu->p_bdr_width);
858 * Finally translate to the upper left of the menu.
860 l_orig_x -= (p_ptr->window_x - menu->x_pos);
861 l_orig_y -= (p_ptr->window_y - menu->y_pos);
864 * Set the return values.
866 *orig_x = l_orig_x;
867 *orig_y = l_orig_y;
871 * _XMRefreshPane - Internal subroutine to completely refresh
872 * the contents of a pane.
874 _XMRefreshPane(register Display *display, register XMenu *menu, register XMPane *pane)
876 register XMSelect *s_list = pane->s_list;
877 register XMSelect *s_ptr;
880 * First clear the pane.
882 XClearWindow(display, pane->window);
883 if (!pane->activated) {
884 XFillRectangle(display,
885 pane->window,
886 menu->inverse_select_GC,
887 pane->label_x - menu->p_fnt_pad,
888 pane->label_uy - menu->p_fnt_info->max_bounds.ascent - menu->p_fnt_pad,
889 pane->label_width + (menu->p_fnt_pad << 1),
890 menu->flag_height);
892 XFillRectangle(display,
893 pane->window,
894 menu->inverse_select_GC,
895 pane->label_x - menu->p_fnt_pad,
896 pane->label_ly - menu->p_fnt_info->max_bounds.ascent - menu->p_fnt_pad,
897 pane->label_width + (menu->p_fnt_pad << 1),
898 menu->flag_height);
900 if (!pane->active) {
901 XDrawString(display,
902 pane->window,
903 menu->inact_GC,
904 pane->label_x, pane->label_uy,
905 pane->label, pane->label_length);
906 XDrawString(display,
907 pane->window,
908 menu->inact_GC,
909 pane->label_x, pane->label_ly,
910 pane->label, pane->label_length);
912 else {
913 XDrawString(display,
914 pane->window,
915 menu->pane_GC,
916 pane->label_x, pane->label_uy,
917 pane->label, pane->label_length);
918 XDrawString(display,
919 pane->window,
920 menu->pane_GC,
921 pane->label_x, pane->label_ly,
922 pane->label, pane->label_length);
925 * Finally refresh each selection if the pane is activated.
927 if (pane->activated) {
928 for (s_ptr = s_list->next; s_ptr != s_list; s_ptr = s_ptr->next)
929 _XMRefreshSelection(display, menu, s_ptr);
938 * _XMRefreshSelection - Internal subroutine that refreshes
939 * a single selection window.
941 _XMRefreshSelection(register Display *display, register XMenu *menu, register XMSelect *select)
943 register int width = select->window_w;
944 register int height = select->window_h;
945 register int bdr_width = menu->s_bdr_width;
947 if (select->type == SEPARATOR) {
948 XDrawLine(display,
949 select->parent_p->window,
950 menu->normal_select_GC,
951 select->window_x,
952 select->window_y + height / 2,
953 select->window_x + width,
954 select->window_y + height / 2);
956 else if (select->activated) {
957 if (menu->menu_mode == INVERT) {
958 XFillRectangle(display,
959 select->parent_p->window,
960 menu->normal_select_GC,
961 select->window_x, select->window_y,
962 width, height);
963 XDrawString(display,
964 select->parent_p->window,
965 menu->inverse_select_GC,
966 select->label_x,
967 select->label_y,
968 select->label, select->label_length);
970 else {
972 * Using BOX mode.
973 * Since most drawing routines with arbitrary width lines
974 * are slow compared to raster-ops lets use a raster-op to
975 * draw the boxes.
978 XDrawRectangle(display,
979 select->parent_p->window,
980 menu->normal_select_GC,
981 select->window_x + (bdr_width >> 1),
982 select->window_y + (bdr_width >> 1 ),
983 width - bdr_width,
984 height - bdr_width);
985 XDrawString(display,
986 select->parent_p->window,
987 menu->normal_select_GC,
988 select->label_x,
989 select->label_y,
990 select->label, select->label_length);
993 else {
994 XClearArea(display,
995 select->parent_p->window,
996 select->window_x, select->window_y,
997 width, height,
998 False);
999 if (select->active) {
1000 XDrawString(display,
1001 select->parent_p->window,
1002 menu->normal_select_GC,
1003 select->label_x,
1004 select->label_y,
1005 select->label, select->label_length);
1007 else {
1008 XDrawString(display,
1009 select->parent_p->window,
1010 menu->inact_GC,
1011 select->label_x,
1012 select->label_y,
1013 select->label, select->label_length);
1018 /* arch-tag: 3ac61957-0852-4e72-8b88-7dfab1a5dee9
1019 (do not change this comment) */