comparison oldXMenu/Internal.c @ 49600:23a1cea22d13

Trailing whitespace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 14:56:31 +0000
parents bbce331da1be
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49599:5ade352e8d1c 49600:23a1cea22d13
1 #include "copyright.h" 1 #include "copyright.h"
2 2
3 /* $Header: /u/src/emacs/19.0/oldXMenu/RCS/Internal.c,v 1.1 1992/04/11 22:10:20 jimb Exp $ */ 3 /* $Header: /cvs/emacs/oldXMenu/Internal.c,v 1.1 1999/10/03 19:35:07 fx Exp $ */
4 /* Copyright Massachusetts Institute of Technology 1985 */ 4 /* Copyright Massachusetts Institute of Technology 1985 */
5 5
6 /* 6 /*
7 * XMenu: MIT Project Athena, X Window system menu package 7 * XMenu: MIT Project Athena, X Window system menu package
8 * 8 *
49 static XMWinQue _XMWinQue; 49 static XMWinQue _XMWinQue;
50 50
51 /* 51 /*
52 * _XMErrorCode - Global XMenu error code. 52 * _XMErrorCode - Global XMenu error code.
53 */ 53 */
54 int _XMErrorCode = XME_NO_ERROR; 54 int _XMErrorCode = XME_NO_ERROR;
55 /* 55 /*
56 * _XMErrorList - Global XMenu error code description strings. 56 * _XMErrorList - Global XMenu error code description strings.
57 */ 57 */
58 char * 58 char *
59 _XMErrorList[XME_CODE_COUNT] = { 59 _XMErrorList[XME_CODE_COUNT] = {
202 XSetWindowAttributes *attributes; /* Attributes to be set. */ 202 XSetWindowAttributes *attributes; /* Attributes to be set. */
203 203
204 /* 204 /*
205 * If the pane window queue is not empty... 205 * If the pane window queue is not empty...
206 */ 206 */
207 207
208 if (_XMWinQue.pq_size > 0) { 208 if (_XMWinQue.pq_size > 0) {
209 /* 209 /*
210 * set up attributes for pane window to be created. 210 * set up attributes for pane window to be created.
211 */ 211 */
212 valuemask = (CWBackPixmap | CWBorderPixel | CWOverrideRedirect); 212 valuemask = (CWBackPixmap | CWBorderPixel | CWOverrideRedirect);
213 attributes = (XSetWindowAttributes *)malloc(sizeof(XSetWindowAttributes)); 213 attributes = (XSetWindowAttributes *)malloc(sizeof(XSetWindowAttributes));
214 attributes->border_pixel = menu->p_bdr_color; 214 attributes->border_pixel = menu->p_bdr_color;
215 attributes->background_pixmap = menu->inact_pixmap; 215 attributes->background_pixmap = menu->inact_pixmap;
216 attributes->override_redirect = True; 216 attributes->override_redirect = True;
217 217
218 /* 218 /*
219 * Create all the pending panes in order, so that the 219 * Create all the pending panes in order, so that the
220 * current pane will be on top, with the others 220 * current pane will be on top, with the others
221 * stacked appropriately under it. 221 * stacked appropriately under it.
222 */ 222 */
223 for (pq_index = _XMWinQue.pq_size - 1; 223 for (pq_index = _XMWinQue.pq_size - 1;
224 pq_index >= 0; 224 pq_index >= 0;
225 pq_index--) 225 pq_index--)
226 { 226 {
227 p_ptr = _XMWinQue.pq[pq_index]; /* Retrieve next pane. */ 227 p_ptr = _XMWinQue.pq[pq_index]; /* Retrieve next pane. */
228 if (p_ptr == pane) break; 228 if (p_ptr == pane) break;
229 p_ptr->window = XCreateWindow(display, 229 p_ptr->window = XCreateWindow(display,
230 menu->parent, 230 menu->parent,
241 XMakeAssoc(display, menu->assoc_tab, p_ptr->window, p_ptr); 241 XMakeAssoc(display, menu->assoc_tab, p_ptr->window, p_ptr);
242 XSelectInput(display, p_ptr->window, menu->p_events); 242 XSelectInput(display, p_ptr->window, menu->p_events);
243 } 243 }
244 for (pq_index = 0; 244 for (pq_index = 0;
245 pq_index < _XMWinQue.pq_size; 245 pq_index < _XMWinQue.pq_size;
246 pq_index++) 246 pq_index++)
247 { 247 {
248 p_ptr = _XMWinQue.pq[pq_index]; /* Retrieve next pane. */ 248 p_ptr = _XMWinQue.pq[pq_index]; /* Retrieve next pane. */
249 p_ptr->window = XCreateWindow(display, 249 p_ptr->window = XCreateWindow(display,
250 menu->parent, 250 menu->parent,
251 p_ptr->window_x, 251 p_ptr->window_x,
271 } 271 }
272 272
273 /* 273 /*
274 * If the selection window queue is not empty... 274 * If the selection window queue is not empty...
275 */ 275 */
276 276
277 if (_XMWinQue.sq_size > 0) { 277 if (_XMWinQue.sq_size > 0) {
278 278
279 for (sq_index = 0; sq_index < _XMWinQue.sq_size; sq_index++) { 279 for (sq_index = 0; sq_index < _XMWinQue.sq_size; sq_index++) {
280 /* 280 /*
281 * Retrieve the XMSelect pointer. 281 * Retrieve the XMSelect pointer.
291 CopyFromParent, 291 CopyFromParent,
292 InputOnly, 292 InputOnly,
293 CopyFromParent, 293 CopyFromParent,
294 0, 294 0,
295 attributes); 295 attributes);
296 296
297 /* 297 /*
298 * Insert the new window id and its 298 * Insert the new window id and its
299 * associated XMSelect structure into the 299 * associated XMSelect structure into the
300 * association table. 300 * association table.
301 */ 301 */
302 XMakeAssoc(display, menu->assoc_tab, s_ptr->window, s_ptr); 302 XMakeAssoc(display, menu->assoc_tab, s_ptr->window, s_ptr);
303 XSelectInput(display, s_ptr->window, menu->s_events); 303 XSelectInput(display, s_ptr->window, menu->s_events);
304 } 304 }
369 register XMPane *p_ptr; /* Pane to find the selection in. */ 369 register XMPane *p_ptr; /* Pane to find the selection in. */
370 register int s_num; /* Index number of the selection to find. */ 370 register int s_num; /* Index number of the selection to find. */
371 { 371 {
372 register XMSelect *s_ptr; /* Selection pointer to be returned. */ 372 register XMSelect *s_ptr; /* Selection pointer to be returned. */
373 register int i; /* Loop counter. */ 373 register int i; /* Loop counter. */
374 374
375 /* 375 /*
376 * Is the selection number out of range? 376 * Is the selection number out of range?
377 */ 377 */
378 if ((s_num < 0) || (s_num > (p_ptr->s_count - 1))) { 378 if ((s_num < 0) || (s_num > (p_ptr->s_count - 1))) {
379 _XMErrorCode = XME_S_NOT_FOUND; 379 _XMErrorCode = XME_S_NOT_FOUND;
398 /* 398 /*
399 * _XMRecomputeGlobals - Internal subroutine to recompute menu wide 399 * _XMRecomputeGlobals - Internal subroutine to recompute menu wide
400 * global values. 400 * global values.
401 */ 401 */
402 _XMRecomputeGlobals(display, menu) 402 _XMRecomputeGlobals(display, menu)
403 register Display *display; /*X11 display variable. */ 403 register Display *display; /*X11 display variable. */
404 register XMenu *menu; /* Menu object to compute from. */ 404 register XMenu *menu; /* Menu object to compute from. */
405 { 405 {
406 register XMPane *p_ptr; /* Pane pointer. */ 406 register XMPane *p_ptr; /* Pane pointer. */
407 register XMSelect *s_ptr; /* Selection pointer. */ 407 register XMSelect *s_ptr; /* Selection pointer. */
408 408
416 int p_height; /* Pane window height. */ 416 int p_height; /* Pane window height. */
417 int p_width; /* Pane window width. */ 417 int p_width; /* Pane window width. */
418 int s_width; /* Selection window width. */ 418 int s_width; /* Selection window width. */
419 419
420 int screen; /* DefaultScreen holder. */ 420 int screen; /* DefaultScreen holder. */
421 421
422 /* 422 /*
423 * For each pane... 423 * For each pane...
424 */ 424 */
425 for ( 425 for (
426 p_ptr = menu->p_list->next; 426 p_ptr = menu->p_list->next;
427 p_ptr != menu->p_list; 427 p_ptr != menu->p_list;
428 p_ptr = p_ptr->next 428 p_ptr = p_ptr->next
429 ){ 429 ){
430 430
431 /* 431 /*
432 * Recompute maximum pane label width. 432 * Recompute maximum pane label width.
433 */ 433 */
434 max_p_label = max(max_p_label, p_ptr->label_width); 434 max_p_label = max(max_p_label, p_ptr->label_width);
435 435
436 /* 436 /*
437 * Recompute maximum selection count. 437 * Recompute maximum selection count.
438 */ 438 */
439 s_count = max(s_count, p_ptr->s_count); 439 s_count = max(s_count, p_ptr->s_count);
440 440
441 /* 441 /*
442 * For each selection in the current pane... 442 * For each selection in the current pane...
493 menu->s_count = s_count; 493 menu->s_count = s_count;
494 menu->p_height = p_height; 494 menu->p_height = p_height;
495 menu->p_width = p_width; 495 menu->p_width = p_width;
496 menu->s_width = s_width; 496 menu->s_width = s_width;
497 497
498 /* 498 /*
499 * Ensure that the origin of the menu is placed so that 499 * Ensure that the origin of the menu is placed so that
500 * None of the panes ore selections are off the screen. 500 * None of the panes ore selections are off the screen.
501 */ 501 */
502 screen = DefaultScreen(display); 502 screen = DefaultScreen(display);
503 if (menu->x_pos + menu->width > DisplayWidth(display, screen)) 503 if (menu->x_pos + menu->width > DisplayWidth(display, screen))
520 register XMPane *p_ptr; /* Pane pointer. */ 520 register XMPane *p_ptr; /* Pane pointer. */
521 register int p_num; /* Pane sequence number. */ 521 register int p_num; /* Pane sequence number. */
522 { 522 {
523 register int window_x; /* Recomputed window X coordinate. */ 523 register int window_x; /* Recomputed window X coordinate. */
524 register int window_y; /* Recomputed window Y coordinate. */ 524 register int window_y; /* Recomputed window Y coordinate. */
525 525
526 unsigned long change_mask; /* Value mask to reconfigure window. */ 526 unsigned long change_mask; /* Value mask to reconfigure window. */
527 XWindowChanges *changes; /* Values to use in configure window. */ 527 XWindowChanges *changes; /* Values to use in configure window. */
528 528
529 register Bool config_p = False; /* Reconfigure pane window? */ 529 register Bool config_p = False; /* Reconfigure pane window? */
530 530
531 /* 531 /*
532 * Update the pane serial number. 532 * Update the pane serial number.
533 */ 533 */
556 } 556 }
557 window_x += menu->x_pos; 557 window_x += menu->x_pos;
558 window_y += menu->y_pos; 558 window_y += menu->y_pos;
559 559
560 /* 560 /*
561 * If the newly compute pane coordinates differ from the 561 * If the newly compute pane coordinates differ from the
562 * current coordinates, reset the current coordinates and 562 * current coordinates, reset the current coordinates and
563 * reconfigure the pane. 563 * reconfigure the pane.
564 */ 564 */
565 if ( 565 if (
566 (window_x != p_ptr->window_x) || 566 (window_x != p_ptr->window_x) ||
606 changes = (XWindowChanges *)malloc(sizeof(XWindowChanges)); 606 changes = (XWindowChanges *)malloc(sizeof(XWindowChanges));
607 changes->x = p_ptr->window_x; 607 changes->x = p_ptr->window_x;
608 changes->y = p_ptr->window_y; 608 changes->y = p_ptr->window_y;
609 changes->width = p_ptr->window_w; 609 changes->width = p_ptr->window_w;
610 changes->height = p_ptr->window_h; 610 changes->height = p_ptr->window_h;
611 611
612 XConfigureWindow( 612 XConfigureWindow(
613 display, 613 display,
614 p_ptr->window, 614 p_ptr->window,
615 change_mask, 615 change_mask,
616 changes 616 changes
617 ); 617 );
618 free(changes); 618 free(changes);
619 619
620 } 620 }
621 else { 621 else {
622 if (_XMWinQueAddPane(display, menu, p_ptr) == _FAILURE) { 622 if (_XMWinQueAddPane(display, menu, p_ptr) == _FAILURE) {
623 return(_FAILURE); 623 return(_FAILURE);
624 } 624 }
625 } 625 }
626 } 626 }
627 627
628 /* 628 /*
629 * Recompute label X position. 629 * Recompute label X position.
630 */ 630 */
631 switch (menu->p_style) { 631 switch (menu->p_style) {
632 case LEFT: 632 case LEFT:
671 register int s_num; /* Selection sequence number. */ 671 register int s_num; /* Selection sequence number. */
672 { 672 {
673 register Bool config_s = False; /* Reconfigure selection window? */ 673 register Bool config_s = False; /* Reconfigure selection window? */
674 XWindowChanges *changes; /* Values to change in configure. */ 674 XWindowChanges *changes; /* Values to change in configure. */
675 unsigned long change_mask; /* Value mask for XConfigureWindow. */ 675 unsigned long change_mask; /* Value mask for XConfigureWindow. */
676 676
677 /* 677 /*
678 * If the selection serial numbers are out of order, begin 678 * If the selection serial numbers are out of order, begin
679 * resequencing selections. Recompute selection window coordinates 679 * resequencing selections. Recompute selection window coordinates
680 * and serial number. 680 * and serial number.
681 * 681 *
733 changes = (XWindowChanges *)malloc(sizeof(XWindowChanges)); 733 changes = (XWindowChanges *)malloc(sizeof(XWindowChanges));
734 changes->x = s_ptr->window_x; 734 changes->x = s_ptr->window_x;
735 changes->y = s_ptr->window_y; 735 changes->y = s_ptr->window_y;
736 changes->width = s_ptr->window_w; 736 changes->width = s_ptr->window_w;
737 changes->height = s_ptr->window_h; 737 changes->height = s_ptr->window_h;
738 738
739 XConfigureWindow( 739 XConfigureWindow(
740 display, 740 display,
741 s_ptr->window, 741 s_ptr->window,
742 change_mask, 742 change_mask,
743 changes 743 changes
744 ); 744 );
745 free(changes); 745 free(changes);
746 746
747 } 747 }
748 else { 748 else {
749 if (_XMWinQueAddSelection(display, menu, s_ptr) == _FAILURE) { 749 if (_XMWinQueAddSelection(display, menu, s_ptr) == _FAILURE) {
750 return(_FAILURE); 750 return(_FAILURE);
751 } 751 }
773 } 773 }
774 /* 774 /*
775 * Recompute label Y position. 775 * Recompute label Y position.
776 */ 776 */
777 s_ptr->label_y = s_ptr->window_y + menu->s_fnt_info->max_bounds.ascent + menu->s_fnt_pad + menu->s_bdr_width; 777 s_ptr->label_y = s_ptr->window_y + menu->s_fnt_info->max_bounds.ascent + menu->s_fnt_pad + menu->s_bdr_width;
778 778
779 /* 779 /*
780 * All went well, return successfully. 780 * All went well, return successfully.
781 */ 781 */
782 _XMErrorCode = XME_NO_ERROR; 782 _XMErrorCode = XME_NO_ERROR;
783 return(_SUCCESS); 783 return(_SUCCESS);
785 785
786 786
787 787
788 /* 788 /*
789 * _XMTransToOrigin - Internal subroutine to translate the point at 789 * _XMTransToOrigin - Internal subroutine to translate the point at
790 * the center of the current pane and selection to the 790 * the center of the current pane and selection to the
791 * the menu origin. 791 * the menu origin.
792 * 792 *
793 * WARNING! ****** Be certain that all menu dependencies have been 793 * WARNING! ****** Be certain that all menu dependencies have been
794 * recomputed before calling this routine or 794 * recomputed before calling this routine or
795 * unpredictable results will follow. 795 * unpredictable results will follow.
804 int *orig_x; /* Return value X coord. of the menu origin. */ 804 int *orig_x; /* Return value X coord. of the menu origin. */
805 int *orig_y; /* Return value Y coord. of the menu origin. */ 805 int *orig_y; /* Return value Y coord. of the menu origin. */
806 { 806 {
807 register int l_orig_x; /* Local X coordinate of the menu origin. */ 807 register int l_orig_x; /* Local X coordinate of the menu origin. */
808 register int l_orig_y; /* Local Y coordinate of the menu origin. */ 808 register int l_orig_y; /* Local Y coordinate of the menu origin. */
809 809
810 /* 810 /*
811 * Translate the menu origin such that the cursor hot point will be in the 811 * Translate the menu origin such that the cursor hot point will be in the
812 * center of the desired current selection and pane. 812 * center of the desired current selection and pane.
813 * If the current selection pointer is NULL then assume that the hot point 813 * If the current selection pointer is NULL then assume that the hot point
814 * will be in the center of the current pane flag. 814 * will be in the center of the current pane flag.
861 { 861 {
862 register XMSelect *s_list = pane->s_list; 862 register XMSelect *s_list = pane->s_list;
863 register XMSelect *s_ptr; 863 register XMSelect *s_ptr;
864 864
865 /* 865 /*
866 * First clear the pane. 866 * First clear the pane.
867 */ 867 */
868 XClearWindow(display, pane->window); 868 XClearWindow(display, pane->window);
869 if (!pane->activated) { 869 if (!pane->activated) {
870 XFillRectangle(display, 870 XFillRectangle(display,
871 pane->window, 871 pane->window,
914 for (s_ptr = s_list->next; s_ptr != s_list; s_ptr = s_ptr->next) 914 for (s_ptr = s_list->next; s_ptr != s_list; s_ptr = s_ptr->next)
915 _XMRefreshSelection(display, menu, s_ptr); 915 _XMRefreshSelection(display, menu, s_ptr);
916 } 916 }
917 } 917 }
918 } 918 }
919 919
920 920
921 921
922 922
923 /* 923 /*
924 * _XMRefreshSelection - Internal subroutine that refreshes 924 * _XMRefreshSelection - Internal subroutine that refreshes
925 * a single selection window. 925 * a single selection window.
926 */ 926 */
927 _XMRefreshSelection(display, menu, select) 927 _XMRefreshSelection(display, menu, select)
928 register Display *display; 928 register Display *display;
929 register XMenu *menu; 929 register XMenu *menu;
930 register XMSelect *select; 930 register XMSelect *select;
931 { 931 {
932 register int width = select->window_w; 932 register int width = select->window_w;
933 register int height = select->window_h; 933 register int height = select->window_h;
934 register int bdr_width = menu->s_bdr_width; 934 register int bdr_width = menu->s_bdr_width;
935 935
936 if (select->type == SEPARATOR) { 936 if (select->type == SEPARATOR) {
937 XDrawLine(display, 937 XDrawLine(display,
938 select->parent_p->window, 938 select->parent_p->window,
939 menu->normal_select_GC, 939 menu->normal_select_GC,
940 select->window_x, 940 select->window_x,
942 select->window_x + width, 942 select->window_x + width,
943 select->window_y + height / 2); 943 select->window_y + height / 2);
944 } 944 }
945 else if (select->activated) { 945 else if (select->activated) {
946 if (menu->menu_mode == INVERT) { 946 if (menu->menu_mode == INVERT) {
947 XFillRectangle(display, 947 XFillRectangle(display,
948 select->parent_p->window, 948 select->parent_p->window,
949 menu->normal_select_GC, 949 menu->normal_select_GC,
950 select->window_x, select->window_y, 950 select->window_x, select->window_y,
951 width, height); 951 width, height);
952 XDrawString(display, 952 XDrawString(display,
953 select->parent_p->window, 953 select->parent_p->window,
954 menu->inverse_select_GC, 954 menu->inverse_select_GC,
955 select->label_x, 955 select->label_x,
956 select->label_y, 956 select->label_y,
961 * Using BOX mode. 961 * Using BOX mode.
962 * Since most drawing routines with arbitrary width lines 962 * Since most drawing routines with arbitrary width lines
963 * are slow compared to raster-ops lets use a raster-op to 963 * are slow compared to raster-ops lets use a raster-op to
964 * draw the boxes. 964 * draw the boxes.
965 */ 965 */
966 966
967 XDrawRectangle(display, 967 XDrawRectangle(display,
968 select->parent_p->window, 968 select->parent_p->window,
969 menu->normal_select_GC, 969 menu->normal_select_GC,
970 select->window_x + (bdr_width >> 1), 970 select->window_x + (bdr_width >> 1),
971 select->window_y + (bdr_width >> 1 ), 971 select->window_y + (bdr_width >> 1 ),
978 select->label_y, 978 select->label_y,
979 select->label, select->label_length); 979 select->label, select->label_length);
980 } 980 }
981 } 981 }
982 else { 982 else {
983 XClearArea(display, 983 XClearArea(display,
984 select->parent_p->window, 984 select->parent_p->window,
985 select->window_x, select->window_y, 985 select->window_x, select->window_y,
986 width, height, 986 width, height,
987 False); 987 False);
988 if (select->active) { 988 if (select->active) {