1: #include <X/mit-copyright.h>
   2: 
   3: /* $Header: deltest.c,v 10.7 86/02/01 16:16:10 tony Rel $ */
   4: /* Copyright    Massachusetts Institute of Technology    1985	*/
   5: 
   6: /*
   7:  * XMenu:	MIT Project Athena, X Window System menu package.
   8:  *
   9:  *	deltest.c		Deltest is an XMenu selection / pane
  10:  *				deletion testing utility.
  11:  *
  12:  *	Author:			Tony Della Fera, DEC
  13:  *				20-Nov-85
  14:  */
  15: 
  16: #include <X/Xlib.h>
  17: #include "../XMenu.h"
  18: #include <stdio.h>
  19: 
  20: main(argc, argv)
  21:     int argc;       /* Argument count. */
  22:     char **argv;    /* Argument vector. */
  23: {
  24:     register int i; /* Counter. */
  25:     register int j; /* Counter. */
  26:     register int stat;  /* Return status. */
  27:     int p_num = 0;  /* Pane number. */
  28:     int s_num = 0;  /* Selection number. */
  29:     int x, y;       /* Mouse X and Y position. */
  30: 
  31:     Window twin;    /* Temporary window. */
  32:     XMenu *menu;    /* Menu structure. */
  33:     char *data;     /* Test data. */
  34: 
  35:     /*
  36:      * Open the display.
  37:      */
  38:     if (XOpenDisplay(NULL) == NULL) {
  39:     printf("deltest: Error opening display.\n");
  40:     exit(0);
  41:     }
  42: 
  43:     /*
  44:      * Create the XMenu.
  45:      */
  46:     menu = (XMenu *)XMenuCreate(RootWindow, argv[0]);
  47:     if (menu == NULL) MenuError();
  48: 
  49:     /*
  50:      * Assemble the panes and selections.
  51:      */
  52:     printf("Deltest assembling panes: zero... ");
  53:     stat = XMenuAddPane(menu, "Pane Zero", 1);
  54:     if (stat == XM_FAILURE) MenuError();
  55:     stat = XMenuAddSelection(menu, 0, (char *)1, "Exit deltest.", 1);
  56:     if (stat == XM_FAILURE) MenuError();
  57:     stat = XMenuAddSelection(menu, 0, (char *)3, "Selection one.", 1);
  58:     if (stat == XM_FAILURE) MenuError();
  59:     stat = XMenuAddSelection(menu, 0, (char *)3, "Selection two.", 1);
  60:     if (stat == XM_FAILURE) MenuError();
  61:     stat = XMenuAddSelection(menu, 0, (char *)3, "Selection three.", 1);
  62:     if (stat == XM_FAILURE) MenuError();
  63: 
  64:     printf("one... ");
  65:     stat = XMenuAddPane(menu, "Pane One", 1);
  66:     if (stat == XM_FAILURE) MenuError();
  67:     stat = XMenuAddSelection(menu, 1, (char *)4, "Delete pane.", 1);
  68:     if (stat == XM_FAILURE) MenuError();
  69:     stat = XMenuAddSelection(menu, 1, (char *)3, "Selection one.", 1);
  70:     if (stat == XM_FAILURE) MenuError();
  71:     stat = XMenuAddSelection(menu, 1, (char *)3, "Selection two.", 1);
  72:     if (stat == XM_FAILURE) MenuError();
  73: 
  74:     printf("two... ");
  75:     stat = XMenuAddPane(menu, "Pane Two", 1);
  76:     if (stat == XM_FAILURE) MenuError();
  77:     stat = XMenuAddSelection(menu, 2, (char *)4, "Delete pane.", 1);
  78:     if (stat == XM_FAILURE) MenuError();
  79:     stat = XMenuAddSelection(menu, 2, (char *)3, "Selection one.", 1);
  80:     if (stat == XM_FAILURE) MenuError();
  81:     stat = XMenuAddSelection(menu, 2, (char *)3, "Selection two.", 1);
  82:     if (stat == XM_FAILURE) MenuError();
  83:     stat = XMenuAddSelection(menu, 2, (char *)3, "Selection three.", 1);
  84:     if (stat == XM_FAILURE) MenuError();
  85:     stat = XMenuAddSelection(menu, 2, (char *)3, "Selection four.", 1);
  86:     if (stat == XM_FAILURE) MenuError();
  87: 
  88:     printf("three... ");
  89:     stat = XMenuAddPane(menu, "Pane Three", 1);
  90:     if (stat == XM_FAILURE) MenuError();
  91:     stat = XMenuAddSelection(menu, 3, (char *)4, "Delete pane.", 1);
  92:     if (stat == XM_FAILURE) MenuError();
  93: 
  94:     printf("four... ");
  95:     stat = XMenuAddPane(menu, "Pane Four", 1);
  96:     if (stat == XM_FAILURE) MenuError();
  97:     stat = XMenuAddSelection(menu, 4, (char *)4, "Delete pane.", 1);
  98:     if (stat == XM_FAILURE) MenuError();
  99:     stat = XMenuAddSelection(menu, 4, (char *)3, "Selection one.", 1);
 100:     if (stat == XM_FAILURE) MenuError();
 101:     printf("done.\n");
 102: 
 103:     /*
 104:      * Recompute menu.
 105:      */
 106:     printf("Deltest recomputing menu dependencies.\n");
 107:     stat = XMenuRecompute(menu);
 108:     if (stat == XM_FAILURE) MenuError();
 109: 
 110:     /*
 111:      * Post the menu.
 112:      */
 113:     while (1) {
 114:     data = NULL;
 115:     p_num = 0;
 116:     s_num = 0;
 117:     printf(
 118:         "Deltest posting menu: pane = %d, selection = %d.\n",
 119:         p_num, s_num
 120:     );
 121:     XQueryMouse(RootWindow, &x, &y, &twin);
 122:     stat = XMenuActivate(
 123:         menu,
 124:         &p_num, &s_num,
 125:         x, y,
 126:         ButtonPressed,
 127:         &data
 128:     );
 129:     printf("Deltest results:  data = %d, pane = %d, selection = %d\n",
 130:         (int)data, p_num, s_num);
 131:     if (stat == XM_FAILURE) MenuError();
 132:     if (stat == XM_NO_SELECT) {
 133:         printf("Deltest reports no selection made.\n");
 134:         s_num = 0;
 135:         continue;
 136:     }
 137:     if (stat == XM_IA_SELECT) {
 138:         printf("Deltest reports no selection active.\n");
 139:         continue;
 140:     }
 141:     if ((int)data == 1) break;
 142:     if ((int)data == 3) {
 143:         printf(
 144:         "Deltest deleteing selection %d in pane %d.\n",
 145:         s_num, p_num
 146:         );
 147:         stat = XMenuDeleteSelection(menu, p_num, s_num);
 148:         if (stat == XM_FAILURE) MenuError();
 149:         printf("Deltest recomputing menu dependencies.\n");
 150:         stat = XMenuRecompute(menu);
 151:         if (stat == XM_FAILURE) MenuError();
 152:     }
 153:     if ((int)data == 4) {
 154:         printf("Deltest deleteing pane %d.\n", p_num);
 155:         stat = XMenuDeletePane(menu, p_num);
 156:         if (stat == XM_FAILURE) MenuError();
 157:         printf("Deltest recomputing menu dependencies.\n");
 158:         stat = XMenuRecompute(menu);
 159:         if (stat == XM_FAILURE) MenuError();
 160:     }
 161:     }
 162: 
 163:     /*
 164:      * Destroy XMenu.
 165:      */
 166:     printf("Deltest destroying menu.\n");
 167:     XMenuDestroy(menu);
 168: }
 169: 
 170: /*
 171:  * Print the XMenu error message.
 172:  */
 173: MenuError()
 174: {
 175:     printf("\nDeltest reports XMenu error: %s.\n\n", XMenuError());
 176:     exit(0);
 177: }

Defined functions

MenuError defined in line 173; used 27 times
main defined in line 20; never used
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1361
Valid CSS Valid XHTML 1.0 Strict