* files.el (move-file-to-trash): Preserve default file modes on error.
[emacs.git] / oldXMenu / Internal.c
bloba779cda82f58340b93025688147069c7856034d1
1 /* Copyright Massachusetts Institute of Technology 1985 */
3 #include "copyright.h"
5 /*
6 Copyright (C) 1993, 1996, 2001-2011 Free Software Foundation, Inc.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 * XMenu: MIT Project Athena, X Window system menu package
25 * XMenuInternal.c - XMenu internal (not user visible) routines.
27 * Author: Tony Della Fera, DEC
28 * November, 1985
32 #include <config.h>
33 #include "XMenuInt.h"
36 * Internal Window creation queue sizes.
38 #define S_QUE_SIZE 300
39 #define P_QUE_SIZE 20
43 * XMWinQue - Internal window creation queue datatype.
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;
55 * _XMWinQue - Internal static window creation queue.
57 static Bool _XMWinQueIsInit = False;
58 static XMWinQue _XMWinQue;
61 * _XMErrorCode - Global XMenu error code.
63 int _XMErrorCode = XME_NO_ERROR;
65 * _XMErrorList - Global XMenu error code description strings.
67 char const *const
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 */
89 * _XMEventHandler - Internal event handler variable.
91 int (*_XMEventHandler)(XEvent*) = NULL;
96 * _XMWinQueInit - Internal routine to initialize the window
97 * queue.
99 void
100 _XMWinQueInit(void)
103 * If the queue is not initialized initialize it.
105 if (!_XMWinQueIsInit) {
107 * Blank the queue structure.
109 register int i;
111 for (i = 0; i < S_QUE_SIZE; i++)
112 _XMWinQue.sq[i] = 0;
114 for (i = 0; i < P_QUE_SIZE; i++)
115 _XMWinQue.pq[i] = 0;
117 _XMWinQue.sq_size = _XMWinQue.pq_size = 0;
120 * Initialize the next free location pointers.
122 _XMWinQue.sq_ptr = _XMWinQue.sq;
123 _XMWinQue.pq_ptr = _XMWinQue.pq;
130 * _XMWinQueAddPane - Internal routine to add a pane to the pane
131 * window queue.
134 _XMWinQueAddPane(register Display *display, register XMenu *menu, register XMPane *p_ptr)
136 /* Menu being manipulated. */
137 /* XMPane being queued. */
140 * If the queue is currently full then flush it.
142 if (_XMWinQue.pq_size == P_QUE_SIZE) {
143 if (_XMWinQueFlush(display, menu, 0, 0) == _FAILURE) return(_FAILURE);
147 * Insert the new XMPane pointer and increment the queue pointer
148 * and the queue size.
150 *_XMWinQue.pq_ptr = p_ptr;
151 _XMWinQue.pq_ptr++;
152 _XMWinQue.pq_size++;
155 * All went well, return successfully.
157 _XMErrorCode = XME_NO_ERROR;
158 return(_SUCCESS);
164 * _XMWinQueAddSelection - Internal routine to add a selection to
165 * the selection window queue.
168 _XMWinQueAddSelection(register Display *display, register XMenu *menu, register XMSelect *s_ptr)
170 /* Menu being manipulated. */
171 /* XMSelection being queued. */
174 * If this entry will overflow the queue then flush it.
176 if (_XMWinQue.sq_size == S_QUE_SIZE) {
177 if (_XMWinQueFlush(display, menu, 0, 0) == _FAILURE) return(_FAILURE);
181 * Insert the new XMSelect pointer and increment the queue pointer
182 * and the queue size.
184 *_XMWinQue.sq_ptr = s_ptr;
185 _XMWinQue.sq_ptr++;
186 _XMWinQue.sq_size++;
189 * All went well, return successfully.
191 _XMErrorCode = XME_NO_ERROR;
192 return(_SUCCESS);
198 * _XMWinQueFlush - Internal routine to flush the pane and
199 * selection window queues.
202 _XMWinQueFlush(register Display *display, register XMenu *menu, register XMPane *pane, XMSelect *sel)
204 /* Menu being manipulated. */
205 /* Current pane. */
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. */
212 XSetWindowAttributes attributes_buf; /* Attributes to be set. */
213 XSetWindowAttributes *attributes = &attributes_buf;
216 * If the pane window queue is not empty...
219 if (_XMWinQue.pq_size > 0) {
221 * set up attributes for pane window to be created.
223 valuemask = (CWBackPixmap | CWBorderPixel | CWOverrideRedirect);
224 attributes->border_pixel = menu->p_bdr_color;
225 attributes->background_pixmap = menu->inact_pixmap;
226 attributes->override_redirect = True;
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.
233 for (pq_index = _XMWinQue.pq_size - 1;
234 pq_index >= 0;
235 pq_index--)
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);
254 for (pq_index = 0;
255 pq_index < _XMWinQue.pq_size;
256 pq_index++)
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;
277 * Reset the pane queue pointer and size.
279 _XMWinQue.pq_size = 0;
280 _XMWinQue.pq_ptr = _XMWinQue.pq;
284 * If the selection window queue is not empty...
287 if (_XMWinQue.sq_size > 0) {
289 for (sq_index = 0; sq_index < _XMWinQue.sq_size; sq_index++) {
291 * Retrieve the XMSelect pointer.
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,
305 attributes);
308 * Insert the new window id and its
309 * associated XMSelect structure into the
310 * association table.
312 XMakeAssoc(display, menu->assoc_tab, s_ptr->window, s_ptr);
313 XSelectInput(display, s_ptr->window, menu->s_events);
317 * Reset the selection queue pointer and size.
319 _XMWinQue.sq_size = 0;
320 _XMWinQue.sq_ptr = _XMWinQue.sq;
324 * Flush X's internal queues.
326 XFlush(display);
329 * All went well, return successfully.
331 _XMErrorCode = XME_NO_ERROR;
332 return(_SUCCESS);
338 * _XMGetPanePtr - Given a menu pointer and a pane index number, return
339 * a pane pointer that points to the indexed pane.
341 XMPane *
342 _XMGetPanePtr(register XMenu *menu, register int p_num)
343 /* Menu to find the pane in. */
344 /* Index number of pane to find. */
346 register XMPane *p_ptr; /* Pane pointer to be returned. */
347 register int i; /* Loop counter. */
350 * Is the pane number out of range?
352 if ((p_num < 0) || (p_num > (menu->p_count - 1))) {
353 _XMErrorCode = XME_P_NOT_FOUND;
354 return(NULL);
358 * Find the right pane.
360 p_ptr = menu->p_list->next;
361 for (i = 0; i < p_num; i++) p_ptr = p_ptr->next;
364 * Return successfully.
366 _XMErrorCode = XME_NO_ERROR;
367 return(p_ptr);
373 * _XMGetSelectionPtr - Given pane pointer and a selection index number,
374 * return a selection pointer that points to the
375 * indexed selection.
377 XMSelect *
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. */
382 register XMSelect *s_ptr; /* Selection pointer to be returned. */
383 register int i; /* Loop counter. */
386 * Is the selection number out of range?
388 if ((s_num < 0) || (s_num > (p_ptr->s_count - 1))) {
389 _XMErrorCode = XME_S_NOT_FOUND;
390 return(NULL);
394 * Find the right selection.
396 s_ptr = p_ptr->s_list->next;
397 for (i = 0; i < s_num; i++) s_ptr = s_ptr->next;
400 * Return successfully.
402 _XMErrorCode = XME_NO_ERROR;
403 return(s_ptr);
409 * _XMRecomputeGlobals - Internal subroutine to recompute menu wide
410 * global values.
412 void
413 _XMRecomputeGlobals(register Display *display, register XMenu *menu)
414 /*X11 display variable. */
415 /* Menu object to compute from. */
417 register XMPane *p_ptr; /* Pane pointer. */
418 register XMSelect *s_ptr; /* Selection pointer. */
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. */
424 int p_s_pad; /* Pane <-> selection padding. */
425 int p_s_diff; /* Pane <-> selection separation. */
427 int p_height; /* Pane window height. */
428 int p_width; /* Pane window width. */
429 int s_width; /* Selection window width. */
431 int screen; /* DefaultScreen holder. */
434 * For each pane...
436 for (
437 p_ptr = menu->p_list->next;
438 p_ptr != menu->p_list;
439 p_ptr = p_ptr->next
443 * Recompute maximum pane label width.
445 max_p_label = max(max_p_label, p_ptr->label_width);
448 * Recompute maximum selection count.
450 s_count = max(s_count, p_ptr->s_count);
453 * For each selection in the current pane...
455 for (
456 s_ptr = p_ptr->s_list->next;
457 s_ptr != p_ptr->s_list;
458 s_ptr = s_ptr->next
462 * Recompute maximum selection label width.
464 max_s_label = max(max_s_label, s_ptr->label_width);
469 * Recompute pane height.
471 p_height = (menu->flag_height << 1) + (menu->s_y_off * s_count);
474 * Recompute horizontal padding between the pane window and the
475 * selection windows.
477 p_s_pad = menu->p_x_off << 1;
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).
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;
497 else if (p_s_diff > p_s_pad) {
498 s_width = p_width - p_s_pad;
502 * Reset menu wide global values.
504 menu->s_count = s_count;
505 menu->p_height = p_height;
506 menu->p_width = p_width;
507 menu->s_width = s_width;
510 * Ensure that the origin of the menu is placed so that
511 * None of the panes ore selections are off the screen.
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;
524 * _XMRecomputePane - Internal subroutine to recompute pane
525 * window dependencies.
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. */
534 register int window_x; /* Recomputed window X coordinate. */
535 register int window_y; /* Recomputed window Y coordinate. */
537 unsigned long change_mask; /* Value mask to reconfigure window. */
538 XWindowChanges *changes; /* Values to use in configure window. */
540 register Bool config_p = False; /* Reconfigure pane window? */
543 * Update the pane serial number.
545 p_ptr->serial = p_num;
548 * Recompute window X and Y coordinates.
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);
568 window_x += menu->x_pos;
569 window_y += menu->y_pos;
572 * If the newly compute pane coordinates differ from the
573 * current coordinates, reset the current coordinates and
574 * reconfigure the pane.
576 if (
577 (window_x != p_ptr->window_x) ||
578 (window_y != p_ptr->window_y)
581 * Reset the coordinates and schedule
582 * the pane for reconfiguration.
584 p_ptr->window_x = window_x;
585 p_ptr->window_y = window_y;
586 config_p = True;
590 * If the local pane width and height differs from the
591 * menu pane width and height, reset the local values.
593 if (
594 (p_ptr->window_w != menu->p_width) ||
595 (p_ptr->window_h != menu->p_height)
598 * Reset window width and height and schedule
599 * the pane for reconfiguration.
601 p_ptr->window_w = menu->p_width;
602 p_ptr->window_h = menu->p_height;
603 config_p = True;
607 * If we need to reconfigure the pane window do it now.
609 if (config_p == True) {
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.
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;
623 XConfigureWindow(
624 display,
625 p_ptr->window,
626 change_mask,
627 changes
629 free(changes);
632 else {
633 if (_XMWinQueAddPane(display, menu, p_ptr) == _FAILURE) {
634 return(_FAILURE);
640 * Recompute label X position.
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);
659 * Recompute label Y positions.
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);
665 * All went well, return successfully.
667 _XMErrorCode = XME_NO_ERROR;
668 return(_SUCCESS);
674 * _XMRecomputeSelection - Internal subroutine to recompute
675 * selection window dependencies.
678 _XMRecomputeSelection(register Display *display, register XMenu *menu, register XMSelect *s_ptr, register int s_num)
680 /* Menu object being recomputed. */
681 /* Selection pointer. */
682 /* Selection sequence number. */
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. */
689 * If the selection serial numbers are out of order, begin
690 * resequencing selections. Recompute selection window coordinates
691 * and serial number.
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.
697 if (s_ptr->serial != s_num) {
699 * Fix the sequence number.
701 s_ptr->serial = s_num;
703 * Recompute window X and Y coordinates.
705 s_ptr->window_x = menu->s_x_off;
706 s_ptr->window_y = menu->flag_height + (menu->s_y_off * s_num);
708 * We must reconfigure the window.
710 config_s = True;
714 * If the local selection width and height differs from the
715 * menu selection width and height, reset the local values.
717 if (
718 (s_ptr->window_w != menu->s_width) ||
719 (s_ptr->window_h != menu->s_height)
722 * We must reconfigure the window.
724 config_s = True;
726 * Reset window width and height.
728 s_ptr->window_w = menu->s_width;
729 s_ptr->window_h = menu->s_height;
733 * If we need to reconfigure the selection window do it now.
735 if (config_s == True) {
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.
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;
750 XConfigureWindow(
751 display,
752 s_ptr->window,
753 change_mask,
754 changes
756 free(changes);
759 else {
760 if (_XMWinQueAddSelection(display, menu, s_ptr) == _FAILURE) {
761 return(_FAILURE);
767 * Recompute label X position.
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);
786 * Recompute label Y position.
788 s_ptr->label_y = s_ptr->window_y + menu->s_fnt_info->max_bounds.ascent + menu->s_fnt_pad + menu->s_bdr_width;
791 * All went well, return successfully.
793 _XMErrorCode = XME_NO_ERROR;
794 return(_SUCCESS);
800 * _XMTransToOrigin - Internal subroutine to translate the point at
801 * the center of the current pane and selection to the
802 * the menu origin.
804 * WARNING! ****** Be certain that all menu dependencies have been
805 * recomputed before calling this routine or
806 * unpredictable results will follow.
808 void
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. */
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. */
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.
829 if (s_ptr == NULL) {
831 * Translate from the center of the pane flag to the upper left
832 * of the current pane window.
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;
837 else {
839 * First translate from the center of the current selection
840 * to the upper left of the current selection window.
842 l_orig_x = x_pos - (menu->s_width >> 1);
843 l_orig_y = y_pos - (menu->s_height >> 1);
846 * Then translate to the upper left of the current pane window.
848 l_orig_x -= (s_ptr->window_x + menu->p_bdr_width);
849 l_orig_y -= (s_ptr->window_y + menu->p_bdr_width);
853 * Finally translate to the upper left of the menu.
855 l_orig_x -= (p_ptr->window_x - menu->x_pos);
856 l_orig_y -= (p_ptr->window_y - menu->y_pos);
859 * Set the return values.
861 *orig_x = l_orig_x;
862 *orig_y = l_orig_y;
866 * _XMRefreshPane - Internal subroutine to completely refresh
867 * the contents of a pane.
869 void
870 _XMRefreshPane(register Display *display, register XMenu *menu, register XMPane *pane)
872 register XMSelect *s_list = pane->s_list;
873 register XMSelect *s_ptr;
876 * First clear the pane.
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);
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);
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);
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);
921 * Finally refresh each selection if the pane is activated.
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);
934 * _XMRefreshSelection - Internal subroutine that refreshes
935 * a single selection window.
937 void
938 _XMRefreshSelection(register Display *display, register XMenu *menu, register XMSelect *sel)
940 register int width = sel->window_w;
941 register int height = sel->window_h;
942 register int bdr_width = menu->s_bdr_width;
944 if (sel->type == SEPARATOR) {
945 XDrawLine(display,
946 sel->parent_p->window,
947 menu->normal_select_GC,
948 sel->window_x,
949 sel->window_y + height / 2,
950 sel->window_x + width,
951 sel->window_y + height / 2);
953 else if (sel->activated) {
954 if (menu->menu_mode == INVERT) {
955 XFillRectangle(display,
956 sel->parent_p->window,
957 menu->normal_select_GC,
958 sel->window_x, sel->window_y,
959 width, height);
960 XDrawString(display,
961 sel->parent_p->window,
962 menu->inverse_select_GC,
963 sel->label_x,
964 sel->label_y,
965 sel->label, sel->label_length);
967 else {
969 * Using BOX mode.
970 * Since most drawing routines with arbitrary width lines
971 * are slow compared to raster-ops let's use a raster-op to
972 * draw the boxes.
975 XDrawRectangle(display,
976 sel->parent_p->window,
977 menu->normal_select_GC,
978 sel->window_x + (bdr_width >> 1),
979 sel->window_y + (bdr_width >> 1 ),
980 width - bdr_width,
981 height - bdr_width);
982 XDrawString(display,
983 sel->parent_p->window,
984 menu->normal_select_GC,
985 sel->label_x,
986 sel->label_y,
987 sel->label, sel->label_length);
990 else {
991 XClearArea(display,
992 sel->parent_p->window,
993 sel->window_x, sel->window_y,
994 width, height,
995 False);
996 if (sel->active) {
997 XDrawString(display,
998 sel->parent_p->window,
999 menu->normal_select_GC,
1000 sel->label_x,
1001 sel->label_y,
1002 sel->label, sel->label_length);
1004 else {
1005 XDrawString(display,
1006 sel->parent_p->window,
1007 menu->inact_GC,
1008 sel->label_x,
1009 sel->label_y,
1010 sel->label, sel->label_length);